]> dgit.raspbian.org Git - nextcloud-desktop.git/commitdiff
improvement to be able to retry the e2ee init steps
authorMatthieu Gallien <matthieu.gallien@nextcloud.com>
Mon, 17 Apr 2023 16:04:31 +0000 (18:04 +0200)
committerMatthieu Gallien <matthieu_gallien@yahoo.fr>
Fri, 30 Jun 2023 13:32:03 +0000 (15:32 +0200)
Signed-off-by: Matthieu Gallien <matthieu.gallien@nextcloud.com>
src/libsync/clientsideencryption.cpp
src/libsync/clientsideencryption.h

index 9264cc46e94d8598222ddce5af4ad05740a93d00..d680e320fdf030d25faebd1f840a82e0001f8706 100644 (file)
@@ -1300,10 +1300,13 @@ void ClientSideEncryption::generateKeyPair(const AccountPtr &account)
 
     qCInfo(lcCse()) << "Keys generated correctly, sending to server.";
     generateCSR(account, std::move(localKeyPair));
+    writeMnemonic(account, [account, keyPair = std::move(keyPair), output, this]() mutable -> void {writeKeyPair(account, std::move(keyPair), output);});
 }
 
-void ClientSideEncryption::generateCSR(AccountPtr account, PKey keyPair)
+QByteArray ClientSideEncryption::generateCSR(AccountPtr account, PKey keyPair)
 {
+    auto result = QByteArray{};
+
     // OpenSSL expects const char.
     auto cnArray = account->davUser().toLocal8Bit();
     qCInfo(lcCse()) << "Getting the following array for the account Id" << cnArray;
@@ -1334,39 +1337,39 @@ void ClientSideEncryption::generateCSR(AccountPtr account, PKey keyPair)
         ret = X509_NAME_add_entry_by_txt(x509_name, v.first,  MBSTRING_ASC, (const unsigned char*) v.second, -1, -1, 0);
         if (ret != 1) {
             qCInfo(lcCse()) << "Error Generating the Certificate while adding" << v.first << v.second;
-            return;
+            return result;
         }
     }
 
     ret = X509_REQ_set_pubkey(x509_req, keyPair);
     if (ret != 1){
         qCInfo(lcCse()) << "Error setting the public key on the csr";
-        return;
+        return result;
     }
 
     ret = X509_REQ_sign(x509_req, keyPair, EVP_sha1());    // return x509_req->signature->length
     if (ret <= 0){
         qCInfo(lcCse()) << "Error setting the public key on the csr";
-        return;
+        return result;
     }
 
     Bio out;
     ret = PEM_write_bio_X509_REQ(out, x509_req);
     if (ret <= 0){
         qCInfo(lcCse()) << "Error exporting the csr to the BIO";
-        return;
+        return result;
     }
 
-    const auto output = BIO2ByteArray(out);
+    result = BIO2ByteArray(out);
 
     qCInfo(lcCse()) << "Returning the certificate";
-    qCInfo(lcCse()) << output;
+    qCInfo(lcCse()) << result;
 
     if (_mnemonic.isEmpty()) {
         generateMnemonic();
     }
 
-    writeMnemonic(account, [account, keyPair = std::move(keyPair), output, this]() mutable -> void {writeKeyPair(account, std::move(keyPair), output);});
+    return result;
 }
 
 void ClientSideEncryption::sendSignRequestCSR(AccountPtr account,
@@ -1460,8 +1463,11 @@ void ClientSideEncryption::checkServerHasSavedKeys(AccountPtr account)
     const auto keyIsNotOnServer = [account, this] () {
         qCInfo(lcCse) << "server is missing keys. upload is necessary";
 
-        generateCSR(account, keyPair)
-        sendSignRequestCSR(account, {}, {});
+        Bio privateKeyBio;
+        auto keyPair = PKey::readPublicKey(privateKeyBio);
+        auto csrData = generateCSR(account, std::move(keyPair));
+        auto keyPair2 = PKey::readPublicKey(privateKeyBio);
+        sendSignRequestCSR(account, std::move(keyPair2), csrData);
     };
 
     const auto privateKeyOnServerIsValid = [this] () {
index fe95d891215c240b67fc671e760815f2a07ee081..1a4d75e1f2dc4fa468f61f45ccbde17784a0851d 100644 (file)
@@ -166,11 +166,13 @@ private slots:
 
 private:
     void generateMnemonic();
-    void generateCSR(AccountPtr account,
-                     PKey keyPair);
+    [[nodiscard]] QByteArray generateCSR(AccountPtr account,
+                                         PKey keyPair);
+
     void sendSignRequestCSR(AccountPtr account,
                             PKey keyPair,
                             QByteArray csrContent);
+
     void writeKeyPair(AccountPtr account,
                       PKey keyPair,
                       QByteArray output);