Skip to content

Commit 21889f9

Browse files
committed
Formatting improvements
1 parent c3ff7e0 commit 21889f9

File tree

4 files changed

+9
-23
lines changed

4 files changed

+9
-23
lines changed

Diff for: libraries/ESP32/examples/MD5Builder/MD5Builder.ino

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// has been phased out as insecure eons ago) by letting you create an
1010
// MD5 of the data the user entered; and then compare this to an MD5
1111
// string that you have put in your code.
12-
//
12+
1313
void setup() {
1414
Serial.begin(115200);
1515
while (!Serial) { delay(10); }
@@ -19,7 +19,6 @@ void setup() {
1919
// matches the original string.
2020
//
2121
// echo -n "Hello World" | openssl md5
22-
//
2322
{
2423
String md5 = "b10a8db164e0754105b7a99be72e3fe5";
2524
String password = "Hello World";
@@ -37,6 +36,7 @@ void setup() {
3736
else
3837
Serial.println("OK!");
3938
}
39+
4040
// Check that this also work if we add the password not as
4141
// a normal string - but as a string with the HEX values.
4242
{
@@ -60,6 +60,7 @@ void setup() {
6060
Serial.println("OK!");
6161

6262
}
63+
6364
// Check that this also work if we add the password as
6465
// an unsigned byte array.
6566
{
@@ -79,7 +80,6 @@ void setup() {
7980
Serial.println("OK!");
8081

8182
// And also check that we can compare this as pure, raw, bytes
82-
//
8383
uint8_t raw[16] = { 0xb1, 0x0a, 0x8d, 0xb1, 0x64, 0xe0, 0x75, 0x41,
8484
0x05, 0xb7, 0xa9, 0x9b, 0xe7, 0x2e, 0x3f, 0xe5
8585
};

Diff for: libraries/WebServer/examples/HttpBasicAuthSHA1/HttpBasicAuthSHA1.ino

-4
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,20 @@ WebServer server(80);
1515

1616
// Passwords as plaintext - human readable and easily visible in
1717
// the sourcecode and in the firmware/binary.
18-
//
1918
const char* www_username = "admin";
2019
const char* www_password = "esp32";
2120

2221
// The sha1 of 'esp32' (without the trailing \0) expressed as 20
2322
// bytes of hex. Created by for example 'echo -n esp32 | openssl sha1'
2423
// or http://www.sha1-online.com.
25-
//
2624
const char* www_username_hex = "hexadmin";
2725
const char* www_password_hex = "8cb124f8c277c16ec0b2ee00569fd151a08e342b";
2826

2927
// The same; but now expressed as a base64 string (e.g. as commonly used
3028
// by webservers). Created by ` echo -n esp32 | openssl sha1 -binary | openssl base64`
31-
//
3229
const char* www_username_base64 = "base64admin";
3330
const char* www_password_base64 = "jLEk+MJ3wW7Asu4AVp/RUaCONCs=";
3431

35-
3632
void setup() {
3733
Serial.begin(115200);
3834
while (!Serial) { delay(10); }

Diff for: libraries/WebServer/examples/HttpBasicAuthSHA1orBearerToken/HttpBasicAuthSHA1orBearerToken.ino

+4-10
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
#include <WebServer.h>
55
#include "mbedtls/sha1.h"
66

7-
8-
/// We have two options - we either come in with a bearer
7+
// We have two options - we either come in with a bearer
98
// token - i.e. a special header or API token; or we
109
// get a normal HTTP style basic auth prompt.
1110
//
@@ -18,11 +17,11 @@
1817

1918
// Create the secet token SHA1 with:
2019
// echo -n SecritToken | openssl sha1
21-
//
20+
2221
String secret_token_hex = "d2cce6b472959484a21c3194080c609b8a2c910b";
2322

2423
// Wifi credentials
25-
//
24+
2625
const char* ssid = "........";
2726
const char* password = "........";
2827

@@ -36,20 +35,17 @@ WebServer server(80);
3635
// The sha1 of 'esp32' (without the trailing \0) expressed as 20
3736
// bytes of hex. Created by for example 'echo -n esp32 | openssl sha1'
3837
// or http://www.sha1-online.com.
39-
//
4038
const char* www_username_hex = "hexadmin";
4139
const char* www_password_hex = "8cb124f8c277c16ec0b2ee00569fd151a08e342b";
4240

4341
// The same; but now expressed as a base64 string (e.g. as commonly used
4442
// by webservers). Created by ` echo -n esp32 | openssl sha1 -binary | openssl base64`
45-
//
4643
const char* www_username_base64 = "base64admin";
4744
const char* www_password_base64 = "jLEk+MJ3wW7Asu4AVp/RUaCONCs=";
4845

4946
static unsigned char _bearer[20];
5047
String * check_bearer_or_auth(HTTPAuthMethod mode, String authReq, String params[]) {
5148
// we expect authReq to be "bearer some-secret"
52-
//
5349
String lcAuthReq = authReq;
5450
lcAuthReq.toLowerCase();
5551
if (mode == OTHER_AUTH && (lcAuthReq.startsWith("bearer "))) {
@@ -64,7 +60,6 @@ String * check_bearer_or_auth(HTTPAuthMethod mode, String authReq, String params
6460
};
6561

6662
// that failed - so do a normal auth
67-
//
6863
return server.authenticateBasicSHA1(www_username_hex, www_password_hex) ?
6964
new String(params[0]) : NULL;
7065
};
@@ -82,9 +77,8 @@ void setup() {
8277
ArduinoOTA.begin();
8378

8479
// Convert token to a convenient binary representation.
85-
//
8680
size_t len = HEXBuilder::hex2bytes(_bearer,sizeof(_bearer),secret_token_hex);
87-
if (len != 20)
81+
if (len != 20)
8882
Serial.println("Bearer token does not look like a valid SHA1 hex string ?!");
8983

9084
server.on("/", []() {

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

+2-6
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ static const char WWW_Authenticate[] = "WWW-Authenticate";
4343
static const char Content_Length[] = "Content-Length";
4444
static const char ETAG_HEADER[] = "If-None-Match";
4545

46-
4746
WebServer::WebServer(IPAddress addr, int port)
4847
: _corsEnabled(false)
4948
, _server(addr, port)
@@ -151,7 +150,6 @@ bool WebServer::authenticateBasicSHA1(const char * _username, const char * _sha1
151150
// we can either decode _sha1base64orHex and then compare the 20 bytes;
152151
// or encode the sha we calculated. We pick the latter as encoding of a
153152
// fixed array of 20 bytes s safer than operating on something external.
154-
//
155153
#define _H2D(x) (((x)>='0' && ((x) <='9')) ? ((x)-'0') : (((x)>='a' && (x)<='f') ? ((x)-'a'+10) : 0))
156154
#define H2D(x) (_H2D(tolower((x))))
157155
if (strlen(_sha1Base64orHex) == 20 * 2) {
@@ -216,7 +214,6 @@ bool WebServer::authenticate(THandlerFunctionAuthCheck fn) {
216214
log_v("%s", authReq.c_str());
217215

218216
// extracting required parameters for RFC 2069 simpler Digest
219-
//
220217
String _username = _extractParam(authReq,F("username=\""),'\"');
221218
String _realm = _extractParam(authReq, F("realm=\""),'\"');
222219
String _uri = _extractParam(authReq, F("uri=\""),'\"');
@@ -239,14 +236,13 @@ bool WebServer::authenticate(THandlerFunctionAuthCheck fn) {
239236
String _response = _extractParam(authReq, F("response=\""),'\"');
240237
String _opaque = _extractParam(authReq, F("opaque=\""),'\"');
241238

242-
if((!_realm.length()) || (!_nonce.length()) || (!_uri.length()) || (!_response.length()) || (!_opaque.length()))
239+
if((!_realm.length()) || (!_nonce.length()) || (!_uri.length()) || (!_response.length()) || (!_opaque.length()))
243240
goto exf;
244241

245-
if((_opaque != _sopaque) || (_nonce != _snonce) || (_realm != _srealm))
242+
if((_opaque != _sopaque) || (_nonce != _snonce) || (_realm != _srealm))
246243
goto exf;
247244

248245
// parameters for the RFC 2617 newer Digest
249-
//
250246
String _nc,_cnonce;
251247
if(authReq.indexOf(FPSTR(qop_auth)) != -1 || authReq.indexOf(FPSTR(qop_auth_quoted)) != -1) {
252248
_nc = _extractParam(authReq, F("nc="), ',');

0 commit comments

Comments
 (0)