Skip to content

Commit 5309188

Browse files
Fix minor BearSSL API issues (#4901)
Fixes #4882 and updates GitHub certificate fingerprint to the current one in BearSSL_Validation example. When setting a authentication mode or stopping, clear all others out in case the object is being re-used. Add in a yield during the SSL handshake to allow a graceful timeout and not a WDT error when the remote server hiccups. Thanks to @Jeroen88 for finding and testing this.
1 parent fcf2ac5 commit 5309188

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

libraries/ESP8266WiFi/examples/BearSSL_Validation/BearSSL_Validation.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ instead of the while certificate. This is not nearly as secure as real
102102
X.509 validation, but is better than nothing.
103103
)EOF");
104104
BearSSL::WiFiClientSecure client;
105-
const uint8_t fp[20] = {0x35, 0x85, 0x74, 0xEF, 0x67, 0x35, 0xA7, 0xCE, 0x40, 0x69, 0x50, 0xF3, 0xC0, 0xF6, 0x80, 0xCF, 0x80, 0x3B, 0x2E, 0x19};
105+
const uint8_t fp[20] = {0x5F, 0xF1, 0x60, 0x31, 0x09, 0x04, 0x3E, 0xF2, 0x90, 0xD2, 0xB0, 0x8A, 0x50, 0x38, 0x04, 0xE8, 0x37, 0x9F, 0xBC, 0x76};
106106
client.setFingerprint(fp);
107107
fetchURL(&client, host, port, path);
108108
}

libraries/ESP8266WiFi/src/WiFiClientSecureBearSSL.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ void WiFiClientSecure::_clearAuthenticationSettings() {
7979
_use_self_signed = false;
8080
_knownkey = nullptr;
8181
_sk = nullptr;
82+
_ta = nullptr;
8283
}
8384

8485

@@ -177,6 +178,7 @@ void WiFiClientSecure::stop() {
177178
_client->abort();
178179
}
179180
WiFiClient::stop();
181+
_clearAuthenticationSettings();
180182
_freeSSL();
181183
}
182184

@@ -510,6 +512,7 @@ bool WiFiClientSecure::_wait_for_handshake() {
510512
if (br_ssl_engine_current_state(_eng) & BR_SSL_SENDAPP) {
511513
_handshake_done = true;
512514
}
515+
optimistic_yield(1000);
513516
}
514517
return _handshake_done;
515518
}

libraries/ESP8266WiFi/src/WiFiClientSecureBearSSL.h

+5
Original file line numberDiff line numberDiff line change
@@ -59,24 +59,29 @@ class WiFiClientSecure : public WiFiClient {
5959

6060
// Don't validate the chain, just accept whatever is given. VERY INSECURE!
6161
void setInsecure() {
62+
_clearAuthenticationSettings();
6263
_use_insecure = true;
6364
}
6465
// Assume a given public key, don't validate or use cert info at all
6566
void setKnownKey(const BearSSLPublicKey *pk, unsigned usages = BR_KEYTYPE_KEYX | BR_KEYTYPE_SIGN) {
67+
_clearAuthenticationSettings();
6668
_knownkey = pk;
6769
_knownkey_usages = usages;
6870
}
6971
// Only check SHA1 fingerprint of certificate
7072
void setFingerprint(const uint8_t fingerprint[20]) {
73+
_clearAuthenticationSettings();
7174
_use_fingerprint = true;
7275
memcpy_P(_fingerprint, fingerprint, 20);
7376
}
7477
// Accept any certificate that's self-signed
7578
void allowSelfSignedCerts() {
79+
_clearAuthenticationSettings();
7680
_use_self_signed = true;
7781
}
7882
// Install certificates of trusted CAs or specific site
7983
void setTrustAnchors(const BearSSLX509List *ta) {
84+
_clearAuthenticationSettings();
8085
_ta = ta;
8186
}
8287
// In cases when NTP is not used, app must set a time manually to check cert validity

0 commit comments

Comments
 (0)