From af181e00b120d0d6e58e44df67bed3ac243092ea Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 19 Feb 2016 14:34:19 -0800 Subject: [PATCH] allow for creation of domain-server keypair in AccountManager --- domain-server/src/DomainServer.cpp | 2 ++ libraries/networking/src/AccountManager.cpp | 21 +++++++++++++------ libraries/networking/src/AccountManager.h | 8 ++++++- .../networking/src/RSAKeypairGenerator.h | 13 ++++++++++-- 4 files changed, 35 insertions(+), 9 deletions(-) diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index 9e13c8e6fa..663b596486 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -526,6 +526,8 @@ void DomainServer::setupICEHeartbeatForFullNetworking() { // we need this DS to know what our public IP is - start trying to figure that out now limitedNodeList->startSTUNPublicSocketUpdate(); + // to send ICE heartbeats we'd better have a private key locally with an uploaded public key + if (!_iceHeartbeatTimer) { // setup a timer to heartbeat with the ice-server every so often _iceHeartbeatTimer = new QTimer { this }; diff --git a/libraries/networking/src/AccountManager.cpp b/libraries/networking/src/AccountManager.cpp index 4ded2216d0..dc58624534 100644 --- a/libraries/networking/src/AccountManager.cpp +++ b/libraries/networking/src/AccountManager.cpp @@ -82,7 +82,7 @@ AccountManager::AccountManager() : connect(&_accountInfo, &DataServerAccountInfo::balanceChanged, this, &AccountManager::accountInfoBalanceChanged); // once we have a profile in account manager make sure we generate a new keypair - connect(this, &AccountManager::profileChanged, this, &AccountManager::generateNewKeypair); + connect(this, &AccountManager::profileChanged, this, &AccountManager::generateNewUserKeypair); } const QString DOUBLE_SLASH_SUBSTITUTE = "slashslash"; @@ -482,23 +482,32 @@ void AccountManager::requestProfileError(QNetworkReply::NetworkError error) { qCDebug(networking) << "AccountManager requestProfileError - " << error; } -void AccountManager::generateNewKeypair() { +void AccountManager::generateNewKeypair(bool isUserKeypair, const QUuid& domainID) { + if (!isUserKeypair && domainID.isNull()) { + qWarning() << "AccountManager::generateNewKeypair called for domain keypair with no domain ID. Will not generate keypair."; + return; + } + // setup a new QThread to generate the keypair on, in case it takes a while QThread* generateThread = new QThread(this); generateThread->setObjectName("Account Manager Generator Thread"); - + // setup a keypair generator RSAKeypairGenerator* keypairGenerator = new RSAKeypairGenerator(); - + + if (!isUserKeypair) { + keypairGenerator->setDomainID(domainID); + } + connect(generateThread, &QThread::started, keypairGenerator, &RSAKeypairGenerator::generateKeypair); connect(keypairGenerator, &RSAKeypairGenerator::generatedKeypair, this, &AccountManager::processGeneratedKeypair); connect(keypairGenerator, &RSAKeypairGenerator::errorGeneratingKeypair, this, &AccountManager::handleKeypairGenerationError); connect(keypairGenerator, &QObject::destroyed, generateThread, &QThread::quit); connect(generateThread, &QThread::finished, generateThread, &QThread::deleteLater); - + keypairGenerator->moveToThread(generateThread); - + qCDebug(networking) << "Starting worker thread to generate 2048-bit RSA key-pair."; generateThread->start(); } diff --git a/libraries/networking/src/AccountManager.h b/libraries/networking/src/AccountManager.h index 719279b0cf..bce5fb512d 100644 --- a/libraries/networking/src/AccountManager.h +++ b/libraries/networking/src/AccountManager.h @@ -87,7 +87,9 @@ public slots: void logout(); void updateBalance(); void accountInfoBalanceChanged(qint64 newBalance); - void generateNewKeypair(); + void generateNewUserKeypair() { generateNewKeypair(); } + void generateNewDomainKeypair(const QUuid& domainID) { generateNewKeypair(false, domainID); } + signals: void authRequired(); void authEndpointChanged(); @@ -97,10 +99,12 @@ signals: void loginFailed(); void logoutComplete(); void balanceChanged(qint64 newBalance); + private slots: void processReply(); void handleKeypairGenerationError(); void processGeneratedKeypair(const QByteArray& publicKey, const QByteArray& privateKey); + private: AccountManager(); AccountManager(AccountManager const& other); // not implemented @@ -111,6 +115,8 @@ private: void passSuccessToCallback(QNetworkReply* reply); void passErrorToCallback(QNetworkReply* reply); + void generateNewKeypair(bool isUserKeypair = true, const QUuid& domainID = QUuid()); + QUrl _authURL; QMap _pendingCallbackMap; diff --git a/libraries/networking/src/RSAKeypairGenerator.h b/libraries/networking/src/RSAKeypairGenerator.h index dd90313625..391065768f 100644 --- a/libraries/networking/src/RSAKeypairGenerator.h +++ b/libraries/networking/src/RSAKeypairGenerator.h @@ -12,17 +12,26 @@ #ifndef hifi_RSAKeypairGenerator_h #define hifi_RSAKeypairGenerator_h -#include +#include +#include class RSAKeypairGenerator : public QObject { Q_OBJECT public: RSAKeypairGenerator(QObject* parent = 0); + + void setDomainID(const QUuid& domainID) { _domainID = domainID; } + const QUuid& getDomainID() const { return _domainID; } + public slots: void generateKeypair(); + signals: void errorGeneratingKeypair(); void generatedKeypair(const QByteArray& publicKey, const QByteArray& privateKey); + +private: + QUuid _domainID; }; -#endif // hifi_RSAKeypairGenerator_h \ No newline at end of file +#endif // hifi_RSAKeypairGenerator_h