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

Commit c2dd50b

Browse files
committed
Now validating SSL certs for *.sha2017.org
2 parents 4ebc773 + d6e961e commit c2dd50b

File tree

4 files changed

+39
-22
lines changed

4 files changed

+39
-22
lines changed

esp32/Makefile

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -155,16 +155,16 @@ SRC_C = \
155155
ugfx_styles.c \
156156
$(SRC_MOD)
157157

158-
### TODO remove hardcoded images when loader works ;)
159-
BADGE_MAIN_SRC_C = $(addprefix ../../main/,\
160-
imgv2_menu.c \
161-
imgv2_nick.c \
162-
imgv2_sha.c \
163-
imgv2_test.c \
164-
imgv2_weather.c \
165-
madison_gurkha.c \
166-
leaseweb.c \
167-
)
158+
### TODO fix hardcoded images when we can't get image loader to work
159+
#BADGE_MAIN_SRC_C = $(addprefix ../../main/,\
160+
# imgv2_menu.c \
161+
# imgv2_nick.c \
162+
# imgv2_sha.c \
163+
# imgv2_test.c \
164+
# imgv2_weather.c \
165+
# madison_gurkha.c \
166+
# leaseweb.c \
167+
# )
168168

169169
EXTMOD_SRC_C = $(addprefix extmod/,\
170170
modonewire.c \

esp32/modbadge.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ STATIC mp_obj_t badge_eink_init_() {
5757
}
5858
STATIC MP_DEFINE_CONST_FUN_OBJ_0(badge_eink_init_obj, badge_eink_init_);
5959

60+
/**
6061
#define NUM_PICTURES 7
6162
const uint8_t *pictures[NUM_PICTURES] = {
6263
imgv2_sha, imgv2_menu, imgv2_nick, imgv2_weather, imgv2_test, mg_logo, leaseweb
@@ -72,6 +73,7 @@ STATIC mp_obj_t badge_display_picture_(mp_obj_t picture_id,
7273
}
7374
STATIC MP_DEFINE_CONST_FUN_OBJ_2(badge_display_picture_obj,
7475
badge_display_picture_);
76+
*/
7577

7678
STATIC mp_obj_t badge_eink_busy_() {
7779
return mp_obj_new_bool(badge_eink_dev_is_busy());
@@ -210,8 +212,10 @@ STATIC const mp_rom_map_elem_t badge_module_globals_table[] = {
210212
{MP_ROM_QSTR(MP_QSTR_eink_busy), MP_ROM_PTR(&badge_eink_busy_obj)},
211213
{MP_ROM_QSTR(MP_QSTR_eink_busy_wait), MP_ROM_PTR(&badge_eink_busy_wait_obj)},
212214

215+
/*
213216
{MP_ROM_QSTR(MP_QSTR_display_picture),
214217
MP_ROM_PTR(&badge_display_picture_obj)},
218+
*/
215219

216220
#if defined(PORTEXP_PIN_NUM_CHRGSTAT) || defined(MPR121_PIN_NUM_CHRGSTAT)
217221
{MP_OBJ_NEW_QSTR(MP_QSTR_battery_charge_status),

esp32/modules/woezel.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,7 @@ def expandhome(s):
104104

105105
import ussl
106106
import usocket
107-
warn_ussl = True
108107
def url_open(url):
109-
global warn_ussl
110-
111108
if debug:
112109
print(url)
113110

@@ -128,9 +125,6 @@ def url_open(url):
128125

129126
if proto == "https:":
130127
s = ussl.wrap_socket(s, server_hostname=host)
131-
if warn_ussl:
132-
print("Warning: %s SSL certificate is not validated" % host)
133-
warn_ussl = False
134128

135129
# MicroPython rawsocket module supports file interface directly
136130
s.write("GET /%s HTTP/1.0\r\nHost: %s\r\n\r\n" % (urlpath, host))

extmod/modussl_mbedtls.c

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@
2323
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2424
* THE SOFTWARE.
2525
*/
26+
#define _GNU_SOURCE
2627

2728
#include "py/mpconfig.h"
2829
#if MICROPY_PY_USSL && MICROPY_SSL_MBEDTLS
2930

3031
#include <stdio.h>
3132
#include <string.h>
3233
#include <errno.h>
34+
#include <string.h>
3335

3436
#include "py/nlr.h"
3537
#include "py/runtime.h"
@@ -148,12 +150,24 @@ STATIC mp_obj_ssl_socket_t *socket_new(mp_obj_t sock, struct ssl_args *args) {
148150
assert(0);
149151
}
150152

151-
ret = mbedtls_x509_crt_parse(&o->cacert, wildcard_sha2017_org, 2151);
153+
bool sha2017_subdomain = false;
154+
if (args->server_hostname.u_obj != mp_const_none) {
155+
const char *sni = mp_obj_str_get_str(args->server_hostname.u_obj);
156+
char *ptr;
157+
sha2017_subdomain = ((ptr = strcasestr(sni, ".sha2017.org")) != NULL && ptr[12] == 0);
158+
if (sha2017_subdomain) {
159+
printf("Validating certificate for: %s\n", sni);
160+
} else {
161+
printf("Warning: %s SSL certificate is not validated\n", sni);
162+
}
163+
}
152164

153-
if(ret < 0)
154-
{
155-
printf("mbedtls_x509_crt_parse returned -0x%x\n\n", -ret);
156-
assert(0);
165+
if (sha2017_subdomain) {
166+
ret = mbedtls_x509_crt_parse_der(&o->cacert, wildcard_sha2017_org, 856);
167+
if(ret < 0) {
168+
printf("mbedtls_x509_crt_parse returned -0x%x\n\n", -ret);
169+
assert(0);
170+
}
157171
}
158172

159173
ret = mbedtls_ssl_config_defaults(&o->conf,
@@ -164,7 +178,12 @@ STATIC mp_obj_ssl_socket_t *socket_new(mp_obj_t sock, struct ssl_args *args) {
164178
assert(0);
165179
}
166180

167-
mbedtls_ssl_conf_authmode(&o->conf, MBEDTLS_SSL_VERIFY_REQUIRED);
181+
if (sha2017_subdomain) {
182+
mbedtls_ssl_conf_authmode(&o->conf, MBEDTLS_SSL_VERIFY_REQUIRED);
183+
mbedtls_ssl_conf_ca_chain(&o->conf, &o->cacert, NULL);
184+
} else {
185+
mbedtls_ssl_conf_authmode(&o->conf, MBEDTLS_SSL_VERIFY_NONE);
186+
}
168187
mbedtls_ssl_conf_rng(&o->conf, mbedtls_ctr_drbg_random, &o->ctr_drbg);
169188
mbedtls_ssl_conf_dbg(&o->conf, mbedtls_debug, NULL);
170189

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