| 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 |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 | 198 |
| 199 std::string GetTestPublicKeyId() { | 199 std::string GetTestPublicKeyId() { |
| 200 return HexToBytes(kTestKeyId); | 200 return HexToBytes(kTestKeyId); |
| 201 } | 201 } |
| 202 | 202 |
| 203 void GetX509CertSCT(scoped_refptr<SignedCertificateTimestamp>* sct_ref) { | 203 void GetX509CertSCT(scoped_refptr<SignedCertificateTimestamp>* sct_ref) { |
| 204 CHECK(sct_ref != NULL); | 204 CHECK(sct_ref != NULL); |
| 205 *sct_ref = new SignedCertificateTimestamp(); | 205 *sct_ref = new SignedCertificateTimestamp(); |
| 206 SignedCertificateTimestamp *const sct(sct_ref->get()); | 206 SignedCertificateTimestamp *const sct(sct_ref->get()); |
| 207 sct->version = ct::SignedCertificateTimestamp::SCT_VERSION_1; | 207 sct->version = ct::SignedCertificateTimestamp::SCT_VERSION_1; |
| 208 sct->log_id = HexToBytes(kTestKeyId); | 208 sct->log_id = GetTestPublicKeyId(); |
| 209 // Time the log issued a SCT for this certificate, which is | 209 // Time the log issued a SCT for this certificate, which is |
| 210 // Fri Apr 5 10:04:16.089 2013 | 210 // Fri Apr 5 10:04:16.089 2013 |
| 211 sct->timestamp = base::Time::UnixEpoch() + | 211 sct->timestamp = base::Time::UnixEpoch() + |
| 212 base::TimeDelta::FromMilliseconds(INT64_C(1365181456089)); | 212 base::TimeDelta::FromMilliseconds(INT64_C(1365181456089)); |
| 213 sct->extensions.clear(); | 213 sct->extensions.clear(); |
| 214 | 214 |
| 215 sct->signature.hash_algorithm = ct::DigitallySigned::HASH_ALGO_SHA256; | 215 sct->signature.hash_algorithm = ct::DigitallySigned::HASH_ALGO_SHA256; |
| 216 sct->signature.signature_algorithm = ct::DigitallySigned::SIG_ALGO_ECDSA; | 216 sct->signature.signature_algorithm = ct::DigitallySigned::SIG_ALGO_ECDSA; |
| 217 sct->signature.signature_data = HexToBytes(kTestSCTSignatureData); | 217 sct->signature.signature_data = HexToBytes(kTestSCTSignatureData); |
| 218 } | 218 } |
| 219 | 219 |
| 220 void GetPrecertSCT(scoped_refptr<SignedCertificateTimestamp>* sct_ref) { | 220 void GetPrecertSCT(scoped_refptr<SignedCertificateTimestamp>* sct_ref) { |
| 221 CHECK(sct_ref != NULL); | 221 CHECK(sct_ref != NULL); |
| 222 *sct_ref = new SignedCertificateTimestamp(); | 222 *sct_ref = new SignedCertificateTimestamp(); |
| 223 SignedCertificateTimestamp *const sct(sct_ref->get()); | 223 SignedCertificateTimestamp *const sct(sct_ref->get()); |
| 224 sct->version = ct::SignedCertificateTimestamp::SCT_VERSION_1; | 224 sct->version = ct::SignedCertificateTimestamp::SCT_VERSION_1; |
| 225 sct->log_id = HexToBytes(kTestKeyId); | 225 sct->log_id = GetTestPublicKeyId(); |
| 226 // Time the log issued a SCT for this Precertificate, which is | 226 // Time the log issued a SCT for this Precertificate, which is |
| 227 // Fri Apr 5 10:04:16.275 2013 | 227 // Fri Apr 5 10:04:16.275 2013 |
| 228 sct->timestamp = base::Time::UnixEpoch() + | 228 sct->timestamp = base::Time::UnixEpoch() + |
| 229 base::TimeDelta::FromMilliseconds(INT64_C(1365181456275)); | 229 base::TimeDelta::FromMilliseconds(INT64_C(1365181456275)); |
| 230 sct->extensions.clear(); | 230 sct->extensions.clear(); |
| 231 | 231 |
| 232 sct->signature.hash_algorithm = ct::DigitallySigned::HASH_ALGO_SHA256; | 232 sct->signature.hash_algorithm = ct::DigitallySigned::HASH_ALGO_SHA256; |
| 233 sct->signature.signature_algorithm = ct::DigitallySigned::SIG_ALGO_ECDSA; | 233 sct->signature.signature_algorithm = ct::DigitallySigned::SIG_ALGO_ECDSA; |
| 234 sct->signature.signature_data = HexToBytes(kTestSCTPrecertSignatureData); | 234 sct->signature.signature_data = HexToBytes(kTestSCTPrecertSignatureData); |
| 235 } | 235 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 250 return HexToBytes(kFakeOCSPResponseCert); | 250 return HexToBytes(kFakeOCSPResponseCert); |
| 251 } | 251 } |
| 252 | 252 |
| 253 std::string GetDerEncodedFakeOCSPResponseIssuerCert() { | 253 std::string GetDerEncodedFakeOCSPResponseIssuerCert() { |
| 254 return HexToBytes(kFakeOCSPResponseIssuerCert); | 254 return HexToBytes(kFakeOCSPResponseIssuerCert); |
| 255 } | 255 } |
| 256 | 256 |
| 257 // A sample, valid STH | 257 // A sample, valid STH |
| 258 bool GetSampleSignedTreeHead(SignedTreeHead* sth) { | 258 bool GetSampleSignedTreeHead(SignedTreeHead* sth) { |
| 259 sth->version = SignedTreeHead::V1; | 259 sth->version = SignedTreeHead::V1; |
| 260 sth->log_id = GetTestPublicKeyId(); |
| 260 sth->timestamp = base::Time::UnixEpoch() + | 261 sth->timestamp = base::Time::UnixEpoch() + |
| 261 base::TimeDelta::FromMilliseconds(kSampleSTHTimestamp); | 262 base::TimeDelta::FromMilliseconds(kSampleSTHTimestamp); |
| 262 sth->tree_size = kSampleSTHTreeSize; | 263 sth->tree_size = kSampleSTHTreeSize; |
| 263 std::string sha256_root_hash = GetSampleSTHSHA256RootHash(); | 264 std::string sha256_root_hash = GetSampleSTHSHA256RootHash(); |
| 264 memcpy(sth->sha256_root_hash, sha256_root_hash.c_str(), kSthRootHashLength); | 265 memcpy(sth->sha256_root_hash, sha256_root_hash.c_str(), kSthRootHashLength); |
| 265 | 266 |
| 266 return GetSampleSTHTreeHeadDecodedSignature(&(sth->signature)); | 267 return GetSampleSTHTreeHeadDecodedSignature(&(sth->signature)); |
| 267 } | 268 } |
| 268 | 269 |
| 269 bool GetSampleEmptySignedTreeHead(SignedTreeHead* sth) { | 270 bool GetSampleEmptySignedTreeHead(SignedTreeHead* sth) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 std::string GetSampleSTHTreeHeadSignature() { | 306 std::string GetSampleSTHTreeHeadSignature() { |
| 306 return HexToBytes(kSampleSTHTreeHeadSignature); | 307 return HexToBytes(kSampleSTHTreeHeadSignature); |
| 307 } | 308 } |
| 308 | 309 |
| 309 bool GetSampleSTHTreeHeadDecodedSignature(DigitallySigned* signature) { | 310 bool GetSampleSTHTreeHeadDecodedSignature(DigitallySigned* signature) { |
| 310 std::string tree_head_signature = HexToBytes(kSampleSTHTreeHeadSignature); | 311 std::string tree_head_signature = HexToBytes(kSampleSTHTreeHeadSignature); |
| 311 base::StringPiece sp(tree_head_signature); | 312 base::StringPiece sp(tree_head_signature); |
| 312 return DecodeDigitallySigned(&sp, signature) && sp.empty(); | 313 return DecodeDigitallySigned(&sp, signature) && sp.empty(); |
| 313 } | 314 } |
| 314 | 315 |
| 316 std::string GetSampleSTH() { |
| 317 const std::string log_id = ct::GetTestPublicKeyId(); |
| 318 const std::string timestamp("\x0\x0\x1\x45\x3c\x5f\xb8\x35", 8); |
| 319 const std::string tree_size("\x0\x0\x0\x0\x0\x0\x0\x15", 8); |
| 320 |
| 321 std::string expected_output; |
| 322 expected_output += log_id; |
| 323 expected_output += timestamp; |
| 324 expected_output += tree_size; |
| 325 expected_output += ct::GetSampleSTHSHA256RootHash(); |
| 326 expected_output += ct::GetSampleSTHTreeHeadSignature(); |
| 327 |
| 328 return expected_output; |
| 329 } |
| 330 |
| 315 std::string GetSampleSTHAsJson() { | 331 std::string GetSampleSTHAsJson() { |
| 316 return CreateSignedTreeHeadJsonString(kSampleSTHTreeSize, kSampleSTHTimestamp, | 332 return CreateSignedTreeHeadJsonString(kSampleSTHTreeSize, kSampleSTHTimestamp, |
| 317 GetSampleSTHSHA256RootHash(), | 333 GetSampleSTHSHA256RootHash(), |
| 318 GetSampleSTHTreeHeadSignature()); | 334 GetSampleSTHTreeHeadSignature()); |
| 319 } | 335 } |
| 320 | 336 |
| 321 std::string CreateSignedTreeHeadJsonString(size_t tree_size, | 337 std::string CreateSignedTreeHeadJsonString(size_t tree_size, |
| 322 int64_t timestamp, | 338 int64_t timestamp, |
| 323 std::string sha256_root_hash, | 339 std::string sha256_root_hash, |
| 324 std::string tree_head_signature) { | 340 std::string tree_head_signature) { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 | 404 |
| 389 bool CheckForSCTOrigin(const ct::CTVerifyResult& result, | 405 bool CheckForSCTOrigin(const ct::CTVerifyResult& result, |
| 390 ct::SignedCertificateTimestamp::Origin origin) { | 406 ct::SignedCertificateTimestamp::Origin origin) { |
| 391 return (result.verified_scts.size() > 0) && | 407 return (result.verified_scts.size() > 0) && |
| 392 (result.verified_scts[0]->origin == origin); | 408 (result.verified_scts[0]->origin == origin); |
| 393 } | 409 } |
| 394 | 410 |
| 395 } // namespace ct | 411 } // namespace ct |
| 396 | 412 |
| 397 } // namespace net | 413 } // namespace net |
| OLD | NEW |