I want to add a SAN in bouncy castle and I am using this code:
var alt_names = new Dictionary<DerObjectIdentifier, string> {
{X509Name.SerialNumber, "334623324234325"},
{X509Name.UID, "310122393500003"},
{X509Name.T, "0000"},
{X509Name.PostalAddress, "Sample E"},
{X509Name.BusinessCategory, "Sample Business"}
};
var sln = new X509Name(alt_names.Keys.Reverse().ToList(), alt_names);
var extensions = new Dictionary<DerObjectIdentifier, X509Extension>()
{
{X509Extensions.BasicConstraints, new X509Extension(true,
new DerOctetString(new BasicConstraints(false)))},
{X509Extensions.KeyUsage, new X509Extension(true,
new DerOctetString(new KeyUsage(KeyUsage.DigitalSignature | KeyUsage.KeyEncipherment
//| KeyUsage.NonRepudiation)))}
};
string certificateTemplateName = "1.3.6.1.4.1.311.20.2";
DerObjectIdentifier certificateTemplateExtensionOid = new DerObjectIdentifier("1.3.6.1.4.1.311.20.2");
DerSequence certificateTemplateExtension = new DerSequence(
new DerObjectIdentifier(certificateTemplateName), new DerPrintableString("ZATCA-Code-Signing"));
extensions.Add(certificateTemplateExtensionOid, new X509Extension(false, new DerOctetString(certificateTemplateExtension)));
extensions.Add(X509Extensions.SubjectAlternativeName, new X509Extension(false,
new DerOctetString(sln)));
and the output I got it after decoded:
Attributes:
Requested Extensions:
1.3.6.1.4.1.311.20.2:
0...+.....7....ZATCA-Code-Signing
X509v3 Subject Alternative Name:
0x1.0...U....Sample Business1.0...U....Sample E1
0...U....00001.0..
..&...,d....3101223935000031.0...U....334623324234325
and the output I need it should be like this:
Attributes:
Requested Extensions:
1.3.6.1.4.1.311.20.2:
..ZATCA-Code-Signing
X509v3 Subject Alternative Name:
DirName:/SN=334623324234325/UID=310122393500003/title=0000/registeredAddress=Sample E/businessCategory=Sample Business
Signature Algorithm: ecdsa-with-SHA256
I want to add Subject Alternative names SN, UID, title, registeredAddress and businessCategory as string and beside it the value for each of them and should start with `DirName:` string.