blob: 209041b6c93f2f64e23d7b30dc0fc7c79e78d1ba (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
/***************************************************************************
* Copyright (c) 2024 Microsoft Corporation
* Copyright (c) 2025-present Eclipse ThreadX Contributors
*
* This program and the accompanying materials are made available under the
* terms of the MIT License which is available at
* https://opensource.org/licenses/MIT.
*
* SPDX-License-Identifier: MIT
**************************************************************************/
/**************************************************************************/
/**************************************************************************/
/** */
/** NetX Secure Component */
/** */
/** Datagram Transport Layer Security (DTLS) */
/** */
/**************************************************************************/
/**************************************************************************/
#define NX_SECURE_SOURCE_CODE
#include "nx_secure_dtls.h"
#if !defined(NX_SECURE_TLS_CLIENT_DISABLED) && defined(NX_SECURE_ENABLE_DTLS)
/**************************************************************************/
/* */
/* FUNCTION RELEASE */
/* */
/* _nx_secure_dtls_process_helloverifyrequest PORTABLE C */
/* 6.1.10 */
/* AUTHOR */
/* */
/* Timothy Stapko, Microsoft Corporation */
/* */
/* DESCRIPTION */
/* */
/* This function processes an incoming HelloVerifyRequest message. */
/* */
/* INPUT */
/* */
/* dtls_session DTLS control block */
/* packet_buffer Pointer to message data */
/* message_length Length of message data (bytes)*/
/* */
/* OUTPUT */
/* */
/* status Completion status */
/* */
/* CALLS */
/* */
/* None */
/* */
/* CALLED BY */
/* */
/* _nx_secure_dtls_client_handshake DTLS client state machine */
/* */
/**************************************************************************/
UINT _nx_secure_dtls_process_helloverifyrequest(NX_SECURE_DTLS_SESSION *dtls_session,
UCHAR *packet_buffer, UINT message_length)
{
UINT length;
/* Parse the HelloVerifyRequest message.
* Structure:
* | 2 | 1 | <Cookie Length> |
* | DTLS version | Cookie length | Server Cookie data |
*/
/* Use our length as an index into the buffer. */
length = 0;
/* First two bytes of the server hello following the header are the TLS major and minor version numbers. */
length += 2;
/* Get the cookie length. */
dtls_session -> nx_secure_dtls_cookie_length = packet_buffer[length];
length += 1;
if (dtls_session -> nx_secure_dtls_cookie_length > NX_SECURE_DTLS_MAX_COOKIE_LENGTH)
{
dtls_session -> nx_secure_dtls_cookie_length = 0;
return(NX_SECURE_TLS_INCORRECT_MESSAGE_LENGTH);
}
if ((3u + dtls_session -> nx_secure_dtls_cookie_length) > message_length)
{
dtls_session -> nx_secure_dtls_cookie_length = 0;
return(NX_SECURE_TLS_INCORRECT_MESSAGE_LENGTH);
}
/* Save off the cookie pointer. */
dtls_session -> nx_secure_dtls_client_cookie_ptr = &packet_buffer[length];
/* Set our state to indicate we sucessfully parsed the HelloVerifyRequest. */
dtls_session -> nx_secure_dtls_tls_session.nx_secure_tls_client_state = NX_SECURE_TLS_CLIENT_STATE_HELLO_VERIFY;
return(NX_SECURE_TLS_SUCCESS);
}
#endif /* !defined(NX_SECURE_TLS_CLIENT_DISABLED) && defined(NX_SECURE_ENABLE_DTLS) */
|