123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
- #pragma warning disable
- using System;
- using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
- using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
- using BestHTTP.SecureProtocol.Org.BouncyCastle.Security.Certificates;
- using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
- namespace BestHTTP.SecureProtocol.Org.BouncyCastle.X509
- {
- /// <remarks>
- /// This class contains a cross certificate pair. Cross certificates pairs may
- /// contain two cross signed certificates from two CAs. A certificate from the
- /// other CA to this CA is contained in the forward certificate, the certificate
- /// from this CA to the other CA is contained in the reverse certificate.
- /// </remarks>
- public class X509CertificatePair
- {
- private readonly X509Certificate forward;
- private readonly X509Certificate reverse;
- /// <summary>Constructor</summary>
- /// <param name="forward">Certificate from the other CA to this CA.</param>
- /// <param name="reverse">Certificate from this CA to the other CA.</param>
- public X509CertificatePair(
- X509Certificate forward,
- X509Certificate reverse)
- {
- this.forward = forward;
- this.reverse = reverse;
- }
- /// <summary>Constructor from a ASN.1 CertificatePair structure.</summary>
- /// <param name="pair">The <c>CertificatePair</c> ASN.1 object.</param>
- public X509CertificatePair(
- CertificatePair pair)
- {
- if (pair.Forward != null)
- {
- this.forward = new X509Certificate(pair.Forward);
- }
- if (pair.Reverse != null)
- {
- this.reverse = new X509Certificate(pair.Reverse);
- }
- }
- public byte[] GetEncoded()
- {
- try
- {
- X509CertificateStructure f = null, r = null;
- if (forward != null)
- {
- f = X509CertificateStructure.GetInstance(
- Asn1Object.FromByteArray(forward.GetEncoded()));
- if (f == null)
- throw new CertificateEncodingException("unable to get encoding for forward");
- }
- if (reverse != null)
- {
- r = X509CertificateStructure.GetInstance(
- Asn1Object.FromByteArray(reverse.GetEncoded()));
- if (r == null)
- throw new CertificateEncodingException("unable to get encoding for reverse");
- }
- return new CertificatePair(f, r).GetDerEncoded();
- }
- catch (Exception e)
- {
- // TODO
- // throw new ExtCertificateEncodingException(e.toString(), e);
- throw new CertificateEncodingException(e.Message, e);
- }
- }
- /// <summary>Returns the certificate from the other CA to this CA.</summary>
- public X509Certificate Forward
- {
- get { return forward; }
- }
- /// <summary>Returns the certificate from this CA to the other CA.</summary>
- public X509Certificate Reverse
- {
- get { return reverse; }
- }
- public override bool Equals(
- object obj)
- {
- if (obj == this)
- return true;
- X509CertificatePair other = obj as X509CertificatePair;
- if (other == null)
- return false;
- return BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.Equals(this.forward, other.forward)
- && BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.Equals(this.reverse, other.reverse);
- }
- public override int GetHashCode()
- {
- int hash = -1;
- if (forward != null)
- {
- hash ^= forward.GetHashCode();
- }
- if (reverse != null)
- {
- hash *= 17;
- hash ^= reverse.GetHashCode();
- }
- return hash;
- }
- }
- }
- #pragma warning restore
- #endif
|