summary refs log tree commit diff
path: root/crypto
diff options
context:
space:
mode:
Diffstat (limited to 'crypto')
-rw-r--r--crypto/src/pkix/PkixCertPathValidatorUtilities.cs18
-rw-r--r--crypto/src/x509/extension/X509ExtensionUtil.cs85
2 files changed, 13 insertions, 90 deletions
diff --git a/crypto/src/pkix/PkixCertPathValidatorUtilities.cs b/crypto/src/pkix/PkixCertPathValidatorUtilities.cs
index fccd0b3c5..2514f1df2 100644
--- a/crypto/src/pkix/PkixCertPathValidatorUtilities.cs
+++ b/crypto/src/pkix/PkixCertPathValidatorUtilities.cs
@@ -1042,23 +1042,9 @@ namespace Org.BouncyCastle.Pkix
 			return certs;
 		}
 
-		/// <summary>
-		/// Extract the value of the given extension, if it exists.
-		/// </summary>
-		/// <param name="ext">The extension object.</param>
-		/// <param name="oid">The object identifier to obtain.</param>
-		/// <returns>Asn1Object</returns>
-		/// <exception cref="Exception">if the extension cannot be read.</exception>
-		internal static Asn1Object GetExtensionValue(
-			IX509Extension		ext,
-			DerObjectIdentifier	oid)
+		internal static Asn1Object GetExtensionValue(IX509Extension extensions, DerObjectIdentifier oid)
 		{
-			Asn1OctetString bytes = ext.GetExtensionValue(oid);
-
-			if (bytes == null)
-				return null;
-
-			return X509ExtensionUtilities.FromExtensionValue(bytes);
+			return X509ExtensionUtilities.FromExtensionValue(extensions, oid);
 		}
 	}
 }
diff --git a/crypto/src/x509/extension/X509ExtensionUtil.cs b/crypto/src/x509/extension/X509ExtensionUtil.cs
index b751658e1..e1f925b08 100644
--- a/crypto/src/x509/extension/X509ExtensionUtil.cs
+++ b/crypto/src/x509/extension/X509ExtensionUtil.cs
@@ -1,88 +1,25 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
-
 using Org.BouncyCastle.Asn1;
-using Org.BouncyCastle.Asn1.X509;
-using Org.BouncyCastle.Security.Certificates;
 
 namespace Org.BouncyCastle.X509.Extension
 {
 	public class X509ExtensionUtilities
 	{
-		public static Asn1Object FromExtensionValue(
-			Asn1OctetString extensionValue)
+		public static Asn1Object FromExtensionValue(Asn1OctetString extensionValue)
 		{
 			return Asn1Object.FromByteArray(extensionValue.GetOctets());
 		}
 
-		public static IList<IList<object>> GetIssuerAlternativeNames(X509Certificate cert)
-		{
-			Asn1OctetString extVal = cert.GetExtensionValue(X509Extensions.IssuerAlternativeName);
-
-			return GetAlternativeName(extVal);
-		}
-
-		public static IList<IList<object>> GetSubjectAlternativeNames(X509Certificate cert)
+		/// <summary>
+		/// Extract the value of the given extension, if it exists.
+		/// </summary>
+		/// <param name="extensions">The extensions object.</param>
+		/// <param name="oid">The object identifier to obtain.</param>
+		/// <returns>Asn1Object</returns>
+		/// <exception cref="Exception">if the extension cannot be read.</exception>
+		public static Asn1Object FromExtensionValue(IX509Extension extensions, DerObjectIdentifier oid)
 		{
-			Asn1OctetString extVal = cert.GetExtensionValue(X509Extensions.SubjectAlternativeName);
-
-			return GetAlternativeName(extVal);
-		}
-
-		private static IList<IList<object>> GetAlternativeName(
-			Asn1OctetString extVal)
-		{
-			var result = new List<IList<object>>();
-
-			if (extVal != null)
-			{
-				try
-				{
-					Asn1Sequence seq = Asn1Sequence.GetInstance(FromExtensionValue(extVal));
-
-					foreach (Asn1Encodable primName in seq)
-					{
-						GeneralName genName = GeneralName.GetInstance(primName);
-
-						var list = new List<object>(2);
-						list.Add(genName.TagNo);
-
-						switch (genName.TagNo)
-						{
-						case GeneralName.EdiPartyName:
-						case GeneralName.X400Address:
-						case GeneralName.OtherName:
-							list.Add(genName.Name.ToAsn1Object());
-							break;
-						case GeneralName.DirectoryName:
-							list.Add(X509Name.GetInstance(genName.Name).ToString());
-							break;
-						case GeneralName.DnsName:
-						case GeneralName.Rfc822Name:
-						case GeneralName.UniformResourceIdentifier:
-							list.Add(((IAsn1String)genName.Name).GetString());
-							break;
-						case GeneralName.RegisteredID:
-							list.Add(DerObjectIdentifier.GetInstance(genName.Name).Id);
-							break;
-						case GeneralName.IPAddress:
-							list.Add(Asn1OctetString.GetInstance(genName.Name).GetOctets());
-							break;
-						default:
-							throw new IOException("Bad tag number: " + genName.TagNo);
-						}
-
-						result.Add(list);
-					}
-				}
-				catch (Exception e)
-				{
-					throw new CertificateParsingException(e.Message);
-				}
-			}
-
-			return result;
+			Asn1OctetString extensionValue = extensions.GetExtensionValue(oid);
+			return extensionValue == null ? null : FromExtensionValue(extensionValue);	
 		}
 	}
 }