jdk/src/share/classes/sun/security/provider/certpath/ForwardState.java
author sherman
Tue, 30 Aug 2011 11:53:11 -0700
changeset 10419 12c063b39232
parent 10336 0bb1999251f8
child 12860 9ffbd4e43413
child 11902 a94ba35d9c4a
permissions -rw-r--r--
7084245: Update usages of InternalError to use exception chaining Summary: to use new InternalError constructor with cause chainning Reviewed-by: alanb, ksrini, xuelei, neugens Contributed-by: sebastian.sickelmann@gmx.de
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
     2
 * Copyright (c) 2000, 2011, 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.PublicKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.security.cert.CertificateException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.security.cert.CertPathValidatorException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.security.cert.PKIXCertPathChecker;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.security.cert.X509Certificate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.security.interfaces.DSAPublicKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.HashSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.util.Iterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.util.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.util.ListIterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import javax.security.auth.x500.X500Principal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import sun.security.util.Debug;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import sun.security.x509.SubjectAlternativeNameExtension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import sun.security.x509.GeneralNames;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import sun.security.x509.GeneralName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import sun.security.x509.GeneralNameInterface;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import sun.security.x509.X500Name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import sun.security.x509.X509CertImpl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * A specification of a forward PKIX validation state
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * which is initialized by each build and updated each time a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * certificate is added to the current path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * @since       1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * @author      Yassir Elley
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
class ForwardState implements State {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    private static final Debug debug = Debug.getInstance("certpath");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    /* The issuer DN of the last cert in the path */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    X500Principal issuerDN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    /* The last cert in the path */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    X509CertImpl cert;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    /* The set of subjectDNs and subjectAltNames of all certs in the path */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    HashSet<GeneralNameInterface> subjectNamesTraversed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * The number of intermediate CA certs which have been traversed so
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * far in the path
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    int traversedCACerts;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    /* Flag indicating if state is initial (path is just starting) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    private boolean init = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    /* the checker used for revocation status */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    public CrlRevocationChecker crlChecker;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    /* The list of user-defined checkers that support forward checking */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    ArrayList<PKIXCertPathChecker> forwardCheckers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    /* Flag indicating if key needing to inherit key parameters has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * encountered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    boolean keyParamsNeededFlag = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * Returns a boolean flag indicating if the state is initial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * (just starting)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * @return boolean flag indicating if the state is initial (just starting)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    public boolean isInitial() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        return init;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * Return boolean flag indicating whether a public key that needs to inherit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * key parameters has been encountered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * @return boolean true if key needing to inherit parameters has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * encountered; false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     */
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
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        StringBuffer sb = new StringBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            sb.append("State [");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            sb.append("\n  issuerDN of last cert: " + issuerDN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            sb.append("\n  traversedCACerts: " + traversedCACerts);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            sb.append("\n  init: " + String.valueOf(init));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            sb.append("\n  keyParamsNeeded: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                + String.valueOf(keyParamsNeededFlag));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            sb.append("\n  subjectNamesTraversed: \n" + subjectNamesTraversed);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            sb.append("]\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                debug.println("ForwardState.toString() unexpected exception");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        return sb.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * Initialize the state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * @param certPathCheckers the list of user-defined PKIXCertPathCheckers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    public void initState(List<PKIXCertPathChecker> certPathCheckers)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        throws CertPathValidatorException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        subjectNamesTraversed = new HashSet<GeneralNameInterface>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        traversedCACerts = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
         * Populate forwardCheckers with every user-defined checker
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
         * that supports forward checking and initialize the forwardCheckers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        forwardCheckers = new ArrayList<PKIXCertPathChecker>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        if (certPathCheckers != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            for (PKIXCertPathChecker checker : certPathCheckers) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                if (checker.isForwardCheckingSupported()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                    checker.init(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                    forwardCheckers.add(checker);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        init = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * Update the state with the next certificate added to the path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * @param cert the certificate which is used to update the state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    public void updateState(X509Certificate cert)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        throws CertificateException, IOException, CertPathValidatorException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        if (cert == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        X509CertImpl icert = X509CertImpl.toImpl(cert);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        /* see if certificate key has null parameters */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        PublicKey newKey = icert.getPublicKey();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        if (newKey instanceof DSAPublicKey &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            ((DSAPublicKey)newKey).getParams() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            keyParamsNeededFlag = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        /* update certificate */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        this.cert = icert;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        /* update issuer DN */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        issuerDN = cert.getIssuerX500Principal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        if (!X509CertImpl.isSelfIssued(cert)) {
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 traversedCACerts only if this is a non-self-issued
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
             * intermediate CA cert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            if (!init && cert.getBasicConstraints() != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                traversedCACerts++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        /* update subjectNamesTraversed only if this is the EE cert or if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
           this cert is not self-issued */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        if (init || !X509CertImpl.isSelfIssued(cert)){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            X500Principal subjName = cert.getSubjectX500Principal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            subjectNamesTraversed.add(X500Name.asX500Name(subjName));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                SubjectAlternativeNameExtension subjAltNameExt
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                    = icert.getSubjectAlternativeNameExtension();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                if (subjAltNameExt != null) {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   209
                    GeneralNames gNames = subjAltNameExt.get(
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   210
                            SubjectAlternativeNameExtension.SUBJECT_NAME);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                    for (Iterator<GeneralName> t = gNames.iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                                t.hasNext(); ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                        GeneralNameInterface gName = t.next().getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                        subjectNamesTraversed.add(gName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                    debug.println("ForwardState.updateState() unexpected "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                        + "exception");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                    e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                throw new CertPathValidatorException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        init = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * Clone current state. The state is cloned as each cert is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * added to the path. This is necessary if backtracking occurs,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * and a prior state needs to be restored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * Note that this is a SMART clone. Not all fields are fully copied,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * because some of them will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * not have their contents modified by subsequent calls to updateState.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     */
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   239
    @SuppressWarnings("unchecked") // Safe casts assuming clone() works correctly
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    public Object clone() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            ForwardState clonedState = (ForwardState) super.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            /* clone checkers, if cloneable */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            clonedState.forwardCheckers = (ArrayList<PKIXCertPathChecker>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                                                forwardCheckers.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            ListIterator<PKIXCertPathChecker> li =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                                clonedState.forwardCheckers.listIterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            while (li.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                PKIXCertPathChecker checker = li.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                if (checker instanceof Cloneable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                    li.set((PKIXCertPathChecker)checker.clone());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
             * Shallow copy traversed names. There is no need to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
             * deep copy contents, since the elements of the Set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
             * are never modified by subsequent calls to updateState().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            clonedState.subjectNamesTraversed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                = (HashSet<GeneralNameInterface>)subjectNamesTraversed.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            return clonedState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        } catch (CloneNotSupportedException e) {
10419
12c063b39232 7084245: Update usages of InternalError to use exception chaining
sherman
parents: 10336
diff changeset
   265
            throw new InternalError(e.toString(), e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
}