I'm having a problem with specifying a template parameter in InitializeFromPrivateKey () of the X509Enrollment.CX509CertificateRequestPkcs10 object. Everything, except for the "User" template, leads to the following exception: -
CertEnroll :: CX509CertificateRequestPkcs10 :: InitializeFromPrivateKey: The requested certificate template is not supported by this certification authority. 0x80094800 (-2146875392)
There is a special certificate template that I need to use, and when I try it, the code throws an exception. The template exists in the CA and on the client machine, which runs the following code.
Javascript code as follows:
<script type="text/javascript"> var sCertificate = null; var sDistinguishedName = "C=\"\";S=\"\";L=\"\";O=\"XXXXX\";OU=\"XXXXXXX\";E=\" XXXXX@XXXX.com \";CN=\"xxxxxxx\";"; var template = "RegistrationCert"; //Anything Other than "User" fails, have tried template Oid too. var classFactory = new ActiveXObject("X509Enrollment.CX509EnrollmentWebClassFactory"); var objEnroll = classFactory.CreateObject("X509Enrollment.CX509Enrollment"); var objPrivateKey = classFactory.CreateObject("X509Enrollment.CX509PrivateKey"); var objRequest = classFactory.CreateObject("X509Enrollment.CX509CertificateRequestPkcs10"); var objDN = classFactory.CreateObject("X509Enrollment.CX500DistinguishedName"); objPrivateKey.ProviderName = "Microsoft Enhanced Cryptographic Provider v1.0"; objPrivateKey.KeySpec = "1"; objPrivateKey.ProviderType = "1"; try { objRequest.InitializeFromPrivateKey(1, objPrivateKey, template); objDN.Encode(sDistinguishedName, 0); objRequest.Subject = objDN; objEnroll.InitializeFromRequest(objRequest); sCertificate = objEnroll.CreateRequest(1); document.writeln(sCertificate); } catch (ex) { document.writeln(ex.description); } </script>
A couple of other questions
- I assume that the template should exist on the client machine? Otherwise, how do I know the location of the CA to request templates?
- Does the CertEnroll on the client even work against the Windows 2003 CA server?
If you can help me, that would be very grateful !!!
Additional Information
- The client is Windows 7, while the MS IE9 client works as an administrator.
- The web application that hosts the above page is accessible via HTTP.
- The web application is hosted on the CA Win2003 server.
Before publishing, I looked ...
- Stackoverflow threads relative to CertEnroll + InitializeFromPrivateKey
- Blogs about using an OID template, not a template name
- MSDN / alejacma Website
- API CertEnroll on MSDN