private void ProcessHandshake()
{
bool read;
do
{
read = false;
/*
* We need the first 4 bytes, they contain type and length of
* the message.
*/
if (handshakeQueue.Available >= 4)
{
byte[] beginning = new byte[4];
handshakeQueue.Read(beginning, 0, 4, 0);
MemoryStream bis = new MemoryStream(beginning, false);
HandshakeType type = (HandshakeType)TlsUtilities.ReadUint8(bis);
int len = TlsUtilities.ReadUint24(bis);
/*
* Check if we have enough bytes in the buffer to read
* the full message.
*/
if (handshakeQueue.Available >= (len + 4))
{
/*
* Read the message.
*/
byte[] buf = new byte[len];
handshakeQueue.Read(buf, 0, len, 4);
handshakeQueue.RemoveData(len + 4);
/*
* RFC 2246 7.4.9. The value handshake_messages includes all
* handshake messages starting at client hello up to, but not
* including, this finished message. [..] Note: [Also,] Hello Request
* messages are omitted from handshake hashes.
*/
switch (type)
{
case HandshakeType.hello_request:
case HandshakeType.finished:
break;
default:
rs.UpdateHandshakeData(beginning, 0, 4);
rs.UpdateHandshakeData(buf, 0, len);
break;
}
/*
* Now, parse the message.
*/
ProcessHandshakeMessage(type, buf);
read = true;
}
}
}
while (read);
}