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