jdk/src/java.base/share/classes/sun/security/provider/certpath/UntrustedChecker.java
author martin
Tue, 15 Sep 2015 21:56:04 -0700
changeset 32649 2ee9017c7597
parent 25859 3317bb8137f4
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:
11900
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
     1
/*
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
     2
 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
     4
 *
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    10
 *
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    15
 * accompanied this code).
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    16
 *
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    20
 *
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    23
 * questions.
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    24
 */
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    25
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    26
package sun.security.provider.certpath;
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    27
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    28
import java.security.cert.Certificate;
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    29
import java.security.cert.X509Certificate;
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    30
import java.security.cert.CertPathValidatorException;
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    31
import java.security.cert.PKIXCertPathChecker;
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    32
import java.util.Set;
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    33
import java.util.Collection;
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    34
import sun.security.util.Debug;
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    35
import sun.security.util.UntrustedCertificates;
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    36
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    37
/**
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    38
 * A <code>PKIXCertPathChecker</code> implementation to check whether a
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    39
 * specified certificate is distrusted.
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    40
 *
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    41
 * @see PKIXCertPathChecker
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    42
 * @see PKIXParameters
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    43
 */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
    44
public final class UntrustedChecker extends PKIXCertPathChecker {
11900
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    45
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    46
    private static final Debug debug = Debug.getInstance("certpath");
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    47
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    48
    /**
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    49
     * Default Constructor
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    50
     */
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    51
    public UntrustedChecker() {
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    52
        // blank
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    53
    }
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    54
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    55
    @Override
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    56
    public void init(boolean forward) throws CertPathValidatorException {
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    57
        // Note that this class supports both forward and reverse modes.
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    58
    }
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    59
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    60
    @Override
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    61
    public boolean isForwardCheckingSupported() {
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    62
        // Note that this class supports both forward and reverse modes.
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    63
        return true;
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    64
    }
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    65
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    66
    @Override
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    67
    public Set<String> getSupportedExtensions() {
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    68
        return null;
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    69
    }
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    70
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    71
    @Override
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    72
    public void check(Certificate cert,
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    73
            Collection<String> unresolvedCritExts)
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    74
            throws CertPathValidatorException {
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    75
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    76
        X509Certificate currCert = (X509Certificate)cert;
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    77
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    78
        if (UntrustedCertificates.isUntrusted(currCert)) {
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    79
            if (debug != null) {
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    80
                debug.println("UntrustedChecker: untrusted certificate " +
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    81
                        currCert.getSubjectX500Principal());
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    82
            }
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    83
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    84
            throw new CertPathValidatorException(
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    85
                "Untrusted certificate: " + currCert.getSubjectX500Principal());
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    86
        }
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    87
    }
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    88
}
9b1d5bef8038 7123519: problems with certification path
xuelei
parents:
diff changeset
    89