Select one of the symbols to view example projects that use it.
 
Outline
...
...
...
...
#define NX_SECURE_SOURCE_CODE
#include "nx_secure_dtls.h"
...
Files
loading (1/7)...
SourceVuSTM32 Libraries and Samplesnetxduonx_secure/src/nx_secure_dtls_send_helloverifyrequest.c
 
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/**************************************************************************/ /* */ /* Copyright (c) Microsoft Corporation. All rights reserved. */ /* */ /* This software is licensed under the Microsoft Software License */ /* Terms for Microsoft Azure RTOS. Full text of the license can be */ /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ /* and in the root directory of this software. */ /* */... /**************************************************************************/ ... /**************************************************************************/ /**************************************************************************/ /** */ /** NetX Secure Component */ /** */ /** Datagram Transport Layer Security (DTLS) */ /** */... /**************************************************************************/ /**************************************************************************/ #define NX_SECURE_SOURCE_CODE #include "nx_secure_dtls.h" #ifdef NX_SECURE_ENABLE_DTLS... /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* _nx_secure_dtls_send_helloverifyrequest PORTABLE C */ /* 6.1 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ /* */ /* DESCRIPTION */ /* */ /* This function populates an NX_PACKET with a HelloVerifyRequest */ /* message. */ /* */ /* INPUT */ /* */ /* dtls_session DTLS control block */ /* send_packet Packet used to send message */ /* */ /* OUTPUT */ /* */ /* status Completion status */ /* */ /* CALLS */ /* */ /* None */ /* */ /* CALLED BY */ /* */ /* _nx_secure_dtls_server_handshake DTLS server state machine */ /* */ /* RELEASE HISTORY */ /* */ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* verified memcpy use cases, */ /* resulting in version 6.1 */ /* */... /**************************************************************************/ UINT _nx_secure_dtls_send_helloverifyrequest(NX_SECURE_DTLS_SESSION *dtls_session, NX_PACKET *send_packet) { UINT length; UINT i; UINT random_value; UCHAR *packet_buffer; USHORT protocol_version; /* Parse the HelloVerifyRequest message. * Structure: * | 2 | 1 | <Cookie Length> | * | DTLS version | Cookie length | Server Cookie data | *//* ... */ if (((ULONG)(send_packet -> nx_packet_data_end) - (ULONG)(send_packet -> nx_packet_append_ptr)) < (3u + dtls_session -> nx_secure_dtls_cookie_length)) { /* Packet buffer is too small to hold random and ID. */ return(NX_SECURE_TLS_PACKET_BUFFER_TOO_SMALL); }if (((ULONG)(send_packet -> nx_packet_data_end) - (ULONG)(send_packet -> nx_packet_append_ptr)) < (3u + dtls_session -> nx_secure_dtls_cookie_length)) { ... } /* Use our length as an index into the buffer. */ length = 0; packet_buffer = send_packet -> nx_packet_append_ptr; /* First two bytes of the HelloVerifyRequest following the header are the (D)TLS major and minor version numbers. The version should be DTLS version 1.0 regardless of the version of TLS that is expected to be negotiated.*//* ... */ protocol_version = NX_SECURE_DTLS_VERSION_1_0; packet_buffer[length] = (UCHAR)((protocol_version & 0xFF00) >> 8); packet_buffer[length + 1] = (UCHAR)(protocol_version & 0x00FF); length += 2; /* Set the cookie length. */ dtls_session -> nx_secure_dtls_cookie_length = 20; packet_buffer[length] = (UCHAR)(dtls_session -> nx_secure_dtls_cookie_length); length += 1; /* Generate the cookie. */ for (i = 0; i < dtls_session -> nx_secure_dtls_cookie_length; i += (UINT)sizeof(random_value)) { random_value = (UINT)NX_RAND(); NX_CHANGE_ULONG_ENDIAN(random_value); NX_SECURE_MEMCPY(&dtls_session -> nx_secure_dtls_cookie[i], (UCHAR *)&random_value, sizeof(random_value)); /* Use case of memcpy is verified. */ }for (i = 0; i < dtls_session -> nx_secure_dtls_cookie_length; i += (UINT)sizeof(random_value)) { ... } if (dtls_session -> nx_secure_dtls_cookie_length > sizeof(dtls_session -> nx_secure_dtls_cookie)) { /* Packet buffer is too small to hold cookie. */ return(NX_SECURE_TLS_PACKET_BUFFER_TOO_SMALL); }if (dtls_session -> nx_secure_dtls_cookie_length > sizeof(dtls_session -> nx_secure_dtls_cookie)) { ... } /* Copy the cookie into the packet. */ NX_SECURE_MEMCPY(&packet_buffer[length], dtls_session -> nx_secure_dtls_cookie, dtls_session -> nx_secure_dtls_cookie_length); /* Use case of memcpy is verified. */ length += dtls_session -> nx_secure_dtls_cookie_length; /* Save off and return the number of bytes we wrote and need to send. */ send_packet -> nx_packet_append_ptr = send_packet -> nx_packet_append_ptr + length; send_packet -> nx_packet_length = send_packet -> nx_packet_length + length; return(NX_SECURE_TLS_SUCCESS); }_nx_secure_dtls_send_helloverifyrequest (NX_SECURE_DTLS_SESSION *dtls_session, NX_PACKET *send_packet) { ... } /* ... */#endif /* NX_SECURE_ENABLE_DTLS */
Details
Show:
from
Types: Columns:
This file uses the notable symbols shown below. Click anywhere in the file to view more details.