diff --git a/src/ESPAsyncWebServer/src/AsyncWebSocket.cpp b/src/ESPAsyncWebServer/src/AsyncWebSocket.cpp index fde70e43..497a7854 100644 --- a/src/ESPAsyncWebServer/src/AsyncWebSocket.cpp +++ b/src/ESPAsyncWebServer/src/AsyncWebSocket.cpp @@ -23,10 +23,20 @@ #include -#ifndef ESP8266 -#include "mbedtls/sha1.h" +// #ifndef ESP8266 +// #include "mbedtls/sha1.h" +// #else +// #include +// #endif + +#ifdef ESP8266 + #include "mbedtls/sha1.h" #else -#include + #if ESP_ARDUINO_VERSION_MAJOR > 2 + #include "SHA1Builder.h" + #else + #include + #endif #endif #define MAX_PRINTF_LEN 64 @@ -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 { @@ -1349,6 +1359,15 @@ 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); @@ -1356,6 +1375,7 @@ AsyncWebSocketResponse::AsyncWebSocketResponse(const String& key, AsyncWebSocket 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); diff --git a/src/ESPAsyncWebServer/src/WebAuthentication.cpp b/src/ESPAsyncWebServer/src/WebAuthentication.cpp index 1a22afdf..7fa30ad4 100644 --- a/src/ESPAsyncWebServer/src/WebAuthentication.cpp +++ b/src/ESPAsyncWebServer/src/WebAuthentication.cpp @@ -20,10 +20,16 @@ */ #include "WebAuthentication.h" #include -#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 @@ -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; @@ -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