jdk/src/share/classes/sun/security/provider/certpath/URICertStore.java
author mullan
Thu, 31 May 2012 17:07:28 -0400
changeset 12861 7aa4d0b3a8c7
parent 12860 9ffbd4e43413
child 13800 2fd4a82efe9c
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10785
diff changeset
     2
 * Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 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;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.security.cert.X509Certificate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.security.cert.X509CertSelector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.security.cert.X509CRL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import java.security.cert.X509CRLSelector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import java.util.Collection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import java.util.Collections;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import java.util.List;
6122
16fa7ed7ff1b 6867345: Turkish regional options cause NPE in sun.security.x509.AlgorithmId.algOID
xuelei
parents: 5506
diff changeset
    53
import java.util.Locale;
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * @since 7.0
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)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    private final static int CHECK_INTERVAL = 30 * 1000;
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)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    private final static int CACHE_SIZE = 185;
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;
10782
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents: 10419
diff changeset
   120
    private CertStoreHelper ldapHelper;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    private CertStore ldapCertStore;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    private String ldapPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * Creates a URICertStore.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * @param parameters specifying the URI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    URICertStore(CertStoreParameters params)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        throws InvalidAlgorithmParameterException, NoSuchAlgorithmException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        super(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        if (!(params instanceof URICertStoreParameters)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            throw new InvalidAlgorithmParameterException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                ("params must be instanceof URICertStoreParameters");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        this.uri = ((URICertStoreParameters) params).uri;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        // 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
   138
        if (uri.getScheme().toLowerCase(Locale.ENGLISH).equals("ldap")) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            ldap = true;
10782
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents: 10419
diff changeset
   140
            ldapHelper = CertStoreHelper.getInstance("LDAP");
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents: 10419
diff changeset
   141
            ldapCertStore = ldapHelper.getCertStore(uri);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            ldapPath = uri.getPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            // strip off leading '/'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            if (ldapPath.charAt(0) == '/') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                ldapPath = ldapPath.substring(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            factory = CertificateFactory.getInstance("X.509");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        } catch (CertificateException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            throw new RuntimeException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * Returns a URI CertStore. This method consults a cache of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * CertStores (shared per JVM) using the URI as a key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     */
10785
1d42311b6355 7092897: sun.security.util.Cache should be generified
mullan
parents: 10782
diff changeset
   159
    private static final Cache<URICertStoreParameters, CertStore>
1d42311b6355 7092897: sun.security.util.Cache should be generified
mullan
parents: 10782
diff changeset
   160
        certStoreCache = Cache.newSoftMemoryCache(CACHE_SIZE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    static synchronized CertStore getInstance(URICertStoreParameters params)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        throws NoSuchAlgorithmException, InvalidAlgorithmParameterException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            debug.println("CertStore URI:" + params.uri);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        }
10785
1d42311b6355 7092897: sun.security.util.Cache should be generified
mullan
parents: 10782
diff changeset
   166
        CertStore ucs = certStoreCache.get(params);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        if (ucs == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            ucs = new UCS(new URICertStore(params), null, "URI", params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            certStoreCache.put(params, ucs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                debug.println("URICertStore.getInstance: cache hit");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        return ucs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * Creates a CertStore from information included in the AccessDescription
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * object of a certificate's Authority Information Access Extension.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    static CertStore getInstance(AccessDescription ad) {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9734
diff changeset
   183
        if (!ad.getAccessMethod().equals((Object)
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9734
diff changeset
   184
                AccessDescription.Ad_CAISSUERS_Id)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        GeneralNameInterface gn = ad.getAccessLocation().getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        if (!(gn instanceof URIName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        URI uri = ((URIName) gn).getURI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            return URICertStore.getInstance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                (new URICertStore.URICertStoreParameters(uri));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        } catch (Exception ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                debug.println("exception creating CertStore: " + ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                ex.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * Returns a <code>Collection</code> of <code>X509Certificate</code>s that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * match the specified selector. If no <code>X509Certificate</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * match the selector, an empty <code>Collection</code> will be returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * @param selector a <code>CertSelector</code> used to select which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     *  <code>X509Certificate</code>s should be returned. Specify
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     *  <code>null</code> to return all <code>X509Certificate</code>s.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * @return a <code>Collection</code> of <code>X509Certificate</code>s that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     *         match the specified selector
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * @throws CertStoreException if an exception occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     */
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10785
diff changeset
   216
    @Override
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9734
diff changeset
   217
    @SuppressWarnings("unchecked")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    public synchronized Collection<X509Certificate> engineGetCertificates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        (CertSelector selector) throws CertStoreException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        // if ldap URI we wrap the CertSelector in an LDAPCertSelector to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        // avoid LDAP DN matching issues (see LDAPCertSelector for more info)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        if (ldap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            X509CertSelector xsel = (X509CertSelector) selector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            try {
10782
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents: 10419
diff changeset
   226
                xsel = ldapHelper.wrap(xsel, xsel.getSubject(), ldapPath);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            } catch (IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                throw new CertStoreException(ioe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            // Fetch the certificates via LDAP. LDAPCertStore has its own
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            // caching mechanism, see the class description for more info.
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9734
diff changeset
   232
            // Safe cast since xsel is an X509 certificate selector.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            return (Collection<X509Certificate>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                ldapCertStore.getCertificates(xsel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        // Return the Certificates for this entry. It returns the cached value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        // if it is still current and fetches the Certificates otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        // For the caching details, see the top of this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        long time = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        if (time - lastChecked < CHECK_INTERVAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                debug.println("Returning certificates from cache");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            return getMatchingCerts(certs, selector);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        lastChecked = time;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            URLConnection connection = uri.toURL().openConnection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            if (lastModified != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                connection.setIfModifiedSince(lastModified);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            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
   254
            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
   255
                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
   256
                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
   257
                    if (oldLastModified == lastModified) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                        if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                            debug.println("Not modified, using cached copy");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                        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
   262
                    } 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
   263
                        // 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
   264
                        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
   265
                        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
   266
                                    == 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
   267
                            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
   268
                                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
   269
                            }
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents: 10419
diff changeset
   270
                            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
   271
                        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                }
10782
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents: 10419
diff changeset
   274
                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
   275
                    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
   276
                }
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents: 10419
diff changeset
   277
                // 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
   278
                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
   279
                    factory.generateCertificates(in);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            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
   282
        } catch (IOException | CertificateException e) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                debug.println("Exception fetching certificates:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        // exception, forget previous values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        lastModified = 0;
10785
1d42311b6355 7092897: sun.security.util.Cache should be generified
mullan
parents: 10782
diff changeset
   290
        certs = Collections.emptySet();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        return certs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * Iterates over the specified Collection of X509Certificates and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * returns only those that match the criteria specified in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * CertSelector.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    private static Collection<X509Certificate> getMatchingCerts
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        (Collection<X509Certificate> certs, CertSelector selector) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        // if selector not specified, all certs match
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        if (selector == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            return certs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        }
10782
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents: 10419
diff changeset
   305
        List<X509Certificate> matchedCerts = new ArrayList<>(certs.size());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        for (X509Certificate cert : certs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            if (selector.match(cert)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                matchedCerts.add(cert);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        return matchedCerts;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * Returns a <code>Collection</code> of <code>X509CRL</code>s that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * match the specified selector. If no <code>X509CRL</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * match the selector, an empty <code>Collection</code> will be returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * @param selector A <code>CRLSelector</code> used to select which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     *  <code>X509CRL</code>s should be returned. Specify <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     *  to return all <code>X509CRL</code>s.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * @return A <code>Collection</code> of <code>X509CRL</code>s that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     *         match the specified selector
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * @throws CertStoreException if an exception occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     */
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10785
diff changeset
   326
    @Override
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9734
diff changeset
   327
    @SuppressWarnings("unchecked")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    public synchronized Collection<X509CRL> engineGetCRLs(CRLSelector selector)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        throws CertStoreException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        // if ldap URI we wrap the CRLSelector in an LDAPCRLSelector to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        // avoid LDAP DN matching issues (see LDAPCRLSelector for more info)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        if (ldap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            X509CRLSelector xsel = (X509CRLSelector) selector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            try {
10782
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents: 10419
diff changeset
   336
                xsel = ldapHelper.wrap(xsel, null, ldapPath);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            } catch (IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                throw new CertStoreException(ioe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            }
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.
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9734
diff changeset
   342
            // Safe cast since xsel is an X509 certificate selector.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            return (Collection<X509CRL>) ldapCertStore.getCRLs(xsel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        // Return the CRLs for this entry. It returns the cached value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        // if it is still current and fetches the CRLs otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        // For the caching details, see the top of this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        long time = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        if (time - lastChecked < CHECK_INTERVAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                debug.println("Returning CRL from cache");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            return getMatchingCRLs(crl, selector);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        lastChecked = time;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            URLConnection connection = uri.toURL().openConnection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            if (lastModified != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                connection.setIfModifiedSince(lastModified);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            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
   363
            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
   364
                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
   365
                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
   366
                    if (oldLastModified == lastModified) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                        if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                            debug.println("Not modified, using cached copy");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                        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
   371
                    } 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
   372
                        // 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
   373
                        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
   374
                        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
   375
                                    == 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
   376
                            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
   377
                                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
   378
                            }
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents: 10419
diff changeset
   379
                            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
   380
                        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                }
10782
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents: 10419
diff changeset
   383
                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
   384
                    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
   385
                }
01689c7b34ac 6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents: 10419
diff changeset
   386
                crl = (X509CRL) factory.generateCRL(in);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            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
   389
        } catch (IOException | CRLException e) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                debug.println("Exception fetching CRL:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        // exception, forget previous values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        lastModified = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        crl = null;
10785
1d42311b6355 7092897: sun.security.util.Cache should be generified
mullan
parents: 10782
diff changeset
   398
        return Collections.emptyList();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * Checks if the specified X509CRL matches the criteria specified in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * CRLSelector.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    private static Collection<X509CRL> getMatchingCRLs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        (X509CRL crl, CRLSelector selector) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        if (selector == null || (crl != null && selector.match(crl))) {
10785
1d42311b6355 7092897: sun.security.util.Cache should be generified
mullan
parents: 10782
diff changeset
   408
            return Collections.singletonList(crl);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        } else {
10785
1d42311b6355 7092897: sun.security.util.Cache should be generified
mullan
parents: 10782
diff changeset
   410
            return Collections.emptyList();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * CertStoreParameters for the URICertStore.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    static class URICertStoreParameters implements CertStoreParameters {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        private final URI uri;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        private volatile int hashCode = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        URICertStoreParameters(URI uri) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
            this.uri = uri;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        }
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10785
diff changeset
   423
        @Override public boolean equals(Object obj) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            if (!(obj instanceof URICertStoreParameters)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            URICertStoreParameters params = (URICertStoreParameters) obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            return uri.equals(params.uri);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        }
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10785
diff changeset
   430
        @Override public int hashCode() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            if (hashCode == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                int result = 17;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                result = 37*result + uri.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                hashCode = result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            return hashCode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        }
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10785
diff changeset
   438
        @Override public Object clone() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                return super.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            } catch (CloneNotSupportedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                /* Cannot happen */
10419
12c063b39232 7084245: Update usages of InternalError to use exception chaining
sherman
parents: 10336
diff changeset
   443
                throw new InternalError(e.toString(), e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * This class allows the URICertStore to be accessed as a CertStore.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    private static class UCS extends CertStore {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        protected UCS(CertStoreSpi spi, Provider p, String type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            CertStoreParameters params) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            super(spi, p, type, params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
}