blob: d31e0cba2c4c6a8ce1c1bfcd4a1e88859e09621a [file] [log] [blame]
Manuel Pégourié-Gonnardcb4137b2014-09-04 14:55:28 +02001/*
2 * UDP proxy: emulate an unreliable UDP connexion for DTLS testing
3 *
Manuel Pégourié-Gonnard6fb81872015-07-27 11:11:48 +02004 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
Bence Szépkúti4e9f7122020-06-05 13:02:18 +02005 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
6 *
7 * This file is provided under the Apache License 2.0, or the
8 * GNU General Public License v2.0 or later.
9 *
10 * **********
11 * Apache License 2.0:
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +020012 *
13 * Licensed under the Apache License, Version 2.0 (the "License"); you may
14 * not use this file except in compliance with the License.
15 * You may obtain a copy of the License at
16 *
17 * http://www.apache.org/licenses/LICENSE-2.0
18 *
19 * Unless required by applicable law or agreed to in writing, software
20 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
21 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 * See the License for the specific language governing permissions and
23 * limitations under the License.
Manuel Pégourié-Gonnardcb4137b2014-09-04 14:55:28 +020024 *
Bence Szépkúti4e9f7122020-06-05 13:02:18 +020025 * **********
26 *
27 * **********
28 * GNU General Public License v2.0 or later:
29 *
30 * This program is free software; you can redistribute it and/or modify
31 * it under the terms of the GNU General Public License as published by
32 * the Free Software Foundation; either version 2 of the License, or
33 * (at your option) any later version.
34 *
35 * This program is distributed in the hope that it will be useful,
36 * but WITHOUT ANY WARRANTY; without even the implied warranty of
37 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
38 * GNU General Public License for more details.
39 *
40 * You should have received a copy of the GNU General Public License along
41 * with this program; if not, write to the Free Software Foundation, Inc.,
42 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
43 *
44 * **********
45 *
Manuel Pégourié-Gonnarde4d48902015-03-06 13:40:52 +000046 * This file is part of mbed TLS (https://tls.mbed.org)
Manuel Pégourié-Gonnardcb4137b2014-09-04 14:55:28 +020047 */
48
Manuel Pégourié-Gonnard5db64322015-06-30 15:40:39 +020049/*
50 * Warning: this is an internal utility program we use for tests.
51 * It does break some abstractions from the NET layer, and is thus NOT an
52 * example of good general usage.
53 */
54
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020055#if !defined(MBEDTLS_CONFIG_FILE)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000056#include "mbedtls/config.h"
Manuel Pégourié-Gonnardcb4137b2014-09-04 14:55:28 +020057#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020058#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcb4137b2014-09-04 14:55:28 +020059#endif
60
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020061#if defined(MBEDTLS_PLATFORM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000062#include "mbedtls/platform.h"
Manuel Pégourié-Gonnardf2246782015-01-29 13:29:20 +000063#else
Simon Butcherd3138c32016-04-27 01:26:50 +010064#include <stdio.h>
65#include <stdlib.h>
66#include <time.h>
Andres Amaya Garcia01e3d212018-04-29 21:58:53 +010067#define mbedtls_time time
68#define mbedtls_time_t time_t
69#define mbedtls_printf printf
Krzysztof Stachowiaka0865222019-04-24 14:24:46 +020070#define mbedtls_exit exit
Andres Amaya Garcia2b0599b2018-04-30 22:42:33 +010071#define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS
Andres Amaya Garcia01e3d212018-04-29 21:58:53 +010072#define MBEDTLS_EXIT_FAILURE EXIT_FAILURE
73#endif /* MBEDTLS_PLATFORM_C */
Manuel Pégourié-Gonnardf2246782015-01-29 13:29:20 +000074
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020075#if !defined(MBEDTLS_NET_C)
Manuel Pégourié-Gonnardcb4137b2014-09-04 14:55:28 +020076int main( void )
77{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020078 mbedtls_printf( "MBEDTLS_NET_C not defined.\n" );
Krzysztof Stachowiaka0865222019-04-24 14:24:46 +020079 mbedtls_exit( 0 );
Manuel Pégourié-Gonnardcb4137b2014-09-04 14:55:28 +020080}
81#else
82
Andres AG788aa4a2016-09-14 14:32:09 +010083#include "mbedtls/net_sockets.h"
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000084#include "mbedtls/error.h"
85#include "mbedtls/ssl.h"
Manuel Pégourié-Gonnardcb4137b2014-09-04 14:55:28 +020086
Manuel Pégourié-Gonnardd901d172015-02-16 18:37:53 +000087#include <string.h>
Manuel Pégourié-Gonnardcb4137b2014-09-04 14:55:28 +020088
89/* For select() */
90#if (defined(_WIN32) || defined(_WIN32_WCE)) && !defined(EFIX64) && \
91 !defined(EFI32)
92#include <winsock2.h>
93#include <windows.h>
94#if defined(_MSC_VER)
95#if defined(_WIN32_WCE)
96#pragma comment( lib, "ws2.lib" )
97#else
98#pragma comment( lib, "ws2_32.lib" )
99#endif
100#endif /* _MSC_VER */
101#else /* ( _WIN32 || _WIN32_WCE ) && !EFIX64 && !EFI32 */
102#include <sys/time.h>
103#include <sys/types.h>
104#include <unistd.h>
105#endif /* ( _WIN32 || _WIN32_WCE ) && !EFIX64 && !EFI32 */
106
Manuel Pégourié-Gonnard7cf35182014-09-20 09:43:48 +0200107/* For gettimeofday() */
108#if !defined(_WIN32)
109#include <sys/time.h>
110#endif
111
Manuel Pégourié-Gonnardb46780e2014-09-23 12:17:30 +0200112#define MAX_MSG_SIZE 16384 + 2048 /* max record/datagram size */
Manuel Pégourié-Gonnardcb4137b2014-09-04 14:55:28 +0200113
114#define DFL_SERVER_ADDR "localhost"
Manuel Pégourié-Gonnardc0d74942015-06-23 12:30:57 +0200115#define DFL_SERVER_PORT "4433"
Manuel Pégourié-Gonnardcb4137b2014-09-04 14:55:28 +0200116#define DFL_LISTEN_ADDR "localhost"
Manuel Pégourié-Gonnardc0d74942015-06-23 12:30:57 +0200117#define DFL_LISTEN_PORT "5556"
Manuel Pégourié-Gonnardcb4137b2014-09-04 14:55:28 +0200118
Manuel Pégourié-Gonnardcb4137b2014-09-04 14:55:28 +0200119#define USAGE \
120 "\n usage: udp_proxy param=<>...\n" \
121 "\n acceptable parameters:\n" \
Manuel Pégourié-Gonnardd0fd1da2014-09-25 17:00:27 +0200122 " server_addr=%%s default: localhost\n" \
Manuel Pégourié-Gonnardcb4137b2014-09-04 14:55:28 +0200123 " server_port=%%d default: 4433\n" \
Manuel Pégourié-Gonnardd0fd1da2014-09-25 17:00:27 +0200124 " listen_addr=%%s default: localhost\n" \
Manuel Pégourié-Gonnardcb4137b2014-09-04 14:55:28 +0200125 " listen_port=%%d default: 4433\n" \
Manuel Pégourié-Gonnard2c41bd82014-09-06 08:14:47 +0200126 "\n" \
127 " duplicate=%%d default: 0 (no duplication)\n" \
Manuel Pégourié-Gonnard992e1362014-09-20 18:06:23 +0200128 " duplicate about 1:N packets randomly\n" \
Manuel Pégourié-Gonnard21398c32014-09-06 14:36:46 +0200129 " delay=%%d default: 0 (no delayed packets)\n" \
Manuel Pégourié-Gonnard992e1362014-09-20 18:06:23 +0200130 " delay about 1:N packets randomly\n" \
Manuel Pégourié-Gonnardd0fd1da2014-09-25 17:00:27 +0200131 " delay_ccs=0/1 default: 0 (don't delay ChangeCipherSpec)\n" \
Manuel Pégourié-Gonnard60fdd7e2014-09-06 14:49:52 +0200132 " drop=%%d default: 0 (no dropped packets)\n" \
Manuel Pégourié-Gonnard992e1362014-09-20 18:06:23 +0200133 " drop about 1:N packets randomly\n" \
Manuel Pégourié-Gonnardeb00bfd2014-09-08 11:11:42 +0200134 " mtu=%%d default: 0 (unlimited)\n" \
135 " drop packets larger than N bytes\n" \
Manuel Pégourié-Gonnardd0fd1da2014-09-25 17:00:27 +0200136 " bad_ad=0/1 default: 0 (don't add bad ApplicationData)\n" \
137 " protect_hvr=0/1 default: 0 (don't protect HelloVerifyRequest)\n" \
Manuel Pégourié-Gonnarda58b0462020-03-13 11:11:02 +0100138 " protect_len=%%d default: (don't protect packets of this size)\n" \
139 " inject_clihlo=0/1 default: 0 (don't inject fake ClientHello)\n" \
Manuel Pégourié-Gonnard992e1362014-09-20 18:06:23 +0200140 "\n" \
141 " seed=%%d default: (use current time)\n" \
Manuel Pégourié-Gonnardcb4137b2014-09-04 14:55:28 +0200142 "\n"
143
Manuel Pégourié-Gonnard44d5e632014-09-06 08:07:45 +0200144/*
145 * global options
146 */
147static struct options
Manuel Pégourié-Gonnardcb4137b2014-09-04 14:55:28 +0200148{
Manuel Pégourié-Gonnard44d5e632014-09-06 08:07:45 +0200149 const char *server_addr; /* address to forward packets to */
Manuel Pégourié-Gonnardc0d74942015-06-23 12:30:57 +0200150 const char *server_port; /* port to forward packets to */
Manuel Pégourié-Gonnard44d5e632014-09-06 08:07:45 +0200151 const char *listen_addr; /* address for accepting client connections */
Manuel Pégourié-Gonnardc0d74942015-06-23 12:30:57 +0200152 const char *listen_port; /* port for accepting client connections */
Manuel Pégourié-Gonnard2c41bd82014-09-06 08:14:47 +0200153
154 int duplicate; /* duplicate 1 in N packets (none if 0) */
Manuel Pégourié-Gonnard21398c32014-09-06 14:36:46 +0200155 int delay; /* delay 1 packet in N (none if 0) */
Manuel Pégourié-Gonnard81f2fe92014-09-08 10:44:57 +0200156 int delay_ccs; /* delay ChangeCipherSpec */
Manuel Pégourié-Gonnard60fdd7e2014-09-06 14:49:52 +0200157 int drop; /* drop 1 packet in N (none if 0) */
Manuel Pégourié-Gonnardeb00bfd2014-09-08 11:11:42 +0200158 int mtu; /* drop packets larger than this */
Manuel Pégourié-Gonnard6c18a392014-09-08 11:24:58 +0200159 int bad_ad; /* inject corrupted ApplicationData record */
Manuel Pégourié-Gonnardd0fd1da2014-09-25 17:00:27 +0200160 int protect_hvr; /* never drop or delay HelloVerifyRequest */
Manuel Pégourié-Gonnardba958b82014-10-09 16:13:44 +0200161 int protect_len; /* never drop/delay packet of the given size*/
Manuel Pégourié-Gonnarda58b0462020-03-13 11:11:02 +0100162 int inject_clihlo; /* inject fake ClientHello after handshake */
Manuel Pégourié-Gonnard992e1362014-09-20 18:06:23 +0200163 unsigned int seed; /* seed for "random" events */
Manuel Pégourié-Gonnard44d5e632014-09-06 08:07:45 +0200164} opt;
165
166static void exit_usage( const char *name, const char *value )
167{
168 if( value == NULL )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200169 mbedtls_printf( " unknown option or missing value: %s\n", name );
Manuel Pégourié-Gonnard44d5e632014-09-06 08:07:45 +0200170 else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200171 mbedtls_printf( " option %s: illegal value: %s\n", name, value );
Manuel Pégourié-Gonnard44d5e632014-09-06 08:07:45 +0200172
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200173 mbedtls_printf( USAGE );
Krzysztof Stachowiaka0865222019-04-24 14:24:46 +0200174 mbedtls_exit( 1 );
Manuel Pégourié-Gonnardcb4137b2014-09-04 14:55:28 +0200175}
176
177static void get_options( int argc, char *argv[] )
178{
179 int i;
180 char *p, *q;
181
182 opt.server_addr = DFL_SERVER_ADDR;
183 opt.server_port = DFL_SERVER_PORT;
184 opt.listen_addr = DFL_LISTEN_ADDR;
185 opt.listen_port = DFL_LISTEN_PORT;
Manuel Pégourié-Gonnard60fdd7e2014-09-06 14:49:52 +0200186 /* Other members default to 0 */
Manuel Pégourié-Gonnardcb4137b2014-09-04 14:55:28 +0200187
188 for( i = 1; i < argc; i++ )
189 {
190 p = argv[i];
191 if( ( q = strchr( p, '=' ) ) == NULL )
Manuel Pégourié-Gonnard44d5e632014-09-06 08:07:45 +0200192 exit_usage( p, NULL );
Manuel Pégourié-Gonnardcb4137b2014-09-04 14:55:28 +0200193 *q++ = '\0';
194
195 if( strcmp( p, "server_addr" ) == 0 )
196 opt.server_addr = q;
197 else if( strcmp( p, "server_port" ) == 0 )
Manuel Pégourié-Gonnardc0d74942015-06-23 12:30:57 +0200198 opt.server_port = q;
Manuel Pégourié-Gonnardcb4137b2014-09-04 14:55:28 +0200199 else if( strcmp( p, "listen_addr" ) == 0 )
200 opt.listen_addr = q;
201 else if( strcmp( p, "listen_port" ) == 0 )
Manuel Pégourié-Gonnardc0d74942015-06-23 12:30:57 +0200202 opt.listen_port = q;
Manuel Pégourié-Gonnard2c41bd82014-09-06 08:14:47 +0200203 else if( strcmp( p, "duplicate" ) == 0 )
204 {
205 opt.duplicate = atoi( q );
Manuel Pégourié-Gonnard992e1362014-09-20 18:06:23 +0200206 if( opt.duplicate < 0 || opt.duplicate > 20 )
Manuel Pégourié-Gonnard2c41bd82014-09-06 08:14:47 +0200207 exit_usage( p, q );
208 }
Manuel Pégourié-Gonnard21398c32014-09-06 14:36:46 +0200209 else if( strcmp( p, "delay" ) == 0 )
210 {
211 opt.delay = atoi( q );
Manuel Pégourié-Gonnard992e1362014-09-20 18:06:23 +0200212 if( opt.delay < 0 || opt.delay > 20 || opt.delay == 1 )
Manuel Pégourié-Gonnard21398c32014-09-06 14:36:46 +0200213 exit_usage( p, q );
214 }
Manuel Pégourié-Gonnard81f2fe92014-09-08 10:44:57 +0200215 else if( strcmp( p, "delay_ccs" ) == 0 )
216 {
217 opt.delay_ccs = atoi( q );
218 if( opt.delay_ccs < 0 || opt.delay_ccs > 1 )
219 exit_usage( p, q );
220 }
Manuel Pégourié-Gonnard60fdd7e2014-09-06 14:49:52 +0200221 else if( strcmp( p, "drop" ) == 0 )
222 {
223 opt.drop = atoi( q );
Manuel Pégourié-Gonnard992e1362014-09-20 18:06:23 +0200224 if( opt.drop < 0 || opt.drop > 20 || opt.drop == 1 )
Manuel Pégourié-Gonnard60fdd7e2014-09-06 14:49:52 +0200225 exit_usage( p, q );
226 }
Manuel Pégourié-Gonnardeb00bfd2014-09-08 11:11:42 +0200227 else if( strcmp( p, "mtu" ) == 0 )
228 {
229 opt.mtu = atoi( q );
230 if( opt.mtu < 0 || opt.mtu > MAX_MSG_SIZE )
231 exit_usage( p, q );
232 }
Manuel Pégourié-Gonnard6c18a392014-09-08 11:24:58 +0200233 else if( strcmp( p, "bad_ad" ) == 0 )
234 {
235 opt.bad_ad = atoi( q );
236 if( opt.bad_ad < 0 || opt.bad_ad > 1 )
237 exit_usage( p, q );
238 }
Manuel Pégourié-Gonnardd0fd1da2014-09-25 17:00:27 +0200239 else if( strcmp( p, "protect_hvr" ) == 0 )
240 {
241 opt.protect_hvr = atoi( q );
242 if( opt.protect_hvr < 0 || opt.protect_hvr > 1 )
243 exit_usage( p, q );
244 }
Manuel Pégourié-Gonnardba958b82014-10-09 16:13:44 +0200245 else if( strcmp( p, "protect_len" ) == 0 )
246 {
247 opt.protect_len = atoi( q );
248 if( opt.protect_len < 0 )
249 exit_usage( p, q );
250 }
Manuel Pégourié-Gonnarda58b0462020-03-13 11:11:02 +0100251 else if( strcmp( p, "inject_clihlo" ) == 0 )
252 {
253 opt.inject_clihlo = atoi( q );
254 if( opt.inject_clihlo < 0 || opt.inject_clihlo > 1 )
255 exit_usage( p, q );
256 }
Manuel Pégourié-Gonnard992e1362014-09-20 18:06:23 +0200257 else if( strcmp( p, "seed" ) == 0 )
258 {
259 opt.seed = atoi( q );
260 if( opt.seed == 0 )
261 exit_usage( p, q );
262 }
Manuel Pégourié-Gonnardcb4137b2014-09-04 14:55:28 +0200263 else
Manuel Pégourié-Gonnard44d5e632014-09-06 08:07:45 +0200264 exit_usage( p, NULL );
265 }
266}
267
268static const char *msg_type( unsigned char *msg, size_t len )
269{
270 if( len < 1 ) return( "Invalid" );
271 switch( msg[0] )
272 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200273 case MBEDTLS_SSL_MSG_CHANGE_CIPHER_SPEC: return( "ChangeCipherSpec" );
274 case MBEDTLS_SSL_MSG_ALERT: return( "Alert" );
275 case MBEDTLS_SSL_MSG_APPLICATION_DATA: return( "ApplicationData" );
276 case MBEDTLS_SSL_MSG_HANDSHAKE: break; /* See below */
Manuel Pégourié-Gonnard44d5e632014-09-06 08:07:45 +0200277 default: return( "Unknown" );
278 }
279
Manuel Pégourié-Gonnard8cc7e032014-09-25 12:59:05 +0200280 if( len < 13 + 12 ) return( "Invalid handshake" );
281
282 /*
283 * Our handshake message are less than 2^16 bytes long, so they should
284 * have 0 as the first byte of length, frag_offset and frag_length.
285 * Otherwise, assume they are encrypted.
286 */
287 if( msg[14] || msg[19] || msg[22] ) return( "Encrypted handshake" );
288
Manuel Pégourié-Gonnard44d5e632014-09-06 08:07:45 +0200289 switch( msg[13] )
290 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200291 case MBEDTLS_SSL_HS_HELLO_REQUEST: return( "HelloRequest" );
292 case MBEDTLS_SSL_HS_CLIENT_HELLO: return( "ClientHello" );
293 case MBEDTLS_SSL_HS_SERVER_HELLO: return( "ServerHello" );
294 case MBEDTLS_SSL_HS_HELLO_VERIFY_REQUEST: return( "HelloVerifyRequest" );
295 case MBEDTLS_SSL_HS_NEW_SESSION_TICKET: return( "NewSessionTicket" );
296 case MBEDTLS_SSL_HS_CERTIFICATE: return( "Certificate" );
297 case MBEDTLS_SSL_HS_SERVER_KEY_EXCHANGE: return( "ServerKeyExchange" );
298 case MBEDTLS_SSL_HS_CERTIFICATE_REQUEST: return( "CertificateRequest" );
299 case MBEDTLS_SSL_HS_SERVER_HELLO_DONE: return( "ServerHelloDone" );
300 case MBEDTLS_SSL_HS_CERTIFICATE_VERIFY: return( "CertificateVerify" );
301 case MBEDTLS_SSL_HS_CLIENT_KEY_EXCHANGE: return( "ClientKeyExchange" );
302 case MBEDTLS_SSL_HS_FINISHED: return( "Finished" );
Manuel Pégourié-Gonnardbc010a02014-09-20 12:40:51 +0200303 default: return( "Unknown handshake" );
Manuel Pégourié-Gonnardcb4137b2014-09-04 14:55:28 +0200304 }
305}
306
Manuel Pégourié-Gonnard7cf35182014-09-20 09:43:48 +0200307/* Return elapsed time in milliseconds since the first call */
308static unsigned long ellapsed_time( void )
309{
310#if defined(_WIN32)
311 return( 0 );
312#else
313 static struct timeval ref = { 0, 0 };
314 struct timeval now;
315
316 if( ref.tv_sec == 0 && ref.tv_usec == 0 )
317 {
318 gettimeofday( &ref, NULL );
319 return( 0 );
320 }
321
322 gettimeofday( &now, NULL );
323 return( 1000 * ( now.tv_sec - ref.tv_sec )
324 + ( now.tv_usec - ref.tv_usec ) / 1000 );
325#endif
326}
327
Manuel Pégourié-Gonnard21398c32014-09-06 14:36:46 +0200328typedef struct
Manuel Pégourié-Gonnardcb4137b2014-09-04 14:55:28 +0200329{
Manuel Pégourié-Gonnard5db64322015-06-30 15:40:39 +0200330 mbedtls_net_context *dst;
Manuel Pégourié-Gonnard21398c32014-09-06 14:36:46 +0200331 const char *way;
Manuel Pégourié-Gonnard2c41bd82014-09-06 08:14:47 +0200332 const char *type;
Manuel Pégourié-Gonnard21398c32014-09-06 14:36:46 +0200333 unsigned len;
334 unsigned char buf[MAX_MSG_SIZE];
335} packet;
Manuel Pégourié-Gonnardcb4137b2014-09-04 14:55:28 +0200336
Manuel Pégourié-Gonnard21398c32014-09-06 14:36:46 +0200337/* Print packet. Outgoing packets come with a reason (forward, dupl, etc.) */
338void print_packet( const packet *p, const char *why )
339{
340 if( why == NULL )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200341 mbedtls_printf( " %05lu %s %s (%u bytes)\n",
Manuel Pégourié-Gonnard7cf35182014-09-20 09:43:48 +0200342 ellapsed_time(), p->way, p->type, p->len );
Manuel Pégourié-Gonnard21398c32014-09-06 14:36:46 +0200343 else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200344 mbedtls_printf( " %s %s (%u bytes): %s\n",
Manuel Pégourié-Gonnard7cf35182014-09-20 09:43:48 +0200345 p->way, p->type, p->len, why );
Manuel Pégourié-Gonnard21398c32014-09-06 14:36:46 +0200346 fflush( stdout );
347}
348
Manuel Pégourié-Gonnarda58b0462020-03-13 11:11:02 +0100349/*
350 * In order to test the server's behaviour when receiving a ClientHello after
351 * the connection is established (this could be a hard reset from the client,
352 * but the server must not drop the existing connection before establishing
353 * client reachability, see RFC 6347 Section 4.2.8), we memorize the first
354 * ClientHello we see (which can't have a cookie), then replay it after the
355 * first ApplicationData record - then we're done.
356 *
357 * This is controlled by the inject_clihlo option.
358 *
359 * We want an explicit state and a place to store the packet.
360 */
Manuel Pégourié-Gonnard7ef7bf32020-03-30 12:46:21 +0200361typedef enum {
362 ICH_INIT, /* haven't seen the first ClientHello yet */
363 ICH_CACHED, /* cached the initial ClientHello */
364 ICH_INJECTED, /* ClientHello already injected, done */
365} inject_clihlo_state_t;
Manuel Pégourié-Gonnarda58b0462020-03-13 11:11:02 +0100366
Manuel Pégourié-Gonnard7ef7bf32020-03-30 12:46:21 +0200367static inject_clihlo_state_t inject_clihlo_state;
Manuel Pégourié-Gonnarda58b0462020-03-13 11:11:02 +0100368static packet initial_clihlo;
369
Manuel Pégourié-Gonnard21398c32014-09-06 14:36:46 +0200370int send_packet( const packet *p, const char *why )
371{
372 int ret;
Manuel Pégourié-Gonnard5db64322015-06-30 15:40:39 +0200373 mbedtls_net_context *dst = p->dst;
Manuel Pégourié-Gonnard21398c32014-09-06 14:36:46 +0200374
Manuel Pégourié-Gonnarda58b0462020-03-13 11:11:02 +0100375 /* save initial ClientHello? */
376 if( opt.inject_clihlo != 0 &&
Manuel Pégourié-Gonnard7ef7bf32020-03-30 12:46:21 +0200377 inject_clihlo_state == ICH_INIT &&
Manuel Pégourié-Gonnarda58b0462020-03-13 11:11:02 +0100378 strcmp( p->type, "ClientHello" ) == 0 )
379 {
380 memcpy( &initial_clihlo, p, sizeof( packet ) );
Manuel Pégourié-Gonnard7ef7bf32020-03-30 12:46:21 +0200381 inject_clihlo_state = ICH_CACHED;
Manuel Pégourié-Gonnarda58b0462020-03-13 11:11:02 +0100382 }
383
Manuel Pégourié-Gonnard6c18a392014-09-08 11:24:58 +0200384 /* insert corrupted ApplicationData record? */
385 if( opt.bad_ad &&
386 strcmp( p->type, "ApplicationData" ) == 0 )
387 {
388 unsigned char buf[MAX_MSG_SIZE];
389 memcpy( buf, p->buf, p->len );
390 ++buf[p->len - 1];
391
392 print_packet( p, "corrupted" );
Manuel Pégourié-Gonnard5db64322015-06-30 15:40:39 +0200393 if( ( ret = mbedtls_net_send( dst, buf, p->len ) ) <= 0 )
Manuel Pégourié-Gonnard6c18a392014-09-08 11:24:58 +0200394 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200395 mbedtls_printf( " ! mbedtls_net_send returned %d\n", ret );
Manuel Pégourié-Gonnard6c18a392014-09-08 11:24:58 +0200396 return( ret );
397 }
398 }
399
Manuel Pégourié-Gonnard21398c32014-09-06 14:36:46 +0200400 print_packet( p, why );
Manuel Pégourié-Gonnard5db64322015-06-30 15:40:39 +0200401 if( ( ret = mbedtls_net_send( dst, p->buf, p->len ) ) <= 0 )
Manuel Pégourié-Gonnardcb4137b2014-09-04 14:55:28 +0200402 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200403 mbedtls_printf( " ! mbedtls_net_send returned %d\n", ret );
Manuel Pégourié-Gonnardcb4137b2014-09-04 14:55:28 +0200404 return( ret );
405 }
406
Manuel Pégourié-Gonnard2c41bd82014-09-06 08:14:47 +0200407 /* Don't duplicate Application Data, only handshake covered */
Manuel Pégourié-Gonnard2c41bd82014-09-06 08:14:47 +0200408 if( opt.duplicate != 0 &&
Manuel Pégourié-Gonnard21398c32014-09-06 14:36:46 +0200409 strcmp( p->type, "ApplicationData" ) != 0 &&
Manuel Pégourié-Gonnard992e1362014-09-20 18:06:23 +0200410 rand() % opt.duplicate == 0 )
Manuel Pégourié-Gonnard2c41bd82014-09-06 08:14:47 +0200411 {
Manuel Pégourié-Gonnard21398c32014-09-06 14:36:46 +0200412 print_packet( p, "duplicated" );
Manuel Pégourié-Gonnard2c41bd82014-09-06 08:14:47 +0200413
Manuel Pégourié-Gonnard5db64322015-06-30 15:40:39 +0200414 if( ( ret = mbedtls_net_send( dst, p->buf, p->len ) ) <= 0 )
Manuel Pégourié-Gonnard2c41bd82014-09-06 08:14:47 +0200415 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200416 mbedtls_printf( " ! mbedtls_net_send returned %d\n", ret );
Manuel Pégourié-Gonnard2c41bd82014-09-06 08:14:47 +0200417 return( ret );
418 }
419 }
Manuel Pégourié-Gonnardcb4137b2014-09-04 14:55:28 +0200420
Manuel Pégourié-Gonnarda58b0462020-03-13 11:11:02 +0100421 /* Inject ClientHello after first ApplicationData */
422 if( opt.inject_clihlo != 0 &&
Manuel Pégourié-Gonnard7ef7bf32020-03-30 12:46:21 +0200423 inject_clihlo_state == ICH_CACHED &&
Manuel Pégourié-Gonnarda58b0462020-03-13 11:11:02 +0100424 strcmp( p->type, "ApplicationData" ) == 0 )
425 {
426 print_packet( &initial_clihlo, "injected" );
427
428 if( ( ret = mbedtls_net_send( dst, initial_clihlo.buf,
429 initial_clihlo.len ) ) <= 0 )
430 {
431 mbedtls_printf( " ! mbedtls_net_send returned %d\n", ret );
432 return( ret );
433 }
434
Manuel Pégourié-Gonnard7ef7bf32020-03-30 12:46:21 +0200435 inject_clihlo_state = ICH_INJECTED;
Manuel Pégourié-Gonnarda58b0462020-03-13 11:11:02 +0100436 }
437
Manuel Pégourié-Gonnard21398c32014-09-06 14:36:46 +0200438 return( 0 );
439}
440
Manuel Pégourié-Gonnard6312e0f2014-09-23 12:46:33 +0200441static packet prev;
442
443void clear_pending( void )
444{
445 memset( &prev, 0, sizeof( packet ) );
446}
447
Manuel Pégourié-Gonnardae666c52014-09-26 12:08:36 +0200448/*
449 * Avoid dropping or delaying a packet that was already dropped twice: this
450 * only results in uninteresting timeouts. We can't rely on type to identify
451 * packets, since during renegotiation they're all encrypted. So, rely on
452 * size mod 2048 (which is usually just size).
453 */
454static unsigned char dropped[2048] = { 0 };
455#define DROP_MAX 2
456
Hanno Becker7bac1ab2019-06-04 13:04:28 +0100457/* We only drop packets at the level of entire datagrams, not at the level
458 * of records. In particular, if the peer changes the way it packs multiple
459 * records into a single datagram, we don't necessarily count the number of
460 * times a record has been dropped correctly. However, the only known reason
461 * why a peer would change datagram packing is disabling the latter on
462 * retransmission, in which case we'd drop involved records at most
463 * DROP_MAX + 1 times. */
Manuel Pégourié-Gonnardae666c52014-09-26 12:08:36 +0200464void update_dropped( const packet *p )
465{
466 size_t id = p->len % sizeof( dropped );
Manuel Pégourié-Gonnardfa60f122014-09-26 16:07:29 +0200467 ++dropped[id];
Manuel Pégourié-Gonnardae666c52014-09-26 12:08:36 +0200468}
469
Manuel Pégourié-Gonnard5db64322015-06-30 15:40:39 +0200470int handle_message( const char *way,
471 mbedtls_net_context *dst,
472 mbedtls_net_context *src )
Manuel Pégourié-Gonnard21398c32014-09-06 14:36:46 +0200473{
474 int ret;
475 packet cur;
Manuel Pégourié-Gonnardae666c52014-09-26 12:08:36 +0200476 size_t id;
Manuel Pégourié-Gonnard21398c32014-09-06 14:36:46 +0200477
Manuel Pégourié-Gonnard63eca932014-09-08 16:39:08 +0200478 /* receive packet */
Manuel Pégourié-Gonnard5db64322015-06-30 15:40:39 +0200479 if( ( ret = mbedtls_net_recv( src, cur.buf, sizeof( cur.buf ) ) ) <= 0 )
Manuel Pégourié-Gonnardcb4137b2014-09-04 14:55:28 +0200480 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200481 mbedtls_printf( " ! mbedtls_net_recv returned %d\n", ret );
Manuel Pégourié-Gonnardcb4137b2014-09-04 14:55:28 +0200482 return( ret );
483 }
484
Manuel Pégourié-Gonnard21398c32014-09-06 14:36:46 +0200485 cur.len = ret;
486 cur.type = msg_type( cur.buf, cur.len );
487 cur.way = way;
Manuel Pégourié-Gonnard6265d302014-09-24 17:42:09 +0200488 cur.dst = dst;
Manuel Pégourié-Gonnard21398c32014-09-06 14:36:46 +0200489 print_packet( &cur, NULL );
490
Manuel Pégourié-Gonnardae666c52014-09-26 12:08:36 +0200491 id = cur.len % sizeof( dropped );
492
Manuel Pégourié-Gonnard60fdd7e2014-09-06 14:49:52 +0200493 /* do we want to drop, delay, or forward it? */
Manuel Pégourié-Gonnardeb00bfd2014-09-08 11:11:42 +0200494 if( ( opt.mtu != 0 &&
495 cur.len > (unsigned) opt.mtu ) ||
496 ( opt.drop != 0 &&
497 strcmp( cur.type, "ApplicationData" ) != 0 &&
Manuel Pégourié-Gonnardd0fd1da2014-09-25 17:00:27 +0200498 ! ( opt.protect_hvr &&
499 strcmp( cur.type, "HelloVerifyRequest" ) == 0 ) &&
Manuel Pégourié-Gonnardba958b82014-10-09 16:13:44 +0200500 cur.len != (size_t) opt.protect_len &&
Manuel Pégourié-Gonnardae666c52014-09-26 12:08:36 +0200501 dropped[id] < DROP_MAX &&
Manuel Pégourié-Gonnard992e1362014-09-20 18:06:23 +0200502 rand() % opt.drop == 0 ) )
Manuel Pégourié-Gonnard60fdd7e2014-09-06 14:49:52 +0200503 {
Manuel Pégourié-Gonnardae666c52014-09-26 12:08:36 +0200504 update_dropped( &cur );
Manuel Pégourié-Gonnard60fdd7e2014-09-06 14:49:52 +0200505 }
Manuel Pégourié-Gonnard81f2fe92014-09-08 10:44:57 +0200506 else if( ( opt.delay_ccs == 1 &&
507 strcmp( cur.type, "ChangeCipherSpec" ) == 0 ) ||
508 ( opt.delay != 0 &&
509 strcmp( cur.type, "ApplicationData" ) != 0 &&
Manuel Pégourié-Gonnardd0fd1da2014-09-25 17:00:27 +0200510 ! ( opt.protect_hvr &&
511 strcmp( cur.type, "HelloVerifyRequest" ) == 0 ) &&
Manuel Pégourié-Gonnard5db64322015-06-30 15:40:39 +0200512 prev.dst == NULL &&
Manuel Pégourié-Gonnardba958b82014-10-09 16:13:44 +0200513 cur.len != (size_t) opt.protect_len &&
Manuel Pégourié-Gonnardae666c52014-09-26 12:08:36 +0200514 dropped[id] < DROP_MAX &&
Manuel Pégourié-Gonnard992e1362014-09-20 18:06:23 +0200515 rand() % opt.delay == 0 ) )
Manuel Pégourié-Gonnard21398c32014-09-06 14:36:46 +0200516 {
Manuel Pégourié-Gonnard21398c32014-09-06 14:36:46 +0200517 memcpy( &prev, &cur, sizeof( packet ) );
518 }
519 else
520 {
Manuel Pégourié-Gonnard60fdd7e2014-09-06 14:49:52 +0200521 /* forward and possibly duplicate */
Manuel Pégourié-Gonnard21398c32014-09-06 14:36:46 +0200522 if( ( ret = send_packet( &cur, "forwarded" ) ) != 0 )
523 return( ret );
524
525 /* send previously delayed message if any */
Manuel Pégourié-Gonnard5db64322015-06-30 15:40:39 +0200526 if( prev.dst != NULL )
Manuel Pégourié-Gonnard21398c32014-09-06 14:36:46 +0200527 {
528 ret = send_packet( &prev, "delayed" );
529 memset( &prev, 0, sizeof( packet ) );
530 if( ret != 0 )
531 return( ret );
532 }
533 }
534
Manuel Pégourié-Gonnardcb4137b2014-09-04 14:55:28 +0200535 return( 0 );
536}
537
538int main( int argc, char *argv[] )
539{
Andres Amaya Garcia01e3d212018-04-29 21:58:53 +0100540 int ret = 1;
541 int exit_code = MBEDTLS_EXIT_FAILURE;
Manuel Pégourié-Gonnardcb4137b2014-09-04 14:55:28 +0200542
Manuel Pégourié-Gonnard5db64322015-06-30 15:40:39 +0200543 mbedtls_net_context listen_fd, client_fd, server_fd;
Manuel Pégourié-Gonnardcb4137b2014-09-04 14:55:28 +0200544
545 int nb_fds;
546 fd_set read_fds;
547
Manuel Pégourié-Gonnard5db64322015-06-30 15:40:39 +0200548 mbedtls_net_init( &listen_fd );
549 mbedtls_net_init( &client_fd );
550 mbedtls_net_init( &server_fd );
551
Manuel Pégourié-Gonnardcb4137b2014-09-04 14:55:28 +0200552 get_options( argc, argv );
Manuel Pégourié-Gonnard992e1362014-09-20 18:06:23 +0200553
554 /*
555 * Decisions to drop/delay/duplicate packets are pseudo-random: dropping
556 * exactly 1 in N packets would lead to problems when a flight has exactly
557 * N packets: the same packet would be dropped on every resend.
558 *
559 * In order to be able to reproduce problems reliably, the seed may be
560 * specified explicitly.
561 */
562 if( opt.seed == 0 )
563 {
Manuel Pégourié-Gonnard9de64f52015-07-01 15:51:43 +0200564 opt.seed = (unsigned int) time( NULL );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200565 mbedtls_printf( " . Pseudo-random seed: %u\n", opt.seed );
Manuel Pégourié-Gonnard992e1362014-09-20 18:06:23 +0200566 }
567
568 srand( opt.seed );
Manuel Pégourié-Gonnardcb4137b2014-09-04 14:55:28 +0200569
570 /*
Manuel Pégourié-Gonnard44d5e632014-09-06 08:07:45 +0200571 * 0. "Connect" to the server
Manuel Pégourié-Gonnardcb4137b2014-09-04 14:55:28 +0200572 */
Manuel Pégourié-Gonnardc0d74942015-06-23 12:30:57 +0200573 mbedtls_printf( " . Connect to server on UDP/%s/%s ...",
Manuel Pégourié-Gonnardcb4137b2014-09-04 14:55:28 +0200574 opt.server_addr, opt.server_port );
575 fflush( stdout );
576
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200577 if( ( ret = mbedtls_net_connect( &server_fd, opt.server_addr, opt.server_port,
578 MBEDTLS_NET_PROTO_UDP ) ) != 0 )
Manuel Pégourié-Gonnardcb4137b2014-09-04 14:55:28 +0200579 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200580 mbedtls_printf( " failed\n ! mbedtls_net_connect returned %d\n\n", ret );
Manuel Pégourié-Gonnardcb4137b2014-09-04 14:55:28 +0200581 goto exit;
582 }
583
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200584 mbedtls_printf( " ok\n" );
Manuel Pégourié-Gonnardcb4137b2014-09-04 14:55:28 +0200585
586 /*
587 * 1. Setup the "listening" UDP socket
588 */
Manuel Pégourié-Gonnardc0d74942015-06-23 12:30:57 +0200589 mbedtls_printf( " . Bind on UDP/%s/%s ...",
Manuel Pégourié-Gonnardcb4137b2014-09-04 14:55:28 +0200590 opt.listen_addr, opt.listen_port );
591 fflush( stdout );
592
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200593 if( ( ret = mbedtls_net_bind( &listen_fd, opt.listen_addr, opt.listen_port,
594 MBEDTLS_NET_PROTO_UDP ) ) != 0 )
Manuel Pégourié-Gonnardcb4137b2014-09-04 14:55:28 +0200595 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200596 mbedtls_printf( " failed\n ! mbedtls_net_bind returned %d\n\n", ret );
Manuel Pégourié-Gonnardcb4137b2014-09-04 14:55:28 +0200597 goto exit;
598 }
599
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200600 mbedtls_printf( " ok\n" );
Manuel Pégourié-Gonnardcb4137b2014-09-04 14:55:28 +0200601
602 /*
603 * 2. Wait until a client connects
604 */
Manuel Pégourié-Gonnard6312e0f2014-09-23 12:46:33 +0200605accept:
Manuel Pégourié-Gonnardabc729e2015-07-01 01:28:24 +0200606 mbedtls_net_free( &client_fd );
607
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200608 mbedtls_printf( " . Waiting for a remote connection ..." );
Manuel Pégourié-Gonnardcb4137b2014-09-04 14:55:28 +0200609 fflush( stdout );
610
Manuel Pégourié-Gonnard5db64322015-06-30 15:40:39 +0200611 if( ( ret = mbedtls_net_accept( &listen_fd, &client_fd,
Manuel Pégourié-Gonnard0b104b02015-05-14 21:52:40 +0200612 NULL, 0, NULL ) ) != 0 )
Manuel Pégourié-Gonnardcb4137b2014-09-04 14:55:28 +0200613 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200614 mbedtls_printf( " failed\n ! mbedtls_net_accept returned %d\n\n", ret );
Manuel Pégourié-Gonnardcb4137b2014-09-04 14:55:28 +0200615 goto exit;
616 }
617
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200618 mbedtls_printf( " ok\n" );
Manuel Pégourié-Gonnard6312e0f2014-09-23 12:46:33 +0200619
Manuel Pégourié-Gonnardcb4137b2014-09-04 14:55:28 +0200620 /*
621 * 3. Forward packets forever (kill the process to terminate it)
622 */
Manuel Pégourié-Gonnardce8588c2014-10-01 00:56:03 +0200623 clear_pending();
624 memset( dropped, 0, sizeof( dropped ) );
625
Manuel Pégourié-Gonnard5db64322015-06-30 15:40:39 +0200626 nb_fds = client_fd.fd;
627 if( nb_fds < server_fd.fd )
628 nb_fds = server_fd.fd;
629 if( nb_fds < listen_fd.fd )
630 nb_fds = listen_fd.fd;
Manuel Pégourié-Gonnard6312e0f2014-09-23 12:46:33 +0200631 ++nb_fds;
Manuel Pégourié-Gonnardcb4137b2014-09-04 14:55:28 +0200632
633 while( 1 )
634 {
635 FD_ZERO( &read_fds );
Manuel Pégourié-Gonnard5db64322015-06-30 15:40:39 +0200636 FD_SET( server_fd.fd, &read_fds );
637 FD_SET( client_fd.fd, &read_fds );
638 FD_SET( listen_fd.fd, &read_fds );
Manuel Pégourié-Gonnardcb4137b2014-09-04 14:55:28 +0200639
640 if( ( ret = select( nb_fds, &read_fds, NULL, NULL, NULL ) ) <= 0 )
641 {
642 perror( "select" );
643 goto exit;
644 }
645
Manuel Pégourié-Gonnard5db64322015-06-30 15:40:39 +0200646 if( FD_ISSET( listen_fd.fd, &read_fds ) )
Manuel Pégourié-Gonnard6312e0f2014-09-23 12:46:33 +0200647 goto accept;
Manuel Pégourié-Gonnard6312e0f2014-09-23 12:46:33 +0200648
Manuel Pégourié-Gonnard5db64322015-06-30 15:40:39 +0200649 if( FD_ISSET( client_fd.fd, &read_fds ) )
Manuel Pégourié-Gonnardcb4137b2014-09-04 14:55:28 +0200650 {
Manuel Pégourié-Gonnard7cf35182014-09-20 09:43:48 +0200651 if( ( ret = handle_message( "S <- C",
Manuel Pégourié-Gonnard5db64322015-06-30 15:40:39 +0200652 &server_fd, &client_fd ) ) != 0 )
Manuel Pégourié-Gonnardce8588c2014-10-01 00:56:03 +0200653 goto accept;
Manuel Pégourié-Gonnardcb4137b2014-09-04 14:55:28 +0200654 }
655
Manuel Pégourié-Gonnard5db64322015-06-30 15:40:39 +0200656 if( FD_ISSET( server_fd.fd, &read_fds ) )
Manuel Pégourié-Gonnardcb4137b2014-09-04 14:55:28 +0200657 {
Manuel Pégourié-Gonnard7cf35182014-09-20 09:43:48 +0200658 if( ( ret = handle_message( "S -> C",
Manuel Pégourié-Gonnard5db64322015-06-30 15:40:39 +0200659 &client_fd, &server_fd ) ) != 0 )
Manuel Pégourié-Gonnardce8588c2014-10-01 00:56:03 +0200660 goto accept;
Manuel Pégourié-Gonnardcb4137b2014-09-04 14:55:28 +0200661 }
662 }
663
Andres Amaya Garcia01e3d212018-04-29 21:58:53 +0100664 exit_code = MBEDTLS_EXIT_SUCCESS;
665
Manuel Pégourié-Gonnardcb4137b2014-09-04 14:55:28 +0200666exit:
667
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200668#ifdef MBEDTLS_ERROR_C
Andres Amaya Garcia01e3d212018-04-29 21:58:53 +0100669 if( exit_code != MBEDTLS_EXIT_SUCCESS )
Manuel Pégourié-Gonnardcb4137b2014-09-04 14:55:28 +0200670 {
671 char error_buf[100];
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200672 mbedtls_strerror( ret, error_buf, 100 );
673 mbedtls_printf( "Last error was: -0x%04X - %s\n\n", - ret, error_buf );
Manuel Pégourié-Gonnardcb4137b2014-09-04 14:55:28 +0200674 fflush( stdout );
675 }
676#endif
677
Manuel Pégourié-Gonnard3d7d00a2015-06-30 15:55:03 +0200678 mbedtls_net_free( &client_fd );
679 mbedtls_net_free( &server_fd );
680 mbedtls_net_free( &listen_fd );
Manuel Pégourié-Gonnardcb4137b2014-09-04 14:55:28 +0200681
682#if defined(_WIN32)
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200683 mbedtls_printf( " Press Enter to exit this program.\n" );
Manuel Pégourié-Gonnardcb4137b2014-09-04 14:55:28 +0200684 fflush( stdout ); getchar();
685#endif
686
Krzysztof Stachowiaka0865222019-04-24 14:24:46 +0200687 mbedtls_exit( exit_code );
Manuel Pégourié-Gonnardcb4137b2014-09-04 14:55:28 +0200688}
689
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200690#endif /* MBEDTLS_NET_C */