1017 * Note that many handshake messages can come in one record (and often
1018 * do, to reduce network resource utilization), and one message can also
1019 * require multiple records (e.g. very large Certificate messages).
1020 */
1021 void processLoop() throws IOException {
1022
1023 // need to read off 4 bytes at least to get the handshake
1024 // message type and length.
1025 while (input.available() >= 4) {
1026 byte messageType;
1027 int messageLen;
1028
1029 /*
1030 * See if we can read the handshake message header, and
1031 * then the entire handshake message. If not, wait till
1032 * we can read and process an entire message.
1033 */
1034 input.mark(4);
1035
1036 messageType = (byte)input.getInt8();
1037 messageLen = input.getInt24();
1038
1039 if (input.available() < messageLen) {
1040 input.reset();
1041 return;
1042 }
1043
1044 // Set the flags in the message receiving side.
1045 if (messageType == HandshakeMessage.ht_client_hello) {
1046 clientHelloDelivered = true;
1047 } else if (messageType == HandshakeMessage.ht_hello_request) {
1048 serverHelloRequested = true;
1049 }
1050
1051 /*
1052 * Process the message. We require
1053 * that processMessage() consumes the entire message. In
1054 * lieu of explicit error checks (how?!) we assume that the
1055 * data will look like garbage on encoding/processing errors,
1056 * and that other protocol code will detect such errors.
|
1017 * Note that many handshake messages can come in one record (and often
1018 * do, to reduce network resource utilization), and one message can also
1019 * require multiple records (e.g. very large Certificate messages).
1020 */
1021 void processLoop() throws IOException {
1022
1023 // need to read off 4 bytes at least to get the handshake
1024 // message type and length.
1025 while (input.available() >= 4) {
1026 byte messageType;
1027 int messageLen;
1028
1029 /*
1030 * See if we can read the handshake message header, and
1031 * then the entire handshake message. If not, wait till
1032 * we can read and process an entire message.
1033 */
1034 input.mark(4);
1035
1036 messageType = (byte)input.getInt8();
1037 if (HandshakeMessage.isUnsupported(messageType)) {
1038 throw new SSLProtocolException(
1039 "Received unsupported or unknown handshake message: " +
1040 messageType);
1041 }
1042
1043 messageLen = input.getInt24();
1044
1045 if (input.available() < messageLen) {
1046 input.reset();
1047 return;
1048 }
1049
1050 // Set the flags in the message receiving side.
1051 if (messageType == HandshakeMessage.ht_client_hello) {
1052 clientHelloDelivered = true;
1053 } else if (messageType == HandshakeMessage.ht_hello_request) {
1054 serverHelloRequested = true;
1055 }
1056
1057 /*
1058 * Process the message. We require
1059 * that processMessage() consumes the entire message. In
1060 * lieu of explicit error checks (how?!) we assume that the
1061 * data will look like garbage on encoding/processing errors,
1062 * and that other protocol code will detect such errors.
|