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 <stdint.h> | 7 #include <stdint.h> |
8 #include <string.h> | 8 #include <string.h> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/base64.h" | 11 #include "base/base64.h" |
12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
13 #include "base/strings/string_piece.h" | 13 #include "base/strings/string_piece.h" |
14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
16 #include "net/cert/ct_serialization.h" | 16 #include "net/cert/ct_serialization.h" |
17 #include "net/cert/signed_certificate_timestamp.h" | 17 #include "net/cert/ct_verify_result.h" |
18 #include "net/cert/signed_tree_head.h" | 18 #include "net/cert/signed_tree_head.h" |
19 #include "net/cert/x509_certificate.h" | 19 #include "net/cert/x509_certificate.h" |
20 | 20 |
21 namespace net { | 21 namespace net { |
22 | 22 |
23 namespace ct { | 23 namespace ct { |
24 | 24 |
25 namespace { | 25 namespace { |
26 | 26 |
27 std::string HexToBytes(const char* hex_data) { | 27 std::string HexToBytes(const char* hex_data) { |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 consistency_proof_json += | 353 consistency_proof_json += |
354 base::StringPrintf("\"%s\"", proof_node_b64.c_str()); | 354 base::StringPrintf("\"%s\"", proof_node_b64.c_str()); |
355 if (it + 1 != raw_nodes.end()) | 355 if (it + 1 != raw_nodes.end()) |
356 consistency_proof_json += std::string(","); | 356 consistency_proof_json += std::string(","); |
357 } | 357 } |
358 consistency_proof_json += std::string("]}"); | 358 consistency_proof_json += std::string("]}"); |
359 | 359 |
360 return consistency_proof_json; | 360 return consistency_proof_json; |
361 } | 361 } |
362 | 362 |
| 363 std::string GetSCTListForTesting() { |
| 364 const std::string sct = ct::GetTestSignedCertificateTimestamp(); |
| 365 std::string sct_list; |
| 366 ct::EncodeSCTListForTesting(sct, &sct_list); |
| 367 return sct_list; |
| 368 } |
| 369 |
| 370 std::string GetSCTListWithInvalidSCT() { |
| 371 std::string sct(ct::GetTestSignedCertificateTimestamp()); |
| 372 |
| 373 // Change a byte inside the Log ID part of the SCT so it does not match the |
| 374 // log used in the tests. |
| 375 sct[15] = 't'; |
| 376 |
| 377 std::string sct_list; |
| 378 ct::EncodeSCTListForTesting(sct, &sct_list); |
| 379 return sct_list; |
| 380 } |
| 381 |
| 382 bool CheckForSingleVerifiedSCTInResult(const ct::CTVerifyResult& result, |
| 383 const std::string& log_description) { |
| 384 return (result.verified_scts.size() == 1U) && result.invalid_scts.empty() && |
| 385 result.unknown_logs_scts.empty() && |
| 386 result.verified_scts[0]->log_description == log_description; |
| 387 } |
| 388 |
| 389 bool CheckForSCTOrigin(const ct::CTVerifyResult& result, |
| 390 ct::SignedCertificateTimestamp::Origin origin) { |
| 391 return (result.verified_scts.size() > 0) && |
| 392 (result.verified_scts[0]->origin == origin); |
| 393 } |
| 394 |
363 } // namespace ct | 395 } // namespace ct |
364 | 396 |
365 } // namespace net | 397 } // namespace net |
OLD | NEW |