src/java.base/share/classes/javax/net/ssl/X509ExtendedTrustManager.java

Print this page


   1 /*
   2  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package javax.net.ssl;
  27 
  28 import java.net.Socket;
  29 import javax.net.ssl.X509TrustManager;
  30 
  31 import java.security.cert.X509Certificate;
  32 import java.security.cert.CertificateException;
  33 
  34 /**
  35  * Extensions to the <code>X509TrustManager</code> interface to support
  36  * SSL/TLS connection sensitive trust management.
  37  * <p>
  38  * To prevent man-in-the-middle attacks, hostname checks can be done
  39  * to verify that the hostname in an end-entity certificate matches the
  40  * targeted hostname.  TLS does not require such checks, but some protocols
  41  * over TLS (such as HTTPS) do.  In earlier versions of the JDK, the
  42  * certificate chain checks were done at the SSL/TLS layer, and the hostname
  43  * verification checks were done at the layer over TLS.  This class allows
  44  * for the checking to be done during a single call to 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 the
  48  * client identification specification for the "HTTPS" algorithm.
  49  *
  50  * @see X509TrustManager
  51  * @see HostnameVerifier
  52  *
  53  * @since 1.7
  54  */
  55 public abstract class X509ExtendedTrustManager implements X509TrustManager {
  56     /**
  57      * Given the partial or complete certificate chain provided by the
  58      * peer, build and validate the certificate path based on the
  59      * authentication type and ssl parameters.
  60      * <p>
  61      * The authentication type is determined by the actual certificate
  62      * used. For instance, if RSAPublicKey is used, the authType
  63      * should be "RSA". Checking is case-sensitive.
  64      * <p>
  65      * If the <code>socket</code> parameter is an instance of
  66      * {@link javax.net.ssl.SSLSocket}, and the endpoint identification
  67      * algorithm of the <code>SSLParameters</code> is non-empty, to prevent
  68      * man-in-the-middle attacks, the address that the <code>socket</code>
  69      * connected to should be checked against the peer's identity presented
  70      * in the end-entity X509 certificate, as specified in the endpoint
  71      * identification algorithm.
  72      * <p>
  73      * If the <code>socket</code> parameter is an instance of
  74      * {@link javax.net.ssl.SSLSocket}, and the algorithm constraints of the
  75      * <code>SSLParameters</code> is non-null, for every certificate in the
  76      * certification path, fields such as subject public key, the signature
  77      * algorithm, key usage, extended key usage, etc. need to conform to the
  78      * algorithm constraints in place on this socket.
  79      *
  80      * @param chain the peer certificate chain
  81      * @param authType the key exchange algorithm used
  82      * @param socket the socket used for this connection. This parameter
  83      *        can be null, which indicates that implementations need not check
  84      *        the ssl parameters
  85      * @throws IllegalArgumentException if null or zero-length array is passed
  86      *        in for the <code>chain</code> parameter or if null or zero-length
  87      *        string is passed in for the <code>authType</code> parameter
  88      * @throws CertificateException if the certificate chain is not trusted
  89      *        by this TrustManager
  90      *
  91      * @see SSLParameters#getEndpointIdentificationAlgorithm
  92      * @see SSLParameters#setEndpointIdentificationAlgorithm(String)
  93      * @see SSLParameters#getAlgorithmConstraints
  94      * @see SSLParameters#setAlgorithmConstraints(AlgorithmConstraints)
  95      */
  96     public abstract void checkClientTrusted(X509Certificate[] chain,
  97             String authType, Socket socket) throws CertificateException;
  98 
  99     /**
 100      * Given the partial or complete certificate chain provided by the
 101      * peer, build and validate the certificate path based on the
 102      * authentication type and ssl parameters.
 103      * <p>
 104      * The authentication type is the key exchange algorithm portion
 105      * of the cipher suites represented as a String, such as "RSA",
 106      * "DHE_DSS". Note: for some exportable cipher suites, the key
 107      * exchange algorithm is determined at run time during the
 108      * handshake. For instance, for TLS_RSA_EXPORT_WITH_RC4_40_MD5,
 109      * the authType should be RSA_EXPORT when an ephemeral RSA key is
 110      * used for the key exchange, and RSA when the key from the server
 111      * certificate is used. Checking is case-sensitive.
 112      * <p>
 113      * If the <code>socket</code> parameter is an instance of
 114      * {@link javax.net.ssl.SSLSocket}, and the endpoint identification
 115      * algorithm of the <code>SSLParameters</code> is non-empty, to prevent
 116      * man-in-the-middle attacks, the address that the <code>socket</code>
 117      * connected to should be checked against the peer's identity presented
 118      * in the end-entity X509 certificate, as specified in the endpoint
 119      * identification algorithm.
 120      * <p>
 121      * If the <code>socket</code> parameter is an instance of
 122      * {@link javax.net.ssl.SSLSocket}, and the algorithm constraints of the
 123      *  <code>SSLParameters</code> is non-null, for every certificate in the
 124      * certification path, fields such as subject public key, the signature
 125      * algorithm, key usage, extended key usage, etc. need to conform to the
 126      * algorithm constraints in place on this socket.
 127      *
 128      * @param chain the peer certificate chain
 129      * @param authType the key exchange algorithm used
 130      * @param socket the socket used for this connection. This parameter
 131      *        can be null, which indicates that implementations need not check
 132      *        the ssl parameters
 133      * @throws IllegalArgumentException if null or zero-length array is passed
 134      *        in for the <code>chain</code> parameter or if null or zero-length
 135      *        string is passed in for the <code>authType</code> parameter
 136      * @throws CertificateException if the certificate chain is not trusted
 137      *        by this TrustManager
 138      *
 139      * @see SSLParameters#getEndpointIdentificationAlgorithm
 140      * @see SSLParameters#setEndpointIdentificationAlgorithm(String)
 141      * @see SSLParameters#getAlgorithmConstraints
 142      * @see SSLParameters#setAlgorithmConstraints(AlgorithmConstraints)
 143      */
 144     public abstract void checkServerTrusted(X509Certificate[] chain,
 145         String authType, Socket socket) throws CertificateException;
 146 
 147     /**
 148      * Given the partial or complete certificate chain provided by the
 149      * peer, build and validate the certificate path based on the
 150      * authentication type and ssl parameters.
 151      * <p>
 152      * The authentication type is determined by the actual certificate
 153      * used. For instance, if RSAPublicKey is used, the authType
 154      * should be "RSA". Checking is case-sensitive.
 155      * <p>
 156      * If the <code>engine</code> parameter is available, and the endpoint
 157      * identification algorithm of the <code>SSLParameters</code> is
 158      * non-empty, to prevent man-in-the-middle attacks, the address that
 159      * the <code>engine</code> connected to should be checked against
 160      * the peer's identity presented in the end-entity X509 certificate,
 161      * as specified in the endpoint identification algorithm.
 162      * <p>
 163      * If the <code>engine</code> parameter is available, and the algorithm
 164      * constraints of the <code>SSLParameters</code> is non-null, for every
 165      * certificate in the certification path, fields such as subject public
 166      * key, the signature algorithm, key usage, extended key usage, etc.
 167      * need to conform to the algorithm constraints in place on this engine.
 168      *
 169      * @param chain the peer certificate chain
 170      * @param authType the key exchange algorithm used
 171      * @param engine the engine used for this connection. This parameter
 172      *        can be null, which indicates that implementations need not check
 173      *        the ssl parameters
 174      * @throws IllegalArgumentException if null or zero-length array is passed
 175      *        in for the <code>chain</code> parameter or if null or zero-length
 176      *        string is passed in for the <code>authType</code> parameter
 177      * @throws CertificateException if the certificate chain is not trusted
 178      *        by this TrustManager
 179      *
 180      * @see SSLParameters#getEndpointIdentificationAlgorithm
 181      * @see SSLParameters#setEndpointIdentificationAlgorithm(String)
 182      * @see SSLParameters#getAlgorithmConstraints
 183      * @see SSLParameters#setAlgorithmConstraints(AlgorithmConstraints)
 184      */
 185     public abstract void checkClientTrusted(X509Certificate[] chain,
 186         String authType, SSLEngine engine) throws CertificateException;
 187 
 188     /**
 189      * Given the partial or complete certificate chain provided by the
 190      * peer, build and validate the certificate path based on the
 191      * authentication type and ssl parameters.
 192      * <p>
 193      * The authentication type is the key exchange algorithm portion
 194      * of the cipher suites represented as a String, such as "RSA",
 195      * "DHE_DSS". Note: for some exportable cipher suites, the key
 196      * exchange algorithm is determined at run time during the
 197      * handshake. For instance, for TLS_RSA_EXPORT_WITH_RC4_40_MD5,
 198      * the authType should be RSA_EXPORT when an ephemeral RSA key is
 199      * used for the key exchange, and RSA when the key from the server
 200      * certificate is used. Checking is case-sensitive.
 201      * <p>
 202      * If the <code>engine</code> parameter is available, and the endpoint
 203      * identification algorithm of the <code>SSLParameters</code> is
 204      * non-empty, to prevent man-in-the-middle attacks, the address that
 205      * the <code>engine</code> connected to should be checked against
 206      * the peer's identity presented in the end-entity X509 certificate,
 207      * as specified in the endpoint identification algorithm.
 208      * <p>
 209      * If the <code>engine</code> parameter is available, and the algorithm
 210      * constraints of the <code>SSLParameters</code> is non-null, for every
 211      * certificate in the certification path, fields such as subject public
 212      * key, the signature algorithm, key usage, extended key usage, etc.
 213      * need to conform to the algorithm constraints in place on this engine.
 214      *
 215      * @param chain the peer certificate chain
 216      * @param authType the key exchange algorithm used
 217      * @param engine the engine used for this connection. This parameter
 218      *        can be null, which indicates that implementations need not check
 219      *        the ssl parameters
 220      * @throws IllegalArgumentException if null or zero-length array is passed
 221      *        in for the <code>chain</code> parameter or if null or zero-length
 222      *        string is passed in for the <code>authType</code> parameter
 223      * @throws CertificateException if the certificate chain is not trusted
 224      *        by this TrustManager
 225      *
 226      * @see SSLParameters#getEndpointIdentificationAlgorithm
 227      * @see SSLParameters#setEndpointIdentificationAlgorithm(String)
 228      * @see SSLParameters#getAlgorithmConstraints
 229      * @see SSLParameters#setAlgorithmConstraints(AlgorithmConstraints)
 230      */
 231     public abstract void checkServerTrusted(X509Certificate[] chain,
 232         String authType, SSLEngine engine) throws CertificateException;
 233 
 234 }
   1 /*
   2  * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package javax.net.ssl;
  27 
  28 import java.net.Socket;
  29 import javax.net.ssl.X509TrustManager;
  30 
  31 import java.security.cert.X509Certificate;
  32 import java.security.cert.CertificateException;
  33 
  34 /**
  35  * Extensions to the {@code X509TrustManager} interface to support
  36  * SSL/TLS/DTLS connection sensitive trust management.
  37  * <p>
  38  * To prevent man-in-the-middle attacks, hostname checks can be done
  39  * to verify that the hostname in an end-entity certificate matches the
  40  * targeted hostname.  TLS/DTLS does not require such checks, but some
  41  * protocols over TLS/DTLS (such as HTTPS) do.  In earlier versions of the
  42  * JDK, the certificate chain checks were done at the SSL/TLS/DTLS layer,
  43  * and the hostname verification checks were done at the layer over TLS/DTLS.
  44  * This class allows for the checking to be done during a single call to
  45  * this class.
  46  * <p>
  47  * RFC 2830 defines the server identification specification for the "LDAPS"
  48  * algorithm. RFC 2818 defines both the server identification and the
  49  * client identification specification for the "HTTPS" algorithm.
  50  *
  51  * @see X509TrustManager
  52  * @see HostnameVerifier
  53  *
  54  * @since 1.7
  55  */
  56 public abstract class X509ExtendedTrustManager implements X509TrustManager {
  57     /**
  58      * Given the partial or complete certificate chain provided by the
  59      * peer, build and validate the certificate path based on the
  60      * authentication type and ssl parameters.
  61      * <p>
  62      * The authentication type is determined by the actual certificate
  63      * used. For instance, if RSAPublicKey is used, the authType
  64      * should be "RSA". Checking is case-sensitive.
  65      * <p>
  66      * If the {@code socket} parameter is an instance of
  67      * {@link javax.net.ssl.SSLSocket}, and the endpoint identification
  68      * algorithm of the {@code SSLParameters} is non-empty, to prevent
  69      * man-in-the-middle attacks, the address that the {@code socket}
  70      * connected to should be checked against the peer's identity presented
  71      * in the end-entity X509 certificate, as specified in the endpoint
  72      * identification algorithm.
  73      * <p>
  74      * If the {@code socket} parameter is an instance of
  75      * {@link javax.net.ssl.SSLSocket}, and the algorithm constraints of the
  76      * {@code SSLParameters} is non-null, for every certificate in the
  77      * certification path, fields such as subject public key, the signature
  78      * algorithm, key usage, extended key usage, etc. need to conform to the
  79      * algorithm constraints in place on this socket.
  80      *
  81      * @param chain the peer certificate chain
  82      * @param authType the key exchange algorithm used
  83      * @param socket the socket used for this connection. This parameter
  84      *        can be null, which indicates that implementations need not check
  85      *        the ssl parameters
  86      * @throws IllegalArgumentException if null or zero-length array is passed
  87      *        in for the {@code chain} parameter or if null or zero-length
  88      *        string is passed in for the {@code authType} parameter
  89      * @throws CertificateException if the certificate chain is not trusted
  90      *        by this TrustManager
  91      *
  92      * @see SSLParameters#getEndpointIdentificationAlgorithm
  93      * @see SSLParameters#setEndpointIdentificationAlgorithm(String)
  94      * @see SSLParameters#getAlgorithmConstraints
  95      * @see SSLParameters#setAlgorithmConstraints(AlgorithmConstraints)
  96      */
  97     public abstract void checkClientTrusted(X509Certificate[] chain,
  98             String authType, Socket socket) throws CertificateException;
  99 
 100     /**
 101      * Given the partial or complete certificate chain provided by the
 102      * peer, build and validate the certificate path based on the
 103      * authentication type and ssl parameters.
 104      * <p>
 105      * The authentication type is the key exchange algorithm portion
 106      * of the cipher suites represented as a String, such as "RSA",
 107      * "DHE_DSS". Note: for some exportable cipher suites, the key
 108      * exchange algorithm is determined at run time during the
 109      * handshake. For instance, for TLS_RSA_EXPORT_WITH_RC4_40_MD5,
 110      * the authType should be RSA_EXPORT when an ephemeral RSA key is
 111      * used for the key exchange, and RSA when the key from the server
 112      * certificate is used. Checking is case-sensitive.
 113      * <p>
 114      * If the {@code socket} parameter is an instance of
 115      * {@link javax.net.ssl.SSLSocket}, and the endpoint identification
 116      * algorithm of the {@code SSLParameters} is non-empty, to prevent
 117      * man-in-the-middle attacks, the address that the {@code socket}
 118      * connected to should be checked against the peer's identity presented
 119      * in the end-entity X509 certificate, as specified in the endpoint
 120      * identification algorithm.
 121      * <p>
 122      * If the {@code socket} parameter is an instance of
 123      * {@link javax.net.ssl.SSLSocket}, and the algorithm constraints of the
 124      *  {@code SSLParameters} is non-null, for every certificate in the
 125      * certification path, fields such as subject public key, the signature
 126      * algorithm, key usage, extended key usage, etc. need to conform to the
 127      * algorithm constraints in place on this socket.
 128      *
 129      * @param chain the peer certificate chain
 130      * @param authType the key exchange algorithm used
 131      * @param socket the socket used for this connection. This parameter
 132      *        can be null, which indicates that implementations need not check
 133      *        the ssl parameters
 134      * @throws IllegalArgumentException if null or zero-length array is passed
 135      *        in for the {@code chain} parameter or if null or zero-length
 136      *        string is passed in for the {@code authType} parameter
 137      * @throws CertificateException if the certificate chain is not trusted
 138      *        by this TrustManager
 139      *
 140      * @see SSLParameters#getEndpointIdentificationAlgorithm
 141      * @see SSLParameters#setEndpointIdentificationAlgorithm(String)
 142      * @see SSLParameters#getAlgorithmConstraints
 143      * @see SSLParameters#setAlgorithmConstraints(AlgorithmConstraints)
 144      */
 145     public abstract void checkServerTrusted(X509Certificate[] chain,
 146         String authType, Socket socket) throws CertificateException;
 147 
 148     /**
 149      * Given the partial or complete certificate chain provided by the
 150      * peer, build and validate the certificate path based on the
 151      * authentication type and ssl parameters.
 152      * <p>
 153      * The authentication type is determined by the actual certificate
 154      * used. For instance, if RSAPublicKey is used, the authType
 155      * should be "RSA". Checking is case-sensitive.
 156      * <p>
 157      * If the {@code engine} parameter is available, and the endpoint
 158      * identification algorithm of the {@code SSLParameters} is
 159      * non-empty, to prevent man-in-the-middle attacks, the address that
 160      * the {@code engine} connected to should be checked against
 161      * the peer's identity presented in the end-entity X509 certificate,
 162      * as specified in the endpoint identification algorithm.
 163      * <p>
 164      * If the {@code engine} parameter is available, and the algorithm
 165      * constraints of the {@code SSLParameters} is non-null, for every
 166      * certificate in the certification path, fields such as subject public
 167      * key, the signature algorithm, key usage, extended key usage, etc.
 168      * need to conform to the algorithm constraints in place on this engine.
 169      *
 170      * @param chain the peer certificate chain
 171      * @param authType the key exchange algorithm used
 172      * @param engine the engine used for this connection. This parameter
 173      *        can be null, which indicates that implementations need not check
 174      *        the ssl parameters
 175      * @throws IllegalArgumentException if null or zero-length array is passed
 176      *        in for the {@code chain} parameter or if null or zero-length
 177      *        string is passed in for the {@code authType} parameter
 178      * @throws CertificateException if the certificate chain is not trusted
 179      *        by this TrustManager
 180      *
 181      * @see SSLParameters#getEndpointIdentificationAlgorithm
 182      * @see SSLParameters#setEndpointIdentificationAlgorithm(String)
 183      * @see SSLParameters#getAlgorithmConstraints
 184      * @see SSLParameters#setAlgorithmConstraints(AlgorithmConstraints)
 185      */
 186     public abstract void checkClientTrusted(X509Certificate[] chain,
 187         String authType, SSLEngine engine) throws CertificateException;
 188 
 189     /**
 190      * Given the partial or complete certificate chain provided by the
 191      * peer, build and validate the certificate path based on the
 192      * authentication type and ssl parameters.
 193      * <p>
 194      * The authentication type is the key exchange algorithm portion
 195      * of the cipher suites represented as a String, such as "RSA",
 196      * "DHE_DSS". Note: for some exportable cipher suites, the key
 197      * exchange algorithm is determined at run time during the
 198      * handshake. For instance, for TLS_RSA_EXPORT_WITH_RC4_40_MD5,
 199      * the authType should be RSA_EXPORT when an ephemeral RSA key is
 200      * used for the key exchange, and RSA when the key from the server
 201      * certificate is used. Checking is case-sensitive.
 202      * <p>
 203      * If the {@code engine} parameter is available, and the endpoint
 204      * identification algorithm of the {@code SSLParameters} is
 205      * non-empty, to prevent man-in-the-middle attacks, the address that
 206      * the {@code engine} connected to should be checked against
 207      * the peer's identity presented in the end-entity X509 certificate,
 208      * as specified in the endpoint identification algorithm.
 209      * <p>
 210      * If the {@code engine} parameter is available, and the algorithm
 211      * constraints of the {@code SSLParameters} is non-null, for every
 212      * certificate in the certification path, fields such as subject public
 213      * key, the signature algorithm, key usage, extended key usage, etc.
 214      * need to conform to the algorithm constraints in place on this engine.
 215      *
 216      * @param chain the peer certificate chain
 217      * @param authType the key exchange algorithm used
 218      * @param engine the engine used for this connection. This parameter
 219      *        can be null, which indicates that implementations need not check
 220      *        the ssl parameters
 221      * @throws IllegalArgumentException if null or zero-length array is passed
 222      *        in for the {@code chain} parameter or if null or zero-length
 223      *        string is passed in for the {@code authType} parameter
 224      * @throws CertificateException if the certificate chain is not trusted
 225      *        by this TrustManager
 226      *
 227      * @see SSLParameters#getEndpointIdentificationAlgorithm
 228      * @see SSLParameters#setEndpointIdentificationAlgorithm(String)
 229      * @see SSLParameters#getAlgorithmConstraints
 230      * @see SSLParameters#setAlgorithmConstraints(AlgorithmConstraints)
 231      */
 232     public abstract void checkServerTrusted(X509Certificate[] chain,
 233         String authType, SSLEngine engine) throws CertificateException;
 234 
 235 }