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_connect.notifyOne();
}
//stop();
close();
stop();
}

View File

@@ -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);
if (oc) {
clients_mutex.unlock();
if (oc) {
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<uint, PIByteArray> 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;

View File

@@ -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;

View File

@@ -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

View File

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

View File

@@ -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) {