jdk/src/java.base/share/classes/sun/security/provider/certpath/URICertStore.java
author martin
Tue, 15 Sep 2015 21:56:04 -0700
changeset 32649 2ee9017c7597
parent 32502 03f7450aec42
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:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
30506
1998a5644f50 8038084: CertStore needs a way to add new CertStore types
valeriep
parents: 25859
diff changeset
     2
 * Copyright (c) 2006, 2015, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4039
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4039
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4039
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4039
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4039
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.security.provider.certpath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.InputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.net.HttpURLConnection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.net.URI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.net.URLConnection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.security.InvalidAlgorithmParameterException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.security.NoSuchAlgorithmException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.security.Provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.security.cert.CertificateException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.security.cert.CertificateFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.security.cert.CertSelector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.security.cert.CertStore;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.security.cert.CertStoreException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.security.cert.CertStoreParameters;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.security.cert.CertStoreSpi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.security.cert.CRLException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.security.cert.CRLSelector;
30506
1998a5644f50 8038084: CertStore needs a way to add new CertStore types
valeriep
parents: 25859
diff changeset
    45
import java.security.cert.URICertStoreParameters;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.security.cert.X509Certificate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.security.cert.X509CRL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import java.util.Collection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import java.util.Collections;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import java.util.List;
6122
16fa7ed7ff1b 6867345: Turkish regional options cause NPE in sun.security.x509.AlgorithmId.algOID
xuelei
parents: 5506
diff changeset
    52
import java.util.Locale;
17044
c67bf062ca30 8013228: Create new system properties to control allowable OCSP clock skew and CRL connection timeout
mullan
parents: 13800
diff changeset
    53
import sun.security.action.GetIntegerAction;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import sun.security.x509.AccessDescription;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
import sun.security.x509.GeneralNameInterface;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
import sun.security.x509.URIName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
import sun.security.util.Cache;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
import sun.security.util.Debug;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * A <code>CertStore</code> that retrieves <code>Certificates</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * <code>CRL</code>s from a URI, for example, as specified in an X.509
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * AuthorityInformationAccess or CRLDistributionPoint extension.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * For CRLs, this implementation retrieves a single DER encoded CRL per URI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * For Certificates, this implementation retrieves a single DER encoded CRL or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * a collection of Certificates encoded as a PKCS#7 "certs-only" CMS message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * This <code>CertStore</code> also implements Certificate/CRL caching.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * Currently, the cache is shared between all applications in the VM and uses a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * hardcoded policy. The cache has a maximum size of 185 entries, which are held
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * by SoftReferences. A request will be satisfied from the cache if we last
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * checked for an update within CHECK_INTERVAL (last 30 seconds). Otherwise,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * we open an URLConnection to download the Certificate(s)/CRL using an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * If-Modified-Since request (HTTP) if possible. Note that both positive and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * negative responses are cached, i.e. if we are unable to open the connection
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * or the Certificate(s)/CRL cannot be parsed, we remember this result and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * additional calls during the CHECK_INTERVAL period do not try to open another
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * connection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * The URICertStore is not currently a standard CertStore type. We should
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * consider adding a standard "URI" CertStore type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * @author Andreas Sterbenz
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * @author Sean Mullan
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 17044
diff changeset
    86
 * @since 1.7
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
class URICertStore extends CertStoreSpi {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    private static final Debug debug = Debug.getInstance("certpath");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    // interval between checks for update of cached Certificates/CRLs
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    // (30 seconds)
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 32502
diff changeset
    94
    private static final int CHECK_INTERVAL = 30 * 1000;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    // size of the cache (see Cache class for sizing recommendations)
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 32502
diff changeset
    97
    private static final int CACHE_SIZE = 185;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    // X.509 certificate factory instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    private final CertificateFactory factory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    // cached Collection of X509Certificates (may be empty, never null)
10785
1d42311b6355 7092897: sun.security.util.Cache should be generified
mullan
parents: 10782
diff changeset
   103
    private Collection<X509Certificate> certs = Collections.emptySet();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    // cached X509CRL (may be null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    private X509CRL crl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    // time we last checked for an update
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    private long lastChecked;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    // time server returned as last modified time stamp
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    // or 0 if not available
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    private long lastModified;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    // the URI of this CertStore
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    private URI uri;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    // true if URI is ldap
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    private boolean ldap = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    private CertStore ldapCertStore;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
17044
c67bf062ca30 8013228: Create new system properties to control allowable OCSP clock skew and CRL connection timeout
mullan
parents: 13800
diff changeset
   122
    // Default maximum connect timeout in milliseconds (15 seconds)
c67bf062ca30 8013228: Create new system properties to control allowable OCSP clock skew and CRL connection timeout
mullan
parents: 13800
diff changeset
   123
    // allowed when downloading CRLs
c67bf062ca30 8013228: Create new system properties to control allowable OCSP clock skew and CRL connection timeout
mullan
parents: 13800
diff changeset
   124
    private static final int DEFAULT_CRL_CONNECT_TIMEOUT = 15000;
c67bf062ca30 8013228: Create new system properties to control allowable OCSP clock skew and CRL connection timeout
mullan
parents: 13800
diff changeset
   125
c67bf062ca30 8013228: Create new system properties to control allowable OCSP clock skew and CRL connection timeout
mullan
parents: 13800
diff changeset
   126
    /**
c67bf062ca30 8013228: Create new system properties to control allowable OCSP clock skew and CRL connection timeout
mullan
parents: 13800
diff changeset
   127
     * Integer value indicating the connect timeout, in seconds, to be
c67bf062ca30 8013228: Create new system properties to control allowable OCSP clock skew and CRL connection timeout
mullan
parents: 13800
diff changeset
   128
     * used for the CRL download. A timeout of zero is interpreted as
c67bf062ca30 8013228: Create new system properties to control allowable OCSP clock skew and CRL connection timeout
mullan
parents: 13800
diff changeset
   129
     * an infinite timeout.
c67bf062ca30 8013228: Create new system properties to control allowable OCSP clock skew and CRL connection timeout
mullan
parents: 13800
diff changeset
   130
     */
c67bf062ca30 8013228: Create new system properties to control allowable OCSP clock skew and CRL connection timeout
mullan
parents: 13800
diff changeset
   131
    private static final int CRL_CONNECT_TIMEOUT = initializeTimeout();
c67bf062ca30 8013228: Create new system properties to control allowable OCSP clock skew and CRL connection timeout
mullan
parents: 13800
diff changeset
   132
c67bf062ca30 8013228: Create new system properties to control allowable OCSP clock skew and CRL connection timeout
mullan
parents: 13800
diff changeset
   133
    /**
c67bf062ca30 8013228: Create new system properties to control allowable OCSP clock skew and CRL connection timeout
mullan
parents: 13800
diff changeset
   134
     * Initialize the timeout length by getting the CRL timeout
c67bf062ca30 8013228: Create new system properties to control allowable OCSP clock skew and CRL connection timeout
mullan
parents: 13800
diff changeset
   135
     * system property. If the property has not been set, or if its
c67bf062ca30 8013228: Create new system properties to control allowable OCSP clock skew and CRL connection timeout
mullan
parents: 13800
diff changeset
   136
     * value is negative, set the timeout length to the default.
c67bf062ca30 8013228: Create new system properties to control allowable OCSP clock skew and CRL connection timeout
mullan
parents: 13800
diff changeset
   137
     */
c67bf062ca30 8013228: Create new system properties to control allowable OCSP clock skew and CRL connection timeout
mullan
parents: 13800
diff changeset
   138
    private static int initializeTimeout() {
c67bf062ca30 8013228: Create new system properties to control allowable OCSP clock skew and CRL connection timeout
mullan
parents: 13800
diff changeset
   139
        Integer tmp = java.security.AccessController.doPrivileged(
c67bf062ca30 8013228: Create new system properties to control allowable OCSP clock skew and CRL connection timeout
mullan
parents: 13800
diff changeset
   140
                new GetIntegerAction("com.sun.security.crl.timeout"));
c67bf062ca30 8013228: Create new system properties to control allowable OCSP clock skew and CRL connection timeout
mullan
parents: 13800
diff changeset
   141
        if (tmp == null || tmp < 0) {
c67bf062ca30 8013228: Create new system properties to control allowable OCSP clock skew and CRL connection timeout
mullan
parents: 13800
diff changeset
   142
            return DEFAULT_CRL_CONNECT_TIMEOUT;
c67bf062ca30 8013228: Create new system properties to control allowable OCSP clock skew and CRL connection timeout
mullan
parents: 13800
diff changeset
   143
        }
c67bf062ca30 8013228: Create new system properties to control allowable OCSP clock skew and CRL connection timeout
mullan
parents: 13800
diff changeset
   144
        // Convert to milliseconds, as the system property will be
c67bf062ca30 8013228: Create new system properties to control allowable OCSP clock skew and CRL connection timeout
mullan
parents: 13800
diff changeset
   145
        // specified in seconds
c67bf062ca30 8013228: Create new system properties to control allowable OCSP clock skew and CRL connection timeout
mullan
parents: 13800
diff changeset
   146
        return tmp * 1000;
c67bf062ca30 8013228: Create new system properties to control allowable OCSP clock skew and CRL connection timeout
mullan
parents: 13800
diff changeset
   147
    }
c67bf062ca30 8013228: Create new system properties to control allowable OCSP clock skew and CRL connection timeout
mullan
parents: 13800
diff changeset
   148
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * Creates a URICertStore.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * @param parameters specifying the URI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    URICertStore(CertStoreParameters params)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        throws InvalidAlgorithmParameterException, NoSuchAlgorithmException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        super(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        if (!(params instanceof URICertStoreParameters)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            throw new InvalidAlgorithmParameterException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                ("params must be instanceof URICertStoreParameters");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        }
32502
03f7450aec42 8134708: Certpath validation fails to load certs and CRLs if AIA and CRLDP extensions point to LDAP resources
asmotrak
parents: 31426
diff changeset
   161
        this.uri = ((URICertStoreParameters) params).getURI();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        // if ldap URI, use an LDAPCertStore to fetch certs and CRLs
6122
16fa7ed7ff1b 6867345: Turkish regional options cause NPE in sun.security.x509.AlgorithmId.algOID
xuelei
parents: 5506
diff changeset
   163
        if (uri.getScheme().toLowerCase(Locale.ENGLISH).equals("ldap")) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            ldap = true;
32502
03f7450aec42 8134708: Certpath validation fails to load certs and CRLs if AIA and CRLDP extensions point to LDAP resources
asmotrak
parents: 31426
diff changeset
   165
            ldapCertStore = CertStore.getInstance("LDAP", params);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            factory = CertificateFactory.getInstance("X.509");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        } catch (CertificateException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            throw new RuntimeException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * Returns a URI CertStore. This method consults a cache of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * CertStores (shared per JVM) using the URI as a key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     */
10785
1d42311b6355 7092897: sun.security.util.Cache should be generified
mullan
parents: 10782
diff changeset
   178
    private static final Cache<URICertStoreParameters, CertStore>
1d42311b6355 7092897: sun.security.util.Cache should be generified
mullan
parents: 10782
diff changeset
   179
        certStoreCache = Cache.newSoftMemoryCache(CACHE_SIZE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    static synchronized CertStore getInstance(URICertStoreParameters params)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        throws NoSuchAlgorithmException, InvalidAlgorithmParameterException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        if (debug != null) {
32502
03f7450aec42 8134708: Certpath validation fails to load certs and CRLs if AIA and CRLDP extensions point to LDAP resources
asmotrak
parents: 31426
diff changeset
   183
            debug.println("CertStore URI:" + params.getURI());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        }
10785
1d42311b6355 7092897: sun.security.util.Cache should be generified
mullan
parents: 10782
diff changeset
   185
        CertStore ucs = certStoreCache.get(params);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        if (ucs == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            ucs = new UCS(new URICertStore(params), null, "URI", params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            certStoreCache.put(params, ucs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                debug.println("URICertStore.getInstance: cache hit");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        return ucs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * Creates a CertStore from information included in the AccessDescription
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * object of a certificate's Authority Information Access Extension.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    static CertStore getInstance(AccessDescription ad) {
31426
9cd672654f97 8022444: Remove sun.security.util.ObjectIdentifier.equals(ObjectIdentifier other) method
juh
parents: 30506
diff changeset
   202
        if (!ad.getAccessMethod().equals(
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9734
diff changeset
   203
                AccessDescription.Ad_CAISSUERS_Id)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        GeneralNameInterface gn = ad.getAccessLocation().getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        if (!(gn instanceof URIName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        URI uri = ((URIName) gn).getURI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        try {
32502
03f7450aec42 8134708: Certpath validation fails to load certs and CRLs if AIA and CRLDP extensions point to LDAP resources
asmotrak
parents: 31426
diff changeset
   212
            return URICertStore.getInstance(new URICertStoreParameters(uri));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        } catch (Exception ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                debug.println("exception creating CertStore: " + ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                ex.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * Returns a <code>Collection</code> of <code>X509Certificate</code>s that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * match the specified selector. If no <code>X509Certificate</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * match the selector, an empty <code>Collection</code> will be returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * @param selector a <code>CertSelector</code> used to select which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     *  <code>X509Certificate</code>s should be returned. Specify
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     *  <code>null</code> to return all <code>X509Certificate</code>s.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * @return a <code>Collection</code> of <code>X509Certificate</code>s that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     *         match the specified selector
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * @throws CertStoreException if an exception occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     */
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10785
diff changeset
   234
    @Override
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9734
diff changeset
   235
    @SuppressWarnings("unchecked")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    public synchronized Collection<X509Certificate> engineGetCertificates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        (CertSelector selector) throws CertStoreException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        if (ldap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            // caching mechanism, see the class description for more info.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            return (Collection<X509Certificate>)
30506
1998a5644f50 8038084: CertStore needs a way to add new CertStore types
valeriep
parents: 25859
diff changeset
   242
                ldapCertStore.getCertificates(selector);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        // Return the Certificates for this entry. It returns the cached value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        // if it is still current and fetches the Certificates otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        // For the caching details, see the top of this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        long time = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        if (time - lastChecked < CHECK_INTERVAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                debug.println("Returning certificates from cache");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            return getMatchingCerts(certs, selector);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        lastChecked = time;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            URLConnection connection = uri.toURL().openConnection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            if (lastModified != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                connection.setIfModifiedSince(lastModified);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            long oldLastModified = lastModified;
10782
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents: 10419
diff changeset
   262
            try (InputStream in = connection.getInputStream()) {
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents: 10419
diff changeset
   263
                lastModified = connection.getLastModified();
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents: 10419
diff changeset
   264
                if (oldLastModified != 0) {
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents: 10419
diff changeset
   265
                    if (oldLastModified == lastModified) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                        if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                            debug.println("Not modified, using cached copy");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                        return getMatchingCerts(certs, selector);
10782
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents: 10419
diff changeset
   270
                    } else if (connection instanceof HttpURLConnection) {
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents: 10419
diff changeset
   271
                        // some proxy servers omit last modified
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents: 10419
diff changeset
   272
                        HttpURLConnection hconn = (HttpURLConnection)connection;
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents: 10419
diff changeset
   273
                        if (hconn.getResponseCode()
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents: 10419
diff changeset
   274
                                    == HttpURLConnection.HTTP_NOT_MODIFIED) {
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents: 10419
diff changeset
   275
                            if (debug != null) {
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents: 10419
diff changeset
   276
                                debug.println("Not modified, using cached copy");
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents: 10419
diff changeset
   277
                            }
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents: 10419
diff changeset
   278
                            return getMatchingCerts(certs, selector);
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents: 10419
diff changeset
   279
                        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                }
10782
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents: 10419
diff changeset
   282
                if (debug != null) {
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents: 10419
diff changeset
   283
                    debug.println("Downloading new certificates...");
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents: 10419
diff changeset
   284
                }
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents: 10419
diff changeset
   285
                // Safe cast since factory is an X.509 certificate factory
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents: 10419
diff changeset
   286
                certs = (Collection<X509Certificate>)
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents: 10419
diff changeset
   287
                    factory.generateCertificates(in);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            return getMatchingCerts(certs, selector);
10782
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents: 10419
diff changeset
   290
        } catch (IOException | CertificateException e) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                debug.println("Exception fetching certificates:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        // exception, forget previous values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        lastModified = 0;
10785
1d42311b6355 7092897: sun.security.util.Cache should be generified
mullan
parents: 10782
diff changeset
   298
        certs = Collections.emptySet();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        return certs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * Iterates over the specified Collection of X509Certificates and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * returns only those that match the criteria specified in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * CertSelector.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    private static Collection<X509Certificate> getMatchingCerts
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        (Collection<X509Certificate> certs, CertSelector selector) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        // if selector not specified, all certs match
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        if (selector == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            return certs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        }
10782
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents: 10419
diff changeset
   313
        List<X509Certificate> matchedCerts = new ArrayList<>(certs.size());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        for (X509Certificate cert : certs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            if (selector.match(cert)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                matchedCerts.add(cert);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        return matchedCerts;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * Returns a <code>Collection</code> of <code>X509CRL</code>s that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * match the specified selector. If no <code>X509CRL</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * match the selector, an empty <code>Collection</code> will be returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * @param selector A <code>CRLSelector</code> used to select which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     *  <code>X509CRL</code>s should be returned. Specify <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     *  to return all <code>X509CRL</code>s.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * @return A <code>Collection</code> of <code>X509CRL</code>s that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     *         match the specified selector
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * @throws CertStoreException if an exception occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     */
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10785
diff changeset
   334
    @Override
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9734
diff changeset
   335
    @SuppressWarnings("unchecked")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    public synchronized Collection<X509CRL> engineGetCRLs(CRLSelector selector)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        throws CertStoreException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        if (ldap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            // Fetch the CRLs via LDAP. LDAPCertStore has its own
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            // caching mechanism, see the class description for more info.
13800
2fd4a82efe9c 7176627: CertPath/jep124/PreferCRL_SoftFail test fails (Could not determine revocation status)
mullan
parents: 12860
diff changeset
   342
            try {
30506
1998a5644f50 8038084: CertStore needs a way to add new CertStore types
valeriep
parents: 25859
diff changeset
   343
                return (Collection<X509CRL>) ldapCertStore.getCRLs(selector);
13800
2fd4a82efe9c 7176627: CertPath/jep124/PreferCRL_SoftFail test fails (Could not determine revocation status)
mullan
parents: 12860
diff changeset
   344
            } catch (CertStoreException cse) {
2fd4a82efe9c 7176627: CertPath/jep124/PreferCRL_SoftFail test fails (Could not determine revocation status)
mullan
parents: 12860
diff changeset
   345
                throw new PKIX.CertStoreTypeException("LDAP", cse);
2fd4a82efe9c 7176627: CertPath/jep124/PreferCRL_SoftFail test fails (Could not determine revocation status)
mullan
parents: 12860
diff changeset
   346
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        // Return the CRLs for this entry. It returns the cached value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        // if it is still current and fetches the CRLs otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        // For the caching details, see the top of this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        long time = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        if (time - lastChecked < CHECK_INTERVAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                debug.println("Returning CRL from cache");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            return getMatchingCRLs(crl, selector);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        lastChecked = time;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            URLConnection connection = uri.toURL().openConnection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            if (lastModified != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                connection.setIfModifiedSince(lastModified);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            long oldLastModified = lastModified;
17044
c67bf062ca30 8013228: Create new system properties to control allowable OCSP clock skew and CRL connection timeout
mullan
parents: 13800
diff changeset
   366
            connection.setConnectTimeout(CRL_CONNECT_TIMEOUT);
10782
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents: 10419
diff changeset
   367
            try (InputStream in = connection.getInputStream()) {
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents: 10419
diff changeset
   368
                lastModified = connection.getLastModified();
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents: 10419
diff changeset
   369
                if (oldLastModified != 0) {
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents: 10419
diff changeset
   370
                    if (oldLastModified == lastModified) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                        if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                            debug.println("Not modified, using cached copy");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                        return getMatchingCRLs(crl, selector);
10782
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents: 10419
diff changeset
   375
                    } else if (connection instanceof HttpURLConnection) {
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents: 10419
diff changeset
   376
                        // some proxy servers omit last modified
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents: 10419
diff changeset
   377
                        HttpURLConnection hconn = (HttpURLConnection)connection;
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents: 10419
diff changeset
   378
                        if (hconn.getResponseCode()
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents: 10419
diff changeset
   379
                                    == HttpURLConnection.HTTP_NOT_MODIFIED) {
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents: 10419
diff changeset
   380
                            if (debug != null) {
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents: 10419
diff changeset
   381
                                debug.println("Not modified, using cached copy");
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents: 10419
diff changeset
   382
                            }
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents: 10419
diff changeset
   383
                            return getMatchingCRLs(crl, selector);
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents: 10419
diff changeset
   384
                        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                }
10782
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents: 10419
diff changeset
   387
                if (debug != null) {
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents: 10419
diff changeset
   388
                    debug.println("Downloading new CRL...");
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents: 10419
diff changeset
   389
                }
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents: 10419
diff changeset
   390
                crl = (X509CRL) factory.generateCRL(in);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            return getMatchingCRLs(crl, selector);
10782
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents: 10419
diff changeset
   393
        } catch (IOException | CRLException e) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                debug.println("Exception fetching CRL:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            }
13800
2fd4a82efe9c 7176627: CertPath/jep124/PreferCRL_SoftFail test fails (Could not determine revocation status)
mullan
parents: 12860
diff changeset
   398
            // exception, forget previous values
2fd4a82efe9c 7176627: CertPath/jep124/PreferCRL_SoftFail test fails (Could not determine revocation status)
mullan
parents: 12860
diff changeset
   399
            lastModified = 0;
2fd4a82efe9c 7176627: CertPath/jep124/PreferCRL_SoftFail test fails (Could not determine revocation status)
mullan
parents: 12860
diff changeset
   400
            crl = null;
2fd4a82efe9c 7176627: CertPath/jep124/PreferCRL_SoftFail test fails (Could not determine revocation status)
mullan
parents: 12860
diff changeset
   401
            throw new PKIX.CertStoreTypeException("URI",
2fd4a82efe9c 7176627: CertPath/jep124/PreferCRL_SoftFail test fails (Could not determine revocation status)
mullan
parents: 12860
diff changeset
   402
                                                  new CertStoreException(e));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * Checks if the specified X509CRL matches the criteria specified in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * CRLSelector.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    private static Collection<X509CRL> getMatchingCRLs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        (X509CRL crl, CRLSelector selector) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        if (selector == null || (crl != null && selector.match(crl))) {
10785
1d42311b6355 7092897: sun.security.util.Cache should be generified
mullan
parents: 10782
diff changeset
   413
            return Collections.singletonList(crl);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        } else {
10785
1d42311b6355 7092897: sun.security.util.Cache should be generified
mullan
parents: 10782
diff changeset
   415
            return Collections.emptyList();
2
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * This class allows the URICertStore to be accessed as a CertStore.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    private static class UCS extends CertStore {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        protected UCS(CertStoreSpi spi, Provider p, String type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            CertStoreParameters params) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            super(spi, p, type, params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
}