mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
expose generated public key and private key from generator
This commit is contained in:
parent
5de8601b43
commit
6e4ecffb09
4 changed files with 43 additions and 31 deletions
|
@ -612,10 +612,6 @@ void AccountManager::generateNewKeypair(bool isUserKeypair, const QUuid& domainI
|
|||
connect(keypairGenerator, &RSAKeypairGenerator::errorGeneratingKeypair,
|
||||
this, &AccountManager::handleKeypairGenerationError);
|
||||
|
||||
// cleanup the keypair generator and the thread once the generation succeeds or fails
|
||||
connect(keypairGenerator, &RSAKeypairGenerator::generatedKeypair, keypairGenerator, &RSAKeypairGenerator::deleteLater);
|
||||
connect(keypairGenerator, &RSAKeypairGenerator::errorGeneratingKeypair, keypairGenerator, &RSAKeypairGenerator::deleteLater);
|
||||
|
||||
connect(keypairGenerator, &QObject::destroyed, generateThread, &QThread::quit);
|
||||
connect(generateThread, &QThread::finished, generateThread, &QThread::deleteLater);
|
||||
|
||||
|
@ -625,32 +621,43 @@ void AccountManager::generateNewKeypair(bool isUserKeypair, const QUuid& domainI
|
|||
generateThread->start();
|
||||
}
|
||||
|
||||
void AccountManager::processGeneratedKeypair(QByteArray publicKey, QByteArray privateKey) {
|
||||
void AccountManager::processGeneratedKeypair() {
|
||||
|
||||
qCDebug(networking) << "Generated 2048-bit RSA key-pair. Storing private key and uploading public key.";
|
||||
|
||||
// set the private key on our metaverse API account info
|
||||
_accountInfo.setPrivateKey(privateKey);
|
||||
persistAccountToSettings();
|
||||
|
||||
// upload the public key so data-web has an up-to-date key
|
||||
const QString PUBLIC_KEY_UPDATE_PATH = "api/v1/user/public_key";
|
||||
|
||||
// setup a multipart upload to send up the public key
|
||||
QHttpMultiPart* requestMultiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType);
|
||||
|
||||
QHttpPart keyPart;
|
||||
keyPart.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("application/octet-stream"));
|
||||
keyPart.setHeader(QNetworkRequest::ContentDispositionHeader,
|
||||
QVariant("form-data; name=\"public_key\"; filename=\"public_key\""));
|
||||
keyPart.setBody(publicKey);
|
||||
|
||||
requestMultiPart->append(keyPart);
|
||||
|
||||
sendRequest(PUBLIC_KEY_UPDATE_PATH, AccountManagerAuth::Required, QNetworkAccessManager::PutOperation,
|
||||
JSONCallbackParameters(), QByteArray(), requestMultiPart);
|
||||
|
||||
RSAKeypairGenerator* keypairGenerator = qobject_cast<RSAKeypairGenerator*>(sender());
|
||||
|
||||
if (keypairGenerator) {
|
||||
// set the private key on our metaverse API account info
|
||||
_accountInfo.setPrivateKey(keypairGenerator->getPrivateKey());
|
||||
persistAccountToSettings();
|
||||
|
||||
// upload the public key so data-web has an up-to-date key
|
||||
const QString PUBLIC_KEY_UPDATE_PATH = "api/v1/user/public_key";
|
||||
|
||||
// setup a multipart upload to send up the public key
|
||||
QHttpMultiPart* requestMultiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType);
|
||||
|
||||
QHttpPart keyPart;
|
||||
keyPart.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("application/octet-stream"));
|
||||
keyPart.setHeader(QNetworkRequest::ContentDispositionHeader,
|
||||
QVariant("form-data; name=\"public_key\"; filename=\"public_key\""));
|
||||
keyPart.setBody(keypairGenerator->getPublicKey());
|
||||
|
||||
requestMultiPart->append(keyPart);
|
||||
|
||||
sendRequest(PUBLIC_KEY_UPDATE_PATH, AccountManagerAuth::Required, QNetworkAccessManager::PutOperation,
|
||||
JSONCallbackParameters(), QByteArray(), requestMultiPart);
|
||||
|
||||
keypairGenerator->deleteLater();
|
||||
} else {
|
||||
qCWarning(networking) << "Expected processGeneratedKeypair to be called by a live RSAKeypairGenerator"
|
||||
<< "but the casted sender is NULL. Will not process generated keypair.";
|
||||
}
|
||||
}
|
||||
|
||||
void AccountManager::handleKeypairGenerationError() {
|
||||
qCritical() << "Error generating keypair - this is likely to cause authentication issues.";
|
||||
|
||||
sender()->deleteLater();
|
||||
}
|
||||
|
|
|
@ -103,7 +103,7 @@ signals:
|
|||
private slots:
|
||||
void processReply();
|
||||
void handleKeypairGenerationError();
|
||||
void processGeneratedKeypair(QByteArray publicKey, QByteArray privateKey);
|
||||
void processGeneratedKeypair();
|
||||
|
||||
private:
|
||||
AccountManager();
|
||||
|
|
|
@ -85,12 +85,12 @@ void RSAKeypairGenerator::generateKeypair() {
|
|||
// we can cleanup the RSA struct before we continue on
|
||||
RSA_free(keyPair);
|
||||
|
||||
QByteArray publicKeyArray(reinterpret_cast<char*>(publicKeyDER), publicKeyLength);
|
||||
QByteArray privateKeyArray(reinterpret_cast<char*>(privateKeyDER), privateKeyLength);
|
||||
_publicKey = QByteArray { reinterpret_cast<char*>(publicKeyDER), publicKeyLength };
|
||||
_privateKey = QByteArray { reinterpret_cast<char*>(privateKeyDER), privateKeyLength };
|
||||
|
||||
// cleanup the publicKeyDER and publicKeyDER data
|
||||
OPENSSL_free(publicKeyDER);
|
||||
OPENSSL_free(privateKeyDER);
|
||||
|
||||
emit generatedKeypair(publicKeyArray, privateKeyArray);
|
||||
emit generatedKeypair();
|
||||
}
|
||||
|
|
|
@ -22,16 +22,21 @@ public:
|
|||
|
||||
void setDomainID(const QUuid& domainID) { _domainID = domainID; }
|
||||
const QUuid& getDomainID() const { return _domainID; }
|
||||
|
||||
const QByteArray& getPublicKey() const { return _publicKey; }
|
||||
const QByteArray& getPrivateKey() const { return _privateKey; }
|
||||
|
||||
public slots:
|
||||
void generateKeypair();
|
||||
|
||||
signals:
|
||||
void errorGeneratingKeypair();
|
||||
void generatedKeypair(QByteArray publicKey, QByteArray privateKey);
|
||||
void generatedKeypair();
|
||||
|
||||
private:
|
||||
QUuid _domainID;
|
||||
QByteArray _publicKey;
|
||||
QByteArray _privateKey;
|
||||
};
|
||||
|
||||
#endif // hifi_RSAKeypairGenerator_h
|
||||
|
|
Loading…
Reference in a new issue