diff --git a/interface/src/commerce/Wallet.cpp b/interface/src/commerce/Wallet.cpp index 6952f3b327..fcb287c2d6 100644 --- a/interface/src/commerce/Wallet.cpp +++ b/interface/src/commerce/Wallet.cpp @@ -725,17 +725,18 @@ void Wallet::handleChallengeOwnershipPacket(QSharedPointer pack QByteArray certID = packet->read(certIDByteArraySize); QByteArray encryptedText = packet->read(encryptedTextByteArraySize); - const auto encryptedTextBuf = reinterpret_cast(encryptedText.constData()); - const unsigned int textLength = (int)strlen((char*)encryptedTextBuf); - RSA* rsa = readKeys(keyFilePath().toStdString().c_str()); if (rsa) { - const int decryptionStatus = RSA_private_decrypt(textLength, encryptedTextBuf, decryptedText, rsa, RSA_PKCS1_OAEP_PADDING); + const int decryptionStatus = RSA_private_decrypt(encryptedTextByteArraySize, + reinterpret_cast(encryptedText.constData()), + decryptedText, + rsa, + RSA_PKCS1_OAEP_PADDING); long error = ERR_get_error(); const char* error_str = ERR_error_string(error, NULL); - qDebug() << "ZRF HERE\n\nEncrypted Text:" << encryptedTextBuf << "\nEncrypted Text Length:" << textLength << "\nDecrypted Text:" << decryptedText << "\nError:" << error_str; + qDebug() << "ZRF HERE\n\nEncrypted Text:" << encryptedText << "\nEncrypted Text ByteArray Size:" << encryptedTextByteArraySize << "\nEncrypted Text Length:" << encryptedText.length() << "\nDecrypted Text:" << decryptedText << "\nError:" << error_str; RSA_free(rsa); diff --git a/libraries/entities/src/EntityTree.cpp b/libraries/entities/src/EntityTree.cpp index d96cdaaa3e..9a2048211f 100644 --- a/libraries/entities/src/EntityTree.cpp +++ b/libraries/entities/src/EntityTree.cpp @@ -1160,7 +1160,7 @@ void EntityTree::startPendingTransferStatusTimer(const QString& certID, const En transferStatusRetryTimer->start(90000); } -QString EntityTree::computeEncryptedNonce(const QString& certID, const QString ownerKey) { +QByteArray EntityTree::computeEncryptedNonce(const QString& certID, const QString ownerKey) { QUuid nonce = QUuid::createUuid(); const auto text = reinterpret_cast(qPrintable(nonce.toString())); const unsigned int textLength = nonce.toString().length(); @@ -1182,6 +1182,8 @@ QString EntityTree::computeEncryptedNonce(const QString& certID, const QString o QWriteLocker locker(&_certNonceMapLock); _certNonceMap.insert(certID, nonce); + qDebug() << "ZRF HERE\n\nEncrypted Text:" << encryptedText << "\nEncrypted Text Length:" << encryptedText.length(); + return encryptedText; } else { return ""; @@ -1251,26 +1253,22 @@ void EntityTree::validatePop(const QString& certID, const EntityItemID& entityIt } else { // Second, challenge ownership of the PoP cert // 1. Encrypt a nonce with the owner's public key - QString encryptedText = computeEncryptedNonce(certID, jsonObject["transfer_recipient_key"].toString()); + QByteArray encryptedText = computeEncryptedNonce(certID, jsonObject["transfer_recipient_key"].toString()); if (encryptedText == "") { qCDebug(entities) << "CRITICAL ERROR: Couldn't compute encrypted nonce. Deleting entity..."; deleteEntity(entityItemID, true); - QWriteLocker locker(&_recentlyDeletedEntitiesLock); - _recentlyDeletedEntityItemIDs.insert(usecTimestampNow(), entityItemID); } else { // 2. Send the encrypted text to the rezzing avatar's node QByteArray certIDByteArray = certID.toUtf8(); int certIDByteArraySize = certIDByteArray.size(); - QByteArray encryptedTextByteArray = encryptedText.toUtf8(); - int encryptedTextByteArraySize = encryptedTextByteArray.size(); auto challengeOwnershipPacket = NLPacket::create(PacketType::ChallengeOwnership, - certIDByteArraySize + encryptedTextByteArraySize + 2 * sizeof(int), + certIDByteArraySize + encryptedText.length() + 2 * sizeof(int), true); challengeOwnershipPacket->writePrimitive(certIDByteArraySize); - challengeOwnershipPacket->writePrimitive(encryptedTextByteArraySize); + challengeOwnershipPacket->writePrimitive(encryptedText.length()); challengeOwnershipPacket->write(certIDByteArray); - challengeOwnershipPacket->write(encryptedTextByteArray); + challengeOwnershipPacket->write(encryptedText); nodeList->sendPacket(std::move(challengeOwnershipPacket), *senderNode); // 3. Kickoff a 10-second timeout timer that deletes the entity if we don't get an ownership response in time diff --git a/libraries/entities/src/EntityTree.h b/libraries/entities/src/EntityTree.h index cffe0f6bb1..00a601d684 100644 --- a/libraries/entities/src/EntityTree.h +++ b/libraries/entities/src/EntityTree.h @@ -385,7 +385,7 @@ protected: Q_INVOKABLE void startPendingTransferStatusTimer(const QString& certID, const EntityItemID& entityItemID, const SharedNodePointer& senderNode); private: - QString computeEncryptedNonce(const QString& certID, const QString ownerKey); + QByteArray computeEncryptedNonce(const QString& certID, const QString ownerKey); bool verifyDecryptedNonce(const QString& certID, const QString& decryptedNonce); void validatePop(const QString& certID, const EntityItemID& entityItemID, const SharedNodePointer& senderNode, bool isRetryingValidation); };