Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/javax/net/ssl/X509ExtendedTrustManager.java
38918 views
/*1* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.net.ssl;2627import java.net.Socket;28import javax.net.ssl.X509TrustManager;2930import java.security.cert.X509Certificate;31import java.security.cert.CertificateException;3233/**34* Extensions to the <code>X509TrustManager</code> interface to support35* SSL/TLS connection sensitive trust management.36* <p>37* To prevent man-in-the-middle attacks, hostname checks can be done38* to verify that the hostname in an end-entity certificate matches the39* targeted hostname. TLS does not require such checks, but some protocols40* over TLS (such as HTTPS) do. In earlier versions of the JDK, the41* certificate chain checks were done at the SSL/TLS layer, and the hostname42* verification checks were done at the layer over TLS. This class allows43* for the checking to be done during a single call to this class.44* <p>45* RFC 2830 defines the server identification specification for the "LDAPS"46* algorithm. RFC 2818 defines both the server identification and the47* client identification specification for the "HTTPS" algorithm.48*49* @see X509TrustManager50* @see HostnameVerifier51*52* @since 1.753*/54public abstract class X509ExtendedTrustManager implements X509TrustManager {55/**56* Given the partial or complete certificate chain provided by the57* peer, build and validate the certificate path based on the58* authentication type and ssl parameters.59* <p>60* The authentication type is determined by the actual certificate61* used. For instance, if RSAPublicKey is used, the authType62* should be "RSA". Checking is case-sensitive.63* <p>64* If the <code>socket</code> parameter is an instance of65* {@link javax.net.ssl.SSLSocket}, and the endpoint identification66* algorithm of the <code>SSLParameters</code> is non-empty, to prevent67* man-in-the-middle attacks, the address that the <code>socket</code>68* connected to should be checked against the peer's identity presented69* in the end-entity X509 certificate, as specified in the endpoint70* identification algorithm.71* <p>72* If the <code>socket</code> parameter is an instance of73* {@link javax.net.ssl.SSLSocket}, and the algorithm constraints of the74* <code>SSLParameters</code> is non-null, for every certificate in the75* certification path, fields such as subject public key, the signature76* algorithm, key usage, extended key usage, etc. need to conform to the77* algorithm constraints in place on this socket.78*79* @param chain the peer certificate chain80* @param authType the key exchange algorithm used81* @param socket the socket used for this connection. This parameter82* can be null, which indicates that implementations need not check83* the ssl parameters84* @throws IllegalArgumentException if null or zero-length array is passed85* in for the <code>chain</code> parameter or if null or zero-length86* string is passed in for the <code>authType</code> parameter87* @throws CertificateException if the certificate chain is not trusted88* by this TrustManager89*90* @see SSLParameters#getEndpointIdentificationAlgorithm91* @see SSLParameters#setEndpointIdentificationAlgorithm(String)92* @see SSLParameters#getAlgorithmConstraints93* @see SSLParameters#setAlgorithmConstraints(AlgorithmConstraints)94*/95public abstract void checkClientTrusted(X509Certificate[] chain,96String authType, Socket socket) throws CertificateException;9798/**99* Given the partial or complete certificate chain provided by the100* peer, build and validate the certificate path based on the101* authentication type and ssl parameters.102* <p>103* The authentication type is the key exchange algorithm portion104* of the cipher suites represented as a String, such as "RSA",105* "DHE_DSS". Note: for some exportable cipher suites, the key106* exchange algorithm is determined at run time during the107* handshake. For instance, for TLS_RSA_EXPORT_WITH_RC4_40_MD5,108* the authType should be RSA_EXPORT when an ephemeral RSA key is109* used for the key exchange, and RSA when the key from the server110* certificate is used. Checking is case-sensitive.111* <p>112* If the <code>socket</code> parameter is an instance of113* {@link javax.net.ssl.SSLSocket}, and the endpoint identification114* algorithm of the <code>SSLParameters</code> is non-empty, to prevent115* man-in-the-middle attacks, the address that the <code>socket</code>116* connected to should be checked against the peer's identity presented117* in the end-entity X509 certificate, as specified in the endpoint118* identification algorithm.119* <p>120* If the <code>socket</code> parameter is an instance of121* {@link javax.net.ssl.SSLSocket}, and the algorithm constraints of the122* <code>SSLParameters</code> is non-null, for every certificate in the123* certification path, fields such as subject public key, the signature124* algorithm, key usage, extended key usage, etc. need to conform to the125* algorithm constraints in place on this socket.126*127* @param chain the peer certificate chain128* @param authType the key exchange algorithm used129* @param socket the socket used for this connection. This parameter130* can be null, which indicates that implementations need not check131* the ssl parameters132* @throws IllegalArgumentException if null or zero-length array is passed133* in for the <code>chain</code> parameter or if null or zero-length134* string is passed in for the <code>authType</code> parameter135* @throws CertificateException if the certificate chain is not trusted136* by this TrustManager137*138* @see SSLParameters#getEndpointIdentificationAlgorithm139* @see SSLParameters#setEndpointIdentificationAlgorithm(String)140* @see SSLParameters#getAlgorithmConstraints141* @see SSLParameters#setAlgorithmConstraints(AlgorithmConstraints)142*/143public abstract void checkServerTrusted(X509Certificate[] chain,144String authType, Socket socket) throws CertificateException;145146/**147* Given the partial or complete certificate chain provided by the148* peer, build and validate the certificate path based on the149* authentication type and ssl parameters.150* <p>151* The authentication type is determined by the actual certificate152* used. For instance, if RSAPublicKey is used, the authType153* should be "RSA". Checking is case-sensitive.154* <p>155* If the <code>engine</code> parameter is available, and the endpoint156* identification algorithm of the <code>SSLParameters</code> is157* non-empty, to prevent man-in-the-middle attacks, the address that158* the <code>engine</code> connected to should be checked against159* the peer's identity presented in the end-entity X509 certificate,160* as specified in the endpoint identification algorithm.161* <p>162* If the <code>engine</code> parameter is available, and the algorithm163* constraints of the <code>SSLParameters</code> is non-null, for every164* certificate in the certification path, fields such as subject public165* key, the signature algorithm, key usage, extended key usage, etc.166* need to conform to the algorithm constraints in place on this engine.167*168* @param chain the peer certificate chain169* @param authType the key exchange algorithm used170* @param engine the engine used for this connection. This parameter171* can be null, which indicates that implementations need not check172* the ssl parameters173* @throws IllegalArgumentException if null or zero-length array is passed174* in for the <code>chain</code> parameter or if null or zero-length175* string is passed in for the <code>authType</code> parameter176* @throws CertificateException if the certificate chain is not trusted177* by this TrustManager178*179* @see SSLParameters#getEndpointIdentificationAlgorithm180* @see SSLParameters#setEndpointIdentificationAlgorithm(String)181* @see SSLParameters#getAlgorithmConstraints182* @see SSLParameters#setAlgorithmConstraints(AlgorithmConstraints)183*/184public abstract void checkClientTrusted(X509Certificate[] chain,185String authType, SSLEngine engine) throws CertificateException;186187/**188* Given the partial or complete certificate chain provided by the189* peer, build and validate the certificate path based on the190* authentication type and ssl parameters.191* <p>192* The authentication type is the key exchange algorithm portion193* of the cipher suites represented as a String, such as "RSA",194* "DHE_DSS". Note: for some exportable cipher suites, the key195* exchange algorithm is determined at run time during the196* handshake. For instance, for TLS_RSA_EXPORT_WITH_RC4_40_MD5,197* the authType should be RSA_EXPORT when an ephemeral RSA key is198* used for the key exchange, and RSA when the key from the server199* certificate is used. Checking is case-sensitive.200* <p>201* If the <code>engine</code> parameter is available, and the endpoint202* identification algorithm of the <code>SSLParameters</code> is203* non-empty, to prevent man-in-the-middle attacks, the address that204* the <code>engine</code> connected to should be checked against205* the peer's identity presented in the end-entity X509 certificate,206* as specified in the endpoint identification algorithm.207* <p>208* If the <code>engine</code> parameter is available, and the algorithm209* constraints of the <code>SSLParameters</code> is non-null, for every210* certificate in the certification path, fields such as subject public211* key, the signature algorithm, key usage, extended key usage, etc.212* need to conform to the algorithm constraints in place on this engine.213*214* @param chain the peer certificate chain215* @param authType the key exchange algorithm used216* @param engine the engine used for this connection. This parameter217* can be null, which indicates that implementations need not check218* the ssl parameters219* @throws IllegalArgumentException if null or zero-length array is passed220* in for the <code>chain</code> parameter or if null or zero-length221* string is passed in for the <code>authType</code> parameter222* @throws CertificateException if the certificate chain is not trusted223* by this TrustManager224*225* @see SSLParameters#getEndpointIdentificationAlgorithm226* @see SSLParameters#setEndpointIdentificationAlgorithm(String)227* @see SSLParameters#getAlgorithmConstraints228* @see SSLParameters#setAlgorithmConstraints(AlgorithmConstraints)229*/230public abstract void checkServerTrusted(X509Certificate[] chain,231String authType, SSLEngine engine) throws CertificateException;232233}234235236