fixed the dtls handshake header handling

This commit is contained in:
John Safranek 2012-08-09 13:27:30 -07:00
parent 93c89ccc35
commit 11df1d25d4
2 changed files with 33 additions and 28 deletions

View File

@ -394,6 +394,8 @@ enum Misc {
DTLS_RECORD_HEADER_SZ = 13, /* normal + epoch(2) + seq_num(6) */
DTLS_HANDSHAKE_EXTRA = 8, /* diff from normal */
DTLS_RECORD_EXTRA = 8, /* diff from normal */
DTLS_HANDSHAKE_SEQ_SZ = 2, /* handshake header sequence number */
DTLS_HANDSHAKE_FRAG_SZ = 3, /* fragment offset and length are 24 bit */
FINISHED_LABEL_SZ = 15, /* TLS finished label size */
TLS_FINISHED_SZ = 12, /* TLS has a shorter size */

View File

@ -1562,6 +1562,7 @@ static int GetHandShakeHeader(CYASSL* ssl, const byte* input, word32* inOutIdx,
return 0;
}
#ifdef CYASSL_DTLS
static int GetDtlsHandShakeHeader(CYASSL* ssl, const byte* input,
word32* inOutIdx, byte *type, word32 *size,
@ -1574,13 +1575,16 @@ static int GetDtlsHandShakeHeader(CYASSL* ssl, const byte* input,
*inOutIdx += HANDSHAKE_HEADER_SZ + DTLS_HANDSHAKE_EXTRA;
*type = input[idx++];
c24to32(input, size);
c24to32(input + idx, size);
idx += BYTE3_LEN;
c24to32(input, fragOffset);
idx += BYTE3_LEN;
c24to32(input, fragSz);
idx += BYTE3_LEN;
/* skip the sequence number */
idx += DTLS_HANDSHAKE_SEQ_SZ;
c24to32(input + idx, fragOffset);
idx += DTLS_HANDSHAKE_FRAG_SZ;
c24to32(input + idx, fragSz);
idx += DTLS_HANDSHAKE_FRAG_SZ;
return 0;
}
@ -2205,6 +2209,28 @@ static int DoHandShakeMsgType(CYASSL* ssl, byte* input, word32* inOutIdx,
}
static int DoHandShakeMsg(CYASSL* ssl, byte* input, word32* inOutIdx,
word32 totalSz)
{
byte type;
word32 size;
int ret = 0;
CYASSL_ENTER("DoHandShakeMsg()");
if (GetHandShakeHeader(ssl, input, inOutIdx, &type, &size) != 0)
return PARSE_ERROR;
if (*inOutIdx + size > totalSz)
return INCOMPLETE_DATA;
ret = DoHandShakeMsgType(ssl, input, inOutIdx, type, size, totalSz);
CYASSL_LEAVE("DoHandShakeMsg()", ret);
return ret;
}
#ifdef CYASSL_DTLS
static int DoDtlsHandShakeMsg(CYASSL* ssl, byte* input, word32* inOutIdx,
word32 totalSz)
@ -2231,29 +2257,6 @@ static int DoDtlsHandShakeMsg(CYASSL* ssl, byte* input, word32* inOutIdx,
#endif
static int DoHandShakeMsg(CYASSL* ssl, byte* input, word32* inOutIdx,
word32 totalSz)
{
byte type;
word32 size;
word32 fragOffset, fragSz;
int ret = 0;
CYASSL_ENTER("DoHandShakeMsg()");
if (GetHandShakeHeader(ssl, input, inOutIdx, &type, &size) != 0)
return PARSE_ERROR;
if (*inOutIdx + size > totalSz)
return INCOMPLETE_DATA;
ret = DoHandShakeMsgType(ssl, input, inOutIdx, type, size, totalSz);
CYASSL_LEAVE("DoHandShakeMsg()", ret);
return ret;
}
static INLINE word32 GetSEQIncrement(CYASSL* ssl, int verify)
{
if (verify)