diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2023-04-04 13:10:44 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2023-04-04 13:10:44 +0700 |
commit | c4edc700b5c68cf4e05a22e83513a39d3de9636a (patch) | |
tree | ea19e53a4e4b8f4b615ab9d9eeca76dbef5e1c93 | |
parent | PKCS10: check for null/empty extension request value (diff) | |
download | BouncyCastle.NET-ed25519-c4edc700b5c68cf4e05a22e83513a39d3de9636a.tar.xz |
Add constructor from template certificate
-rw-r--r-- | crypto/src/x509/X509V3CertificateGenerator.cs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/crypto/src/x509/X509V3CertificateGenerator.cs b/crypto/src/x509/X509V3CertificateGenerator.cs index ee35b9479..d5c9ffe92 100644 --- a/crypto/src/x509/X509V3CertificateGenerator.cs +++ b/crypto/src/x509/X509V3CertificateGenerator.cs @@ -26,6 +26,39 @@ namespace Org.BouncyCastle.X509 tbsGen = new V3TbsCertificateGenerator(); } + /// <summary>Create a generator for a version 3 certificate, initialised with another certificate.</summary> + /// <param name="template">Template certificate to base the new one on.</param> + public X509V3CertificateGenerator(X509Certificate template) + : this(template.CertificateStructure) + { + } + + public X509V3CertificateGenerator(X509CertificateStructure template) + { + tbsGen = new V3TbsCertificateGenerator(); + tbsGen.SetSerialNumber(template.SerialNumber); + tbsGen.SetIssuer(template.Issuer); + tbsGen.SetStartDate(template.StartDate); + tbsGen.SetEndDate(template.EndDate); + tbsGen.SetSubject(template.Subject); + tbsGen.SetSubjectPublicKeyInfo(template.SubjectPublicKeyInfo); + + var extensions = template.TbsCertificate.Extensions; + + foreach (var oid in extensions.ExtensionOids) + { + if (X509Extensions.SubjectAltPublicKeyInfo.Equals(oid) || + X509Extensions.AltSignatureAlgorithm.Equals(oid) || + X509Extensions.AltSignatureValue.Equals(oid)) + { + continue; + } + + X509Extension ext = extensions.GetExtension(oid); + extGenerator.AddExtension(oid, ext.critical, ext.Value.GetOctets()); + } + } + /// <summary> /// Reset the Generator. /// </summary> |