1
1
/*
2
- * Copyright (c) 2015, 2019 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2015, 2020 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
37
37
import java .util .TreeSet ;
38
38
import javax .crypto .BadPaddingException ;
39
39
import javax .net .ssl .SSLException ;
40
+ import javax .net .ssl .SSLProtocolException ;
40
41
import sun .security .ssl .SSLCipher .SSLReadCipher ;
41
42
42
43
/**
@@ -91,7 +92,7 @@ void finishHandshake() {
91
92
}
92
93
93
94
@ Override
94
- Plaintext acquirePlaintext () {
95
+ Plaintext acquirePlaintext () throws SSLProtocolException {
95
96
if (reassembler != null ) {
96
97
return reassembler .acquirePlaintext ();
97
98
}
@@ -114,7 +115,7 @@ Plaintext[] decode(ByteBuffer[] srcs, int srcsOffset,
114
115
}
115
116
}
116
117
117
- Plaintext [] decode (ByteBuffer packet ) {
118
+ Plaintext [] decode (ByteBuffer packet ) throws SSLProtocolException {
118
119
if (isClosed ) {
119
120
return null ;
120
121
}
@@ -346,7 +347,7 @@ private int bytesInCompletePacket(ByteBuffer packet) throws SSLException {
346
347
private static HandshakeFragment parseHandshakeMessage (
347
348
byte contentType , byte majorVersion , byte minorVersion ,
348
349
byte [] recordEnS , int recordEpoch , long recordSeq ,
349
- ByteBuffer plaintextFragment ) {
350
+ ByteBuffer plaintextFragment ) throws SSLProtocolException {
350
351
351
352
int remaining = plaintextFragment .remaining ();
352
353
if (remaining < handshakeHeaderSize ) {
@@ -376,6 +377,16 @@ private static HandshakeFragment parseHandshakeMessage(
376
377
((plaintextFragment .get () & 0xFF ) << 16 ) |
377
378
((plaintextFragment .get () & 0xFF ) << 8 ) |
378
379
(plaintextFragment .get () & 0xFF ); // pos: 1-3
380
+
381
+ if (messageLength > SSLConfiguration .maxHandshakeMessageSize ) {
382
+ throw new SSLProtocolException (
383
+ "The size of the handshake message ("
384
+ + messageLength
385
+ + ") exceeds the maximum allowed size ("
386
+ + SSLConfiguration .maxHandshakeMessageSize
387
+ + ")" );
388
+ }
389
+
379
390
int messageSeq =
380
391
((plaintextFragment .get () & 0xFF ) << 8 ) |
381
392
(plaintextFragment .get () & 0xFF ); // pos: 4/5
@@ -968,7 +979,7 @@ private boolean isEmpty() {
968
979
(needToCheckFlight && !flightIsReady ()));
969
980
}
970
981
971
- Plaintext acquirePlaintext () {
982
+ Plaintext acquirePlaintext () throws SSLProtocolException {
972
983
if (bufferedFragments .isEmpty ()) {
973
984
if (SSLLogger .isOn && SSLLogger .isOn ("verbose" )) {
974
985
SSLLogger .fine ("No received handshake messages" );
@@ -1080,7 +1091,7 @@ private void resetHandshakeFlight(HandshakeFlight prev) {
1080
1091
needToCheckFlight = false ;
1081
1092
}
1082
1093
1083
- private Plaintext acquireCachedMessage () {
1094
+ private Plaintext acquireCachedMessage () throws SSLProtocolException {
1084
1095
RecordFragment rFrag = bufferedFragments .first ();
1085
1096
if (readEpoch != rFrag .recordEpoch ) {
1086
1097
if (readEpoch > rFrag .recordEpoch ) {
0 commit comments