30 |
30 |
31 import java.security.cert.X509Certificate; |
31 import java.security.cert.X509Certificate; |
32 import java.security.cert.CertificateException; |
32 import java.security.cert.CertificateException; |
33 |
33 |
34 /** |
34 /** |
35 * Extensions to the <code>X509TrustManager</code> interface to support |
35 * Extensions to the {@code X509TrustManager} interface to support |
36 * SSL/TLS connection sensitive trust management. |
36 * SSL/TLS/DTLS connection sensitive trust management. |
37 * <p> |
37 * <p> |
38 * To prevent man-in-the-middle attacks, hostname checks can be done |
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 |
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 |
40 * targeted hostname. TLS/DTLS does not require such checks, but some |
41 * over TLS (such as HTTPS) do. In earlier versions of the JDK, the |
41 * protocols over TLS/DTLS (such as HTTPS) do. In earlier versions of the |
42 * certificate chain checks were done at the SSL/TLS layer, and the hostname |
42 * JDK, the certificate chain checks were done at the SSL/TLS/DTLS layer, |
43 * verification checks were done at the layer over TLS. This class allows |
43 * and the hostname verification checks were done at the layer over TLS/DTLS. |
44 * for the checking to be done during a single call to this class. |
44 * This class allows for the checking to be done during a single call to |
|
45 * this class. |
45 * <p> |
46 * <p> |
46 * RFC 2830 defines the server identification specification for the "LDAPS" |
47 * RFC 2830 defines the server identification specification for the "LDAPS" |
47 * algorithm. RFC 2818 defines both the server identification and the |
48 * algorithm. RFC 2818 defines both the server identification and the |
48 * client identification specification for the "HTTPS" algorithm. |
49 * client identification specification for the "HTTPS" algorithm. |
49 * |
50 * |
60 * <p> |
61 * <p> |
61 * The authentication type is determined by the actual certificate |
62 * The authentication type is determined by the actual certificate |
62 * used. For instance, if RSAPublicKey is used, the authType |
63 * used. For instance, if RSAPublicKey is used, the authType |
63 * should be "RSA". Checking is case-sensitive. |
64 * should be "RSA". Checking is case-sensitive. |
64 * <p> |
65 * <p> |
65 * If the <code>socket</code> parameter is an instance of |
66 * If the {@code socket} parameter is an instance of |
66 * {@link javax.net.ssl.SSLSocket}, and the endpoint identification |
67 * {@link javax.net.ssl.SSLSocket}, and the endpoint identification |
67 * algorithm of the <code>SSLParameters</code> is non-empty, to prevent |
68 * algorithm of the {@code SSLParameters} is non-empty, to prevent |
68 * man-in-the-middle attacks, the address that the <code>socket</code> |
69 * man-in-the-middle attacks, the address that the {@code socket} |
69 * connected to should be checked against the peer's identity presented |
70 * connected to should be checked against the peer's identity presented |
70 * in the end-entity X509 certificate, as specified in the endpoint |
71 * in the end-entity X509 certificate, as specified in the endpoint |
71 * identification algorithm. |
72 * identification algorithm. |
72 * <p> |
73 * <p> |
73 * If the <code>socket</code> parameter is an instance of |
74 * If the {@code socket} parameter is an instance of |
74 * {@link javax.net.ssl.SSLSocket}, and the algorithm constraints of the |
75 * {@link javax.net.ssl.SSLSocket}, and the algorithm constraints of the |
75 * <code>SSLParameters</code> is non-null, for every certificate in the |
76 * {@code SSLParameters} is non-null, for every certificate in the |
76 * certification path, fields such as subject public key, the signature |
77 * 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, key usage, extended key usage, etc. need to conform to the |
78 * algorithm constraints in place on this socket. |
79 * algorithm constraints in place on this socket. |
79 * |
80 * |
80 * @param chain the peer certificate chain |
81 * @param chain the peer certificate chain |
81 * @param authType the key exchange algorithm used |
82 * @param authType the key exchange algorithm used |
82 * @param socket the socket used for this connection. This parameter |
83 * @param socket the socket used for this connection. This parameter |
83 * can be null, which indicates that implementations need not check |
84 * can be null, which indicates that implementations need not check |
84 * the ssl parameters |
85 * the ssl parameters |
85 * @throws IllegalArgumentException if null or zero-length array is passed |
86 * @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 * in for the {@code chain} parameter or if null or zero-length |
87 * string is passed in for the <code>authType</code> parameter |
88 * string is passed in for the {@code authType} parameter |
88 * @throws CertificateException if the certificate chain is not trusted |
89 * @throws CertificateException if the certificate chain is not trusted |
89 * by this TrustManager |
90 * by this TrustManager |
90 * |
91 * |
91 * @see SSLParameters#getEndpointIdentificationAlgorithm |
92 * @see SSLParameters#getEndpointIdentificationAlgorithm |
92 * @see SSLParameters#setEndpointIdentificationAlgorithm(String) |
93 * @see SSLParameters#setEndpointIdentificationAlgorithm(String) |
108 * handshake. For instance, for TLS_RSA_EXPORT_WITH_RC4_40_MD5, |
109 * 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 * 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 * used for the key exchange, and RSA when the key from the server |
111 * certificate is used. Checking is case-sensitive. |
112 * certificate is used. Checking is case-sensitive. |
112 * <p> |
113 * <p> |
113 * If the <code>socket</code> parameter is an instance of |
114 * If the {@code socket} parameter is an instance of |
114 * {@link javax.net.ssl.SSLSocket}, and the endpoint identification |
115 * {@link javax.net.ssl.SSLSocket}, and the endpoint identification |
115 * algorithm of the <code>SSLParameters</code> is non-empty, to prevent |
116 * algorithm of the {@code SSLParameters} is non-empty, to prevent |
116 * man-in-the-middle attacks, the address that the <code>socket</code> |
117 * man-in-the-middle attacks, the address that the {@code socket} |
117 * connected to should be checked against the peer's identity presented |
118 * connected to should be checked against the peer's identity presented |
118 * in the end-entity X509 certificate, as specified in the endpoint |
119 * in the end-entity X509 certificate, as specified in the endpoint |
119 * identification algorithm. |
120 * identification algorithm. |
120 * <p> |
121 * <p> |
121 * If the <code>socket</code> parameter is an instance of |
122 * If the {@code socket} parameter is an instance of |
122 * {@link javax.net.ssl.SSLSocket}, and the algorithm constraints of the |
123 * {@link javax.net.ssl.SSLSocket}, and the algorithm constraints of the |
123 * <code>SSLParameters</code> is non-null, for every certificate in the |
124 * {@code SSLParameters} is non-null, for every certificate in the |
124 * certification path, fields such as subject public key, the signature |
125 * 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, key usage, extended key usage, etc. need to conform to the |
126 * algorithm constraints in place on this socket. |
127 * algorithm constraints in place on this socket. |
127 * |
128 * |
128 * @param chain the peer certificate chain |
129 * @param chain the peer certificate chain |
129 * @param authType the key exchange algorithm used |
130 * @param authType the key exchange algorithm used |
130 * @param socket the socket used for this connection. This parameter |
131 * @param socket the socket used for this connection. This parameter |
131 * can be null, which indicates that implementations need not check |
132 * can be null, which indicates that implementations need not check |
132 * the ssl parameters |
133 * the ssl parameters |
133 * @throws IllegalArgumentException if null or zero-length array is passed |
134 * @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 * in for the {@code chain} parameter or if null or zero-length |
135 * string is passed in for the <code>authType</code> parameter |
136 * string is passed in for the {@code authType} parameter |
136 * @throws CertificateException if the certificate chain is not trusted |
137 * @throws CertificateException if the certificate chain is not trusted |
137 * by this TrustManager |
138 * by this TrustManager |
138 * |
139 * |
139 * @see SSLParameters#getEndpointIdentificationAlgorithm |
140 * @see SSLParameters#getEndpointIdentificationAlgorithm |
140 * @see SSLParameters#setEndpointIdentificationAlgorithm(String) |
141 * @see SSLParameters#setEndpointIdentificationAlgorithm(String) |
151 * <p> |
152 * <p> |
152 * The authentication type is determined by the actual certificate |
153 * The authentication type is determined by the actual certificate |
153 * used. For instance, if RSAPublicKey is used, the authType |
154 * used. For instance, if RSAPublicKey is used, the authType |
154 * should be "RSA". Checking is case-sensitive. |
155 * should be "RSA". Checking is case-sensitive. |
155 * <p> |
156 * <p> |
156 * If the <code>engine</code> parameter is available, and the endpoint |
157 * If the {@code engine} parameter is available, and the endpoint |
157 * identification algorithm of the <code>SSLParameters</code> is |
158 * identification algorithm of the {@code SSLParameters} is |
158 * non-empty, to prevent man-in-the-middle attacks, the address that |
159 * 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 {@code engine} connected to should be checked against |
160 * the peer's identity presented in the end-entity X509 certificate, |
161 * the peer's identity presented in the end-entity X509 certificate, |
161 * as specified in the endpoint identification algorithm. |
162 * as specified in the endpoint identification algorithm. |
162 * <p> |
163 * <p> |
163 * If the <code>engine</code> parameter is available, and the algorithm |
164 * If the {@code engine} parameter is available, and the algorithm |
164 * constraints of the <code>SSLParameters</code> is non-null, for every |
165 * constraints of the {@code SSLParameters} is non-null, for every |
165 * certificate in the certification path, fields such as subject public |
166 * certificate in the certification path, fields such as subject public |
166 * key, the signature algorithm, key usage, extended key usage, etc. |
167 * key, the signature algorithm, key usage, extended key usage, etc. |
167 * need to conform to the algorithm constraints in place on this engine. |
168 * need to conform to the algorithm constraints in place on this engine. |
168 * |
169 * |
169 * @param chain the peer certificate chain |
170 * @param chain the peer certificate chain |
170 * @param authType the key exchange algorithm used |
171 * @param authType the key exchange algorithm used |
171 * @param engine the engine used for this connection. This parameter |
172 * @param engine the engine used for this connection. This parameter |
172 * can be null, which indicates that implementations need not check |
173 * can be null, which indicates that implementations need not check |
173 * the ssl parameters |
174 * the ssl parameters |
174 * @throws IllegalArgumentException if null or zero-length array is passed |
175 * @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 * in for the {@code chain} parameter or if null or zero-length |
176 * string is passed in for the <code>authType</code> parameter |
177 * string is passed in for the {@code authType} parameter |
177 * @throws CertificateException if the certificate chain is not trusted |
178 * @throws CertificateException if the certificate chain is not trusted |
178 * by this TrustManager |
179 * by this TrustManager |
179 * |
180 * |
180 * @see SSLParameters#getEndpointIdentificationAlgorithm |
181 * @see SSLParameters#getEndpointIdentificationAlgorithm |
181 * @see SSLParameters#setEndpointIdentificationAlgorithm(String) |
182 * @see SSLParameters#setEndpointIdentificationAlgorithm(String) |
197 * handshake. For instance, for TLS_RSA_EXPORT_WITH_RC4_40_MD5, |
198 * 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 * 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 * used for the key exchange, and RSA when the key from the server |
200 * certificate is used. Checking is case-sensitive. |
201 * certificate is used. Checking is case-sensitive. |
201 * <p> |
202 * <p> |
202 * If the <code>engine</code> parameter is available, and the endpoint |
203 * If the {@code engine} parameter is available, and the endpoint |
203 * identification algorithm of the <code>SSLParameters</code> is |
204 * identification algorithm of the {@code SSLParameters} is |
204 * non-empty, to prevent man-in-the-middle attacks, the address that |
205 * 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 {@code engine} connected to should be checked against |
206 * the peer's identity presented in the end-entity X509 certificate, |
207 * the peer's identity presented in the end-entity X509 certificate, |
207 * as specified in the endpoint identification algorithm. |
208 * as specified in the endpoint identification algorithm. |
208 * <p> |
209 * <p> |
209 * If the <code>engine</code> parameter is available, and the algorithm |
210 * If the {@code engine} parameter is available, and the algorithm |
210 * constraints of the <code>SSLParameters</code> is non-null, for every |
211 * constraints of the {@code SSLParameters} is non-null, for every |
211 * certificate in the certification path, fields such as subject public |
212 * certificate in the certification path, fields such as subject public |
212 * key, the signature algorithm, key usage, extended key usage, etc. |
213 * key, the signature algorithm, key usage, extended key usage, etc. |
213 * need to conform to the algorithm constraints in place on this engine. |
214 * need to conform to the algorithm constraints in place on this engine. |
214 * |
215 * |
215 * @param chain the peer certificate chain |
216 * @param chain the peer certificate chain |
216 * @param authType the key exchange algorithm used |
217 * @param authType the key exchange algorithm used |
217 * @param engine the engine used for this connection. This parameter |
218 * @param engine the engine used for this connection. This parameter |
218 * can be null, which indicates that implementations need not check |
219 * can be null, which indicates that implementations need not check |
219 * the ssl parameters |
220 * the ssl parameters |
220 * @throws IllegalArgumentException if null or zero-length array is passed |
221 * @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 * in for the {@code chain} parameter or if null or zero-length |
222 * string is passed in for the <code>authType</code> parameter |
223 * string is passed in for the {@code authType} parameter |
223 * @throws CertificateException if the certificate chain is not trusted |
224 * @throws CertificateException if the certificate chain is not trusted |
224 * by this TrustManager |
225 * by this TrustManager |
225 * |
226 * |
226 * @see SSLParameters#getEndpointIdentificationAlgorithm |
227 * @see SSLParameters#getEndpointIdentificationAlgorithm |
227 * @see SSLParameters#setEndpointIdentificationAlgorithm(String) |
228 * @see SSLParameters#setEndpointIdentificationAlgorithm(String) |