Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(378)

Unified Diff: components/cryptauth/device_to_device_secure_context_unittest.cc

Issue 2899863002: Updating D2D protocol to v1 to support separate sequence numbers. (Closed)
Patch Set: Addressing comments Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/cryptauth/device_to_device_secure_context_unittest.cc
diff --git a/components/cryptauth/device_to_device_secure_context_unittest.cc b/components/cryptauth/device_to_device_secure_context_unittest.cc
index 12c1994fa208f5c4b50f9e6faf475b68db457781..f26749264a88b5d4721120bfd04ab07034ee0b6b 100644
--- a/components/cryptauth/device_to_device_secure_context_unittest.cc
+++ b/components/cryptauth/device_to_device_secure_context_unittest.cc
@@ -11,6 +11,7 @@
#include "components/cryptauth/fake_secure_message_delegate.h"
#include "components/cryptauth/proto/cryptauth_api.pb.h"
#include "components/cryptauth/proto/securemessage.pb.h"
+#include "components/cryptauth/session_keys.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace cryptauth {
@@ -27,16 +28,34 @@ void SaveResult(std::string* result_out, const std::string& result) {
*result_out = result;
}
+// The responder's secure context will have the encoding / decoding keys
+// inverted.
+class InvertedSessionKeys : public SessionKeys {
+ public:
+ explicit InvertedSessionKeys(const std::string& master_symmetric_key)
+ : SessionKeys(master_symmetric_key) {}
+
+ InvertedSessionKeys() : SessionKeys() {}
+
+ InvertedSessionKeys(const InvertedSessionKeys& other) : SessionKeys(other) {}
+
+ std::string initiator_encode_key() const override {
+ return SessionKeys::responder_encode_key();
+ }
+ std::string responder_encode_key() const override {
+ return SessionKeys::initiator_encode_key();
+ }
+};
+
} // namespace
class ProximityAuthDeviceToDeviceSecureContextTest : public testing::Test {
protected:
ProximityAuthDeviceToDeviceSecureContextTest()
- : secure_context_(
- base::MakeUnique<FakeSecureMessageDelegate>(),
- kSymmetricKey,
- kResponderAuthMessage,
- kProtocolVersion) {}
+ : secure_context_(base::MakeUnique<FakeSecureMessageDelegate>(),
+ SessionKeys(kSymmetricKey),
+ kResponderAuthMessage,
+ kProtocolVersion) {}
DeviceToDeviceSecureContext secure_context_;
};
@@ -74,11 +93,18 @@ TEST_F(ProximityAuthDeviceToDeviceSecureContextTest, DecodeInvalidMessage) {
TEST_F(ProximityAuthDeviceToDeviceSecureContextTest, EncodeAndDecode) {
// Initialize second secure channel with the same parameters as the first.
+ InvertedSessionKeys inverted_session_keys(kSymmetricKey);
DeviceToDeviceSecureContext secure_context2(
- base::MakeUnique<FakeSecureMessageDelegate>(), kSymmetricKey,
+ base::MakeUnique<FakeSecureMessageDelegate>(), inverted_session_keys,
kResponderAuthMessage, kProtocolVersion);
std::string message = "encrypt this message";
+ SessionKeys session_keys(kSymmetricKey);
+ EXPECT_EQ(session_keys.initiator_encode_key(),
+ inverted_session_keys.responder_encode_key());
+ EXPECT_EQ(session_keys.responder_encode_key(),
+ inverted_session_keys.initiator_encode_key());
+
// Pass some messages between the two secure contexts.
for (int i = 0; i < 3; ++i) {
std::string encoded_message;
@@ -96,8 +122,9 @@ TEST_F(ProximityAuthDeviceToDeviceSecureContextTest,
DecodeInvalidSequenceNumber) {
// Initialize second secure channel with the same parameters as the first.
DeviceToDeviceSecureContext secure_context2(
- base::MakeUnique<FakeSecureMessageDelegate>(), kSymmetricKey,
- kResponderAuthMessage, kProtocolVersion);
+ base::MakeUnique<FakeSecureMessageDelegate>(),
+ InvertedSessionKeys(kSymmetricKey), kResponderAuthMessage,
+ kProtocolVersion);
// Send a few messages over the first secure context.
std::string message = "encrypt this message";
« no previous file with comments | « components/cryptauth/device_to_device_secure_context.cc ('k') | components/cryptauth/proto/securemessage.proto » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698