From 0a83d3e743b917075aeb7d90a02d148a2af8739c Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Fri, 8 Dec 2017 11:24:22 +0100 Subject: [PATCH] [CSE] Fix reading the public key for the metadata This broke when we started to use QSslKey and the Qt Keychain framework. --- src/libsync/clientsideencryption.cpp | 12 ++++-------- src/libsync/clientsideencryption.h | 2 +- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/libsync/clientsideencryption.cpp b/src/libsync/clientsideencryption.cpp index 5e0b7ea79..f96e97c03 100644 --- a/src/libsync/clientsideencryption.cpp +++ b/src/libsync/clientsideencryption.cpp @@ -1134,16 +1134,12 @@ FolderMetadata::FolderMetadata(AccountPtr account, const QByteArray& metadata) : // RSA/ECB/OAEPWithSHA-256AndMGF1Padding using private / public key. QByteArray FolderMetadata::encryptMetadataKeys(const nlohmann::json& metadataKeys) const { - auto path = publicKeyPath(_account); - const char *pathC = qPrintable(path); - FILE* pkeyFile = fopen(pathC, "r"); - if (!pkeyFile) { - qCInfo(lcCse()) << "Could not open the public key"; - exit(1); - } + BIO *publicKeyBio = BIO_new(BIO_s_mem()); + QByteArray publicKeyPem = _account->e2e()->_publicKey.toPem(); + BIO_write(publicKeyBio, publicKeyPem.constData(), publicKeyPem.size()); - EVP_PKEY *key = PEM_read_PUBKEY(pkeyFile, NULL, NULL, NULL); + EVP_PKEY *key = PEM_read_bio_PUBKEY(publicKeyBio, NULL, NULL, NULL); auto data = QByteArray::fromStdString(metadataKeys.dump()); auto ret = EncryptionHelper::encryptStringAsymmetric(key, data); diff --git a/src/libsync/clientsideencryption.h b/src/libsync/clientsideencryption.h index f2d931971..c43dfb8cb 100644 --- a/src/libsync/clientsideencryption.h +++ b/src/libsync/clientsideencryption.h @@ -42,7 +42,6 @@ public: void encryptPrivateKey(); void setTokenForFolder(const QByteArray& folder, const QByteArray& token); QByteArray tokenForFolder(const QByteArray& folder) const; - void fetchFolderEncryptedStatus(); // to be used together with FolderStatusModel::FolderInfo::_path. @@ -77,6 +76,7 @@ private: QMap _folder2token; QMap _folder2encryptedStatus; +public: QSslKey _privateKey; QSslKey _publicKey; QSslCertificate _certificate;