IssuingDistributionPoint.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using System.Text;
  5. using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
  6. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509
  7. {
  8. /**
  9. * <pre>
  10. * IssuingDistributionPoint ::= SEQUENCE {
  11. * distributionPoint [0] DistributionPointName OPTIONAL,
  12. * onlyContainsUserCerts [1] BOOLEAN DEFAULT FALSE,
  13. * onlyContainsCACerts [2] BOOLEAN DEFAULT FALSE,
  14. * onlySomeReasons [3] ReasonFlags OPTIONAL,
  15. * indirectCRL [4] BOOLEAN DEFAULT FALSE,
  16. * onlyContainsAttributeCerts [5] BOOLEAN DEFAULT FALSE }
  17. * </pre>
  18. */
  19. public class IssuingDistributionPoint
  20. : Asn1Encodable
  21. {
  22. private readonly DistributionPointName _distributionPoint;
  23. private readonly bool _onlyContainsUserCerts;
  24. private readonly bool _onlyContainsCACerts;
  25. private readonly ReasonFlags _onlySomeReasons;
  26. private readonly bool _indirectCRL;
  27. private readonly bool _onlyContainsAttributeCerts;
  28. private readonly Asn1Sequence seq;
  29. public static IssuingDistributionPoint GetInstance(
  30. Asn1TaggedObject obj,
  31. bool explicitly)
  32. {
  33. return GetInstance(Asn1Sequence.GetInstance(obj, explicitly));
  34. }
  35. public static IssuingDistributionPoint GetInstance(
  36. object obj)
  37. {
  38. if (obj == null || obj is IssuingDistributionPoint)
  39. {
  40. return (IssuingDistributionPoint) obj;
  41. }
  42. if (obj is Asn1Sequence)
  43. {
  44. return new IssuingDistributionPoint((Asn1Sequence) obj);
  45. }
  46. throw new ArgumentException("unknown object in factory: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
  47. }
  48. /**
  49. * Constructor from given details.
  50. *
  51. * @param distributionPoint
  52. * May contain an URI as pointer to most current CRL.
  53. * @param onlyContainsUserCerts Covers revocation information for end certificates.
  54. * @param onlyContainsCACerts Covers revocation information for CA certificates.
  55. *
  56. * @param onlySomeReasons
  57. * Which revocation reasons does this point cover.
  58. * @param indirectCRL
  59. * If <code>true</code> then the CRL contains revocation
  60. * information about certificates ssued by other CAs.
  61. * @param onlyContainsAttributeCerts Covers revocation information for attribute certificates.
  62. */
  63. public IssuingDistributionPoint(
  64. DistributionPointName distributionPoint,
  65. bool onlyContainsUserCerts,
  66. bool onlyContainsCACerts,
  67. ReasonFlags onlySomeReasons,
  68. bool indirectCRL,
  69. bool onlyContainsAttributeCerts)
  70. {
  71. this._distributionPoint = distributionPoint;
  72. this._indirectCRL = indirectCRL;
  73. this._onlyContainsAttributeCerts = onlyContainsAttributeCerts;
  74. this._onlyContainsCACerts = onlyContainsCACerts;
  75. this._onlyContainsUserCerts = onlyContainsUserCerts;
  76. this._onlySomeReasons = onlySomeReasons;
  77. Asn1EncodableVector vec = new Asn1EncodableVector();
  78. if (distributionPoint != null)
  79. { // CHOICE item so explicitly tagged
  80. vec.Add(new DerTaggedObject(true, 0, distributionPoint));
  81. }
  82. if (onlyContainsUserCerts)
  83. {
  84. vec.Add(new DerTaggedObject(false, 1, DerBoolean.True));
  85. }
  86. if (onlyContainsCACerts)
  87. {
  88. vec.Add(new DerTaggedObject(false, 2, DerBoolean.True));
  89. }
  90. if (onlySomeReasons != null)
  91. {
  92. vec.Add(new DerTaggedObject(false, 3, onlySomeReasons));
  93. }
  94. if (indirectCRL)
  95. {
  96. vec.Add(new DerTaggedObject(false, 4, DerBoolean.True));
  97. }
  98. if (onlyContainsAttributeCerts)
  99. {
  100. vec.Add(new DerTaggedObject(false, 5, DerBoolean.True));
  101. }
  102. seq = new DerSequence(vec);
  103. }
  104. /**
  105. * Constructor from Asn1Sequence
  106. */
  107. private IssuingDistributionPoint(
  108. Asn1Sequence seq)
  109. {
  110. this.seq = seq;
  111. for (int i = 0; i != seq.Count; i++)
  112. {
  113. Asn1TaggedObject o = Asn1TaggedObject.GetInstance(seq[i]);
  114. switch (o.TagNo)
  115. {
  116. case 0:
  117. // CHOICE so explicit
  118. _distributionPoint = DistributionPointName.GetInstance(o, true);
  119. break;
  120. case 1:
  121. _onlyContainsUserCerts = DerBoolean.GetInstance(o, false).IsTrue;
  122. break;
  123. case 2:
  124. _onlyContainsCACerts = DerBoolean.GetInstance(o, false).IsTrue;
  125. break;
  126. case 3:
  127. _onlySomeReasons = new ReasonFlags(ReasonFlags.GetInstance(o, false));
  128. break;
  129. case 4:
  130. _indirectCRL = DerBoolean.GetInstance(o, false).IsTrue;
  131. break;
  132. case 5:
  133. _onlyContainsAttributeCerts = DerBoolean.GetInstance(o, false).IsTrue;
  134. break;
  135. default:
  136. throw new ArgumentException("unknown tag in IssuingDistributionPoint");
  137. }
  138. }
  139. }
  140. public bool OnlyContainsUserCerts
  141. {
  142. get { return _onlyContainsUserCerts; }
  143. }
  144. public bool OnlyContainsCACerts
  145. {
  146. get { return _onlyContainsCACerts; }
  147. }
  148. public bool IsIndirectCrl
  149. {
  150. get { return _indirectCRL; }
  151. }
  152. public bool OnlyContainsAttributeCerts
  153. {
  154. get { return _onlyContainsAttributeCerts; }
  155. }
  156. /**
  157. * @return Returns the distributionPoint.
  158. */
  159. public DistributionPointName DistributionPoint
  160. {
  161. get { return _distributionPoint; }
  162. }
  163. /**
  164. * @return Returns the onlySomeReasons.
  165. */
  166. public ReasonFlags OnlySomeReasons
  167. {
  168. get { return _onlySomeReasons; }
  169. }
  170. public override Asn1Object ToAsn1Object()
  171. {
  172. return seq;
  173. }
  174. public override string ToString()
  175. {
  176. string sep = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.NewLine;
  177. StringBuilder buf = new StringBuilder();
  178. buf.Append("IssuingDistributionPoint: [");
  179. buf.Append(sep);
  180. if (_distributionPoint != null)
  181. {
  182. appendObject(buf, sep, "distributionPoint", _distributionPoint.ToString());
  183. }
  184. if (_onlyContainsUserCerts)
  185. {
  186. appendObject(buf, sep, "onlyContainsUserCerts", _onlyContainsUserCerts.ToString());
  187. }
  188. if (_onlyContainsCACerts)
  189. {
  190. appendObject(buf, sep, "onlyContainsCACerts", _onlyContainsCACerts.ToString());
  191. }
  192. if (_onlySomeReasons != null)
  193. {
  194. appendObject(buf, sep, "onlySomeReasons", _onlySomeReasons.ToString());
  195. }
  196. if (_onlyContainsAttributeCerts)
  197. {
  198. appendObject(buf, sep, "onlyContainsAttributeCerts", _onlyContainsAttributeCerts.ToString());
  199. }
  200. if (_indirectCRL)
  201. {
  202. appendObject(buf, sep, "indirectCRL", _indirectCRL.ToString());
  203. }
  204. buf.Append("]");
  205. buf.Append(sep);
  206. return buf.ToString();
  207. }
  208. private void appendObject(
  209. StringBuilder buf,
  210. string sep,
  211. string name,
  212. string val)
  213. {
  214. string indent = " ";
  215. buf.Append(indent);
  216. buf.Append(name);
  217. buf.Append(":");
  218. buf.Append(sep);
  219. buf.Append(indent);
  220. buf.Append(indent);
  221. buf.Append(val);
  222. buf.Append(sep);
  223. }
  224. }
  225. }
  226. #pragma warning restore
  227. #endif