Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "net/spdy/spdy_test_utils.h" | 5 #include "net/spdy/spdy_test_utils.h" |
| 6 | 6 |
| 7 #include <cstring> | 7 #include <cstring> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/base64.h" | |
| 10 #include "base/logging.h" | 11 #include "base/logging.h" |
| 11 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/sys_byteorder.h" | 14 #include "base/sys_byteorder.h" |
| 15 #include "net/ssl/ssl_info.h" | |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 17 |
| 16 namespace net { | 18 namespace net { |
| 17 | 19 |
| 18 namespace test { | 20 namespace test { |
| 19 | 21 |
| 20 std::string HexDumpWithMarks(const unsigned char* data, int length, | 22 std::string HexDumpWithMarks(const unsigned char* data, int length, |
| 21 const bool* marks, int mark_length) { | 23 const bool* marks, int mark_length) { |
| 22 static const char kHexChars[] = "0123456789abcdef"; | 24 static const char kHexChars[] = "0123456789abcdef"; |
| 23 static const int kColumns = 4; | 25 static const int kColumns = 4; |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 132 } | 134 } |
| 133 | 135 |
| 134 std::string a2b_hex(const char* hex_data) { | 136 std::string a2b_hex(const char* hex_data) { |
| 135 std::vector<uint8> output; | 137 std::vector<uint8> output; |
| 136 std::string result; | 138 std::string result; |
| 137 if (base::HexStringToBytes(hex_data, &output)) | 139 if (base::HexStringToBytes(hex_data, &output)) |
| 138 result.assign(reinterpret_cast<const char*>(&output[0]), output.size()); | 140 result.assign(reinterpret_cast<const char*>(&output[0]), output.size()); |
| 139 return result; | 141 return result; |
| 140 } | 142 } |
| 141 | 143 |
| 144 HashValue GetTestHashValue(uint8 label) { | |
| 145 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.
| |
| 146 memset(hash_value.data(), label, hash_value.size()); | |
| 147 return hash_value; | |
| 148 } | |
| 149 | |
| 150 std::string GetTestPin(uint8 label) { | |
| 151 HashValue hash_value = GetTestHashValue(label); | |
| 152 std::string base64; | |
| 153 base::Base64Encode(base::StringPiece( | |
| 154 reinterpret_cast<char*>(hash_value.data()), hash_value.size()), &base64); | |
| 155 | |
| 156 return std::string("pin-sha1=\"") + base64 + "\""; | |
| 157 } | |
| 158 | |
| 159 void AddPin(TransportSecurityState* state, | |
| 160 const std::string& host, | |
| 161 uint8 primary_label, | |
| 162 uint8 backup_label) { | |
| 163 std::string primary_pin = GetTestPin(primary_label); | |
| 164 std::string backup_pin = GetTestPin(backup_label); | |
| 165 std::string header = "max-age = 10000; " + primary_pin + "; " + backup_pin; | |
| 166 | |
| 167 // Construct a fake SSLInfo that will pass AddHPKPHeader's checks. | |
| 168 SSLInfo ssl_info; | |
| 169 ssl_info.is_issued_by_known_root = true; | |
| 170 ssl_info.public_key_hashes.push_back(GetTestHashValue(primary_label)); | |
| 171 EXPECT_TRUE(state->AddHPKPHeader(host, header, ssl_info)); | |
| 172 } | |
| 173 | |
| 142 } // namespace test | 174 } // namespace test |
| 143 | 175 |
| 144 } // namespace net | 176 } // namespace net |
| OLD | NEW |