From e2f02347dd17b1bdde83ff75adac42157e8fd1a5 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 23 Feb 2016 10:57:54 -0800 Subject: [PATCH] repairs to issues discovered during ID change --- domain-server/src/DomainServer.cpp | 14 ++++++++++++-- ice-server/src/IceServer.cpp | 3 +-- libraries/networking/src/AccountManager.cpp | 4 ++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index 46aa9ab2ee..de34802bb7 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -1055,6 +1055,15 @@ void DomainServer::sendHeartbeatToDataServer(const QString& networkAddress) { void DomainServer::sendHeartbeatToIceServer() { if (!_iceServerSocket.getAddress().isNull()) { + + auto& accountManager = AccountManager::getInstance(); + if (!accountManager.getAccountInfo().hasPrivateKey()) { + qWarning() << "Cannot send an ice-server heartbeat without a private key for signature."; + qWarning() << "Please re-launch your domain-server to generate a new keypair."; + + return; + } + // NOTE: I'd love to specify the correct size for the packet here, but it's a little trickey with // QDataStream and the possibility of IPv6 address for the sockets. static auto heartbeatPacket = NLPacket::create(PacketType::ICEServerHeartbeat); @@ -1073,7 +1082,9 @@ void DomainServer::sendHeartbeatToIceServer() { HifiSockAddr publicSocket, localSocket; heartbeatStream >> senderUUID >> publicSocket >> localSocket; - if (publicSocket != limitedNodeList->getPublicSockAddr() || localSocket != limitedNodeList->getLocalSockAddr()) { + if (senderUUID != limitedNodeList->getSessionUUID() + || publicSocket != limitedNodeList->getPublicSockAddr() + || localSocket != limitedNodeList->getLocalSockAddr()) { shouldRecreatePacket = true; } } else { @@ -1095,7 +1106,6 @@ void DomainServer::sendHeartbeatToIceServer() { auto plaintext = QByteArray::fromRawData(heartbeatPacket->getPayload(), heartbeatPacket->getPayloadSize()); // generate a signature for the plaintext data in the packet - auto& accountManager = AccountManager::getInstance(); auto signature = accountManager.getAccountInfo().signPlaintext(plaintext); // pack the signature with the data diff --git a/ice-server/src/IceServer.cpp b/ice-server/src/IceServer.cpp index d0dad812aa..1de9a4bb58 100644 --- a/ice-server/src/IceServer.cpp +++ b/ice-server/src/IceServer.cpp @@ -237,8 +237,7 @@ void IceServer::publicKeyReplyFinished(QNetworkReply* reply) { if (responseObject[STATUS_KEY].toString() == SUCCESS_VALUE) { auto dataObject = responseObject[DATA_KEY].toObject(); if (dataObject.contains(PUBLIC_KEY_KEY)) { - _domainPublicKeys.emplace(domainID, - QByteArray::fromBase64(dataObject[PUBLIC_KEY_KEY].toString().toUtf8())); + _domainPublicKeys[domainID] = QByteArray::fromBase64(dataObject[PUBLIC_KEY_KEY].toString().toUtf8()); } else { qWarning() << "There was no public key present in response for domain with ID" << domainID; } diff --git a/libraries/networking/src/AccountManager.cpp b/libraries/networking/src/AccountManager.cpp index fc1d8e9458..d9099aa925 100644 --- a/libraries/networking/src/AccountManager.cpp +++ b/libraries/networking/src/AccountManager.cpp @@ -589,6 +589,10 @@ void AccountManager::generateNewKeypair(bool isUserKeypair, const QUuid& domainI return; } + // clear the current private key + qDebug() << "Clearing current private key in DataServerAccountInfo"; + _accountInfo.setPrivateKey(QByteArray()); + // 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");