From f0e24109296e1980fdb740275745de0c0aba2168 Mon Sep 17 00:00:00 2001 From: andrey Date: Thu, 8 Apr 2021 11:53:10 +0300 Subject: [PATCH] PICrypt passwordHash fix hash and return, PICloud repair Server exit, fix PIAuth pass_hash gen --- libs/cloud/picloudclient.cpp | 2 +- libs/cloud/picloudserver.cpp | 13 +++++++------ libs/crypt/piauth.cpp | 4 ++-- libs/crypt/picrypt.cpp | 11 ++++++----- libs/main/cloud/picloudserver.h | 2 +- libs/main/io_devices/pibinarylog.cpp | 2 +- 6 files changed, 18 insertions(+), 16 deletions(-) diff --git a/libs/cloud/picloudclient.cpp b/libs/cloud/picloudclient.cpp index 82e640a4..89809bb9 100644 --- a/libs/cloud/picloudclient.cpp +++ b/libs/cloud/picloudclient.cpp @@ -45,8 +45,8 @@ PICloudClient::~PICloudClient() { cond_buff.notifyOne(); cond_connect.notifyOne(); } - //stop(); close(); + stop(); } diff --git a/libs/cloud/picloudserver.cpp b/libs/cloud/picloudserver.cpp index 6547e84e..28427c80 100644 --- a/libs/cloud/picloudserver.cpp +++ b/libs/cloud/picloudserver.cpp @@ -69,8 +69,8 @@ bool PICloudServer::closeDevice() { eth.stop(); clients_mutex.lock(); for (auto c : clients_) { - c->stop(); c->close(); + c->stop(); } clients_mutex.unlock(); eth.close(); @@ -111,8 +111,8 @@ PICloudServer::Client::~Client() { is_connected = false; cond_buff.notifyOne(); } - stop(); close(); + stop(); } @@ -167,13 +167,14 @@ void PICloudServer::_readed(PIByteArray & ba) { uint id = tcp.parseConnect(ba); clients_mutex.lock(); Client * oc = index_clients.value(id, nullptr); + clients_mutex.unlock(); if (oc) { - clients_mutex.unlock(); tcp.sendDisconnected(id); } else { piCoutObj << "new Client" << id; Client * c = new Client(this, id); - CONNECTU(c, deleted, this, clientDeleted) + CONNECTU(c, deleted, this, clientDeleted); + clients_mutex.lock(); clients_ << c; index_clients.insert(id, c); clients_mutex.unlock(); @@ -184,18 +185,18 @@ void PICloudServer::_readed(PIByteArray & ba) { uint id = tcp.parseDisconnect(ba); clients_mutex.lock(); Client * oc = index_clients.value(id, nullptr); + clients_mutex.unlock(); if (oc) { oc->is_connected = false; oc->close(); } - clients_mutex.unlock(); } break; case PICloud::TCP::Data: { PIPair d = tcp.parseDataServer(ba); clients_mutex.lock(); Client * oc = index_clients.value(d.first, nullptr); - if (oc && !d.second.isEmpty()) oc->pushBuffer(d.second); clients_mutex.unlock(); + if (oc && !d.second.isEmpty()) oc->pushBuffer(d.second); } break; default: break; diff --git a/libs/crypt/piauth.cpp b/libs/crypt/piauth.cpp index 23e64f57..dcb91369 100644 --- a/libs/crypt/piauth.cpp +++ b/libs/crypt/piauth.cpp @@ -30,7 +30,7 @@ PIAuth::PIAuth(const PIByteArray & sign) : PIObject() { void PIAuth::setServerPassword(const PIString & ps) { - pass_hash = crypt.passwordHash(ps, PIByteArray::fromHex("PIAuth")); + pass_hash = crypt.passwordHash(ps, PIString("PIAuth").toByteArray()); } @@ -127,7 +127,7 @@ PIAuth::State PIAuth::receive(PIByteArray & ba) { PIByteArray ph; passwordRequest(&ps); if (ps.isEmpty()) return disconnect(ba, "Canceled by user"); - ph = crypt.passwordHash(ps, PIByteArray::fromHex("PIAuth")); + ph = crypt.passwordHash(ps, PIString("PIAuth").toByteArray()); ps.fill(0); tba.clear(); tba << ph << auth_sign << sign_pk; diff --git a/libs/crypt/picrypt.cpp b/libs/crypt/picrypt.cpp index e5c79041..56ab0f29 100644 --- a/libs/crypt/picrypt.cpp +++ b/libs/crypt/picrypt.cpp @@ -376,19 +376,20 @@ PIByteArray PICrypt::passwordHash(const PIString & password, const PIByteArray & #ifdef crypto_pwhash_ALG_ARGON2I13 // char out[crypto_pwhash_STRBYTES]; PIByteArray pass = password.toUTF8(); - PIByteArray n; + PIByteArray n = hash(seed); PIByteArray ph; ph.resize(crypto_box_SEEDBYTES); n.resize(crypto_pwhash_SALTBYTES); // randombytes_buf(n.data(), n.size()); - crypto_shorthash(n.data(), seed.data(), seed.size(), PIByteArray(crypto_shorthash_KEYBYTES).data()); +// crypto_shorthash(n.data(), seed.data(), seed.size(), PIByteArray(crypto_shorthash_KEYBYTES).data()); int r = crypto_pwhash(ph.data(), ph.size(), (const char*)pass.data(), pass.size(), n.data(), crypto_pwhash_argon2i_opslimit_moderate(), crypto_pwhash_argon2i_memlimit_moderate(), crypto_pwhash_ALG_ARGON2I13); //crypto_pwhash_str(out, (const char*)pass.data(), pass.size(), crypto_pwhash_argon2i_opslimit_moderate(), crypto_pwhash_argon2i_memlimit_moderate()); pass.fill(0); if (r != 0) return PIByteArray(); - PIByteArray ret; - ret << ph << n << crypto_pwhash_argon2i_opslimit_moderate() << crypto_pwhash_argon2i_memlimit_moderate(); - return ret; + return ph; +// PIByteArray ret; +// ret << ph << n << crypto_pwhash_argon2i_opslimit_moderate() << crypto_pwhash_argon2i_memlimit_moderate(); +// return ret; #else return PIByteArray(); #endif diff --git a/libs/main/cloud/picloudserver.h b/libs/main/cloud/picloudserver.h index 79409c09..e7f423eb 100644 --- a/libs/main/cloud/picloudserver.h +++ b/libs/main/cloud/picloudserver.h @@ -59,7 +59,7 @@ public: void setServerName(const PIString & server_name); - PIVector clients() const;; + PIVector clients() const; EVENT1(newConnection, PICloudServer::Client * , client) diff --git a/libs/main/io_devices/pibinarylog.cpp b/libs/main/io_devices/pibinarylog.cpp index 07552d2e..1a8472dc 100644 --- a/libs/main/io_devices/pibinarylog.cpp +++ b/libs/main/io_devices/pibinarylog.cpp @@ -670,7 +670,7 @@ void PIBinaryLog::seekTo(int rindex) { if (rindex < index.size_s() && rindex >= 0) { file.seek(index[rindex].pos); moveIndex(index_pos.value(file.pos(), -1)); - double prev_pt = play_time; + //double prev_pt = play_time; play_time = index[rindex].timestamp.toMilliseconds(); lastrecord.timestamp = index[rindex].timestamp; if (play_mode == PlayRealTime) {