IssuingDistributionPoint.cs 6.7 KB

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