From 9a90a0c1135ca640315df8a26c7d7c32b907ebf4 Mon Sep 17 00:00:00 2001 From: toddouska Date: Tue, 16 Sep 2014 11:51:13 -0700 Subject: [PATCH] save secure r verify data --- cyassl/internal.h | 1 + src/internal.c | 30 +++++++++++++++++++++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/cyassl/internal.h b/cyassl/internal.h index 6ce74d9e8..f51063ff1 100644 --- a/cyassl/internal.h +++ b/cyassl/internal.h @@ -1884,6 +1884,7 @@ typedef struct DtlsMsg { byte server_verify_data[TLS_FINISHED_SZ]; /* previous handshake value */ byte secure_renegotation; /* is current connection using */ byte doing_secure_renegotation; /* are we doing it now flag */ + byte enabled; /* runtime allowed? */ } SecureR_State; #endif diff --git a/src/internal.c b/src/internal.c index c61216fe9..25586d9b7 100644 --- a/src/internal.c +++ b/src/internal.c @@ -1775,6 +1775,7 @@ int InitSSL(CYASSL* ssl, CYASSL_CTX* ctx) #ifdef HAVE_SECURE_RENEGOTIATION ssl->secureR_state.secure_renegotation = 0; ssl->secureR_state.doing_secure_renegotation = 0; + ssl->secureR_state.enabled = 0; #endif /* HAVE_SECURE_RENEGOTIATION */ /* all done with init, now can return errors, call other stuff */ @@ -4387,6 +4388,10 @@ int DoFinished(CYASSL* ssl, const byte* input, word32* inOutIdx, word32 size, if (finishedSz != size) return BUFFER_ERROR; + /* check against totalSz */ + if (*inOutIdx + size + ssl->keys.padSz > totalSz) + return BUFFER_E; + #ifdef CYASSL_CALLBACKS if (ssl->hsInfoOn) AddPacketName("Finished", &ssl->handShakeInfo); if (ssl->toInfoOn) AddLateName("Finished", &ssl->timeoutInfo); @@ -4399,9 +4404,17 @@ int DoFinished(CYASSL* ssl, const byte* input, word32* inOutIdx, word32 size, } } - /* increment beyond input + size should be checked against totalSz */ - if (*inOutIdx + size + ssl->keys.padSz > totalSz) - return INCOMPLETE_DATA; +#ifdef HAVE_SECURE_RENEGOTIATION + if (ssl->secureR_state.enabled) { + /* save peer's state */ + if (ssl->options.side == CYASSL_CLIENT_END) + XMEMCPY(ssl->secureR_state.server_verify_data, input + *inOutIdx, + TLS_FINISHED_SZ); + else + XMEMCPY(ssl->secureR_state.client_verify_data, input + *inOutIdx, + TLS_FINISHED_SZ); + } +#endif /* HAVE_SECURE_RENEGOTIATION */ /* force input exhaustion at ProcessReply consuming padSz */ *inOutIdx += size + ssl->keys.padSz; @@ -6719,6 +6732,17 @@ int SendFinished(CYASSL* ssl) ssl->options.side == CYASSL_CLIENT_END ? client : server); if (ret != 0) return ret; +#ifdef HAVE_SECURE_RENEGOTIATION + if (ssl->secureR_state.enabled) { + if (ssl->options.side == CYASSL_CLIENT_END) + XMEMCPY(ssl->secureR_state.client_verify_data, hashes, + TLS_FINISHED_SZ); + else + XMEMCPY(ssl->secureR_state.server_verify_data, hashes, + TLS_FINISHED_SZ); + } +#endif /* HAVE_SECURE_RENEGOTIATION */ + sendSz = BuildMessage(ssl, output, outputSz, input, headerSz + finishedSz, handshake); if (sendSz < 0)