diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-06-27 22:02:57 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-06-27 22:02:57 +0700 |
commit | 7937784671130cb17e58066ab743d6b46931c475 (patch) | |
tree | 8143df7b0da7a4ef6c00ef1db04b84fbd14189ec /crypto/src/x509/X509Certificate.cs | |
parent | Generics migration in Asn1 (diff) | |
download | BouncyCastle.NET-ed25519-7937784671130cb17e58066ab743d6b46931c475.tar.xz |
Update alternative names from bc-java
Diffstat (limited to 'crypto/src/x509/X509Certificate.cs')
-rw-r--r-- | crypto/src/x509/X509Certificate.cs | 48 |
1 files changed, 39 insertions, 9 deletions
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; |