author | xuelei |
Mon, 25 Jun 2018 13:41:39 -0700 | |
changeset 50768 | 68fa3d4026ea |
parent 47216 | 71c04702a3d5 |
child 51407 | 910f7b56592f |
permissions | -rw-r--r-- |
2 | 1 |
/* |
50768 | 2 |
* Copyright (c) 1996, 2018, 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.LinkedList; |
|
31 |
import javax.net.ssl.SSLHandshakeException; |
|
30904 | 32 |
|
50768 | 33 |
import sun.security.ssl.SSLCipher.SSLWriteCipher; |
34 |
import sun.security.ssl.KeyUpdate.KeyUpdateMessage; |
|
35 |
import sun.security.ssl.KeyUpdate.KeyUpdateRequest; |
|
2 | 36 |
|
37 |
/** |
|
30904 | 38 |
* {@code OutputRecord} implementation for {@code SSLEngine}. |
2 | 39 |
*/ |
30904 | 40 |
final class SSLEngineOutputRecord extends OutputRecord implements SSLRecord { |
41 |
||
42 |
private HandshakeFragment fragmenter = null; |
|
43 |
private boolean isTalkingToV2 = false; // SSLv2Hello |
|
44 |
private ByteBuffer v2ClientHello = null; // SSLv2Hello |
|
45 |
||
46 |
private boolean isCloseWaiting = false; |
|
47 |
||
50768 | 48 |
SSLEngineOutputRecord(HandshakeHash handshakeHash) { |
49 |
super(handshakeHash, SSLWriteCipher.nullTlsWriteCipher()); |
|
30904 | 50 |
|
51 |
this.packetSize = SSLRecord.maxRecordSize; |
|
50768 | 52 |
this.protocolVersion = ProtocolVersion.NONE; |
30904 | 53 |
} |
2 | 54 |
|
30904 | 55 |
@Override |
32649
2ee9017c7597
8136583: Core libraries should use blessed modifier order
martin
parents:
30904
diff
changeset
|
56 |
public synchronized void close() throws IOException { |
30904 | 57 |
if (!isClosed) { |
50768 | 58 |
if (fragmenter != null && fragmenter.hasAlert()) { |
30904 | 59 |
isCloseWaiting = true; |
60 |
} else { |
|
61 |
super.close(); |
|
62 |
} |
|
63 |
} |
|
64 |
} |
|
65 |
||
66 |
@Override |
|
67 |
void encodeAlert(byte level, byte description) throws IOException { |
|
50768 | 68 |
if (fragmenter == null) { |
69 |
fragmenter = new HandshakeFragment(); |
|
70 |
} |
|
30904 | 71 |
|
50768 | 72 |
fragmenter.queueUpAlert(level, description); |
30904 | 73 |
} |
2 | 74 |
|
30904 | 75 |
@Override |
76 |
void encodeHandshake(byte[] source, |
|
77 |
int offset, int length) throws IOException { |
|
78 |
||
79 |
if (fragmenter == null) { |
|
80 |
fragmenter = new HandshakeFragment(); |
|
81 |
} |
|
82 |
||
83 |
if (firstMessage) { |
|
84 |
firstMessage = false; |
|
2 | 85 |
|
30904 | 86 |
if ((helloVersion == ProtocolVersion.SSL20Hello) && |
50768 | 87 |
(source[offset] == SSLHandshake.CLIENT_HELLO.id) && |
30904 | 88 |
// 5: recode header size |
89 |
(source[offset + 4 + 2 + 32] == 0)) { |
|
90 |
// V3 session ID is empty |
|
91 |
// 4: handshake header size |
|
92 |
// 2: client_version in ClientHello |
|
93 |
// 32: random in ClientHello |
|
94 |
||
95 |
// Double space should be big enough for the converted message. |
|
96 |
v2ClientHello = encodeV2ClientHello( |
|
97 |
source, (offset + 4), (length - 4)); |
|
2 | 98 |
|
30904 | 99 |
v2ClientHello.position(2); // exclude the header |
50768 | 100 |
handshakeHash.deliver(v2ClientHello); |
30904 | 101 |
v2ClientHello.position(0); |
102 |
||
103 |
return; |
|
104 |
} |
|
105 |
} |
|
106 |
||
107 |
byte handshakeType = source[offset]; |
|
50768 | 108 |
if (handshakeHash.isHashable(handshakeType)) { |
109 |
handshakeHash.deliver(source, offset, length); |
|
30904 | 110 |
} |
111 |
||
112 |
fragmenter.queueUpFragment(source, offset, length); |
|
113 |
} |
|
114 |
||
115 |
@Override |
|
116 |
void encodeChangeCipherSpec() throws IOException { |
|
117 |
if (fragmenter == null) { |
|
118 |
fragmenter = new HandshakeFragment(); |
|
119 |
} |
|
120 |
fragmenter.queueUpChangeCipherSpec(); |
|
121 |
} |
|
122 |
||
123 |
@Override |
|
124 |
void encodeV2NoCipher() throws IOException { |
|
125 |
isTalkingToV2 = true; |
|
2 | 126 |
} |
127 |
||
30904 | 128 |
@Override |
50768 | 129 |
Ciphertext encode( |
130 |
ByteBuffer[] srcs, int srcsOffset, int srcsLength, |
|
131 |
ByteBuffer[] dsts, int dstsOffset, int dstsLength) throws IOException { |
|
132 |
return encode(srcs, srcsOffset, srcsLength, dsts[0]); |
|
133 |
} |
|
134 |
||
135 |
private Ciphertext encode(ByteBuffer[] sources, int offset, int length, |
|
30904 | 136 |
ByteBuffer destination) throws IOException { |
2 | 137 |
|
50768 | 138 |
if (writeCipher.authenticator.seqNumOverflow()) { |
139 |
if (SSLLogger.isOn && SSLLogger.isOn("ssl")) { |
|
140 |
SSLLogger.fine( |
|
141 |
"sequence number extremely close to overflow " + |
|
30904 | 142 |
"(2^64-1 packets). Closing connection."); |
143 |
} |
|
2 | 144 |
|
30904 | 145 |
throw new SSLHandshakeException("sequence number overflow"); |
146 |
} |
|
2 | 147 |
|
50768 | 148 |
// Don't process the incoming record until all of the |
149 |
// buffered records get handled. |
|
150 |
Ciphertext ct = acquireCiphertext(destination); |
|
151 |
if (ct != null) { |
|
152 |
return ct; |
|
153 |
} |
|
154 |
||
155 |
if (sources == null || sources.length == 0) { |
|
156 |
return null; |
|
157 |
} |
|
158 |
||
159 |
int srcsRemains = 0; |
|
160 |
for (int i = offset; i < offset + length; i++) { |
|
161 |
srcsRemains += sources[i].remaining(); |
|
162 |
} |
|
163 |
||
164 |
if (srcsRemains == 0) { |
|
165 |
return null; |
|
2 | 166 |
} |
167 |
||
30904 | 168 |
int dstLim = destination.limit(); |
169 |
boolean isFirstRecordOfThePayload = true; |
|
170 |
int packetLeftSize = Math.min(maxRecordSize, packetSize); |
|
171 |
boolean needMorePayload = true; |
|
172 |
long recordSN = 0L; |
|
173 |
while (needMorePayload) { |
|
174 |
int fragLen; |
|
175 |
if (isFirstRecordOfThePayload && needToSplitPayload()) { |
|
176 |
needMorePayload = true; |
|
177 |
||
178 |
fragLen = 1; |
|
179 |
isFirstRecordOfThePayload = false; |
|
180 |
} else { |
|
181 |
needMorePayload = false; |
|
182 |
||
183 |
if (packetLeftSize > 0) { |
|
184 |
fragLen = writeCipher.calculateFragmentSize( |
|
50768 | 185 |
packetLeftSize, headerSize); |
30904 | 186 |
|
187 |
fragLen = Math.min(fragLen, Record.maxDataSize); |
|
188 |
} else { |
|
189 |
fragLen = Record.maxDataSize; |
|
190 |
} |
|
191 |
||
192 |
if (fragmentSize > 0) { |
|
193 |
fragLen = Math.min(fragLen, fragmentSize); |
|
194 |
} |
|
195 |
} |
|
196 |
||
197 |
int dstPos = destination.position(); |
|
198 |
int dstContent = dstPos + headerSize + |
|
199 |
writeCipher.getExplicitNonceSize(); |
|
200 |
destination.position(dstContent); |
|
2 | 201 |
|
30904 | 202 |
int remains = Math.min(fragLen, destination.remaining()); |
203 |
fragLen = 0; |
|
204 |
int srcsLen = offset + length; |
|
205 |
for (int i = offset; (i < srcsLen) && (remains > 0); i++) { |
|
206 |
int amount = Math.min(sources[i].remaining(), remains); |
|
207 |
int srcLimit = sources[i].limit(); |
|
208 |
sources[i].limit(sources[i].position() + amount); |
|
209 |
destination.put(sources[i]); |
|
210 |
sources[i].limit(srcLimit); // restore the limit |
|
211 |
remains -= amount; |
|
212 |
fragLen += amount; |
|
213 |
||
214 |
if (remains > 0) { |
|
215 |
offset++; |
|
216 |
length--; |
|
217 |
} |
|
218 |
} |
|
219 |
||
220 |
destination.limit(destination.position()); |
|
221 |
destination.position(dstContent); |
|
222 |
||
50768 | 223 |
if (SSLLogger.isOn && SSLLogger.isOn("record")) { |
224 |
SSLLogger.fine( |
|
225 |
"WRITE: " + protocolVersion + " " + |
|
226 |
ContentType.APPLICATION_DATA.name + |
|
30904 | 227 |
", length = " + destination.remaining()); |
228 |
} |
|
229 |
||
230 |
// Encrypt the fragment and wrap up a record. |
|
50768 | 231 |
recordSN = encrypt(writeCipher, |
232 |
ContentType.APPLICATION_DATA.id, destination, |
|
30904 | 233 |
dstPos, dstLim, headerSize, |
50768 | 234 |
protocolVersion); |
30904 | 235 |
|
50768 | 236 |
if (SSLLogger.isOn && SSLLogger.isOn("packet")) { |
30904 | 237 |
ByteBuffer temporary = destination.duplicate(); |
238 |
temporary.limit(temporary.position()); |
|
239 |
temporary.position(dstPos); |
|
50768 | 240 |
SSLLogger.fine("Raw write", temporary); |
30904 | 241 |
} |
242 |
||
243 |
packetLeftSize -= destination.position() - dstPos; |
|
244 |
||
245 |
// remain the limit unchanged |
|
246 |
destination.limit(dstLim); |
|
247 |
||
248 |
if (isFirstAppOutputRecord) { |
|
249 |
isFirstAppOutputRecord = false; |
|
250 |
} |
|
50768 | 251 |
|
252 |
// atKeyLimit() inactive when limits not checked, tc set when limits |
|
253 |
// are active. |
|
254 |
if (writeCipher.atKeyLimit()) { |
|
255 |
if (SSLLogger.isOn && SSLLogger.isOn("ssl")) { |
|
256 |
SSLLogger.fine("KeyUpdate: triggered, write side."); |
|
257 |
} |
|
258 |
||
259 |
PostHandshakeContext p = new PostHandshakeContext(tc); |
|
260 |
KeyUpdate.handshakeProducer.produce(p, |
|
261 |
new KeyUpdateMessage(p, KeyUpdateRequest.REQUESTED)); |
|
262 |
} |
|
30904 | 263 |
} |
264 |
||
50768 | 265 |
return new Ciphertext(ContentType.APPLICATION_DATA.id, |
266 |
SSLHandshake.NOT_APPLICABLE.id, recordSN); |
|
2 | 267 |
} |
268 |
||
50768 | 269 |
private Ciphertext acquireCiphertext(ByteBuffer destination) throws IOException { |
30904 | 270 |
if (isTalkingToV2) { // SSLv2Hello |
271 |
// We don't support SSLv2. Send an SSLv2 error message |
|
272 |
// so that the connection can be closed gracefully. |
|
273 |
// |
|
274 |
// Please don't change the limit of the destination buffer. |
|
275 |
destination.put(SSLRecord.v2NoCipher); |
|
50768 | 276 |
if (SSLLogger.isOn && SSLLogger.isOn("packet")) { |
277 |
SSLLogger.fine("Raw write", SSLRecord.v2NoCipher); |
|
30904 | 278 |
} |
279 |
||
280 |
isTalkingToV2 = false; |
|
281 |
||
50768 | 282 |
return new Ciphertext(ContentType.ALERT.id, |
283 |
SSLHandshake.NOT_APPLICABLE.id, -1L); |
|
30904 | 284 |
} |
285 |
||
286 |
if (v2ClientHello != null) { |
|
287 |
// deliver the SSLv2 format ClientHello message |
|
288 |
// |
|
289 |
// Please don't change the limit of the destination buffer. |
|
50768 | 290 |
if (SSLLogger.isOn) { |
291 |
if (SSLLogger.isOn("record")) { |
|
292 |
SSLLogger.fine(Thread.currentThread().getName() + |
|
30904 | 293 |
", WRITE: SSLv2 ClientHello message" + |
294 |
", length = " + v2ClientHello.remaining()); |
|
295 |
} |
|
296 |
||
50768 | 297 |
if (SSLLogger.isOn("packet")) { |
298 |
SSLLogger.fine("Raw write", v2ClientHello); |
|
30904 | 299 |
} |
300 |
} |
|
301 |
||
302 |
destination.put(v2ClientHello); |
|
303 |
v2ClientHello = null; |
|
304 |
||
50768 | 305 |
return new Ciphertext(ContentType.HANDSHAKE.id, |
306 |
SSLHandshake.CLIENT_HELLO.id, -1L); |
|
30904 | 307 |
} |
308 |
||
309 |
if (fragmenter != null) { |
|
310 |
return fragmenter.acquireCiphertext(destination); |
|
311 |
} |
|
312 |
||
313 |
return null; |
|
2 | 314 |
} |
315 |
||
30904 | 316 |
@Override |
317 |
boolean isEmpty() { |
|
318 |
return (!isTalkingToV2) && (v2ClientHello == null) && |
|
50768 | 319 |
((fragmenter == null) || fragmenter.isEmpty()); |
30904 | 320 |
} |
321 |
||
322 |
// buffered record fragment |
|
323 |
private static class RecordMemo { |
|
324 |
byte contentType; |
|
325 |
byte majorVersion; |
|
326 |
byte minorVersion; |
|
50768 | 327 |
SSLWriteCipher encodeCipher; |
30904 | 328 |
|
329 |
byte[] fragment; |
|
330 |
} |
|
331 |
||
332 |
private static class HandshakeMemo extends RecordMemo { |
|
333 |
byte handshakeType; |
|
334 |
int acquireOffset; |
|
2 | 335 |
} |
336 |
||
30904 | 337 |
final class HandshakeFragment { |
338 |
private LinkedList<RecordMemo> handshakeMemos = new LinkedList<>(); |
|
339 |
||
340 |
void queueUpFragment(byte[] source, |
|
341 |
int offset, int length) throws IOException { |
|
342 |
HandshakeMemo memo = new HandshakeMemo(); |
|
343 |
||
50768 | 344 |
memo.contentType = ContentType.HANDSHAKE.id; |
30904 | 345 |
memo.majorVersion = protocolVersion.major; // kick start version? |
346 |
memo.minorVersion = protocolVersion.minor; |
|
347 |
memo.encodeCipher = writeCipher; |
|
348 |
||
349 |
memo.handshakeType = source[offset]; |
|
350 |
memo.acquireOffset = 0; |
|
351 |
memo.fragment = new byte[length - 4]; // 4: header size |
|
352 |
// 1: HandshakeType |
|
353 |
// 3: message length |
|
354 |
System.arraycopy(source, offset + 4, memo.fragment, 0, length - 4); |
|
355 |
||
356 |
handshakeMemos.add(memo); |
|
357 |
} |
|
358 |
||
359 |
void queueUpChangeCipherSpec() { |
|
360 |
RecordMemo memo = new RecordMemo(); |
|
361 |
||
50768 | 362 |
memo.contentType = ContentType.CHANGE_CIPHER_SPEC.id; |
30904 | 363 |
memo.majorVersion = protocolVersion.major; |
364 |
memo.minorVersion = protocolVersion.minor; |
|
365 |
memo.encodeCipher = writeCipher; |
|
366 |
||
367 |
memo.fragment = new byte[1]; |
|
368 |
memo.fragment[0] = 1; |
|
369 |
||
370 |
handshakeMemos.add(memo); |
|
371 |
} |
|
372 |
||
50768 | 373 |
void queueUpAlert(byte level, byte description) { |
374 |
RecordMemo memo = new RecordMemo(); |
|
375 |
||
376 |
memo.contentType = ContentType.ALERT.id; |
|
377 |
memo.majorVersion = protocolVersion.major; |
|
378 |
memo.minorVersion = protocolVersion.minor; |
|
379 |
memo.encodeCipher = writeCipher; |
|
380 |
||
381 |
memo.fragment = new byte[2]; |
|
382 |
memo.fragment[0] = level; |
|
383 |
memo.fragment[1] = description; |
|
384 |
||
385 |
handshakeMemos.add(memo); |
|
386 |
} |
|
387 |
||
30904 | 388 |
Ciphertext acquireCiphertext(ByteBuffer dstBuf) throws IOException { |
389 |
if (isEmpty()) { |
|
390 |
return null; |
|
391 |
} |
|
392 |
||
393 |
RecordMemo memo = handshakeMemos.getFirst(); |
|
394 |
HandshakeMemo hsMemo = null; |
|
50768 | 395 |
if (memo.contentType == ContentType.HANDSHAKE.id) { |
30904 | 396 |
hsMemo = (HandshakeMemo)memo; |
397 |
} |
|
398 |
||
399 |
// ChangeCipherSpec message is pretty small. Don't worry about |
|
400 |
// the fragmentation of ChangeCipherSpec record. |
|
401 |
int fragLen; |
|
402 |
if (packetSize > 0) { |
|
403 |
fragLen = Math.min(maxRecordSize, packetSize); |
|
404 |
fragLen = memo.encodeCipher.calculateFragmentSize( |
|
50768 | 405 |
fragLen, headerSize); |
30904 | 406 |
} else { |
407 |
fragLen = Record.maxDataSize; |
|
408 |
} |
|
409 |
||
410 |
if (fragmentSize > 0) { |
|
411 |
fragLen = Math.min(fragLen, fragmentSize); |
|
412 |
} |
|
413 |
||
414 |
int dstPos = dstBuf.position(); |
|
415 |
int dstLim = dstBuf.limit(); |
|
416 |
int dstContent = dstPos + headerSize + |
|
417 |
memo.encodeCipher.getExplicitNonceSize(); |
|
418 |
dstBuf.position(dstContent); |
|
419 |
||
420 |
if (hsMemo != null) { |
|
421 |
int remainingFragLen = fragLen; |
|
422 |
while ((remainingFragLen > 0) && !handshakeMemos.isEmpty()) { |
|
423 |
int memoFragLen = hsMemo.fragment.length; |
|
424 |
if (hsMemo.acquireOffset == 0) { |
|
425 |
// Don't fragment handshake message header |
|
426 |
if (remainingFragLen <= 4) { |
|
427 |
break; |
|
428 |
} |
|
429 |
||
430 |
dstBuf.put(hsMemo.handshakeType); |
|
431 |
dstBuf.put((byte)((memoFragLen >> 16) & 0xFF)); |
|
432 |
dstBuf.put((byte)((memoFragLen >> 8) & 0xFF)); |
|
433 |
dstBuf.put((byte)(memoFragLen & 0xFF)); |
|
434 |
||
435 |
remainingFragLen -= 4; |
|
436 |
} // Otherwise, handshake message is fragmented. |
|
437 |
||
438 |
int chipLen = Math.min(remainingFragLen, |
|
439 |
(memoFragLen - hsMemo.acquireOffset)); |
|
440 |
dstBuf.put(hsMemo.fragment, hsMemo.acquireOffset, chipLen); |
|
441 |
||
442 |
hsMemo.acquireOffset += chipLen; |
|
443 |
if (hsMemo.acquireOffset == memoFragLen) { |
|
444 |
handshakeMemos.removeFirst(); |
|
445 |
||
446 |
// still have space for more records? |
|
447 |
if ((remainingFragLen > chipLen) && |
|
448 |
!handshakeMemos.isEmpty()) { |
|
449 |
||
450 |
// look for the next buffered record fragment |
|
50768 | 451 |
RecordMemo rm = handshakeMemos.getFirst(); |
452 |
if (rm.contentType == ContentType.HANDSHAKE.id && |
|
453 |
rm.encodeCipher == hsMemo.encodeCipher) { |
|
454 |
hsMemo = (HandshakeMemo)rm; |
|
30904 | 455 |
} else { |
50768 | 456 |
// not of the flight, break the loop |
30904 | 457 |
break; |
458 |
} |
|
459 |
} |
|
460 |
} |
|
461 |
||
462 |
remainingFragLen -= chipLen; |
|
463 |
} |
|
464 |
} else { |
|
465 |
fragLen = Math.min(fragLen, memo.fragment.length); |
|
466 |
dstBuf.put(memo.fragment, 0, fragLen); |
|
467 |
||
468 |
handshakeMemos.removeFirst(); |
|
469 |
} |
|
470 |
||
471 |
dstBuf.limit(dstBuf.position()); |
|
472 |
dstBuf.position(dstContent); |
|
473 |
||
50768 | 474 |
if (SSLLogger.isOn && SSLLogger.isOn("record")) { |
475 |
SSLLogger.fine( |
|
476 |
"WRITE: " + protocolVersion + " " + |
|
477 |
ContentType.nameOf(memo.contentType) + |
|
30904 | 478 |
", length = " + dstBuf.remaining()); |
479 |
} |
|
480 |
||
481 |
// Encrypt the fragment and wrap up a record. |
|
50768 | 482 |
long recordSN = encrypt( |
483 |
memo.encodeCipher, |
|
30904 | 484 |
memo.contentType, dstBuf, |
485 |
dstPos, dstLim, headerSize, |
|
486 |
ProtocolVersion.valueOf(memo.majorVersion, |
|
50768 | 487 |
memo.minorVersion)); |
30904 | 488 |
|
50768 | 489 |
if (SSLLogger.isOn && SSLLogger.isOn("packet")) { |
30904 | 490 |
ByteBuffer temporary = dstBuf.duplicate(); |
491 |
temporary.limit(temporary.position()); |
|
492 |
temporary.position(dstPos); |
|
50768 | 493 |
SSLLogger.fine("Raw write", temporary); |
30904 | 494 |
} |
495 |
||
496 |
// remain the limit unchanged |
|
497 |
dstBuf.limit(dstLim); |
|
498 |
||
499 |
// Reset the fragmentation offset. |
|
500 |
if (hsMemo != null) { |
|
50768 | 501 |
return new Ciphertext(hsMemo.contentType, |
502 |
hsMemo.handshakeType, recordSN); |
|
30904 | 503 |
} else { |
50768 | 504 |
if (isCloseWaiting && |
505 |
memo.contentType == ContentType.ALERT.id) { |
|
506 |
close(); |
|
507 |
} |
|
508 |
||
509 |
return new Ciphertext(memo.contentType, |
|
510 |
SSLHandshake.NOT_APPLICABLE.id, recordSN); |
|
30904 | 511 |
} |
512 |
} |
|
513 |
||
514 |
boolean isEmpty() { |
|
515 |
return handshakeMemos.isEmpty(); |
|
516 |
} |
|
50768 | 517 |
|
518 |
boolean hasAlert() { |
|
519 |
for (RecordMemo memo : handshakeMemos) { |
|
520 |
if (memo.contentType == ContentType.ALERT.id) { |
|
521 |
return true; |
|
522 |
} |
|
523 |
} |
|
524 |
||
525 |
return false; |
|
526 |
} |
|
2 | 527 |
} |
528 |
||
529 |
/* |
|
30904 | 530 |
* Need to split the payload except the following cases: |
531 |
* |
|
532 |
* 1. protocol version is TLS 1.1 or later; |
|
533 |
* 2. bulk cipher does not use CBC mode, including null bulk cipher suites. |
|
534 |
* 3. the payload is the first application record of a freshly |
|
535 |
* negotiated TLS session. |
|
536 |
* 4. the CBC protection is disabled; |
|
537 |
* |
|
538 |
* By default, we counter chosen plaintext issues on CBC mode |
|
539 |
* ciphersuites in SSLv3/TLS1.0 by sending one byte of application |
|
540 |
* data in the first record of every payload, and the rest in |
|
541 |
* subsequent record(s). Note that the issues have been solved in |
|
542 |
* TLS 1.1 or later. |
|
543 |
* |
|
544 |
* It is not necessary to split the very first application record of |
|
545 |
* a freshly negotiated TLS session, as there is no previous |
|
546 |
* application data to guess. To improve compatibility, we will not |
|
547 |
* split such records. |
|
548 |
* |
|
549 |
* This avoids issues in the outbound direction. For a full fix, |
|
550 |
* the peer must have similar protections. |
|
2 | 551 |
*/ |
30904 | 552 |
boolean needToSplitPayload() { |
553 |
return (!protocolVersion.useTLS11PlusSpec()) && |
|
554 |
writeCipher.isCBCMode() && !isFirstAppOutputRecord && |
|
555 |
Record.enableCBCProtection; |
|
2 | 556 |
} |
557 |
} |