summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2021-02-08 18:26:36 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2021-02-08 18:26:36 +0700
commitdaa9aa34afb5261218f5dddd5e33829cf130aab6 (patch)
tree0a925e9f6e42ffe4305d63d7471074fe8d2118bf
parentSupport V1 attribute certificates and holders (diff)
downloadBouncyCastle.NET-ed25519-daa9aa34afb5261218f5dddd5e33829cf130aab6.tar.xz
Env. var. to enforce correct X.509 cert encoding
- Org.BouncyCastle.X509.Allow_Non-DER_TBSCert
-rw-r--r--crypto/src/asn1/x509/TBSCertificateStructure.cs42
1 files changed, 40 insertions, 2 deletions
diff --git a/crypto/src/asn1/x509/TBSCertificateStructure.cs b/crypto/src/asn1/x509/TBSCertificateStructure.cs
index 4e3c789e2..e600685f0 100644
--- a/crypto/src/asn1/x509/TBSCertificateStructure.cs
+++ b/crypto/src/asn1/x509/TBSCertificateStructure.cs
@@ -1,7 +1,7 @@
 using System;
 
-using Org.BouncyCastle.Asn1.Pkcs;
 using Org.BouncyCastle.Math;
+using Org.BouncyCastle.Utilities;
 
 namespace Org.BouncyCastle.Asn1.X509
 {
@@ -213,7 +213,45 @@ namespace Org.BouncyCastle.Asn1.X509
 
 		public override Asn1Object ToAsn1Object()
         {
-            return seq;
+            string property = Platform.GetEnvironmentVariable("Org.BouncyCastle.X509.Allow_Non-DER_TBSCert");
+            if (null == property || Platform.EqualsIgnoreCase("true", property))
+                return seq;
+
+            Asn1EncodableVector v = new Asn1EncodableVector();
+
+            // DEFAULT Zero
+            if (!version.HasValue(BigIntegers.Zero))
+            {
+                v.Add(new DerTaggedObject(true, 0, version));
+            }
+
+            v.Add(serialNumber, signature, issuer);
+
+			//
+			// before and after dates
+			//
+			v.Add(new DerSequence(startDate, endDate));
+
+            if (subject != null)
+            {
+                v.Add(subject);
+            }
+            else
+            {
+                v.Add(new DerSequence());
+            }
+
+            v.Add(subjectPublicKeyInfo);
+
+            // Note: implicit tag
+			v.AddOptionalTagged(false, 1, issuerUniqueID);
+
+			// Note: implicit tag
+			v.AddOptionalTagged(false, 2, subjectUniqueID);
+
+			v.AddOptionalTagged(true, 3, extensions);
+
+            return new DerSequence(v);
         }
     }
 }