Skip to content

Commit 45e9aea

Browse files
author
Dmitriy Nabok
committed
added SHA512 password encryption
1 parent 8faa51e commit 45e9aea

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/ucentral-client/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ platform/plat.a:
1919

2020
ucentral-client: ucentral-client.o proto.o platform/plat.a \
2121
ucentral-json-parser.o ucentral-log.o router-utils.o base64.o
22-
g++ -g -o $@ $^ -lcurl -lwebsockets -lcjson -lssl -lcrypto -lpthread -ljsoncpp -lresolv -lhiredis -ldbus-1
22+
g++ -g -o $@ $^ -lcurl -lwebsockets -lcjson -lssl -lcrypto -lpthread -ljsoncpp -lresolv -lhiredis -ldbus-1 -lcrypt
2323

2424
test:
2525
@echo "========= running unit tests ========="

src/ucentral-client/platform/larch-sonic/system.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,15 @@
33
#include <utils.hpp>
44

55
#define UC_LOG_COMPONENT UC_LOG_COMPONENT_PLAT
6-
#include <ucentral-log.h>
6+
7+
#define HASH_SHA512_TYPE "$6$"
8+
#define HASH_SHA512_SALT "c53N"
9+
#define HASH_SHA512_CONFIG HASH_SHA512_TYPE HASH_SHA512_SALT
10+
11+
#include <crypt.h>
712
#include <simppl/dispatcher.h>
813
#include <simppl/stub.h>
14+
#include <ucentral-log.h>
915

1016
namespace larch {
1117

@@ -15,13 +21,21 @@ void apply_system_password_config(struct plat_cfg *cfg)
1521
{
1622
try
1723
{
24+
struct crypt_data cd;
25+
memset(&cd, 0, sizeof cd);
26+
27+
std::string hash = crypt_r(cfg->unit.system.password, HASH_SHA512_CONFIG, &cd);
28+
1829
simppl::dbus::Dispatcher disp{"bus:system"};
1930
simppl::dbus::Stub<org::SONiC::HostService::system_password> stub{
2031
disp,
2132
"org.SONiC.HostService",
2233
"/org/SONiC/HostService/system_password"};
2334

24-
stub.update(cfg->unit.system.password);
35+
const auto ret = stub.update(hash);
36+
UC_LOG_INFO("system_password update returned %d: %s",
37+
std::get<0>(ret),
38+
std::get<1>(ret).c_str());
2539
}
2640
catch (const std::exception &ex)
2741
{

0 commit comments

Comments
 (0)