jdk/src/share/classes/sun/security/provider/certpath/ForwardBuilder.java
author xuelei
Tue, 18 Aug 2009 20:47:13 -0700
changeset 4190 227655c2ff8c
parent 3225 023603ebeb1f
child 4209 e2e5a973b879
permissions -rw-r--r--
6861062: Disable MD2 support Reviewed-by: mullan, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
3225
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
     2
 * Copyright 2000-2009 Sun Microsystems, Inc.  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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
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 sun.security.provider.certpath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.security.GeneralSecurityException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.security.InvalidKeyException;
3225
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
    33
import java.security.cert.Certificate;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.security.cert.CertificateException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.security.cert.CertPathValidatorException;
1238
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents: 792
diff changeset
    36
import java.security.cert.PKIXReason;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.security.cert.CertStore;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.security.cert.CertStoreException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.security.cert.PKIXBuilderParameters;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.security.cert.PKIXCertPathChecker;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.security.cert.TrustAnchor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.security.cert.X509Certificate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.security.cert.X509CertSelector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import javax.security.auth.x500.X500Principal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import sun.security.util.Debug;
3225
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
    47
import sun.security.util.DerOutputStream;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import sun.security.x509.AccessDescription;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import sun.security.x509.AuthorityInfoAccessExtension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import sun.security.x509.PKIXExtensions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import sun.security.x509.PolicyMappingsExtension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import sun.security.x509.X500Name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import sun.security.x509.X509CertImpl;
3225
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
    54
import sun.security.x509.X509CRLImpl;
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
    55
import sun.security.x509.AuthorityKeyIdentifierExtension;
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
    56
import sun.security.x509.KeyIdentifier;
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
    57
import sun.security.x509.SubjectKeyIdentifierExtension;
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
    58
import sun.security.x509.SerialNumber;
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
    59
import sun.security.x509.GeneralNames;
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
    60
import sun.security.x509.GeneralName;
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
    61
import sun.security.x509.GeneralNameInterface;
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
    62
import java.math.BigInteger;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * This class represents a forward builder, which is able to retrieve
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * matching certificates from CertStores and verify a particular certificate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * against a ForwardState.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * @since       1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * @author      Yassir Elley
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * @author      Sean Mullan
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
class ForwardBuilder extends Builder {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    private static final Debug debug = Debug.getInstance("certpath");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    private final Set<X509Certificate> trustedCerts;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    private final Set<X500Principal> trustedSubjectDNs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    private final Set<TrustAnchor> trustAnchors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    private X509CertSelector eeSelector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    private X509CertSelector caSelector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    private X509CertSelector caTargetSelector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    TrustAnchor trustAnchor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    private Comparator<X509Certificate> comparator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    private boolean searchAllCertStores = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * Initialize the builder with the input parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * @param params the parameter set used to build a certification path
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    ForwardBuilder(PKIXBuilderParameters buildParams,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        X500Principal targetSubjectDN, boolean searchAllCertStores)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        super(buildParams, targetSubjectDN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        // populate sets of trusted certificates and subject DNs
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        trustAnchors = buildParams.getTrustAnchors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        trustedCerts = new HashSet<X509Certificate>(trustAnchors.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        trustedSubjectDNs = new HashSet<X500Principal>(trustAnchors.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        for (TrustAnchor anchor : trustAnchors) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            X509Certificate trustedCert = anchor.getTrustedCert();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            if (trustedCert != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                trustedCerts.add(trustedCert);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                trustedSubjectDNs.add(trustedCert.getSubjectX500Principal());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                trustedSubjectDNs.add(anchor.getCA());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        comparator = new PKIXCertComparator(trustedSubjectDNs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        this.searchAllCertStores = searchAllCertStores;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * Retrieves all certs from the specified CertStores that satisfy the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * requirements specified in the parameters and the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * PKIX state (name constraints, policy constraints, etc).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * @param currentState the current state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     *        Must be an instance of <code>ForwardState</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * @param certStores list of CertStores
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    Collection<X509Certificate> getMatchingCerts
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        (State currentState, List<CertStore> certStores)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        throws CertStoreException, CertificateException, IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            debug.println("ForwardBuilder.getMatchingCerts()...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        ForwardState currState = (ForwardState) currentState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
         * We store certs in a Set because we don't want duplicates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
         * As each cert is added, it is sorted based on the PKIXCertComparator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
         * algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        Set<X509Certificate> certs = new TreeSet<X509Certificate>(comparator);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
         * Only look for EE certs if search has just started.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        if (currState.isInitial()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            getMatchingEECerts(currState, certStores, certs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        getMatchingCACerts(currState, certStores, certs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        return certs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * Retrieves all end-entity certificates which satisfy constraints
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * and requirements specified in the parameters and PKIX state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    private void getMatchingEECerts(ForwardState currentState,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        List<CertStore> certStores, Collection<X509Certificate> eeCerts)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            debug.println("ForwardBuilder.getMatchingEECerts()...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
         * Compose a certificate matching rule to filter out
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
         * certs which don't satisfy constraints
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
         * First, retrieve clone of current target cert constraints,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
         * and then add more selection criteria based on current validation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
         * state. Since selector never changes, cache local copy & reuse.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        if (eeSelector == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            eeSelector = (X509CertSelector) targetCertConstraints.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
             * Match on certificate validity date
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            eeSelector.setCertificateValid(date);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
             * Policy processing optimizations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            if (buildParams.isExplicitPolicyRequired()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                eeSelector.setPolicy(getMatchingPolicies());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
             * Require EE certs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            eeSelector.setBasicConstraints(-2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        /* Retrieve matching EE certs from CertStores */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        addMatchingCerts(eeSelector, certStores, eeCerts, searchAllCertStores);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * Retrieves all CA certificates which satisfy constraints
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * and requirements specified in the parameters and PKIX state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    private void getMatchingCACerts(ForwardState currentState,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        List<CertStore> certStores, Collection<X509Certificate> caCerts)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            debug.println("ForwardBuilder.getMatchingCACerts()...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        int initialSize = caCerts.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
         * Compose a CertSelector to filter out
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
         * certs which do not satisfy requirements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        X509CertSelector sel = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        if (currentState.isInitial()) {
792
214933bde360 6714842: CertPathBuilder returns incorrect CertPath for BasicConstraints in builderParams
mullan
parents: 2
diff changeset
   213
            if (targetCertConstraints.getBasicConstraints() == -2) {
214933bde360 6714842: CertPathBuilder returns incorrect CertPath for BasicConstraints in builderParams
mullan
parents: 2
diff changeset
   214
                // no need to continue: this means we never can match a CA cert
214933bde360 6714842: CertPathBuilder returns incorrect CertPath for BasicConstraints in builderParams
mullan
parents: 2
diff changeset
   215
                return;
214933bde360 6714842: CertPathBuilder returns incorrect CertPath for BasicConstraints in builderParams
mullan
parents: 2
diff changeset
   216
            }
214933bde360 6714842: CertPathBuilder returns incorrect CertPath for BasicConstraints in builderParams
mullan
parents: 2
diff changeset
   217
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            /* This means a CA is the target, so match on same stuff as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
             * getMatchingEECerts
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                debug.println("ForwardBuilder.getMatchingCACerts(): ca is target");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            if (caTargetSelector == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                caTargetSelector = (X509CertSelector)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                    targetCertConstraints.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                 * Match on certificate validity date
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                caTargetSelector.setCertificateValid(date);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                 * Policy processing optimizations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                if (buildParams.isExplicitPolicyRequired())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                    caTargetSelector.setPolicy(getMatchingPolicies());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
             * Require CA certs with a pathLenConstraint that allows
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
             * at least as many CA certs that have already been traversed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            caTargetSelector.setBasicConstraints(currentState.traversedCACerts);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            sel = caTargetSelector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            if (caSelector == null) {
3225
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   251
                caSelector = new AdaptableX509CertSelector();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                 * Match on certificate validity date.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                caSelector.setCertificateValid(date);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                 * Policy processing optimizations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                if (buildParams.isExplicitPolicyRequired())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                    caSelector.setPolicy(getMatchingPolicies());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
             * Match on subject (issuer of previous cert)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            caSelector.setSubject(currentState.issuerDN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
             * Match on subjectNamesTraversed (both DNs and AltNames)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
             * (checks that current cert's name constraints permit it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
             * to certify all the DNs and AltNames that have been traversed)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            CertPathHelper.setPathToNames
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                (caSelector, currentState.subjectNamesTraversed);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
             * Require CA certs with a pathLenConstraint that allows
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
             * at least as many CA certs that have already been traversed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            caSelector.setBasicConstraints(currentState.traversedCACerts);
3225
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   283
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   284
            /*
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   285
             * Facilitate certification path construction with authority
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   286
             * key identifier and subject key identifier.
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   287
             */
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   288
            AuthorityKeyIdentifierExtension akidext =
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   289
                    currentState.cert.getAuthorityKeyIdentifierExtension();
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   290
            if (akidext != null) {
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   291
                KeyIdentifier akid = (KeyIdentifier)akidext.get(akidext.KEY_ID);
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   292
                if (akid != null) {
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   293
                    DerOutputStream derout = new DerOutputStream();
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   294
                    derout.putOctetString(akid.getIdentifier());
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   295
                    caSelector.setSubjectKeyIdentifier(derout.toByteArray());
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   296
                }
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   297
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   298
                SerialNumber asn =
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   299
                    (SerialNumber)akidext.get(akidext.SERIAL_NUMBER);
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   300
                if (asn != null) {
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   301
                    caSelector.setSerialNumber(asn.getNumber());
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   302
                }
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   303
                // the subject criterion was set previously.
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   304
            }
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   305
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            sel = caSelector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
         * Check if any of the trusted certs could be a match.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
         * Since we are not validating the trusted cert, we can't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
         * re-use the selector we've built up (sel) - we need
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
         * to use a new selector (trustedSel)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        X509CertSelector trustedSel = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        if (currentState.isInitial()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            trustedSel = targetCertConstraints;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            trustedSel = new X509CertSelector();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            trustedSel.setSubject(currentState.issuerDN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        boolean foundMatchingCert = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        for (X509Certificate trustedCert : trustedCerts) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            if (trustedSel.match(trustedCert)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                    debug.println("ForwardBuilder.getMatchingCACerts: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                        + "found matching trust anchor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                if (caCerts.add(trustedCert) && !searchAllCertStores) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
         * If we have already traversed as many CA certs as the maxPathLength
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
         * will allow us to, then we don't bother looking through these
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
         * certificate pairs. If maxPathLength has a value of -1, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
         * means it is unconstrained, so we always look through the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
         * certificate pairs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        if (currentState.isInitial() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
           (buildParams.getMaxPathLength() == -1) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
           (buildParams.getMaxPathLength() > currentState.traversedCACerts))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            if (addMatchingCerts(sel, certStores, caCerts, searchAllCertStores)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                && !searchAllCertStores) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        if (!currentState.isInitial() && Builder.USE_AIA) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            // check for AuthorityInformationAccess extension
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            AuthorityInfoAccessExtension aiaExt =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                currentState.cert.getAuthorityInfoAccessExtension();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            if (aiaExt != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                getCerts(aiaExt, caCerts);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            int numCerts = caCerts.size() - initialSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            debug.println("ForwardBuilder.getMatchingCACerts: found " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                numCerts + " CA certs");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        }
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
     * Download Certificates from the given AIA and add them to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * specified Collection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    private boolean getCerts(AuthorityInfoAccessExtension aiaExt,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        Collection<X509Certificate> certs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        if (Builder.USE_AIA == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        List<AccessDescription> adList = aiaExt.getAccessDescriptions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        if (adList == null || adList.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        boolean add = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        for (AccessDescription ad : adList) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            CertStore cs = URICertStore.getInstance(ad);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                if (certs.addAll((Collection<X509Certificate>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                    cs.getCertificates(caSelector))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                    add = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                    if (!searchAllCertStores) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            } catch (CertStoreException cse) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                    debug.println("exception getting certs from CertStore:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                    cse.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        return add;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * This inner class compares 2 PKIX certificates according to which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * should be tried first when building a path from the target.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * The preference order is as follows:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * Given trusted certificate(s):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     *    Subject:ou=D,ou=C,o=B,c=A
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * Preference order for current cert:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * 1) Issuer matches a trusted subject
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     *    Issuer: ou=D,ou=C,o=B,c=A
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * 2) Issuer is a descendant of a trusted subject (in order of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     *    number of links to the trusted subject)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     *    a) Issuer: ou=E,ou=D,ou=C,o=B,c=A        [links=1]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     *    b) Issuer: ou=F,ou=E,ou=D,ou=C,ou=B,c=A  [links=2]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * 3) Issuer is an ancestor of a trusted subject (in order of number of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     *    links to the trusted subject)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     *    a) Issuer: ou=C,o=B,c=A [links=1]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     *    b) Issuer: o=B,c=A      [links=2]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     * 4) Issuer is in the same namespace as a trusted subject (in order of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     *    number of links to the trusted subject)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     *    a) Issuer: ou=G,ou=C,o=B,c=A  [links=2]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     *    b) Issuer: ou=H,o=B,c=A       [links=3]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * 5) Issuer is an ancestor of certificate subject (in order of number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     *    of links to the certificate subject)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     *    a) Issuer:  ou=K,o=J,c=A
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     *       Subject: ou=L,ou=K,o=J,c=A
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     *    b) Issuer:  o=J,c=A
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     *       Subject: ou=L,ou=K,0=J,c=A
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * 6) Any other certificates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    static class PKIXCertComparator implements Comparator<X509Certificate> {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        final static String METHOD_NME = "PKIXCertComparator.compare()";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        private final Set<X500Principal> trustedSubjectDNs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        PKIXCertComparator(Set<X500Principal> trustedSubjectDNs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            this.trustedSubjectDNs = trustedSubjectDNs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
         * @param oCert1 First X509Certificate to be compared
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
         * @param oCert2 Second X509Certificate to be compared
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
         * @return -1 if oCert1 is preferable to oCert2, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
         *            if oCert1 and oCert2 are equally preferable (in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
         *            case it doesn't matter which is preferable, but we don't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
         *            return 0 because the comparator would behave strangely
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
         *            when used in a SortedSet).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
         *          1 if oCert2 is preferable to oCert1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
         *          0 if oCert1.equals(oCert2). We only return 0 if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
         *          certs are equal so that this comparator behaves
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
         *          correctly when used in a SortedSet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
         * @throws ClassCastException if either argument is not of type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
         * X509Certificate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        public int compare(X509Certificate oCert1, X509Certificate oCert2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            // if certs are the same, return 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
            if (oCert1.equals(oCert2)) return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            X500Principal cIssuer1 = oCert1.getIssuerX500Principal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            X500Principal cIssuer2 = oCert2.getIssuerX500Principal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
            X500Name cIssuer1Name = X500Name.asX500Name(cIssuer1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            X500Name cIssuer2Name = X500Name.asX500Name(cIssuer2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                debug.println(METHOD_NME + " o1 Issuer:  " + cIssuer1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                debug.println(METHOD_NME + " o2 Issuer:  " + cIssuer2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
            /* If one cert's issuer matches a trusted subject, then it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
             * preferable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                debug.println(METHOD_NME + " MATCH TRUSTED SUBJECT TEST...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
            boolean m1 = trustedSubjectDNs.contains(cIssuer1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            boolean m2 = trustedSubjectDNs.contains(cIssuer2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
            if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                debug.println(METHOD_NME + " m1: " + m1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
                debug.println(METHOD_NME + " m2: " + m2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
            if (m1 && m2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
            } else if (m1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
            } else if (m2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
            /* If one cert's issuer is a naming descendant of a trusted subject,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
             * then it is preferable, in order of increasing naming distance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
            if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                debug.println(METHOD_NME + " NAMING DESCENDANT TEST...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
            for (X500Principal tSubject : trustedSubjectDNs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                X500Name tSubjectName = X500Name.asX500Name(tSubject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                int distanceTto1 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                    Builder.distance(tSubjectName, cIssuer1Name, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                int distanceTto2 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                    Builder.distance(tSubjectName, cIssuer2Name, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                    debug.println(METHOD_NME +" distanceTto1: " + distanceTto1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
                    debug.println(METHOD_NME +" distanceTto2: " + distanceTto2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
                if (distanceTto1 > 0 || distanceTto2 > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
                    if (distanceTto1 == distanceTto2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                    } else if (distanceTto1 > 0 && distanceTto2 <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                    } else if (distanceTto1 <= 0 && distanceTto2 > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                        return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                    } else if (distanceTto1 < distanceTto2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                    } else {    // distanceTto1 > distanceTto2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                        return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
            /* If one cert's issuer is a naming ancestor of a trusted subject,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
             * then it is preferable, in order of increasing naming distance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
            if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                debug.println(METHOD_NME + " NAMING ANCESTOR TEST...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
            for (X500Principal tSubject : trustedSubjectDNs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                X500Name tSubjectName = X500Name.asX500Name(tSubject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                int distanceTto1 = Builder.distance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                    (tSubjectName, cIssuer1Name, Integer.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                int distanceTto2 = Builder.distance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                    (tSubjectName, cIssuer2Name, Integer.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                    debug.println(METHOD_NME +" distanceTto1: " + distanceTto1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                    debug.println(METHOD_NME +" distanceTto2: " + distanceTto2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                if (distanceTto1 < 0 || distanceTto2 < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                    if (distanceTto1 == distanceTto2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                    } else if (distanceTto1 < 0 && distanceTto2 >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                    } else if (distanceTto1 >= 0 && distanceTto2 < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                        return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                    } else if (distanceTto1 > distanceTto2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                        return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
            /* If one cert's issuer is in the same namespace as a trusted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
             * subject, then it is preferable, in order of increasing naming
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
             * distance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
            if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                debug.println(METHOD_NME +" SAME NAMESPACE AS TRUSTED TEST...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
            for (X500Principal tSubject : trustedSubjectDNs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                X500Name tSubjectName = X500Name.asX500Name(tSubject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                X500Name tAo1 = tSubjectName.commonAncestor(cIssuer1Name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
                X500Name tAo2 = tSubjectName.commonAncestor(cIssuer2Name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
                    debug.println(METHOD_NME +" tAo1: " + String.valueOf(tAo1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
                    debug.println(METHOD_NME +" tAo2: " + String.valueOf(tAo2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                if (tAo1 != null || tAo2 != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                    if (tAo1 != null && tAo2 != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                        int hopsTto1 = Builder.hops
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                            (tSubjectName, cIssuer1Name, Integer.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
                        int hopsTto2 = Builder.hops
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                            (tSubjectName, cIssuer2Name, Integer.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
                        if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                            debug.println(METHOD_NME +" hopsTto1: " + hopsTto1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                            debug.println(METHOD_NME +" hopsTto2: " + hopsTto2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
                        if (hopsTto1 == hopsTto2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
                        } else if (hopsTto1 > hopsTto2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                            return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
                        } else {  // hopsTto1 < hopsTto2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
                            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
                    } else if (tAo1 == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
                        return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
                        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
                    }
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
            /* If one cert's issuer is an ancestor of that cert's subject,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
             * then it is preferable, in order of increasing naming distance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                debug.println(METHOD_NME+" CERT ISSUER/SUBJECT COMPARISON TEST...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
            X500Principal cSubject1 = oCert1.getSubjectX500Principal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
            X500Principal cSubject2 = oCert2.getSubjectX500Principal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
            X500Name cSubject1Name = X500Name.asX500Name(cSubject1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
            X500Name cSubject2Name = X500Name.asX500Name(cSubject2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
            if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
                debug.println(METHOD_NME + " o1 Subject: " + cSubject1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
                debug.println(METHOD_NME + " o2 Subject: " + cSubject2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
            int distanceStoI1 = Builder.distance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
                (cSubject1Name, cIssuer1Name, Integer.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
            int distanceStoI2 = Builder.distance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
                (cSubject2Name, cIssuer2Name, Integer.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
            if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
                debug.println(METHOD_NME + " distanceStoI1: " + distanceStoI1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
                debug.println(METHOD_NME + " distanceStoI2: " + distanceStoI2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
            if (distanceStoI2 > distanceStoI1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
                return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
            } else if (distanceStoI2 < distanceStoI1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
                return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
            /* Otherwise, certs are equally preferable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
            if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
                debug.println(METHOD_NME + " no tests matched; RETURN 0");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     * Verifies a matching certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     * This method executes the validation steps in the PKIX path
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     * validation algorithm <draft-ietf-pkix-new-part1-08.txt> which were
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     * not satisfied by the selection criteria used by getCertificates()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     * to find the certs and only the steps that can be executed in a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
     * forward direction (target to trust anchor). Those steps that can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
     * only be executed in a reverse direction are deferred until the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     * complete path has been built.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     * Trust anchor certs are not validated, but are used to verify the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
     * signature and revocation status of the previous cert.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     * If the last certificate is being verified (the one whose subject
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     * matches the target subject, then steps in 6.1.4 of the PKIX
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     * Certification Path Validation algorithm are NOT executed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
     * regardless of whether or not the last cert is an end-entity
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
     * cert or not. This allows callers to certify CA certs as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
     * well as EE certs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     * @param cert the certificate to be verified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     * @param currentState the current state against which the cert is verified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     * @param certPathList the certPathList generated thus far
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
    void verifyCert(X509Certificate cert, State currentState,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        List<X509Certificate> certPathList) throws GeneralSecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
        if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
            debug.println("ForwardBuilder.verifyCert(SN: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
                + Debug.toHexString(cert.getSerialNumber())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
                + "\n  Issuer: " + cert.getIssuerX500Principal() + ")"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
                + "\n  Subject: " + cert.getSubjectX500Principal() + ")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
        ForwardState currState = (ForwardState) currentState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
         * check for looping - abort a loop if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
         * ((we encounter the same certificate twice) AND
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
         * ((policyMappingInhibited = true) OR (no policy mapping
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
         * extensions can be found between the occurences of the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
         * certificate)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
        if (certPathList != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
            boolean policyMappingFound = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
            for (X509Certificate cpListCert : certPathList) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
                X509CertImpl cpListCertImpl = X509CertImpl.toImpl(cpListCert);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
                PolicyMappingsExtension policyMappingsExt
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
                    = cpListCertImpl.getPolicyMappingsExtension();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
                if (policyMappingsExt != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
                    policyMappingFound = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
                if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
                    debug.println("policyMappingFound = " + policyMappingFound);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
                if (cert.equals(cpListCert)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
                    if ((buildParams.isPolicyMappingInhibited()) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
                        (!policyMappingFound)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
                        if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
                            debug.println("loop detected!!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
                        throw new CertPathValidatorException("loop detected");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
        /* check if trusted cert */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
        boolean isTrustedCert = trustedCerts.contains(cert);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
        /* we don't perform any validation of the trusted cert */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        if (!isTrustedCert) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
            /*
4190
227655c2ff8c 6861062: Disable MD2 support
xuelei
parents: 3225
diff changeset
   719
             * check that the signature algorithm is not disabled.
227655c2ff8c 6861062: Disable MD2 support
xuelei
parents: 3225
diff changeset
   720
             */
227655c2ff8c 6861062: Disable MD2 support
xuelei
parents: 3225
diff changeset
   721
            AlgorithmChecker.check(cert);
227655c2ff8c 6861062: Disable MD2 support
xuelei
parents: 3225
diff changeset
   722
227655c2ff8c 6861062: Disable MD2 support
xuelei
parents: 3225
diff changeset
   723
            /*
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
             * Check CRITICAL private extensions for user checkers that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
             * support forward checking (forwardCheckers) and remove
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
             * ones we know how to check.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
            Set<String> unresCritExts = cert.getCriticalExtensionOIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
            if (unresCritExts == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
                unresCritExts = Collections.<String>emptySet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
            for (PKIXCertPathChecker checker : currState.forwardCheckers) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
                checker.check(cert, unresCritExts);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
             * Remove extensions from user checkers that don't support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
             * forward checking. After this step, we will have removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
             * all extensions that all user checkers are capable of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
             * processing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
            for (PKIXCertPathChecker checker : buildParams.getCertPathCheckers()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
                if (!checker.isForwardCheckingSupported()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
                    Set<String> supportedExts = checker.getSupportedExtensions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
                    if (supportedExts != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
                        unresCritExts.removeAll(supportedExts);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
             * Look at the remaining extensions and remove any ones we know how
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
             * to check. If there are any left, throw an exception!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
            if (!unresCritExts.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
                unresCritExts.remove(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
                    PKIXExtensions.BasicConstraints_Id.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
                unresCritExts.remove(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
                    PKIXExtensions.NameConstraints_Id.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
                unresCritExts.remove(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
                    PKIXExtensions.CertificatePolicies_Id.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
                unresCritExts.remove(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
                    PKIXExtensions.PolicyMappings_Id.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
                unresCritExts.remove(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
                    PKIXExtensions.PolicyConstraints_Id.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
                unresCritExts.remove(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
                    PKIXExtensions.InhibitAnyPolicy_Id.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
                unresCritExts.remove(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
                    PKIXExtensions.SubjectAlternativeName_Id.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
                unresCritExts.remove(PKIXExtensions.KeyUsage_Id.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
                unresCritExts.remove(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
                    PKIXExtensions.ExtendedKeyUsage_Id.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
                if (!unresCritExts.isEmpty())
1238
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents: 792
diff changeset
   775
                    throw new CertPathValidatorException
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents: 792
diff changeset
   776
                        ("Unrecognized critical extension(s)", null, null, -1,
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents: 792
diff changeset
   777
                         PKIXReason.UNRECOGNIZED_CRIT_EXT);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
         * if this is the target certificate (init=true), then we are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
         * not able to do any more verification, so just return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
        if (currState.isInitial()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
        /* we don't perform any validation of the trusted cert */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
        if (!isTrustedCert) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
            /* Make sure this is a CA cert */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
            if (cert.getBasicConstraints() == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
                throw new CertificateException("cert is NOT a CA cert");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
             * Check keyUsage extension
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
            KeyChecker.verifyCAKeyUsage(cert);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
         * the following checks are performed even when the cert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
         * is a trusted cert, since we are only extracting the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
         * subjectDN, and publicKey from the cert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
         * in order to verify a previous cert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
         * Check revocation for the previous cert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
        if (buildParams.isRevocationEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
            // first off, see if this cert can authorize revocation...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
            if (CrlRevocationChecker.certCanSignCrl(cert)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
                // And then check to be sure no key requiring key parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
                // has been encountered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
                if (!currState.keyParamsNeeded())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
                    // If all that checks out, we can check the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
                    // revocation status of the cert. Otherwise,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
                    // we'll just wait until the end.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
                    currState.crlChecker.check(currState.cert,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
                                               cert.getPublicKey(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
                                               true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
         * Check signature only if no key requiring key parameters has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
         * encountered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
        if (!currState.keyParamsNeeded()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
            (currState.cert).verify(cert.getPublicKey(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
                                    buildParams.getSigProvider());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
     * Verifies whether the input certificate completes the path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
     * Checks the cert against each trust anchor that was specified, in order,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
     * and returns true as soon as it finds a valid anchor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
     * Returns true if the cert matches a trust anchor specified as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
     * certificate or if the cert verifies with a trust anchor that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
     * was specified as a trusted {pubkey, caname} pair. Returns false if none
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
     * of the trust anchors are valid for this cert.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
     * @param cert the certificate to test
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
     * @return a boolean value indicating whether the cert completes the path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
    boolean isPathCompleted(X509Certificate cert) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
        for (TrustAnchor anchor : trustAnchors) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
            if (anchor.getTrustedCert() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
                if (cert.equals(anchor.getTrustedCert())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
                    this.trustAnchor = anchor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
                }
3225
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   859
            } else {
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   860
                X500Principal principal = anchor.getCA();
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   861
                java.security.PublicKey publicKey = anchor.getCAPublicKey();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
3225
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   863
                if (principal != null && publicKey != null &&
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   864
                        principal.equals(cert.getSubjectX500Principal())) {
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   865
                    if (publicKey.equals(cert.getPublicKey())) {
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   866
                        // the cert itself is a trust anchor
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   867
                        this.trustAnchor = anchor;
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   868
                        return true;
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   869
                    }
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   870
                    // else, it is a self-issued certificate of the anchor
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   871
                }
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   872
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   873
                // Check subject/issuer name chaining
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   874
                if (principal == null ||
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   875
                        !principal.equals(cert.getIssuerX500Principal())) {
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   876
                    continue;
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   877
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
            /* Check revocation if it is enabled */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
            if (buildParams.isRevocationEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
                    CrlRevocationChecker crlChecker =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
                        new CrlRevocationChecker(anchor, buildParams);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
                    crlChecker.check(cert, anchor.getCAPublicKey(), true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
                } catch (CertPathValidatorException cpve) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
                    if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
                        debug.println("ForwardBuilder.isPathCompleted() cpve");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
                        cpve.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
             * Check signature
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
                // NOTE: the DSA public key in the buildParams may lack
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
                // parameters, yet there is no key to inherit the parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
                // from.  This is probably such a rare case that it is not worth
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
                // trying to detect the situation earlier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
                cert.verify(anchor.getCAPublicKey(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
                            buildParams.getSigProvider());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
            } catch (InvalidKeyException ike) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
                if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
                    debug.println("ForwardBuilder.isPathCompleted() invalid "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
                        + "DSA key found");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
            } catch (Exception e){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
                if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
                    debug.println("ForwardBuilder.isPathCompleted() " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
                        "unexpected exception");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
                    e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
            this.trustAnchor = anchor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
    /** Adds the certificate to the certPathList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
     * @param cert the certificate to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
     * @param certPathList the certification path list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
    void addCertToPath(X509Certificate cert,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
        LinkedList<X509Certificate> certPathList) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
        certPathList.addFirst(cert);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
    /** Removes final certificate from the certPathList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
     * @param certPathList the certification path list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
    void removeFinalCertFromPath(LinkedList<X509Certificate> certPathList) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
        certPathList.removeFirst();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
    }
3225
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   944
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   945
    /** Verifies whether a CRL is issued by a certain certificate
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   946
     *
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   947
     * @param cert the certificate
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   948
     * @param crl the CRL to be verified
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   949
     * @param provider the name of the signature provider
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   950
     */
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   951
    static boolean issues(X509CertImpl cert, X509CRLImpl crl, String provider)
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   952
            throws IOException {
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   953
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   954
        boolean kidmatched = false;
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   955
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   956
        // check certificate's key usage
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   957
        boolean[] usages = cert.getKeyUsage();
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   958
        if (usages != null && !usages[6]) {
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   959
            return false;
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   960
        }
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   961
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   962
        // check certificate's SKID and CRL's AKID
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   963
        AuthorityKeyIdentifierExtension akidext = crl.getAuthKeyIdExtension();
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   964
        if (akidext != null) {
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   965
            // the highest priority, matching KID
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   966
            KeyIdentifier akid = (KeyIdentifier)akidext.get(akidext.KEY_ID);
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   967
            if (akid != null) {
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   968
                SubjectKeyIdentifierExtension skidext =
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   969
                            cert.getSubjectKeyIdentifierExtension();
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   970
                if (skidext != null) {
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   971
                    KeyIdentifier skid =
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   972
                            (KeyIdentifier)skidext.get(skidext.KEY_ID);
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   973
                    if (!akid.equals(skid)) {
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   974
                        return false;
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   975
                    }
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   976
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   977
                    kidmatched = true;
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   978
                }
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   979
                // conservatively, in case of X509 V1 certificate,
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   980
                // does return false here if no SKID extension.
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   981
            }
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   982
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   983
            // the medium priority, matching issuer name/serial number
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   984
            SerialNumber asn = (SerialNumber)akidext.get(akidext.SERIAL_NUMBER);
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   985
            GeneralNames anames = (GeneralNames)akidext.get(akidext.AUTH_NAME);
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   986
            if (asn != null && anames != null) {
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   987
                X500Name subject = (X500Name)cert.getSubjectDN();
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   988
                BigInteger serial = cert.getSerialNumber();
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   989
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   990
                if (serial != null && subject != null) {
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   991
                    if (serial.equals(asn.getNumber())) {
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   992
                        return false;
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   993
                    }
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   994
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   995
                    for (GeneralName name : anames.names()) {
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   996
                        GeneralNameInterface gni = name.getName();
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   997
                        if (subject.equals(gni)) {
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   998
                            return true;
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
   999
                        }
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
  1000
                    }
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
  1001
                }
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
  1002
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
  1003
                return false;
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
  1004
            }
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
  1005
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
  1006
            if (kidmatched) {
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
  1007
                return true;
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
  1008
            }
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
  1009
        }
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
  1010
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
  1011
        // the last priority, verify the CRL signature with the cert.
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
  1012
        X500Principal crlIssuer = crl.getIssuerX500Principal();
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
  1013
        X500Principal certSubject = cert.getSubjectX500Principal();
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
  1014
        if (certSubject != null && certSubject.equals(crlIssuer)) {
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
  1015
            try {
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
  1016
                crl.verify(cert.getPublicKey(), provider);
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
  1017
                return true;
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
  1018
            } catch (Exception e) {
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
  1019
                // ignore all exceptions.
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
  1020
            }
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
  1021
        }
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
  1022
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
  1023
        return false;
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
  1024
    }
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
  1025
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
  1026
    /**
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
  1027
     * An adaptable X509 certificate selector for forward certification path
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
  1028
     * building.
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
  1029
     */
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
  1030
    private static class AdaptableX509CertSelector extends X509CertSelector {
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
  1031
        public AdaptableX509CertSelector() {
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
  1032
            super();
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
  1033
        }
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
  1034
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
  1035
        /**
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
  1036
         * Decides whether a <code>Certificate</code> should be selected.
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
  1037
         *
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
  1038
         * For the purpose of compatibility, when a certificate is of
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
  1039
         * version 1 and version 2, or the certificate does not include
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
  1040
         * a subject key identifier extension, the selection criterion
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
  1041
         * of subjectKeyIdentifier will be disabled.
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
  1042
         *
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
  1043
         * @Override
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
  1044
         */
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
  1045
        public boolean match(Certificate cert) {
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
  1046
            if (!(cert instanceof X509Certificate)) {
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
  1047
                return false;
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
  1048
            }
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
  1049
            X509Certificate xcert = (X509Certificate)cert;
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
  1050
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
  1051
            if (xcert.getVersion() < 3 ||
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
  1052
                xcert.getExtensionValue("2.5.29.14") == null) {
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
  1053
                // disable the subjectKeyIdentifier criterion
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
  1054
                setSubjectKeyIdentifier(null);
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
  1055
            }
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
  1056
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
  1057
            return super.match(cert);
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
  1058
        }
023603ebeb1f 6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents: 1238
diff changeset
  1059
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
}