PkixParameters.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using System.Collections;
  5. using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
  6. using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Collections;
  7. using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Date;
  8. using BestHTTP.SecureProtocol.Org.BouncyCastle.X509.Store;
  9. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Pkix
  10. {
  11. /// <summary>
  12. /// Summary description for PkixParameters.
  13. /// </summary>
  14. public class PkixParameters
  15. // : ICertPathParameters
  16. {
  17. /**
  18. * This is the default PKIX validity model. Actually there are two variants
  19. * of this: The PKIX model and the modified PKIX model. The PKIX model
  20. * verifies that all involved certificates must have been valid at the
  21. * current time. The modified PKIX model verifies that all involved
  22. * certificates were valid at the signing time. Both are indirectly choosen
  23. * with the {@link PKIXParameters#setDate(java.util.Date)} method, so this
  24. * methods sets the Date when <em>all</em> certificates must have been
  25. * valid.
  26. */
  27. public const int PkixValidityModel = 0;
  28. /**
  29. * This model uses the following validity model. Each certificate must have
  30. * been valid at the moment where is was used. That means the end
  31. * certificate must have been valid at the time the signature was done. The
  32. * CA certificate which signed the end certificate must have been valid,
  33. * when the end certificate was signed. The CA (or Root CA) certificate must
  34. * have been valid, when the CA certificate was signed and so on. So the
  35. * {@link PKIXParameters#setDate(java.util.Date)} method sets the time, when
  36. * the <em>end certificate</em> must have been valid. <p/> It is used e.g.
  37. * in the German signature law.
  38. */
  39. public const int ChainValidityModel = 1;
  40. private ISet trustAnchors;
  41. private DateTimeObject date;
  42. private IList certPathCheckers;
  43. private bool revocationEnabled = true;
  44. private ISet initialPolicies;
  45. //private bool checkOnlyEECertificateCrl = false;
  46. private bool explicitPolicyRequired = false;
  47. private bool anyPolicyInhibited = false;
  48. private bool policyMappingInhibited = false;
  49. private bool policyQualifiersRejected = true;
  50. private IX509Selector certSelector;
  51. private IList stores;
  52. private IX509Selector selector;
  53. private bool additionalLocationsEnabled;
  54. private IList additionalStores;
  55. private ISet trustedACIssuers;
  56. private ISet necessaryACAttributes;
  57. private ISet prohibitedACAttributes;
  58. private ISet attrCertCheckers;
  59. private int validityModel = PkixValidityModel;
  60. private bool useDeltas = false;
  61. /**
  62. * Creates an instance of PKIXParameters with the specified Set of
  63. * most-trusted CAs. Each element of the set is a TrustAnchor.<br />
  64. * <br />
  65. * Note that the Set is copied to protect against subsequent modifications.
  66. *
  67. * @param trustAnchors
  68. * a Set of TrustAnchors
  69. *
  70. * @exception InvalidAlgorithmParameterException
  71. * if the specified Set is empty
  72. * <code>(trustAnchors.isEmpty() == true)</code>
  73. * @exception NullPointerException
  74. * if the specified Set is <code>null</code>
  75. * @exception ClassCastException
  76. * if any of the elements in the Set are not of type
  77. * <code>java.security.cert.TrustAnchor</code>
  78. */
  79. public PkixParameters(
  80. ISet trustAnchors)
  81. {
  82. SetTrustAnchors(trustAnchors);
  83. this.initialPolicies = new HashSet();
  84. this.certPathCheckers = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList();
  85. this.stores = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList();
  86. this.additionalStores = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList();
  87. this.trustedACIssuers = new HashSet();
  88. this.necessaryACAttributes = new HashSet();
  89. this.prohibitedACAttributes = new HashSet();
  90. this.attrCertCheckers = new HashSet();
  91. }
  92. // // TODO implement for other keystores (see Java build)?
  93. // /**
  94. // * Creates an instance of <code>PKIXParameters</code> that
  95. // * populates the set of most-trusted CAs from the trusted
  96. // * certificate entries contained in the specified <code>KeyStore</code>.
  97. // * Only keystore entries that contain trusted <code>X509Certificates</code>
  98. // * are considered; all other certificate types are ignored.
  99. // *
  100. // * @param keystore a <code>KeyStore</code> from which the set of
  101. // * most-trusted CAs will be populated
  102. // * @throws KeyStoreException if the keystore has not been initialized
  103. // * @throws InvalidAlgorithmParameterException if the keystore does
  104. // * not contain at least one trusted certificate entry
  105. // * @throws NullPointerException if the keystore is <code>null</code>
  106. // */
  107. // public PkixParameters(
  108. // Pkcs12Store keystore)
  109. //// throws KeyStoreException, InvalidAlgorithmParameterException
  110. // {
  111. // if (keystore == null)
  112. // throw new ArgumentNullException("keystore");
  113. // ISet trustAnchors = new HashSet();
  114. // foreach (string alias in keystore.Aliases)
  115. // {
  116. // if (keystore.IsCertificateEntry(alias))
  117. // {
  118. // X509CertificateEntry x509Entry = keystore.GetCertificate(alias);
  119. // trustAnchors.Add(new TrustAnchor(x509Entry.Certificate, null));
  120. // }
  121. // }
  122. // SetTrustAnchors(trustAnchors);
  123. //
  124. // this.initialPolicies = new HashSet();
  125. // this.certPathCheckers = new ArrayList();
  126. // this.stores = new ArrayList();
  127. // this.additionalStores = new ArrayList();
  128. // this.trustedACIssuers = new HashSet();
  129. // this.necessaryACAttributes = new HashSet();
  130. // this.prohibitedACAttributes = new HashSet();
  131. // this.attrCertCheckers = new HashSet();
  132. // }
  133. public virtual bool IsRevocationEnabled
  134. {
  135. get { return revocationEnabled; }
  136. set { revocationEnabled = value; }
  137. }
  138. public virtual bool IsExplicitPolicyRequired
  139. {
  140. get { return explicitPolicyRequired; }
  141. set { this.explicitPolicyRequired = value; }
  142. }
  143. public virtual bool IsAnyPolicyInhibited
  144. {
  145. get { return anyPolicyInhibited; }
  146. set { this.anyPolicyInhibited = value; }
  147. }
  148. public virtual bool IsPolicyMappingInhibited
  149. {
  150. get { return policyMappingInhibited; }
  151. set { this.policyMappingInhibited = value; }
  152. }
  153. public virtual bool IsPolicyQualifiersRejected
  154. {
  155. get { return policyQualifiersRejected; }
  156. set { this.policyQualifiersRejected = value; }
  157. }
  158. //public bool IsCheckOnlyEECertificateCrl
  159. //{
  160. // get { return this.checkOnlyEECertificateCrl; }
  161. // set { this.checkOnlyEECertificateCrl = value; }
  162. //}
  163. public virtual DateTimeObject Date
  164. {
  165. get { return this.date; }
  166. set { this.date = value; }
  167. }
  168. // Returns a Set of the most-trusted CAs.
  169. public virtual ISet GetTrustAnchors()
  170. {
  171. return new HashSet(this.trustAnchors);
  172. }
  173. // Sets the set of most-trusted CAs.
  174. // Set is copied to protect against subsequent modifications.
  175. public virtual void SetTrustAnchors(
  176. ISet tas)
  177. {
  178. if (tas == null)
  179. throw new ArgumentNullException("value");
  180. if (tas.IsEmpty)
  181. throw new ArgumentException("non-empty set required", "value");
  182. // Explicit copy to enforce type-safety
  183. this.trustAnchors = new HashSet();
  184. foreach (TrustAnchor ta in tas)
  185. {
  186. if (ta != null)
  187. {
  188. trustAnchors.Add(ta);
  189. }
  190. }
  191. }
  192. /**
  193. * Returns the required constraints on the target certificate. The
  194. * constraints are returned as an instance of CertSelector. If
  195. * <code>null</code>, no constraints are defined.<br />
  196. * <br />
  197. * Note that the CertSelector returned is cloned to protect against
  198. * subsequent modifications.
  199. *
  200. * @return a CertSelector specifying the constraints on the target
  201. * certificate (or <code>null</code>)
  202. *
  203. * @see #setTargetCertConstraints(CertSelector)
  204. */
  205. public virtual X509CertStoreSelector GetTargetCertConstraints()
  206. {
  207. if (certSelector == null)
  208. {
  209. return null;
  210. }
  211. return (X509CertStoreSelector)certSelector.Clone();
  212. }
  213. /**
  214. * Sets the required constraints on the target certificate. The constraints
  215. * are specified as an instance of CertSelector. If null, no constraints are
  216. * defined.<br />
  217. * <br />
  218. * Note that the CertSelector specified is cloned to protect against
  219. * subsequent modifications.
  220. *
  221. * @param selector
  222. * a CertSelector specifying the constraints on the target
  223. * certificate (or <code>null</code>)
  224. *
  225. * @see #getTargetCertConstraints()
  226. */
  227. public virtual void SetTargetCertConstraints(
  228. IX509Selector selector)
  229. {
  230. if (selector == null)
  231. {
  232. certSelector = null;
  233. }
  234. else
  235. {
  236. certSelector = (IX509Selector)selector.Clone();
  237. }
  238. }
  239. /**
  240. * Returns an immutable Set of initial policy identifiers (OID strings),
  241. * indicating that any one of these policies would be acceptable to the
  242. * certificate user for the purposes of certification path processing. The
  243. * default return value is an empty <code>Set</code>, which is
  244. * interpreted as meaning that any policy would be acceptable.
  245. *
  246. * @return an immutable <code>Set</code> of initial policy OIDs in String
  247. * format, or an empty <code>Set</code> (implying any policy is
  248. * acceptable). Never returns <code>null</code>.
  249. *
  250. * @see #setInitialPolicies(java.util.Set)
  251. */
  252. public virtual ISet GetInitialPolicies()
  253. {
  254. ISet returnSet = initialPolicies;
  255. // TODO Can it really be null?
  256. if (initialPolicies == null)
  257. {
  258. returnSet = new HashSet();
  259. }
  260. return new HashSet(returnSet);
  261. }
  262. /**
  263. * Sets the <code>Set</code> of initial policy identifiers (OID strings),
  264. * indicating that any one of these policies would be acceptable to the
  265. * certificate user for the purposes of certification path processing. By
  266. * default, any policy is acceptable (i.e. all policies), so a user that
  267. * wants to allow any policy as acceptable does not need to call this
  268. * method, or can call it with an empty <code>Set</code> (or
  269. * <code>null</code>).<br />
  270. * <br />
  271. * Note that the Set is copied to protect against subsequent modifications.<br />
  272. * <br />
  273. *
  274. * @param initialPolicies
  275. * a Set of initial policy OIDs in String format (or
  276. * <code>null</code>)
  277. *
  278. * @exception ClassCastException
  279. * if any of the elements in the set are not of type String
  280. *
  281. * @see #getInitialPolicies()
  282. */
  283. public virtual void SetInitialPolicies(
  284. ISet initialPolicies)
  285. {
  286. this.initialPolicies = new HashSet();
  287. if (initialPolicies != null)
  288. {
  289. foreach (string obj in initialPolicies)
  290. {
  291. if (obj != null)
  292. {
  293. this.initialPolicies.Add(obj);
  294. }
  295. }
  296. }
  297. }
  298. /**
  299. * Sets a <code>List</code> of additional certification path checkers. If
  300. * the specified List contains an object that is not a PKIXCertPathChecker,
  301. * it is ignored.<br />
  302. * <br />
  303. * Each <code>PKIXCertPathChecker</code> specified implements additional
  304. * checks on a certificate. Typically, these are checks to process and
  305. * verify private extensions contained in certificates. Each
  306. * <code>PKIXCertPathChecker</code> should be instantiated with any
  307. * initialization parameters needed to execute the check.<br />
  308. * <br />
  309. * This method allows sophisticated applications to extend a PKIX
  310. * <code>CertPathValidator</code> or <code>CertPathBuilder</code>. Each
  311. * of the specified PKIXCertPathCheckers will be called, in turn, by a PKIX
  312. * <code>CertPathValidator</code> or <code>CertPathBuilder</code> for
  313. * each certificate processed or validated.<br />
  314. * <br />
  315. * Regardless of whether these additional PKIXCertPathCheckers are set, a
  316. * PKIX <code>CertPathValidator</code> or <code>CertPathBuilder</code>
  317. * must perform all of the required PKIX checks on each certificate. The one
  318. * exception to this rule is if the RevocationEnabled flag is set to false
  319. * (see the {@link #setRevocationEnabled(boolean) setRevocationEnabled}
  320. * method).<br />
  321. * <br />
  322. * Note that the List supplied here is copied and each PKIXCertPathChecker
  323. * in the list is cloned to protect against subsequent modifications.
  324. *
  325. * @param checkers
  326. * a List of PKIXCertPathCheckers. May be null, in which case no
  327. * additional checkers will be used.
  328. * @exception ClassCastException
  329. * if any of the elements in the list are not of type
  330. * <code>java.security.cert.PKIXCertPathChecker</code>
  331. * @see #getCertPathCheckers()
  332. */
  333. public virtual void SetCertPathCheckers(IList checkers)
  334. {
  335. certPathCheckers = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList();
  336. if (checkers != null)
  337. {
  338. foreach (PkixCertPathChecker obj in checkers)
  339. {
  340. certPathCheckers.Add(obj.Clone());
  341. }
  342. }
  343. }
  344. /**
  345. * Returns the List of certification path checkers. Each PKIXCertPathChecker
  346. * in the returned IList is cloned to protect against subsequent modifications.
  347. *
  348. * @return an immutable List of PKIXCertPathCheckers (may be empty, but not
  349. * <code>null</code>)
  350. *
  351. * @see #setCertPathCheckers(java.util.List)
  352. */
  353. public virtual IList GetCertPathCheckers()
  354. {
  355. IList checkers = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList();
  356. foreach (PkixCertPathChecker obj in certPathCheckers)
  357. {
  358. checkers.Add(obj.Clone());
  359. }
  360. return checkers;
  361. }
  362. /**
  363. * Adds a <code>PKIXCertPathChecker</code> to the list of certification
  364. * path checkers. See the {@link #setCertPathCheckers setCertPathCheckers}
  365. * method for more details.
  366. * <p>
  367. * Note that the <code>PKIXCertPathChecker</code> is cloned to protect
  368. * against subsequent modifications.</p>
  369. *
  370. * @param checker a <code>PKIXCertPathChecker</code> to add to the list of
  371. * checks. If <code>null</code>, the checker is ignored (not added to list).
  372. */
  373. public virtual void AddCertPathChecker(
  374. PkixCertPathChecker checker)
  375. {
  376. if (checker != null)
  377. {
  378. certPathCheckers.Add(checker.Clone());
  379. }
  380. }
  381. public virtual object Clone()
  382. {
  383. // FIXME Check this whole method against the Java implementation!
  384. PkixParameters parameters = new PkixParameters(GetTrustAnchors());
  385. parameters.SetParams(this);
  386. return parameters;
  387. // PkixParameters obj = new PkixParameters(new HashSet());
  388. //// (PkixParameters) this.MemberwiseClone();
  389. // obj.x509Stores = new ArrayList(x509Stores);
  390. // obj.certPathCheckers = new ArrayList(certPathCheckers);
  391. //
  392. // //Iterator iter = certPathCheckers.iterator();
  393. // //obj.certPathCheckers = new ArrayList();
  394. // //while (iter.hasNext())
  395. // //{
  396. // // obj.certPathCheckers.add(((PKIXCertPathChecker)iter.next())
  397. // // .clone());
  398. // //}
  399. // //if (initialPolicies != null)
  400. // //{
  401. // // obj.initialPolicies = new HashSet(initialPolicies);
  402. // //}
  403. //// if (trustAnchors != null)
  404. //// {
  405. //// obj.trustAnchors = new HashSet(trustAnchors);
  406. //// }
  407. //// if (certSelector != null)
  408. //// {
  409. //// obj.certSelector = (X509CertStoreSelector) certSelector.Clone();
  410. //// }
  411. // return obj;
  412. }
  413. /**
  414. * Method to support <code>Clone()</code> under J2ME.
  415. * <code>super.Clone()</code> does not exist and fields are not copied.
  416. *
  417. * @param params Parameters to set. If this are
  418. * <code>ExtendedPkixParameters</code> they are copied to.
  419. */
  420. protected virtual void SetParams(
  421. PkixParameters parameters)
  422. {
  423. Date = parameters.Date;
  424. SetCertPathCheckers(parameters.GetCertPathCheckers());
  425. IsAnyPolicyInhibited = parameters.IsAnyPolicyInhibited;
  426. IsExplicitPolicyRequired = parameters.IsExplicitPolicyRequired;
  427. IsPolicyMappingInhibited = parameters.IsPolicyMappingInhibited;
  428. IsRevocationEnabled = parameters.IsRevocationEnabled;
  429. SetInitialPolicies(parameters.GetInitialPolicies());
  430. IsPolicyQualifiersRejected = parameters.IsPolicyQualifiersRejected;
  431. SetTargetCertConstraints(parameters.GetTargetCertConstraints());
  432. SetTrustAnchors(parameters.GetTrustAnchors());
  433. validityModel = parameters.validityModel;
  434. useDeltas = parameters.useDeltas;
  435. additionalLocationsEnabled = parameters.additionalLocationsEnabled;
  436. selector = parameters.selector == null ? null
  437. : (IX509Selector) parameters.selector.Clone();
  438. stores = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList(parameters.stores);
  439. additionalStores = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList(parameters.additionalStores);
  440. trustedACIssuers = new HashSet(parameters.trustedACIssuers);
  441. prohibitedACAttributes = new HashSet(parameters.prohibitedACAttributes);
  442. necessaryACAttributes = new HashSet(parameters.necessaryACAttributes);
  443. attrCertCheckers = new HashSet(parameters.attrCertCheckers);
  444. }
  445. /**
  446. * Whether delta CRLs should be used for checking the revocation status.
  447. * Defaults to <code>false</code>.
  448. */
  449. public virtual bool IsUseDeltasEnabled
  450. {
  451. get { return useDeltas; }
  452. set { useDeltas = value; }
  453. }
  454. /**
  455. * The validity model.
  456. * @see #CHAIN_VALIDITY_MODEL
  457. * @see #PKIX_VALIDITY_MODEL
  458. */
  459. public virtual int ValidityModel
  460. {
  461. get { return validityModel; }
  462. set { validityModel = value; }
  463. }
  464. /**
  465. * Sets the Bouncy Castle Stores for finding CRLs, certificates, attribute
  466. * certificates or cross certificates.
  467. * <p>
  468. * The <code>IList</code> is cloned.
  469. * </p>
  470. *
  471. * @param stores A list of stores to use.
  472. * @see #getStores
  473. * @throws ClassCastException if an element of <code>stores</code> is not
  474. * a {@link Store}.
  475. */
  476. public virtual void SetStores(
  477. IList stores)
  478. {
  479. if (stores == null)
  480. {
  481. this.stores = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList();
  482. }
  483. else
  484. {
  485. foreach (object obj in stores)
  486. {
  487. if (!(obj is IX509Store))
  488. {
  489. throw new InvalidCastException(
  490. "All elements of list must be of type " + typeof(IX509Store).FullName);
  491. }
  492. }
  493. this.stores = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList(stores);
  494. }
  495. }
  496. /**
  497. * Adds a Bouncy Castle {@link Store} to find CRLs, certificates, attribute
  498. * certificates or cross certificates.
  499. * <p>
  500. * This method should be used to add local stores, like collection based
  501. * X.509 stores, if available. Local stores should be considered first,
  502. * before trying to use additional (remote) locations, because they do not
  503. * need possible additional network traffic.
  504. * </p><p>
  505. * If <code>store</code> is <code>null</code> it is ignored.
  506. * </p>
  507. *
  508. * @param store The store to add.
  509. * @see #getStores
  510. */
  511. public virtual void AddStore(
  512. IX509Store store)
  513. {
  514. if (store != null)
  515. {
  516. stores.Add(store);
  517. }
  518. }
  519. /**
  520. * Adds an additional Bouncy Castle {@link Store} to find CRLs, certificates,
  521. * attribute certificates or cross certificates.
  522. * <p>
  523. * You should not use this method. This method is used for adding additional
  524. * X.509 stores, which are used to add (remote) locations, e.g. LDAP, found
  525. * during X.509 object processing, e.g. in certificates or CRLs. This method
  526. * is used in PKIX certification path processing.
  527. * </p><p>
  528. * If <code>store</code> is <code>null</code> it is ignored.
  529. * </p>
  530. *
  531. * @param store The store to add.
  532. * @see #getStores()
  533. */
  534. public virtual void AddAdditionalStore(
  535. IX509Store store)
  536. {
  537. if (store != null)
  538. {
  539. additionalStores.Add(store);
  540. }
  541. }
  542. /**
  543. * Returns an <code>IList</code> of additional Bouncy Castle
  544. * <code>Store</code>s used for finding CRLs, certificates, attribute
  545. * certificates or cross certificates.
  546. *
  547. * @return an immutable <code>IList</code> of additional Bouncy Castle
  548. * <code>Store</code>s. Never <code>null</code>.
  549. *
  550. * @see #addAddionalStore(Store)
  551. */
  552. public virtual IList GetAdditionalStores()
  553. {
  554. return BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList(additionalStores);
  555. }
  556. /**
  557. * Returns an <code>IList</code> of Bouncy Castle
  558. * <code>Store</code>s used for finding CRLs, certificates, attribute
  559. * certificates or cross certificates.
  560. *
  561. * @return an immutable <code>IList</code> of Bouncy Castle
  562. * <code>Store</code>s. Never <code>null</code>.
  563. *
  564. * @see #setStores(IList)
  565. */
  566. public virtual IList GetStores()
  567. {
  568. return BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList(stores);
  569. }
  570. /**
  571. * Returns if additional {@link X509Store}s for locations like LDAP found
  572. * in certificates or CRLs should be used.
  573. *
  574. * @return Returns <code>true</code> if additional stores are used.
  575. */
  576. public virtual bool IsAdditionalLocationsEnabled
  577. {
  578. get { return additionalLocationsEnabled; }
  579. }
  580. /**
  581. * Sets if additional {@link X509Store}s for locations like LDAP found in
  582. * certificates or CRLs should be used.
  583. *
  584. * @param enabled <code>true</code> if additional stores are used.
  585. */
  586. public virtual void SetAdditionalLocationsEnabled(
  587. bool enabled)
  588. {
  589. additionalLocationsEnabled = enabled;
  590. }
  591. /**
  592. * Returns the required constraints on the target certificate or attribute
  593. * certificate. The constraints are returned as an instance of
  594. * <code>IX509Selector</code>. If <code>null</code>, no constraints are
  595. * defined.
  596. *
  597. * <p>
  598. * The target certificate in a PKIX path may be a certificate or an
  599. * attribute certificate.
  600. * </p><p>
  601. * Note that the <code>IX509Selector</code> returned is cloned to protect
  602. * against subsequent modifications.
  603. * </p>
  604. * @return a <code>IX509Selector</code> specifying the constraints on the
  605. * target certificate or attribute certificate (or <code>null</code>)
  606. * @see #setTargetConstraints
  607. * @see X509CertStoreSelector
  608. * @see X509AttributeCertStoreSelector
  609. */
  610. public virtual IX509Selector GetTargetConstraints()
  611. {
  612. if (selector != null)
  613. {
  614. return (IX509Selector) selector.Clone();
  615. }
  616. else
  617. {
  618. return null;
  619. }
  620. }
  621. /**
  622. * Sets the required constraints on the target certificate or attribute
  623. * certificate. The constraints are specified as an instance of
  624. * <code>IX509Selector</code>. If <code>null</code>, no constraints are
  625. * defined.
  626. * <p>
  627. * The target certificate in a PKIX path may be a certificate or an
  628. * attribute certificate.
  629. * </p><p>
  630. * Note that the <code>IX509Selector</code> specified is cloned to protect
  631. * against subsequent modifications.
  632. * </p>
  633. *
  634. * @param selector a <code>IX509Selector</code> specifying the constraints on
  635. * the target certificate or attribute certificate (or
  636. * <code>null</code>)
  637. * @see #getTargetConstraints
  638. * @see X509CertStoreSelector
  639. * @see X509AttributeCertStoreSelector
  640. */
  641. public virtual void SetTargetConstraints(IX509Selector selector)
  642. {
  643. if (selector != null)
  644. {
  645. this.selector = (IX509Selector) selector.Clone();
  646. }
  647. else
  648. {
  649. this.selector = null;
  650. }
  651. }
  652. /**
  653. * Returns the trusted attribute certificate issuers. If attribute
  654. * certificates is verified the trusted AC issuers must be set.
  655. * <p>
  656. * The returned <code>ISet</code> consists of <code>TrustAnchor</code>s.
  657. * </p><p>
  658. * The returned <code>ISet</code> is immutable. Never <code>null</code>
  659. * </p>
  660. *
  661. * @return Returns an immutable set of the trusted AC issuers.
  662. */
  663. public virtual ISet GetTrustedACIssuers()
  664. {
  665. return new HashSet(trustedACIssuers);
  666. }
  667. /**
  668. * Sets the trusted attribute certificate issuers. If attribute certificates
  669. * is verified the trusted AC issuers must be set.
  670. * <p>
  671. * The <code>trustedACIssuers</code> must be a <code>ISet</code> of
  672. * <code>TrustAnchor</code>
  673. * </p><p>
  674. * The given set is cloned.
  675. * </p>
  676. *
  677. * @param trustedACIssuers The trusted AC issuers to set. Is never
  678. * <code>null</code>.
  679. * @throws ClassCastException if an element of <code>stores</code> is not
  680. * a <code>TrustAnchor</code>.
  681. */
  682. public virtual void SetTrustedACIssuers(
  683. ISet trustedACIssuers)
  684. {
  685. if (trustedACIssuers == null)
  686. {
  687. this.trustedACIssuers = new HashSet();
  688. }
  689. else
  690. {
  691. foreach (object obj in trustedACIssuers)
  692. {
  693. if (!(obj is TrustAnchor))
  694. {
  695. throw new InvalidCastException("All elements of set must be "
  696. + "of type " + typeof(TrustAnchor).FullName + ".");
  697. }
  698. }
  699. this.trustedACIssuers = new HashSet(trustedACIssuers);
  700. }
  701. }
  702. /**
  703. * Returns the necessary attributes which must be contained in an attribute
  704. * certificate.
  705. * <p>
  706. * The returned <code>ISet</code> is immutable and contains
  707. * <code>String</code>s with the OIDs.
  708. * </p>
  709. *
  710. * @return Returns the necessary AC attributes.
  711. */
  712. public virtual ISet GetNecessaryACAttributes()
  713. {
  714. return new HashSet(necessaryACAttributes);
  715. }
  716. /**
  717. * Sets the necessary which must be contained in an attribute certificate.
  718. * <p>
  719. * The <code>ISet</code> must contain <code>String</code>s with the
  720. * OIDs.
  721. * </p><p>
  722. * The set is cloned.
  723. * </p>
  724. *
  725. * @param necessaryACAttributes The necessary AC attributes to set.
  726. * @throws ClassCastException if an element of
  727. * <code>necessaryACAttributes</code> is not a
  728. * <code>String</code>.
  729. */
  730. public virtual void SetNecessaryACAttributes(
  731. ISet necessaryACAttributes)
  732. {
  733. if (necessaryACAttributes == null)
  734. {
  735. this.necessaryACAttributes = new HashSet();
  736. }
  737. else
  738. {
  739. foreach (object obj in necessaryACAttributes)
  740. {
  741. if (!(obj is string))
  742. {
  743. throw new InvalidCastException("All elements of set must be "
  744. + "of type string.");
  745. }
  746. }
  747. this.necessaryACAttributes = new HashSet(necessaryACAttributes);
  748. }
  749. }
  750. /**
  751. * Returns the attribute certificates which are not allowed.
  752. * <p>
  753. * The returned <code>ISet</code> is immutable and contains
  754. * <code>String</code>s with the OIDs.
  755. * </p>
  756. *
  757. * @return Returns the prohibited AC attributes. Is never <code>null</code>.
  758. */
  759. public virtual ISet GetProhibitedACAttributes()
  760. {
  761. return new HashSet(prohibitedACAttributes);
  762. }
  763. /**
  764. * Sets the attribute certificates which are not allowed.
  765. * <p>
  766. * The <code>ISet</code> must contain <code>String</code>s with the
  767. * OIDs.
  768. * </p><p>
  769. * The set is cloned.
  770. * </p>
  771. *
  772. * @param prohibitedACAttributes The prohibited AC attributes to set.
  773. * @throws ClassCastException if an element of
  774. * <code>prohibitedACAttributes</code> is not a
  775. * <code>String</code>.
  776. */
  777. public virtual void SetProhibitedACAttributes(
  778. ISet prohibitedACAttributes)
  779. {
  780. if (prohibitedACAttributes == null)
  781. {
  782. this.prohibitedACAttributes = new HashSet();
  783. }
  784. else
  785. {
  786. foreach (object obj in prohibitedACAttributes)
  787. {
  788. if (!(obj is String))
  789. {
  790. throw new InvalidCastException("All elements of set must be "
  791. + "of type string.");
  792. }
  793. }
  794. this.prohibitedACAttributes = new HashSet(prohibitedACAttributes);
  795. }
  796. }
  797. /**
  798. * Returns the attribute certificate checker. The returned set contains
  799. * {@link PKIXAttrCertChecker}s and is immutable.
  800. *
  801. * @return Returns the attribute certificate checker. Is never
  802. * <code>null</code>.
  803. */
  804. public virtual ISet GetAttrCertCheckers()
  805. {
  806. return new HashSet(attrCertCheckers);
  807. }
  808. /**
  809. * Sets the attribute certificate checkers.
  810. * <p>
  811. * All elements in the <code>ISet</code> must a {@link PKIXAttrCertChecker}.
  812. * </p>
  813. * <p>
  814. * The given set is cloned.
  815. * </p>
  816. *
  817. * @param attrCertCheckers The attribute certificate checkers to set. Is
  818. * never <code>null</code>.
  819. * @throws ClassCastException if an element of <code>attrCertCheckers</code>
  820. * is not a <code>PKIXAttrCertChecker</code>.
  821. */
  822. public virtual void SetAttrCertCheckers(
  823. ISet attrCertCheckers)
  824. {
  825. if (attrCertCheckers == null)
  826. {
  827. this.attrCertCheckers = new HashSet();
  828. }
  829. else
  830. {
  831. foreach (object obj in attrCertCheckers)
  832. {
  833. if (!(obj is PkixAttrCertChecker))
  834. {
  835. throw new InvalidCastException("All elements of set must be "
  836. + "of type " + typeof(PkixAttrCertChecker).FullName + ".");
  837. }
  838. }
  839. this.attrCertCheckers = new HashSet(attrCertCheckers);
  840. }
  841. }
  842. }
  843. }
  844. #pragma warning restore
  845. #endif