1. /*
  2. * @(#)PKIXParameters.java 1.14 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.security.cert;
  8. import java.security.InvalidAlgorithmParameterException;
  9. import java.security.KeyStore;
  10. import java.security.KeyStoreException;
  11. import java.util.ArrayList;
  12. import java.util.Collections;
  13. import java.util.Date;
  14. import java.util.Enumeration;
  15. import java.util.HashSet;
  16. import java.util.Iterator;
  17. import java.util.List;
  18. import java.util.Set;
  19. /**
  20. * Parameters used as input for the PKIX <code>CertPathValidator</code>
  21. * algorithm.
  22. * <p>
  23. * A PKIX <code>CertPathValidator</code> uses these parameters to
  24. * validate a <code>CertPath</code> according to the PKIX certification path
  25. * validation algorithm.
  26. *
  27. * <p>To instantiate a <code>PKIXParameters</code> object, an
  28. * application must specify one or more <i>most-trusted CAs</i> as defined by
  29. * the PKIX certification path validation algorithm. The most-trusted CAs
  30. * can be specified using one of two constructors. An application
  31. * can call {@link #PKIXParameters(Set) PKIXParameters(Set)},
  32. * specifying a <code>Set</code> of <code>TrustAnchor</code> objects, each
  33. * of which identify a most-trusted CA. Alternatively, an application can call
  34. * {@link #PKIXParameters(KeyStore) PKIXParameters(KeyStore)}, specifying a
  35. * <code>KeyStore</code> instance containing trusted certificate entries, each
  36. * of which will be considered as a most-trusted CA.
  37. * <p>
  38. * Once a <code>PKIXParameters</code> object has been created, other parameters
  39. * can be specified (by calling {@link #setInitialPolicies setInitialPolicies}
  40. * or {@link #setDate setDate}, for instance) and then the
  41. * <code>PKIXParameters</code> is passed along with the <code>CertPath</code>
  42. * to be validated to {@link CertPathValidator#validate
  43. * CertPathValidator.validate}.
  44. * <p>
  45. * Any parameter that is not set (or is set to <code>null</code>) will
  46. * be set to the default value for that parameter. The default value for the
  47. * <code>date</code> parameter is <code>null</code>, which indicates
  48. * the current time when the path is validated. The default for the
  49. * remaining parameters is the least constrained.
  50. * <p>
  51. * <b>Concurrent Access</b>
  52. * <p>
  53. * Unless otherwise specified, the methods defined in this class are not
  54. * thread-safe. Multiple threads that need to access a single
  55. * object concurrently should synchronize amongst themselves and
  56. * provide the necessary locking. Multiple threads each manipulating
  57. * separate objects need not synchronize.
  58. *
  59. * @see CertPathValidator
  60. *
  61. * @version 1.14 01/23/03
  62. * @since 1.4
  63. * @author Sean Mullan
  64. * @author Yassir Elley
  65. */
  66. public class PKIXParameters implements CertPathParameters {
  67. private Set unmodTrustAnchors;
  68. private Date date;
  69. private List certPathCheckers;
  70. private String sigProvider;
  71. private boolean revocationEnabled = true;
  72. private Set unmodInitialPolicies;
  73. private boolean explicitPolicyRequired = false;
  74. private boolean policyMappingInhibited = false;
  75. private boolean anyPolicyInhibited = false;
  76. private boolean policyQualifiersRejected = true;
  77. private List certStores;
  78. private CertSelector certSelector;
  79. /**
  80. * Creates an instance of <code>PKIXParameters</code> with the specified
  81. * <code>Set</code> of most-trusted CAs. Each element of the
  82. * set is a {@link TrustAnchor TrustAnchor}.
  83. * <p>
  84. * Note that the <code>Set</code> is copied to protect against
  85. * subsequent modifications.
  86. *
  87. * @param trustAnchors a <code>Set</code> of <code>TrustAnchor</code>s
  88. * @throws InvalidAlgorithmParameterException if the specified
  89. * <code>Set</code> is empty <code>(trustAnchors.isEmpty() == true)</code>
  90. * @throws NullPointerException if the specified <code>Set</code> is
  91. * <code>null</code>
  92. * @throws ClassCastException if any of the elements in the <code>Set</code>
  93. * are not of type <code>java.security.cert.TrustAnchor</code>
  94. */
  95. public PKIXParameters(Set trustAnchors)
  96. throws InvalidAlgorithmParameterException
  97. {
  98. setTrustAnchors(trustAnchors);
  99. this.unmodInitialPolicies = Collections.unmodifiableSet(new HashSet());
  100. this.certPathCheckers = new ArrayList();
  101. this.certStores = new ArrayList();
  102. }
  103. /**
  104. * Creates an instance of <code>PKIXParameters</code> that
  105. * populates the set of most-trusted CAs from the trusted
  106. * certificate entries contained in the specified <code>KeyStore</code>.
  107. * Only keystore entries that contain trusted <code>X509Certificates</code>
  108. * are considered; all other certificate types are ignored.
  109. *
  110. * @param keystore a <code>KeyStore</code> from which the set of
  111. * most-trusted CAs will be populated
  112. * @throws KeyStoreException if the keystore has not been initialized
  113. * @throws InvalidAlgorithmParameterException if the keystore does
  114. * not contain at least one trusted certificate entry
  115. * @throws NullPointerException if the keystore is <code>null</code>
  116. */
  117. public PKIXParameters(KeyStore keystore)
  118. throws KeyStoreException, InvalidAlgorithmParameterException
  119. {
  120. if (keystore == null)
  121. throw new NullPointerException("the keystore parameter must be " +
  122. "non-null");
  123. HashSet hashSet = new HashSet();
  124. Enumeration aliases = keystore.aliases();
  125. while (aliases.hasMoreElements()) {
  126. String alias = (String) aliases.nextElement();
  127. if (keystore.isCertificateEntry(alias)) {
  128. Certificate cert = keystore.getCertificate(alias);
  129. if (cert instanceof X509Certificate)
  130. hashSet.add(new TrustAnchor((X509Certificate)cert, null));
  131. }
  132. }
  133. setTrustAnchors(hashSet);
  134. this.unmodInitialPolicies = Collections.unmodifiableSet(new HashSet());
  135. this.certPathCheckers = new ArrayList();
  136. this.certStores = new ArrayList();
  137. }
  138. /**
  139. * Returns an immutable <code>Set</code> of the most-trusted
  140. * CAs.
  141. *
  142. * @return an immutable <code>Set</code> of <code>TrustAnchor</code>s
  143. * (never <code>null</code>)
  144. *
  145. * @see #setTrustAnchors
  146. */
  147. public Set getTrustAnchors() {
  148. return this.unmodTrustAnchors;
  149. }
  150. /**
  151. * Sets the <code>Set</code> of most-trusted CAs.
  152. * <p>
  153. * Note that the <code>Set</code> is copied to protect against
  154. * subsequent modifications.
  155. *
  156. * @param trustAnchors a <code>Set</code> of <code>TrustAnchor</code>s
  157. * @throws InvalidAlgorithmParameterException if the specified
  158. * <code>Set</code> is empty <code>(trustAnchors.isEmpty() == true)</code>
  159. * @throws NullPointerException if the specified <code>Set</code> is
  160. * <code>null</code>
  161. * @throws ClassCastException if any of the elements in the set
  162. * are not of type <code>java.security.cert.TrustAnchor</code>
  163. *
  164. * @see #getTrustAnchors
  165. */
  166. public void setTrustAnchors(Set trustAnchors)
  167. throws InvalidAlgorithmParameterException
  168. {
  169. if (trustAnchors == null)
  170. throw new NullPointerException("the trustAnchors parameters must" +
  171. " be non-null");
  172. if (trustAnchors.isEmpty())
  173. throw new InvalidAlgorithmParameterException("the trustAnchors " +
  174. "parameter must be non-empty");
  175. for (Iterator i = trustAnchors.iterator(); i.hasNext();) {
  176. if (!(i.next() instanceof TrustAnchor))
  177. throw new ClassCastException("all elements of set must be "
  178. + "of type java.security.cert.TrustAnchor");
  179. }
  180. this.unmodTrustAnchors =
  181. Collections.unmodifiableSet(new HashSet(trustAnchors));
  182. }
  183. /**
  184. * Returns an immutable <code>Set</code> of initial
  185. * policy identifiers (OID strings), indicating that any one of these
  186. * policies would be acceptable to the certificate user for the purposes of
  187. * certification path processing. The default return value is an empty
  188. * <code>Set</code>, which is interpreted as meaning that any policy would
  189. * be acceptable.
  190. *
  191. * @return an immutable <code>Set</code> of initial policy OIDs in
  192. * <code>String</code> format, or an empty <code>Set</code> (implying any
  193. * policy is acceptable). Never returns <code>null</code>.
  194. *
  195. * @see #setInitialPolicies
  196. */
  197. public Set getInitialPolicies() {
  198. return this.unmodInitialPolicies;
  199. }
  200. /**
  201. * Sets the <code>Set</code> of initial policy identifiers
  202. * (OID strings), indicating that any one of these
  203. * policies would be acceptable to the certificate user for the purposes of
  204. * certification path processing. By default, any policy is acceptable
  205. * (i.e. all policies), so a user that wants to allow any policy as
  206. * acceptable does not need to call this method, or can call it
  207. * with an empty <code>Set</code> (or <code>null</code>).
  208. * <p>
  209. * Note that the <code>Set</code> is copied to protect against
  210. * subsequent modifications.
  211. *
  212. * @param initialPolicies a <code>Set</code> of initial policy
  213. * OIDs in <code>String</code> format (or <code>null</code>)
  214. * @throws ClassCastException if any of the elements in the set are
  215. * not of type <code>String</code>
  216. *
  217. * @see #getInitialPolicies
  218. */
  219. public void setInitialPolicies(Set initialPolicies) {
  220. if (initialPolicies != null) {
  221. for (Iterator i = initialPolicies.iterator(); i.hasNext();) {
  222. if (!(i.next() instanceof String))
  223. throw new ClassCastException("all elements of set must be "
  224. + "of type java.lang.String");
  225. }
  226. this.unmodInitialPolicies =
  227. Collections.unmodifiableSet(new HashSet(initialPolicies));
  228. } else
  229. this.unmodInitialPolicies =
  230. Collections.unmodifiableSet(new HashSet());
  231. }
  232. /**
  233. * Sets the list of <code>CertStore</code>s to be used in finding
  234. * certificates and CRLs. May be <code>null</code>, in which case
  235. * no <code>CertStore</code>s will be used. The first
  236. * <code>CertStore</code>s in the list may be preferred to those that
  237. * appear later.
  238. * <p>
  239. * Note that the <code>List</code> is copied to protect against
  240. * subsequent modifications.
  241. *
  242. * @param stores a <code>List</code> of <code>CertStore</code>s (or
  243. * <code>null</code>)
  244. * @throws ClassCastException if any of the elements in the list are
  245. * not of type <code>java.security.cert.CertStore</code>
  246. *
  247. * @see #getCertStores
  248. */
  249. public void setCertStores(List stores) {
  250. if (stores == null)
  251. this.certStores = new ArrayList();
  252. else {
  253. for (Iterator i = stores.iterator(); i.hasNext();) {
  254. if (!(i.next() instanceof CertStore))
  255. throw new ClassCastException("all elements of list must be "
  256. + "of type java.security.cert.CertStore");
  257. }
  258. this.certStores = new ArrayList(stores);
  259. }
  260. }
  261. /**
  262. * Adds a <code>CertStore</code> to the end of the list of
  263. * <code>CertStore</code>s used in finding certificates and CRLs.
  264. *
  265. * @param store the <code>CertStore</code> to add. If <code>null</code>,
  266. * the store is ignored (not added to list).
  267. */
  268. public void addCertStore(CertStore store) {
  269. if (store != null)
  270. this.certStores.add(store);
  271. }
  272. /**
  273. * Returns an immutable <code>List</code> of <code>CertStore</code>s that
  274. * are used to find certificates and CRLs.
  275. *
  276. * @return an immutable <code>List</code> of <code>CertStore</code>s
  277. * (may be empty, but never <code>null</code>)
  278. *
  279. * @see #setCertStores
  280. */
  281. public List getCertStores() {
  282. return Collections.unmodifiableList(new ArrayList(this.certStores));
  283. }
  284. /**
  285. * Sets the RevocationEnabled flag. If this flag is true, the default
  286. * revocation checking mechanism of the underlying PKIX service provider
  287. * will be used. If this flag is false, the default revocation checking
  288. * mechanism will be disabled (not used).
  289. * <p>
  290. * When a <code>PKIXParameters</code> object is created, this flag is set
  291. * to true. This setting reflects the most common strategy for checking
  292. * revocation, since each service provider must support revocation
  293. * checking to be PKIX compliant. Sophisticated applications should set
  294. * this flag to false when it is not practical to use a PKIX service
  295. * provider's default revocation checking mechanism or when an alternative
  296. * revocation checking mechanism is to be substituted (by also calling the
  297. * {@link #addCertPathChecker addCertPathChecker} or {@link
  298. * #setCertPathCheckers setCertPathCheckers} methods).
  299. *
  300. * @param val the new value of the RevocationEnabled flag
  301. */
  302. public void setRevocationEnabled(boolean val) {
  303. revocationEnabled = val;
  304. }
  305. /**
  306. * Checks the RevocationEnabled flag. If this flag is true, the default
  307. * revocation checking mechanism of the underlying PKIX service provider
  308. * will be used. If this flag is false, the default revocation checking
  309. * mechanism will be disabled (not used). See the {@link
  310. * #setRevocationEnabled setRevocationEnabled} method for more details on
  311. * setting the value of this flag.
  312. *
  313. * @return the current value of the RevocationEnabled flag
  314. */
  315. public boolean isRevocationEnabled() {
  316. return revocationEnabled;
  317. }
  318. /**
  319. * Sets the ExplicitPolicyRequired flag. If this flag is true, an
  320. * acceptable policy needs to be explicitly identified in every certificate.
  321. * By default, the ExplicitPolicyRequired flag is false.
  322. *
  323. * @param val <code>true</code> if explicit policy is to be required,
  324. * <code>false</code> otherwise
  325. */
  326. public void setExplicitPolicyRequired(boolean val) {
  327. explicitPolicyRequired = val;
  328. }
  329. /**
  330. * Checks if explicit policy is required. If this flag is true, an
  331. * acceptable policy needs to be explicitly identified in every certificate.
  332. * By default, the ExplicitPolicyRequired flag is false.
  333. *
  334. * @return <code>true</code> if explicit policy is required,
  335. * <code>false</code> otherwise
  336. */
  337. public boolean isExplicitPolicyRequired() {
  338. return explicitPolicyRequired;
  339. }
  340. /**
  341. * Sets the PolicyMappingInhibited flag. If this flag is true, policy
  342. * mapping is inhibited. By default, policy mapping is not inhibited (the
  343. * flag is false).
  344. *
  345. * @param val <code>true</code> if policy mapping is to be inhibited,
  346. * <code>false</code> otherwise
  347. */
  348. public void setPolicyMappingInhibited(boolean val) {
  349. policyMappingInhibited = val;
  350. }
  351. /**
  352. * Checks if policy mapping is inhibited. If this flag is true, policy
  353. * mapping is inhibited. By default, policy mapping is not inhibited (the
  354. * flag is false).
  355. *
  356. * @return true if policy mapping is inhibited, false otherwise
  357. */
  358. public boolean isPolicyMappingInhibited() {
  359. return policyMappingInhibited;
  360. }
  361. /**
  362. * Sets state to determine if the any policy OID should be processed
  363. * if it is included in a certificate. By default, the any policy OID
  364. * is not inhibited ({@link #isAnyPolicyInhibited isAnyPolicyInhibited()}
  365. * returns <code>false</code>).
  366. *
  367. * @param val <code>true</code> if the any policy OID is to be
  368. * inhibited, <code>false</code> otherwise
  369. */
  370. public void setAnyPolicyInhibited(boolean val) {
  371. anyPolicyInhibited = val;
  372. }
  373. /**
  374. * Checks whether the any policy OID should be processed if it
  375. * is included in a certificate.
  376. *
  377. * @return <code>true</code> if the any policy OID is inhibited,
  378. * <code>false</code> otherwise
  379. */
  380. public boolean isAnyPolicyInhibited() {
  381. return anyPolicyInhibited;
  382. }
  383. /**
  384. * Sets the PolicyQualifiersRejected flag. If this flag is true,
  385. * certificates that include policy qualifiers in a certificate
  386. * policies extension that is marked critical are rejected.
  387. * If the flag is false, certificates are not rejected on this basis.
  388. *
  389. * <p> When a <code>PKIXParameters</code> object is created, this flag is
  390. * set to true. This setting reflects the most common (and simplest)
  391. * strategy for processing policy qualifiers. Applications that want to use
  392. * a more sophisticated policy must set this flag to false.
  393. * <p>
  394. * Note that the PKIX certification path validation algorithm specifies
  395. * that any policy qualifier in a certificate policies extension that is
  396. * marked critical must be processed and validated. Otherwise the
  397. * certification path must be rejected. If the policyQualifiersRejected flag
  398. * is set to false, it is up to the application to validate all policy
  399. * qualifiers in this manner in order to be PKIX compliant.
  400. *
  401. * @param qualifiersRejected the new value of the PolicyQualifiersRejected
  402. * flag
  403. * @see #getPolicyQualifiersRejected
  404. * @see PolicyQualifierInfo
  405. */
  406. public void setPolicyQualifiersRejected(boolean qualifiersRejected) {
  407. policyQualifiersRejected = qualifiersRejected;
  408. }
  409. /**
  410. * Gets the PolicyQualifiersRejected flag. If this flag is true,
  411. * certificates that include policy qualifiers in a certificate policies
  412. * extension that is marked critical are rejected.
  413. * If the flag is false, certificates are not rejected on this basis.
  414. *
  415. * <p> When a <code>PKIXParameters</code> object is created, this flag is
  416. * set to true. This setting reflects the most common (and simplest)
  417. * strategy for processing policy qualifiers. Applications that want to use
  418. * a more sophisticated policy must set this flag to false.
  419. *
  420. * @return the current value of the PolicyQualifiersRejected flag
  421. * @see #setPolicyQualifiersRejected
  422. */
  423. public boolean getPolicyQualifiersRejected() {
  424. return policyQualifiersRejected;
  425. }
  426. /**
  427. * Returns the time for which the validity of the certification path
  428. * should be determined. If <code>null</code>, the current time is used.
  429. * <p>
  430. * Note that the <code>Date</code> returned is copied to protect against
  431. * subsequent modifications.
  432. *
  433. * @return the <code>Date</code>, or <code>null</code> if not set
  434. * @see #setDate
  435. */
  436. public Date getDate() {
  437. if (date == null)
  438. return null;
  439. else
  440. return (Date) this.date.clone();
  441. }
  442. /**
  443. * Sets the time for which the validity of the certification path
  444. * should be determined. If <code>null</code>, the current time is used.
  445. * <p>
  446. * Note that the <code>Date</code> supplied here is copied to protect
  447. * against subsequent modifications.
  448. *
  449. * @param date the <code>Date</code>, or <code>null</code> for the
  450. * current time
  451. * @see #getDate
  452. */
  453. public void setDate(Date date) {
  454. if (date != null)
  455. this.date = (Date) date.clone();
  456. else
  457. date = null;
  458. }
  459. /**
  460. * Sets a <code>List</code> of additional certification path checkers. If
  461. * the specified <code>List</code> contains an object that is not a
  462. * <code>PKIXCertPathChecker</code>, it is ignored.
  463. * <p>
  464. * Each <code>PKIXCertPathChecker</code> specified implements
  465. * additional checks on a certificate. Typically, these are checks to
  466. * process and verify private extensions contained in certificates.
  467. * Each <code>PKIXCertPathChecker</code> should be instantiated with any
  468. * initialization parameters needed to execute the check.
  469. * <p>
  470. * This method allows sophisticated applications to extend a PKIX
  471. * <code>CertPathValidator</code> or <code>CertPathBuilder</code>.
  472. * Each of the specified <code>PKIXCertPathChecker</code>s will be called,
  473. * in turn, by a PKIX <code>CertPathValidator</code> or
  474. * <code>CertPathBuilder</code> for each certificate processed or
  475. * validated.
  476. * <p>
  477. * Regardless of whether these additional <code>PKIXCertPathChecker</code>s
  478. * are set, a PKIX <code>CertPathValidator</code> or
  479. * <code>CertPathBuilder</code> must perform all of the required PKIX
  480. * checks on each certificate. The one exception to this rule is if the
  481. * RevocationEnabled flag is set to false (see the {@link
  482. * #setRevocationEnabled setRevocationEnabled} method).
  483. * <p>
  484. * Note that the <code>List</code> supplied here is copied and each
  485. * <code>PKIXCertPathChecker</code> in the list is cloned to protect
  486. * against subsequent modifications.
  487. *
  488. * @param checkers a <code>List</code> of <code>PKIXCertPathChecker</code>s.
  489. * May be <code>null</code>, in which case no additional checkers will be
  490. * used.
  491. * @throws ClassCastException if any of the elements in the list
  492. * are not of type <code>java.security.cert.PKIXCertPathChecker</code>
  493. * @see #getCertPathCheckers
  494. */
  495. public void setCertPathCheckers(List checkers) {
  496. if (checkers != null) {
  497. ArrayList tmpList = new ArrayList();
  498. Iterator it = checkers.iterator();
  499. while (it.hasNext()) {
  500. PKIXCertPathChecker ck = (PKIXCertPathChecker) it.next();
  501. tmpList.add(ck.clone());
  502. }
  503. this.certPathCheckers = tmpList;
  504. } else
  505. this.certPathCheckers = new ArrayList();
  506. }
  507. /**
  508. * Returns the <code>List</code> of certification path checkers.
  509. * The returned <code>List</code> is immutable, and each
  510. * <code>PKIXCertPathChecker</code> in the <code>List</code> is cloned
  511. * to protect against subsequent modifications.
  512. *
  513. * @return an immutable <code>List</code> of
  514. * <code>PKIXCertPathChecker</code>s (may be empty, but not
  515. * <code>null</code>)
  516. * @see #setCertPathCheckers
  517. */
  518. public List getCertPathCheckers() {
  519. ArrayList tmpList = new ArrayList();
  520. Iterator it = certPathCheckers.iterator();
  521. while (it.hasNext()) {
  522. PKIXCertPathChecker ck = (PKIXCertPathChecker) it.next();
  523. tmpList.add(ck.clone());
  524. }
  525. return Collections.unmodifiableList(tmpList);
  526. }
  527. /**
  528. * Adds a <code>PKIXCertPathChecker</code> to the list of certification
  529. * path checkers. See the {@link #setCertPathCheckers setCertPathCheckers}
  530. * method for more details.
  531. * <p>
  532. * Note that the <code>PKIXCertPathChecker</code> is cloned to protect
  533. * against subsequent modifications.
  534. *
  535. * @param checker a <code>PKIXCertPathChecker</code> to add to the list of
  536. * checks. If <code>null</code>, the checker is ignored (not added to list).
  537. */
  538. public void addCertPathChecker(PKIXCertPathChecker checker) {
  539. if (checker != null)
  540. certPathCheckers.add(checker.clone());
  541. }
  542. /**
  543. * Returns the signature provider's name, or <code>null</code>
  544. * if not set.
  545. *
  546. * @return the signature provider's name (or <code>null</code>)
  547. * @see #setSigProvider
  548. */
  549. public String getSigProvider() {
  550. return this.sigProvider;
  551. }
  552. /**
  553. * Sets the signature provider's name. The specified provider will be
  554. * preferred when creating {@link java.security.Signature Signature}
  555. * objects. If <code>null</code> or not set, the first provider found
  556. * supporting the algorithm will be used.
  557. *
  558. * @param sigProvider the signature provider's name (or <code>null</code>)
  559. * @see #getSigProvider
  560. */
  561. public void setSigProvider(String sigProvider) {
  562. this.sigProvider = sigProvider;
  563. }
  564. /**
  565. * Returns the required constraints on the target certificate.
  566. * The constraints are returned as an instance of <code>CertSelector</code>.
  567. * If <code>null</code>, no constraints are defined.
  568. *
  569. * <p>Note that the <code>CertSelector</code> returned is cloned
  570. * to protect against subsequent modifications.
  571. *
  572. * @return a <code>CertSelector</code> specifying the constraints
  573. * on the target certificate (or <code>null</code>)
  574. * @see #setTargetCertConstraints
  575. */
  576. public CertSelector getTargetCertConstraints() {
  577. if (certSelector != null)
  578. return (CertSelector) certSelector.clone();
  579. else
  580. return null;
  581. }
  582. /**
  583. * Sets the required constraints on the target certificate.
  584. * The constraints are specified as an instance of
  585. * <code>CertSelector</code>. If <code>null</code>, no constraints are
  586. * defined.
  587. *
  588. * <p>Note that the <code>CertSelector</code> specified is cloned
  589. * to protect against subsequent modifications.
  590. *
  591. * @param selector a <code>CertSelector</code> specifying the constraints
  592. * on the target certificate (or <code>null</code>)
  593. * @see #getTargetCertConstraints
  594. */
  595. public void setTargetCertConstraints(CertSelector selector) {
  596. if (selector != null)
  597. certSelector = (CertSelector) selector.clone();
  598. else
  599. certSelector = null;
  600. }
  601. /**
  602. * Makes a copy of this <code>PKIXParameters</code> object. Changes
  603. * to the copy will not affect the original and vice versa.
  604. *
  605. * @return a copy of this <code>PKIXParameters</code> object
  606. */
  607. public Object clone() {
  608. try {
  609. Object copy = super.clone();
  610. // Must clone these because addCertStore, et al. modify them
  611. if (certStores != null) {
  612. certStores = new ArrayList(certStores);
  613. }
  614. if (certPathCheckers != null) {
  615. certPathCheckers = new ArrayList(certPathCheckers);
  616. }
  617. return copy;
  618. } catch (CloneNotSupportedException e) {
  619. /* Cannot happen */
  620. throw new InternalError(e.toString());
  621. }
  622. }
  623. /**
  624. * Returns a formatted string describing the parameters.
  625. *
  626. * @return a formatted string describing the parameters.
  627. */
  628. public String toString() {
  629. StringBuffer sb = new StringBuffer();
  630. sb.append("[\n");
  631. /* start with trusted anchor info */
  632. if (unmodTrustAnchors != null) {
  633. sb.append(" Trust Anchors: " + unmodTrustAnchors.toString()
  634. + "\n");
  635. }
  636. /* now, append initial state information */
  637. if (unmodInitialPolicies != null) {
  638. if (unmodInitialPolicies.isEmpty()) {
  639. sb.append(" Initial Policy OIDs: any\n");
  640. } else {
  641. sb.append(" Initial Policy OIDs: ["
  642. + unmodInitialPolicies.toString() + "]\n");
  643. }
  644. }
  645. /* now, append constraints on all certificates in the path */
  646. sb.append(" Validity Date: " + String.valueOf(date) + "\n");
  647. sb.append(" Signature Provider: " + String.valueOf(sigProvider) + "\n");
  648. sb.append(" Default Revocation Enabled: " + revocationEnabled + "\n");
  649. sb.append(" Explicit Policy Required: " + explicitPolicyRequired + "\n");
  650. sb.append(" Policy Mapping Inhibited: " + policyMappingInhibited + "\n");
  651. sb.append(" Any Policy Inhibited: " + anyPolicyInhibited + "\n");
  652. sb.append(" Policy Qualifiers Rejected: " + policyQualifiersRejected + "\n");
  653. /* now, append target cert requirements */
  654. sb.append(" Target Cert Constraints: " + String.valueOf(certSelector) + "\n");
  655. /* finally, append miscellaneous parameters */
  656. if (certPathCheckers != null)
  657. sb.append(" Certification Path Checkers: ["
  658. + certPathCheckers.toString() + "]\n");
  659. if (certStores != null)
  660. sb.append(" CertStores: [" + certStores.toString() + "]\n");
  661. sb.append("]");
  662. return sb.toString();
  663. }
  664. }