@@ -274,7 +274,7 @@ void MOcppMongooseClient::maintainWsConn() {
274274 #if MO_MG_USE_VERSION <= MO_MG_V708
275275 mg_base64_encode (token, len, base64);
276276 #else
277- mg_base64_encode (token, len, base64, sizeof (base64) );
277+ mg_base64_encode (token, len, base64, base64_length + 1 );
278278 #endif
279279 delete[] token;
280280
@@ -452,16 +452,24 @@ void MOcppMongooseClient::reloadConfigs() {
452452 {
453453 if (setting_auth_key_hex_str) {
454454 auto auth_key_hex = setting_auth_key_hex_str->getString ();
455+ auto auth_key_hex_len = strlen (setting_auth_key_hex_str->getString ());
456+ if (!validateAuthorizationKeyHex (auth_key_hex)) {
457+ MO_DBG_ERR (" AuthorizationKey stored with format error. Disable Basic Auth" );
458+ auth_key_hex_len = 0 ;
459+ }
460+
461+ auth_key_len = auth_key_hex_len / 2 ;
455462
456463 #if MO_MG_VERSION_614
457- cs_from_hex ((char *)auth_key, auth_key_hex, strlen (auth_key_hex) );
464+ cs_from_hex ((char *)auth_key, auth_key_hex, auth_key_hex_len );
458465 #elif MO_MG_USE_VERSION <= MO_MG_V713
459- mg_unhex (auth_key_hex, strlen (auth_key_hex) , auth_key);
466+ mg_unhex (auth_key_hex, auth_key_hex_len , auth_key);
460467 #else
461- mg_str_to_num (mg_str (auth_key_hex), 16 , auth_key, MO_AUTHKEY_LEN_MAX);
468+ for (size_t i = 0 ; i < auth_key_len; i++) {
469+ mg_str_to_num (mg_str_n (auth_key_hex + 2 *i, 2 ), 16 , auth_key + i, sizeof (uint8_t ));
470+ }
462471 #endif
463472
464- auth_key_len = strlen (setting_auth_key_hex_str->getString ()) / 2 ;
465473 auth_key[auth_key_len] = ' \0 ' ; // need null-termination as long as deprecated `const char *getAuthKey()` exists
466474 }
467475 }
0 commit comments