PKIBody.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Crmf;
  5. using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Pkcs;
  6. using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
  7. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cmp
  8. {
  9. public class PkiBody
  10. : Asn1Encodable, IAsn1Choice
  11. {
  12. public const int TYPE_INIT_REQ = 0;
  13. public const int TYPE_INIT_REP = 1;
  14. public const int TYPE_CERT_REQ = 2;
  15. public const int TYPE_CERT_REP = 3;
  16. public const int TYPE_P10_CERT_REQ = 4;
  17. public const int TYPE_POPO_CHALL = 5;
  18. public const int TYPE_POPO_REP = 6;
  19. public const int TYPE_KEY_UPDATE_REQ = 7;
  20. public const int TYPE_KEY_UPDATE_REP = 8;
  21. public const int TYPE_KEY_RECOVERY_REQ = 9;
  22. public const int TYPE_KEY_RECOVERY_REP = 10;
  23. public const int TYPE_REVOCATION_REQ = 11;
  24. public const int TYPE_REVOCATION_REP = 12;
  25. public const int TYPE_CROSS_CERT_REQ = 13;
  26. public const int TYPE_CROSS_CERT_REP = 14;
  27. public const int TYPE_CA_KEY_UPDATE_ANN = 15;
  28. public const int TYPE_CERT_ANN = 16;
  29. public const int TYPE_REVOCATION_ANN = 17;
  30. public const int TYPE_CRL_ANN = 18;
  31. public const int TYPE_CONFIRM = 19;
  32. public const int TYPE_NESTED = 20;
  33. public const int TYPE_GEN_MSG = 21;
  34. public const int TYPE_GEN_REP = 22;
  35. public const int TYPE_ERROR = 23;
  36. public const int TYPE_CERT_CONFIRM = 24;
  37. public const int TYPE_POLL_REQ = 25;
  38. public const int TYPE_POLL_REP = 26;
  39. private int tagNo;
  40. private Asn1Encodable body;
  41. public static PkiBody GetInstance(object obj)
  42. {
  43. if (obj is PkiBody)
  44. return (PkiBody)obj;
  45. if (obj is Asn1TaggedObject)
  46. return new PkiBody((Asn1TaggedObject)obj);
  47. throw new ArgumentException("Invalid object: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
  48. }
  49. private PkiBody(Asn1TaggedObject tagged)
  50. {
  51. tagNo = tagged.TagNo;
  52. body = GetBodyForType(tagNo, tagged.GetObject());
  53. }
  54. /**
  55. * Creates a new PkiBody.
  56. * @param type one of the TYPE_* constants
  57. * @param content message content
  58. */
  59. public PkiBody(
  60. int type,
  61. Asn1Encodable content)
  62. {
  63. tagNo = type;
  64. body = GetBodyForType(type, content);
  65. }
  66. private static Asn1Encodable GetBodyForType(
  67. int type,
  68. Asn1Encodable o)
  69. {
  70. switch (type)
  71. {
  72. case TYPE_INIT_REQ:
  73. return CertReqMessages.GetInstance(o);
  74. case TYPE_INIT_REP:
  75. return CertRepMessage.GetInstance(o);
  76. case TYPE_CERT_REQ:
  77. return CertReqMessages.GetInstance(o);
  78. case TYPE_CERT_REP:
  79. return CertRepMessage.GetInstance(o);
  80. case TYPE_P10_CERT_REQ:
  81. return CertificationRequest.GetInstance(o);
  82. case TYPE_POPO_CHALL:
  83. return PopoDecKeyChallContent.GetInstance(o);
  84. case TYPE_POPO_REP:
  85. return PopoDecKeyRespContent.GetInstance(o);
  86. case TYPE_KEY_UPDATE_REQ:
  87. return CertReqMessages.GetInstance(o);
  88. case TYPE_KEY_UPDATE_REP:
  89. return CertRepMessage.GetInstance(o);
  90. case TYPE_KEY_RECOVERY_REQ:
  91. return CertReqMessages.GetInstance(o);
  92. case TYPE_KEY_RECOVERY_REP:
  93. return KeyRecRepContent.GetInstance(o);
  94. case TYPE_REVOCATION_REQ:
  95. return RevReqContent.GetInstance(o);
  96. case TYPE_REVOCATION_REP:
  97. return RevRepContent.GetInstance(o);
  98. case TYPE_CROSS_CERT_REQ:
  99. return CertReqMessages.GetInstance(o);
  100. case TYPE_CROSS_CERT_REP:
  101. return CertRepMessage.GetInstance(o);
  102. case TYPE_CA_KEY_UPDATE_ANN:
  103. return CAKeyUpdAnnContent.GetInstance(o);
  104. case TYPE_CERT_ANN:
  105. return CmpCertificate.GetInstance(o);
  106. case TYPE_REVOCATION_ANN:
  107. return RevAnnContent.GetInstance(o);
  108. case TYPE_CRL_ANN:
  109. return CrlAnnContent.GetInstance(o);
  110. case TYPE_CONFIRM:
  111. return PkiConfirmContent.GetInstance(o);
  112. case TYPE_NESTED:
  113. return PkiMessages.GetInstance(o);
  114. case TYPE_GEN_MSG:
  115. return GenMsgContent.GetInstance(o);
  116. case TYPE_GEN_REP:
  117. return GenRepContent.GetInstance(o);
  118. case TYPE_ERROR:
  119. return ErrorMsgContent.GetInstance(o);
  120. case TYPE_CERT_CONFIRM:
  121. return CertConfirmContent.GetInstance(o);
  122. case TYPE_POLL_REQ:
  123. return PollReqContent.GetInstance(o);
  124. case TYPE_POLL_REP:
  125. return PollRepContent.GetInstance(o);
  126. default:
  127. throw new ArgumentException("unknown tag number: " + type, "type");
  128. }
  129. }
  130. public virtual int Type
  131. {
  132. get { return tagNo; }
  133. }
  134. public virtual Asn1Encodable Content
  135. {
  136. get { return body; }
  137. }
  138. /**
  139. * <pre>
  140. * PkiBody ::= CHOICE { -- message-specific body elements
  141. * ir [0] CertReqMessages, --Initialization Request
  142. * ip [1] CertRepMessage, --Initialization Response
  143. * cr [2] CertReqMessages, --Certification Request
  144. * cp [3] CertRepMessage, --Certification Response
  145. * p10cr [4] CertificationRequest, --imported from [PKCS10]
  146. * popdecc [5] POPODecKeyChallContent, --pop Challenge
  147. * popdecr [6] POPODecKeyRespContent, --pop Response
  148. * kur [7] CertReqMessages, --Key Update Request
  149. * kup [8] CertRepMessage, --Key Update Response
  150. * krr [9] CertReqMessages, --Key Recovery Request
  151. * krp [10] KeyRecRepContent, --Key Recovery Response
  152. * rr [11] RevReqContent, --Revocation Request
  153. * rp [12] RevRepContent, --Revocation Response
  154. * ccr [13] CertReqMessages, --Cross-Cert. Request
  155. * ccp [14] CertRepMessage, --Cross-Cert. Response
  156. * ckuann [15] CAKeyUpdAnnContent, --CA Key Update Ann.
  157. * cann [16] CertAnnContent, --Certificate Ann.
  158. * rann [17] RevAnnContent, --Revocation Ann.
  159. * crlann [18] CRLAnnContent, --CRL Announcement
  160. * pkiconf [19] PKIConfirmContent, --Confirmation
  161. * nested [20] NestedMessageContent, --Nested Message
  162. * genm [21] GenMsgContent, --General Message
  163. * genp [22] GenRepContent, --General Response
  164. * error [23] ErrorMsgContent, --Error Message
  165. * certConf [24] CertConfirmContent, --Certificate confirm
  166. * pollReq [25] PollReqContent, --Polling request
  167. * pollRep [26] PollRepContent --Polling response
  168. * }
  169. * </pre>
  170. * @return a basic ASN.1 object representation.
  171. */
  172. public override Asn1Object ToAsn1Object()
  173. {
  174. return new DerTaggedObject(true, tagNo, body);
  175. }
  176. }
  177. }
  178. #pragma warning restore
  179. #endif