add profiling messages for password hash, if it last to long

This commit is contained in:
Dario 2020-07-14 20:41:59 +02:00
parent c37eff474a
commit 92de466261
2 changed files with 14 additions and 3 deletions

View File

@ -3,6 +3,7 @@
#include "sodium.h" #include "sodium.h"
#include "../ServerConfig.h" #include "../ServerConfig.h"
#include <assert.h> #include <assert.h>
#include "../lib/Profiler.h"
AuthenticatedEncryption::AuthenticatedEncryption() AuthenticatedEncryption::AuthenticatedEncryption()
: mOpsLimit(10), mMemLimit(33554432), mAlgo(2), mEncryptionKey(nullptr), mEncryptionKeyHash(0) : mOpsLimit(10), mMemLimit(33554432), mAlgo(2), mEncryptionKey(nullptr), mEncryptionKeyHash(0)
@ -31,8 +32,12 @@ AuthenticatedEncryption::ResultType AuthenticatedEncryption::createKey(const std
auto app_secret = ServerConfig::g_CryptoAppSecret; auto app_secret = ServerConfig::g_CryptoAppSecret;
assert(app_secret); assert(app_secret);
Profiler timeUsed;
std::unique_lock<std::shared_mutex> _lock(mWorkingMutex); std::unique_lock<std::shared_mutex> _lock(mWorkingMutex);
if (timeUsed.millis() > 10) {
printf("[AuthenticatedEncryption::createKey] wait %s on getting lock\n", timeUsed.string().data());
timeUsed.reset();
}
// use hash512 because existing data where calculated with that, but could be also changed to hash256 // use hash512 because existing data where calculated with that, but could be also changed to hash256
auto hash512_salt = mm->getFreeMemory(crypto_hash_sha512_BYTES); // need at least crypto_pwhash_SALTBYTES 16U auto hash512_salt = mm->getFreeMemory(crypto_hash_sha512_BYTES); // need at least crypto_pwhash_SALTBYTES 16U
@ -44,6 +49,10 @@ AuthenticatedEncryption::ResultType AuthenticatedEncryption::createKey(const std
crypto_hash_sha512_update(&state, *app_secret, app_secret->size()); crypto_hash_sha512_update(&state, *app_secret, app_secret->size());
crypto_hash_sha512_final(&state, *hash512_salt); crypto_hash_sha512_final(&state, *hash512_salt);
if (timeUsed.millis() > 200) {
printf("[AuthenticatedEncryption::createKey] %s calculating sha512\n", timeUsed.string().data());
timeUsed.reset();
}
//unsigned char* key = (unsigned char *)malloc(crypto_box_SEEDBYTES); // 32U //unsigned char* key = (unsigned char *)malloc(crypto_box_SEEDBYTES); // 32U
//ObfusArray* key = new ObfusArray(crypto_box_SEEDBYTES); //ObfusArray* key = new ObfusArray(crypto_box_SEEDBYTES);
@ -59,7 +68,9 @@ AuthenticatedEncryption::ResultType AuthenticatedEncryption::createKey(const std
return AUTH_CREATE_ENCRYPTION_KEY_FAILED; return AUTH_CREATE_ENCRYPTION_KEY_FAILED;
} }
if (timeUsed.millis() > 400) {
printf("[AuthenticatedEncryption::createKey] %s calculating pwd hash\n", timeUsed.string().data());
}
// generate hash from key for compare // generate hash from key for compare
assert(sizeof(KeyHashed) >= crypto_shorthash_BYTES); assert(sizeof(KeyHashed) >= crypto_shorthash_BYTES);
assert(ServerConfig::g_ServerCryptoKey); assert(ServerConfig::g_ServerCryptoKey);

View File

@ -222,7 +222,7 @@ namespace model {
} }
update << "UPDATE " << getTableName() << " SET " << fieldName << " = ? where id = ?", update << "UPDATE " << getTableName() << " SET " << fieldName << " = ? where id = ?",
Poco::Data::Keywords::useRef(fieldValue), Poco::Data::Keywords::use(mID); Poco::Data::Keywords::bind(fieldValue), Poco::Data::Keywords::bind(mID);
size_t resultCount = 0; size_t resultCount = 0;
try { try {