| 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" | |
| 11 #include "base/logging.h" | 10 #include "base/logging.h" |
| 12 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/sys_byteorder.h" | 13 #include "base/sys_byteorder.h" |
| 15 #include "net/http/transport_security_state.h" | |
| 16 #include "net/ssl/ssl_info.h" | |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 15 |
| 19 namespace net { | 16 namespace net { |
| 20 | 17 |
| 21 namespace test { | 18 namespace test { |
| 22 | 19 |
| 23 std::string HexDumpWithMarks(const unsigned char* data, int length, | 20 std::string HexDumpWithMarks(const unsigned char* data, int length, |
| 24 const bool* marks, int mark_length) { | 21 const bool* marks, int mark_length) { |
| 25 static const char kHexChars[] = "0123456789abcdef"; | 22 static const char kHexChars[] = "0123456789abcdef"; |
| 26 static const int kColumns = 4; | 23 static const int kColumns = 4; |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 } | 132 } |
| 136 | 133 |
| 137 std::string a2b_hex(const char* hex_data) { | 134 std::string a2b_hex(const char* hex_data) { |
| 138 std::vector<uint8> output; | 135 std::vector<uint8> output; |
| 139 std::string result; | 136 std::string result; |
| 140 if (base::HexStringToBytes(hex_data, &output)) | 137 if (base::HexStringToBytes(hex_data, &output)) |
| 141 result.assign(reinterpret_cast<const char*>(&output[0]), output.size()); | 138 result.assign(reinterpret_cast<const char*>(&output[0]), output.size()); |
| 142 return result; | 139 return result; |
| 143 } | 140 } |
| 144 | 141 |
| 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 | |
| 175 } // namespace test | 142 } // namespace test |
| 176 | 143 |
| 177 } // namespace net | 144 } // namespace net |
| OLD | NEW |