No sharing in metadata yet and PEM as PKCS#8

* Don't store the metadata yet this crashes android
  - Yes android should be fixed but for now this is quicker ;)
* QSslKey exports PEM as PKCS#1
  - This is not handled properly on android so use PKCS#8 helper

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
Roeland Jago Douma 2018-01-23 21:02:52 +01:00
parent a2b8724adf
commit 21d55c3321
No known key found for this signature in database
GPG key ID: F941078878347C0C
2 changed files with 24 additions and 3 deletions

View file

@ -381,6 +381,23 @@ QByteArray EncryptionHelper::decryptStringSymmetric(const QByteArray& key, const
return result;
}
QByteArray EncryptionHelper::privateKeyToPem(const QSslKey key) {
BIO *privateKeyBio = BIO_new(BIO_s_mem());
QByteArray privateKeyPem = key.toPem();
BIO_write(privateKeyBio, privateKeyPem.constData(), privateKeyPem.size());
EVP_PKEY *pkey = PEM_read_bio_PrivateKey(privateKeyBio, NULL, NULL, NULL);
BIO *pemBio = BIO_new(BIO_s_mem());
PEM_write_bio_PKCS8PrivateKey(pemBio, pkey, NULL, NULL, 0, NULL, NULL);
QByteArray pem = BIO2ByteArray(pemBio);
BIO_free_all(privateKeyBio);
BIO_free_all(pemBio);
EVP_PKEY_free(pkey);
return pem;
}
QByteArray EncryptionHelper::encryptStringSymmetric(const QByteArray& key, const QByteArray& data) {
QByteArray iv = generateRandom(16);
@ -706,7 +723,7 @@ void ClientSideEncryption::mnemonicKeyFetched(QKeychain::Job *incoming) {
_mnemonic = readJob->textData();
qCInfo(lcCse()) << "Mnemonic key fetched from keychain";
qCInfo(lcCse()) << "Mnemonic key fetched from keychain: " << _mnemonic;
emit initializationFinished();
}
@ -937,7 +954,7 @@ void ClientSideEncryption::encryptPrivateKey()
auto salt = EncryptionHelper::generateRandom(40);
auto secretKey = EncryptionHelper::generatePassword(passPhrase, salt);
auto cryptedText = EncryptionHelper::encryptPrivateKey(secretKey, _privateKey.toPem(), salt);
auto cryptedText = EncryptionHelper::encryptPrivateKey(secretKey, EncryptionHelper::privateKeyToPem(_privateKey), salt);
// Send private key to the server
auto job = new StorePrivateKeyApiJob(_account, baseUrl() + "private-key", this);
@ -1240,6 +1257,7 @@ QByteArray FolderMetadata::encryptedMetadata() {
metadataKeys.insert(QString::number(it.key()), QString(encryptedKey));
}
/* NO SHARING IN V1
QJsonObject recepients;
for (auto it = _sharing.constBegin(), end = _sharing.constEnd(); it != end; it++) {
recepients.insert(it->first, it->second);
@ -1247,10 +1265,11 @@ QByteArray FolderMetadata::encryptedMetadata() {
QJsonDocument recepientDoc;
recepientDoc.setObject(recepients);
QString sharingEncrypted = encryptJsonObject(recepientDoc.toJson(QJsonDocument::Compact), _metadataKeys.last());
*/
QJsonObject metadata = {
{"metadataKeys", metadataKeys},
{"sharing", sharingEncrypted},
// {"sharing", sharingEncrypted},
{"version", 1}
};

View file

@ -49,6 +49,8 @@ public:
const QByteArray& data
);
static QByteArray privateKeyToPem(const QSslKey key);
//TODO: change those two EVP_PKEY into QSslKey.
static QByteArray encryptStringAsymmetric(
EVP_PKEY *publicKey,