Skip to content

Commit dcb650c

Browse files
jeplerdhalbert
authored andcommitted
pico w: add ssl module
Note: at this time, the ssl module on pico_w never verifies the server certificate. This means it does not actually provide a higher security level than regular socket / http protocols.
1 parent 1d25049 commit dcb650c

File tree

19 files changed

+905
-22
lines changed

19 files changed

+905
-22
lines changed

locale/circuitpython.pot

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,6 @@ msgstr ""
152152
msgid "%q must be >= %d"
153153
msgstr ""
154154

155-
#: py/argcheck.c
156-
msgid "%q must be >= 0"
157-
msgstr ""
158-
159-
#: shared-bindings/vectorio/Circle.c shared-bindings/vectorio/Rectangle.c
160-
msgid "%q must be >= 1"
161-
msgstr ""
162-
163155
#: shared-bindings/analogbufio/BufferedIn.c
164156
#: shared-bindings/audiocore/RawSample.c
165157
msgid "%q must be a bytearray or array of type 'h', 'H', 'b', or 'B'"
@@ -910,8 +902,7 @@ msgstr ""
910902
msgid "Error: Failure to bind"
911903
msgstr ""
912904

913-
#: ports/raspberrypi/bindings/rp2pio/StateMachine.c py/enum.c
914-
#: shared-bindings/_bleio/__init__.c shared-bindings/aesio/aes.c
905+
#: py/enum.c shared-bindings/_bleio/__init__.c shared-bindings/aesio/aes.c
915906
#: shared-bindings/alarm/__init__.c shared-bindings/busio/SPI.c
916907
#: shared-bindings/microcontroller/Pin.c
917908
#: shared-bindings/neopixel_write/__init__.c
@@ -1243,6 +1234,7 @@ msgid "Invalid size"
12431234
msgstr ""
12441235

12451236
#: ports/espressif/common-hal/ssl/SSLContext.c
1237+
#: ports/raspberrypi/common-hal/ssl/SSLSocket.c
12461238
msgid "Invalid socket for TLS"
12471239
msgstr ""
12481240

@@ -1569,10 +1561,12 @@ msgid "Only 8 or 16 bit mono with "
15691561
msgstr ""
15701562

15711563
#: ports/espressif/common-hal/wifi/__init__.c
1564+
#: ports/raspberrypi/common-hal/wifi/__init__.c
15721565
msgid "Only IPv4 addresses supported"
15731566
msgstr ""
15741567

15751568
#: ports/espressif/common-hal/socketpool/Socket.c
1569+
#: ports/raspberrypi/common-hal/socketpool/Socket.c
15761570
msgid "Only IPv4 sockets supported"
15771571
msgstr ""
15781572

@@ -1642,6 +1636,7 @@ msgid "Out of memory"
16421636
msgstr ""
16431637

16441638
#: ports/espressif/common-hal/socketpool/Socket.c
1639+
#: ports/raspberrypi/common-hal/socketpool/Socket.c
16451640
msgid "Out of sockets"
16461641
msgstr ""
16471642

@@ -1696,7 +1691,6 @@ msgid "Pin interrupt already in use"
16961691
msgstr ""
16971692

16981693
#: shared-bindings/adafruit_bus_device/spi_device/SPIDevice.c
1699-
#: shared-bindings/digitalio/DigitalInOut.c
17001694
msgid "Pin is input only"
17011695
msgstr ""
17021696

@@ -1916,6 +1910,7 @@ msgid "Slices not supported"
19161910
msgstr ""
19171911

19181912
#: ports/espressif/common-hal/socketpool/SocketPool.c
1913+
#: ports/raspberrypi/common-hal/socketpool/SocketPool.c
19191914
msgid "SocketPool can only be used with wifi.radio"
19201915
msgstr ""
19211916

@@ -2341,10 +2336,6 @@ msgstr ""
23412336
msgid "a bytes-like object is required"
23422337
msgstr ""
23432338

2344-
#: shared-bindings/i2ctarget/I2CTarget.c
2345-
msgid "address out of bounds"
2346-
msgstr ""
2347-
23482339
#: shared-bindings/i2ctarget/I2CTarget.c
23492340
msgid "addresses is empty"
23502341
msgstr ""
@@ -2814,10 +2805,6 @@ msgstr ""
28142805
msgid "destination buffer must be an array of type 'H' for bit_depth = 16"
28152806
msgstr ""
28162807

2817-
#: shared-bindings/audiobusio/PDMIn.c
2818-
msgid "destination_length must be an int >= 0"
2819-
msgstr ""
2820-
28212808
#: py/objdict.c
28222809
msgid "dict update sequence has wrong length"
28232810
msgstr ""
@@ -3241,6 +3228,10 @@ msgstr ""
32413228
msgid "invalid bits_per_pixel %d, must be, 1, 2, 4, 8, 16, 24, or 32"
32423229
msgstr ""
32433230

3231+
#: ports/raspberrypi/common-hal/ssl/SSLSocket.c
3232+
msgid "invalid cert"
3233+
msgstr ""
3234+
32443235
#: shared-bindings/bitmaptools/__init__.c
32453236
#, c-format
32463237
msgid "invalid element size %d for bits_per_pixel %d\n"
@@ -3267,6 +3258,10 @@ msgstr ""
32673258
msgid "invalid hostname"
32683259
msgstr ""
32693260

3261+
#: ports/raspberrypi/common-hal/ssl/SSLSocket.c
3262+
msgid "invalid key"
3263+
msgstr ""
3264+
32703265
#: py/compile.c
32713266
msgid "invalid micropython decorator"
32723267
msgstr ""

ports/espressif/common-hal/ssl/SSLSocket.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ mp_uint_t common_hal_ssl_sslsocket_send(ssl_sslsocket_obj_t *self, const uint8_t
158158

159159
if (err == ESP_ERR_MBEDTLS_SSL_SETUP_FAILED) {
160160
mp_raise_espidf_MemoryError();
161-
} else if (ESP_ERR_MBEDTLS_SSL_HANDSHAKE_FAILED) {
161+
} else if (err == ESP_ERR_MBEDTLS_SSL_HANDSHAKE_FAILED) {
162162
mp_raise_OSError_msg_varg(translate("Failed SSL handshake"));
163163
} else {
164164
mp_raise_OSError_msg_varg(translate("Unhandled ESP TLS error %d %d %x %d"), esp_tls_code, flags, err, sent);

ports/raspberrypi/Makefile

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,88 @@ SRC_C += \
276276
$(SRC_CYW43) \
277277
$(SRC_LWIP) \
278278

279+
ifeq ($(CIRCUITPY_SSL),1)
280+
CFLAGS += -isystem $(TOP)/mbedtls/include
281+
SRC_MBEDTLS := $(addprefix lib/mbedtls/library/, \
282+
aes.c \
283+
aesni.c \
284+
arc4.c \
285+
asn1parse.c \
286+
asn1write.c \
287+
base64.c \
288+
bignum.c \
289+
blowfish.c \
290+
camellia.c \
291+
ccm.c \
292+
certs.c \
293+
chacha20.c \
294+
chachapoly.c \
295+
cipher.c \
296+
cipher_wrap.c \
297+
cmac.c \
298+
ctr_drbg.c \
299+
debug.c \
300+
des.c \
301+
dhm.c \
302+
ecdh.c \
303+
ecdsa.c \
304+
ecjpake.c \
305+
ecp.c \
306+
ecp_curves.c \
307+
entropy.c \
308+
entropy_poll.c \
309+
gcm.c \
310+
havege.c \
311+
hmac_drbg.c \
312+
md2.c \
313+
md4.c \
314+
md5.c \
315+
md.c \
316+
md_wrap.c \
317+
oid.c \
318+
padlock.c \
319+
pem.c \
320+
pk.c \
321+
pkcs11.c \
322+
pkcs12.c \
323+
pkcs5.c \
324+
pkparse.c \
325+
pk_wrap.c \
326+
pkwrite.c \
327+
platform.c \
328+
platform_util.c \
329+
poly1305.c \
330+
ripemd160.c \
331+
rsa.c \
332+
rsa_internal.c \
333+
sha1.c \
334+
sha256.c \
335+
sha512.c \
336+
ssl_cache.c \
337+
ssl_ciphersuites.c \
338+
ssl_cli.c \
339+
ssl_cookie.c \
340+
ssl_srv.c \
341+
ssl_ticket.c \
342+
ssl_tls.c \
343+
timing.c \
344+
x509.c \
345+
x509_create.c \
346+
x509_crl.c \
347+
x509_crt.c \
348+
x509_csr.c \
349+
x509write_crt.c \
350+
x509write_csr.c \
351+
xtea.c \
352+
)
353+
SRC_C += $(SRC_MBEDTLS) mbedtls/mbedtls_port.c
354+
CFLAGS += \
355+
-isystem $(TOP)/lib/mbedtls/include \
356+
-DMBEDTLS_CONFIG_FILE='"mbedtls/mbedtls_config.h"' \
357+
358+
$(patsubst %.c,$(BUILD)/%.o,$(SRC_MBEDTLS))): CFLAGS += -Wno-suggest-attribute=format
359+
endif
360+
279361
SRC_COMMON_HAL_EXPANDED = $(addprefix shared-bindings/, $(SRC_COMMON_HAL)) \
280362
$(addprefix shared-bindings/, $(SRC_BINDINGS_ENUMS)) \
281363
$(addprefix common-hal/, $(SRC_COMMON_HAL))

ports/raspberrypi/boards/raspberry_pi_pico_w/mpconfigboard.mk

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ EXTERNAL_FLASH_DEVICES = "W25Q16JVxQ"
1111
CIRCUITPY__EVE = 1
1212

1313
CIRCUITPY_CYW43 = 1
14-
CIRCUITPY_SSL = 0
14+
CIRCUITPY_SSL = 1
15+
CIRCUITPY_SSL_MBEDTLS = 1
1516
CIRCUITPY_HASHLIB = 0
1617
CIRCUITPY_WEB_WORKFLOW = 0
1718
CIRCUITPY_MDNS = 0
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2020 Scott Shawcroft for Adafruit Industries
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#include "shared-bindings/ssl/SSLContext.h"
28+
#include "shared-bindings/ssl/SSLSocket.h"
29+
#include "shared-bindings/socketpool/SocketPool.h"
30+
31+
#include "py/runtime.h"
32+
#include "py/stream.h"
33+
34+
void common_hal_ssl_sslcontext_construct(ssl_sslcontext_obj_t *self) {
35+
}
36+
37+
void common_hal_ssl_sslcontext_load_verify_locations(ssl_sslcontext_obj_t *self,
38+
const char *cadata) {
39+
mp_raise_NotImplementedError(NULL);
40+
}
41+
42+
void common_hal_ssl_sslcontext_set_default_verify_paths(ssl_sslcontext_obj_t *self) {
43+
mp_raise_NotImplementedError(NULL);
44+
}
45+
46+
bool common_hal_ssl_sslcontext_get_check_hostname(ssl_sslcontext_obj_t *self) {
47+
return self->check_name;
48+
}
49+
50+
void common_hal_ssl_sslcontext_set_check_hostname(ssl_sslcontext_obj_t *self, bool value) {
51+
self->check_name = value;
52+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2020 Scott Shawcroft for Adafruit Industries
7+
* Copyright (c) 2022 Jeff Epler for Adafruit Industries
8+
*
9+
* Permission is hereby granted, free of charge, to any person obtaining a copy
10+
* of this software and associated documentation files (the "Software"), to deal
11+
* in the Software without restriction, including without limitation the rights
12+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
* copies of the Software, and to permit persons to whom the Software is
14+
* furnished to do so, subject to the following conditions:
15+
*
16+
* The above copyright notice and this permission notice shall be included in
17+
* all copies or substantial portions of the Software.
18+
*
19+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
* THE SOFTWARE.
26+
*/
27+
28+
#pragma once
29+
30+
#include "py/obj.h"
31+
32+
typedef struct {
33+
mp_obj_base_t base;
34+
bool check_name;
35+
} ssl_sslcontext_obj_t;

0 commit comments

Comments
 (0)