jdk/src/java.base/share/classes/sun/security/provider/certpath/ssl/SSLServerCertStore.java
author martin
Tue, 15 Sep 2015 21:56:04 -0700
changeset 32649 2ee9017c7597
parent 30506 1998a5644f50
permissions -rw-r--r--
8136583: Core libraries should use blessed modifier order Summary: Run blessed-modifier-order script (see bug) Reviewed-by: psandoz, chegar, alanb, plevart
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10782
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
     1
/*
30506
1998a5644f50 8038084: CertStore needs a way to add new CertStore types
valeriep
parents: 25859
diff changeset
     2
 * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
10782
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
     4
 *
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
    10
 *
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
    15
 * accompanied this code).
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
    16
 *
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
    20
 *
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
    23
 * questions.
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
    24
 */
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
    25
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
    26
package sun.security.provider.certpath.ssl;
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
    27
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
    28
import java.io.IOException;
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
    29
import java.net.URI;
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
    30
import java.util.ArrayList;
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
    31
import java.util.Arrays;
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
    32
import java.util.Collection;
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
    33
import java.util.Collections;
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
    34
import java.util.List;
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
    35
import java.security.GeneralSecurityException;
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
    36
import java.security.InvalidAlgorithmParameterException;
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
    37
import java.security.Provider;
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
    38
import java.security.cert.CertificateException;
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
    39
import java.security.cert.CertSelector;
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
    40
import java.security.cert.CertStore;
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
    41
import java.security.cert.CertStoreException;
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
    42
import java.security.cert.CertStoreParameters;
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
    43
import java.security.cert.CertStoreSpi;
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
    44
import java.security.cert.CRLSelector;
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
    45
import java.security.cert.X509Certificate;
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
    46
import java.security.cert.X509CRL;
11108
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
    47
import java.net.Socket;
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
    48
import java.net.URLConnection;
10782
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
    49
import javax.net.ssl.HostnameVerifier;
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
    50
import javax.net.ssl.HttpsURLConnection;
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
    51
import javax.net.ssl.SSLContext;
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
    52
import javax.net.ssl.SSLSession;
11108
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
    53
import javax.net.ssl.SSLEngine;
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
    54
import javax.net.ssl.SSLSocketFactory;
10782
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
    55
import javax.net.ssl.TrustManager;
11108
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
    56
import javax.net.ssl.X509ExtendedTrustManager;
10782
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
    57
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
    58
/**
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
    59
 * A CertStore that retrieves an SSL server's certificate chain.
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
    60
 */
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
    61
public final class SSLServerCertStore extends CertStoreSpi {
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
    62
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
    63
    private final URI uri;
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 30506
diff changeset
    64
    private static final GetChainTrustManager trustManager;
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 30506
diff changeset
    65
    private static final SSLSocketFactory socketFactory;
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 30506
diff changeset
    66
    private static final HostnameVerifier hostnameVerifier;
11108
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
    67
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
    68
    static {
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
    69
        trustManager = new GetChainTrustManager();
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
    70
        hostnameVerifier = new HostnameVerifier() {
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
    71
            public boolean verify(String hostname, SSLSession session) {
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
    72
                return true;
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
    73
            }
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
    74
        };
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
    75
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
    76
        SSLSocketFactory tempFactory;
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
    77
        try {
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
    78
            SSLContext context = SSLContext.getInstance("SSL");
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
    79
            context.init(null, new TrustManager[] { trustManager }, null);
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
    80
            tempFactory = context.getSocketFactory();
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
    81
        } catch (GeneralSecurityException gse) {
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
    82
            tempFactory = null;
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
    83
        }
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
    84
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
    85
        socketFactory = tempFactory;
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
    86
    }
10782
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
    87
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
    88
    SSLServerCertStore(URI uri) throws InvalidAlgorithmParameterException {
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
    89
        super(null);
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
    90
        this.uri = uri;
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
    91
    }
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
    92
11108
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
    93
    public Collection<X509Certificate> engineGetCertificates
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
    94
            (CertSelector selector) throws CertStoreException {
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
    95
10782
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
    96
        try {
11108
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
    97
            URLConnection urlConn = uri.toURL().openConnection();
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
    98
            if (urlConn instanceof HttpsURLConnection) {
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
    99
                if (socketFactory == null) {
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   100
                    throw new CertStoreException(
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   101
                        "No initialized SSLSocketFactory");
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   102
                }
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   103
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   104
                HttpsURLConnection https = (HttpsURLConnection)urlConn;
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   105
                https.setSSLSocketFactory(socketFactory);
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   106
                https.setHostnameVerifier(hostnameVerifier);
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   107
                synchronized (trustManager) {
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   108
                    try {
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   109
                        https.connect();
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   110
                        return getMatchingCerts(
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   111
                            trustManager.serverChain, selector);
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   112
                    } catch (IOException ioe) {
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   113
                        // If the server certificate has already been
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   114
                        // retrieved, don't mind the connection state.
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   115
                        if (trustManager.exchangedServerCerts) {
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   116
                            return getMatchingCerts(
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   117
                                trustManager.serverChain, selector);
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   118
                        }
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   119
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   120
                        // otherwise, rethrow the exception
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   121
                        throw ioe;
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   122
                    } finally {
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   123
                        trustManager.cleanup();
10782
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
   124
                    }
11108
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   125
                }
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   126
            }
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   127
        } catch (IOException ioe) {
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   128
            throw new CertStoreException(ioe);
10782
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
   129
        }
11108
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   130
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   131
        return Collections.<X509Certificate>emptySet();
10782
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
   132
    }
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
   133
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
   134
    private static List<X509Certificate> getMatchingCerts
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
   135
        (List<X509Certificate> certs, CertSelector selector)
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
   136
    {
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
   137
        // if selector not specified, all certs match
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
   138
        if (selector == null) {
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
   139
            return certs;
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
   140
        }
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
   141
        List<X509Certificate> matchedCerts = new ArrayList<>(certs.size());
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
   142
        for (X509Certificate cert : certs) {
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
   143
            if (selector.match(cert)) {
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
   144
                matchedCerts.add(cert);
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
   145
            }
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
   146
        }
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
   147
        return matchedCerts;
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
   148
    }
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
   149
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
   150
    public Collection<X509CRL> engineGetCRLs(CRLSelector selector)
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
   151
        throws CertStoreException
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
   152
    {
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
   153
        throw new UnsupportedOperationException();
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
   154
    }
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
   155
30506
1998a5644f50 8038084: CertStore needs a way to add new CertStore types
valeriep
parents: 25859
diff changeset
   156
    public static CertStore getInstance(URI uri)
10782
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
   157
        throws InvalidAlgorithmParameterException
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
   158
    {
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
   159
        return new CS(new SSLServerCertStore(uri), null, "SSLServer", null);
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
   160
    }
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
   161
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
   162
    /*
11108
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   163
     * An X509ExtendedTrustManager that ignores the server certificate
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   164
     * validation.
10782
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
   165
     */
11108
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   166
    private static class GetChainTrustManager
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   167
            extends X509ExtendedTrustManager {
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   168
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   169
        private List<X509Certificate> serverChain =
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   170
                        Collections.<X509Certificate>emptyList();
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   171
        private boolean exchangedServerCerts = false;
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   172
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   173
        @Override
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   174
        public X509Certificate[] getAcceptedIssuers() {
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   175
            return new X509Certificate[0];
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   176
        }
10782
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
   177
11108
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   178
        @Override
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   179
        public void checkClientTrusted(X509Certificate[] chain,
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   180
                String authType) throws CertificateException {
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   181
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   182
            throw new UnsupportedOperationException();
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   183
        }
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   184
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   185
        @Override
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   186
        public void checkClientTrusted(X509Certificate[] chain, String authType,
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   187
                Socket socket) throws CertificateException {
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   188
10782
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
   189
            throw new UnsupportedOperationException();
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
   190
        }
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
   191
11108
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   192
        @Override
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   193
        public void checkClientTrusted(X509Certificate[] chain, String authType,
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   194
                SSLEngine engine) throws CertificateException {
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   195
10782
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
   196
            throw new UnsupportedOperationException();
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
   197
        }
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
   198
11108
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   199
        @Override
10782
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
   200
        public void checkServerTrusted(X509Certificate[] chain,
11108
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   201
                String authType) throws CertificateException {
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   202
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   203
            exchangedServerCerts = true;
10782
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
   204
            this.serverChain = (chain == null)
11108
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   205
                           ? Collections.<X509Certificate>emptyList()
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   206
                           : Arrays.<X509Certificate>asList(chain);
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   207
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   208
        }
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   209
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   210
        @Override
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   211
        public void checkServerTrusted(X509Certificate[] chain, String authType,
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   212
                Socket socket) throws CertificateException {
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   213
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   214
            checkServerTrusted(chain, authType);
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   215
        }
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   216
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   217
        @Override
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   218
        public void checkServerTrusted(X509Certificate[] chain, String authType,
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   219
                SSLEngine engine) throws CertificateException {
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   220
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   221
            checkServerTrusted(chain, authType);
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   222
        }
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   223
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   224
        void cleanup() {
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   225
            exchangedServerCerts = false;
6561c702c8a7 7115524: sun.security.provider.certpath.ssl.SSLServerCertStore no longer works
xuelei
parents: 10782
diff changeset
   226
            serverChain = Collections.<X509Certificate>emptyList();
10782
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
   227
        }
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
   228
    }
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
   229
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
   230
    /**
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
   231
     * This class allows the SSLServerCertStore to be accessed as a CertStore.
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
   232
     */
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
   233
    private static class CS extends CertStore {
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
   234
        protected CS(CertStoreSpi spi, Provider p, String type,
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
   235
                     CertStoreParameters params)
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
   236
        {
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
   237
            super(spi, p, type, params);
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
   238
        }
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
   239
    }
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
diff changeset
   240
}