Chromium Code Reviews| Index: net/spdy/spdy_test_utils.cc |
| diff --git a/net/spdy/spdy_test_utils.cc b/net/spdy/spdy_test_utils.cc |
| index e33a08bc1c33f81d4bcdef41e91a16abedef0084..ef2b7971feed3fca79c6eb9f3127bc901668097e 100644 |
| --- a/net/spdy/spdy_test_utils.cc |
| +++ b/net/spdy/spdy_test_utils.cc |
| @@ -7,10 +7,12 @@ |
| #include <cstring> |
| #include <vector> |
| +#include "base/base64.h" |
| #include "base/logging.h" |
| #include "base/memory/scoped_ptr.h" |
| #include "base/strings/string_number_conversions.h" |
| #include "base/sys_byteorder.h" |
| +#include "net/ssl/ssl_info.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| namespace net { |
| @@ -139,6 +141,36 @@ std::string a2b_hex(const char* hex_data) { |
| return result; |
| } |
| +HashValue GetTestHashValue(uint8 label) { |
| + HashValue hash_value(HASH_VALUE_SHA1); |
|
Ryan Sleevi
2014/08/11 18:45:17
Use SHA-256 for these.
SHA-1 is deprecated in HPK
Ryan Hamilton
2014/08/12 14:39:06
Done.
|
| + memset(hash_value.data(), label, hash_value.size()); |
| + return hash_value; |
| +} |
| + |
| +std::string GetTestPin(uint8 label) { |
| + HashValue hash_value = GetTestHashValue(label); |
| + std::string base64; |
| + base::Base64Encode(base::StringPiece( |
| + reinterpret_cast<char*>(hash_value.data()), hash_value.size()), &base64); |
| + |
| + return std::string("pin-sha1=\"") + base64 + "\""; |
| +} |
| + |
| +void AddPin(TransportSecurityState* state, |
| + const std::string& host, |
| + uint8 primary_label, |
| + uint8 backup_label) { |
| + std::string primary_pin = GetTestPin(primary_label); |
| + std::string backup_pin = GetTestPin(backup_label); |
| + std::string header = "max-age = 10000; " + primary_pin + "; " + backup_pin; |
| + |
| + // Construct a fake SSLInfo that will pass AddHPKPHeader's checks. |
| + SSLInfo ssl_info; |
| + ssl_info.is_issued_by_known_root = true; |
| + ssl_info.public_key_hashes.push_back(GetTestHashValue(primary_label)); |
| + EXPECT_TRUE(state->AddHPKPHeader(host, header, ssl_info)); |
| +} |
| + |
| } // namespace test |
| } // namespace net |