LinkedCertificate.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
  5. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.BC
  6. {
  7. /**
  8. * Extension to tie an alternate certificate to the containing certificate.
  9. * <pre>
  10. * LinkedCertificate := SEQUENCE {
  11. * digest DigestInfo, -- digest of PQC certificate
  12. * certLocation GeneralName, -- location of PQC certificate
  13. * certIssuer [0] Name OPTIONAL, -- issuer of PQC cert (if different from current certificate)
  14. * cACerts [1] GeneralNames OPTIONAL, -- CA certificates for PQC cert (one of more locations)
  15. * }
  16. * </pre>
  17. */
  18. public class LinkedCertificate
  19. : Asn1Encodable
  20. {
  21. private readonly DigestInfo mDigest;
  22. private readonly GeneralName mCertLocation;
  23. private X509Name mCertIssuer;
  24. private GeneralNames mCACerts;
  25. public LinkedCertificate(DigestInfo digest, GeneralName certLocation)
  26. : this(digest, certLocation, null, null)
  27. {
  28. }
  29. public LinkedCertificate(DigestInfo digest, GeneralName certLocation, X509Name certIssuer, GeneralNames caCerts)
  30. {
  31. this.mDigest = digest;
  32. this.mCertLocation = certLocation;
  33. this.mCertIssuer = certIssuer;
  34. this.mCACerts = caCerts;
  35. }
  36. private LinkedCertificate(Asn1Sequence seq)
  37. {
  38. this.mDigest = DigestInfo.GetInstance(seq[0]);
  39. this.mCertLocation = GeneralName.GetInstance(seq[1]);
  40. for (int i = 2; i < seq.Count; ++i)
  41. {
  42. Asn1TaggedObject tagged = Asn1TaggedObject.GetInstance(seq[i]);
  43. switch (tagged.TagNo)
  44. {
  45. case 0:
  46. this.mCertIssuer = X509Name.GetInstance(tagged, false);
  47. break;
  48. case 1:
  49. this.mCACerts = GeneralNames.GetInstance(tagged, false);
  50. break;
  51. default:
  52. throw new ArgumentException("unknown tag in tagged field");
  53. }
  54. }
  55. }
  56. public static LinkedCertificate GetInstance(object obj)
  57. {
  58. if (obj is LinkedCertificate)
  59. return (LinkedCertificate)obj;
  60. if (obj != null)
  61. return new LinkedCertificate(Asn1Sequence.GetInstance(obj));
  62. return null;
  63. }
  64. public virtual DigestInfo Digest
  65. {
  66. get { return mDigest; }
  67. }
  68. public virtual GeneralName CertLocation
  69. {
  70. get { return mCertLocation; }
  71. }
  72. public virtual X509Name CertIssuer
  73. {
  74. get { return mCertIssuer; }
  75. }
  76. public virtual GeneralNames CACerts
  77. {
  78. get { return mCACerts; }
  79. }
  80. public override Asn1Object ToAsn1Object()
  81. {
  82. Asn1EncodableVector v = new Asn1EncodableVector(mDigest, mCertLocation);
  83. v.AddOptionalTagged(false, 0, mCertIssuer);
  84. v.AddOptionalTagged(false, 1, mCACerts);
  85. return new DerSequence(v);
  86. }
  87. }
  88. }
  89. #pragma warning restore
  90. #endif