Skip to content

Commit 2736575

Browse files
committed
Fix ssl_client mbedtls_pk_parse_key callback
1 parent 6cc8f11 commit 2736575

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

libraries/WiFiClientSecure/src/ssl_client.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,6 @@ void ssl_init(sslclient_context *ssl_client)
5353
mbedtls_ctr_drbg_init(&ssl_client->drbg_ctx);
5454
}
5555

56-
#warning This needs to be properly filled
57-
static int ssl_rng(void *ctx, unsigned char *data, size_t len)
58-
{
59-
// while (len-- != 0) {
60-
// *data++ = random();
61-
// }
62-
return 0;
63-
}
64-
6556
int start_ssl_client(sslclient_context *ssl_client, const char *host, uint32_t port, int timeout, const char *rootCABuff, bool useRootCABundle, const char *cli_cert, const char *cli_key, const char *pskIdent, const char *psKey, bool insecure, const char **alpn_protos)
6657
{
6758
char buf[512];
@@ -254,7 +245,10 @@ int start_ssl_client(sslclient_context *ssl_client, const char *host, uint32_t p
254245
}
255246

256247
log_v("Loading private key");
257-
ret = mbedtls_pk_parse_key(&ssl_client->client_key, (const unsigned char *)cli_key, strlen(cli_key) + 1, NULL, 0, ssl_rng, NULL);
248+
mbedtls_ctr_drbg_context ctr_drbg;
249+
mbedtls_ctr_drbg_init( &ctr_drbg );
250+
ret = mbedtls_pk_parse_key(&ssl_client->client_key, (const unsigned char *)cli_key, strlen(cli_key) + 1, NULL, 0, mbedtls_ctr_drbg_random, &ctr_drbg);
251+
mbedtls_ctr_drbg_free( &ctr_drbg );
258252

259253
if (ret != 0) {
260254
mbedtls_x509_crt_free(&ssl_client->client_cert); // cert+key are free'd in pair

0 commit comments

Comments
 (0)