locked
CertEnroll creates the request in UTF8String RRS feed

  • Question

  • Hi,

     

     I have a issue in creating the certificate request in Vista, I have successfully create the certificate request but my server implementation is looking for the type PrintableString or IA5String. But whatever the certificate request is created is of type UTF8String.

     

    My sDistinguishedName value is

    "cn=sample:test,o=Testing Company Ltd.,c=GB";

     

    Following is my java script code:

     

    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");
    // set the provider
    var nCSPIndex=document.requestForm.selectCapi.selectedIndex;
    var nProvType=document.requestForm.selectCapi.options[nCSPIndex].value;
    objPrivateKey.KeyProtection = XCN_NCRYPT_UI_FORCE_HIGH_PROTECTION_FLAG;
    objPrivateKey.ExportPolicy = XCN_NCRYPT_ALLOW_EXPORT_FLAG;
    objPrivateKey.Length = keyLength;
    objPrivateKey.ProviderName = document.requestForm.selectCapi.options[nCSPIndex].text;
    objPrivateKey.KeySpec = keySpecValue;
    objPrivateKey.ProviderType = nProvType;
    objRequest.InitializeFromPrivateKey(contextUser, objPrivateKey, "");
    var extensionTemplate1 = classFactory.CreateObject("X509Enrollment.CX509ExtensionTemplateName");
    extensionTemplate1.InitializeEncode("1.3.6.1.4.1.311.2.1.21");
    objRequest.X509Extensions.Add(extensionTemplate1)
    objDN.Encode(sDistinguishedName, 2);//XCN_CERT_NAME_STR_NONE);
    objRequest.Subject = objDN;
    objEnroll.InitializeFromRequest(objRequest);
    szDN = objEnroll.CreateRequest(1);//CRYPT_STRING_BASE64
    alert(szDN);
    fullRequest="-----BEGIN CERTIFICATE REQUEST-----\n\r"+szDN+"-----END CERTIFICATE REQUEST-----\n\r";
    document.requestForm.textarea1.value=fullRequest;
    document.requestForm.certRequest.value=fullRequest;

     

    After I generate the Request I am able to get the country alone in PrintableString, but remaing are coming in UTF8String

     

    Can we change UTF8String to PrintableString?

     

    Thanks in advance.

    Tuesday, July 8, 2008 5:00 PM

All replies

  • Hi,
    I found this solution:

    Dim X500DistinguishedName
    Set X500DistinguishedName = g_objClassFactory.CreateObject("X509Enrollment.CX500DistinguishedName")

    Const XCN_CERT_NAME_STR_DISABLE_UTF8_DIR_STR_FLAG = 1048576  
    Call X500DistinguishedName.Encode(sDN, XCN_CERT_NAME_STR_DISABLE_UTF8_DIR_STR_FLAG)

    I hope this can help you

    Barbara
    Thursday, October 9, 2008 3:51 PM