forked from wolfSSL/wolfssl
Merge pull request #3671 from julek-wolfssl/dtls-scr-2
DTLS secure renegotiation fixes
This commit is contained in:
@ -6559,6 +6559,7 @@ void SSL_ResourceFree(WOLFSSL* ssl)
|
|||||||
/* Free any handshake resources no longer needed */
|
/* Free any handshake resources no longer needed */
|
||||||
void FreeHandshakeResources(WOLFSSL* ssl)
|
void FreeHandshakeResources(WOLFSSL* ssl)
|
||||||
{
|
{
|
||||||
|
WOLFSSL_ENTER("FreeHandshakeResources");
|
||||||
|
|
||||||
#ifdef WOLFSSL_DTLS
|
#ifdef WOLFSSL_DTLS
|
||||||
/* DTLS_POOL */
|
/* DTLS_POOL */
|
||||||
@ -6929,6 +6930,7 @@ void WriteSEQ(WOLFSSL* ssl, int verifyOrder, byte* out)
|
|||||||
DtlsMsg* DtlsMsgNew(word32 sz, void* heap)
|
DtlsMsg* DtlsMsgNew(word32 sz, void* heap)
|
||||||
{
|
{
|
||||||
DtlsMsg* msg;
|
DtlsMsg* msg;
|
||||||
|
WOLFSSL_ENTER("DtlsMsgNew()");
|
||||||
|
|
||||||
(void)heap;
|
(void)heap;
|
||||||
msg = (DtlsMsg*)XMALLOC(sizeof(DtlsMsg), heap, DYNAMIC_TYPE_DTLS_MSG);
|
msg = (DtlsMsg*)XMALLOC(sizeof(DtlsMsg), heap, DYNAMIC_TYPE_DTLS_MSG);
|
||||||
@ -6954,6 +6956,7 @@ DtlsMsg* DtlsMsgNew(word32 sz, void* heap)
|
|||||||
void DtlsMsgDelete(DtlsMsg* item, void* heap)
|
void DtlsMsgDelete(DtlsMsg* item, void* heap)
|
||||||
{
|
{
|
||||||
(void)heap;
|
(void)heap;
|
||||||
|
WOLFSSL_ENTER("DtlsMsgDelete()");
|
||||||
|
|
||||||
if (item != NULL) {
|
if (item != NULL) {
|
||||||
DtlsFrag* cur = item->fragList;
|
DtlsFrag* cur = item->fragList;
|
||||||
@ -6972,6 +6975,7 @@ void DtlsMsgDelete(DtlsMsg* item, void* heap)
|
|||||||
void DtlsMsgListDelete(DtlsMsg* head, void* heap)
|
void DtlsMsgListDelete(DtlsMsg* head, void* heap)
|
||||||
{
|
{
|
||||||
DtlsMsg* next;
|
DtlsMsg* next;
|
||||||
|
WOLFSSL_ENTER("DtlsMsgListDelete()");
|
||||||
while (head) {
|
while (head) {
|
||||||
next = head->next;
|
next = head->next;
|
||||||
DtlsMsgDelete(head, heap);
|
DtlsMsgDelete(head, heap);
|
||||||
@ -6986,6 +6990,7 @@ void DtlsTxMsgListClean(WOLFSSL* ssl)
|
|||||||
{
|
{
|
||||||
DtlsMsg* head = ssl->dtls_tx_msg_list;
|
DtlsMsg* head = ssl->dtls_tx_msg_list;
|
||||||
DtlsMsg* next;
|
DtlsMsg* next;
|
||||||
|
WOLFSSL_ENTER("DtlsTxMsgListClean()");
|
||||||
while (head) {
|
while (head) {
|
||||||
next = head->next;
|
next = head->next;
|
||||||
if (VerifyForTxDtlsMsgDelete(ssl, head))
|
if (VerifyForTxDtlsMsgDelete(ssl, head))
|
||||||
@ -7009,6 +7014,8 @@ static DtlsFrag* CreateFragment(word32* begin, word32 end, const byte* data,
|
|||||||
DtlsFrag* newFrag;
|
DtlsFrag* newFrag;
|
||||||
word32 added = end - *begin + 1;
|
word32 added = end - *begin + 1;
|
||||||
|
|
||||||
|
WOLFSSL_ENTER("CreateFragment()");
|
||||||
|
|
||||||
(void)heap;
|
(void)heap;
|
||||||
newFrag = (DtlsFrag*)XMALLOC(sizeof(DtlsFrag), heap,
|
newFrag = (DtlsFrag*)XMALLOC(sizeof(DtlsFrag), heap,
|
||||||
DYNAMIC_TYPE_DTLS_FRAG);
|
DYNAMIC_TYPE_DTLS_FRAG);
|
||||||
@ -7029,6 +7036,7 @@ static DtlsFrag* CreateFragment(word32* begin, word32 end, const byte* data,
|
|||||||
int DtlsMsgSet(DtlsMsg* msg, word32 seq, word16 epoch, const byte* data, byte type,
|
int DtlsMsgSet(DtlsMsg* msg, word32 seq, word16 epoch, const byte* data, byte type,
|
||||||
word32 fragOffset, word32 fragSz, void* heap)
|
word32 fragOffset, word32 fragSz, void* heap)
|
||||||
{
|
{
|
||||||
|
WOLFSSL_ENTER("DtlsMsgSet()");
|
||||||
if (msg != NULL && data != NULL && msg->fragSz <= msg->sz &&
|
if (msg != NULL && data != NULL && msg->fragSz <= msg->sz &&
|
||||||
(fragOffset + fragSz) <= msg->sz) {
|
(fragOffset + fragSz) <= msg->sz) {
|
||||||
DtlsFrag* cur = msg->fragList;
|
DtlsFrag* cur = msg->fragList;
|
||||||
@ -7130,6 +7138,7 @@ int DtlsMsgSet(DtlsMsg* msg, word32 seq, word16 epoch, const byte* data, byte ty
|
|||||||
|
|
||||||
DtlsMsg* DtlsMsgFind(DtlsMsg* head, word32 epoch, word32 seq)
|
DtlsMsg* DtlsMsgFind(DtlsMsg* head, word32 epoch, word32 seq)
|
||||||
{
|
{
|
||||||
|
WOLFSSL_ENTER("DtlsMsgFind()");
|
||||||
while (head != NULL && !(head->epoch == epoch && head->seq == seq)) {
|
while (head != NULL && !(head->epoch == epoch && head->seq == seq)) {
|
||||||
head = head->next;
|
head = head->next;
|
||||||
}
|
}
|
||||||
@ -7158,6 +7167,7 @@ void DtlsMsgStore(WOLFSSL* ssl, word32 epoch, word32 seq, const byte* data,
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
DtlsMsg* head = ssl->dtls_rx_msg_list;
|
DtlsMsg* head = ssl->dtls_rx_msg_list;
|
||||||
|
WOLFSSL_ENTER("DtlsMsgStore()");
|
||||||
|
|
||||||
if (head != NULL) {
|
if (head != NULL) {
|
||||||
DtlsMsg* cur = DtlsMsgFind(head, epoch, seq);
|
DtlsMsg* cur = DtlsMsgFind(head, epoch, seq);
|
||||||
@ -7199,6 +7209,7 @@ void DtlsMsgStore(WOLFSSL* ssl, word32 epoch, word32 seq, const byte* data,
|
|||||||
/* DtlsMsgInsert() is an in-order insert. */
|
/* DtlsMsgInsert() is an in-order insert. */
|
||||||
DtlsMsg* DtlsMsgInsert(DtlsMsg* head, DtlsMsg* item)
|
DtlsMsg* DtlsMsgInsert(DtlsMsg* head, DtlsMsg* item)
|
||||||
{
|
{
|
||||||
|
WOLFSSL_ENTER("DtlsMsgInsert()");
|
||||||
if (head == NULL || (item->epoch <= head->epoch &&
|
if (head == NULL || (item->epoch <= head->epoch &&
|
||||||
item->seq < head->seq)) {
|
item->seq < head->seq)) {
|
||||||
item->next = head;
|
item->next = head;
|
||||||
@ -7279,6 +7290,7 @@ int DtlsMsgPoolSave(WOLFSSL* ssl, const byte* data, word32 dataSz,
|
|||||||
int DtlsMsgPoolTimeout(WOLFSSL* ssl)
|
int DtlsMsgPoolTimeout(WOLFSSL* ssl)
|
||||||
{
|
{
|
||||||
int result = -1;
|
int result = -1;
|
||||||
|
WOLFSSL_ENTER("DtlsMsgPoolTimeout()");
|
||||||
if (ssl->dtls_timeout < ssl->dtls_timeout_max) {
|
if (ssl->dtls_timeout < ssl->dtls_timeout_max) {
|
||||||
ssl->dtls_timeout *= DTLS_TIMEOUT_MULTIPLIER;
|
ssl->dtls_timeout *= DTLS_TIMEOUT_MULTIPLIER;
|
||||||
result = 0;
|
result = 0;
|
||||||
@ -7316,7 +7328,7 @@ int VerifyForDtlsMsgPoolSend(WOLFSSL* ssl, byte type, word32 fragOffset)
|
|||||||
((ssl->options.verifyPeer) && (type == certificate)) ||
|
((ssl->options.verifyPeer) && (type == certificate)) ||
|
||||||
((!ssl->options.verifyPeer) && (type == client_key_exchange)))) ||
|
((!ssl->options.verifyPeer) && (type == client_key_exchange)))) ||
|
||||||
((ssl->options.side == WOLFSSL_CLIENT_END) &&
|
((ssl->options.side == WOLFSSL_CLIENT_END) &&
|
||||||
(type == server_hello))));
|
(type == hello_request || type == server_hello))));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -7326,6 +7338,7 @@ int VerifyForDtlsMsgPoolSend(WOLFSSL* ssl, byte type, word32 fragOffset)
|
|||||||
*/
|
*/
|
||||||
int VerifyForTxDtlsMsgDelete(WOLFSSL* ssl, DtlsMsg* item)
|
int VerifyForTxDtlsMsgDelete(WOLFSSL* ssl, DtlsMsg* item)
|
||||||
{
|
{
|
||||||
|
WOLFSSL_ENTER("VerifyForTxDtlsMsgDelete()");
|
||||||
if (item->epoch < ssl->keys.dtls_epoch - 1)
|
if (item->epoch < ssl->keys.dtls_epoch - 1)
|
||||||
/* Messages not from current or previous epoch can be deleted */
|
/* Messages not from current or previous epoch can be deleted */
|
||||||
return 1;
|
return 1;
|
||||||
@ -15882,8 +15895,21 @@ int ProcessReply(WOLFSSL* ssl)
|
|||||||
WOLFSSL_MSG("got app DATA");
|
WOLFSSL_MSG("got app DATA");
|
||||||
#ifdef WOLFSSL_DTLS
|
#ifdef WOLFSSL_DTLS
|
||||||
if (ssl->options.dtls && ssl->options.dtlsHsRetain) {
|
if (ssl->options.dtls && ssl->options.dtlsHsRetain) {
|
||||||
|
#ifdef HAVE_SECURE_RENEGOTIATION
|
||||||
|
/*
|
||||||
|
* Only free HS resources when not in the process of a
|
||||||
|
* secure renegotiation and we have received APP DATA
|
||||||
|
* from the current epoch
|
||||||
|
*/
|
||||||
|
if (!IsSCR(ssl) && (DtlsUseSCRKeys(ssl)
|
||||||
|
|| !DtlsSCRKeysSet(ssl))) {
|
||||||
|
FreeHandshakeResources(ssl);
|
||||||
|
ssl->options.dtlsHsRetain = 0;
|
||||||
|
}
|
||||||
|
#else
|
||||||
FreeHandshakeResources(ssl);
|
FreeHandshakeResources(ssl);
|
||||||
ssl->options.dtlsHsRetain = 0;
|
ssl->options.dtlsHsRetain = 0;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef WOLFSSL_TLS13
|
#ifdef WOLFSSL_TLS13
|
||||||
|
@ -354,6 +354,7 @@ int EmbedReceiveFrom(WOLFSSL *ssl, char *buf, int sz, void *ctx)
|
|||||||
else if(IsSCR(ssl)) {
|
else if(IsSCR(ssl)) {
|
||||||
if (ssl->dtls_start_timeout &&
|
if (ssl->dtls_start_timeout &&
|
||||||
LowResTimer() - ssl->dtls_start_timeout > (word32)dtls_timeout) {
|
LowResTimer() - ssl->dtls_start_timeout > (word32)dtls_timeout) {
|
||||||
|
ssl->dtls_start_timeout = 0;
|
||||||
return WOLFSSL_CBIO_ERR_TIMEOUT;
|
return WOLFSSL_CBIO_ERR_TIMEOUT;
|
||||||
}
|
}
|
||||||
else if (!ssl->dtls_start_timeout) {
|
else if (!ssl->dtls_start_timeout) {
|
||||||
|
Reference in New Issue
Block a user