PICrypt passwordHash fix hash and return, PICloud repair Server exit, fix PIAuth pass_hash gen

This commit is contained in:
2021-04-08 11:53:10 +03:00
parent 4584d9c639
commit f0e2410929
6 changed files with 18 additions and 16 deletions

View File

@@ -45,8 +45,8 @@ PICloudClient::~PICloudClient() {
cond_buff.notifyOne(); cond_buff.notifyOne();
cond_connect.notifyOne(); cond_connect.notifyOne();
} }
//stop();
close(); close();
stop();
} }

View File

@@ -69,8 +69,8 @@ bool PICloudServer::closeDevice() {
eth.stop(); eth.stop();
clients_mutex.lock(); clients_mutex.lock();
for (auto c : clients_) { for (auto c : clients_) {
c->stop();
c->close(); c->close();
c->stop();
} }
clients_mutex.unlock(); clients_mutex.unlock();
eth.close(); eth.close();
@@ -111,8 +111,8 @@ PICloudServer::Client::~Client() {
is_connected = false; is_connected = false;
cond_buff.notifyOne(); cond_buff.notifyOne();
} }
stop();
close(); close();
stop();
} }
@@ -167,13 +167,14 @@ void PICloudServer::_readed(PIByteArray & ba) {
uint id = tcp.parseConnect(ba); uint id = tcp.parseConnect(ba);
clients_mutex.lock(); clients_mutex.lock();
Client * oc = index_clients.value(id, nullptr); Client * oc = index_clients.value(id, nullptr);
clients_mutex.unlock();
if (oc) { if (oc) {
clients_mutex.unlock();
tcp.sendDisconnected(id); tcp.sendDisconnected(id);
} else { } else {
piCoutObj << "new Client" << id; piCoutObj << "new Client" << id;
Client * c = new Client(this, id); Client * c = new Client(this, id);
CONNECTU(c, deleted, this, clientDeleted) CONNECTU(c, deleted, this, clientDeleted);
clients_mutex.lock();
clients_ << c; clients_ << c;
index_clients.insert(id, c); index_clients.insert(id, c);
clients_mutex.unlock(); clients_mutex.unlock();
@@ -184,18 +185,18 @@ void PICloudServer::_readed(PIByteArray & ba) {
uint id = tcp.parseDisconnect(ba); uint id = tcp.parseDisconnect(ba);
clients_mutex.lock(); clients_mutex.lock();
Client * oc = index_clients.value(id, nullptr); Client * oc = index_clients.value(id, nullptr);
clients_mutex.unlock();
if (oc) { if (oc) {
oc->is_connected = false; oc->is_connected = false;
oc->close(); oc->close();
} }
clients_mutex.unlock();
} break; } break;
case PICloud::TCP::Data: { case PICloud::TCP::Data: {
PIPair<uint, PIByteArray> d = tcp.parseDataServer(ba); PIPair<uint, PIByteArray> d = tcp.parseDataServer(ba);
clients_mutex.lock(); clients_mutex.lock();
Client * oc = index_clients.value(d.first, nullptr); Client * oc = index_clients.value(d.first, nullptr);
if (oc && !d.second.isEmpty()) oc->pushBuffer(d.second);
clients_mutex.unlock(); clients_mutex.unlock();
if (oc && !d.second.isEmpty()) oc->pushBuffer(d.second);
} break; } break;
default: default:
break; break;

View File

@@ -30,7 +30,7 @@ PIAuth::PIAuth(const PIByteArray & sign) : PIObject() {
void PIAuth::setServerPassword(const PIString & ps) { 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; PIByteArray ph;
passwordRequest(&ps); passwordRequest(&ps);
if (ps.isEmpty()) return disconnect(ba, "Canceled by user"); 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); ps.fill(0);
tba.clear(); tba.clear();
tba << ph << auth_sign << sign_pk; tba << ph << auth_sign << sign_pk;

View File

@@ -376,19 +376,20 @@ PIByteArray PICrypt::passwordHash(const PIString & password, const PIByteArray &
#ifdef crypto_pwhash_ALG_ARGON2I13 #ifdef crypto_pwhash_ALG_ARGON2I13
// char out[crypto_pwhash_STRBYTES]; // char out[crypto_pwhash_STRBYTES];
PIByteArray pass = password.toUTF8(); PIByteArray pass = password.toUTF8();
PIByteArray n; PIByteArray n = hash(seed);
PIByteArray ph; PIByteArray ph;
ph.resize(crypto_box_SEEDBYTES); ph.resize(crypto_box_SEEDBYTES);
n.resize(crypto_pwhash_SALTBYTES); n.resize(crypto_pwhash_SALTBYTES);
// randombytes_buf(n.data(), n.size()); // 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); 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()); //crypto_pwhash_str(out, (const char*)pass.data(), pass.size(), crypto_pwhash_argon2i_opslimit_moderate(), crypto_pwhash_argon2i_memlimit_moderate());
pass.fill(0); pass.fill(0);
if (r != 0) return PIByteArray(); if (r != 0) return PIByteArray();
PIByteArray ret; return ph;
ret << ph << n << crypto_pwhash_argon2i_opslimit_moderate() << crypto_pwhash_argon2i_memlimit_moderate(); // PIByteArray ret;
return ret; // ret << ph << n << crypto_pwhash_argon2i_opslimit_moderate() << crypto_pwhash_argon2i_memlimit_moderate();
// return ret;
#else #else
return PIByteArray(); return PIByteArray();
#endif #endif

View File

@@ -59,7 +59,7 @@ public:
void setServerName(const PIString & server_name); void setServerName(const PIString & server_name);
PIVector<Client *> clients() const;; PIVector<Client *> clients() const;
EVENT1(newConnection, PICloudServer::Client * , client) EVENT1(newConnection, PICloudServer::Client * , client)

View File

@@ -670,7 +670,7 @@ void PIBinaryLog::seekTo(int rindex) {
if (rindex < index.size_s() && rindex >= 0) { if (rindex < index.size_s() && rindex >= 0) {
file.seek(index[rindex].pos); file.seek(index[rindex].pos);
moveIndex(index_pos.value(file.pos(), -1)); moveIndex(index_pos.value(file.pos(), -1));
double prev_pt = play_time; //double prev_pt = play_time;
play_time = index[rindex].timestamp.toMilliseconds(); play_time = index[rindex].timestamp.toMilliseconds();
lastrecord.timestamp = index[rindex].timestamp; lastrecord.timestamp = index[rindex].timestamp;
if (play_mode == PlayRealTime) { if (play_mode == PlayRealTime) {