From 4b255b1756a3de4800d5d3ebaf381035bfe34f7b Mon Sep 17 00:00:00 2001 From: Harald Alvestrand Date: Mon, 10 Oct 2022 10:22:39 +0000 Subject: [PATCH] Deprecate non-message STUN integrity check functions The one to use is StunMessage::ValidateMessageIntegrity(password). Bug: chromium:1177125 Change-Id: I345f4d6b60090651bc23c3aa6358d4fb24723f9f Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/278601 Commit-Queue: Harald Alvestrand Reviewed-by: Johannes Kron Cr-Commit-Position: refs/heads/main@{#38338} --- api/transport/stun.cc | 20 ++++++++++++++++++++ api/transport/stun.h | 36 +++++++++++++++++------------------- 2 files changed, 37 insertions(+), 19 deletions(-) diff --git a/api/transport/stun.cc b/api/transport/stun.cc index 53515b17aa..0bd2d24fa5 100644 --- a/api/transport/stun.cc +++ b/api/transport/stun.cc @@ -327,6 +327,25 @@ StunMessage::IntegrityStatus StunMessage::ValidateMessageIntegrity( return integrity_; } +bool StunMessage::ValidateMessageIntegrityForTesting( + const char* data, + size_t size, + const std::string& password) { + return ValidateMessageIntegrityOfType(STUN_ATTR_MESSAGE_INTEGRITY, + kStunMessageIntegritySize, data, size, + password); +} + +bool StunMessage::ValidateMessageIntegrity32ForTesting( + const char* data, + size_t size, + const std::string& password) { + return ValidateMessageIntegrityOfType(STUN_ATTR_GOOG_MESSAGE_INTEGRITY_32, + kStunMessageIntegrity32Size, data, size, + password); +} + +// Deprecated bool StunMessage::ValidateMessageIntegrity(const char* data, size_t size, const std::string& password) { @@ -335,6 +354,7 @@ bool StunMessage::ValidateMessageIntegrity(const char* data, password); } +// Deprecated bool StunMessage::ValidateMessageIntegrity32(const char* data, size_t size, const std::string& password) { diff --git a/api/transport/stun.h b/api/transport/stun.h index 2098330f5a..72a77990b4 100644 --- a/api/transport/stun.h +++ b/api/transport/stun.h @@ -283,29 +283,27 @@ class StunMessage { bool EqualAttributes(const StunMessage* other, std::function attribute_type_mask) const; - // Expose raw-buffer ValidateMessageIntegrity function for testing. - static bool ValidateMessageIntegrityForTesting(const char* data, - size_t size, - const std::string& password) { - return ValidateMessageIntegrity(data, size, password); - } - // Expose raw-buffer ValidateMessageIntegrity function for testing. - static bool ValidateMessageIntegrity32ForTesting( - const char* data, - size_t size, - const std::string& password) { - return ValidateMessageIntegrity32(data, size, password); - } // Validates that a STUN message in byte buffer form // has a correct MESSAGE-INTEGRITY value. // These functions are not recommended and will be deprecated; use // ValidateMessageIntegrity(password) on the parsed form instead. - static bool ValidateMessageIntegrity(const char* data, - size_t size, - const std::string& password); - static bool ValidateMessageIntegrity32(const char* data, - size_t size, - const std::string& password); + [[deprecated("Use member function")]] static bool ValidateMessageIntegrity( + const char* data, + size_t size, + const std::string& password); + [[deprecated("Use member function")]] static bool ValidateMessageIntegrity32( + const char* data, + size_t size, + const std::string& password); + + // Expose raw-buffer ValidateMessageIntegrity function for testing. + static bool ValidateMessageIntegrityForTesting(const char* data, + size_t size, + const std::string& password); + // Expose raw-buffer ValidateMessageIntegrity function for testing. + static bool ValidateMessageIntegrity32ForTesting(const char* data, + size_t size, + const std::string& password); protected: // Verifies that the given attribute is allowed for this message.