author | chegar |
Thu, 17 Oct 2019 20:54:25 +0100 | |
branch | datagramsocketimpl-branch |
changeset 58679 | 9c3209ff7550 |
parent 58678 | 9cf78a70fa4f |
parent 57799 | 7cc5a5b4eee9 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
55336
c2398053ee90
8211018: Session Resumption without Server-Side State
ascarpino
parents:
51407
diff
changeset
|
2 |
* Copyright (c) 2006, 2019, 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 sun.security.ssl; |
|
27 |
||
50768 | 28 |
import java.io.IOException; |
29 |
import java.nio.ByteBuffer; |
|
30 |
import java.util.AbstractMap.SimpleImmutableEntry; |
|
31 |
import java.util.Map; |
|
32 |
import javax.net.ssl.SSLException; |
|
2 | 33 |
|
50768 | 34 |
enum SSLHandshake implements SSLConsumer, HandshakeProducer { |
35 |
@SuppressWarnings({"unchecked", "rawtypes"}) |
|
36 |
HELLO_REQUEST ((byte)0x00, "hello_request", |
|
37 |
(Map.Entry<SSLConsumer, ProtocolVersion[]>[])(new Map.Entry[] { |
|
38 |
new SimpleImmutableEntry<SSLConsumer, ProtocolVersion[]>( |
|
39 |
HelloRequest.handshakeConsumer, |
|
40 |
ProtocolVersion.PROTOCOLS_TO_12 |
|
41 |
) |
|
42 |
}), |
|
43 |
(Map.Entry<HandshakeProducer, ProtocolVersion[]>[])(new Map.Entry[] { |
|
44 |
new SimpleImmutableEntry<HandshakeProducer, ProtocolVersion[]>( |
|
45 |
HelloRequest.handshakeProducer, |
|
46 |
ProtocolVersion.PROTOCOLS_TO_12 |
|
47 |
) |
|
48 |
})), |
|
2 | 49 |
|
50768 | 50 |
@SuppressWarnings({"unchecked", "rawtypes"}) |
51 |
CLIENT_HELLO ((byte)0x01, "client_hello", |
|
52 |
(Map.Entry<SSLConsumer, ProtocolVersion[]>[])(new Map.Entry[] { |
|
53 |
new SimpleImmutableEntry<SSLConsumer, ProtocolVersion[]>( |
|
54 |
ClientHello.handshakeConsumer, |
|
55 |
ProtocolVersion.PROTOCOLS_TO_13 |
|
56 |
) |
|
57 |
}), |
|
58 |
(Map.Entry<HandshakeProducer, ProtocolVersion[]>[])(new Map.Entry[] { |
|
59 |
new SimpleImmutableEntry<HandshakeProducer, ProtocolVersion[]>( |
|
60 |
ClientHello.handshakeProducer, |
|
61 |
ProtocolVersion.PROTOCOLS_TO_13 |
|
62 |
) |
|
63 |
})), |
|
2 | 64 |
|
50768 | 65 |
@SuppressWarnings({"unchecked", "rawtypes"}) |
66 |
SERVER_HELLO ((byte)0x02, "server_hello", |
|
67 |
(Map.Entry<SSLConsumer, ProtocolVersion[]>[])(new Map.Entry[] { |
|
68 |
new SimpleImmutableEntry<SSLConsumer, ProtocolVersion[]>( |
|
69 |
ServerHello.handshakeConsumer, |
|
70 |
ProtocolVersion.PROTOCOLS_TO_13 |
|
71 |
) |
|
72 |
}), |
|
73 |
(Map.Entry<HandshakeProducer, ProtocolVersion[]>[])(new Map.Entry[] { |
|
74 |
new SimpleImmutableEntry<HandshakeProducer, ProtocolVersion[]>( |
|
75 |
ServerHello.t12HandshakeProducer, |
|
76 |
ProtocolVersion.PROTOCOLS_TO_12 |
|
77 |
), |
|
78 |
new SimpleImmutableEntry<HandshakeProducer, ProtocolVersion[]>( |
|
79 |
ServerHello.t13HandshakeProducer, |
|
80 |
ProtocolVersion.PROTOCOLS_OF_13 |
|
81 |
) |
|
82 |
})), |
|
2 | 83 |
|
50768 | 84 |
@SuppressWarnings({"unchecked", "rawtypes"}) |
85 |
HELLO_RETRY_REQUEST ((byte)0x02, "hello_retry_request", |
|
86 |
(Map.Entry<SSLConsumer, ProtocolVersion[]>[])(new Map.Entry[] { |
|
87 |
new SimpleImmutableEntry<SSLConsumer, ProtocolVersion[]>( |
|
88 |
ServerHello.handshakeConsumer, // Use ServerHello consumer |
|
89 |
ProtocolVersion.PROTOCOLS_TO_13 |
|
90 |
) |
|
91 |
}), |
|
92 |
(Map.Entry<HandshakeProducer, ProtocolVersion[]>[])(new Map.Entry[] { |
|
93 |
new SimpleImmutableEntry<HandshakeProducer, ProtocolVersion[]>( |
|
94 |
ServerHello.hrrHandshakeProducer, |
|
95 |
ProtocolVersion.PROTOCOLS_OF_13 |
|
96 |
) |
|
97 |
})), |
|
2 | 98 |
|
50768 | 99 |
@SuppressWarnings({"unchecked", "rawtypes"}) |
100 |
HELLO_VERIFY_REQUEST ((byte)0x03, "hello_verify_request", |
|
101 |
(Map.Entry<SSLConsumer, ProtocolVersion[]>[])(new Map.Entry[] { |
|
102 |
new SimpleImmutableEntry<SSLConsumer, ProtocolVersion[]>( |
|
103 |
HelloVerifyRequest.handshakeConsumer, |
|
104 |
ProtocolVersion.PROTOCOLS_TO_12 |
|
105 |
) |
|
106 |
}), |
|
107 |
(Map.Entry<HandshakeProducer, ProtocolVersion[]>[])(new Map.Entry[] { |
|
108 |
new SimpleImmutableEntry<HandshakeProducer, ProtocolVersion[]>( |
|
109 |
HelloVerifyRequest.handshakeProducer, |
|
110 |
ProtocolVersion.PROTOCOLS_TO_12 |
|
111 |
) |
|
112 |
})), |
|
2 | 113 |
|
50768 | 114 |
@SuppressWarnings({"unchecked", "rawtypes"}) |
115 |
NEW_SESSION_TICKET ((byte)0x04, "new_session_ticket", |
|
116 |
(Map.Entry<SSLConsumer, ProtocolVersion[]>[])(new Map.Entry[] { |
|
117 |
new SimpleImmutableEntry<SSLConsumer, ProtocolVersion[]>( |
|
55336
c2398053ee90
8211018: Session Resumption without Server-Side State
ascarpino
parents:
51407
diff
changeset
|
118 |
NewSessionTicket.handshake12Consumer, |
c2398053ee90
8211018: Session Resumption without Server-Side State
ascarpino
parents:
51407
diff
changeset
|
119 |
ProtocolVersion.PROTOCOLS_TO_12 |
c2398053ee90
8211018: Session Resumption without Server-Side State
ascarpino
parents:
51407
diff
changeset
|
120 |
), |
c2398053ee90
8211018: Session Resumption without Server-Side State
ascarpino
parents:
51407
diff
changeset
|
121 |
new SimpleImmutableEntry<SSLConsumer, ProtocolVersion[]>( |
c2398053ee90
8211018: Session Resumption without Server-Side State
ascarpino
parents:
51407
diff
changeset
|
122 |
NewSessionTicket.handshakeConsumer, |
c2398053ee90
8211018: Session Resumption without Server-Side State
ascarpino
parents:
51407
diff
changeset
|
123 |
ProtocolVersion.PROTOCOLS_OF_13 |
c2398053ee90
8211018: Session Resumption without Server-Side State
ascarpino
parents:
51407
diff
changeset
|
124 |
) |
50768 | 125 |
}), |
126 |
(Map.Entry<HandshakeProducer, ProtocolVersion[]>[])(new Map.Entry[] { |
|
127 |
new SimpleImmutableEntry<HandshakeProducer, ProtocolVersion[]>( |
|
55336
c2398053ee90
8211018: Session Resumption without Server-Side State
ascarpino
parents:
51407
diff
changeset
|
128 |
NewSessionTicket.handshake12Producer, |
c2398053ee90
8211018: Session Resumption without Server-Side State
ascarpino
parents:
51407
diff
changeset
|
129 |
ProtocolVersion.PROTOCOLS_TO_12 |
c2398053ee90
8211018: Session Resumption without Server-Side State
ascarpino
parents:
51407
diff
changeset
|
130 |
) |
50768 | 131 |
})), |
132 |
END_OF_EARLY_DATA ((byte)0x05, "end_of_early_data"), |
|
2 | 133 |
|
50768 | 134 |
@SuppressWarnings({"unchecked", "rawtypes"}) |
135 |
ENCRYPTED_EXTENSIONS ((byte)0x08, "encrypted_extensions", |
|
136 |
(Map.Entry<SSLConsumer, ProtocolVersion[]>[])(new Map.Entry[] { |
|
137 |
new SimpleImmutableEntry<SSLConsumer, ProtocolVersion[]>( |
|
138 |
EncryptedExtensions.handshakeConsumer, |
|
139 |
ProtocolVersion.PROTOCOLS_OF_13 |
|
140 |
) |
|
141 |
}), |
|
142 |
(Map.Entry<HandshakeProducer, ProtocolVersion[]>[])(new Map.Entry[] { |
|
143 |
new SimpleImmutableEntry<HandshakeProducer, ProtocolVersion[]>( |
|
144 |
EncryptedExtensions.handshakeProducer, |
|
145 |
ProtocolVersion.PROTOCOLS_OF_13 |
|
146 |
) |
|
147 |
})), |
|
2 | 148 |
|
50768 | 149 |
@SuppressWarnings({"unchecked", "rawtypes"}) |
150 |
CERTIFICATE ((byte)0x0B, "certificate", |
|
151 |
(Map.Entry<SSLConsumer, ProtocolVersion[]>[])(new Map.Entry[] { |
|
152 |
new SimpleImmutableEntry<SSLConsumer, ProtocolVersion[]>( |
|
153 |
CertificateMessage.t12HandshakeConsumer, |
|
154 |
ProtocolVersion.PROTOCOLS_TO_12 |
|
155 |
), |
|
156 |
new SimpleImmutableEntry<SSLConsumer, ProtocolVersion[]>( |
|
157 |
CertificateMessage.t13HandshakeConsumer, |
|
158 |
ProtocolVersion.PROTOCOLS_OF_13 |
|
159 |
) |
|
160 |
}), |
|
161 |
(Map.Entry<HandshakeProducer, ProtocolVersion[]>[])(new Map.Entry[] { |
|
162 |
new SimpleImmutableEntry<HandshakeProducer, ProtocolVersion[]>( |
|
163 |
CertificateMessage.t12HandshakeProducer, |
|
164 |
ProtocolVersion.PROTOCOLS_TO_12 |
|
165 |
), |
|
166 |
new SimpleImmutableEntry<HandshakeProducer, ProtocolVersion[]>( |
|
167 |
CertificateMessage.t13HandshakeProducer, |
|
168 |
ProtocolVersion.PROTOCOLS_OF_13 |
|
169 |
) |
|
170 |
})), |
|
2 | 171 |
|
50768 | 172 |
@SuppressWarnings({"unchecked", "rawtypes"}) |
173 |
SERVER_KEY_EXCHANGE ((byte)0x0C, "server_key_exchange", |
|
174 |
(Map.Entry<SSLConsumer, ProtocolVersion[]>[])(new Map.Entry[] { |
|
175 |
new SimpleImmutableEntry<SSLConsumer, ProtocolVersion[]>( |
|
176 |
ServerKeyExchange.handshakeConsumer, |
|
177 |
ProtocolVersion.PROTOCOLS_TO_12 |
|
178 |
) |
|
179 |
}), |
|
180 |
(Map.Entry<HandshakeProducer, ProtocolVersion[]>[])(new Map.Entry[] { |
|
181 |
new SimpleImmutableEntry<HandshakeProducer, ProtocolVersion[]>( |
|
182 |
ServerKeyExchange.handshakeProducer, |
|
183 |
ProtocolVersion.PROTOCOLS_TO_12 |
|
184 |
) |
|
185 |
})), |
|
2 | 186 |
|
50768 | 187 |
@SuppressWarnings({"unchecked", "rawtypes"}) |
188 |
CERTIFICATE_REQUEST ((byte)0x0D, "certificate_request", |
|
189 |
(Map.Entry<SSLConsumer, ProtocolVersion[]>[])(new Map.Entry[] { |
|
190 |
new SimpleImmutableEntry<SSLConsumer, ProtocolVersion[]>( |
|
191 |
CertificateRequest.t10HandshakeConsumer, |
|
192 |
ProtocolVersion.PROTOCOLS_TO_11 |
|
193 |
), |
|
194 |
new SimpleImmutableEntry<SSLConsumer, ProtocolVersion[]>( |
|
195 |
CertificateRequest.t12HandshakeConsumer, |
|
196 |
ProtocolVersion.PROTOCOLS_OF_12 |
|
197 |
), |
|
198 |
new SimpleImmutableEntry<SSLConsumer, ProtocolVersion[]>( |
|
199 |
CertificateRequest.t13HandshakeConsumer, |
|
200 |
ProtocolVersion.PROTOCOLS_OF_13 |
|
201 |
) |
|
202 |
}), |
|
203 |
(Map.Entry<HandshakeProducer, ProtocolVersion[]>[])(new Map.Entry[] { |
|
204 |
new SimpleImmutableEntry<HandshakeProducer, ProtocolVersion[]>( |
|
205 |
CertificateRequest.t10HandshakeProducer, |
|
206 |
ProtocolVersion.PROTOCOLS_TO_11 |
|
207 |
), |
|
208 |
new SimpleImmutableEntry<HandshakeProducer, ProtocolVersion[]>( |
|
209 |
CertificateRequest.t12HandshakeProducer, |
|
210 |
ProtocolVersion.PROTOCOLS_OF_12 |
|
211 |
), |
|
212 |
new SimpleImmutableEntry<HandshakeProducer, ProtocolVersion[]>( |
|
213 |
CertificateRequest.t13HandshakeProducer, |
|
214 |
ProtocolVersion.PROTOCOLS_OF_13 |
|
215 |
) |
|
216 |
})), |
|
2 | 217 |
|
50768 | 218 |
@SuppressWarnings({"unchecked", "rawtypes"}) |
219 |
SERVER_HELLO_DONE ((byte)0x0E, "server_hello_done", |
|
220 |
(Map.Entry<SSLConsumer, ProtocolVersion[]>[])(new Map.Entry[] { |
|
221 |
new SimpleImmutableEntry<SSLConsumer, ProtocolVersion[]>( |
|
222 |
ServerHelloDone.handshakeConsumer, |
|
223 |
ProtocolVersion.PROTOCOLS_TO_12 |
|
224 |
) |
|
225 |
}), |
|
226 |
(Map.Entry<HandshakeProducer, ProtocolVersion[]>[])(new Map.Entry[] { |
|
227 |
new SimpleImmutableEntry<HandshakeProducer, ProtocolVersion[]>( |
|
228 |
ServerHelloDone.handshakeProducer, |
|
229 |
ProtocolVersion.PROTOCOLS_TO_12 |
|
230 |
) |
|
231 |
})), |
|
46060 | 232 |
|
50768 | 233 |
@SuppressWarnings({"unchecked", "rawtypes"}) |
234 |
CERTIFICATE_VERIFY ((byte)0x0F, "certificate_verify", |
|
235 |
(Map.Entry<SSLConsumer, ProtocolVersion[]>[])(new Map.Entry[] { |
|
236 |
new SimpleImmutableEntry<SSLConsumer, ProtocolVersion[]>( |
|
237 |
CertificateVerify.s30HandshakeConsumer, |
|
238 |
ProtocolVersion.PROTOCOLS_OF_30 |
|
239 |
), |
|
240 |
new SimpleImmutableEntry<SSLConsumer, ProtocolVersion[]>( |
|
241 |
CertificateVerify.t10HandshakeConsumer, |
|
242 |
ProtocolVersion.PROTOCOLS_10_11 |
|
243 |
), |
|
244 |
new SimpleImmutableEntry<SSLConsumer, ProtocolVersion[]>( |
|
245 |
CertificateVerify.t12HandshakeConsumer, |
|
246 |
ProtocolVersion.PROTOCOLS_OF_12 |
|
247 |
), |
|
248 |
new SimpleImmutableEntry<SSLConsumer, ProtocolVersion[]>( |
|
249 |
CertificateVerify.t13HandshakeConsumer, |
|
250 |
ProtocolVersion.PROTOCOLS_OF_13 |
|
251 |
) |
|
252 |
}), |
|
253 |
(Map.Entry<HandshakeProducer, ProtocolVersion[]>[])(new Map.Entry[] { |
|
254 |
new SimpleImmutableEntry<HandshakeProducer, ProtocolVersion[]>( |
|
255 |
CertificateVerify.s30HandshakeProducer, |
|
256 |
ProtocolVersion.PROTOCOLS_OF_30 |
|
257 |
), |
|
258 |
new SimpleImmutableEntry<HandshakeProducer, ProtocolVersion[]>( |
|
259 |
CertificateVerify.t10HandshakeProducer, |
|
260 |
ProtocolVersion.PROTOCOLS_10_11 |
|
261 |
), |
|
262 |
new SimpleImmutableEntry<HandshakeProducer, ProtocolVersion[]>( |
|
263 |
CertificateVerify.t12HandshakeProducer, |
|
264 |
ProtocolVersion.PROTOCOLS_OF_12 |
|
265 |
), |
|
266 |
new SimpleImmutableEntry<HandshakeProducer, ProtocolVersion[]>( |
|
267 |
CertificateVerify.t13HandshakeProducer, |
|
268 |
ProtocolVersion.PROTOCOLS_OF_13 |
|
269 |
) |
|
270 |
})), |
|
2 | 271 |
|
50768 | 272 |
@SuppressWarnings({"unchecked", "rawtypes"}) |
273 |
CLIENT_KEY_EXCHANGE ((byte)0x10, "client_key_exchange", |
|
274 |
(Map.Entry<SSLConsumer, ProtocolVersion[]>[])(new Map.Entry[] { |
|
275 |
new SimpleImmutableEntry<SSLConsumer, ProtocolVersion[]>( |
|
276 |
ClientKeyExchange.handshakeConsumer, |
|
277 |
ProtocolVersion.PROTOCOLS_TO_12 |
|
278 |
) |
|
279 |
}), |
|
280 |
(Map.Entry<HandshakeProducer, ProtocolVersion[]>[])(new Map.Entry[] { |
|
281 |
new SimpleImmutableEntry<HandshakeProducer, ProtocolVersion[]>( |
|
282 |
ClientKeyExchange.handshakeProducer, |
|
283 |
ProtocolVersion.PROTOCOLS_TO_12 |
|
284 |
) |
|
285 |
})), |
|
2 | 286 |
|
50768 | 287 |
@SuppressWarnings({"unchecked", "rawtypes"}) |
288 |
FINISHED ((byte)0x14, "finished", |
|
289 |
(Map.Entry<SSLConsumer, ProtocolVersion[]>[])(new Map.Entry[] { |
|
290 |
new SimpleImmutableEntry<SSLConsumer, ProtocolVersion[]>( |
|
291 |
Finished.t12HandshakeConsumer, |
|
292 |
ProtocolVersion.PROTOCOLS_TO_12 |
|
293 |
), |
|
294 |
new SimpleImmutableEntry<SSLConsumer, ProtocolVersion[]>( |
|
295 |
Finished.t13HandshakeConsumer, |
|
296 |
ProtocolVersion.PROTOCOLS_OF_13 |
|
297 |
) |
|
298 |
}), |
|
299 |
(Map.Entry<HandshakeProducer, ProtocolVersion[]>[])(new Map.Entry[] { |
|
300 |
new SimpleImmutableEntry<HandshakeProducer, ProtocolVersion[]>( |
|
301 |
Finished.t12HandshakeProducer, |
|
302 |
ProtocolVersion.PROTOCOLS_TO_12 |
|
303 |
), |
|
304 |
new SimpleImmutableEntry<HandshakeProducer, ProtocolVersion[]>( |
|
305 |
Finished.t13HandshakeProducer, |
|
306 |
ProtocolVersion.PROTOCOLS_OF_13 |
|
307 |
) |
|
308 |
})), |
|
2 | 309 |
|
50768 | 310 |
CERTIFICATE_URL ((byte)0x15, "certificate_url"), |
2 | 311 |
|
50768 | 312 |
@SuppressWarnings({"unchecked", "rawtypes"}) |
313 |
CERTIFICATE_STATUS ((byte)0x16, "certificate_status", |
|
314 |
(Map.Entry<SSLConsumer, ProtocolVersion[]>[])(new Map.Entry[] { |
|
315 |
new SimpleImmutableEntry<SSLConsumer, ProtocolVersion[]>( |
|
316 |
CertificateStatus.handshakeConsumer, |
|
317 |
ProtocolVersion.PROTOCOLS_TO_12 |
|
318 |
) |
|
319 |
}), |
|
320 |
(Map.Entry<HandshakeProducer, ProtocolVersion[]>[])(new Map.Entry[] { |
|
321 |
new SimpleImmutableEntry<HandshakeProducer, ProtocolVersion[]>( |
|
322 |
CertificateStatus.handshakeProducer, |
|
323 |
ProtocolVersion.PROTOCOLS_TO_12 |
|
324 |
) |
|
325 |
}), |
|
326 |
(Map.Entry<HandshakeAbsence, ProtocolVersion[]>[])(new Map.Entry[] { |
|
327 |
new SimpleImmutableEntry<HandshakeAbsence, ProtocolVersion[]>( |
|
328 |
CertificateStatus.handshakeAbsence, |
|
329 |
ProtocolVersion.PROTOCOLS_TO_12 |
|
330 |
) |
|
331 |
})), |
|
2 | 332 |
|
50768 | 333 |
SUPPLEMENTAL_DATA ((byte)0x17, "supplemental_data"), |
2 | 334 |
|
50768 | 335 |
@SuppressWarnings({"unchecked", "rawtypes"}) |
336 |
KEY_UPDATE ((byte)0x18, "key_update", |
|
337 |
(Map.Entry<SSLConsumer, ProtocolVersion[]>[])(new Map.Entry[] { |
|
338 |
new SimpleImmutableEntry<SSLConsumer, ProtocolVersion[]>( |
|
339 |
KeyUpdate.handshakeConsumer, |
|
340 |
ProtocolVersion.PROTOCOLS_OF_13 |
|
341 |
) |
|
342 |
}), |
|
343 |
(Map.Entry<HandshakeProducer, ProtocolVersion[]>[])(new Map.Entry[] { |
|
344 |
new SimpleImmutableEntry<HandshakeProducer, ProtocolVersion[]>( |
|
345 |
KeyUpdate.handshakeProducer, |
|
346 |
ProtocolVersion.PROTOCOLS_OF_13 |
|
347 |
) |
|
348 |
})), |
|
349 |
MESSAGE_HASH ((byte)0xFE, "message_hash"), |
|
350 |
NOT_APPLICABLE ((byte)0xFF, "not_applicable"); |
|
2 | 351 |
|
50768 | 352 |
final byte id; |
353 |
final String name; |
|
354 |
final Map.Entry<SSLConsumer, ProtocolVersion[]>[] handshakeConsumers; |
|
355 |
final Map.Entry<HandshakeProducer, ProtocolVersion[]>[] handshakeProducers; |
|
356 |
final Map.Entry<HandshakeAbsence, ProtocolVersion[]>[] handshakeAbsences; |
|
2 | 357 |
|
50768 | 358 |
@SuppressWarnings({"unchecked", "rawtypes"}) |
359 |
SSLHandshake(byte id, String name) { |
|
360 |
this(id, name, |
|
361 |
(Map.Entry<SSLConsumer, ProtocolVersion[]>[])( |
|
362 |
new Map.Entry[0]), |
|
363 |
(Map.Entry<HandshakeProducer, ProtocolVersion[]>[])( |
|
364 |
new Map.Entry[0]), |
|
365 |
(Map.Entry<HandshakeAbsence, ProtocolVersion[]>[])( |
|
366 |
new Map.Entry[0])); |
|
2 | 367 |
} |
368 |
||
50768 | 369 |
@SuppressWarnings({"unchecked", "rawtypes"}) |
370 |
SSLHandshake(byte id, String name, |
|
371 |
Map.Entry<SSLConsumer, ProtocolVersion[]>[] handshakeConsumers, |
|
372 |
Map.Entry<HandshakeProducer, ProtocolVersion[]>[] handshakeProducers) { |
|
51407
910f7b56592f
8207009: TLS 1.3 half-close and synchronization issues
xuelei
parents:
50768
diff
changeset
|
373 |
|
50768 | 374 |
this(id, name, handshakeConsumers, handshakeProducers, |
375 |
(Map.Entry<HandshakeAbsence, ProtocolVersion[]>[])( |
|
376 |
new Map.Entry[0])); |
|
2 | 377 |
} |
378 |
||
50768 | 379 |
SSLHandshake(byte id, String name, |
380 |
Map.Entry<SSLConsumer, ProtocolVersion[]>[] handshakeConsumers, |
|
381 |
Map.Entry<HandshakeProducer, ProtocolVersion[]>[] handshakeProducers, |
|
382 |
Map.Entry<HandshakeAbsence, ProtocolVersion[]>[] handshakeAbsence) { |
|
51407
910f7b56592f
8207009: TLS 1.3 half-close and synchronization issues
xuelei
parents:
50768
diff
changeset
|
383 |
|
50768 | 384 |
this.id = id; |
385 |
this.name = name; |
|
386 |
this.handshakeConsumers = handshakeConsumers; |
|
387 |
this.handshakeProducers = handshakeProducers; |
|
388 |
this.handshakeAbsences = handshakeAbsence; |
|
6856 | 389 |
} |
390 |
||
391 |
@Override |
|
50768 | 392 |
public void consume(ConnectionContext context, |
393 |
ByteBuffer message) throws IOException { |
|
394 |
SSLConsumer hc = getHandshakeConsumer(context); |
|
395 |
if (hc != null) { |
|
396 |
hc.consume(context, message); |
|
397 |
} else { |
|
398 |
throw new UnsupportedOperationException( |
|
399 |
"Unsupported handshake consumer: " + this.name); |
|
2 | 400 |
} |
401 |
} |
|
402 |
||
50768 | 403 |
private SSLConsumer getHandshakeConsumer(ConnectionContext context) { |
404 |
if (handshakeConsumers.length == 0) { |
|
405 |
return null; |
|
2 | 406 |
} |
407 |
||
50768 | 408 |
// The consuming happens in handshake context only. |
409 |
HandshakeContext hc = (HandshakeContext)context; |
|
410 |
ProtocolVersion protocolVersion; |
|
411 |
if ((hc.negotiatedProtocol == null) || |
|
412 |
(hc.negotiatedProtocol == ProtocolVersion.NONE)) { |
|
51407
910f7b56592f
8207009: TLS 1.3 half-close and synchronization issues
xuelei
parents:
50768
diff
changeset
|
413 |
if (hc.conContext.isNegotiated && |
910f7b56592f
8207009: TLS 1.3 half-close and synchronization issues
xuelei
parents:
50768
diff
changeset
|
414 |
hc.conContext.protocolVersion != ProtocolVersion.NONE) { |
910f7b56592f
8207009: TLS 1.3 half-close and synchronization issues
xuelei
parents:
50768
diff
changeset
|
415 |
protocolVersion = hc.conContext.protocolVersion; |
910f7b56592f
8207009: TLS 1.3 half-close and synchronization issues
xuelei
parents:
50768
diff
changeset
|
416 |
} else { |
910f7b56592f
8207009: TLS 1.3 half-close and synchronization issues
xuelei
parents:
50768
diff
changeset
|
417 |
protocolVersion = hc.maximumActiveProtocol; |
910f7b56592f
8207009: TLS 1.3 half-close and synchronization issues
xuelei
parents:
50768
diff
changeset
|
418 |
} |
50768 | 419 |
} else { |
420 |
protocolVersion = hc.negotiatedProtocol; |
|
421 |
} |
|
2 | 422 |
|
50768 | 423 |
for (Map.Entry<SSLConsumer, |
424 |
ProtocolVersion[]> phe : handshakeConsumers) { |
|
425 |
for (ProtocolVersion pv : phe.getValue()) { |
|
426 |
if (protocolVersion == pv) { |
|
427 |
return phe.getKey(); |
|
2 | 428 |
} |
429 |
} |
|
430 |
} |
|
431 |
||
50768 | 432 |
return null; |
2 | 433 |
} |
434 |
||
14664
e71aa0962e70
8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents:
14194
diff
changeset
|
435 |
@Override |
50768 | 436 |
public byte[] produce(ConnectionContext context, |
437 |
HandshakeMessage message) throws IOException { |
|
438 |
HandshakeProducer hp = getHandshakeProducer(context); |
|
439 |
if (hp != null) { |
|
440 |
return hp.produce(context, message); |
|
32032 | 441 |
} else { |
50768 | 442 |
throw new UnsupportedOperationException( |
443 |
"Unsupported handshake producer: " + this.name); |
|
32032 | 444 |
} |
445 |
} |
|
446 |
||
50768 | 447 |
private HandshakeProducer getHandshakeProducer( |
448 |
ConnectionContext context) { |
|
449 |
if (handshakeConsumers.length == 0) { |
|
450 |
return null; |
|
451 |
} |
|
452 |
||
453 |
// The consuming happens in handshake context only. |
|
454 |
HandshakeContext hc = (HandshakeContext)context; |
|
455 |
ProtocolVersion protocolVersion; |
|
456 |
if ((hc.negotiatedProtocol == null) || |
|
457 |
(hc.negotiatedProtocol == ProtocolVersion.NONE)) { |
|
51407
910f7b56592f
8207009: TLS 1.3 half-close and synchronization issues
xuelei
parents:
50768
diff
changeset
|
458 |
if (hc.conContext.isNegotiated && |
910f7b56592f
8207009: TLS 1.3 half-close and synchronization issues
xuelei
parents:
50768
diff
changeset
|
459 |
hc.conContext.protocolVersion != ProtocolVersion.NONE) { |
910f7b56592f
8207009: TLS 1.3 half-close and synchronization issues
xuelei
parents:
50768
diff
changeset
|
460 |
protocolVersion = hc.conContext.protocolVersion; |
910f7b56592f
8207009: TLS 1.3 half-close and synchronization issues
xuelei
parents:
50768
diff
changeset
|
461 |
} else { |
910f7b56592f
8207009: TLS 1.3 half-close and synchronization issues
xuelei
parents:
50768
diff
changeset
|
462 |
protocolVersion = hc.maximumActiveProtocol; |
910f7b56592f
8207009: TLS 1.3 half-close and synchronization issues
xuelei
parents:
50768
diff
changeset
|
463 |
} |
50768 | 464 |
} else { |
465 |
protocolVersion = hc.negotiatedProtocol; |
|
466 |
} |
|
32032 | 467 |
|
50768 | 468 |
for (Map.Entry<HandshakeProducer, |
469 |
ProtocolVersion[]> phe : handshakeProducers) { |
|
470 |
for (ProtocolVersion pv : phe.getValue()) { |
|
471 |
if (protocolVersion == pv) { |
|
472 |
return phe.getKey(); |
|
473 |
} |
|
32032 | 474 |
} |
50768 | 475 |
} |
32032 | 476 |
|
50768 | 477 |
return null; |
478 |
} |
|
32032 | 479 |
|
50768 | 480 |
@Override |
481 |
public String toString() { |
|
482 |
return name; |
|
32032 | 483 |
} |
484 |
||
50768 | 485 |
static String nameOf(byte id) { |
486 |
// If two handshake message share the same handshake type, returns |
|
487 |
// the first handshake message name. |
|
488 |
// |
|
489 |
// It is not a big issue at present as only ServerHello and |
|
490 |
// HellRetryRequest share a handshake type. |
|
491 |
for (SSLHandshake hs : SSLHandshake.values()) { |
|
492 |
if (hs.id == id) { |
|
493 |
return hs.name; |
|
32032 | 494 |
} |
495 |
} |
|
496 |
||
50768 | 497 |
return "UNKNOWN-HANDSHAKE-MESSAGE(" + id + ")"; |
32032 | 498 |
} |
499 |
||
57799
7cc5a5b4eee9
8228757: Fail fast if the handshake type is unknown
xuelei
parents:
55336
diff
changeset
|
500 |
static boolean isKnown(byte id) { |
7cc5a5b4eee9
8228757: Fail fast if the handshake type is unknown
xuelei
parents:
55336
diff
changeset
|
501 |
for (SSLHandshake hs : SSLHandshake.values()) { |
7cc5a5b4eee9
8228757: Fail fast if the handshake type is unknown
xuelei
parents:
55336
diff
changeset
|
502 |
if (hs.id == id && id != NOT_APPLICABLE.id) { |
7cc5a5b4eee9
8228757: Fail fast if the handshake type is unknown
xuelei
parents:
55336
diff
changeset
|
503 |
return true; |
7cc5a5b4eee9
8228757: Fail fast if the handshake type is unknown
xuelei
parents:
55336
diff
changeset
|
504 |
} |
7cc5a5b4eee9
8228757: Fail fast if the handshake type is unknown
xuelei
parents:
55336
diff
changeset
|
505 |
} |
7cc5a5b4eee9
8228757: Fail fast if the handshake type is unknown
xuelei
parents:
55336
diff
changeset
|
506 |
|
7cc5a5b4eee9
8228757: Fail fast if the handshake type is unknown
xuelei
parents:
55336
diff
changeset
|
507 |
return false; |
7cc5a5b4eee9
8228757: Fail fast if the handshake type is unknown
xuelei
parents:
55336
diff
changeset
|
508 |
} |
7cc5a5b4eee9
8228757: Fail fast if the handshake type is unknown
xuelei
parents:
55336
diff
changeset
|
509 |
|
50768 | 510 |
static final void kickstart(HandshakeContext context) throws IOException { |
511 |
if (context instanceof ClientHandshakeContext) { |
|
512 |
// For initial handshaking, including session resumption, |
|
513 |
// ClientHello message is used as the kickstart message. |
|
514 |
// |
|
515 |
// (D)TLS 1.2 and older protocols support renegotiation on existing |
|
516 |
// connections. A ClientHello messages is used to kickstart the |
|
517 |
// renegotiation. |
|
518 |
// |
|
519 |
// (D)TLS 1.3 forbids renegotiation. The post-handshake KeyUpdate |
|
520 |
// message is used to update the sending cryptographic keys. |
|
521 |
if (context.conContext.isNegotiated && |
|
522 |
context.conContext.protocolVersion.useTLS13PlusSpec()) { |
|
523 |
// Use KeyUpdate message for renegotiation. |
|
524 |
KeyUpdate.kickstartProducer.produce(context); |
|
525 |
} else { |
|
526 |
// Using ClientHello message for the initial handshaking |
|
527 |
// (including session resumption) or renegotiation. |
|
528 |
// SSLHandshake.CLIENT_HELLO.produce(context); |
|
529 |
ClientHello.kickstartProducer.produce(context); |
|
32032 | 530 |
} |
531 |
} else { |
|
50768 | 532 |
// The server side can delivering kickstart message after the |
533 |
// connection has established. |
|
534 |
// |
|
535 |
// (D)TLS 1.2 and older protocols use HelloRequest to begin a |
|
536 |
// negotiation process anew. |
|
537 |
// |
|
538 |
// While (D)TLS 1.3 uses the post-handshake KeyUpdate message |
|
539 |
// to update the sending cryptographic keys. |
|
540 |
if (context.conContext.protocolVersion.useTLS13PlusSpec()) { |
|
541 |
// Use KeyUpdate message for renegotiation. |
|
542 |
KeyUpdate.kickstartProducer.produce(context); |
|
543 |
} else { |
|
544 |
// SSLHandshake.HELLO_REQUEST.produce(context); |
|
545 |
HelloRequest.kickstartProducer.produce(context); |
|
32032 | 546 |
} |
547 |
} |
|
548 |
} |
|
549 |
||
550 |
/** |
|
50768 | 551 |
* A (transparent) specification of handshake message. |
32032 | 552 |
*/ |
50768 | 553 |
static abstract class HandshakeMessage { |
554 |
final HandshakeContext handshakeContext; |
|
2 | 555 |
|
50768 | 556 |
HandshakeMessage(HandshakeContext handshakeContext) { |
557 |
this.handshakeContext = handshakeContext; |
|
2 | 558 |
} |
559 |
||
50768 | 560 |
abstract SSLHandshake handshakeType(); |
561 |
abstract int messageLength(); |
|
562 |
abstract void send(HandshakeOutStream hos) throws IOException; |
|
45064
b1b45177051b
8140436: Negotiated Finite Field Diffie-Hellman Ephemeral Parameters for TLS
xuelei
parents:
41471
diff
changeset
|
563 |
|
50768 | 564 |
void write(HandshakeOutStream hos) throws IOException { |
565 |
int len = messageLength(); |
|
566 |
if (len >= Record.OVERFLOW_OF_INT24) { |
|
567 |
throw new SSLException("Handshake message is overflow" |
|
568 |
+ ", type = " + handshakeType() + ", len = " + len); |
|
7043 | 569 |
} |
50768 | 570 |
hos.write(handshakeType().id); |
571 |
hos.putInt24(len); |
|
572 |
send(hos); |
|
573 |
hos.complete(); |
|
2 | 574 |
} |
575 |
} |
|
576 |
} |