Skip to content
This repository was archived by the owner on Oct 28, 2023. It is now read-only.

Commit f21ba90

Browse files
committed
Broken mbed_tls_pinning
1 parent cdaaaf9 commit f21ba90

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

extmod/modussl_mbedtls.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@
4545
#include "mbedtls/ctr_drbg.h"
4646
#include "mbedtls/debug.h"
4747

48+
extern const uint8_t server_root_cert_pem_start[] asm("_binary_server_root_cert_pem_start");
49+
extern const uint8_t server_root_cert_pem_end[] asm("_binary_server_root_cert_pem_end");
50+
4851
typedef struct _mp_obj_ssl_socket_t {
4952
mp_obj_base_t base;
5053
mp_obj_t sock;
@@ -136,7 +139,7 @@ STATIC mp_obj_ssl_socket_t *socket_new(mp_obj_t sock, struct ssl_args *args) {
136139
mbedtls_pk_init(&o->pkey);
137140
mbedtls_ctr_drbg_init(&o->ctr_drbg);
138141
// Debug level (0-4)
139-
mbedtls_debug_set_threshold(0);
142+
mbedtls_debug_set_threshold(4);
140143

141144
mbedtls_entropy_init(&o->entropy);
142145
const byte seed[] = "upy";
@@ -146,6 +149,15 @@ STATIC mp_obj_ssl_socket_t *socket_new(mp_obj_t sock, struct ssl_args *args) {
146149
assert(0);
147150
}
148151

152+
ret = mbedtls_x509_crt_parse(&o->cacert, server_root_cert_pem_start,
153+
server_root_cert_pem_end-server_root_cert_pem_start);
154+
155+
if(ret < 0)
156+
{
157+
printf("mbedtls_x509_crt_parse returned -0x%x\n\n", -ret);
158+
assert(0);
159+
}
160+
149161
ret = mbedtls_ssl_config_defaults(&o->conf,
150162
MBEDTLS_SSL_IS_CLIENT,
151163
MBEDTLS_SSL_TRANSPORT_STREAM,
@@ -154,7 +166,7 @@ STATIC mp_obj_ssl_socket_t *socket_new(mp_obj_t sock, struct ssl_args *args) {
154166
assert(0);
155167
}
156168

157-
mbedtls_ssl_conf_authmode(&o->conf, MBEDTLS_SSL_VERIFY_NONE);
169+
mbedtls_ssl_conf_authmode(&o->conf, MBEDTLS_SSL_VERIFY_REQUIRED);
158170
mbedtls_ssl_conf_rng(&o->conf, mbedtls_ctr_drbg_random, &o->ctr_drbg);
159171
mbedtls_ssl_conf_dbg(&o->conf, mbedtls_debug, NULL);
160172

@@ -223,7 +235,7 @@ STATIC mp_uint_t socket_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *errc
223235
return 0;
224236
}
225237

226-
if (ret == MBEDTLS_ERR_SSL_WANT_READ) {
238+
if (ret == MBEDTLS_ERR_SSL_WANT_READ) {
227239
*errcode = EWOULDBLOCK;
228240
return 0;
229241
}
@@ -243,7 +255,7 @@ STATIC mp_uint_t socket_write(mp_obj_t o_in, const void *buf, mp_uint_t size, in
243255
return ret;
244256
}
245257

246-
if (ret == MBEDTLS_ERR_SSL_WANT_WRITE) {
258+
if (ret == MBEDTLS_ERR_SSL_WANT_WRITE) {
247259
*errcode = EWOULDBLOCK;
248260
return 0;
249261
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy