Will it compile?

This commit is contained in:
Zach Fox 2017-10-31 12:31:42 -07:00
parent 6f96e0c7bd
commit f5ada4fe62
5 changed files with 47 additions and 21 deletions

View file

@ -67,7 +67,6 @@ signals:
private slots: private slots:
void handleChallengeOwnershipPacket(QSharedPointer<ReceivedMessage> packet, SharedNodePointer sendingNode); void handleChallengeOwnershipPacket(QSharedPointer<ReceivedMessage> packet, SharedNodePointer sendingNode);
void handleChallengeOwnershipRequestPacket(QSharedPointer<ReceivedMessage> packet, SharedNodePointer sendingNode);
private: private:
QStringList _publicKeys{}; QStringList _publicKeys{};

View file

@ -71,6 +71,10 @@ ContextOverlayInterface::ContextOverlayInterface() {
connect(&qApp->getOverlays(), &Overlays::hoverLeaveOverlay, this, &ContextOverlayInterface::contextOverlays_hoverLeaveOverlay); connect(&qApp->getOverlays(), &Overlays::hoverLeaveOverlay, this, &ContextOverlayInterface::contextOverlays_hoverLeaveOverlay);
connect(_selectionScriptingInterface.data(), &SelectionScriptingInterface::selectedItemsListChanged, &_selectionToSceneHandler, &SelectionToSceneHandler::selectedItemsListChanged); connect(_selectionScriptingInterface.data(), &SelectionScriptingInterface::selectedItemsListChanged, &_selectionToSceneHandler, &SelectionToSceneHandler::selectedItemsListChanged);
auto nodeList = DependencyManager::get<NodeList>();
auto& packetReceiver = nodeList->getPacketReceiver();
packetReceiver.registerListener(PacketType::ChallengeOwnershipReply, this, "handleChallengeOwnershipReplyPacket");
} }
static const uint32_t MOUSE_HW_ID = 0; static const uint32_t MOUSE_HW_ID = 0;
@ -375,3 +379,19 @@ void ContextOverlayInterface::deletingEntity(const EntityItemID& entityID) {
destroyContextOverlay(_currentEntityWithContextOverlay, PointerEvent()); destroyContextOverlay(_currentEntityWithContextOverlay, PointerEvent());
} }
} }
void ContextOverlayInterface::handleChallengeOwnershipReplyPacket(QSharedPointer<ReceivedMessage> packet, SharedNodePointer sendingNode) {
int certIDByteArraySize;
int decryptedTextByteArraySize;
packet->readPrimitive(&certIDByteArraySize);
packet->readPrimitive(&decryptedTextByteArraySize);
QString certID(packet->read(certIDByteArraySize));
QString decryptedText(packet->read(decryptedTextByteArraySize));
EntityItemID id;
bool verificationSuccess = DependencyManager::get<EntityTreeRenderer>()->getTree()->verifyDecryptedNonce(certID, decryptedText, id);
qDebug() << "ZRF VERIFICATION STATUS:" << verificationSuccess;
}

View file

@ -70,6 +70,9 @@ public slots:
void contextOverlays_hoverLeaveEntity(const EntityItemID& entityID, const PointerEvent& event); void contextOverlays_hoverLeaveEntity(const EntityItemID& entityID, const PointerEvent& event);
bool contextOverlayFilterPassed(const EntityItemID& entityItemID); bool contextOverlayFilterPassed(const EntityItemID& entityItemID);
private slots:
void handleChallengeOwnershipReplyPacket(QSharedPointer<ReceivedMessage> packet, SharedNodePointer sendingNode);
private: private:
bool _verboseLogging { true }; bool _verboseLogging { true };
bool _enabled { true }; bool _enabled { true };

View file

@ -1206,9 +1206,7 @@ QByteArray EntityTree::computeEncryptedNonce(const QString& certID, const QStrin
} }
} }
bool EntityTree::verifyDecryptedNonce(const QString& certID, const QString& decryptedNonce) { bool EntityTree::verifyDecryptedNonce(const QString& certID, const QString& decryptedNonce, EntityItemID& id) {
EntityItemID id;
{ {
QReadLocker certIdMapLocker(&_entityCertificateIDMapLock); QReadLocker certIdMapLocker(&_entityCertificateIDMapLock);
id = _entityCertificateIDMap.value(certID); id = _entityCertificateIDMap.value(certID);
@ -1221,14 +1219,12 @@ bool EntityTree::verifyDecryptedNonce(const QString& certID, const QString& decr
} }
bool verificationSuccess = (actualNonce == decryptedNonce); bool verificationSuccess = (actualNonce == decryptedNonce);
if (!verificationSuccess) {
if (!id.isNull()) { if (verificationSuccess) {
qCDebug(entities) << "Ownership challenge for Cert ID" << certID << "failed; deleting entity" << id qCDebug(entities) << "Ownership challenge for Cert ID" << certID << "succeeded for entity" << id;
<< "\nActual nonce:" << actualNonce << "\nDecrypted nonce:" << decryptedNonce;
deleteEntity(id, true);
}
} else { } else {
qCDebug(entities) << "Ownership challenge for Cert ID" << certID << "succeeded; keeping entity" << id; qCDebug(entities) << "Ownership challenge for Cert ID" << certID << "failed for entity" << id
<< "\nActual nonce:" << actualNonce << "\nDecrypted nonce:" << decryptedNonce;
} }
return verificationSuccess; return verificationSuccess;
@ -1268,8 +1264,6 @@ void EntityTree::processChallengeOwnershipReplyPacket(ReceivedMessage& message,
QByteArray decryptedText(message.read(decryptedTextByteArraySize)); QByteArray decryptedText(message.read(decryptedTextByteArraySize));
QUuid challengingNode = QUuid::fromRfc4122(message.read(senderNodeUUIDByteArraySize)); QUuid challengingNode = QUuid::fromRfc4122(message.read(senderNodeUUIDByteArraySize));
auto challengeOwnershipReplyPacket = NLPacket::create(PacketType::ChallengeOwnershipReply, auto challengeOwnershipReplyPacket = NLPacket::create(PacketType::ChallengeOwnershipReply,
certIDByteArraySize + decryptedText.length() + 2 * sizeof(int), certIDByteArraySize + decryptedText.length() + 2 * sizeof(int),
true); true);
@ -1319,19 +1313,24 @@ void EntityTree::sendChallengeOwnershipRequestPacket(const QString& certID, cons
// In this case, Client A is challenging Client B. Client A is inspecting a certified entity that it wants // In this case, Client A is challenging Client B. Client A is inspecting a certified entity that it wants
// to make sure belongs to Avatar B. // to make sure belongs to Avatar B.
QByteArray senderNodeUUID = senderNode->getUUID().toRfc4122();
QByteArray encryptedTextByteArray = encryptedText.toUtf8();
QByteArray certIDByteArray = certID.toUtf8(); QByteArray certIDByteArray = certID.toUtf8();
int certIDByteArraySize = certIDByteArray.size(); QByteArray encryptedTextByteArray = encryptedText.toUtf8();
QByteArray senderNodeUUID = senderNode->getUUID().toRfc4122();
int certIDByteArraySize = certIDByteArray.length();
int encryptedTextByteArraySize = encryptedTextByteArray.length();
int senderNodeUUIDSize = senderNodeUUID.length();
auto challengeOwnershipPacket = NLPacket::create(PacketType::ChallengeOwnershipRequest, auto challengeOwnershipPacket = NLPacket::create(PacketType::ChallengeOwnershipRequest,
certIDByteArraySize + encryptedTextByteArray.length() + senderNodeUUID.length() + 3 * sizeof(int), certIDByteArraySize + encryptedTextByteArraySize + senderNodeUUIDSize + 3 * sizeof(int),
true); true);
challengeOwnershipPacket->writePrimitive(certIDByteArraySize); challengeOwnershipPacket->writePrimitive(certIDByteArraySize);
challengeOwnershipPacket->writePrimitive(encryptedTextByteArray.length()); challengeOwnershipPacket->writePrimitive(encryptedTextByteArraySize);
challengeOwnershipPacket->writePrimitive(senderNodeUUID.length()); challengeOwnershipPacket->writePrimitive(senderNodeUUIDSize);
challengeOwnershipPacket->write(certIDByteArray); challengeOwnershipPacket->write(certIDByteArray);
challengeOwnershipPacket->write(encryptedTextByteArray); challengeOwnershipPacket->write(encryptedTextByteArray);
challengeOwnershipPacket->write(senderNodeUUID); challengeOwnershipPacket->write(senderNodeUUID);
nodeList->sendPacket(std::move(challengeOwnershipPacket), *(nodeList->nodeWithUUID(nodeToChallenge))); nodeList->sendPacket(std::move(challengeOwnershipPacket), *(nodeList->nodeWithUUID(nodeToChallenge)));
} }
@ -1408,7 +1407,12 @@ void EntityTree::processChallengeOwnershipPacket(ReceivedMessage& message, const
emit killChallengeOwnershipTimeoutTimer(certID); emit killChallengeOwnershipTimeoutTimer(certID);
verifyDecryptedNonce(certID, decryptedText); EntityItemID id;
if (!verifyDecryptedNonce(certID, decryptedText, id)) {
if (!id.isNull()) {
deleteEntity(id, true);
}
}
} }
int EntityTree::processEditPacketData(ReceivedMessage& message, const unsigned char* editData, int maxLength, int EntityTree::processEditPacketData(ReceivedMessage& message, const unsigned char* editData, int maxLength,

View file

@ -276,7 +276,7 @@ public:
static const float DEFAULT_MAX_TMP_ENTITY_LIFETIME; static const float DEFAULT_MAX_TMP_ENTITY_LIFETIME;
QByteArray computeEncryptedNonce(const QString& certID, const QString ownerKey); QByteArray computeEncryptedNonce(const QString& certID, const QString ownerKey);
bool verifyDecryptedNonce(const QString& certID, const QString& decryptedNonce); bool verifyDecryptedNonce(const QString& certID, const QString& decryptedNonce, EntityItemID& id);
signals: signals:
void deletingEntity(const EntityItemID& entityID); void deletingEntity(const EntityItemID& entityID);