@@ -48,6 +48,10 @@ const char *pass = STAPSK;
4848// The HTTPS server
4949BearSSL::WiFiServerSecure server (443 );
5050
51+ // #define USE_EC // Enable Elliptic Curve signed cert
52+
53+ #ifndef USE_EC
54+
5155// The server's private key which must be kept secret
5256const char server_private_key[] PROGMEM = R"EOF(
5357-----BEGIN PRIVATE KEY-----
@@ -104,6 +108,37 @@ UsQIIGpPVh1plR1vYNndDeBpRJSFkoJTkgAIrlFzSMwNebU0pg==
104108-----END CERTIFICATE-----
105109)EOF" ;
106110
111+ #else
112+ const char server_cert[] PROGMEM = R"EOF(
113+ -----BEGIN CERTIFICATE-----
114+ MIIB0zCCAXqgAwIBAgIJALANi2eTiGD/MAoGCCqGSM49BAMCMEUxCzAJBgNVBAYT
115+ AkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBXaWRn
116+ aXRzIFB0eSBMdGQwHhcNMTkwNjExMjIyOTU2WhcNMjAwNjEwMjIyOTU2WjBFMQsw
117+ CQYDVQQGEwJBVTETMBEGA1UECAwKU29tZS1TdGF0ZTEhMB8GA1UECgwYSW50ZXJu
118+ ZXQgV2lkZ2l0cyBQdHkgTHRkMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAExIkZ
119+ w7zjk6TGcScff1PAehuEGmKZTf8VfnkjyJH0IbBgZibZ+qwYGBEnkz4KpKv7TkHo
120+ W+j7F5EMcLcSrUIpy6NTMFEwHQYDVR0OBBYEFI6A0f+g0HyxUT6xrbVmRU79urbj
121+ MB8GA1UdIwQYMBaAFI6A0f+g0HyxUT6xrbVmRU79urbjMA8GA1UdEwEB/wQFMAMB
122+ Af8wCgYIKoZIzj0EAwIDRwAwRAIgWvy7ofQTGZMNqxUfe4gjtkU+C9AkQtaOMW2U
123+ 5xFFSvcCICvcGrQpoi7tRTq8xsXFmr8MYWgQTpVAtj6opXMQct/l
124+ -----END CERTIFICATE-----
125+ )EOF" ;
126+
127+ // The server's private key which must be kept secret
128+ const char server_private_key[] PROGMEM = R"EOF(
129+ -----BEGIN EC PARAMETERS-----
130+ BggqhkjOPQMBBw==
131+ -----END EC PARAMETERS-----
132+ -----BEGIN EC PRIVATE KEY-----
133+ MHcCAQEEIKyLR9/NT7ZdWM+2rklehveuk+jyIHJ+P8ZUQ392HOYvoAoGCCqGSM49
134+ AwEHoUQDQgAExIkZw7zjk6TGcScff1PAehuEGmKZTf8VfnkjyJH0IbBgZibZ+qwY
135+ GBEnkz4KpKv7TkHoW+j7F5EMcLcSrUIpyw==
136+ -----END EC PRIVATE KEY-----
137+ )EOF" ;
138+
139+ #endif
140+
141+
107142void setup () {
108143 Serial.begin (115200 );
109144 Serial.println ();
@@ -128,7 +163,11 @@ void setup() {
128163 // Attach the server private cert/key combo
129164 BearSSL::X509List *serverCertList = new BearSSL::X509List (server_cert);
130165 BearSSL::PrivateKey *serverPrivKey = new BearSSL::PrivateKey (server_private_key);
166+ #ifndef USE_EC
131167 server.setRSACert (serverCertList, serverPrivKey);
168+ #else
169+ server.setECCert (serverCertList, BR_KEYTYPE_KEYX|BR_KEYTYPE_SIGN, serverPrivKey);
170+ #endif
132171
133172 // Actually start accepting connections
134173 server.begin ();
@@ -147,11 +186,12 @@ static const char *HTTP_RES =
147186 " </html>\r\n " ;
148187
149188void loop () {
189+ static int cnt;
150190 BearSSL::WiFiClientSecure incoming = server.available ();
151191 if (!incoming) {
152192 return ;
153193 }
154- Serial.println (" Incoming connection...\n " );
194+ Serial.printf (" Incoming connection...%d \n " ,cnt++ );
155195
156196 // Ugly way to wait for \r\n (i.e. end of HTTP request which we don't actually parse here)
157197 uint32_t timeout=millis () + 1000 ;
0 commit comments