PkixParameters.cs 26 KB

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