backup private key early

Signed-off-by: Matthieu Gallien <matthieu.gallien@nextcloud.com>
This commit is contained in:
Matthieu Gallien 2023-04-07 16:24:57 +02:00 committed by Matthieu Gallien
parent 0e8e8daaea
commit 15f3e2acae
2 changed files with 25 additions and 0 deletions

View file

@ -1292,6 +1292,9 @@ void ClientSideEncryption::generateCSR(const AccountPtr &account, PKey keyPair)
qCInfo(lcCse()) << "Returning the certificate";
qCInfo(lcCse()) << output;
writeMnemonic(account);
writeKeyPair(account);
sendSignRequestCSR(account, std::move(keyPair), output);
}
@ -1326,6 +1329,26 @@ void ClientSideEncryption::sendSignRequestCSR(const AccountPtr &account, PKey ke
job->start();
}
bool ClientSideEncryption::writeKeyPair(const AccountPtr &account,
const PKey &keyPair)
{
const QString kck = AbstractCredentials::keychainKey(
account->url().toString(),
account->credentials()->user() + e2e_private,
account->id()
);
auto *job = new WritePasswordJob(Theme::instance()->appName());
job->setInsecureFallback(false);
job->setKey(kck);
job->setBinaryData(_privateKey);
connect(job, &WritePasswordJob::finished, [](Job *incoming) {
Q_UNUSED(incoming);
qCInfo(lcCse()) << "Private key stored in keychain";
});
job->start();
}
void ClientSideEncryption::encryptPrivateKey(const AccountPtr &account)
{
QStringList list = WordList::getRandomWords(12);

View file

@ -166,6 +166,8 @@ private slots:
private:
void generateCSR(const AccountPtr &account, PKey keyPair);
void sendSignRequestCSR(const AccountPtr &account, PKey keyPair, const QByteArray &csrContent);
[[nodiscard]] bool writeKeyPair(const AccountPtr &account,
const PKey &keyPair);
[[nodiscard]] bool checkPublicKeyValidity(const AccountPtr &account) const;
[[nodiscard]] bool checkServerPublicKeyValidity(const QByteArray &serverPublicKeyString) const;