summary refs log tree commit diff
path: root/crypto
diff options
context:
space:
mode:
Diffstat (limited to 'crypto')
-rw-r--r--crypto/src/x509/X509Certificate.cs23
-rw-r--r--crypto/test/src/test/CertTest.cs12
2 files changed, 30 insertions, 5 deletions
diff --git a/crypto/src/x509/X509Certificate.cs b/crypto/src/x509/X509Certificate.cs
index 098a2b95a..56d9e639f 100644
--- a/crypto/src/x509/X509Certificate.cs
+++ b/crypto/src/x509/X509Certificate.cs
@@ -379,9 +379,14 @@ namespace Org.BouncyCastle.X509
             return -1;
         }
 
-        public virtual IList<IList<object>> GetSubjectAlternativeNames()
+        public virtual GeneralNames GetIssuerAlternativeNameExtension()
         {
-            return GetAlternativeNames(X509Extensions.SubjectAlternativeName);
+            return GetAlternativeNameExtension(X509Extensions.IssuerAlternativeName);
+        }
+
+        public virtual GeneralNames GetSubjectAlternativeNameExtension()
+        {
+            return GetAlternativeNameExtension(X509Extensions.SubjectAlternativeName);
         }
 
         public virtual IList<IList<object>> GetIssuerAlternativeNames()
@@ -389,7 +394,12 @@ namespace Org.BouncyCastle.X509
             return GetAlternativeNames(X509Extensions.IssuerAlternativeName);
         }
 
-        protected virtual IList<IList<object>> GetAlternativeNames(DerObjectIdentifier oid)
+        public virtual IList<IList<object>> GetSubjectAlternativeNames()
+        {
+            return GetAlternativeNames(X509Extensions.SubjectAlternativeName);
+        }
+
+        protected virtual GeneralNames GetAlternativeNameExtension(DerObjectIdentifier oid)
         {
             Asn1OctetString altNames = GetExtensionValue(oid);
             if (altNames == null)
@@ -397,7 +407,12 @@ namespace Org.BouncyCastle.X509
 
             Asn1Object asn1Object = X509ExtensionUtilities.FromExtensionValue(altNames);
 
-            var generalNames = GeneralNames.GetInstance(asn1Object);
+            return GeneralNames.GetInstance(asn1Object);
+        }
+
+        protected virtual IList<IList<object>> GetAlternativeNames(DerObjectIdentifier oid)
+        {
+            var generalNames = GetAlternativeNameExtension(oid);
             var gns = generalNames.GetNames();
 
             var result = new List<IList<object>>(gns.Length);
diff --git a/crypto/test/src/test/CertTest.cs b/crypto/test/src/test/CertTest.cs
index 84b29ab89..7fb2c89c1 100644
--- a/crypto/test/src/test/CertTest.cs
+++ b/crypto/test/src/test/CertTest.cs
@@ -1221,9 +1221,19 @@ namespace Org.BouncyCastle.Tests
                 Fail("failed extended key usage test");
             }
 
+            foreach (var gn in cert.GetSubjectAlternativeNameExtension().GetNames())
+            {
+                if (gn.TagNo != GeneralName.Rfc822Name ||
+                    !((IAsn1String)gn.Name).GetString().Equals("test@test.test"))
+                {
+                    Fail("failed subject alternative name extension test");
+                }
+            }
+
             foreach (var gn in cert.GetSubjectAlternativeNames())
             {
-                if (!gn[1].Equals("test@test.test"))
+                if (!gn[0].Equals(GeneralName.Rfc822Name) ||
+                    !gn[1].Equals("test@test.test"))
                 {
                     Fail("failed subject alternative names test");
                 }