/* * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package java.security.cert; import java.net.URI; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; /** * A {@code PKIXCertPathChecker} for checking the revocation status of * certificates with the PKIX algorithm. * *

A {@code PKIXRevocationChecker} checks the revocation status of * certificates with the Online Certificate Status Protocol (OCSP) or * Certificate Revocation Lists (CRLs). OCSP is described in RFC 2560 and * is a network protocol for determining the status of a certificate. A CRL * is a time-stamped list identifying revoked certificates, and RFC 5280 * describes an algorithm for determining the revocation status of certificates * using CRLs. * *

Each {@code PKIXRevocationChecker} must be able to check the revocation * status of certificates with OCSP and CRLs. By default, OCSP is the * preferred mechanism for checking revocation status, with CRLs as the * fallback mechanism. However, this preference can be switched to CRLs with * the {@link Option#PREFER_CRLS PREFER_CRLS} option. In addition, the fallback * mechanism can be disabled with the {@link Option#NO_FALLBACK NO_FALLBACK} * option. * *

A {@code PKIXRevocationChecker} is obtained by calling the * {@link CertPathValidator#getRevocationChecker getRevocationChecker} method * of a PKIX {@code CertPathValidator}. Additional parameters and options * specific to revocation can be set (by calling the * {@link #setOcspResponder setOcspResponder} method for instance). The * {@code PKIXRevocationChecker} is added to a {@code PKIXParameters} object * using the {@link PKIXParameters#addCertPathChecker addCertPathChecker} * or {@link PKIXParameters#setCertPathCheckers setCertPathCheckers} method, * and then the {@code PKIXParameters} is passed along with the {@code CertPath} * to be validated to the {@link CertPathValidator#validate validate} method * of a PKIX {@code CertPathValidator}. When supplying a revocation checker in * this manner, it will be used to check revocation irrespective of the setting * of the {@link PKIXParameters#isRevocationEnabled RevocationEnabled} flag. * Similarly, a {@code PKIXRevocationChecker} may be added to a * {@code PKIXBuilderParameters} object for use with a PKIX * {@code CertPathBuilder}. * *

Note that when a {@code PKIXRevocationChecker} is added to * {@code PKIXParameters}, it clones the {@code PKIXRevocationChecker}; * thus any subsequent modifications to the {@code PKIXRevocationChecker} * have no effect. * *

Any parameter that is not set (or is set to {@code null}) will be set to * the default value for that parameter. * *

Concurrent Access * *

Unless otherwise specified, the methods defined in this class are not * thread-safe. Multiple threads that need to access a single object * concurrently should synchronize amongst themselves and provide the * necessary locking. Multiple threads each manipulating separate objects * need not synchronize. * *

See RFC 2560: X.509 Internet Public Key Infrastructure Online Certificate Status Protocol - * OCSP, RFC 5280: Internet X.509 Public Key Infrastructure Certificate and Certificate Revocation * List (CRL) Profile (Android note: this paragraph was originally in a malformed "see" tag below, * moved here for correct construction of the docs). * * @since 1.8 */ public abstract class PKIXRevocationChecker extends PKIXCertPathChecker { private URI ocspResponder; private X509Certificate ocspResponderCert; private List ocspExtensions = Collections.emptyList(); private Map ocspResponses = Collections.emptyMap(); private Set

* An implementation of {@code PKIXRevocationChecker} is responsible for * adding the ignored exceptions to the list. * * @return an unmodifiable list containing the ignored exceptions. The list * is empty if no exceptions have been ignored. */ public abstract List getSoftFailExceptions(); @Override public PKIXRevocationChecker clone() { PKIXRevocationChecker copy = (PKIXRevocationChecker)super.clone(); copy.ocspExtensions = new ArrayList<>(ocspExtensions); copy.ocspResponses = new HashMap<>(ocspResponses); // deep-copy the encoded responses, since they are mutable for (Map.Entry entry : copy.ocspResponses.entrySet()) { byte[] encoded = entry.getValue(); entry.setValue(encoded.clone()); } copy.options = new HashSet<>(options); return copy; } /** * Various revocation options that can be specified for the revocation * checking mechanism. */ public enum Option { /** * Only check the revocation status of end-entity certificates. */ ONLY_END_ENTITY, /** * Prefer CRLs to OSCP. The default behavior is to prefer OCSP. Each * PKIX implementation should document further details of their * specific preference rules and fallback policies. */ PREFER_CRLS, /** * Disable the fallback mechanism. */ NO_FALLBACK, /** * Allow revocation check to succeed if the revocation status cannot be * determined for one of the following reasons: *


* Note that these conditions apply to both OCSP and CRLs, and unless * the {@code NO_FALLBACK} option is set, the revocation check is * allowed to succeed only if both mechanisms fail under one of the * conditions as stated above. * Exceptions that cause the network errors are ignored but can be * later retrieved by calling the * {@link #getSoftFailExceptions getSoftFailExceptions} method. */ SOFT_FAIL } }