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