Change the separator in the private key
authorKevin Ottens <kevin.ottens@nextcloud.com>
Thu, 9 Jul 2020 07:54:39 +0000 (09:54 +0200)
committerCamila <smayres@gmail.com>
Thu, 9 Jul 2020 14:22:54 +0000 (16:22 +0200)
It used to be a base64 encoded '|', now it is still a '|' but not
encoded, let's adjust accordingly.

Signed-off-by: Kevin Ottens <kevin.ottens@nextcloud.com>
src/libsync/clientsideencryption.cpp

index c7cf7a5bd3d41f60c29bf2df408d30a1014d46a6..3d339a4b5b097b25f5c42c839a4e9f5b07c3130f 100644 (file)
@@ -359,9 +359,9 @@ QByteArray encryptPrivateKey(
     cipherTXT.append(tag);
 
     QByteArray result = cipherTXT.toBase64();
-    result += "fA==";
+    result += '|';
     result += iv.toBase64();
-    result += "fA==";
+    result += '|';
     result += salt.toBase64();
 
     return result;
@@ -371,11 +371,11 @@ QByteArray decryptPrivateKey(const QByteArray& key, const QByteArray& data) {
     qCInfo(lcCse()) << "decryptStringSymmetric key: " << key;
     qCInfo(lcCse()) << "decryptStringSymmetric data: " << data;
 
-    int sep = data.indexOf("fA==");
+    int sep = data.indexOf('|');
     qCInfo(lcCse()) << "sep at" << sep;
 
     QByteArray cipherTXT64 = data.left(sep);
-    QByteArray ivB64 = data.right(data.size() - sep - 4);
+    QByteArray ivB64 = data.right(data.size() - sep - 1);
 
     qCInfo(lcCse()) << "decryptStringSymmetric cipherTXT: " << cipherTXT64;
     qCInfo(lcCse()) << "decryptStringSymmetric IV: " << ivB64;
@@ -447,11 +447,11 @@ QByteArray decryptStringSymmetric(const QByteArray& key, const QByteArray& data)
     qCInfo(lcCse()) << "decryptStringSymmetric key: " << key;
     qCInfo(lcCse()) << "decryptStringSymmetric data: " << data;
 
-    int sep = data.indexOf("fA==");
+    int sep = data.indexOf('|');
     qCInfo(lcCse()) << "sep at" << sep;
 
     QByteArray cipherTXT64 = data.left(sep);
-    QByteArray ivB64 = data.right(data.size() - sep - 4);
+    QByteArray ivB64 = data.right(data.size() - sep - 1);
 
     qCInfo(lcCse()) << "decryptStringSymmetric cipherTXT: " << cipherTXT64;
     qCInfo(lcCse()) << "decryptStringSymmetric IV: " << ivB64;
@@ -606,7 +606,7 @@ QByteArray encryptStringSymmetric(const QByteArray& key, const QByteArray& data)
     cipherTXT.append(tag);
 
     QByteArray result = cipherTXT.toBase64();
-    result += "fA==";
+    result += '|';
     result += iv.toBase64();
 
     return result;
@@ -1131,8 +1131,8 @@ void ClientSideEncryption::decryptPrivateKey(const QByteArray &key) {
 
             // split off salt
             // Todo better place?
-            auto pos = key.lastIndexOf("fA==");
-            QByteArray salt = QByteArray::fromBase64(key.mid(pos + 4));
+            auto pos = key.lastIndexOf('|');
+            QByteArray salt = QByteArray::fromBase64(key.mid(pos + 1));
             auto key2 = key.left(pos);
 
             auto pass = EncryptionHelper::generatePassword(mnemonic, salt);