3002N/A/*
3002N/A * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
3002N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3002N/A *
3002N/A * This code is free software; you can redistribute it and/or modify it
3002N/A * under the terms of the GNU General Public License version 2 only, as
3002N/A * published by the Free Software Foundation. Oracle designates this
3002N/A * particular file as subject to the "Classpath" exception as provided
3002N/A * by Oracle in the LICENSE file that accompanied this code.
3002N/A *
3002N/A * This code is distributed in the hope that it will be useful, but WITHOUT
3002N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3002N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3002N/A * version 2 for more details (a copy is included in the LICENSE file that
3002N/A * accompanied this code).
3002N/A *
3002N/A * You should have received a copy of the GNU General Public License version
3002N/A * 2 along with this work; if not, write to the Free Software Foundation,
3002N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3002N/A *
3002N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3002N/A * or visit www.oracle.com if you need additional information or have any
3002N/A * questions.
3002N/A */
3002N/A
3002N/Apackage javax.net.ssl;
3002N/A
3002N/Aimport java.net.Socket;
3002N/Aimport javax.net.ssl.X509TrustManager;
3002N/A
3002N/Aimport java.security.cert.X509Certificate;
3002N/Aimport java.security.cert.CertificateException;
3002N/A
3002N/A/**
3002N/A * Extensions to the <code>X509TrustManager</code> interface to support
3002N/A * SSL/TLS connection sensitive trust management.
3002N/A * <p>
3002N/A * To prevent man-in-the-middle attacks, hostname checks can be done
3002N/A * to verify that the hostname in an end-entity certificate matches the
3002N/A * targeted hostname. TLS does not require such checks, but some protocols
3002N/A * over TLS (such as HTTPS) do. In earlier versions of the JDK, the
3002N/A * certificate chain checks were done at the SSL/TLS layer, and the hostname
3002N/A * verification checks were done at the layer over TLS. This class allows
3002N/A * for the checking to be done during a single call to this class.
3002N/A * <p>
3002N/A * RFC 2830 defines the server identification specification for the "LDAPS"
3002N/A * algorithm. RFC 2818 defines both the server identification and the
3002N/A * client identification specification for the "HTTPS" algorithm.
3002N/A *
3002N/A * @see X509TrustManager
3002N/A * @see HostnameVerifier
3002N/A *
3002N/A * @since 1.7
3002N/A */
3002N/Apublic abstract class X509ExtendedTrustManager implements X509TrustManager {
3002N/A /**
3002N/A * Given the partial or complete certificate chain provided by the
3002N/A * peer, build and validate the certificate path based on the
3002N/A * authentication type and ssl parameters.
3002N/A * <p>
3002N/A * The authentication type is determined by the actual certificate
3002N/A * used. For instance, if RSAPublicKey is used, the authType
3002N/A * should be "RSA". Checking is case-sensitive.
3002N/A * <p>
3002N/A * If the <code>socket</code> parameter is an instance of
3319N/A * {@link javax.net.ssl.SSLSocket}, and the endpoint identification
3002N/A * algorithm of the <code>SSLParameters</code> is non-empty, to prevent
3002N/A * man-in-the-middle attacks, the address that the <code>socket</code>
3002N/A * connected to should be checked against the peer's identity presented
3002N/A * in the end-entity X509 certificate, as specified in the endpoint
3002N/A * identification algorithm.
3002N/A * <p>
3002N/A * If the <code>socket</code> parameter is an instance of
3319N/A * {@link javax.net.ssl.SSLSocket}, and the algorithm constraints of the
3002N/A * <code>SSLParameters</code> is non-null, for every certificate in the
3002N/A * certification path, fields such as subject public key, the signature
3002N/A * algorithm, key usage, extended key usage, etc. need to conform to the
3002N/A * algorithm constraints in place on this socket.
3002N/A *
3002N/A * @param chain the peer certificate chain
3002N/A * @param authType the key exchange algorithm used
3002N/A * @param socket the socket used for this connection. This parameter
3002N/A * can be null, which indicates that implementations need not check
3002N/A * the ssl parameters
3002N/A * @throws IllegalArgumentException if null or zero-length array is passed
3002N/A * in for the <code>chain</code> parameter or if null or zero-length
3002N/A * string is passed in for the <code>authType</code> parameter
3002N/A * @throws CertificateException if the certificate chain is not trusted
3002N/A * by this TrustManager
3002N/A *
3319N/A * @see SSLParameters#getEndpointIdentificationAlgorithm
3319N/A * @see SSLParameters#setEndpointIdentificationAlgorithm(String)
3002N/A * @see SSLParameters#getAlgorithmConstraints
3002N/A * @see SSLParameters#setAlgorithmConstraints(AlgorithmConstraints)
3002N/A */
3002N/A public abstract void checkClientTrusted(X509Certificate[] chain,
3002N/A String authType, Socket socket) throws CertificateException;
3002N/A
3002N/A /**
3002N/A * Given the partial or complete certificate chain provided by the
3002N/A * peer, build and validate the certificate path based on the
3002N/A * authentication type and ssl parameters.
3002N/A * <p>
3002N/A * The authentication type is the key exchange algorithm portion
3002N/A * of the cipher suites represented as a String, such as "RSA",
3002N/A * "DHE_DSS". Note: for some exportable cipher suites, the key
3002N/A * exchange algorithm is determined at run time during the
3002N/A * handshake. For instance, for TLS_RSA_EXPORT_WITH_RC4_40_MD5,
3002N/A * the authType should be RSA_EXPORT when an ephemeral RSA key is
3002N/A * used for the key exchange, and RSA when the key from the server
3002N/A * certificate is used. Checking is case-sensitive.
3002N/A * <p>
3002N/A * If the <code>socket</code> parameter is an instance of
3319N/A * {@link javax.net.ssl.SSLSocket}, and the endpoint identification
3002N/A * algorithm of the <code>SSLParameters</code> is non-empty, to prevent
3002N/A * man-in-the-middle attacks, the address that the <code>socket</code>
3002N/A * connected to should be checked against the peer's identity presented
3002N/A * in the end-entity X509 certificate, as specified in the endpoint
3002N/A * identification algorithm.
3002N/A * <p>
3002N/A * If the <code>socket</code> parameter is an instance of
3319N/A * {@link javax.net.ssl.SSLSocket}, and the algorithm constraints of the
3002N/A * <code>SSLParameters</code> is non-null, for every certificate in the
3002N/A * certification path, fields such as subject public key, the signature
3002N/A * algorithm, key usage, extended key usage, etc. need to conform to the
3002N/A * algorithm constraints in place on this socket.
3002N/A *
3002N/A * @param chain the peer certificate chain
3002N/A * @param authType the key exchange algorithm used
3002N/A * @param socket the socket used for this connection. This parameter
3002N/A * can be null, which indicates that implementations need not check
3002N/A * the ssl parameters
3002N/A * @throws IllegalArgumentException if null or zero-length array is passed
3002N/A * in for the <code>chain</code> parameter or if null or zero-length
3002N/A * string is passed in for the <code>authType</code> parameter
3002N/A * @throws CertificateException if the certificate chain is not trusted
3002N/A * by this TrustManager
3002N/A *
3319N/A * @see SSLParameters#getEndpointIdentificationAlgorithm
3319N/A * @see SSLParameters#setEndpointIdentificationAlgorithm(String)
3002N/A * @see SSLParameters#getAlgorithmConstraints
3002N/A * @see SSLParameters#setAlgorithmConstraints(AlgorithmConstraints)
3002N/A */
3002N/A public abstract void checkServerTrusted(X509Certificate[] chain,
3002N/A String authType, Socket socket) throws CertificateException;
3002N/A
3002N/A /**
3002N/A * Given the partial or complete certificate chain provided by the
3002N/A * peer, build and validate the certificate path based on the
3002N/A * authentication type and ssl parameters.
3002N/A * <p>
3002N/A * The authentication type is determined by the actual certificate
3002N/A * used. For instance, if RSAPublicKey is used, the authType
3002N/A * should be "RSA". Checking is case-sensitive.
3002N/A * <p>
3002N/A * If the <code>engine</code> parameter is available, and the endpoint
3002N/A * identification algorithm of the <code>SSLParameters</code> is
3002N/A * non-empty, to prevent man-in-the-middle attacks, the address that
3002N/A * the <code>engine</code> connected to should be checked against
3002N/A * the peer's identity presented in the end-entity X509 certificate,
3002N/A * as specified in the endpoint identification algorithm.
3002N/A * <p>
3002N/A * If the <code>engine</code> parameter is available, and the algorithm
3002N/A * constraints of the <code>SSLParameters</code> is non-null, for every
3002N/A * certificate in the certification path, fields such as subject public
3002N/A * key, the signature algorithm, key usage, extended key usage, etc.
3002N/A * need to conform to the algorithm constraints in place on this engine.
3002N/A *
3002N/A * @param chain the peer certificate chain
3002N/A * @param authType the key exchange algorithm used
3002N/A * @param engine the engine used for this connection. This parameter
3002N/A * can be null, which indicates that implementations need not check
3002N/A * the ssl parameters
3002N/A * @throws IllegalArgumentException if null or zero-length array is passed
3002N/A * in for the <code>chain</code> parameter or if null or zero-length
3002N/A * string is passed in for the <code>authType</code> parameter
3002N/A * @throws CertificateException if the certificate chain is not trusted
3002N/A * by this TrustManager
3002N/A *
3319N/A * @see SSLParameters#getEndpointIdentificationAlgorithm
3319N/A * @see SSLParameters#setEndpointIdentificationAlgorithm(String)
3002N/A * @see SSLParameters#getAlgorithmConstraints
3002N/A * @see SSLParameters#setAlgorithmConstraints(AlgorithmConstraints)
3002N/A */
3002N/A public abstract void checkClientTrusted(X509Certificate[] chain,
3002N/A String authType, SSLEngine engine) throws CertificateException;
3002N/A
3002N/A /**
3002N/A * Given the partial or complete certificate chain provided by the
3002N/A * peer, build and validate the certificate path based on the
3002N/A * authentication type and ssl parameters.
3002N/A * <p>
3002N/A * The authentication type is the key exchange algorithm portion
3002N/A * of the cipher suites represented as a String, such as "RSA",
3002N/A * "DHE_DSS". Note: for some exportable cipher suites, the key
3002N/A * exchange algorithm is determined at run time during the
3002N/A * handshake. For instance, for TLS_RSA_EXPORT_WITH_RC4_40_MD5,
3002N/A * the authType should be RSA_EXPORT when an ephemeral RSA key is
3002N/A * used for the key exchange, and RSA when the key from the server
3002N/A * certificate is used. Checking is case-sensitive.
3002N/A * <p>
3002N/A * If the <code>engine</code> parameter is available, and the endpoint
3002N/A * identification algorithm of the <code>SSLParameters</code> is
3002N/A * non-empty, to prevent man-in-the-middle attacks, the address that
3002N/A * the <code>engine</code> connected to should be checked against
3002N/A * the peer's identity presented in the end-entity X509 certificate,
3002N/A * as specified in the endpoint identification algorithm.
3002N/A * <p>
3002N/A * If the <code>engine</code> parameter is available, and the algorithm
3002N/A * constraints of the <code>SSLParameters</code> is non-null, for every
3002N/A * certificate in the certification path, fields such as subject public
3002N/A * key, the signature algorithm, key usage, extended key usage, etc.
3002N/A * need to conform to the algorithm constraints in place on this engine.
3002N/A *
3002N/A * @param chain the peer certificate chain
3002N/A * @param authType the key exchange algorithm used
3002N/A * @param engine the engine used for this connection. This parameter
3002N/A * can be null, which indicates that implementations need not check
3002N/A * the ssl parameters
3002N/A * @throws IllegalArgumentException if null or zero-length array is passed
3002N/A * in for the <code>chain</code> parameter or if null or zero-length
3002N/A * string is passed in for the <code>authType</code> parameter
3002N/A * @throws CertificateException if the certificate chain is not trusted
3002N/A * by this TrustManager
3002N/A *
3319N/A * @see SSLParameters#getEndpointIdentificationAlgorithm
3319N/A * @see SSLParameters#setEndpointIdentificationAlgorithm(String)
3002N/A * @see SSLParameters#getAlgorithmConstraints
3002N/A * @see SSLParameters#setAlgorithmConstraints(AlgorithmConstraints)
3002N/A */
3002N/A public abstract void checkServerTrusted(X509Certificate[] chain,
3002N/A String authType, SSLEngine engine) throws CertificateException;
3002N/A
3002N/A}