PKIStatusInfo.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using BestHTTP.SecureProtocol.Org.BouncyCastle.Math;
  5. using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
  6. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cmp
  7. {
  8. public class PkiStatusInfo
  9. : Asn1Encodable
  10. {
  11. DerInteger status;
  12. PkiFreeText statusString;
  13. DerBitString failInfo;
  14. public static PkiStatusInfo GetInstance(
  15. Asn1TaggedObject obj,
  16. bool isExplicit)
  17. {
  18. return GetInstance(Asn1Sequence.GetInstance(obj, isExplicit));
  19. }
  20. public static PkiStatusInfo GetInstance(
  21. object obj)
  22. {
  23. if (obj is PkiStatusInfo)
  24. {
  25. return (PkiStatusInfo)obj;
  26. }
  27. else if (obj is Asn1Sequence)
  28. {
  29. return new PkiStatusInfo((Asn1Sequence)obj);
  30. }
  31. throw new ArgumentException("Unknown object in factory: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
  32. }
  33. public PkiStatusInfo(
  34. Asn1Sequence seq)
  35. {
  36. this.status = DerInteger.GetInstance(seq[0]);
  37. this.statusString = null;
  38. this.failInfo = null;
  39. if (seq.Count > 2)
  40. {
  41. this.statusString = PkiFreeText.GetInstance(seq[1]);
  42. this.failInfo = DerBitString.GetInstance(seq[2]);
  43. }
  44. else if (seq.Count > 1)
  45. {
  46. object obj = seq[1];
  47. if (obj is DerBitString)
  48. {
  49. this.failInfo = DerBitString.GetInstance(obj);
  50. }
  51. else
  52. {
  53. this.statusString = PkiFreeText.GetInstance(obj);
  54. }
  55. }
  56. }
  57. /**
  58. * @param status
  59. */
  60. public PkiStatusInfo(int status)
  61. {
  62. this.status = new DerInteger(status);
  63. }
  64. /**
  65. * @param status
  66. * @param statusString
  67. */
  68. public PkiStatusInfo(
  69. int status,
  70. PkiFreeText statusString)
  71. {
  72. this.status = new DerInteger(status);
  73. this.statusString = statusString;
  74. }
  75. public PkiStatusInfo(
  76. int status,
  77. PkiFreeText statusString,
  78. PkiFailureInfo failInfo)
  79. {
  80. this.status = new DerInteger(status);
  81. this.statusString = statusString;
  82. this.failInfo = failInfo;
  83. }
  84. public BigInteger Status
  85. {
  86. get
  87. {
  88. return status.Value;
  89. }
  90. }
  91. public PkiFreeText StatusString
  92. {
  93. get
  94. {
  95. return statusString;
  96. }
  97. }
  98. public DerBitString FailInfo
  99. {
  100. get
  101. {
  102. return failInfo;
  103. }
  104. }
  105. /**
  106. * <pre>
  107. * PkiStatusInfo ::= SEQUENCE {
  108. * status PKIStatus, (INTEGER)
  109. * statusString PkiFreeText OPTIONAL,
  110. * failInfo PkiFailureInfo OPTIONAL (BIT STRING)
  111. * }
  112. *
  113. * PKIStatus:
  114. * granted (0), -- you got exactly what you asked for
  115. * grantedWithMods (1), -- you got something like what you asked for
  116. * rejection (2), -- you don't get it, more information elsewhere in the message
  117. * waiting (3), -- the request body part has not yet been processed, expect to hear more later
  118. * revocationWarning (4), -- this message contains a warning that a revocation is imminent
  119. * revocationNotification (5), -- notification that a revocation has occurred
  120. * keyUpdateWarning (6) -- update already done for the oldCertId specified in CertReqMsg
  121. *
  122. * PkiFailureInfo:
  123. * badAlg (0), -- unrecognized or unsupported Algorithm Identifier
  124. * badMessageCheck (1), -- integrity check failed (e.g., signature did not verify)
  125. * badRequest (2), -- transaction not permitted or supported
  126. * badTime (3), -- messageTime was not sufficiently close to the system time, as defined by local policy
  127. * badCertId (4), -- no certificate could be found matching the provided criteria
  128. * badDataFormat (5), -- the data submitted has the wrong format
  129. * wrongAuthority (6), -- the authority indicated in the request is different from the one creating the response token
  130. * incorrectData (7), -- the requester's data is incorrect (for notary services)
  131. * missingTimeStamp (8), -- when the timestamp is missing but should be there (by policy)
  132. * badPOP (9) -- the proof-of-possession failed
  133. *
  134. * </pre>
  135. */
  136. public override Asn1Object ToAsn1Object()
  137. {
  138. Asn1EncodableVector v = new Asn1EncodableVector(status);
  139. v.AddOptional(statusString, failInfo);
  140. return new DerSequence(v);
  141. }
  142. }
  143. }
  144. #pragma warning restore
  145. #endif