-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmbed_tests.cpp
More file actions
101 lines (81 loc) · 2.28 KB
/
mbed_tests.cpp
File metadata and controls
101 lines (81 loc) · 2.28 KB
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
#if !defined(MBEDTLS_CONFIG_FILE)
#include "mbedtls/config.h"
#else
#include MBEDTLS_CONFIG_FILE
#endif
#if !defined(MBEDTLS_ENTROPY_C) || \
!defined(MBEDTLS_SSL_TLS_C) || !defined(MBEDTLS_SSL_CLI_C) || \
!defined(MBEDTLS_NET_C) || !defined(MBEDTLS_CTR_DRBG_C)
int main( void )
{
mbedtls_printf("MBEDTLS_ENTROPY_C and/or "
"MBEDTLS_SSL_TLS_C and/or MBEDTLS_SSL_CLI_C and/or "
"MBEDTLS_NET_C and/or MBEDTLS_CTR_DRBG_C and/or not defined.\n");
return( 0 );
}
#else
#include "common/Usage.c"
#include "common/SslClient.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <exception>
int main( int argc, char *argv[] )
{
int ret;
#if defined(MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED)
unsigned char psk[MBEDTLS_PSK_MAX_LEN];
size_t psk_len = 0;
#endif
#if defined(MBEDTLS_SSL_ALPN)
const char *alpn_list[10];
#endif
#if defined(MBEDTLS_SSL_ALPN)
memset( (void * ) alpn_list, 0, sizeof( alpn_list ) );
#endif
Options opt;
for(int i = 0; i<argc; ++i)
std::cout<<argv[i]<<std::endl;
if(opt.HandleCliArgs(argc, argv))
return 0;
#if defined(MBEDTLS_DEBUG_C)
mbedtls_debug_set_threshold( opt.debug_level );
#endif
if(opt.IsCiphersuiteForced())
ret = opt.HandleCiphersuiteRequest();
if(opt.IsPSKEnabled())
opt.UnhexifyPSK(psk, psk_len);
#if defined(MBEDTLS_SSL_ALPN)
opt.SslAlpn(alpn_list);
#endif /* MBEDTLS_SSL_ALPN */
try{
SslClient cl;
cl.InitRng();
cl.LoadTrustedCerts(opt);
cl.LoadClientKeys(opt);
cl.StartConnection(opt);
cl.SetupStuff(opt, alpn_list, psk, psk_len);
cl.PerformHandshake(opt);
cl.VerifyServerCert(opt);
cl.SendGet(opt);
cl.ReadResponse(opt);
cl.ReuseConnection(opt);
cl.CloseConnection();
cl.Reconnect(opt);
}
catch(MbedException e){
e.what();
}
#if defined(_WIN32)
mbedtls_printf( " + Press Enter to exit this program.\n" );
fflush( stdout ); getchar();
#endif
// Shell can not handle large exit numbers -> 1 for errors
if( ret < 0 )
ret = 1;
return( ret );
}
#endif /* MBEDTLS_BIGNUM_C && MBEDTLS_ENTROPY_C && MBEDTLS_SSL_TLS_C &&
MBEDTLS_SSL_CLI_C && MBEDTLS_NET_C && MBEDTLS_RSA_C &&
MBEDTLS_CTR_DRBG_C MBEDTLS_TIMING_C */