ssl certificates in hex format

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
ttmetro
Posts: 104
Joined: Mon Jul 31, 2017 12:44 am

ssl certificates in hex format

Post by ttmetro » Thu Dec 09, 2021 9:45 pm

I'm trying to get the https server example working (https://github.com/micropython/micropyt ... ver_ssl.py) and am stuck creating the certificates in the correct hex format. What I currently have:

Code: Select all

cat << EOF >cert.conf
[req]
distinguished_name = req_distinguished_name
x509_extensions = v3_req
prompt = no
[req_distinguished_name]
C = US
ST = CA
O = MicroPython Webserver
[v3_req]
keyUsage = critical, digitalSignature, keyAgreement
extendedKeyUsage = serverAuth
subjectAltName = @alt_names
[alt_names]
DNS.1 = 10.39.40.168
IP.1  = 10.39.40.168
EOF

openssl req -x509 -nodes -days 3650 -newkey rsa:2048 \
    -keyout cert.key -out cert.crt -config cert.conf       
The files

Code: Select all

cert.key
and

Code: Select all

cert.crt 
work correctly on a host (CPython). But it look like for MicroPython I need them in hex format. How can I convert them?
Bernhard Boser

ttmetro
Posts: 104
Joined: Mon Jul 31, 2017 12:44 am

Re: ssl certificates in hex format

Post by ttmetro » Mon Dec 13, 2021 3:18 am

Adding

Code: Select all

-outform PEM
to the openssl command and reading the certificates (after stripping the first and last line) in MicroPython with

Code: Select all

with open('/ssl/cert.key') as f:
    key  = binascii.a2b_base64(f.read())

with open('/ssl/cert.crt') as f:
    cert = binascii.a2b_base64(f.read())
solves the problem.
Bernhard Boser

ttmetro
Posts: 104
Joined: Mon Jul 31, 2017 12:44 am

Re: ssl certificates in hex format

Post by ttmetro » Mon Dec 13, 2021 6:57 pm

In case anyone else runs into this issue - I've put an example at https://iot49.org/projects/internet/soc ... ure-server.
Bernhard Boser

Post Reply