@@ -43,7 +43,8 @@ private static void Start(CommandLineOptions options)
4343 options . SubjectAltName ,
4444 caKeyPair ,
4545 subjectKeyPair . Public ,
46- options . CRLPath
46+ options . CRLPath ,
47+ options . SerialNumber
4748 ) ;
4849
4950 PrintCertInfo ( "\n Forged Certificate Information:" , cert ) ;
@@ -102,7 +103,8 @@ private static X509Certificate GenerateCertificate(
102103 X509Name issuer , string subject , string subjectAltName ,
103104 KeyPair issuerKeyPair ,
104105 AsymmetricKeyParameter subjectPublic ,
105- string CRL = "" )
106+ string CRL = "" ,
107+ BigInteger SerialNumber = null )
106108 {
107109 ISignatureFactory signatureFactory ;
108110 if ( issuerKeyPair . Key is ECPrivateKeyParameters )
@@ -121,8 +123,15 @@ private static X509Certificate GenerateCertificate(
121123 var certGenerator = new X509V3CertificateGenerator ( ) ;
122124 certGenerator . SetIssuerDN ( issuer ) ;
123125 certGenerator . SetSubjectDN ( new X509Name ( subject ) ) ;
124- certGenerator . SetSerialNumber ( BigIntegers . CreateRandomInRange ( BigInteger . One , BigInteger . Two . Pow ( 128 ) , Random ) ) ;
125-
126+
127+ if ( SerialNumber == null )
128+ {
129+ certGenerator . SetSerialNumber ( BigIntegers . CreateRandomInRange ( BigInteger . One , BigInteger . Two . Pow ( 128 ) , Random ) ) ;
130+ } else
131+ {
132+ certGenerator . SetSerialNumber ( SerialNumber ) ;
133+ }
134+
126135 // Yes, the end lifetime can be changed easily, up to the lifetime of the CA certificate being used to forge
127136 certGenerator . SetNotAfter ( DateTime . UtcNow . AddYears ( 1 ) ) ;
128137
0 commit comments