[cse] Call the CSR job.

There's something wrong on the CSR job that I need to discover.
This commit is contained in:
Tomaz Canabrava 2017-09-13 19:57:39 +02:00 committed by Roeland Jago Douma
parent 304231811d
commit 307dfd195c
No known key found for this signature in database
GPG key ID: F941078878347C0C
2 changed files with 20 additions and 10 deletions

View file

@ -148,13 +148,11 @@ QString ClientSideEncryption::generateCSR(EVP_PKEY *keyPair)
int ret = 0;
int nVersion = 1;
X509_REQ *x509_req = NULL;
X509_REQ *x509_req = nullptr;
auto out = BIO_new(BIO_s_mem());
QString output;
QByteArray output("csr=\"");
char data[80];
// auto out = BIO_new_file("/home/tcanabrava/.nextcloud-keys/request.pem","w");
SignPublicKeyApiJob *job = nullptr;
// 2. set version of x509 req
x509_req = X509_REQ_new();
@ -191,14 +189,18 @@ QString ClientSideEncryption::generateCSR(EVP_PKEY *keyPair)
if (output.endsWith("-----END CERTIFICATE REQUEST-----"))
break;
} while (ret > 0 );
if (ret != 1) {
qCInfo(lcCse()) << "Error saving the csr file";
}
output += "\"";
qCInfo(lcCse()) << "Returning the certificate";
qCInfo(lcCse()) << output;
job = new SignPublicKeyApiJob(_account, baseUrl + "public-key", this);
job->setCsr(output);
connect(job, &SignPublicKeyApiJob::jsonReceived, [this](const QJsonDocument& doc, int retCode) {
qCInfo(lcCse()) << retCode;
qCInfo(lcCse()) << doc;
});
job->start();
free_all:
X509_REQ_free(x509_req);

View file

@ -958,6 +958,11 @@ void SignPublicKeyApiJob::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);
sendRequest("POST", url, req, &_csr);
AbstractNetworkJob::start();
}
@ -965,7 +970,10 @@ void SignPublicKeyApiJob::start()
bool SignPublicKeyApiJob::finished()
{
qCInfo(lcSignPublicKeyApiJob()) << "Sending CSR ended with" << path() << errorString() << reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute);
qCInfo(lcSignPublicKeyApiJob()) << reply()->readAll();
QJsonParseError error;
auto json = QJsonDocument::fromJson(reply()->readAll(), &error);
emit jsonReceived(json, reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt());
}
} // namespace OCC