Path: blob/master/src/java.base/share/classes/javax/net/ssl/X509ExtendedTrustManager.java
41159 views
/*1* Copyright (c) 2010, 2020, 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} interface to support35* SSL/TLS/DTLS 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/DTLS does not require such checks, but some40* protocols over TLS/DTLS (such as HTTPS) do. In earlier versions of the41* JDK, the certificate chain checks were done at the SSL/TLS/DTLS layer,42* and the hostname verification checks were done at the layer over TLS/DTLS.43* This class allows for the checking to be done during a single call to44* this class.45* <p>46* RFC 2830 defines the server identification specification for the "LDAPS"47* algorithm. RFC 2818 defines both the server identification and the48* client identification specification for the "HTTPS" algorithm.49*50* @see X509TrustManager51* @see HostnameVerifier52*53* @since 1.754*/55public abstract class X509ExtendedTrustManager implements X509TrustManager {56/**57* Constructor for subclasses to call.58*/59public X509ExtendedTrustManager() {}6061/**62* Given the partial or complete certificate chain provided by the63* peer, build and validate the certificate path based on the64* authentication type and ssl parameters.65* <p>66* The authentication type is determined by the actual certificate67* used. For instance, if RSAPublicKey is used, the authType68* should be "RSA". Checking is case-sensitive.69* <p>70* If the {@code socket} parameter is an instance of71* {@link javax.net.ssl.SSLSocket}, and the endpoint identification72* algorithm of the {@code SSLParameters} is non-empty, to prevent73* man-in-the-middle attacks, the address that the {@code socket}74* connected to should be checked against the peer's identity presented75* in the end-entity X509 certificate, as specified in the endpoint76* identification algorithm.77* <p>78* If the {@code socket} parameter is an instance of79* {@link javax.net.ssl.SSLSocket}, and the algorithm constraints of the80* {@code SSLParameters} is non-null, for every certificate in the81* certification path, fields such as subject public key, the signature82* algorithm, key usage, extended key usage, etc. need to conform to the83* algorithm constraints in place on this socket.84*85* @param chain the peer certificate chain86* @param authType the key exchange algorithm used87* @param socket the socket used for this connection. This parameter88* can be null, which indicates that implementations need not check89* the ssl parameters90* @throws IllegalArgumentException if null or zero-length array is passed91* in for the {@code chain} parameter or if null or zero-length92* string is passed in for the {@code authType} parameter93* @throws CertificateException if the certificate chain is not trusted94* by this TrustManager95*96* @see SSLParameters#getEndpointIdentificationAlgorithm97* @see SSLParameters#setEndpointIdentificationAlgorithm(String)98* @see SSLParameters#getAlgorithmConstraints99* @see SSLParameters#setAlgorithmConstraints(AlgorithmConstraints)100*/101public abstract void checkClientTrusted(X509Certificate[] chain,102String authType, Socket socket) throws CertificateException;103104/**105* Given the partial or complete certificate chain provided by the106* peer, build and validate the certificate path based on the107* authentication type and ssl parameters.108* <p>109* The authentication type is the key exchange algorithm portion110* of the cipher suites represented as a String, such as "RSA",111* "DHE_DSS". Note: for some exportable cipher suites, the key112* exchange algorithm is determined at run time during the113* handshake. For instance, for TLS_RSA_EXPORT_WITH_RC4_40_MD5,114* the authType should be RSA_EXPORT when an ephemeral RSA key is115* used for the key exchange, and RSA when the key from the server116* certificate is used. Checking is case-sensitive.117* <p>118* If the {@code socket} parameter is an instance of119* {@link javax.net.ssl.SSLSocket}, and the endpoint identification120* algorithm of the {@code SSLParameters} is non-empty, to prevent121* man-in-the-middle attacks, the address that the {@code socket}122* connected to should be checked against the peer's identity presented123* in the end-entity X509 certificate, as specified in the endpoint124* identification algorithm.125* <p>126* If the {@code socket} parameter is an instance of127* {@link javax.net.ssl.SSLSocket}, and the algorithm constraints of the128* {@code SSLParameters} is non-null, for every certificate in the129* certification path, fields such as subject public key, the signature130* algorithm, key usage, extended key usage, etc. need to conform to the131* algorithm constraints in place on this socket.132*133* @param chain the peer certificate chain134* @param authType the key exchange algorithm used135* @param socket the socket used for this connection. This parameter136* can be null, which indicates that implementations need not check137* the ssl parameters138* @throws IllegalArgumentException if null or zero-length array is passed139* in for the {@code chain} parameter or if null or zero-length140* string is passed in for the {@code authType} parameter141* @throws CertificateException if the certificate chain is not trusted142* by this TrustManager143*144* @see SSLParameters#getEndpointIdentificationAlgorithm145* @see SSLParameters#setEndpointIdentificationAlgorithm(String)146* @see SSLParameters#getAlgorithmConstraints147* @see SSLParameters#setAlgorithmConstraints(AlgorithmConstraints)148*/149public abstract void checkServerTrusted(X509Certificate[] chain,150String authType, Socket socket) throws CertificateException;151152/**153* Given the partial or complete certificate chain provided by the154* peer, build and validate the certificate path based on the155* authentication type and ssl parameters.156* <p>157* The authentication type is determined by the actual certificate158* used. For instance, if RSAPublicKey is used, the authType159* should be "RSA". Checking is case-sensitive.160* <p>161* If the {@code engine} parameter is available, and the endpoint162* identification algorithm of the {@code SSLParameters} is163* non-empty, to prevent man-in-the-middle attacks, the address that164* the {@code engine} connected to should be checked against165* the peer's identity presented in the end-entity X509 certificate,166* as specified in the endpoint identification algorithm.167* <p>168* If the {@code engine} parameter is available, and the algorithm169* constraints of the {@code SSLParameters} is non-null, for every170* certificate in the certification path, fields such as subject public171* key, the signature algorithm, key usage, extended key usage, etc.172* need to conform to the algorithm constraints in place on this engine.173*174* @param chain the peer certificate chain175* @param authType the key exchange algorithm used176* @param engine the engine used for this connection. This parameter177* can be null, which indicates that implementations need not check178* the ssl parameters179* @throws IllegalArgumentException if null or zero-length array is passed180* in for the {@code chain} parameter or if null or zero-length181* string is passed in for the {@code authType} parameter182* @throws CertificateException if the certificate chain is not trusted183* by this TrustManager184*185* @see SSLParameters#getEndpointIdentificationAlgorithm186* @see SSLParameters#setEndpointIdentificationAlgorithm(String)187* @see SSLParameters#getAlgorithmConstraints188* @see SSLParameters#setAlgorithmConstraints(AlgorithmConstraints)189*/190public abstract void checkClientTrusted(X509Certificate[] chain,191String authType, SSLEngine engine) throws CertificateException;192193/**194* Given the partial or complete certificate chain provided by the195* peer, build and validate the certificate path based on the196* authentication type and ssl parameters.197* <p>198* The authentication type is the key exchange algorithm portion199* of the cipher suites represented as a String, such as "RSA",200* "DHE_DSS". Note: for some exportable cipher suites, the key201* exchange algorithm is determined at run time during the202* handshake. For instance, for TLS_RSA_EXPORT_WITH_RC4_40_MD5,203* the authType should be RSA_EXPORT when an ephemeral RSA key is204* used for the key exchange, and RSA when the key from the server205* certificate is used. Checking is case-sensitive.206* <p>207* If the {@code engine} parameter is available, and the endpoint208* identification algorithm of the {@code SSLParameters} is209* non-empty, to prevent man-in-the-middle attacks, the address that210* the {@code engine} connected to should be checked against211* the peer's identity presented in the end-entity X509 certificate,212* as specified in the endpoint identification algorithm.213* <p>214* If the {@code engine} parameter is available, and the algorithm215* constraints of the {@code SSLParameters} is non-null, for every216* certificate in the certification path, fields such as subject public217* key, the signature algorithm, key usage, extended key usage, etc.218* need to conform to the algorithm constraints in place on this engine.219*220* @param chain the peer certificate chain221* @param authType the key exchange algorithm used222* @param engine the engine used for this connection. This parameter223* can be null, which indicates that implementations need not check224* the ssl parameters225* @throws IllegalArgumentException if null or zero-length array is passed226* in for the {@code chain} parameter or if null or zero-length227* string is passed in for the {@code authType} parameter228* @throws CertificateException if the certificate chain is not trusted229* by this TrustManager230*231* @see SSLParameters#getEndpointIdentificationAlgorithm232* @see SSLParameters#setEndpointIdentificationAlgorithm(String)233* @see SSLParameters#getAlgorithmConstraints234* @see SSLParameters#setAlgorithmConstraints(AlgorithmConstraints)235*/236public abstract void checkServerTrusted(X509Certificate[] chain,237String authType, SSLEngine engine) throws CertificateException;238239}240241242