OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/test/ct_test_util.h" | 5 #include "net/test/ct_test_util.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
11 #include "base/strings/string_piece.h" | 11 #include "base/strings/string_piece.h" |
12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
13 #include "net/cert/ct_serialization.h" | 13 #include "net/cert/ct_serialization.h" |
14 #include "net/cert/signed_certificate_timestamp.h" | 14 #include "net/cert/signed_certificate_timestamp.h" |
| 15 #include "net/cert/signed_tree_head.h" |
15 #include "net/cert/x509_certificate.h" | 16 #include "net/cert/x509_certificate.h" |
16 | 17 |
17 namespace net { | 18 namespace net { |
18 | 19 |
19 namespace ct { | 20 namespace ct { |
20 | 21 |
21 namespace { | 22 namespace { |
22 | 23 |
23 std::string HexToBytes(const char* hex_data) { | 24 std::string HexToBytes(const char* hex_data) { |
24 std::vector<uint8> output; | 25 std::vector<uint8> output; |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 "71c64aa5ecf07d020103a333303130120603551d130101ff040830060101ff020100301b06" | 148 "71c64aa5ecf07d020103a333303130120603551d130101ff040830060101ff020100301b06" |
148 "03551d200101000411300f300d060b2b06010401d6790201ce0f300d06092a864886f70d01" | 149 "03551d200101000411300f300d060b2b06010401d6790201ce0f300d06092a864886f70d01" |
149 "01050500038181003f4936f8d00e83fbdde331f2c64335dcf7dec8b1a2597683edeed61af0" | 150 "01050500038181003f4936f8d00e83fbdde331f2c64335dcf7dec8b1a2597683edeed61af0" |
150 "fa862412fad848938fe7ab77f1f9a43671ff6fdb729386e26f49e7aca0c0ea216e5970d933" | 151 "fa862412fad848938fe7ab77f1f9a43671ff6fdb729386e26f49e7aca0c0ea216e5970d933" |
151 "3ea1e11df2ccb357a5fed5220f9c6239e8946b9b7517707631d51ab996833d58a022cff5a6" | 152 "3ea1e11df2ccb357a5fed5220f9c6239e8946b9b7517707631d51ab996833d58a022cff5a6" |
152 "2169ac9258ec110efee78da9ab4a641e3b3c9ee5e8bd291460"; | 153 "2169ac9258ec110efee78da9ab4a641e3b3c9ee5e8bd291460"; |
153 | 154 |
154 | 155 |
155 const char kFakeOCSPExtensionValue[] = "74657374"; // "test" | 156 const char kFakeOCSPExtensionValue[] = "74657374"; // "test" |
156 | 157 |
| 158 // For the sample STH |
| 159 const char kSampleSTHSHA256RootHash[] = |
| 160 "726467216167397babca293dca398e4ce6b621b18b9bc42f30c900d1f92ac1e4"; |
| 161 const char kSampleSTHTreeHeadSignature[] = |
| 162 "0403004730450220365a91a2a88f2b9332f41d8959fa7086da7e6d634b7b089bc9da066426" |
| 163 "6c7a20022100e38464f3c0fd066257b982074f7ac87655e0c8f714768a050b4be9a7b441cb" |
| 164 "d3"; |
| 165 |
157 } // namespace | 166 } // namespace |
158 | 167 |
159 void GetX509CertLogEntry(LogEntry* entry) { | 168 void GetX509CertLogEntry(LogEntry* entry) { |
160 entry->type = ct::LogEntry::LOG_ENTRY_TYPE_X509; | 169 entry->type = ct::LogEntry::LOG_ENTRY_TYPE_X509; |
161 entry->leaf_certificate = HexToBytes(kDefaultDerCert); | 170 entry->leaf_certificate = HexToBytes(kDefaultDerCert); |
162 } | 171 } |
163 | 172 |
164 std::string GetDerEncodedX509Cert() { return HexToBytes(kDefaultDerCert); } | 173 std::string GetDerEncodedX509Cert() { return HexToBytes(kDefaultDerCert); } |
165 | 174 |
166 void GetPrecertLogEntry(LogEntry* entry) { | 175 void GetPrecertLogEntry(LogEntry* entry) { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 } | 242 } |
234 | 243 |
235 std::string GetDerEncodedFakeOCSPResponseCert() { | 244 std::string GetDerEncodedFakeOCSPResponseCert() { |
236 return HexToBytes(kFakeOCSPResponseCert); | 245 return HexToBytes(kFakeOCSPResponseCert); |
237 } | 246 } |
238 | 247 |
239 std::string GetDerEncodedFakeOCSPResponseIssuerCert() { | 248 std::string GetDerEncodedFakeOCSPResponseIssuerCert() { |
240 return HexToBytes(kFakeOCSPResponseIssuerCert); | 249 return HexToBytes(kFakeOCSPResponseIssuerCert); |
241 } | 250 } |
242 | 251 |
| 252 std::string GetSampleSTHSHA256RootHash() { |
| 253 return HexToBytes(kSampleSTHSHA256RootHash); |
| 254 } |
| 255 |
| 256 // A sample, valid STH |
| 257 void GetSignedTreeHead(SignedTreeHead* sth) { |
| 258 sth->version = SignedTreeHead::V1; |
| 259 sth->timestamp = base::Time::UnixEpoch() + |
| 260 base::TimeDelta::FromMilliseconds(1396877277237); |
| 261 sth->tree_size = 21u; |
| 262 std::string sha256_root_hash = GetSampleSTHSHA256RootHash(); |
| 263 memcpy(sth->sha256_root_hash, sha256_root_hash.c_str(), kSthRootHashLength); |
| 264 |
| 265 std::string tree_head_signature = HexToBytes(kSampleSTHTreeHeadSignature); |
| 266 base::StringPiece sp(tree_head_signature); |
| 267 DecodeDigitallySigned(&sp, &(sth->signature)); |
| 268 } |
| 269 |
243 } // namespace ct | 270 } // namespace ct |
244 | 271 |
245 } // namespace net | 272 } // namespace net |
OLD | NEW |