mirror of
https://github.com/nextcloud/desktop.git
synced 2024-12-14 17:51:41 +03:00
[cse] Start the encryption algorithm for the Private Key
This commit is contained in:
parent
fd00e180f5
commit
5395fc56b1
2 changed files with 43 additions and 4 deletions
|
@ -18,6 +18,8 @@
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
|
|
||||||
|
#include "wordlist.h"
|
||||||
|
|
||||||
namespace OCC
|
namespace OCC
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -198,18 +200,19 @@ QString ClientSideEncryption::generateCSR(EVP_PKEY *keyPair)
|
||||||
|
|
||||||
job = new SignPublicKeyApiJob(_account, baseUrl + "public-key", this);
|
job = new SignPublicKeyApiJob(_account, baseUrl + "public-key", this);
|
||||||
job->setCsr(output);
|
job->setCsr(output);
|
||||||
// TODO: Extract this function, should not be a lambda.
|
|
||||||
connect(job, &SignPublicKeyApiJob::jsonReceived, [this](const QJsonDocument& json, int retCode) {
|
connect(job, &SignPublicKeyApiJob::jsonReceived, [this, keyPair](const QJsonDocument& json, int retCode) {
|
||||||
if (retCode == 200) {
|
if (retCode == 200) {
|
||||||
auto caps = json.object().value("ocs").toObject().value("data").toObject().value("public-key").toString();
|
auto caps = json.object().value("ocs").toObject().value("data").toObject().value("public-key").toString();
|
||||||
qCInfo(lcCse()) << "Public Key Returned" << caps;
|
qCInfo(lcCse()) << "Public Key Returned" << caps;
|
||||||
QFile file(publicKeyPath() + ".sign"); // TODO: Verify if I need to keep the old file.
|
QFile file(publicKeyPath() + ".sign");
|
||||||
if (file.open(QIODevice::WriteOnly)) {
|
if (file.open(QIODevice::WriteOnly)) {
|
||||||
QTextStream s(&file);
|
QTextStream s(&file);
|
||||||
s << caps;
|
s << caps;
|
||||||
}
|
}
|
||||||
file.close();
|
file.close();
|
||||||
qCInfo(lcCse()) << "public key saved.";
|
qCInfo(lcCse()) << "public key saved, Encrypting Private Key.";
|
||||||
|
encryptPrivateKey(keyPair);
|
||||||
}
|
}
|
||||||
qCInfo(lcCse()) << retCode;
|
qCInfo(lcCse()) << retCode;
|
||||||
});
|
});
|
||||||
|
@ -221,6 +224,41 @@ free_all:
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ClientSideEncryption::encryptPrivateKey(EVP_PKEY *keyPair)
|
||||||
|
{
|
||||||
|
// Write the Private File to a BIO
|
||||||
|
// Retrieve the BIO contents, and encrypt it.
|
||||||
|
// Send the encrypted key to the server.
|
||||||
|
// I have no idea what I'm doing.
|
||||||
|
|
||||||
|
static const char* salt = "$4$YmBjm3hk$Qb74D5IUYwghUmzsMqeNFx5z0/8$";
|
||||||
|
static const int iterationCount = 1024;
|
||||||
|
static const int keyStrength = 256;
|
||||||
|
BIO* bio = BIO_new(BIO_s_mem());
|
||||||
|
|
||||||
|
QString passPhrase = WordList::getUnifiedString(WordList::getRandomWords(12));
|
||||||
|
const char* passPhrasePtr = qPrintable(passPhrase);
|
||||||
|
qCInfo(lcCse()) << "Passphrase Generated:";
|
||||||
|
qCInfo(lcCse()) << passPhrase;
|
||||||
|
|
||||||
|
// Extract the Private key from the key pair.
|
||||||
|
PEM_write_bio_PrivateKey(bio, keyPair, NULL, NULL, 0, 0, NULL);
|
||||||
|
char data[80];
|
||||||
|
QString output;
|
||||||
|
int ret = 0;
|
||||||
|
do {
|
||||||
|
ret = BIO_gets(bio, data, 80);
|
||||||
|
output += data;
|
||||||
|
if (output.endsWith("-----END PRIVATE KEY-----")) {
|
||||||
|
output = output.trimmed();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} while (ret > 0 );
|
||||||
|
|
||||||
|
qCInfo(lcCse()) << "Private Key Extracted";
|
||||||
|
qCInfo(lcCse()) << output;
|
||||||
|
}
|
||||||
|
|
||||||
void ClientSideEncryption::getPrivateKeyFromServer()
|
void ClientSideEncryption::getPrivateKeyFromServer()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@ public:
|
||||||
void getPrivateKeyFromServer();
|
void getPrivateKeyFromServer();
|
||||||
void getPublicKeyFromServer();
|
void getPublicKeyFromServer();
|
||||||
void signPublicKey();
|
void signPublicKey();
|
||||||
|
void encryptPrivateKey(EVP_PKEY *keyPair);
|
||||||
QString privateKeyPath() const;
|
QString privateKeyPath() const;
|
||||||
QString publicKeyPath() const;
|
QString publicKeyPath() const;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue