X509CertificateStructure.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Pkcs;
  5. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509
  6. {
  7. /**
  8. * an X509Certificate structure.
  9. * <pre>
  10. * Certificate ::= Sequence {
  11. * tbsCertificate TbsCertificate,
  12. * signatureAlgorithm AlgorithmIdentifier,
  13. * signature BIT STRING
  14. * }
  15. * </pre>
  16. */
  17. public class X509CertificateStructure
  18. : Asn1Encodable
  19. {
  20. private readonly TbsCertificateStructure tbsCert;
  21. private readonly AlgorithmIdentifier sigAlgID;
  22. private readonly DerBitString sig;
  23. public static X509CertificateStructure GetInstance(
  24. Asn1TaggedObject obj,
  25. bool explicitly)
  26. {
  27. return GetInstance(Asn1Sequence.GetInstance(obj, explicitly));
  28. }
  29. public static X509CertificateStructure GetInstance(
  30. object obj)
  31. {
  32. if (obj is X509CertificateStructure)
  33. return (X509CertificateStructure)obj;
  34. if (obj == null)
  35. return null;
  36. return new X509CertificateStructure(Asn1Sequence.GetInstance(obj));
  37. }
  38. public X509CertificateStructure(
  39. TbsCertificateStructure tbsCert,
  40. AlgorithmIdentifier sigAlgID,
  41. DerBitString sig)
  42. {
  43. if (tbsCert == null)
  44. throw new ArgumentNullException("tbsCert");
  45. if (sigAlgID == null)
  46. throw new ArgumentNullException("sigAlgID");
  47. if (sig == null)
  48. throw new ArgumentNullException("sig");
  49. this.tbsCert = tbsCert;
  50. this.sigAlgID = sigAlgID;
  51. this.sig = sig;
  52. }
  53. private X509CertificateStructure(
  54. Asn1Sequence seq)
  55. {
  56. if (seq.Count != 3)
  57. throw new ArgumentException("sequence wrong size for a certificate", "seq");
  58. //
  59. // correct x509 certficate
  60. //
  61. tbsCert = TbsCertificateStructure.GetInstance(seq[0]);
  62. sigAlgID = AlgorithmIdentifier.GetInstance(seq[1]);
  63. sig = DerBitString.GetInstance(seq[2]);
  64. }
  65. public TbsCertificateStructure TbsCertificate
  66. {
  67. get { return tbsCert; }
  68. }
  69. public int Version
  70. {
  71. get { return tbsCert.Version; }
  72. }
  73. public DerInteger SerialNumber
  74. {
  75. get { return tbsCert.SerialNumber; }
  76. }
  77. public X509Name Issuer
  78. {
  79. get { return tbsCert.Issuer; }
  80. }
  81. public Time StartDate
  82. {
  83. get { return tbsCert.StartDate; }
  84. }
  85. public Time EndDate
  86. {
  87. get { return tbsCert.EndDate; }
  88. }
  89. public X509Name Subject
  90. {
  91. get { return tbsCert.Subject; }
  92. }
  93. public SubjectPublicKeyInfo SubjectPublicKeyInfo
  94. {
  95. get { return tbsCert.SubjectPublicKeyInfo; }
  96. }
  97. public AlgorithmIdentifier SignatureAlgorithm
  98. {
  99. get { return sigAlgID; }
  100. }
  101. public DerBitString Signature
  102. {
  103. get { return sig; }
  104. }
  105. public byte[] GetSignatureOctets()
  106. {
  107. return sig.GetOctets();
  108. }
  109. public override Asn1Object ToAsn1Object()
  110. {
  111. return new DerSequence(tbsCert, sigAlgID, sig);
  112. }
  113. }
  114. }
  115. #pragma warning restore
  116. #endif