mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 00:56:45 +02: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,
|
connect(keypairGenerator, &RSAKeypairGenerator::errorGeneratingKeypair,
|
||||||
this, &AccountManager::handleKeypairGenerationError);
|
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(keypairGenerator, &QObject::destroyed, generateThread, &QThread::quit);
|
||||||
connect(generateThread, &QThread::finished, generateThread, &QThread::deleteLater);
|
connect(generateThread, &QThread::finished, generateThread, &QThread::deleteLater);
|
||||||
|
|
||||||
|
@ -625,32 +621,43 @@ void AccountManager::generateNewKeypair(bool isUserKeypair, const QUuid& domainI
|
||||||
generateThread->start();
|
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.";
|
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
|
RSAKeypairGenerator* keypairGenerator = qobject_cast<RSAKeypairGenerator*>(sender());
|
||||||
_accountInfo.setPrivateKey(privateKey);
|
|
||||||
persistAccountToSettings();
|
if (keypairGenerator) {
|
||||||
|
// set the private key on our metaverse API account info
|
||||||
// upload the public key so data-web has an up-to-date key
|
_accountInfo.setPrivateKey(keypairGenerator->getPrivateKey());
|
||||||
const QString PUBLIC_KEY_UPDATE_PATH = "api/v1/user/public_key";
|
persistAccountToSettings();
|
||||||
|
|
||||||
// setup a multipart upload to send up the public key
|
// upload the public key so data-web has an up-to-date key
|
||||||
QHttpMultiPart* requestMultiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType);
|
const QString PUBLIC_KEY_UPDATE_PATH = "api/v1/user/public_key";
|
||||||
|
|
||||||
QHttpPart keyPart;
|
// setup a multipart upload to send up the public key
|
||||||
keyPart.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("application/octet-stream"));
|
QHttpMultiPart* requestMultiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType);
|
||||||
keyPart.setHeader(QNetworkRequest::ContentDispositionHeader,
|
|
||||||
QVariant("form-data; name=\"public_key\"; filename=\"public_key\""));
|
QHttpPart keyPart;
|
||||||
keyPart.setBody(publicKey);
|
keyPart.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("application/octet-stream"));
|
||||||
|
keyPart.setHeader(QNetworkRequest::ContentDispositionHeader,
|
||||||
requestMultiPart->append(keyPart);
|
QVariant("form-data; name=\"public_key\"; filename=\"public_key\""));
|
||||||
|
keyPart.setBody(keypairGenerator->getPublicKey());
|
||||||
sendRequest(PUBLIC_KEY_UPDATE_PATH, AccountManagerAuth::Required, QNetworkAccessManager::PutOperation,
|
|
||||||
JSONCallbackParameters(), QByteArray(), requestMultiPart);
|
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() {
|
void AccountManager::handleKeypairGenerationError() {
|
||||||
qCritical() << "Error generating keypair - this is likely to cause authentication issues.";
|
qCritical() << "Error generating keypair - this is likely to cause authentication issues.";
|
||||||
|
|
||||||
|
sender()->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,7 +103,7 @@ signals:
|
||||||
private slots:
|
private slots:
|
||||||
void processReply();
|
void processReply();
|
||||||
void handleKeypairGenerationError();
|
void handleKeypairGenerationError();
|
||||||
void processGeneratedKeypair(QByteArray publicKey, QByteArray privateKey);
|
void processGeneratedKeypair();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
AccountManager();
|
AccountManager();
|
||||||
|
|
|
@ -85,12 +85,12 @@ void RSAKeypairGenerator::generateKeypair() {
|
||||||
// we can cleanup the RSA struct before we continue on
|
// we can cleanup the RSA struct before we continue on
|
||||||
RSA_free(keyPair);
|
RSA_free(keyPair);
|
||||||
|
|
||||||
QByteArray publicKeyArray(reinterpret_cast<char*>(publicKeyDER), publicKeyLength);
|
_publicKey = QByteArray { reinterpret_cast<char*>(publicKeyDER), publicKeyLength };
|
||||||
QByteArray privateKeyArray(reinterpret_cast<char*>(privateKeyDER), privateKeyLength);
|
_privateKey = QByteArray { reinterpret_cast<char*>(privateKeyDER), privateKeyLength };
|
||||||
|
|
||||||
// cleanup the publicKeyDER and publicKeyDER data
|
// cleanup the publicKeyDER and publicKeyDER data
|
||||||
OPENSSL_free(publicKeyDER);
|
OPENSSL_free(publicKeyDER);
|
||||||
OPENSSL_free(privateKeyDER);
|
OPENSSL_free(privateKeyDER);
|
||||||
|
|
||||||
emit generatedKeypair(publicKeyArray, privateKeyArray);
|
emit generatedKeypair();
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,16 +22,21 @@ public:
|
||||||
|
|
||||||
void setDomainID(const QUuid& domainID) { _domainID = domainID; }
|
void setDomainID(const QUuid& domainID) { _domainID = domainID; }
|
||||||
const QUuid& getDomainID() const { return _domainID; }
|
const QUuid& getDomainID() const { return _domainID; }
|
||||||
|
|
||||||
|
const QByteArray& getPublicKey() const { return _publicKey; }
|
||||||
|
const QByteArray& getPrivateKey() const { return _privateKey; }
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void generateKeypair();
|
void generateKeypair();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void errorGeneratingKeypair();
|
void errorGeneratingKeypair();
|
||||||
void generatedKeypair(QByteArray publicKey, QByteArray privateKey);
|
void generatedKeypair();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QUuid _domainID;
|
QUuid _domainID;
|
||||||
|
QByteArray _publicKey;
|
||||||
|
QByteArray _privateKey;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_RSAKeypairGenerator_h
|
#endif // hifi_RSAKeypairGenerator_h
|
||||||
|
|
Loading…
Reference in a new issue