#!/bin/bash # This script generates a self-signed certificate for use by the ESP8266 # Replace your-name-here with somethine appropriate before running and use # the generated .H files in your code as follows: # # static const uint8_t rsakey[] PROGMEM = { # #include "key.h" # }; # # static const uint8_t x509[] PROGMEM = { # #include "x509.h" # }; # # .... # WiFiServerSecure server(443); # server.setServerKeyAndCert_P(rsakey, sizeof(rsakey), x509, sizeof(x509)); # .... # 1024 or 512. 512 saves memory... BITS=512 C=$PWD pushd /tmp openssl genrsa -out tls.ca_key.pem $BITS openssl genrsa -out tls.key_$BITS.pem $BITS openssl rsa -in tls.key_$BITS.pem -out tls.key_$BITS -outform DER cat > certs.conf < "$C/key.h" xxd -i tls.x509_$BITS.cer | sed 's/.*{//' | sed 's/\};//' | sed 's/unsigned.*//' > "$C/x509.h" rm -f tls.ca_key.pem tls.key_$BITS.pem tls.key_$BITS certs.conf tls.ca_x509.req tls.x509_$BITS.req tls.ca_x509.pem tls.x509_$BITS.pem tls.srl tls.x509_$BITS.cer tls.ca_x509.cer popd