mirror of
https://github.com/nextcloud/desktop.git
synced 2024-12-14 01:34:22 +03:00
[CSE] Send the Private Key to the server
This commit is contained in:
parent
78136a10b0
commit
cfb6e3be8c
3 changed files with 95 additions and 5 deletions
|
@ -467,7 +467,7 @@ void ClientSideEncryption::encryptPrivateKey(EVP_PKEY *keyPair)
|
|||
cryptedText, // unsigned char *ciphertext,
|
||||
tag // unsigned char *tag
|
||||
);
|
||||
|
||||
/*
|
||||
qCInfo(lcCse()) << "Encrypted Text" << QByteArray( (const char*) cryptedText, cryptedText_len);
|
||||
int decryptedText_len = decrypt(
|
||||
cryptedText, //unsigned char *ciphertext,
|
||||
|
@ -480,12 +480,20 @@ void ClientSideEncryption::encryptPrivateKey(EVP_PKEY *keyPair)
|
|||
decryptedText //unsigned char *plaintext
|
||||
);
|
||||
qCInfo(lcCse()) << "Decrypted Text" << QByteArray( (const char*) decryptedText, decryptedText_len);
|
||||
|
||||
*/
|
||||
// Pretend that the private key is actually encrypted and send it to the server.
|
||||
auto job = new StorePrivateKeyApiJob(_account, baseUrl + "private-key", this);
|
||||
job->setPrivateKey(QByteArray((const char*) cryptedText, 128));
|
||||
connect(job, &StorePrivateKeyApiJob::jsonReceived, [this](const QJsonDocument& doc, int retCode) {
|
||||
qCInfo(lcCse()) << doc;
|
||||
qCInfo(lcCse()) << "Store Private Key returned with" << retCode;
|
||||
});
|
||||
job->start();
|
||||
}
|
||||
|
||||
void ClientSideEncryption::getPrivateKeyFromServer()
|
||||
{
|
||||
|
||||
qCInfo(lcCse()) << "Trying to store the private key on the server.";
|
||||
}
|
||||
|
||||
void ClientSideEncryption::getPublicKeyFromServer()
|
||||
|
|
|
@ -49,6 +49,7 @@ Q_LOGGING_CATEGORY(lcProppatchJob, "sync.networkjob.proppatch", QtInfoMsg)
|
|||
Q_LOGGING_CATEGORY(lcJsonApiJob, "sync.networkjob.jsonapi", QtInfoMsg)
|
||||
Q_LOGGING_CATEGORY(lcDetermineAuthTypeJob, "sync.networkjob.determineauthtype", QtInfoMsg)
|
||||
Q_LOGGING_CATEGORY(lcSignPublicKeyApiJob, "sync.networkjob.sendcsr", QtInfoMsg);
|
||||
Q_LOGGING_CATEGORY(lcStorePrivateKeyApiJob, "sync.networkjob.storeprivatekey", QtInfoMsg);
|
||||
|
||||
RequestEtagJob::RequestEtagJob(AccountPtr account, const QString &path, QObject *parent)
|
||||
: AbstractNetworkJob(account, path, parent)
|
||||
|
@ -971,7 +972,44 @@ void SignPublicKeyApiJob::start()
|
|||
|
||||
bool SignPublicKeyApiJob::finished()
|
||||
{
|
||||
qCInfo(lcSignPublicKeyApiJob()) << "Sending CSR ended with" << path() << errorString() << reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute);
|
||||
qCInfo(lcStorePrivateKeyApiJob()) << "Sending CSR ended with" << path() << errorString() << reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute);
|
||||
|
||||
QJsonParseError error;
|
||||
auto json = QJsonDocument::fromJson(reply()->readAll(), &error);
|
||||
emit jsonReceived(json, reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt());
|
||||
}
|
||||
|
||||
|
||||
StorePrivateKeyApiJob::StorePrivateKeyApiJob(const AccountPtr& account, const QString& path, QObject* parent)
|
||||
: AbstractNetworkJob(account, path, parent)
|
||||
{
|
||||
}
|
||||
|
||||
void StorePrivateKeyApiJob::setPrivateKey(const QByteArray& privKey)
|
||||
{
|
||||
QByteArray data = "privateKey=";
|
||||
data += QUrl::toPercentEncoding(privKey);
|
||||
_privKey.setData(data);
|
||||
}
|
||||
|
||||
void StorePrivateKeyApiJob::start()
|
||||
{
|
||||
QNetworkRequest req;
|
||||
req.setRawHeader("OCS-APIREQUEST", "true");
|
||||
QUrl url = Utility::concatUrlPath(account()->url(), path());
|
||||
QList<QPair<QString, QString>> params = {
|
||||
qMakePair(QString::fromLatin1("format"), QString::fromLatin1("json"))
|
||||
};
|
||||
url.setQueryItems(params);
|
||||
|
||||
qCInfo(lcStorePrivateKeyApiJob) << "Sending the private key" << _privKey.data();
|
||||
sendRequest("POST", url, req, &_privKey);
|
||||
AbstractNetworkJob::start();
|
||||
}
|
||||
|
||||
bool StorePrivateKeyApiJob::finished()
|
||||
{
|
||||
qCInfo(lcStorePrivateKeyApiJob()) << "Sending private key ended with" << path() << errorString() << reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute);
|
||||
|
||||
QJsonParseError error;
|
||||
auto json = QJsonDocument::fromJson(reply()->readAll(), &error);
|
||||
|
|
|
@ -470,9 +470,53 @@ signals:
|
|||
|
||||
private:
|
||||
QBuffer _csr;
|
||||
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* @brief Job to upload the PrivateKey that return JSON
|
||||
*
|
||||
* To be used like this:
|
||||
* \code
|
||||
* _job = new StorePrivateKeyApiJob(account, QLatin1String("ocs/v1.php/foo/bar"), this);
|
||||
* _job->setPrivateKey( privKey );
|
||||
* connect(_job...);
|
||||
* _job->start();
|
||||
* \encode
|
||||
*
|
||||
* @ingroup libsync
|
||||
*/
|
||||
class OWNCLOUDSYNC_EXPORT StorePrivateKeyApiJob : public AbstractNetworkJob
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit StorePrivateKeyApiJob(const AccountPtr &account, const QString &path, QObject *parent = 0);
|
||||
|
||||
/**
|
||||
* @brief setCsr - the CSR with the public key.
|
||||
* This function needs to be called before start() obviously.
|
||||
*/
|
||||
void setPrivateKey(const QByteArray& privateKey);
|
||||
|
||||
public slots:
|
||||
void start() override;
|
||||
|
||||
protected:
|
||||
bool finished() override;
|
||||
signals:
|
||||
|
||||
/**
|
||||
* @brief jsonReceived - signal to report the json answer from ocs
|
||||
* @param json - the parsed json document
|
||||
* @param statusCode - the OCS status code: 100 (!) for success
|
||||
*/
|
||||
void jsonReceived(const QJsonDocument &json, int statusCode);
|
||||
|
||||
private:
|
||||
QBuffer _privKey;
|
||||
};
|
||||
|
||||
|
||||
} // namespace OCC
|
||||
|
||||
#endif // NETWORKJOBS_H
|
||||
|
|
Loading…
Reference in a new issue