src/java.base/share/classes/sun/security/ssl/SSLEngineInputRecord.java
branchJDK-8145252-TLS13-branch
changeset 56694 aa54a1f8e426
parent 56542 56aaa6cb3693
child 56704 c3ee22c3a0f6
equal deleted inserted replaced
56693:64aa781522be 56694:aa54a1f8e426
    23  * questions.
    23  * questions.
    24  */
    24  */
    25 
    25 
    26 package sun.security.ssl;
    26 package sun.security.ssl;
    27 
    27 
    28 import java.io.*;
    28 import java.io.IOException;
    29 import java.nio.*;
    29 import java.nio.ByteBuffer;
    30 import java.security.GeneralSecurityException;
    30 import java.security.GeneralSecurityException;
    31 import java.util.ArrayList;
    31 import java.util.ArrayList;
    32 import javax.crypto.BadPaddingException;
    32 import javax.crypto.BadPaddingException;
    33 import javax.net.ssl.*;
    33 import javax.net.ssl.SSLException;
       
    34 import javax.net.ssl.SSLHandshakeException;
       
    35 import javax.net.ssl.SSLProtocolException;
    34 import sun.security.ssl.SSLCipher.SSLReadCipher;
    36 import sun.security.ssl.SSLCipher.SSLReadCipher;
    35 
    37 
    36 /**
    38 /**
    37  * {@code InputRecord} implementation for {@code SSLEngine}.
    39  * {@code InputRecord} implementation for {@code SSLEngine}.
    38  */
    40  */
    39 final class SSLEngineInputRecord extends InputRecord implements SSLRecord {
    41 final class SSLEngineInputRecord extends InputRecord implements SSLRecord {
    40     // used by handshake hash computation for handshake fragment
       
    41     private byte prevType = -1;
       
    42     private int hsMsgOff = 0;
       
    43     private int hsMsgLen = 0;
       
    44 
       
    45     private boolean formatVerified = false;     // SSLv2 ruled out?
    42     private boolean formatVerified = false;     // SSLv2 ruled out?
    46 
    43 
    47     // Cache for incomplete handshake messages.
    44     // Cache for incomplete handshake messages.
    48     private ByteBuffer handshakeBuffer = null;
    45     private ByteBuffer handshakeBuffer = null;
    49 
    46 
    82         int len = 0;
    79         int len = 0;
    83 
    80 
    84         /*
    81         /*
    85          * If we have already verified previous packets, we can
    82          * If we have already verified previous packets, we can
    86          * ignore the verifications steps, and jump right to the
    83          * ignore the verifications steps, and jump right to the
    87          * determination.  Otherwise, try one last hueristic to
    84          * determination.  Otherwise, try one last heuristic to
    88          * see if it's SSL/TLS.
    85          * see if it's SSL/TLS.
    89          */
    86          */
    90         if (formatVerified ||
    87         if (formatVerified ||
    91                 (byteZero == ContentType.HANDSHAKE.id) ||
    88                 (byteZero == ContentType.HANDSHAKE.id) ||
    92                 (byteZero == ContentType.ALERT.id)) {
    89                 (byteZero == ContentType.ALERT.id)) {
   231         }
   228         }
   232 
   229 
   233         //
   230         //
   234         // check for handshake fragment
   231         // check for handshake fragment
   235         //
   232         //
   236         if (contentType != ContentType.HANDSHAKE.id && hsMsgOff != hsMsgLen) {
   233         if (contentType != ContentType.HANDSHAKE.id &&
       
   234                 handshakeBuffer != null && handshakeBuffer.hasRemaining()) {
   237             throw new SSLProtocolException(
   235             throw new SSLProtocolException(
   238                     "Expected to get a handshake fragment");
   236                     "Expected to get a handshake fragment");
   239         }
   237         }
   240 
   238 
   241         //
   239         //