Skip to content

Commit

Permalink
fix some review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Matthieu Gallien <[email protected]>
  • Loading branch information
mgallien committed Jun 30, 2023
1 parent a453bcf commit df2b3a3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
18 changes: 8 additions & 10 deletions src/libsync/clientsideencryption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1325,13 +1325,11 @@ void ClientSideEncryption::generateKeyPair(const AccountPtr &account)
return;
}

auto privateKey = PKey::readPrivateKey(privKey);

qCDebug(lcCse()) << "Key correctly generated";

auto csrOutput = generateCSR(account, std::move(localKeyPair), std::move(privateKey));
writeMnemonic(account, [account, keyPair = std::move(csrOutput.second), output = std::move(csrOutput.first), this]() mutable -> void {
writeKeyPair(account, std::move(keyPair), output);
auto csrContent = generateCSR(account, std::move(localKeyPair), PKey::readPrivateKey(privKey));
writeMnemonic(account, [account, keyPair = std::move(csrContent.second), csrContent = std::move(csrContent.first), this]() mutable -> void {
writeKeyPair(account, std::move(keyPair), csrContent);
});
}

Expand Down Expand Up @@ -1406,7 +1404,7 @@ std::pair<QByteArray, ClientSideEncryption::PKey> ClientSideEncryption::generate

void ClientSideEncryption::sendSignRequestCSR(const AccountPtr &account,
PKey keyPair,
QByteArray csrContent)
const QByteArray &csrContent)
{
auto job = new SignPublicKeyApiJob(account, e2eeBaseUrl() + "public-key", this);
job->setCsr(csrContent);
Expand Down Expand Up @@ -1441,7 +1439,7 @@ void ClientSideEncryption::sendSignRequestCSR(const AccountPtr &account,

void ClientSideEncryption::writeKeyPair(const AccountPtr &account,
PKey keyPair,
QByteArray output)
const QByteArray &csrContent)
{
const auto privateKeyKeychainId = AbstractCredentials::keychainKey(
account->url().toString(),
Expand All @@ -1467,7 +1465,7 @@ void ClientSideEncryption::writeKeyPair(const AccountPtr &account,
privateKeyJob->setInsecureFallback(false);
privateKeyJob->setKey(privateKeyKeychainId);
privateKeyJob->setBinaryData(bytearrayPrivateKey);
connect(privateKeyJob, &WritePasswordJob::finished, [keyPair = std::move(keyPair), publicKeyKeychainId, account, output, this] (Job *incoming) mutable {
connect(privateKeyJob, &WritePasswordJob::finished, [keyPair = std::move(keyPair), publicKeyKeychainId, account, csrContent, this] (Job *incoming) mutable {
if (incoming->error() != Error::NoError) {
failedToInitialize(account);
return;
Expand All @@ -1486,13 +1484,13 @@ void ClientSideEncryption::writeKeyPair(const AccountPtr &account,
publicKeyJob->setInsecureFallback(false);
publicKeyJob->setKey(publicKeyKeychainId);
publicKeyJob->setBinaryData(bytearrayPublicKey);
connect(publicKeyJob, &WritePasswordJob::finished, [account, keyPair = std::move(keyPair), output, this](Job *incoming) mutable {
connect(publicKeyJob, &WritePasswordJob::finished, [account, keyPair = std::move(keyPair), csrContent, this](Job *incoming) mutable {
if (incoming->error() != Error::NoError) {
failedToInitialize(account);
return;
}

sendSignRequestCSR(account, std::move(keyPair), output);
sendSignRequestCSR(account, std::move(keyPair), csrContent);
});
publicKeyJob->start();
});
Expand Down
4 changes: 2 additions & 2 deletions src/libsync/clientsideencryption.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,11 @@ private slots:

void sendSignRequestCSR(const AccountPtr &account,
PKey keyPair,
QByteArray csrContent);
const QByteArray &csrContent);

void writeKeyPair(const AccountPtr &account,
PKey keyPair,
QByteArray output);
const QByteArray &csrContent);

template <typename L>
void writeMnemonic(OCC::AccountPtr account,
Expand Down

0 comments on commit df2b3a3

Please sign in to comment.