* Add an example for how to enable TLS verification. TLS should really be used with verification enabled, as otherwise you can still suffer from a "man in the middle" attack. Add an example that demonstrates how to do this. Fixes #337
46 lines
1.3 KiB
C
46 lines
1.3 KiB
C
/*
|
|
* Copyright (c) 2023 Raspberry Pi (Trading) Ltd.
|
|
*
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
*/
|
|
|
|
#include "pico/stdlib.h"
|
|
#include "pico/cyw43_arch.h"
|
|
|
|
#define TLS_CLIENT_SERVER "worldtimeapi.org"
|
|
#define TLS_CLIENT_HTTP_REQUEST "GET /api/ip HTTP/1.1\r\n" \
|
|
"Host: " TLS_CLIENT_SERVER "\r\n" \
|
|
"Connection: close\r\n" \
|
|
"\r\n"
|
|
#define TLS_CLIENT_TIMEOUT_SECS 15
|
|
|
|
extern bool run_tls_client_test(const uint8_t *cert, size_t cert_len, const char *server, const char *request, int timeout);
|
|
|
|
int main() {
|
|
stdio_init_all();
|
|
|
|
if (cyw43_arch_init()) {
|
|
printf("failed to initialise\n");
|
|
return 1;
|
|
}
|
|
cyw43_arch_enable_sta_mode();
|
|
|
|
if (cyw43_arch_wifi_connect_timeout_ms(WIFI_SSID, WIFI_PASSWORD, CYW43_AUTH_WPA2_AES_PSK, 30000)) {
|
|
printf("failed to connect\n");
|
|
return 1;
|
|
}
|
|
bool pass = run_tls_client_test(NULL, 0, TLS_CLIENT_SERVER, TLS_CLIENT_HTTP_REQUEST, TLS_CLIENT_TIMEOUT_SECS);
|
|
if (pass) {
|
|
printf("Test passed\n");
|
|
} else {
|
|
printf("Test failed\n");
|
|
}
|
|
/* sleep a bit to let usb stdio write out any buffer to host */
|
|
sleep_ms(100);
|
|
|
|
cyw43_arch_deinit();
|
|
printf("All done\n");
|
|
return pass ? 0 : 1;
|
|
}
|
|
|