Skip to content

Commit

Permalink
ESP32 v3 core
Browse files Browse the repository at this point in the history
  • Loading branch information
cotestatnt committed Jun 6, 2024
1 parent 5ae7229 commit 8ca4d6c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 7 deletions.
28 changes: 24 additions & 4 deletions src/ESPAsyncWebServer/src/AsyncWebSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,20 @@

#include <libb64/cencode.h>

#ifndef ESP8266
#include "mbedtls/sha1.h"
// #ifndef ESP8266
// #include "mbedtls/sha1.h"
// #else
// #include <Hash.h>
// #endif

#ifdef ESP8266
#include "mbedtls/sha1.h"
#else
#include <Hash.h>
#if ESP_ARDUINO_VERSION_MAJOR > 2
#include "SHA1Builder.h"
#else
#include <Hash.h>
#endif
#endif

#define MAX_PRINTF_LEN 64
Expand Down Expand Up @@ -619,7 +629,7 @@ void AsyncWebSocketClient::_queueMessage(AsyncWebSocketMessage *dataMessage){
return;
}
if(_messageQueue.length() >= WS_MAX_QUEUED_MESSAGES){
ets_printf(String(F("ERROR: Too many messages queued\n")).c_str());
log_e("ERROR: Too many messages queued");
// Serial.printf("%u Q3\n", _clientId);
delete dataMessage;
} else {
Expand Down Expand Up @@ -1349,13 +1359,23 @@ AsyncWebSocketResponse::AsyncWebSocketResponse(const String& key, AsyncWebSocket
#ifdef ESP8266
sha1(key + WS_STR_UUID, hash);
#else
#if ESP_ARDUINO_VERSION_MAJOR > 2
SHA1Builder sha1;
String input = key + WS_STR_UUID;
sha1.begin();
sha1.add(input);
sha1.calculate();
sha1.getBytes(hash);
#else

(String&)key += WS_STR_UUID;
mbedtls_sha1_context ctx;
mbedtls_sha1_init(&ctx);
mbedtls_sha1_starts_ret(&ctx);
mbedtls_sha1_update_ret(&ctx, (const unsigned char*)key.c_str(), key.length());
mbedtls_sha1_finish_ret(&ctx, hash);
mbedtls_sha1_free(&ctx);
#endif
#endif
base64_encodestate _state;
base64_init_encodestate(&_state);
Expand Down
23 changes: 20 additions & 3 deletions src/ESPAsyncWebServer/src/WebAuthentication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,16 @@
*/
#include "WebAuthentication.h"
#include <libb64/cencode.h>
#ifdef ESP32
#include "mbedtls/md5.h"


#ifdef ESP8266
#include "md5.h"
#else
#include "md5.h"
#if ESP_ARDUINO_VERSION_MAJOR > 2
#include "MD5Builder.h"
#else
#include "mbedtls/md5.h"
#endif
#endif


Expand Down Expand Up @@ -64,6 +70,16 @@ bool checkBasicAuthentication(const char * hash, const char * username, const ch
return false;
}

#if ESP_ARDUINO_VERSION_MAJOR > 2
static bool getMD5(uint8_t * data, uint16_t len, char * output){
MD5Builder md5;
md5.begin();
md5.add(data, len);
md5.calculate();
md5.getChars(output);
return true;
}
#else
static bool getMD5(uint8_t * data, uint16_t len, char * output){//33 bytes or more
#ifdef ESP32
mbedtls_md5_context _ctx;
Expand Down Expand Up @@ -91,6 +107,7 @@ static bool getMD5(uint8_t * data, uint16_t len, char * output){//33 bytes or mo
free(_buf);
return true;
}
#endif

static String genRandomMD5(){
#ifdef ESP8266
Expand Down

0 comments on commit 8ca4d6c

Please sign in to comment.