OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "components/cryptauth/session_keys.h" |
| 6 |
| 7 #include <string> |
| 8 #include <vector> |
| 9 |
| 10 #include "base/macros.h" |
| 11 #include "base/strings/string_number_conversions.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 |
| 14 namespace cryptauth { |
| 15 namespace { |
| 16 |
| 17 // Values generated using the Android implementation. |
| 18 const char kMasterKeyHex[] = |
| 19 "f611126a04302551ac1e8ed512952ee287a1d2561e2a2c72e7bf1ebe4bdc74ce"; |
| 20 const char kInitiatorKeyHex[] = |
| 21 "787ec48783f0a1f9fb9c5bc0230c2e7f45b8783acf8c9bd1c63242df9da31999"; |
| 22 const char kResponderKeyHex[] = |
| 23 "a366ec1f9cf327b69c341211216545cc302379078229eae78b43d60c110a6fba"; |
| 24 |
| 25 } // namespace |
| 26 |
| 27 class CryptAuthSessionKeysTest : public testing::Test { |
| 28 protected: |
| 29 CryptAuthSessionKeysTest() {} |
| 30 |
| 31 DISALLOW_COPY_AND_ASSIGN(CryptAuthSessionKeysTest); |
| 32 }; |
| 33 |
| 34 TEST_F(CryptAuthSessionKeysTest, GenerateKeys) { |
| 35 std::vector<uint8_t> data; |
| 36 |
| 37 std::string master_key(kMasterKeyHex); |
| 38 ASSERT_TRUE(base::HexStringToBytes(master_key, &data)); |
| 39 master_key.assign(reinterpret_cast<char*>(&data[0]), data.size()); |
| 40 |
| 41 data.clear(); |
| 42 std::string initiator_key(kInitiatorKeyHex); |
| 43 ASSERT_TRUE(base::HexStringToBytes(initiator_key, &data)); |
| 44 initiator_key.assign(reinterpret_cast<char*>(&data[0]), data.size()); |
| 45 |
| 46 data.clear(); |
| 47 std::string responder_key(kResponderKeyHex); |
| 48 ASSERT_TRUE(base::HexStringToBytes(responder_key, &data)); |
| 49 responder_key.assign(reinterpret_cast<char*>(&data[0]), data.size()); |
| 50 |
| 51 SessionKeys session_keys(master_key); |
| 52 EXPECT_EQ(initiator_key, session_keys.initiator_encode_key()); |
| 53 EXPECT_EQ(responder_key, session_keys.responder_encode_key()); |
| 54 } |
| 55 |
| 56 } // namespace cryptauth |
OLD | NEW |