You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
2.0 KiB
74 lines
2.0 KiB
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR) |
|
#pragma warning disable |
|
using System; |
|
using System.IO; |
|
|
|
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1; |
|
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509; |
|
using BestHTTP.SecureProtocol.Org.BouncyCastle.Security.Certificates; |
|
|
|
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.X509 |
|
{ |
|
/// <remarks> |
|
/// A utility class that will extract X509Principal objects from X.509 certificates. |
|
/// <p> |
|
/// Use this in preference to trying to recreate a principal from a string, not all |
|
/// DNs are what they should be, so it's best to leave them encoded where they |
|
/// can be.</p> |
|
/// </remarks> |
|
public class PrincipalUtilities |
|
{ |
|
/// <summary>Return the issuer of the given cert as an X509Principal.</summary> |
|
public static X509Name GetIssuerX509Principal( |
|
X509Certificate cert) |
|
{ |
|
try |
|
{ |
|
TbsCertificateStructure tbsCert = TbsCertificateStructure.GetInstance( |
|
Asn1Object.FromByteArray(cert.GetTbsCertificate())); |
|
|
|
return tbsCert.Issuer; |
|
} |
|
catch (Exception e) |
|
{ |
|
throw new CertificateEncodingException("Could not extract issuer", e); |
|
} |
|
} |
|
|
|
/// <summary>Return the subject of the given cert as an X509Principal.</summary> |
|
public static X509Name GetSubjectX509Principal( |
|
X509Certificate cert) |
|
{ |
|
try |
|
{ |
|
TbsCertificateStructure tbsCert = TbsCertificateStructure.GetInstance( |
|
Asn1Object.FromByteArray(cert.GetTbsCertificate())); |
|
|
|
return tbsCert.Subject; |
|
} |
|
catch (Exception e) |
|
{ |
|
throw new CertificateEncodingException("Could not extract subject", e); |
|
} |
|
} |
|
|
|
/// <summary>Return the issuer of the given CRL as an X509Principal.</summary> |
|
public static X509Name GetIssuerX509Principal( |
|
X509Crl crl) |
|
{ |
|
try |
|
{ |
|
TbsCertificateList tbsCertList = TbsCertificateList.GetInstance( |
|
Asn1Object.FromByteArray(crl.GetTbsCertList())); |
|
|
|
return tbsCertList.Issuer; |
|
} |
|
catch (Exception e) |
|
{ |
|
throw new CrlException("Could not extract issuer", e); |
|
} |
|
} |
|
} |
|
} |
|
#pragma warning restore |
|
#endif
|
|
|