Skip to content

Commit 7696dcc

Browse files
authored
WebServer: use MD5Builder instead of mbedtls (espressif#9123)
Backport of espressif#8667
1 parent 911061c commit 7696dcc

File tree

1 file changed

+7
-18
lines changed

1 file changed

+7
-18
lines changed

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

+7-18
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@
2424
#include <Arduino.h>
2525
#include <esp32-hal-log.h>
2626
#include <libb64/cencode.h>
27+
#include "esp_random.h"
2728
#include "WiFiServer.h"
2829
#include "WiFiClient.h"
2930
#include "WebServer.h"
3031
#include "FS.h"
3132
#include "detail/RequestHandlersImpl.h"
32-
#include "mbedtls/md5.h"
33+
#include "MD5Builder.h"
3334

3435

3536
static const char AUTHORIZATION_HEADER[] = "Authorization";
@@ -119,23 +120,11 @@ String WebServer::_extractParam(String& authReq,const String& param,const char d
119120
}
120121

121122
static String md5str(String &in){
122-
char out[33] = {0};
123-
mbedtls_md5_context _ctx;
124-
uint8_t i;
125-
uint8_t * _buf = (uint8_t*)malloc(16);
126-
if(_buf == NULL)
127-
return String(out);
128-
memset(_buf, 0x00, 16);
129-
mbedtls_md5_init(&_ctx);
130-
mbedtls_md5_starts_ret(&_ctx);
131-
mbedtls_md5_update_ret(&_ctx, (const uint8_t *)in.c_str(), in.length());
132-
mbedtls_md5_finish_ret(&_ctx, _buf);
133-
for(i = 0; i < 16; i++) {
134-
sprintf(out + (i * 2), "%02x", _buf[i]);
135-
}
136-
out[32] = 0;
137-
free(_buf);
138-
return String(out);
123+
MD5Builder md5 = MD5Builder();
124+
md5.begin();
125+
md5.add(in);
126+
md5.calculate();
127+
return md5.toString();
139128
}
140129

141130
bool WebServer::authenticate(const char * username, const char * password){

0 commit comments

Comments
 (0)