@@ -38,7 +38,7 @@ protected static X509Certificate2 CreateCertificate(string subjectName, IEnumera
38
38
// * Start date: 24hrs ago
39
39
// * End date: 24hrs in the future
40
40
// * Subject: {subjectName}
41
- // * Subject alternative names: {dnsNames}, {ipAddresses}
41
+ // * Subject alternative names: {subjectName}, { dnsNames}, {ipAddresses}
42
42
// * Public key: 2048-bit RSA
43
43
// * Hash algorithm: SHA256
44
44
// * Key usage: digital signature, key encipherment
@@ -55,18 +55,17 @@ protected static X509Certificate2 CreateCertificate(string subjectName, IEnumera
55
55
X500DistinguishedNameBuilder subjectBuilder = new X500DistinguishedNameBuilder ( ) ;
56
56
SubjectAlternativeNameBuilder sanBuilder = new SubjectAlternativeNameBuilder ( ) ;
57
57
RSA rsaKey = RSA . Create ( 2048 ) ;
58
- bool hasSans = false ;
59
58
60
59
subjectBuilder . AddCommonName ( subjectName ) ;
60
+
61
+ sanBuilder . AddDnsName ( subjectName ) ;
61
62
foreach ( string dnsName in dnsNames )
62
63
{
63
64
sanBuilder . AddDnsName ( dnsName ) ;
64
- hasSans = true ;
65
65
}
66
66
foreach ( string ipAddress in ipAddresses )
67
67
{
68
68
sanBuilder . AddIpAddress ( System . Net . IPAddress . Parse ( ipAddress ) ) ;
69
- hasSans = true ;
70
69
}
71
70
72
71
CertificateRequest request = new CertificateRequest ( subjectBuilder . Build ( ) , rsaKey , HashAlgorithmName . SHA256 , RSASignaturePadding . Pkcs1 ) ;
@@ -75,10 +74,7 @@ protected static X509Certificate2 CreateCertificate(string subjectName, IEnumera
75
74
request . CertificateExtensions . Add ( new X509KeyUsageExtension ( X509KeyUsageFlags . DigitalSignature | X509KeyUsageFlags . KeyEncipherment , false ) ) ;
76
75
request . CertificateExtensions . Add ( new X509EnhancedKeyUsageExtension ( new OidCollection ( ) { new Oid ( "1.3.6.1.5.5.7.3.1" ) , new Oid ( "1.3.6.1.5.5.7.3.2" ) } , true ) ) ;
77
76
78
- if ( hasSans )
79
- {
80
- request . CertificateExtensions . Add ( sanBuilder . Build ( ) ) ;
81
- }
77
+ request . CertificateExtensions . Add ( sanBuilder . Build ( ) ) ;
82
78
83
79
// Generate an ephemeral certificate, then export it and return it as a new certificate with the correct key storage flags set.
84
80
// This is to ensure that it's imported into the certificate stores with its private key.
0 commit comments