Skip to content

Commit 4e5ba8f

Browse files
Apply suggestions from code review
Co-authored-by: Jan Procházka <[email protected]>
1 parent 5829954 commit 4e5ba8f

File tree

4 files changed

+13
-16
lines changed

4 files changed

+13
-16
lines changed

Diff for: libraries/WiFiClientSecure/examples/WiFiClientSecureProtocolUpgradeSTARTT/WiFIClientSecureProtocolUpgradeSTARTTLS.ino

+3-6
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@
4848
#define SMTP_PORT (587) // Standard (plaintext) submission port
4949
#endif
5050

51-
const char* ssid = WIFI_NETWORK; // your network SSID (name of wifi network)
52-
const char* password = WIFI_PASSWD; // your network password
53-
const char* server = SMTP_HOST; // Server URL
51+
const char* ssid = WIFI_NETWORK; // your network SSID (name of wifi network)
52+
const char* password = WIFI_PASSWD; // your network password
53+
const char* server = SMTP_HOST; // Server URL
5454
const int submission_port = SMTP_PORT; // submission port.
5555

5656
WiFiClientSecure client;
@@ -82,7 +82,6 @@ void setup() {
8282

8383
// skip verification for this demo. In production one should at the very least
8484
// enable TOFU; or ideally hardcode a (CA) certificate that is trusted.
85-
//
8685
client.setInsecure();
8786

8887
// Enable a plain-test start.
@@ -134,15 +133,13 @@ err:
134133

135134
// SMTP command repsponse start with three digits and a space;
136135
// or, for continuation, with three digits and a '-'.
137-
//
138136
static bool readAllSMTPLines() {
139137
String s = "";
140138
int i;
141139

142140
// blocking read; we cannot rely on a timeout
143141
// of a WiFiClientSecure read; as it is non
144142
// blocking.
145-
//
146143
const unsigned long timeout = 15 * 1000;
147144
unsigned long start = millis(); // the timeout is for the entire CMD block response; not per character/line.
148145
while (1) {

Diff for: libraries/WiFiClientSecure/src/WiFiClientSecure.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ int WiFiClientSecure::startTLS()
173173
};
174174
_stillinPlainStart = false;
175175
} else
176-
log_e("startTLS: ignoring StartTLS - as we should be secure already");
176+
log_i("startTLS: ignoring StartTLS - as we should be secure already");
177177
return 1;
178178
}
179179

@@ -285,7 +285,7 @@ int WiFiClientSecure::read(uint8_t *buf, size_t size)
285285
res = get_ssl_receive(sslclient, buf, size);
286286

287287
if (res < 0) {
288-
log_d("Closing connection on failed read");
288+
log_e("Closing connection on failed read");
289289
stop();
290290
return peeked?peeked:res;
291291
}
@@ -304,7 +304,7 @@ int WiFiClientSecure::available()
304304
res = data_to_read(sslclient);
305305

306306
if (res < 0 && !_stillinPlainStart) {
307-
log_e("Closing connection on failed avail check");
307+
log_e("Closing connection on failed available check");
308308
stop();
309309
return peeked?peeked:res;
310310
}
@@ -339,7 +339,7 @@ void WiFiClientSecure::setCACert (const char *rootCA)
339339
{
340340
if (bundle != NULL)
341341
{
342-
esp_crt_bundle_set(bundle,sizeof(bundle));
342+
esp_crt_bundle_set(bundle, sizeof(bundle));
343343
_use_ca_bundle = true;
344344
} else {
345345
esp_crt_bundle_detach(NULL);

Diff for: libraries/WiFiClientSecure/src/WiFiClientSecure.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ class WiFiClientSecure : public WiFiClient
8282

8383
// Certain protocols start in plain-text; and then have the client
8484
// give some STARTSSL command to `upgrade' the connection to TLS
85-
// or SSL. setting PlainStart to true (the default is false) enables
85+
// or SSL. Setting PlainStart to true (the default is false) enables
8686
// this. It is up to the application code to then call 'startTLS()'
8787
// at the right point to initialise the SSL or TLS upgrade.
88-
//
88+
8989
void setPlainStart() { _stillinPlainStart = true; };
9090
bool stillInPlainStart() { return _stillinPlainStart; };
9191
int startTLS();

Diff for: libraries/WiFiClientSecure/src/ssl_client.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ int start_ssl_client(sslclient_context *ssl_client, const IPAddress& ip, uint32_
227227

228228
// Note - this check for BOTH key and cert is relied on
229229
// later during cleanup.
230-
//
230+
231231
if (!insecure && cli_cert != NULL && cli_key != NULL) {
232232
mbedtls_x509_crt_init(&ssl_client->client_cert);
233233
mbedtls_pk_init(&ssl_client->client_key);
@@ -313,9 +313,9 @@ int ssl_starttls_handshake(sslclient_context *ssl_client)
313313
mbedtls_x509_crt_free(&ssl_client->ca_cert);
314314
}
315315

316-
// we know that we always have a client cert/key pair -- and we
317-
// cannot look into the prviate client_key pk struct for newer
318-
//versions of mbedtls. So rely on a public field of the cert
316+
// We know that we always have a client cert/key pair -- and we
317+
// cannot look into the private client_key pk struct for newer
318+
// versions of mbedtls. So rely on a public field of the cert
319319
// and infer that there is a key too.
320320
if (ssl_client->client_cert.version) {
321321
mbedtls_x509_crt_free(&ssl_client->client_cert);

0 commit comments

Comments
 (0)