jdk/src/share/classes/sun/security/provider/certpath/OCSPChecker.java
author mullan
Thu, 11 Sep 2008 14:05:16 -0400
changeset 1238 6d1f4b722acd
parent 715 f16baef3a20e
child 3214 3ee25b27ed91
permissions -rw-r--r--
6465942: Add problem identification facility to the CertPathValidator framework Summary: Add support to the java.security.cert APIs for determining the reason that a certification path is invalid. Reviewed-by: vinnie
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
715
f16baef3a20e 6719955: Update copyright year
xdono
parents: 625
diff changeset
     2
 * Copyright 2003-2008 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.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.math.BigInteger;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.security.Principal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.security.PrivilegedAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.security.Security;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.security.cert.*;
1238
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents: 715
diff changeset
    36
import java.security.cert.CertPathValidatorException.BasicReason;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.net.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import javax.security.auth.x500.X500Principal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import sun.security.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import sun.security.x509.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * OCSPChecker is a <code>PKIXCertPathChecker</code> that uses the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * Online Certificate Status Protocol (OCSP) as specified in RFC 2560
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * <a href="http://www.ietf.org/rfc/rfc2560.txt">
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * http://www.ietf.org/rfc/rfc2560.txt</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * @author      Ram Marti
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
class OCSPChecker extends PKIXCertPathChecker {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    public static final String OCSP_ENABLE_PROP = "ocsp.enable";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    public static final String OCSP_URL_PROP = "ocsp.responderURL";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    public static final String OCSP_CERT_SUBJECT_PROP =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        "ocsp.responderCertSubjectName";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    public static final String OCSP_CERT_ISSUER_PROP =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        "ocsp.responderCertIssuerName";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    public static final String OCSP_CERT_NUMBER_PROP =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        "ocsp.responderCertSerialNumber";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    private static final String HEX_DIGITS = "0123456789ABCDEFabcdef";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    private static final Debug DEBUG = Debug.getInstance("certpath");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    private static final boolean dump = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    // Supported extensions
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    private static final int OCSP_NONCE_DATA[] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        { 1, 3, 6, 1, 5, 5, 7, 48, 1, 2 };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    private static final ObjectIdentifier OCSP_NONCE_OID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        OCSP_NONCE_OID = ObjectIdentifier.newInternal(OCSP_NONCE_DATA);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    private int remainingCerts;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    private X509Certificate[] certs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    private CertPath cp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    private PKIXParameters pkixParams;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * Default Constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * @param certPath the X509 certification path
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * @param pkixParams the input PKIX parameter set
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * @exception CertPathValidatorException Exception thrown if cert path
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * does not validate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    OCSPChecker(CertPath certPath, PKIXParameters pkixParams)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        throws CertPathValidatorException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        this.cp = certPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        this.pkixParams = pkixParams;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        List<? extends Certificate> tmp = cp.getCertificates();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        certs = tmp.toArray(new X509Certificate[tmp.size()]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        init(false);
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
     * Initializes the internal state of the checker from parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * specified in the constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    public void init(boolean forward) throws CertPathValidatorException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        if (!forward) {
625
ba0b63c29671 6383078: OCSP checking does not work on end-entity certificate
vinnie
parents: 2
diff changeset
   106
            remainingCerts = certs.length + 1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            throw new CertPathValidatorException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                "Forward checking not supported");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    public boolean isForwardCheckingSupported() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    public Set<String> getSupportedExtensions() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        return Collections.<String>emptySet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * Sends an OCSPRequest for the certificate to the OCSP Server and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * processes the response back from the OCSP Server.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * @param cert the Certificate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * @param unresolvedCritExts the unresolved critical extensions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * @exception CertPathValidatorException Exception is thrown if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     *            certificate has been revoked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    public void check(Certificate cert, Collection<String> unresolvedCritExts)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        throws CertPathValidatorException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        InputStream in = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        OutputStream out = null;
625
ba0b63c29671 6383078: OCSP checking does not work on end-entity certificate
vinnie
parents: 2
diff changeset
   135
ba0b63c29671 6383078: OCSP checking does not work on end-entity certificate
vinnie
parents: 2
diff changeset
   136
        // Decrement the certificate counter
ba0b63c29671 6383078: OCSP checking does not work on end-entity certificate
vinnie
parents: 2
diff changeset
   137
        remainingCerts--;
ba0b63c29671 6383078: OCSP checking does not work on end-entity certificate
vinnie
parents: 2
diff changeset
   138
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            X509Certificate responderCert = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            boolean seekResponderCert = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            X500Principal responderSubjectName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            X500Principal responderIssuerName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            BigInteger responderSerialNumber = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
625
ba0b63c29671 6383078: OCSP checking does not work on end-entity certificate
vinnie
parents: 2
diff changeset
   146
            boolean seekIssuerCert = true;
ba0b63c29671 6383078: OCSP checking does not work on end-entity certificate
vinnie
parents: 2
diff changeset
   147
            X509CertImpl issuerCertImpl = null;
ba0b63c29671 6383078: OCSP checking does not work on end-entity certificate
vinnie
parents: 2
diff changeset
   148
            X509CertImpl currCertImpl =
ba0b63c29671 6383078: OCSP checking does not work on end-entity certificate
vinnie
parents: 2
diff changeset
   149
                X509CertImpl.toImpl((X509Certificate)cert);
ba0b63c29671 6383078: OCSP checking does not work on end-entity certificate
vinnie
parents: 2
diff changeset
   150
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
             * OCSP security property values, in the following order:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
             *   1. ocsp.responderURL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
             *   2. ocsp.responderCertSubjectName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
             *   3. ocsp.responderCertIssuerName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
             *   4. ocsp.responderCertSerialNumber
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            String[] properties = getOCSPProperties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
625
ba0b63c29671 6383078: OCSP checking does not work on end-entity certificate
vinnie
parents: 2
diff changeset
   160
            // Check whether OCSP is feasible before seeking cert information
ba0b63c29671 6383078: OCSP checking does not work on end-entity certificate
vinnie
parents: 2
diff changeset
   161
            URL url = getOCSPServerURL(currCertImpl, properties);
ba0b63c29671 6383078: OCSP checking does not work on end-entity certificate
vinnie
parents: 2
diff changeset
   162
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            // When responder's subject name is set then the issuer/serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            // properties are ignored
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            if (properties[1] != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                responderSubjectName = new X500Principal(properties[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            } else if (properties[2] != null && properties[3] != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                responderIssuerName = new X500Principal(properties[2]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                // remove colon or space separators
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                String value = stripOutSeparators(properties[3]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                responderSerialNumber = new BigInteger(value, 16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            } else if (properties[2] != null || properties[3] != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                throw new CertPathValidatorException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                    "Must specify both ocsp.responderCertIssuerName and " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                    "ocsp.responderCertSerialNumber properties");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            // If the OCSP responder cert properties are set then the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            // identified cert must be located in the trust anchors or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            // in the cert stores.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            if (responderSubjectName != null || responderIssuerName != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                seekResponderCert = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
625
ba0b63c29671 6383078: OCSP checking does not work on end-entity certificate
vinnie
parents: 2
diff changeset
   187
            // Set the issuer certificate to the next cert in the chain
ba0b63c29671 6383078: OCSP checking does not work on end-entity certificate
vinnie
parents: 2
diff changeset
   188
            // (unless we're processing the final cert).
ba0b63c29671 6383078: OCSP checking does not work on end-entity certificate
vinnie
parents: 2
diff changeset
   189
            if (remainingCerts < certs.length) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                issuerCertImpl = X509CertImpl.toImpl(certs[remainingCerts]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                seekIssuerCert = false; // done
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                // By default, the OCSP responder's cert is the same as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                // issuer of the cert being validated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                if (! seekResponderCert) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                    responderCert = certs[remainingCerts];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                    if (DEBUG != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                        DEBUG.println("Responder's certificate is the same " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                            "as the issuer of the certificate being validated");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            // Check anchor certs for:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            //    - the issuer cert (of the cert being validated)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            //    - the OCSP responder's cert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            if (seekIssuerCert || seekResponderCert) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                if (DEBUG != null && seekResponderCert) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                    DEBUG.println("Searching trust anchors for responder's " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                        "certificate");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                // Extract the anchor certs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                Iterator anchors = pkixParams.getTrustAnchors().iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                if (! anchors.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                    throw new CertPathValidatorException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                        "Must specify at least one trust anchor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                X500Principal certIssuerName =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                    currCertImpl.getIssuerX500Principal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                while (anchors.hasNext() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                        (seekIssuerCert || seekResponderCert)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                    TrustAnchor anchor = (TrustAnchor)anchors.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                    X509Certificate anchorCert = anchor.getTrustedCert();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                    X500Principal anchorSubjectName =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                        anchorCert.getSubjectX500Principal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                    if (dump) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                        System.out.println("Issuer DN is " + certIssuerName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                        System.out.println("Subject DN is " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                            anchorSubjectName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                    // Check if anchor cert is the issuer cert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                    if (seekIssuerCert &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                        certIssuerName.equals(anchorSubjectName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                        issuerCertImpl = X509CertImpl.toImpl(anchorCert);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                        seekIssuerCert = false; // done
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                        // By default, the OCSP responder's cert is the same as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                        // the issuer of the cert being validated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                        if (! seekResponderCert && responderCert == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                            responderCert = anchorCert;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                            if (DEBUG != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                                DEBUG.println("Responder's certificate is the" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                                    " same as the issuer of the certificate " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                                    "being validated");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                            }
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
                    // Check if anchor cert is the responder cert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                    if (seekResponderCert) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                        // Satisfy the responder subject name property only, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                        // satisfy the responder issuer name and serial number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                        // properties only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                        if ((responderSubjectName != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                             responderSubjectName.equals(anchorSubjectName)) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                            (responderIssuerName != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                             responderSerialNumber != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                             responderIssuerName.equals(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                                anchorCert.getIssuerX500Principal()) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                             responderSerialNumber.equals(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                                anchorCert.getSerialNumber()))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                            responderCert = anchorCert;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                            seekResponderCert = false; // done
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                if (issuerCertImpl == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                    throw new CertPathValidatorException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                        "No trusted certificate for " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                        currCertImpl.getIssuerDN());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                // Check cert stores if responder cert has not yet been found
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                if (seekResponderCert) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                    if (DEBUG != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                        DEBUG.println("Searching cert stores for responder's " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                            "certificate");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                    X509CertSelector filter = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                    if (responderSubjectName != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                        filter = new X509CertSelector();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                        filter.setSubject(responderSubjectName.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                    } else if (responderIssuerName != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                        responderSerialNumber != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                        filter = new X509CertSelector();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                        filter.setIssuer(responderIssuerName.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                        filter.setSerialNumber(responderSerialNumber);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                    if (filter != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                        List<CertStore> certStores = pkixParams.getCertStores();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                        for (CertStore certStore : certStores) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                            Iterator i =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                                certStore.getCertificates(filter).iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                            if (i.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                                responderCert = (X509Certificate) i.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                                seekResponderCert = false; // done
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            // Could not find the certificate identified in the OCSP properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            if (seekResponderCert) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                throw new CertPathValidatorException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                    "Cannot find the responder's certificate " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                    "(set using the OCSP security properties).");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            // Construct an OCSP Request
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            OCSPRequest ocspRequest =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                new OCSPRequest(currCertImpl, issuerCertImpl);
625
ba0b63c29671 6383078: OCSP checking does not work on end-entity certificate
vinnie
parents: 2
diff changeset
   322
ba0b63c29671 6383078: OCSP checking does not work on end-entity certificate
vinnie
parents: 2
diff changeset
   323
            // Use the URL to the OCSP service that was created earlier
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            HttpURLConnection con = (HttpURLConnection)url.openConnection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            if (DEBUG != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                DEBUG.println("connecting to OCSP service at: " + url);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            // Indicate that both input and output will be performed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            // that the method is POST, and that the content length is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            // the length of the byte array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            con.setDoOutput(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            con.setDoInput(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            con.setRequestMethod("POST");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            con.setRequestProperty("Content-type", "application/ocsp-request");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            byte[] bytes = ocspRequest.encodeBytes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            CertId certId = ocspRequest.getCertId();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            con.setRequestProperty("Content-length",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                String.valueOf(bytes.length));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            out = con.getOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            out.write(bytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            out.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            // Check the response
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            if (DEBUG != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                con.getResponseCode() != HttpURLConnection.HTTP_OK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                DEBUG.println("Received HTTP error: " + con.getResponseCode() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                    " - " + con.getResponseMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            in = con.getInputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            int contentLength = con.getContentLength();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            if (contentLength == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                contentLength = Integer.MAX_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            byte[] response = new byte[contentLength];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            int total = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            int count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            while (count != -1 && total < contentLength) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                count = in.read(response, total, response.length - total);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                total += count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            OCSPResponse ocspResponse = new OCSPResponse(response, pkixParams,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                responderCert);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            // Check that response applies to the cert that was supplied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            if (! certId.equals(ocspResponse.getCertId())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                throw new CertPathValidatorException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                    "Certificate in the OCSP response does not match the " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                    "certificate supplied in the OCSP request.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            SerialNumber serialNumber = currCertImpl.getSerialNumberObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            int certOCSPStatus = ocspResponse.getCertStatus(serialNumber);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            if (DEBUG != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                DEBUG.println("Status of certificate (with serial number " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                    serialNumber.getNumber() + ") is: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                    OCSPResponse.certStatusToText(certOCSPStatus));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            if (certOCSPStatus == OCSPResponse.CERT_STATUS_REVOKED) {
1238
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents: 715
diff changeset
   385
                Throwable t = new CertificateRevokedException(
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                        ocspResponse.getRevocationTime(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                        ocspResponse.getRevocationReason(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                        responderCert.getSubjectX500Principal(),
1238
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents: 715
diff changeset
   389
                        ocspResponse.getSingleExtensions());
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents: 715
diff changeset
   390
                throw new CertPathValidatorException(t.getMessage(), t,
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents: 715
diff changeset
   391
                        null, -1, BasicReason.REVOKED);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            } else if (certOCSPStatus == OCSPResponse.CERT_STATUS_UNKNOWN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                throw new CertPathValidatorException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                    "Certificate's revocation status is unknown", null, cp,
1238
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents: 715
diff changeset
   396
                    remainingCerts, BasicReason.UNDETERMINED_REVOCATION_STATUS);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            throw new CertPathValidatorException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            if (in != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                    in.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                } catch (IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                    throw new CertPathValidatorException(ioe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            if (out != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                    out.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                } catch (IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                    throw new CertPathValidatorException(ioe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * The OCSP security property values are in the following order:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     *   1. ocsp.responderURL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     *   2. ocsp.responderCertSubjectName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     *   3. ocsp.responderCertIssuerName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     *   4. ocsp.responderCertSerialNumber
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    private static URL getOCSPServerURL(X509CertImpl currCertImpl,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        String[] properties)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        throws CertificateParsingException, CertPathValidatorException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        if (properties[0] != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
           try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                return new URL(properties[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
           } catch (java.net.MalformedURLException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                throw new CertPathValidatorException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        // Examine the certificate's AuthorityInfoAccess extension
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        AuthorityInfoAccessExtension aia =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            currCertImpl.getAuthorityInfoAccessExtension();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        if (aia == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            throw new CertPathValidatorException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                "Must specify the location of an OCSP Responder");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        List<AccessDescription> descriptions = aia.getAccessDescriptions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        for (AccessDescription description : descriptions) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
            if (description.getAccessMethod().equals(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                AccessDescription.Ad_OCSP_Id)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                GeneralName generalName = description.getAccessLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                if (generalName.getType() == GeneralNameInterface.NAME_URI) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                        URIName uri = (URIName) generalName.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                        return (new URL(uri.getName()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                    } catch (java.net.MalformedURLException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                        throw new CertPathValidatorException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        throw new CertPathValidatorException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            "Cannot find the location of the OCSP Responder");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     * Retrieves the values of the OCSP security properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    private static String[] getOCSPProperties() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        final String[] properties = new String[4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
            new PrivilegedAction<Void>() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                public Void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                    properties[0] = Security.getProperty(OCSP_URL_PROP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                    properties[1] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                        Security.getProperty(OCSP_CERT_SUBJECT_PROP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                    properties[2] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                        Security.getProperty(OCSP_CERT_ISSUER_PROP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                    properties[3] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                        Security.getProperty(OCSP_CERT_NUMBER_PROP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        return properties;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * Removes any non-hexadecimal characters from a string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    private static String stripOutSeparators(String value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        char[] chars = value.toCharArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        StringBuilder hexNumber = new StringBuilder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        for (int i = 0; i < chars.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
            if (HEX_DIGITS.indexOf(chars[i]) != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                hexNumber.append(chars[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        return hexNumber.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
}