| 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/ct_verify_result.h" | 17 #include "net/cert/ct_verify_result.h" |
| 18 #include "net/cert/merkle_tree_leaf.h" |
| 18 #include "net/cert/signed_tree_head.h" | 19 #include "net/cert/signed_tree_head.h" |
| 19 #include "net/cert/x509_certificate.h" | 20 #include "net/cert/x509_certificate.h" |
| 20 | 21 |
| 21 namespace net { | 22 namespace net { |
| 22 | 23 |
| 23 namespace ct { | 24 namespace ct { |
| 24 | 25 |
| 25 namespace { | 26 namespace { |
| 26 | 27 |
| 27 std::string HexToBytes(const char* hex_data) { | 28 std::string HexToBytes(const char* hex_data) { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 "beef98e7c26877ae385f75325a0c1d329bedf18faaf4d796bf047eb7e1ce15c95ba2f80ee4" | 72 "beef98e7c26877ae385f75325a0c1d329bedf18faaf4d796bf047eb7e1ce15c95ba2f80ee4" |
| 72 "58bd7db86f8a4b252191a79bd700c38e9c0389b45cd4dc9a120ab21e0cb41cd0e72805a410" | 73 "58bd7db86f8a4b252191a79bd700c38e9c0389b45cd4dc9a120ab21e0cb41cd0e72805a410" |
| 73 "cd9c5bdb5d4927726daf1710f60187377ea25b1a1e39eed0b88119dc154dc68f7da8e30caf" | 74 "cd9c5bdb5d4927726daf1710f60187377ea25b1a1e39eed0b88119dc154dc68f7da8e30caf" |
| 74 "158a33e6c9509f4a05b01409ff5dd87eb50203010001a381ac3081a9301d0603551d0e0416" | 75 "158a33e6c9509f4a05b01409ff5dd87eb50203010001a381ac3081a9301d0603551d0e0416" |
| 75 "04142031541af25c05ffd8658b6843794f5e9036f7b4307d0603551d230476307480145f9d" | 76 "04142031541af25c05ffd8658b6843794f5e9036f7b4307d0603551d230476307480145f9d" |
| 76 "880dc873e654d4f80dd8e6b0c124b447c355a159a4573055310b3009060355040613024742" | 77 "880dc873e654d4f80dd8e6b0c124b447c355a159a4573055310b3009060355040613024742" |
| 77 "31243022060355040a131b4365727469666963617465205472616e73706172656e63792043" | 78 "31243022060355040a131b4365727469666963617465205472616e73706172656e63792043" |
| 78 "41310e300c0603550408130557616c65733110300e060355040713074572772057656e8201" | 79 "41310e300c0603550408130557616c65733110300e060355040713074572772057656e8201" |
| 79 "0030090603551d1304023000"; | 80 "0030090603551d1304023000"; |
| 80 | 81 |
| 82 const char kDefaultExtensions[] = "666f6f626172"; // "foobar" |
| 83 |
| 81 const char kTestDigitallySigned[] = | 84 const char kTestDigitallySigned[] = |
| 82 "0403004730450220606e10ae5c2d5a1b0aed49dc4937f48de71a4e9784e9c208dfbfe9ef53" | 85 "0403004730450220606e10ae5c2d5a1b0aed49dc4937f48de71a4e9784e9c208dfbfe9ef53" |
| 83 "6cf7f2022100beb29c72d7d06d61d06bdb38a069469aa86fe12e18bb7cc45689a2c0187ef5" | 86 "6cf7f2022100beb29c72d7d06d61d06bdb38a069469aa86fe12e18bb7cc45689a2c0187ef5" |
| 84 "a5"; | 87 "a5"; |
| 85 | 88 |
| 86 const char kTestSignedCertificateTimestamp[] = | 89 const char kTestSignedCertificateTimestamp[] = |
| 87 "00df1c2ec11500945247a96168325ddc5c7959e8f7c6d388fc002e0bbd3f74d7640000013d" | 90 "00df1c2ec11500945247a96168325ddc5c7959e8f7c6d388fc002e0bbd3f74d7640000013d" |
| 88 "db27ded900000403004730450220606e10ae5c2d5a1b0aed49dc4937f48de71a4e9784e9c2" | 91 "db27ded900000403004730450220606e10ae5c2d5a1b0aed49dc4937f48de71a4e9784e9c2" |
| 89 "08dfbfe9ef536cf7f2022100beb29c72d7d06d61d06bdb38a069469aa86fe12e18bb7cc456" | 92 "08dfbfe9ef536cf7f2022100beb29c72d7d06d61d06bdb38a069469aa86fe12e18bb7cc456" |
| 90 "89a2c0187ef5a5"; | 93 "89a2c0187ef5a5"; |
| 91 | 94 |
| 92 const char kEcP256PublicKey[] = | 95 const char kEcP256PublicKey[] = |
| 93 "3059301306072a8648ce3d020106082a8648ce3d0301070342000499783cb14533c0161a5a" | 96 "3059301306072a8648ce3d020106082a8648ce3d0301070342000499783cb14533c0161a5a" |
| 94 "b45bf95d08a29cd0ea8dd4c84274e2be59ad15c676960cf0afa1074a57ac644b23479e5b3f" | 97 "b45bf95d08a29cd0ea8dd4c84274e2be59ad15c676960cf0afa1074a57ac644b23479e5b3f" |
| 95 "b7b245eb4b420ef370210371a944beaceb"; | 98 "b7b245eb4b420ef370210371a944beaceb"; |
| 96 | 99 |
| 97 const char kTestKeyId[] = | 100 const char kTestKeyId[] = |
| 98 "df1c2ec11500945247a96168325ddc5c7959e8f7c6d388fc002e0bbd3f74d764"; | 101 "df1c2ec11500945247a96168325ddc5c7959e8f7c6d388fc002e0bbd3f74d764"; |
| 99 | 102 |
| 103 const int64_t kTestTimestamp = INT64_C(1396877277237); |
| 104 |
| 100 const char kTestSCTSignatureData[] = | 105 const char kTestSCTSignatureData[] = |
| 101 "30450220606e10ae5c2d5a1b0aed49dc4937f48de71a4e9784e9c208dfbfe9ef536cf7f202" | 106 "30450220606e10ae5c2d5a1b0aed49dc4937f48de71a4e9784e9c208dfbfe9ef536cf7f202" |
| 102 "2100beb29c72d7d06d61d06bdb38a069469aa86fe12e18bb7cc45689a2c0187ef5a5"; | 107 "2100beb29c72d7d06d61d06bdb38a069469aa86fe12e18bb7cc45689a2c0187ef5a5"; |
| 103 | 108 |
| 104 const char kTestSCTPrecertSignatureData[] = | 109 const char kTestSCTPrecertSignatureData[] = |
| 105 "30450220482f6751af35dba65436be1fd6640f3dbf9a41429495924530288fa3e5e23e0602" | 110 "30450220482f6751af35dba65436be1fd6640f3dbf9a41429495924530288fa3e5e23e0602" |
| 106 "2100e4edc0db3ac572b1e2f5e8ab6a680653987dcf41027dfeffa105519d89edbf08"; | 111 "2100e4edc0db3ac572b1e2f5e8ab6a680653987dcf41027dfeffa105519d89edbf08"; |
| 107 | 112 |
| 108 // A well-formed OCSP response with fake SCT contents. Does not come from | 113 // A well-formed OCSP response with fake SCT contents. Does not come from |
| 109 // http://code.google.com/p/certificate-transparency, does not pertain to any | 114 // http://code.google.com/p/certificate-transparency, does not pertain to any |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 "a87f133d2f378eeeeed52a77e44d0fc9ff6f07ff32cbf3da999de4ed65832afcb0807f9878" | 153 "a87f133d2f378eeeeed52a77e44d0fc9ff6f07ff32cbf3da999de4ed65832afcb0807f9878" |
| 149 "7506539d258a0ce3c2c77967653099a9034a9b115a876c39a8c4e4ed4acd0c64095946fb39" | 154 "7506539d258a0ce3c2c77967653099a9034a9b115a876c39a8c4e4ed4acd0c64095946fb39" |
| 150 "eeeb47a0704dbb018acf48c3a1c4b895fc409fb4a340a986b1afc45519ab9eca47c30185c7" | 155 "eeeb47a0704dbb018acf48c3a1c4b895fc409fb4a340a986b1afc45519ab9eca47c30185c7" |
| 151 "71c64aa5ecf07d020103a333303130120603551d130101ff040830060101ff020100301b06" | 156 "71c64aa5ecf07d020103a333303130120603551d130101ff040830060101ff020100301b06" |
| 152 "03551d200101000411300f300d060b2b06010401d6790201ce0f300d06092a864886f70d01" | 157 "03551d200101000411300f300d060b2b06010401d6790201ce0f300d06092a864886f70d01" |
| 153 "01050500038181003f4936f8d00e83fbdde331f2c64335dcf7dec8b1a2597683edeed61af0" | 158 "01050500038181003f4936f8d00e83fbdde331f2c64335dcf7dec8b1a2597683edeed61af0" |
| 154 "fa862412fad848938fe7ab77f1f9a43671ff6fdb729386e26f49e7aca0c0ea216e5970d933" | 159 "fa862412fad848938fe7ab77f1f9a43671ff6fdb729386e26f49e7aca0c0ea216e5970d933" |
| 155 "3ea1e11df2ccb357a5fed5220f9c6239e8946b9b7517707631d51ab996833d58a022cff5a6" | 160 "3ea1e11df2ccb357a5fed5220f9c6239e8946b9b7517707631d51ab996833d58a022cff5a6" |
| 156 "2169ac9258ec110efee78da9ab4a641e3b3c9ee5e8bd291460"; | 161 "2169ac9258ec110efee78da9ab4a641e3b3c9ee5e8bd291460"; |
| 157 | 162 |
| 158 | |
| 159 const char kFakeOCSPExtensionValue[] = "74657374"; // "test" | 163 const char kFakeOCSPExtensionValue[] = "74657374"; // "test" |
| 160 | 164 |
| 161 // For the sample STH | 165 // For the sample STH |
| 162 const char kSampleSTHSHA256RootHash[] = | 166 const char kSampleSTHSHA256RootHash[] = |
| 163 "726467216167397babca293dca398e4ce6b621b18b9bc42f30c900d1f92ac1e4"; | 167 "726467216167397babca293dca398e4ce6b621b18b9bc42f30c900d1f92ac1e4"; |
| 164 const char kSampleSTHTreeHeadSignature[] = | 168 const char kSampleSTHTreeHeadSignature[] = |
| 165 "0403004730450220365a91a2a88f2b9332f41d8959fa7086da7e6d634b7b089bc9da066426" | 169 "0403004730450220365a91a2a88f2b9332f41d8959fa7086da7e6d634b7b089bc9da066426" |
| 166 "6c7a20022100e38464f3c0fd066257b982074f7ac87655e0c8f714768a050b4be9a7b441cb" | 170 "6c7a20022100e38464f3c0fd066257b982074f7ac87655e0c8f714768a050b4be9a7b441cb" |
| 167 "d3"; | 171 "d3"; |
| 168 size_t kSampleSTHTreeSize = 21u; | 172 size_t kSampleSTHTreeSize = 21u; |
| 169 int64_t kSampleSTHTimestamp = INT64_C(1396877277237); | |
| 170 | 173 |
| 171 } // namespace | 174 } // namespace |
| 172 | 175 |
| 173 void GetX509CertLogEntry(LogEntry* entry) { | 176 void GetX509CertLogEntry(LogEntry* entry) { |
| 174 entry->type = ct::LogEntry::LOG_ENTRY_TYPE_X509; | 177 entry->type = ct::LogEntry::LOG_ENTRY_TYPE_X509; |
| 175 entry->leaf_certificate = HexToBytes(kDefaultDerCert); | 178 entry->leaf_certificate = HexToBytes(kDefaultDerCert); |
| 176 } | 179 } |
| 177 | 180 |
| 181 void GetX509CertTreeLeaf(MerkleTreeLeaf* tree_leaf) { |
| 182 tree_leaf->log_id = HexToBytes(kTestKeyId); |
| 183 tree_leaf->timestamp = base::Time::FromJsTime(kTestTimestamp); |
| 184 GetX509CertLogEntry(&tree_leaf->log_entry); |
| 185 tree_leaf->extensions = HexToBytes(kDefaultExtensions); |
| 186 } |
| 187 |
| 178 std::string GetDerEncodedX509Cert() { return HexToBytes(kDefaultDerCert); } | 188 std::string GetDerEncodedX509Cert() { return HexToBytes(kDefaultDerCert); } |
| 179 | 189 |
| 180 void GetPrecertLogEntry(LogEntry* entry) { | 190 void GetPrecertLogEntry(LogEntry* entry) { |
| 181 entry->type = ct::LogEntry::LOG_ENTRY_TYPE_PRECERT; | 191 entry->type = ct::LogEntry::LOG_ENTRY_TYPE_PRECERT; |
| 182 std::string issuer_hash(HexToBytes(kDefaultIssuerKeyHash)); | 192 std::string issuer_hash(HexToBytes(kDefaultIssuerKeyHash)); |
| 183 memcpy(entry->issuer_key_hash.data, issuer_hash.data(), issuer_hash.size()); | 193 memcpy(entry->issuer_key_hash.data, issuer_hash.data(), issuer_hash.size()); |
| 184 entry->tbs_certificate = HexToBytes(kDefaultDerTbsCert); | 194 entry->tbs_certificate = HexToBytes(kDefaultDerTbsCert); |
| 185 } | 195 } |
| 186 | 196 |
| 197 void GetPrecertTreeLeaf(MerkleTreeLeaf* tree_leaf) { |
| 198 tree_leaf->log_id = HexToBytes(kTestKeyId); |
| 199 tree_leaf->timestamp = base::Time::FromJsTime(kTestTimestamp); |
| 200 GetPrecertLogEntry(&tree_leaf->log_entry); |
| 201 tree_leaf->extensions = HexToBytes(kDefaultExtensions); |
| 202 } |
| 203 |
| 187 std::string GetTestDigitallySigned() { | 204 std::string GetTestDigitallySigned() { |
| 188 return HexToBytes(kTestDigitallySigned); | 205 return HexToBytes(kTestDigitallySigned); |
| 189 } | 206 } |
| 190 | 207 |
| 191 std::string GetTestSignedCertificateTimestamp() { | 208 std::string GetTestSignedCertificateTimestamp() { |
| 192 return HexToBytes(kTestSignedCertificateTimestamp); | 209 return HexToBytes(kTestSignedCertificateTimestamp); |
| 193 } | 210 } |
| 194 | 211 |
| 195 std::string GetTestPublicKey() { | 212 std::string GetTestPublicKey() { |
| 196 return HexToBytes(kEcP256PublicKey); | 213 return HexToBytes(kEcP256PublicKey); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 } | 268 } |
| 252 | 269 |
| 253 std::string GetDerEncodedFakeOCSPResponseIssuerCert() { | 270 std::string GetDerEncodedFakeOCSPResponseIssuerCert() { |
| 254 return HexToBytes(kFakeOCSPResponseIssuerCert); | 271 return HexToBytes(kFakeOCSPResponseIssuerCert); |
| 255 } | 272 } |
| 256 | 273 |
| 257 // A sample, valid STH | 274 // A sample, valid STH |
| 258 bool GetSampleSignedTreeHead(SignedTreeHead* sth) { | 275 bool GetSampleSignedTreeHead(SignedTreeHead* sth) { |
| 259 sth->version = SignedTreeHead::V1; | 276 sth->version = SignedTreeHead::V1; |
| 260 sth->timestamp = base::Time::UnixEpoch() + | 277 sth->timestamp = base::Time::UnixEpoch() + |
| 261 base::TimeDelta::FromMilliseconds(kSampleSTHTimestamp); | 278 base::TimeDelta::FromMilliseconds(kTestTimestamp); |
| 262 sth->tree_size = kSampleSTHTreeSize; | 279 sth->tree_size = kSampleSTHTreeSize; |
| 263 std::string sha256_root_hash = GetSampleSTHSHA256RootHash(); | 280 std::string sha256_root_hash = GetSampleSTHSHA256RootHash(); |
| 264 memcpy(sth->sha256_root_hash, sha256_root_hash.c_str(), kSthRootHashLength); | 281 memcpy(sth->sha256_root_hash, sha256_root_hash.c_str(), kSthRootHashLength); |
| 265 | 282 |
| 266 return GetSampleSTHTreeHeadDecodedSignature(&(sth->signature)); | 283 return GetSampleSTHTreeHeadDecodedSignature(&(sth->signature)); |
| 267 } | 284 } |
| 268 | 285 |
| 269 bool GetSampleEmptySignedTreeHead(SignedTreeHead* sth) { | 286 bool GetSampleEmptySignedTreeHead(SignedTreeHead* sth) { |
| 270 sth->version = SignedTreeHead::V1; | 287 sth->version = SignedTreeHead::V1; |
| 271 sth->timestamp = base::Time::UnixEpoch() + | 288 sth->timestamp = base::Time::UnixEpoch() + |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 return HexToBytes(kSampleSTHTreeHeadSignature); | 323 return HexToBytes(kSampleSTHTreeHeadSignature); |
| 307 } | 324 } |
| 308 | 325 |
| 309 bool GetSampleSTHTreeHeadDecodedSignature(DigitallySigned* signature) { | 326 bool GetSampleSTHTreeHeadDecodedSignature(DigitallySigned* signature) { |
| 310 std::string tree_head_signature = HexToBytes(kSampleSTHTreeHeadSignature); | 327 std::string tree_head_signature = HexToBytes(kSampleSTHTreeHeadSignature); |
| 311 base::StringPiece sp(tree_head_signature); | 328 base::StringPiece sp(tree_head_signature); |
| 312 return DecodeDigitallySigned(&sp, signature) && sp.empty(); | 329 return DecodeDigitallySigned(&sp, signature) && sp.empty(); |
| 313 } | 330 } |
| 314 | 331 |
| 315 std::string GetSampleSTHAsJson() { | 332 std::string GetSampleSTHAsJson() { |
| 316 return CreateSignedTreeHeadJsonString(kSampleSTHTreeSize, kSampleSTHTimestamp, | 333 return CreateSignedTreeHeadJsonString(kSampleSTHTreeSize, kTestTimestamp, |
| 317 GetSampleSTHSHA256RootHash(), | 334 GetSampleSTHSHA256RootHash(), |
| 318 GetSampleSTHTreeHeadSignature()); | 335 GetSampleSTHTreeHeadSignature()); |
| 319 } | 336 } |
| 320 | 337 |
| 321 std::string CreateSignedTreeHeadJsonString(size_t tree_size, | 338 std::string CreateSignedTreeHeadJsonString(size_t tree_size, |
| 322 int64_t timestamp, | 339 int64_t timestamp, |
| 323 std::string sha256_root_hash, | 340 std::string sha256_root_hash, |
| 324 std::string tree_head_signature) { | 341 std::string tree_head_signature) { |
| 325 std::string sth_json = | 342 std::string sth_json = |
| 326 std::string("{\"tree_size\":") + base::SizeTToString(tree_size) + | 343 std::string("{\"tree_size\":") + base::SizeTToString(tree_size) + |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 | 405 |
| 389 bool CheckForSCTOrigin(const ct::CTVerifyResult& result, | 406 bool CheckForSCTOrigin(const ct::CTVerifyResult& result, |
| 390 ct::SignedCertificateTimestamp::Origin origin) { | 407 ct::SignedCertificateTimestamp::Origin origin) { |
| 391 return (result.verified_scts.size() > 0) && | 408 return (result.verified_scts.size() > 0) && |
| 392 (result.verified_scts[0]->origin == origin); | 409 (result.verified_scts[0]->origin == origin); |
| 393 } | 410 } |
| 394 | 411 |
| 395 } // namespace ct | 412 } // namespace ct |
| 396 | 413 |
| 397 } // namespace net | 414 } // namespace net |
| OLD | NEW |