@@ -25,6 +25,7 @@ SOFTWARE.
2525#include " CentralSystemEventsHandler.h"
2626#include " ChargePointDatabase.h"
2727
28+ #include < array>
2829#include < iostream>
2930#include < random>
3031#include < sstream>
@@ -99,7 +100,8 @@ bool CentralSystemEventsHandler::checkCredentials(const std::string& chargepoint
99100{
100101 bool ret = false ;
101102
102- cout << " Check credentials for [" << chargepoint_id << " ] : " << password << endl;
103+ std::string hex_encoded_password = ocpp::helpers::toHexString (password);
104+ cout << " Check credentials for [" << chargepoint_id << " ] : " << hex_encoded_password << endl;
103105
104106 // HTTP Basic Authentication is for Charge Points configured with Security Profile 1 or 2 only
105107
@@ -111,7 +113,7 @@ bool CentralSystemEventsHandler::checkCredentials(const std::string& chargepoint
111113 {
112114 if ((security_profile == 1u ) || (security_profile == 2u ))
113115 {
114- ret = (password == authent_key);
116+ ret = (hex_encoded_password == authent_key);
115117 }
116118 else
117119 {
@@ -257,14 +259,18 @@ ocpp::types::RegistrationStatus CentralSystemEventsHandler::ChargePointRequestHa
257259 }
258260 else
259261 {
260- // Generate an authent key for the charge point : minimal 16 bytes, max : 20 bytes
261- std::stringstream ss_authent_key;
262- ss_authent_key << std::hex;
263- for (int i = 0 ; i < 5 ; i++)
262+ // Generate an authent key for the charge point : minimal 8 bytes, max : 20 bytes
263+ std::mt19937 rand_gen;
264+ std::uniform_int_distribution<unsigned int > rand_distrib;
265+ std::random_device rd;
266+ rand_gen.seed (rd ());
267+
268+ std::array<uint8_t , 17u > authent_key_bytes;
269+ for (auto & val : authent_key_bytes)
264270 {
265- ss_authent_key << std::setfill ( ' 0 ' ) << std::setw ( 4 ) << std::rand ( );
271+ val = static_cast < uint8_t >( rand_distrib (rand_gen) );
266272 }
267- m_authent_key = ss_authent_key. str ( );
273+ m_authent_key = ocpp::helpers::toHexString (authent_key_bytes );
268274
269275 // Add the charge point to the database
270276 m_chargepoint_db.addChargePoint (this ->proxy ()->identifier (), serial_number, vendor, model, 0 , m_authent_key);
0 commit comments