< prev index next >

src/share/classes/sun/security/ssl/SSLSocketInputRecord.java

Print this page
rev 14411 : 8228757: Fail fast if the handshake type is unknown
Reviewed-by: jnimeh


 285                     (handshakeBuffer.remaining() != 0)) {
 286                 ByteBuffer bb = ByteBuffer.wrap(new byte[
 287                         handshakeBuffer.remaining() + fragment.remaining()]);
 288                 bb.put(handshakeBuffer);
 289                 bb.put(fragment);
 290                 handshakeFrag = (ByteBuffer)bb.rewind();
 291                 handshakeBuffer = null;
 292             }
 293 
 294             ArrayList<Plaintext> plaintexts = new ArrayList<>(5);
 295             while (handshakeFrag.hasRemaining()) {
 296                 int remaining = handshakeFrag.remaining();
 297                 if (remaining < handshakeHeaderSize) {
 298                     handshakeBuffer = ByteBuffer.wrap(new byte[remaining]);
 299                     handshakeBuffer.put(handshakeFrag);
 300                     handshakeBuffer.rewind();
 301                     break;
 302                 }
 303 
 304                 handshakeFrag.mark();
 305                 // skip the first byte: handshake type

 306                 byte handshakeType = handshakeFrag.get();






 307                 int handshakeBodyLen = Record.getInt24(handshakeFrag);
 308                 if (handshakeBodyLen > SSLConfiguration.maxHandshakeMessageSize) {
 309                     throw new SSLProtocolException(
 310                             "The size of the handshake message ("
 311                             + handshakeBodyLen
 312                             + ") exceeds the maximum allowed size ("
 313                             + SSLConfiguration.maxHandshakeMessageSize
 314                             + ")");
 315                 }
 316 
 317                 handshakeFrag.reset();
 318                 int handshakeMessageLen =
 319                         handshakeHeaderSize + handshakeBodyLen;
 320                 if (remaining < handshakeMessageLen) {
 321                     handshakeBuffer = ByteBuffer.wrap(new byte[remaining]);
 322                     handshakeBuffer.put(handshakeFrag);
 323                     handshakeBuffer.rewind();
 324                     break;
 325                 } if (remaining == handshakeMessageLen) {
 326                     if (handshakeHash.isHashable(handshakeType)) {




 285                     (handshakeBuffer.remaining() != 0)) {
 286                 ByteBuffer bb = ByteBuffer.wrap(new byte[
 287                         handshakeBuffer.remaining() + fragment.remaining()]);
 288                 bb.put(handshakeBuffer);
 289                 bb.put(fragment);
 290                 handshakeFrag = (ByteBuffer)bb.rewind();
 291                 handshakeBuffer = null;
 292             }
 293 
 294             ArrayList<Plaintext> plaintexts = new ArrayList<>(5);
 295             while (handshakeFrag.hasRemaining()) {
 296                 int remaining = handshakeFrag.remaining();
 297                 if (remaining < handshakeHeaderSize) {
 298                     handshakeBuffer = ByteBuffer.wrap(new byte[remaining]);
 299                     handshakeBuffer.put(handshakeFrag);
 300                     handshakeBuffer.rewind();
 301                     break;
 302                 }
 303 
 304                 handshakeFrag.mark();
 305 
 306                 // Fail fast for unknown handshake message.
 307                 byte handshakeType = handshakeFrag.get();
 308                 if (!SSLHandshake.isKnown(handshakeType)) {
 309                     throw new SSLProtocolException(
 310                         "Unknown handshake type size, Handshake.msg_type = " +
 311                         (handshakeType & 0xFF));
 312                 }
 313 
 314                 int handshakeBodyLen = Record.getInt24(handshakeFrag);
 315                 if (handshakeBodyLen > SSLConfiguration.maxHandshakeMessageSize) {
 316                     throw new SSLProtocolException(
 317                             "The size of the handshake message ("
 318                             + handshakeBodyLen
 319                             + ") exceeds the maximum allowed size ("
 320                             + SSLConfiguration.maxHandshakeMessageSize
 321                             + ")");
 322                 }
 323 
 324                 handshakeFrag.reset();
 325                 int handshakeMessageLen =
 326                         handshakeHeaderSize + handshakeBodyLen;
 327                 if (remaining < handshakeMessageLen) {
 328                     handshakeBuffer = ByteBuffer.wrap(new byte[remaining]);
 329                     handshakeBuffer.put(handshakeFrag);
 330                     handshakeBuffer.rewind();
 331                     break;
 332                 } if (remaining == handshakeMessageLen) {
 333                     if (handshakeHash.isHashable(handshakeType)) {


< prev index next >