src/java.base/share/classes/sun/security/provider/certpath/ForwardState.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 25859 jdk/src/java.base/share/classes/sun/security/provider/certpath/ForwardState.java@3317bb8137f4
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10419
diff changeset
     2
 * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package 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.security.cert.CertificateException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.security.cert.CertPathValidatorException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.security.cert.PKIXCertPathChecker;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.security.cert.X509Certificate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.HashSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.ListIterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import javax.security.auth.x500.X500Principal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import sun.security.util.Debug;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import sun.security.x509.SubjectAlternativeNameExtension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import sun.security.x509.GeneralNames;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import sun.security.x509.GeneralName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import sun.security.x509.GeneralNameInterface;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import sun.security.x509.X500Name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import sun.security.x509.X509CertImpl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * A specification of a forward PKIX validation state
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * which is initialized by each build and updated each time a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * certificate is added to the current path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * @since       1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * @author      Yassir Elley
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
class ForwardState implements State {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private static final Debug debug = Debug.getInstance("certpath");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    /* The issuer DN of the last cert in the path */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    X500Principal issuerDN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    /* The last cert in the path */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    X509CertImpl cert;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    /* The set of subjectDNs and subjectAltNames of all certs in the path */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    HashSet<GeneralNameInterface> subjectNamesTraversed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * The number of intermediate CA certs which have been traversed so
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * far in the path
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    int traversedCACerts;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    /* Flag indicating if state is initial (path is just starting) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    private boolean init = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
11900
9b1d5bef8038 7123519: problems with certification path
xuelei
parents: 5506
diff changeset
    77
    /* the untrusted certificates checker */
9b1d5bef8038 7123519: problems with certification path
xuelei
parents: 5506
diff changeset
    78
    UntrustedChecker untrustedChecker;
9b1d5bef8038 7123519: problems with certification path
xuelei
parents: 5506
diff changeset
    79
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    /* The list of user-defined checkers that support forward checking */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    ArrayList<PKIXCertPathChecker> forwardCheckers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    /* Flag indicating if key needing to inherit key parameters has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * encountered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    boolean keyParamsNeededFlag = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * Returns a boolean flag indicating if the state is initial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * (just starting)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * @return boolean flag indicating if the state is initial (just starting)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     */
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10419
diff changeset
    94
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    public boolean isInitial() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        return init;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * Return boolean flag indicating whether a public key that needs to inherit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * key parameters has been encountered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * @return boolean true if key needing to inherit parameters has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * encountered; false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     */
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10419
diff changeset
   106
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    public boolean keyParamsNeeded() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        return keyParamsNeededFlag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * Display state for debugging purposes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     */
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10419
diff changeset
   114
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    public String toString() {
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10419
diff changeset
   116
        StringBuilder sb = new StringBuilder();
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10419
diff changeset
   117
        sb.append("State [");
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10419
diff changeset
   118
        sb.append("\n  issuerDN of last cert: ").append(issuerDN);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10419
diff changeset
   119
        sb.append("\n  traversedCACerts: ").append(traversedCACerts);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10419
diff changeset
   120
        sb.append("\n  init: ").append(String.valueOf(init));
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10419
diff changeset
   121
        sb.append("\n  keyParamsNeeded: ").append
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10419
diff changeset
   122
                 (String.valueOf(keyParamsNeededFlag));
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10419
diff changeset
   123
        sb.append("\n  subjectNamesTraversed: \n").append
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10419
diff changeset
   124
                 (subjectNamesTraversed);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10419
diff changeset
   125
        sb.append("]\n");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        return sb.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * Initialize the state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * @param certPathCheckers the list of user-defined PKIXCertPathCheckers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    public void initState(List<PKIXCertPathChecker> certPathCheckers)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        throws CertPathValidatorException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        subjectNamesTraversed = new HashSet<GeneralNameInterface>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        traversedCACerts = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
         * Populate forwardCheckers with every user-defined checker
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
         * that supports forward checking and initialize the forwardCheckers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        forwardCheckers = new ArrayList<PKIXCertPathChecker>();
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10419
diff changeset
   145
        for (PKIXCertPathChecker checker : certPathCheckers) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10419
diff changeset
   146
            if (checker.isForwardCheckingSupported()) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10419
diff changeset
   147
                checker.init(true);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10419
diff changeset
   148
                forwardCheckers.add(checker);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        init = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * Update the state with the next certificate added to the path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * @param cert the certificate which is used to update the state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     */
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10419
diff changeset
   160
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    public void updateState(X509Certificate cert)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        throws CertificateException, IOException, CertPathValidatorException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        if (cert == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        X509CertImpl icert = X509CertImpl.toImpl(cert);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        /* see if certificate key has null parameters */
13806
b18118646a65 7195409: CertPath/CertPathValidatorTest/KeyParamsInheritanceTest fails with NullPointerException
mullan
parents: 12861
diff changeset
   170
        if (PKIX.isDSAPublicKeyWithoutParams(icert.getPublicKey())) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            keyParamsNeededFlag = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        /* update certificate */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        this.cert = icert;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        /* update issuer DN */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        issuerDN = cert.getIssuerX500Principal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        if (!X509CertImpl.isSelfIssued(cert)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
             * update traversedCACerts only if this is a non-self-issued
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
             * intermediate CA cert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            if (!init && cert.getBasicConstraints() != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                traversedCACerts++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        /* update subjectNamesTraversed only if this is the EE cert or if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
           this cert is not self-issued */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        if (init || !X509CertImpl.isSelfIssued(cert)){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            X500Principal subjName = cert.getSubjectX500Principal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            subjectNamesTraversed.add(X500Name.asX500Name(subjName));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                SubjectAlternativeNameExtension subjAltNameExt
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                    = icert.getSubjectAlternativeNameExtension();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                if (subjAltNameExt != null) {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   201
                    GeneralNames gNames = subjAltNameExt.get(
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   202
                            SubjectAlternativeNameExtension.SUBJECT_NAME);
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10419
diff changeset
   203
                    for (GeneralName gName : gNames.names()) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10419
diff changeset
   204
                        subjectNamesTraversed.add(gName.getName());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                }
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10419
diff changeset
   207
            } catch (IOException e) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                    debug.println("ForwardState.updateState() unexpected "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                        + "exception");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                    e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                throw new CertPathValidatorException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        init = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * Clone current state. The state is cloned as each cert is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * added to the path. This is necessary if backtracking occurs,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * and a prior state needs to be restored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * Note that this is a SMART clone. Not all fields are fully copied,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * because some of them will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * not have their contents modified by subsequent calls to updateState.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     */
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10419
diff changeset
   229
    @Override
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   230
    @SuppressWarnings("unchecked") // Safe casts assuming clone() works correctly
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    public Object clone() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            ForwardState clonedState = (ForwardState) super.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            /* clone checkers, if cloneable */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            clonedState.forwardCheckers = (ArrayList<PKIXCertPathChecker>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                                                forwardCheckers.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            ListIterator<PKIXCertPathChecker> li =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                                clonedState.forwardCheckers.listIterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            while (li.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                PKIXCertPathChecker checker = li.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                if (checker instanceof Cloneable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                    li.set((PKIXCertPathChecker)checker.clone());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
             * Shallow copy traversed names. There is no need to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
             * deep copy contents, since the elements of the Set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
             * are never modified by subsequent calls to updateState().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            clonedState.subjectNamesTraversed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                = (HashSet<GeneralNameInterface>)subjectNamesTraversed.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            return clonedState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        } catch (CloneNotSupportedException e) {
10419
12c063b39232 7084245: Update usages of InternalError to use exception chaining
sherman
parents: 10336
diff changeset
   256
            throw new InternalError(e.toString(), e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
}