author | erikj |
Tue, 12 Sep 2017 19:03:39 +0200 | |
changeset 47216 | 71c04702a3d5 |
parent 45118 | jdk/src/java.base/share/classes/javax/net/ssl/SSLContext.java@e4258d800b54 |
child 52762 | b3866f3879e1 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
45118
e4258d800b54
8178278: Move Standard Algorithm Names document to specs directory
ihse
parents:
41826
diff
changeset
|
2 |
* Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 24 |
*/ |
25 |
||
26 |
package javax.net.ssl; |
|
27 |
||
28 |
import java.security.*; |
|
41826
b35ee9b35b09
4985694: Incomplete spec for most of the getInstances
wetmore
parents:
37348
diff
changeset
|
29 |
import java.util.Objects; |
2 | 30 |
|
31 |
import sun.security.jca.GetInstance; |
|
32 |
||
33 |
/** |
|
34 |
* Instances of this class represent a secure socket protocol |
|
35 |
* implementation which acts as a factory for secure socket |
|
30904 | 36 |
* factories or {@code SSLEngine}s. This class is initialized |
2 | 37 |
* with an optional set of key and trust managers and source of |
38 |
* secure random bytes. |
|
39 |
* |
|
8152
94e5966bdf22
5001004: Required Security Algorithms need to be defined
mullan
parents:
5820
diff
changeset
|
40 |
* <p> Every implementation of the Java platform is required to support the |
32647 | 41 |
* following standard {@code SSLContext} protocols: |
8152
94e5966bdf22
5001004: Required Security Algorithms need to be defined
mullan
parents:
5820
diff
changeset
|
42 |
* <ul> |
32210
958d823579c3
8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents:
30904
diff
changeset
|
43 |
* <li>{@code TLSv1}</li> |
32647 | 44 |
* <li>{@code TLSv1.1}</li> |
45 |
* <li>{@code TLSv1.2}</li> |
|
8152
94e5966bdf22
5001004: Required Security Algorithms need to be defined
mullan
parents:
5820
diff
changeset
|
46 |
* </ul> |
32647 | 47 |
* These protocols are described in the <a href= |
45118
e4258d800b54
8178278: Move Standard Algorithm Names document to specs directory
ihse
parents:
41826
diff
changeset
|
48 |
* "{@docRoot}/../specs/security/standard-names.html#sslcontext-algorithms"> |
8152
94e5966bdf22
5001004: Required Security Algorithms need to be defined
mullan
parents:
5820
diff
changeset
|
49 |
* SSLContext section</a> of the |
45118
e4258d800b54
8178278: Move Standard Algorithm Names document to specs directory
ihse
parents:
41826
diff
changeset
|
50 |
* Java Security Standard Algorithm Names Specification. |
8152
94e5966bdf22
5001004: Required Security Algorithms need to be defined
mullan
parents:
5820
diff
changeset
|
51 |
* Consult the release documentation for your implementation to see if any |
94e5966bdf22
5001004: Required Security Algorithms need to be defined
mullan
parents:
5820
diff
changeset
|
52 |
* other algorithms are supported. |
94e5966bdf22
5001004: Required Security Algorithms need to be defined
mullan
parents:
5820
diff
changeset
|
53 |
* |
2 | 54 |
* @since 1.4 |
55 |
*/ |
|
56 |
public class SSLContext { |
|
57 |
private final Provider provider; |
|
58 |
||
59 |
private final SSLContextSpi contextSpi; |
|
60 |
||
61 |
private final String protocol; |
|
62 |
||
63 |
/** |
|
64 |
* Creates an SSLContext object. |
|
65 |
* |
|
66 |
* @param contextSpi the delegate |
|
67 |
* @param provider the provider |
|
68 |
* @param protocol the protocol |
|
69 |
*/ |
|
70 |
protected SSLContext(SSLContextSpi contextSpi, Provider provider, |
|
71 |
String protocol) { |
|
72 |
this.contextSpi = contextSpi; |
|
73 |
this.provider = provider; |
|
74 |
this.protocol = protocol; |
|
75 |
} |
|
76 |
||
77 |
private static SSLContext defaultContext; |
|
78 |
||
79 |
/** |
|
80 |
* Returns the default SSL context. |
|
81 |
* |
|
82 |
* <p>If a default context was set using the {@link #setDefault |
|
83 |
* SSLContext.setDefault()} method, it is returned. Otherwise, the first |
|
84 |
* call of this method triggers the call |
|
30904 | 85 |
* {@code SSLContext.getInstance("Default")}. |
2 | 86 |
* If successful, that object is made the default SSL context and returned. |
87 |
* |
|
88 |
* <p>The default context is immediately |
|
89 |
* usable and does not require {@linkplain #init initialization}. |
|
90 |
* |
|
91 |
* @return the default SSL context |
|
92 |
* @throws NoSuchAlgorithmException if the |
|
93 |
* {@link SSLContext#getInstance SSLContext.getInstance()} call fails |
|
94 |
* @since 1.6 |
|
95 |
*/ |
|
96 |
public static synchronized SSLContext getDefault() |
|
97 |
throws NoSuchAlgorithmException { |
|
98 |
if (defaultContext == null) { |
|
99 |
defaultContext = SSLContext.getInstance("Default"); |
|
100 |
} |
|
101 |
return defaultContext; |
|
102 |
} |
|
103 |
||
104 |
/** |
|
105 |
* Sets the default SSL context. It will be returned by subsequent calls |
|
106 |
* to {@link #getDefault}. The default context must be immediately usable |
|
107 |
* and not require {@linkplain #init initialization}. |
|
108 |
* |
|
109 |
* @param context the SSLContext |
|
110 |
* @throws NullPointerException if context is null |
|
111 |
* @throws SecurityException if a security manager exists and its |
|
30904 | 112 |
* {@code checkPermission} method does not allow |
113 |
* {@code SSLPermission("setDefaultSSLContext")} |
|
2 | 114 |
* @since 1.6 |
115 |
*/ |
|
116 |
public static synchronized void setDefault(SSLContext context) { |
|
117 |
if (context == null) { |
|
118 |
throw new NullPointerException(); |
|
119 |
} |
|
120 |
SecurityManager sm = System.getSecurityManager(); |
|
121 |
if (sm != null) { |
|
122 |
sm.checkPermission(new SSLPermission("setDefaultSSLContext")); |
|
123 |
} |
|
124 |
defaultContext = context; |
|
125 |
} |
|
126 |
||
127 |
/** |
|
30904 | 128 |
* Returns a {@code SSLContext} object that implements the |
2 | 129 |
* specified secure socket protocol. |
130 |
* |
|
131 |
* <p> This method traverses the list of registered security Providers, |
|
132 |
* starting with the most preferred Provider. |
|
133 |
* A new SSLContext object encapsulating the |
|
134 |
* SSLContextSpi implementation from the first |
|
135 |
* Provider that supports the specified protocol is returned. |
|
136 |
* |
|
137 |
* <p> Note that the list of registered providers may be retrieved via |
|
138 |
* the {@link Security#getProviders() Security.getProviders()} method. |
|
139 |
* |
|
33241
27eb2d6abda9
8133151: Preferred provider configuration for JCE
ascarpino
parents:
32647
diff
changeset
|
140 |
* @implNote |
27eb2d6abda9
8133151: Preferred provider configuration for JCE
ascarpino
parents:
32647
diff
changeset
|
141 |
* The JDK Reference Implementation additionally uses the |
37348
9ccec3170d5e
8152205: jdk.security.provider.preferred is ambiguously documented
ascarpino
parents:
33241
diff
changeset
|
142 |
* {@code jdk.security.provider.preferred} |
9ccec3170d5e
8152205: jdk.security.provider.preferred is ambiguously documented
ascarpino
parents:
33241
diff
changeset
|
143 |
* {@link Security#getProperty(String) Security} property to determine |
33241
27eb2d6abda9
8133151: Preferred provider configuration for JCE
ascarpino
parents:
32647
diff
changeset
|
144 |
* the preferred provider order for the specified algorithm. This |
27eb2d6abda9
8133151: Preferred provider configuration for JCE
ascarpino
parents:
32647
diff
changeset
|
145 |
* may be different than the order of providers returned by |
27eb2d6abda9
8133151: Preferred provider configuration for JCE
ascarpino
parents:
32647
diff
changeset
|
146 |
* {@link Security#getProviders() Security.getProviders()}. |
27eb2d6abda9
8133151: Preferred provider configuration for JCE
ascarpino
parents:
32647
diff
changeset
|
147 |
* |
2 | 148 |
* @param protocol the standard name of the requested protocol. |
8152
94e5966bdf22
5001004: Required Security Algorithms need to be defined
mullan
parents:
5820
diff
changeset
|
149 |
* See the SSLContext section in the <a href= |
45118
e4258d800b54
8178278: Move Standard Algorithm Names document to specs directory
ihse
parents:
41826
diff
changeset
|
150 |
* "{@docRoot}/../specs/security/standard-names.html#sslcontext-algorithms"> |
e4258d800b54
8178278: Move Standard Algorithm Names document to specs directory
ihse
parents:
41826
diff
changeset
|
151 |
* Java Security Standard Algorithm Names Specification</a> |
2 | 152 |
* for information about standard protocol names. |
153 |
* |
|
41826
b35ee9b35b09
4985694: Incomplete spec for most of the getInstances
wetmore
parents:
37348
diff
changeset
|
154 |
* @return the new {@code SSLContext} object |
2 | 155 |
* |
41826
b35ee9b35b09
4985694: Incomplete spec for most of the getInstances
wetmore
parents:
37348
diff
changeset
|
156 |
* @throws NoSuchAlgorithmException if no {@code Provider} supports a |
b35ee9b35b09
4985694: Incomplete spec for most of the getInstances
wetmore
parents:
37348
diff
changeset
|
157 |
* {@code SSLContextSpi} implementation for the |
b35ee9b35b09
4985694: Incomplete spec for most of the getInstances
wetmore
parents:
37348
diff
changeset
|
158 |
* specified protocol |
b35ee9b35b09
4985694: Incomplete spec for most of the getInstances
wetmore
parents:
37348
diff
changeset
|
159 |
* |
b35ee9b35b09
4985694: Incomplete spec for most of the getInstances
wetmore
parents:
37348
diff
changeset
|
160 |
* @throws NullPointerException if {@code protocol} is {@code null} |
2 | 161 |
* |
162 |
* @see java.security.Provider |
|
163 |
*/ |
|
164 |
public static SSLContext getInstance(String protocol) |
|
165 |
throws NoSuchAlgorithmException { |
|
41826
b35ee9b35b09
4985694: Incomplete spec for most of the getInstances
wetmore
parents:
37348
diff
changeset
|
166 |
Objects.requireNonNull(protocol, "null protocol name"); |
2 | 167 |
GetInstance.Instance instance = GetInstance.getInstance |
168 |
("SSLContext", SSLContextSpi.class, protocol); |
|
169 |
return new SSLContext((SSLContextSpi)instance.impl, instance.provider, |
|
170 |
protocol); |
|
171 |
} |
|
172 |
||
173 |
/** |
|
30904 | 174 |
* Returns a {@code SSLContext} object that implements the |
2 | 175 |
* specified secure socket protocol. |
176 |
* |
|
177 |
* <p> A new SSLContext object encapsulating the |
|
178 |
* SSLContextSpi implementation from the specified provider |
|
179 |
* is returned. The specified provider must be registered |
|
180 |
* in the security provider list. |
|
181 |
* |
|
182 |
* <p> Note that the list of registered providers may be retrieved via |
|
183 |
* the {@link Security#getProviders() Security.getProviders()} method. |
|
184 |
* |
|
185 |
* @param protocol the standard name of the requested protocol. |
|
8152
94e5966bdf22
5001004: Required Security Algorithms need to be defined
mullan
parents:
5820
diff
changeset
|
186 |
* See the SSLContext section in the <a href= |
45118
e4258d800b54
8178278: Move Standard Algorithm Names document to specs directory
ihse
parents:
41826
diff
changeset
|
187 |
* "{@docRoot}/../specs/security/standard-names.html#sslcontext-algorithms"> |
e4258d800b54
8178278: Move Standard Algorithm Names document to specs directory
ihse
parents:
41826
diff
changeset
|
188 |
* Java Security Standard Algorithm Names Specification</a> |
2 | 189 |
* for information about standard protocol names. |
190 |
* |
|
191 |
* @param provider the name of the provider. |
|
192 |
* |
|
41826
b35ee9b35b09
4985694: Incomplete spec for most of the getInstances
wetmore
parents:
37348
diff
changeset
|
193 |
* @return the new {@code SSLContext} object |
2 | 194 |
* |
41826
b35ee9b35b09
4985694: Incomplete spec for most of the getInstances
wetmore
parents:
37348
diff
changeset
|
195 |
* @throws IllegalArgumentException if the provider name is |
b35ee9b35b09
4985694: Incomplete spec for most of the getInstances
wetmore
parents:
37348
diff
changeset
|
196 |
* {@code null} or empty |
b35ee9b35b09
4985694: Incomplete spec for most of the getInstances
wetmore
parents:
37348
diff
changeset
|
197 |
* |
b35ee9b35b09
4985694: Incomplete spec for most of the getInstances
wetmore
parents:
37348
diff
changeset
|
198 |
* @throws NoSuchAlgorithmException if a {@code SSLContextSpi} |
b35ee9b35b09
4985694: Incomplete spec for most of the getInstances
wetmore
parents:
37348
diff
changeset
|
199 |
* implementation for the specified protocol is not |
b35ee9b35b09
4985694: Incomplete spec for most of the getInstances
wetmore
parents:
37348
diff
changeset
|
200 |
* available from the specified provider |
2 | 201 |
* |
202 |
* @throws NoSuchProviderException if the specified provider is not |
|
41826
b35ee9b35b09
4985694: Incomplete spec for most of the getInstances
wetmore
parents:
37348
diff
changeset
|
203 |
* registered in the security provider list |
2 | 204 |
* |
41826
b35ee9b35b09
4985694: Incomplete spec for most of the getInstances
wetmore
parents:
37348
diff
changeset
|
205 |
* @throws NullPointerException if {@code protocol} is {@code null} |
2 | 206 |
* |
207 |
* @see java.security.Provider |
|
208 |
*/ |
|
209 |
public static SSLContext getInstance(String protocol, String provider) |
|
210 |
throws NoSuchAlgorithmException, NoSuchProviderException { |
|
41826
b35ee9b35b09
4985694: Incomplete spec for most of the getInstances
wetmore
parents:
37348
diff
changeset
|
211 |
Objects.requireNonNull(protocol, "null protocol name"); |
2 | 212 |
GetInstance.Instance instance = GetInstance.getInstance |
213 |
("SSLContext", SSLContextSpi.class, protocol, provider); |
|
214 |
return new SSLContext((SSLContextSpi)instance.impl, instance.provider, |
|
215 |
protocol); |
|
216 |
} |
|
217 |
||
218 |
/** |
|
30904 | 219 |
* Returns a {@code SSLContext} object that implements the |
2 | 220 |
* specified secure socket protocol. |
221 |
* |
|
222 |
* <p> A new SSLContext object encapsulating the |
|
223 |
* SSLContextSpi implementation from the specified Provider |
|
224 |
* object is returned. Note that the specified Provider object |
|
225 |
* does not have to be registered in the provider list. |
|
226 |
* |
|
227 |
* @param protocol the standard name of the requested protocol. |
|
8152
94e5966bdf22
5001004: Required Security Algorithms need to be defined
mullan
parents:
5820
diff
changeset
|
228 |
* See the SSLContext section in the <a href= |
45118
e4258d800b54
8178278: Move Standard Algorithm Names document to specs directory
ihse
parents:
41826
diff
changeset
|
229 |
* "{@docRoot}/../specs/security/standard-names.html#sslcontext-algorithms"> |
e4258d800b54
8178278: Move Standard Algorithm Names document to specs directory
ihse
parents:
41826
diff
changeset
|
230 |
* Java Security Standard Algorithm Names Specification</a> |
2 | 231 |
* for information about standard protocol names. |
232 |
* |
|
233 |
* @param provider an instance of the provider. |
|
234 |
* |
|
41826
b35ee9b35b09
4985694: Incomplete spec for most of the getInstances
wetmore
parents:
37348
diff
changeset
|
235 |
* @return the new {@code SSLContext} object |
b35ee9b35b09
4985694: Incomplete spec for most of the getInstances
wetmore
parents:
37348
diff
changeset
|
236 |
* |
b35ee9b35b09
4985694: Incomplete spec for most of the getInstances
wetmore
parents:
37348
diff
changeset
|
237 |
* @throws IllegalArgumentException if the provider is {@code null} |
2 | 238 |
* |
41826
b35ee9b35b09
4985694: Incomplete spec for most of the getInstances
wetmore
parents:
37348
diff
changeset
|
239 |
* @throws NoSuchAlgorithmException if a {@code SSLContextSpi} |
b35ee9b35b09
4985694: Incomplete spec for most of the getInstances
wetmore
parents:
37348
diff
changeset
|
240 |
* implementation for the specified protocol is not available |
b35ee9b35b09
4985694: Incomplete spec for most of the getInstances
wetmore
parents:
37348
diff
changeset
|
241 |
* from the specified {@code Provider} object |
2 | 242 |
* |
41826
b35ee9b35b09
4985694: Incomplete spec for most of the getInstances
wetmore
parents:
37348
diff
changeset
|
243 |
* @throws NullPointerException if {@code protocol} is {@code null} |
2 | 244 |
* |
245 |
* @see java.security.Provider |
|
246 |
*/ |
|
247 |
public static SSLContext getInstance(String protocol, Provider provider) |
|
248 |
throws NoSuchAlgorithmException { |
|
41826
b35ee9b35b09
4985694: Incomplete spec for most of the getInstances
wetmore
parents:
37348
diff
changeset
|
249 |
Objects.requireNonNull(protocol, "null protocol name"); |
2 | 250 |
GetInstance.Instance instance = GetInstance.getInstance |
251 |
("SSLContext", SSLContextSpi.class, protocol, provider); |
|
252 |
return new SSLContext((SSLContextSpi)instance.impl, instance.provider, |
|
253 |
protocol); |
|
254 |
} |
|
255 |
||
256 |
/** |
|
30904 | 257 |
* Returns the protocol name of this {@code SSLContext} object. |
2 | 258 |
* |
259 |
* <p>This is the same name that was specified in one of the |
|
30904 | 260 |
* {@code getInstance} calls that created this |
261 |
* {@code SSLContext} object. |
|
2 | 262 |
* |
30904 | 263 |
* @return the protocol name of this {@code SSLContext} object. |
2 | 264 |
*/ |
265 |
public final String getProtocol() { |
|
266 |
return this.protocol; |
|
267 |
} |
|
268 |
||
269 |
/** |
|
30904 | 270 |
* Returns the provider of this {@code SSLContext} object. |
2 | 271 |
* |
30904 | 272 |
* @return the provider of this {@code SSLContext} object |
2 | 273 |
*/ |
274 |
public final Provider getProvider() { |
|
275 |
return this.provider; |
|
276 |
} |
|
277 |
||
278 |
/** |
|
279 |
* Initializes this context. Either of the first two parameters |
|
280 |
* may be null in which case the installed security providers will |
|
281 |
* be searched for the highest priority implementation of the |
|
282 |
* appropriate factory. Likewise, the secure random parameter may |
|
283 |
* be null in which case the default implementation will be used. |
|
284 |
* <P> |
|
285 |
* Only the first instance of a particular key and/or trust manager |
|
286 |
* implementation type in the array is used. (For example, only |
|
287 |
* the first javax.net.ssl.X509KeyManager in the array will be used.) |
|
288 |
* |
|
289 |
* @param km the sources of authentication keys or null |
|
290 |
* @param tm the sources of peer authentication trust decisions or null |
|
291 |
* @param random the source of randomness for this generator or null |
|
292 |
* @throws KeyManagementException if this operation fails |
|
293 |
*/ |
|
294 |
public final void init(KeyManager[] km, TrustManager[] tm, |
|
295 |
SecureRandom random) |
|
296 |
throws KeyManagementException { |
|
297 |
contextSpi.engineInit(km, tm, random); |
|
298 |
} |
|
299 |
||
300 |
/** |
|
30904 | 301 |
* Returns a {@code SocketFactory} object for this |
2 | 302 |
* context. |
303 |
* |
|
30904 | 304 |
* @return the {@code SocketFactory} object |
305 |
* @throws UnsupportedOperationException if the underlying provider |
|
306 |
* does not implement the operation. |
|
2 | 307 |
* @throws IllegalStateException if the SSLContextImpl requires |
30904 | 308 |
* initialization and the {@code init()} has not been called |
2 | 309 |
*/ |
310 |
public final SSLSocketFactory getSocketFactory() { |
|
311 |
return contextSpi.engineGetSocketFactory(); |
|
312 |
} |
|
313 |
||
314 |
/** |
|
30904 | 315 |
* Returns a {@code ServerSocketFactory} object for |
2 | 316 |
* this context. |
317 |
* |
|
30904 | 318 |
* @return the {@code ServerSocketFactory} object |
319 |
* @throws UnsupportedOperationException if the underlying provider |
|
320 |
* does not implement the operation. |
|
2 | 321 |
* @throws IllegalStateException if the SSLContextImpl requires |
30904 | 322 |
* initialization and the {@code init()} has not been called |
2 | 323 |
*/ |
324 |
public final SSLServerSocketFactory getServerSocketFactory() { |
|
325 |
return contextSpi.engineGetServerSocketFactory(); |
|
326 |
} |
|
327 |
||
328 |
/** |
|
30904 | 329 |
* Creates a new {@code SSLEngine} using this context. |
2 | 330 |
* <P> |
331 |
* Applications using this factory method are providing no hints |
|
332 |
* for an internal session reuse strategy. If hints are desired, |
|
333 |
* {@link #createSSLEngine(String, int)} should be used |
|
334 |
* instead. |
|
335 |
* <P> |
|
336 |
* Some cipher suites (such as Kerberos) require remote hostname |
|
337 |
* information, in which case this factory method should not be used. |
|
338 |
* |
|
30904 | 339 |
* @return the {@code SSLEngine} object |
2 | 340 |
* @throws UnsupportedOperationException if the underlying provider |
341 |
* does not implement the operation. |
|
342 |
* @throws IllegalStateException if the SSLContextImpl requires |
|
30904 | 343 |
* initialization and the {@code init()} has not been called |
2 | 344 |
* @since 1.5 |
345 |
*/ |
|
346 |
public final SSLEngine createSSLEngine() { |
|
347 |
try { |
|
348 |
return contextSpi.engineCreateSSLEngine(); |
|
349 |
} catch (AbstractMethodError e) { |
|
350 |
UnsupportedOperationException unsup = |
|
351 |
new UnsupportedOperationException( |
|
352 |
"Provider: " + getProvider() + |
|
353 |
" doesn't support this operation"); |
|
354 |
unsup.initCause(e); |
|
355 |
throw unsup; |
|
356 |
} |
|
357 |
} |
|
358 |
||
359 |
/** |
|
30904 | 360 |
* Creates a new {@code SSLEngine} using this context using |
2 | 361 |
* advisory peer information. |
362 |
* <P> |
|
363 |
* Applications using this factory method are providing hints |
|
364 |
* for an internal session reuse strategy. |
|
365 |
* <P> |
|
366 |
* Some cipher suites (such as Kerberos) require remote hostname |
|
367 |
* information, in which case peerHost needs to be specified. |
|
368 |
* |
|
369 |
* @param peerHost the non-authoritative name of the host |
|
370 |
* @param peerPort the non-authoritative port |
|
30904 | 371 |
* @return the new {@code SSLEngine} object |
2 | 372 |
* @throws UnsupportedOperationException if the underlying provider |
373 |
* does not implement the operation. |
|
374 |
* @throws IllegalStateException if the SSLContextImpl requires |
|
30904 | 375 |
* initialization and the {@code init()} has not been called |
2 | 376 |
* @since 1.5 |
377 |
*/ |
|
378 |
public final SSLEngine createSSLEngine(String peerHost, int peerPort) { |
|
379 |
try { |
|
380 |
return contextSpi.engineCreateSSLEngine(peerHost, peerPort); |
|
381 |
} catch (AbstractMethodError e) { |
|
382 |
UnsupportedOperationException unsup = |
|
383 |
new UnsupportedOperationException( |
|
384 |
"Provider: " + getProvider() + |
|
385 |
" does not support this operation"); |
|
386 |
unsup.initCause(e); |
|
387 |
throw unsup; |
|
388 |
} |
|
389 |
} |
|
390 |
||
391 |
/** |
|
392 |
* Returns the server session context, which represents the set of |
|
393 |
* SSL sessions available for use during the handshake phase of |
|
394 |
* server-side SSL sockets. |
|
395 |
* <P> |
|
396 |
* This context may be unavailable in some environments, in which |
|
397 |
* case this method returns null. For example, when the underlying |
|
398 |
* SSL provider does not provide an implementation of SSLSessionContext |
|
399 |
* interface, this method returns null. A non-null session context |
|
400 |
* is returned otherwise. |
|
401 |
* |
|
402 |
* @return server session context bound to this SSL context |
|
403 |
*/ |
|
404 |
public final SSLSessionContext getServerSessionContext() { |
|
405 |
return contextSpi.engineGetServerSessionContext(); |
|
406 |
} |
|
407 |
||
408 |
/** |
|
409 |
* Returns the client session context, which represents the set of |
|
410 |
* SSL sessions available for use during the handshake phase of |
|
411 |
* client-side SSL sockets. |
|
412 |
* <P> |
|
413 |
* This context may be unavailable in some environments, in which |
|
414 |
* case this method returns null. For example, when the underlying |
|
415 |
* SSL provider does not provide an implementation of SSLSessionContext |
|
416 |
* interface, this method returns null. A non-null session context |
|
417 |
* is returned otherwise. |
|
418 |
* |
|
419 |
* @return client session context bound to this SSL context |
|
420 |
*/ |
|
421 |
public final SSLSessionContext getClientSessionContext() { |
|
422 |
return contextSpi.engineGetClientSessionContext(); |
|
423 |
} |
|
424 |
||
425 |
/** |
|
426 |
* Returns a copy of the SSLParameters indicating the default |
|
427 |
* settings for this SSL context. |
|
428 |
* |
|
429 |
* <p>The parameters will always have the ciphersuites and protocols |
|
430 |
* arrays set to non-null values. |
|
431 |
* |
|
432 |
* @return a copy of the SSLParameters object with the default settings |
|
433 |
* @throws UnsupportedOperationException if the default SSL parameters |
|
434 |
* could not be obtained. |
|
435 |
* @since 1.6 |
|
436 |
*/ |
|
437 |
public final SSLParameters getDefaultSSLParameters() { |
|
438 |
return contextSpi.engineGetDefaultSSLParameters(); |
|
439 |
} |
|
440 |
||
441 |
/** |
|
442 |
* Returns a copy of the SSLParameters indicating the supported |
|
443 |
* settings for this SSL context. |
|
444 |
* |
|
445 |
* <p>The parameters will always have the ciphersuites and protocols |
|
446 |
* arrays set to non-null values. |
|
447 |
* |
|
448 |
* @return a copy of the SSLParameters object with the supported |
|
449 |
* settings |
|
450 |
* @throws UnsupportedOperationException if the supported SSL parameters |
|
451 |
* could not be obtained. |
|
452 |
* @since 1.6 |
|
453 |
*/ |
|
454 |
public final SSLParameters getSupportedSSLParameters() { |
|
455 |
return contextSpi.engineGetSupportedSSLParameters(); |
|
456 |
} |
|
457 |
||
458 |
} |