< prev index next >
src/java.base/share/classes/sun/security/ssl/X509TrustManagerImpl.java
Print this page
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2018, 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
@@ -21,24 +21,20 @@
* 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 sun.security.ssl;
import java.net.Socket;
-import javax.net.ssl.SSLSession;
-
-import java.util.*;
import java.security.*;
import java.security.cert.*;
+import java.util.*;
import javax.net.ssl.*;
-
-import sun.security.validator.*;
import sun.security.util.AnchorCertificates;
import sun.security.util.HostnameChecker;
+import sun.security.validator.*;
/**
* This class implements the SunJSSE X.509 trust manager using the internal
* validator API in J2SE core. The logic in this class is minimal.<p>
* <p>
@@ -65,12 +61,10 @@
// note that we need separate validator for client and server due to
// the different extension checks. They are initialized lazily on demand.
private volatile Validator clientValidator, serverValidator;
- private static final Debug debug = Debug.getInstance("ssl");
-
X509TrustManagerImpl(String validatorType,
Collection<X509Certificate> trustedCerts) {
this.validatorType = validatorType;
this.pkixParams = null;
@@ -79,12 +73,13 @@
trustedCerts = Collections.<X509Certificate>emptySet();
}
this.trustedCerts = trustedCerts;
- if (debug != null && Debug.isOn("trustmanager")) {
- showTrustedCerts();
+ if (SSLLogger.isOn && SSLLogger.isOn("ssl,trustmanager")) {
+ SSLLogger.fine("adding as trusted certificates",
+ (Object[])trustedCerts.toArray(new X509Certificate[0]));
}
}
X509TrustManagerImpl(String validatorType, PKIXBuilderParameters params) {
this.validatorType = validatorType;
@@ -95,12 +90,13 @@
// the little extra footprint
Validator v = getValidator(Validator.VAR_TLS_SERVER);
trustedCerts = v.getTrustedCertificates();
serverValidator = v;
- if (debug != null && Debug.isOn("trustmanager")) {
- showTrustedCerts();
+ if (SSLLogger.isOn && SSLLogger.isOn("ssl,trustmanager")) {
+ SSLLogger.fine("adding as trusted certificates",
+ (Object[])trustedCerts.toArray(new X509Certificate[0]));
}
}
@Override
public void checkClientTrusted(X509Certificate[] chain, String authType)
@@ -200,15 +196,14 @@
if (session == null) {
throw new CertificateException("No handshake session");
}
// create the algorithm constraints
- ProtocolVersion protocolVersion =
- ProtocolVersion.valueOf(session.getProtocol());
boolean isExtSession = (session instanceof ExtendedSSLSession);
- AlgorithmConstraints constraints = null;
- if (protocolVersion.v >= ProtocolVersion.TLS12.v && isExtSession) {
+ AlgorithmConstraints constraints;
+ if (isExtSession &&
+ ProtocolVersion.useTLS12PlusSpec(session.getProtocol())) {
ExtendedSSLSession extSession = (ExtendedSSLSession)session;
String[] localSupportedSignAlgs =
extSession.getLocalSupportedSignatureAlgorithms();
constraints = new SSLAlgorithmConstraints(
@@ -226,12 +221,12 @@
trustedChain = validate(v, chain, responseList,
constraints, isClient ? null : authType);
// check if EE certificate chains to a public root CA (as
// pre-installed in cacerts)
- boolean chainsToPublicCA =
- AnchorCertificates.contains(trustedChain[trustedChain.length-1]);
+ boolean chainsToPublicCA = AnchorCertificates.contains(
+ trustedChain[trustedChain.length-1]);
// check endpoint identity
String identityAlg = sslSocket.getSSLParameters().
getEndpointIdentificationAlgorithm();
if (identityAlg != null && identityAlg.length() != 0) {
@@ -240,13 +235,14 @@
}
} else {
trustedChain = validate(v, chain, Collections.emptyList(),
null, isClient ? null : authType);
}
- if (debug != null && Debug.isOn("trustmanager")) {
- System.out.println("Found trusted certificate:");
- System.out.println(trustedChain[trustedChain.length - 1]);
+
+ if (SSLLogger.isOn && SSLLogger.isOn("ssl,trustmanager")) {
+ SSLLogger.fine("Found trusted certificate",
+ trustedChain[trustedChain.length - 1]);
}
}
private void checkTrusted(X509Certificate[] chain, String authType,
SSLEngine engine, boolean isClient) throws CertificateException {
@@ -258,15 +254,14 @@
if (session == null) {
throw new CertificateException("No handshake session");
}
// create the algorithm constraints
- ProtocolVersion protocolVersion =
- ProtocolVersion.valueOf(session.getProtocol());
boolean isExtSession = (session instanceof ExtendedSSLSession);
- AlgorithmConstraints constraints = null;
- if (protocolVersion.v >= ProtocolVersion.TLS12.v && isExtSession) {
+ AlgorithmConstraints constraints;
+ if (isExtSession &&
+ ProtocolVersion.useTLS12PlusSpec(session.getProtocol())) {
ExtendedSSLSession extSession = (ExtendedSSLSession)session;
String[] localSupportedSignAlgs =
extSession.getLocalSupportedSignatureAlgorithms();
constraints = new SSLAlgorithmConstraints(
@@ -284,12 +279,12 @@
trustedChain = validate(v, chain, responseList,
constraints, isClient ? null : authType);
// check if EE certificate chains to a public root CA (as
// pre-installed in cacerts)
- boolean chainsToPublicCA =
- AnchorCertificates.contains(trustedChain[trustedChain.length-1]);
+ boolean chainsToPublicCA = AnchorCertificates.contains(
+ trustedChain[trustedChain.length-1]);
// check endpoint identity
String identityAlg = engine.getSSLParameters().
getEndpointIdentificationAlgorithm();
if (identityAlg != null && identityAlg.length() != 0) {
@@ -298,31 +293,14 @@
}
} else {
trustedChain = validate(v, chain, Collections.emptyList(),
null, isClient ? null : authType);
}
- if (debug != null && Debug.isOn("trustmanager")) {
- System.out.println("Found trusted certificate:");
- System.out.println(trustedChain[trustedChain.length - 1]);
- }
- }
- private void showTrustedCerts() {
- for (X509Certificate cert : trustedCerts) {
- System.out.println("adding as trusted cert:");
- System.out.println(" Subject: "
- + cert.getSubjectX500Principal());
- System.out.println(" Issuer: "
- + cert.getIssuerX500Principal());
- System.out.println(" Algorithm: "
- + cert.getPublicKey().getAlgorithm()
- + "; Serial number: 0x"
- + cert.getSerialNumber().toString(16));
- System.out.println(" Valid from "
- + cert.getNotBefore() + " until "
- + cert.getNotAfter());
- System.out.println();
+ if (SSLLogger.isOn && SSLLogger.isOn("ssl,trustmanager")) {
+ SSLLogger.fine("Found trusted certificate",
+ trustedChain[trustedChain.length - 1]);
}
}
private Validator getValidator(String variant) {
Validator v;
@@ -362,12 +340,12 @@
} else {
try {
hostname = new SNIHostName(sniName.getEncoded());
} catch (IllegalArgumentException iae) {
// unlikely to happen, just in case ...
- if ((debug != null) && Debug.isOn("trustmanager")) {
- System.out.println("Illegal server name: " + sniName);
+ if (SSLLogger.isOn && SSLLogger.isOn("ssl,trustmanager")) {
+ SSLLogger.fine("Illegal server name: " + sniName);
}
}
}
// no more than server name of the same name type
@@ -489,5 +467,6 @@
"Unknown identification algorithm: " + algorithm);
}
}
}
}
+
< prev index next >