Re-use challenge nonce until challenge succeeds

This commit is contained in:
Simon Walton 2019-10-18 14:37:04 -07:00
parent 6bcb9f64f7
commit f573f8e03b
2 changed files with 16 additions and 7 deletions

View file

@ -52,7 +52,7 @@ void MixerAvatar::challengeTimeout() {
} else { } else {
_certifyFailed = true; _certifyFailed = true;
_needsIdentityUpdate = true; _needsIdentityUpdate = true;
qCDebug(avatars) << "Dynamic verification TIMED-OUT for" << getDisplayName() << getSessionUUID(); qCWarning(avatars) << "ALERT: Dynamic verification TIMED-OUT for" << getDisplayName() << getSessionUUID();
} }
break; break;
@ -64,6 +64,7 @@ void MixerAvatar::challengeTimeout() {
default: default:
qCDebug(avatars) << "Ignoring timeout of avatar challenge"; qCDebug(avatars) << "Ignoring timeout of avatar challenge";
break;
} }
} }
@ -76,7 +77,7 @@ void MixerAvatar::fetchAvatarFST() {
_pendingEvent = false; _pendingEvent = false;
QUrl avatarURL = getSkeletonModelURL(); QUrl avatarURL = getSkeletonModelURL();
if (avatarURL.isEmpty() || avatarURL.isLocalFile() || avatarURL.scheme() == "qrc") { if ((avatarURL.isEmpty() || avatarURL.isLocalFile() || avatarURL.scheme() == "qrc") && !isCertifyFailed()) {
// Not network FST. // Not network FST.
return; return;
} }
@ -340,18 +341,24 @@ void MixerAvatar::processCertifyEvents() {
void MixerAvatar::sendOwnerChallenge() { void MixerAvatar::sendOwnerChallenge() {
auto nodeList = DependencyManager::get<NodeList>(); auto nodeList = DependencyManager::get<NodeList>();
QByteArray avatarID = ("{" + _marketplaceIdFromFST + "}").toUtf8(); QByteArray avatarID = ("{" + _marketplaceIdFromFST + "}").toUtf8();
QByteArray nonce = QUuid::createUuid().toByteArray(); if (_challengeNonce.isEmpty()) {
_challengeNonce = QUuid::createUuid().toByteArray();
QCryptographicHash nonceHash(QCryptographicHash::Sha256);
nonceHash.addData(_challengeNonce);
_challengeNonceHash = nonceHash.result();
}
auto challengeOwnershipPacket = NLPacket::create(PacketType::ChallengeOwnership, auto challengeOwnershipPacket = NLPacket::create(PacketType::ChallengeOwnership,
2 * sizeof(int) + nonce.length() + avatarID.length(), true); 2 * sizeof(int) + _challengeNonce.length() + avatarID.length(), true);
challengeOwnershipPacket->writePrimitive(avatarID.length()); challengeOwnershipPacket->writePrimitive(avatarID.length());
challengeOwnershipPacket->writePrimitive(nonce.length()); challengeOwnershipPacket->writePrimitive(_challengeNonce.length());
challengeOwnershipPacket->write(avatarID); challengeOwnershipPacket->write(avatarID);
challengeOwnershipPacket->write(nonce); challengeOwnershipPacket->write(_challengeNonce);
nodeList->sendPacket(std::move(challengeOwnershipPacket), *(nodeList->nodeWithUUID(getSessionUUID())) ); nodeList->sendPacket(std::move(challengeOwnershipPacket), *(nodeList->nodeWithUUID(getSessionUUID())) );
QCryptographicHash nonceHash(QCryptographicHash::Sha256); QCryptographicHash nonceHash(QCryptographicHash::Sha256);
nonceHash.addData(nonce); nonceHash.addData(_challengeNonce);
_challengeNonceHash = nonceHash.result(); _challengeNonceHash = nonceHash.result();
_pendingEvent = false; _pendingEvent = false;
@ -390,6 +397,7 @@ void MixerAvatar::processChallengeResponse(ReceivedMessage& response) {
emit startChallengeTimer(); emit startChallengeTimer();
} else { } else {
qCDebug(avatars) << "Dynamic verification SUCCEEDED for" << getDisplayName() << getSessionUUID(); qCDebug(avatars) << "Dynamic verification SUCCEEDED for" << getDisplayName() << getSessionUUID();
_challengeNonce.clear();
} }
} else { } else {

View file

@ -58,6 +58,7 @@ private:
QString _certificateIdFromFST; QString _certificateIdFromFST;
QString _dynamicMarketResponse; QString _dynamicMarketResponse;
QString _ownerPublicKey; QString _ownerPublicKey;
QByteArray _challengeNonce;
QByteArray _challengeNonceHash; QByteArray _challengeNonceHash;
QTimer _challengeTimer; QTimer _challengeTimer;
static constexpr int NUM_CHALLENGES_BEFORE_FAIL = 1; static constexpr int NUM_CHALLENGES_BEFORE_FAIL = 1;