summary refs log tree commit diff
path: root/crypto
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2020-04-05 13:58:29 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2020-04-05 13:58:29 +0700
commita50f22c7ecc8d6a238b9bb5ca9d8f453d5f00e3c (patch)
tree3ce1d940538d5a738766d96f1f93cb205461b95e /crypto
parentFix bad MAC padding length calculation (diff)
downloadBouncyCastle.NET-ed25519-a50f22c7ecc8d6a238b9bb5ca9d8f453d5f00e3c.tar.xz
Improve SigAlgName for certs/CRLs
Diffstat (limited to 'crypto')
-rw-r--r--crypto/src/x509/X509Certificate.cs23
-rw-r--r--crypto/src/x509/X509Crl.cs12
-rw-r--r--crypto/src/x509/X509SignatureUtil.cs7
3 files changed, 26 insertions, 16 deletions
diff --git a/crypto/src/x509/X509Certificate.cs b/crypto/src/x509/X509Certificate.cs
index d8d97ec5e..b4e1c17f8 100644
--- a/crypto/src/x509/X509Certificate.cs
+++ b/crypto/src/x509/X509Certificate.cs
@@ -29,6 +29,8 @@ namespace Org.BouncyCastle.X509
         private readonly X509CertificateStructure c;
         //private Hashtable pkcs12Attributes = Platform.CreateHashtable();
         //private ArrayList pkcs12Ordering = Platform.CreateArrayList();
+        private readonly string sigAlgName;
+        private readonly byte[] sigAlgParams;
 		private readonly BasicConstraints basicConstraints;
 		private readonly bool[] keyUsage;
 
@@ -47,6 +49,18 @@ namespace Org.BouncyCastle.X509
 		{
 			this.c = c;
 
+            try
+            {
+                this.sigAlgName = X509SignatureUtilities.GetSignatureName(c.SignatureAlgorithm);
+
+                Asn1Encodable parameters = c.SignatureAlgorithm.Parameters;
+                this.sigAlgParams = (null == parameters) ? null : parameters.GetEncoded(Asn1Encodable.Der);
+            }
+            catch (Exception e)
+            {
+                throw new CrlException("Certificate contents invalid: " + e);
+            }
+
 			try
 			{
 				Asn1OctetString str = this.GetExtensionValue(new DerObjectIdentifier("2.5.29.19"));
@@ -249,7 +263,7 @@ namespace Org.BouncyCastle.X509
 		/// <returns>A sting representing the signature algorithm.</returns>
 		public virtual string SigAlgName
 		{
-            get { return SignerUtilities.GetEncodingName(c.SignatureAlgorithm.Algorithm); }
+            get { return sigAlgName; }
 		}
 
 		/// <summary>
@@ -267,12 +281,7 @@ namespace Org.BouncyCastle.X509
 		/// <returns>A byte array containing the Der encoded version of the parameters or null if there are none.</returns>
 		public virtual byte[] GetSigAlgParams()
 		{
-			if (c.SignatureAlgorithm.Parameters != null)
-			{
-				return c.SignatureAlgorithm.Parameters.GetDerEncoded();
-			}
-
-			return null;
+            return Arrays.Clone(sigAlgParams);
 		}
 
 		/// <summary>
diff --git a/crypto/src/x509/X509Crl.cs b/crypto/src/x509/X509Crl.cs
index 8903e69d0..7b841599f 100644
--- a/crypto/src/x509/X509Crl.cs
+++ b/crypto/src/x509/X509Crl.cs
@@ -48,16 +48,10 @@ namespace Org.BouncyCastle.X509
 			{
 				this.sigAlgName = X509SignatureUtilities.GetSignatureName(c.SignatureAlgorithm);
 
-				if (c.SignatureAlgorithm.Parameters != null)
-				{
-					this.sigAlgParams = ((Asn1Encodable)c.SignatureAlgorithm.Parameters).GetDerEncoded();
-				}
-				else
-				{
-					this.sigAlgParams = null;
-				}
+                Asn1Encodable parameters = c.SignatureAlgorithm.Parameters;
+                this.sigAlgParams = (null == parameters) ? null : parameters.GetEncoded(Asn1Encodable.Der);
 
-				this.isIndirect = IsIndirectCrl;
+                this.isIndirect = IsIndirectCrl;
 			}
 			catch (Exception e)
 			{
diff --git a/crypto/src/x509/X509SignatureUtil.cs b/crypto/src/x509/X509SignatureUtil.cs
index 83863aee1..6a6c0cf2d 100644
--- a/crypto/src/x509/X509SignatureUtil.cs
+++ b/crypto/src/x509/X509SignatureUtil.cs
@@ -9,6 +9,7 @@ using Org.BouncyCastle.Asn1.TeleTrust;
 using Org.BouncyCastle.Asn1.X509;
 using Org.BouncyCastle.Asn1.X9;
 using Org.BouncyCastle.Crypto;
+using Org.BouncyCastle.Security;
 
 namespace Org.BouncyCastle.X509
 {
@@ -69,6 +70,12 @@ namespace Org.BouncyCastle.X509
 				}
 			}
 
+            string sigName = SignerUtilities.GetEncodingName(sigAlgId.Algorithm);
+            if (null != sigName)
+            {
+                return sigName;
+            }
+
             return sigAlgId.Algorithm.Id;
 		}