summary refs log tree commit diff
path: root/crypto/src
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2022-06-27 22:02:57 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2022-06-27 22:02:57 +0700
commit7937784671130cb17e58066ab743d6b46931c475 (patch)
tree8143df7b0da7a4ef6c00ef1db04b84fbd14189ec /crypto/src
parentGenerics migration in Asn1 (diff)
downloadBouncyCastle.NET-ed25519-7937784671130cb17e58066ab743d6b46931c475.tar.xz
Update alternative names from bc-java
Diffstat (limited to 'crypto/src')
-rw-r--r--crypto/src/pkix/PkixCertPathValidatorUtilities.cs8
-rw-r--r--crypto/src/x509/X509Certificate.cs48
2 files changed, 41 insertions, 15 deletions
diff --git a/crypto/src/pkix/PkixCertPathValidatorUtilities.cs b/crypto/src/pkix/PkixCertPathValidatorUtilities.cs
index a1e37f09d..80ae2f83d 100644
--- a/crypto/src/pkix/PkixCertPathValidatorUtilities.cs
+++ b/crypto/src/pkix/PkixCertPathValidatorUtilities.cs
@@ -1,5 +1,4 @@
 using System;
-using System.Collections;
 using System.Collections.Generic;
 using System.IO;
 
@@ -160,7 +159,7 @@ namespace Org.BouncyCastle.Pkix
 			var issuerAltNames = cert.GetIssuerAlternativeNames();
 			if (issuerAltNames != null)
 			{
-				foreach (IList list in issuerAltNames)
+				foreach (var list in issuerAltNames)
 				{
 					// look for URI
 					if (list.Count >= 2 && list[0].Equals(GeneralName.UniformResourceIdentifier))
@@ -721,10 +720,7 @@ namespace Org.BouncyCastle.Pkix
 				}
 
 				// add and check issuer principals
-				for (IEnumerator it = issuerPrincipals.GetEnumerator(); it.MoveNext(); )
-				{
-					issuers.Add((X509Name)it.Current);
-				}
+				issuers.AddRange(issuerPrincipals);
 			}
 			// TODO: is not found although this should correctly add the rel name. selector of Sun is buggy here or PKI test case is invalid
 			// distributionPoint
diff --git a/crypto/src/x509/X509Certificate.cs b/crypto/src/x509/X509Certificate.cs
index 2fbad4ba5..098a2b95a 100644
--- a/crypto/src/x509/X509Certificate.cs
+++ b/crypto/src/x509/X509Certificate.cs
@@ -1,7 +1,7 @@
 using System;
-using System.Collections;
 using System.Collections.Generic;
 using System.IO;
+using System.Net;
 using System.Text;
 
 using Org.BouncyCastle.Asn1;
@@ -379,17 +379,17 @@ namespace Org.BouncyCastle.X509
             return -1;
         }
 
-        public virtual ICollection GetSubjectAlternativeNames()
+        public virtual IList<IList<object>> GetSubjectAlternativeNames()
         {
             return GetAlternativeNames(X509Extensions.SubjectAlternativeName);
         }
 
-        public virtual ICollection GetIssuerAlternativeNames()
+        public virtual IList<IList<object>> GetIssuerAlternativeNames()
         {
             return GetAlternativeNames(X509Extensions.IssuerAlternativeName);
         }
 
-        protected virtual ICollection GetAlternativeNames(DerObjectIdentifier oid)
+        protected virtual IList<IList<object>> GetAlternativeNames(DerObjectIdentifier oid)
         {
             Asn1OctetString altNames = GetExtensionValue(oid);
             if (altNames == null)
@@ -397,14 +397,44 @@ namespace Org.BouncyCastle.X509
 
             Asn1Object asn1Object = X509ExtensionUtilities.FromExtensionValue(altNames);
 
-            GeneralNames gns = GeneralNames.GetInstance(asn1Object);
+            var generalNames = GeneralNames.GetInstance(asn1Object);
+            var gns = generalNames.GetNames();
 
-            IList result = Platform.CreateArrayList();
-            foreach (GeneralName gn in gns.GetNames())
+            var result = new List<IList<object>>(gns.Length);
+            foreach (GeneralName gn in gns)
             {
-                IList entry = Platform.CreateArrayList();
+                var entry = new List<object>(2);
                 entry.Add(gn.TagNo);
-                entry.Add(gn.Name.ToString());
+
+                switch (gn.TagNo)
+                {
+                case GeneralName.EdiPartyName:
+                case GeneralName.X400Address:
+                case GeneralName.OtherName:
+                    entry.Add(gn.GetEncoded());
+                    break;
+                case GeneralName.DirectoryName:
+                    // TODO Styles
+                    //entry.Add(X509Name.GetInstance(Rfc4519Style.Instance, gn.Name).ToString());
+                    entry.Add(X509Name.GetInstance(gn.Name).ToString());
+                    break;
+                case GeneralName.DnsName:
+                case GeneralName.Rfc822Name:
+                case GeneralName.UniformResourceIdentifier:
+                    entry.Add(((IAsn1String)gn.Name).GetString());
+                    break;
+                case GeneralName.RegisteredID:
+                    entry.Add(DerObjectIdentifier.GetInstance(gn.Name).Id);
+                    break;
+                case GeneralName.IPAddress:
+                    byte[] addrBytes = Asn1OctetString.GetInstance(gn.Name).GetOctets();
+                    IPAddress ipAddress = new IPAddress(addrBytes);
+                    entry.Add(ipAddress.ToString());
+                    break;
+                default:
+                    throw new IOException("Bad tag number: " + gn.TagNo);
+                }
+
                 result.Add(entry);
             }
             return result;