| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/proximity_auth/cryptauth/fake_secure_message_delegate.h" | 5 #include "components/proximity_auth/cryptauth/fake_secure_message_delegate.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/md5.h" | 10 #include "base/md5.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 const std::string& payload, | 69 const std::string& payload, |
| 70 const std::string& associated_data, | 70 const std::string& associated_data, |
| 71 const std::string& key, | 71 const std::string& key, |
| 72 const securemessage::SigScheme& signature_scheme) { | 72 const securemessage::SigScheme& signature_scheme) { |
| 73 std::string signing_key; | 73 std::string signing_key; |
| 74 | 74 |
| 75 if (signature_scheme == securemessage::HMAC_SHA256) { | 75 if (signature_scheme == securemessage::HMAC_SHA256) { |
| 76 signing_key = key; | 76 signing_key = key; |
| 77 } else { | 77 } else { |
| 78 std::string prefix = kPrivateKeyPrefix; | 78 std::string prefix = kPrivateKeyPrefix; |
| 79 bool is_private_key = base::StartsWithASCII(key, prefix, true); | 79 bool is_private_key = |
| 80 base::StartsWith(key, prefix, base::CompareCase::SENSITIVE); |
| 80 signing_key = is_private_key ? key.substr(prefix.size()) : prefix + key; | 81 signing_key = is_private_key ? key.substr(prefix.size()) : prefix + key; |
| 81 } | 82 } |
| 82 | 83 |
| 83 std::string expected_signature = Sign(payload, associated_data, signing_key); | 84 std::string expected_signature = Sign(payload, associated_data, signing_key); |
| 84 return signature == expected_signature; | 85 return signature == expected_signature; |
| 85 } | 86 } |
| 86 | 87 |
| 87 } // namespace | 88 } // namespace |
| 88 | 89 |
| 89 FakeSecureMessageDelegate::FakeSecureMessageDelegate() | 90 FakeSecureMessageDelegate::FakeSecureMessageDelegate() |
| (...skipping 16 matching lines...) Expand all Loading... |
| 106 } | 107 } |
| 107 | 108 |
| 108 void FakeSecureMessageDelegate::DeriveKey(const std::string& private_key, | 109 void FakeSecureMessageDelegate::DeriveKey(const std::string& private_key, |
| 109 const std::string& public_key, | 110 const std::string& public_key, |
| 110 const DeriveKeyCallback& callback) { | 111 const DeriveKeyCallback& callback) { |
| 111 // To ensure that the same symmetric key is derived for DeriveKey(private1, | 112 // To ensure that the same symmetric key is derived for DeriveKey(private1, |
| 112 // public2) and DeriveKey(private2, public1), we remove the prefix from the | 113 // public2) and DeriveKey(private2, public1), we remove the prefix from the |
| 113 // private key so it is equal to its corresponding public key. | 114 // private key so it is equal to its corresponding public key. |
| 114 std::string prefix(kPrivateKeyPrefix); | 115 std::string prefix(kPrivateKeyPrefix); |
| 115 std::string normalized_private_key = | 116 std::string normalized_private_key = |
| 116 base::StartsWithASCII(private_key, prefix, true) | 117 base::StartsWith(private_key, prefix, base::CompareCase::SENSITIVE) |
| 117 ? private_key.substr(prefix.size()) | 118 ? private_key.substr(prefix.size()) |
| 118 : private_key; | 119 : private_key; |
| 119 | 120 |
| 120 std::vector<std::string> keys; | 121 std::vector<std::string> keys; |
| 121 keys.push_back(normalized_private_key); | 122 keys.push_back(normalized_private_key); |
| 122 keys.push_back(public_key); | 123 keys.push_back(public_key); |
| 123 std::sort(keys.begin(), keys.end()); | 124 std::sort(keys.begin(), keys.end()); |
| 124 callback.Run(base::MD5String(keys[0] + "|" + keys[1])); | 125 callback.Run(base::MD5String(keys[0] + "|" + keys[1])); |
| 125 } | 126 } |
| 126 | 127 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 callback.Run(false, std::string(), securemessage::Header()); | 189 callback.Run(false, std::string(), securemessage::Header()); |
| 189 } | 190 } |
| 190 } | 191 } |
| 191 | 192 |
| 192 std::string FakeSecureMessageDelegate::GetPrivateKeyForPublicKey( | 193 std::string FakeSecureMessageDelegate::GetPrivateKeyForPublicKey( |
| 193 const std::string& public_key) { | 194 const std::string& public_key) { |
| 194 return kPrivateKeyPrefix + public_key; | 195 return kPrivateKeyPrefix + public_key; |
| 195 } | 196 } |
| 196 | 197 |
| 197 } // namespace proximity_auth | 198 } // namespace proximity_auth |
| OLD | NEW |