Unverified Commit 7696dcc7 authored by Jason2866's avatar Jason2866 Committed by GitHub

WebServer: use MD5Builder instead of mbedtls (#9123)

Backport of #8667
parent 911061c8
...@@ -24,12 +24,13 @@ ...@@ -24,12 +24,13 @@
#include <Arduino.h> #include <Arduino.h>
#include <esp32-hal-log.h> #include <esp32-hal-log.h>
#include <libb64/cencode.h> #include <libb64/cencode.h>
#include "esp_random.h"
#include "WiFiServer.h" #include "WiFiServer.h"
#include "WiFiClient.h" #include "WiFiClient.h"
#include "WebServer.h" #include "WebServer.h"
#include "FS.h" #include "FS.h"
#include "detail/RequestHandlersImpl.h" #include "detail/RequestHandlersImpl.h"
#include "mbedtls/md5.h" #include "MD5Builder.h"
static const char AUTHORIZATION_HEADER[] = "Authorization"; static const char AUTHORIZATION_HEADER[] = "Authorization";
...@@ -119,23 +120,11 @@ String WebServer::_extractParam(String& authReq,const String& param,const char d ...@@ -119,23 +120,11 @@ String WebServer::_extractParam(String& authReq,const String& param,const char d
} }
static String md5str(String &in){ static String md5str(String &in){
char out[33] = {0}; MD5Builder md5 = MD5Builder();
mbedtls_md5_context _ctx; md5.begin();
uint8_t i; md5.add(in);
uint8_t * _buf = (uint8_t*)malloc(16); md5.calculate();
if(_buf == NULL) return md5.toString();
return String(out);
memset(_buf, 0x00, 16);
mbedtls_md5_init(&_ctx);
mbedtls_md5_starts_ret(&_ctx);
mbedtls_md5_update_ret(&_ctx, (const uint8_t *)in.c_str(), in.length());
mbedtls_md5_finish_ret(&_ctx, _buf);
for(i = 0; i < 16; i++) {
sprintf(out + (i * 2), "%02x", _buf[i]);
}
out[32] = 0;
free(_buf);
return String(out);
} }
bool WebServer::authenticate(const char * username, const char * password){ bool WebServer::authenticate(const char * username, const char * password){
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment