A customer of mine wanted to set Issuer Alternative Name (XCN_OID_ISSUER_ALT_NAME2 – “188.8.131.52”) extension to his certificate requests in C# in the same way we did this, and he didn’t know how:
All I knew was that we should use this generic interface as we don’t have a custom object in CertEnroll like we do for Subject Alternative Name or Alternative Directory Name:
To create the version 3 extensions for which Microsoft does not provide a custom object, you can use the IX509Extension interface.
you can use the IX509Extension interface to define private extensions that contain information that is unique to a specific community.
Extensions are added to the Attributes structure of a PKCS #10 request and to the TaggedAttributes structure of a CMC request. To add extensions to either request format, you must first add them to an IX509Extensions collection and use the collection to initialize an IX509AttributeExtensions object. For more information, see the PKCS #10 Extensions and the CMC Extensions topics.
This sounded a bit complicated, specially as I couldn’t find any samples on how to use this the way my customer needed.
Fortunatelly I was able to set Issuer Alternative Name in an easy way. Basically the idea is based on the fact that Issuer Alternative Name is encoded the same way than Subject Alternative Name, so we used the same classes and methods we used for the Subject Alternative Name (see the post above), but then changed the OID that identifies the extension to convert it to an Issuer Alternative Name extension. This is the code that worked for us:
CObjectId objOID = new CObjectIdClass();
CAlternativeName objAlternativeName = new CAlternativeName();
CAlternativeNames objAlternativeNames = new CAlternativeNames();
CX509ExtensionAlternativeNames objExtensionAlternativeNames = new CX509ExtensionAlternativeNames();
CX509Extension objExtension = new CX509Extension();
string rawData = null;
// Create the Issuer Alternative Name as if it were a Subject Alternative Name
objAlternativeName.InitializeFromString(AlternativeNameType.XCN_CERT_ALT_NAME_DNS_NAME, "My DNS Name");
// Change the OID of the Subject Alternative Name extension to convert it to an Issuer Alternative Name extension
rawData = objExtensionAlternativeNames.get_RawData(EncodingType.XCN_CRYPT_STRING_BINARY);
objOID.InitializeFromValue("184.108.40.206"); // XCN_OID_ISSUER_ALT_NAME2
objExtension.Initialize(objOID, EncodingType.XCN_CRYPT_STRING_BINARY, rawData);
// Add the extension to the request
I hope this helps.
Alex (Alejandro Campos Magencio)