From 61018d046c6d109c5f5b8c35b0e0e1f1a883fb99 Mon Sep 17 00:00:00 2001 From: Long Le Date: Fri, 24 Feb 2023 10:55:37 +0100 Subject: [PATCH 1/2] Verify peer's public key earlier: Fix an issue introduced by #4195 / 5a15229 (part of 1.10.0-b1) --- src/ripple/overlay/impl/Handshake.cpp | 36 +++++++++++++-------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/ripple/overlay/impl/Handshake.cpp b/src/ripple/overlay/impl/Handshake.cpp index 793dec19eef..02af6d571e2 100644 --- a/src/ripple/overlay/impl/Handshake.cpp +++ b/src/ripple/overlay/impl/Handshake.cpp @@ -301,6 +301,24 @@ verifyHandshake( throw std::runtime_error("Bad node public key"); }(); + // This check gets two birds with one stone: + // + // 1) it verifies that the node we are talking to has access to the + // private key corresponding to the public node identity it claims. + // 2) it verifies that our SSL session is end-to-end with that node + // and not through a proxy that establishes two separate sessions. + { + auto const iter = headers.find("Session-Signature"); + + if (iter == headers.end()) + throw std::runtime_error("No session signature specified"); + + auto sig = base64_decode(iter->value().to_string()); + + if (!verifyDigest(publicKey, sharedValue, makeSlice(sig), false)) + throw std::runtime_error("Failed to verify session"); + } + if (publicKey == app.nodeIdentity().first) { auto const peerInstanceID = [&headers]() { @@ -331,24 +349,6 @@ verifyHandshake( throw std::runtime_error("Self connection"); } - // This check gets two birds with one stone: - // - // 1) it verifies that the node we are talking to has access to the - // private key corresponding to the public node identity it claims. - // 2) it verifies that our SSL session is end-to-end with that node - // and not through a proxy that establishes two separate sessions. - { - auto const iter = headers.find("Session-Signature"); - - if (iter == headers.end()) - throw std::runtime_error("No session signature specified"); - - auto sig = base64_decode(iter->value().to_string()); - - if (!verifyDigest(publicKey, sharedValue, makeSlice(sig), false)) - throw std::runtime_error("Failed to verify session"); - } - if (auto const iter = headers.find("Local-IP"); iter != headers.end()) { boost::system::error_code ec; From d4e51f933d62bae54a5693154c31a3ee2d86607a Mon Sep 17 00:00:00 2001 From: Nik Bougalis Date: Sat, 25 Feb 2023 01:43:18 -0800 Subject: [PATCH 2/2] [FOLD] Fix the remaining attack vector Partially revert the functionality introduced with 5a15229eeb13b69c8adf1f653b88a8f8b9480546. --- src/ripple/overlay/impl/Handshake.cpp | 29 +-------------------------- 1 file changed, 1 insertion(+), 28 deletions(-) diff --git a/src/ripple/overlay/impl/Handshake.cpp b/src/ripple/overlay/impl/Handshake.cpp index 02af6d571e2..f2c2bfd22af 100644 --- a/src/ripple/overlay/impl/Handshake.cpp +++ b/src/ripple/overlay/impl/Handshake.cpp @@ -320,35 +320,8 @@ verifyHandshake( } if (publicKey == app.nodeIdentity().first) - { - auto const peerInstanceID = [&headers]() { - std::uint64_t iid = 0; - - if (auto const iter = headers.find("Instance-Cookie"); - iter != headers.end()) - { - if (!beast::lexicalCastChecked(iid, iter->value().to_string())) - throw std::runtime_error("Invalid instance cookie"); - - if (iid == 0) - throw std::runtime_error("Invalid instance cookie"); - } - - return iid; - }(); - - // Attempt to differentiate self-connections as opposed to accidental - // node identity reuse caused by accidental misconfiguration. When we - // detect this, we stop the process and log an error message. - if (peerInstanceID != app.instanceID()) - { - app.signalStop("Remote server is using our node identity"); - throw std::runtime_error("Node identity reuse detected"); - } - throw std::runtime_error("Self connection"); - } - + if (auto const iter = headers.find("Local-IP"); iter != headers.end()) { boost::system::error_code ec;