< prev index next >

src/java.base/share/classes/sun/security/ssl/X509TrustManagerImpl.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 1997, 2017, 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 --- 1,7 ---- /* ! * 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,44 **** * 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 javax.net.ssl.*; - - import sun.security.validator.*; import sun.security.util.AnchorCertificates; import sun.security.util.HostnameChecker; /** * 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> --- 21,40 ---- * 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 java.security.*; import java.security.cert.*; + import java.util.*; import javax.net.ssl.*; 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,76 **** // 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; --- 61,70 ----
*** 79,90 **** trustedCerts = Collections.<X509Certificate>emptySet(); } this.trustedCerts = trustedCerts; ! if (debug != null && Debug.isOn("trustmanager")) { ! showTrustedCerts(); } } X509TrustManagerImpl(String validatorType, PKIXBuilderParameters params) { this.validatorType = validatorType; --- 73,85 ---- trustedCerts = Collections.<X509Certificate>emptySet(); } this.trustedCerts = trustedCerts; ! 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,106 **** // the little extra footprint Validator v = getValidator(Validator.VAR_TLS_SERVER); trustedCerts = v.getTrustedCertificates(); serverValidator = v; ! if (debug != null && Debug.isOn("trustmanager")) { ! showTrustedCerts(); } } @Override public void checkClientTrusted(X509Certificate[] chain, String authType) --- 90,102 ---- // the little extra footprint Validator v = getValidator(Validator.VAR_TLS_SERVER); trustedCerts = v.getTrustedCertificates(); serverValidator = v; ! 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,214 **** 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) { ExtendedSSLSession extSession = (ExtendedSSLSession)session; String[] localSupportedSignAlgs = extSession.getLocalSupportedSignatureAlgorithms(); constraints = new SSLAlgorithmConstraints( --- 196,209 ---- if (session == null) { throw new CertificateException("No handshake session"); } // create the algorithm constraints boolean isExtSession = (session instanceof ExtendedSSLSession); ! AlgorithmConstraints constraints; ! if (isExtSession && ! ProtocolVersion.useTLS12PlusSpec(session.getProtocol())) { ExtendedSSLSession extSession = (ExtendedSSLSession)session; String[] localSupportedSignAlgs = extSession.getLocalSupportedSignatureAlgorithms(); constraints = new SSLAlgorithmConstraints(
*** 226,237 **** 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]); // check endpoint identity String identityAlg = sslSocket.getSSLParameters(). getEndpointIdentificationAlgorithm(); if (identityAlg != null && identityAlg.length() != 0) { --- 221,232 ---- 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]); // check endpoint identity String identityAlg = sslSocket.getSSLParameters(). getEndpointIdentificationAlgorithm(); if (identityAlg != null && identityAlg.length() != 0) {
*** 240,252 **** } } 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 checkTrusted(X509Certificate[] chain, String authType, SSLEngine engine, boolean isClient) throws CertificateException { --- 235,248 ---- } } else { trustedChain = validate(v, chain, Collections.emptyList(), null, isClient ? null : authType); } ! ! 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,272 **** 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) { ExtendedSSLSession extSession = (ExtendedSSLSession)session; String[] localSupportedSignAlgs = extSession.getLocalSupportedSignatureAlgorithms(); constraints = new SSLAlgorithmConstraints( --- 254,267 ---- if (session == null) { throw new CertificateException("No handshake session"); } // create the algorithm constraints boolean isExtSession = (session instanceof ExtendedSSLSession); ! AlgorithmConstraints constraints; ! if (isExtSession && ! ProtocolVersion.useTLS12PlusSpec(session.getProtocol())) { ExtendedSSLSession extSession = (ExtendedSSLSession)session; String[] localSupportedSignAlgs = extSession.getLocalSupportedSignatureAlgorithms(); constraints = new SSLAlgorithmConstraints(
*** 284,295 **** 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]); // check endpoint identity String identityAlg = engine.getSSLParameters(). getEndpointIdentificationAlgorithm(); if (identityAlg != null && identityAlg.length() != 0) { --- 279,290 ---- 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]); // check endpoint identity String identityAlg = engine.getSSLParameters(). getEndpointIdentificationAlgorithm(); if (identityAlg != null && identityAlg.length() != 0) {
*** 298,328 **** } } 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(); } } private Validator getValidator(String variant) { Validator v; --- 293,306 ---- } } else { trustedChain = validate(v, chain, Collections.emptyList(), null, isClient ? null : authType); } ! if (SSLLogger.isOn && SSLLogger.isOn("ssl,trustmanager")) { ! SSLLogger.fine("Found trusted certificate", ! trustedChain[trustedChain.length - 1]); } } private Validator getValidator(String variant) { Validator v;
*** 362,373 **** } 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); } } } // no more than server name of the same name type --- 340,351 ---- } else { try { hostname = new SNIHostName(sniName.getEncoded()); } catch (IllegalArgumentException iae) { // unlikely to happen, just in case ... ! if (SSLLogger.isOn && SSLLogger.isOn("ssl,trustmanager")) { ! SSLLogger.fine("Illegal server name: " + sniName); } } } // no more than server name of the same name type
*** 489,493 **** --- 467,472 ---- "Unknown identification algorithm: " + algorithm); } } } } +
< prev index next >