Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.base/share/classes/javax/net/ssl/SSLContextSpi.java
41159 views
1
/*
2
* Copyright (c) 1999, 2020, 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.security.*;
29
30
/**
31
* This class defines the <i>Service Provider Interface</i> (<b>SPI</b>)
32
* for the {@code SSLContext} class.
33
*
34
* <p> All the abstract methods in this class must be implemented by each
35
* cryptographic service provider who wishes to supply the implementation
36
* of a particular SSL context.
37
*
38
* @since 1.4
39
* @see SSLContext
40
*/
41
public abstract class SSLContextSpi {
42
/**
43
* Constructor for subclasses to call.
44
*/
45
public SSLContextSpi() {}
46
47
/**
48
* Initializes this context.
49
*
50
* @param km the sources of authentication keys
51
* @param tm the sources of peer authentication trust decisions
52
* @param sr the source of randomness
53
* @throws KeyManagementException if this operation fails
54
* @see SSLContext#init(KeyManager [], TrustManager [], SecureRandom)
55
*/
56
protected abstract void engineInit(KeyManager[] km, TrustManager[] tm,
57
SecureRandom sr) throws KeyManagementException;
58
59
/**
60
* Returns a {@code SocketFactory} object for this
61
* context.
62
*
63
* @return the {@code SocketFactory} object
64
* @throws UnsupportedOperationException if the underlying provider
65
* does not implement the operation.
66
* @throws IllegalStateException if the SSLContextImpl requires
67
* initialization and the {@code engineInit()}
68
* has not been called
69
* @see javax.net.ssl.SSLContext#getSocketFactory()
70
*/
71
protected abstract SSLSocketFactory engineGetSocketFactory();
72
73
/**
74
* Returns a {@code ServerSocketFactory} object for
75
* this context.
76
*
77
* @return the {@code ServerSocketFactory} object
78
* @throws UnsupportedOperationException if the underlying provider
79
* does not implement the operation.
80
* @throws IllegalStateException if the SSLContextImpl requires
81
* initialization and the {@code engineInit()}
82
* has not been called
83
* @see javax.net.ssl.SSLContext#getServerSocketFactory()
84
*/
85
protected abstract SSLServerSocketFactory engineGetServerSocketFactory();
86
87
/**
88
* Creates a new {@code SSLEngine} using this context.
89
* <P>
90
* Applications using this factory method are providing no hints
91
* for an internal session reuse strategy. If hints are desired,
92
* {@link #engineCreateSSLEngine(String, int)} should be used
93
* instead.
94
* <P>
95
* Some cipher suites (such as Kerberos) require remote hostname
96
* information, in which case this factory method should not be used.
97
*
98
* @implNote
99
* It is provider-specific if the returned SSLEngine uses client or
100
* server mode by default for the (D)TLS connection. The JDK SunJSSE
101
* provider implementation uses server mode by default. However, it
102
* is recommended to always set the desired mode explicitly by calling
103
* {@link SSLEngine#setUseClientMode(boolean) SSLEngine.setUseClientMode()}
104
* before invoking other methods of the SSLEngine.
105
*
106
* @return the {@code SSLEngine} Object
107
* @throws IllegalStateException if the SSLContextImpl requires
108
* initialization and the {@code engineInit()}
109
* has not been called
110
*
111
* @see SSLContext#createSSLEngine()
112
*
113
* @since 1.5
114
*/
115
protected abstract SSLEngine engineCreateSSLEngine();
116
117
/**
118
* Creates a {@code SSLEngine} using this context.
119
* <P>
120
* Applications using this factory method are providing hints
121
* for an internal session reuse strategy.
122
* <P>
123
* Some cipher suites (such as Kerberos) require remote hostname
124
* information, in which case peerHost needs to be specified.
125
*
126
* @implNote
127
* It is provider-specific if the returned SSLEngine uses client or
128
* server mode by default for the (D)TLS connection. The JDK SunJSSE
129
* provider implementation uses server mode by default. However, it
130
* is recommended to always set the desired mode explicitly by calling
131
* {@link SSLEngine#setUseClientMode(boolean) SSLEngine.setUseClientMode()}
132
* before invoking other methods of the SSLEngine.
133
*
134
* @param host the non-authoritative name of the host
135
* @param port the non-authoritative port
136
* @return the {@code SSLEngine} Object
137
* @throws IllegalStateException if the SSLContextImpl requires
138
* initialization and the {@code engineInit()}
139
* has not been called
140
*
141
* @see SSLContext#createSSLEngine(String, int)
142
*
143
* @since 1.5
144
*/
145
protected abstract SSLEngine engineCreateSSLEngine(String host, int port);
146
147
/**
148
* Returns a server {@code SSLSessionContext} object for
149
* this context.
150
*
151
* @return the {@code SSLSessionContext} object
152
* @see javax.net.ssl.SSLContext#getServerSessionContext()
153
*/
154
protected abstract SSLSessionContext engineGetServerSessionContext();
155
156
/**
157
* Returns a client {@code SSLSessionContext} object for
158
* this context.
159
*
160
* @return the {@code SSLSessionContext} object
161
* @see javax.net.ssl.SSLContext#getClientSessionContext()
162
*/
163
protected abstract SSLSessionContext engineGetClientSessionContext();
164
165
private SSLSocket getDefaultSocket() {
166
try {
167
SSLSocketFactory factory = engineGetSocketFactory();
168
return (SSLSocket)factory.createSocket();
169
} catch (java.io.IOException e) {
170
throw new UnsupportedOperationException("Could not obtain parameters", e);
171
}
172
}
173
174
/**
175
* Returns a copy of the SSLParameters indicating the default
176
* settings for this SSL context.
177
*
178
* <p>The parameters will always have the ciphersuite and protocols
179
* arrays set to non-null values.
180
*
181
* <p>The default implementation obtains the parameters from an
182
* SSLSocket created by calling the
183
* {@linkplain javax.net.SocketFactory#createSocket
184
* SocketFactory.createSocket()} method of this context's SocketFactory.
185
*
186
* @return a copy of the SSLParameters object with the default settings
187
* @throws UnsupportedOperationException if the default SSL parameters
188
* could not be obtained.
189
*
190
* @since 1.6
191
*/
192
protected SSLParameters engineGetDefaultSSLParameters() {
193
SSLSocket socket = getDefaultSocket();
194
return socket.getSSLParameters();
195
}
196
197
/**
198
* Returns a copy of the SSLParameters indicating the maximum supported
199
* settings for this SSL context.
200
*
201
* <p>The parameters will always have the ciphersuite and protocols
202
* arrays set to non-null values.
203
*
204
* <p>The default implementation obtains the parameters from an
205
* SSLSocket created by calling the
206
* {@linkplain javax.net.SocketFactory#createSocket
207
* SocketFactory.createSocket()} method of this context's SocketFactory.
208
*
209
* @return a copy of the SSLParameters object with the maximum supported
210
* settings
211
* @throws UnsupportedOperationException if the supported SSL parameters
212
* could not be obtained.
213
*
214
* @since 1.6
215
*/
216
protected SSLParameters engineGetSupportedSSLParameters() {
217
SSLSocket socket = getDefaultSocket();
218
SSLParameters params = socket.getSSLParameters();
219
params.setCipherSuites(socket.getSupportedCipherSuites());
220
params.setProtocols(socket.getSupportedProtocols());
221
return params;
222
}
223
}
224
225