Update legacy database hashes automatically

This commit is contained in:
varjolintu 2019-07-16 20:33:16 +03:00 committed by Jonathan White
parent fccbb98b8e
commit 493b51882b
2 changed files with 22 additions and 0 deletions

View File

@ -149,6 +149,16 @@ QJsonObject BrowserAction::handleGetDatabaseHash(const QJsonObject& json, const
QJsonObject message = buildMessage(newNonce);
message["hash"] = hash;
// Update a legacy database hash if found
const QJsonArray hashes = decrypted.value("connectedKeys").toArray();
if (!hashes.isEmpty()) {
const QString legacyHash = getLegacyDatabaseHash();
if (hashes.contains(legacyHash)) {
message["oldHash"] = legacyHash;
}
}
return buildResponse(action, message, newNonce);
}
@ -528,6 +538,17 @@ QString BrowserAction::getReturnValue(const BrowserService::ReturnValue returnVa
}
QString BrowserAction::getDatabaseHash()
{
QMutexLocker locker(&m_mutex);
QByteArray hash =
QCryptographicHash::hash(
m_browserService.getDatabaseRootUuid().toUtf8(),
QCryptographicHash::Sha256)
.toHex();
return QString(hash);
}
QString BrowserAction::getLegacyDatabaseHash()
{
QMutexLocker locker(&m_mutex);
QByteArray hash =

View File

@ -75,6 +75,7 @@ private:
QString getErrorMessage(const int errorCode) const;
QString getReturnValue(const BrowserService::ReturnValue returnValue) const;
QString getDatabaseHash();
QString getLegacyDatabaseHash();
QString encryptMessage(const QJsonObject& message, const QString& nonce);
QJsonObject decryptMessage(const QString& message, const QString& nonce);