| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 // Program to test the SafeBrowsing protocol parsing v2.1. | 5 // Program to test the SafeBrowsing protocol parsing v2.1. |
| 6 | 6 |
| 7 #include "base/hash_tables.h" | 7 #include "base/hash_tables.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "chrome/browser/safe_browsing/protocol_parser.h" | 10 #include "chrome/browser/safe_browsing/protocol_parser.h" |
| (...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 EXPECT_EQ(memcmp(&full_hashes[1].hash, | 448 EXPECT_EQ(memcmp(&full_hashes[1].hash, |
| 449 "cafebeefcafebeefdeaddeaddeaddead", | 449 "cafebeefcafebeefdeaddeaddeaddead", |
| 450 sizeof(SBFullHash)), 0); | 450 sizeof(SBFullHash)), 0); |
| 451 EXPECT_EQ(full_hashes[1].list_name, "goog-malware-shavar"); | 451 EXPECT_EQ(full_hashes[1].list_name, "goog-malware-shavar"); |
| 452 EXPECT_EQ(memcmp(&full_hashes[2].hash, | 452 EXPECT_EQ(memcmp(&full_hashes[2].hash, |
| 453 "zzzzyyyyxxxxwwwwvvvvuuuuttttssss", | 453 "zzzzyyyyxxxxwwwwvvvvuuuuttttssss", |
| 454 sizeof(SBFullHash)), 0); | 454 sizeof(SBFullHash)), 0); |
| 455 EXPECT_EQ(full_hashes[2].list_name, "goog-malware-shavar"); | 455 EXPECT_EQ(full_hashes[2].list_name, "goog-malware-shavar"); |
| 456 } | 456 } |
| 457 | 457 |
| 458 // TODO(port): Enable when we have ported VerifyMAC in safe_browsing_util.cc. | |
| 459 #if defined(OS_WIN) | |
| 460 TEST(SafeBrowsingProtocolParsingTest, TestGetHashWithMac) { | 458 TEST(SafeBrowsingProtocolParsingTest, TestGetHashWithMac) { |
| 461 const unsigned char get_hash[] = { | 459 const unsigned char get_hash[] = { |
| 462 0x32, 0x56, 0x74, 0x6f, 0x6b, 0x36, 0x64, 0x41, | 460 0x32, 0x56, 0x74, 0x6f, 0x6b, 0x36, 0x64, 0x41, |
| 463 0x51, 0x72, 0x65, 0x51, 0x62, 0x38, 0x51, 0x68, | 461 0x51, 0x72, 0x65, 0x51, 0x62, 0x38, 0x51, 0x68, |
| 464 0x59, 0x45, 0x57, 0x51, 0x57, 0x4d, 0x52, 0x65, | 462 0x59, 0x45, 0x57, 0x51, 0x57, 0x4d, 0x52, 0x65, |
| 465 0x42, 0x63, 0x41, 0x3d, 0x0a, 0x67, 0x6f, 0x6f, | 463 0x42, 0x63, 0x41, 0x3d, 0x0a, 0x67, 0x6f, 0x6f, |
| 466 0x67, 0x2d, 0x70, 0x68, 0x69, 0x73, 0x68, 0x2d, | 464 0x67, 0x2d, 0x70, 0x68, 0x69, 0x73, 0x68, 0x2d, |
| 467 0x73, 0x68, 0x61, 0x76, 0x61, 0x72, 0x3a, 0x36, | 465 0x73, 0x68, 0x61, 0x76, 0x61, 0x72, 0x3a, 0x36, |
| 468 0x31, 0x36, 0x39, 0x3a, 0x33, 0x32, 0x0a, 0x17, | 466 0x31, 0x36, 0x39, 0x3a, 0x33, 0x32, 0x0a, 0x17, |
| 469 0x7f, 0x03, 0x42, 0x28, 0x1c, 0x31, 0xb9, 0x0b, | 467 0x7f, 0x03, 0x42, 0x28, 0x1c, 0x31, 0xb9, 0x0b, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 485 SafeBrowsingProtocolParser parser; | 483 SafeBrowsingProtocolParser parser; |
| 486 EXPECT_TRUE(parser.ParseGetHash(reinterpret_cast<const char*>(get_hash), | 484 EXPECT_TRUE(parser.ParseGetHash(reinterpret_cast<const char*>(get_hash), |
| 487 sizeof(get_hash), | 485 sizeof(get_hash), |
| 488 key, | 486 key, |
| 489 &re_key, | 487 &re_key, |
| 490 &full_hashes)); | 488 &full_hashes)); |
| 491 EXPECT_FALSE(re_key); | 489 EXPECT_FALSE(re_key); |
| 492 EXPECT_EQ(full_hashes.size(), static_cast<size_t>(1)); | 490 EXPECT_EQ(full_hashes.size(), static_cast<size_t>(1)); |
| 493 EXPECT_EQ(memcmp(hash_result, &full_hashes[0].hash, sizeof(SBFullHash)), 0); | 491 EXPECT_EQ(memcmp(hash_result, &full_hashes[0].hash, sizeof(SBFullHash)), 0); |
| 494 } | 492 } |
| 495 #endif // defined(OS_WIN) | |
| 496 | |
| 497 | 493 |
| 498 TEST(SafeBrowsingProtocolParsingTest, TestFormatHash) { | 494 TEST(SafeBrowsingProtocolParsingTest, TestFormatHash) { |
| 499 SafeBrowsingProtocolParser parser; | 495 SafeBrowsingProtocolParser parser; |
| 500 std::vector<SBPrefix> prefixes; | 496 std::vector<SBPrefix> prefixes; |
| 501 std::string get_hash; | 497 std::string get_hash; |
| 502 | 498 |
| 503 prefixes.push_back(0x34333231); | 499 prefixes.push_back(0x34333231); |
| 504 prefixes.push_back(0x64636261); | 500 prefixes.push_back(0x64636261); |
| 505 prefixes.push_back(0x73727170); | 501 prefixes.push_back(0x73727170); |
| 506 | 502 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 int next_update = -1; | 544 int next_update = -1; |
| 549 std::vector<SBChunkDelete> deletes; | 545 std::vector<SBChunkDelete> deletes; |
| 550 std::vector<ChunkUrl> urls; | 546 std::vector<ChunkUrl> urls; |
| 551 EXPECT_TRUE(parser.ParseUpdate(update.data(), | 547 EXPECT_TRUE(parser.ParseUpdate(update.data(), |
| 552 static_cast<int>(update.size()), "", | 548 static_cast<int>(update.size()), "", |
| 553 &next_update, &re_key, | 549 &next_update, &re_key, |
| 554 &reset, &deletes, &urls)); | 550 &reset, &deletes, &urls)); |
| 555 EXPECT_TRUE(reset); | 551 EXPECT_TRUE(reset); |
| 556 } | 552 } |
| 557 | 553 |
| 558 // TODO(port): Enable when we have ported VerifyMAC in safe_browsing_util.cc. | |
| 559 #if defined(OS_WIN) | |
| 560 TEST(SafeBrowsingProtocolParsingTest, TestVerifyUpdateMac) { | 554 TEST(SafeBrowsingProtocolParsingTest, TestVerifyUpdateMac) { |
| 561 SafeBrowsingProtocolParser parser; | 555 SafeBrowsingProtocolParser parser; |
| 562 | 556 |
| 563 const std::string update = | 557 const std::string update = |
| 564 "m:XIU0LiQhAPJq6dynXwHbygjS5tw=\n" | 558 "m:XIU0LiQhAPJq6dynXwHbygjS5tw=\n" |
| 565 "n:1895\n" | 559 "n:1895\n" |
| 566 "i:goog-phish-shavar\n" | 560 "i:goog-phish-shavar\n" |
| 567 "u:s.ytimg.com/safebrowsing/rd/goog-phish-shavar_s_6501-6505:6501-6505,pcY
6iVeT9-CBQ3fdAF0rpnKjR1Y=\n" | 561 "u:s.ytimg.com/safebrowsing/rd/goog-phish-shavar_s_6501-6505:6501-6505,pcY
6iVeT9-CBQ3fdAF0rpnKjR1Y=\n" |
| 568 "u:s.ytimg.com/safebrowsing/rd/goog-phish-shavar_s_6506-6510:6506-6510,SDB
rYC3rX3KEPe72LOypnP6QYac=\n" | 562 "u:s.ytimg.com/safebrowsing/rd/goog-phish-shavar_s_6506-6510:6506-6510,SDB
rYC3rX3KEPe72LOypnP6QYac=\n" |
| 569 "u:s.ytimg.com/safebrowsing/rd/goog-phish-shavar_s_6511-6520:6511-6520,9UQ
o-e7OkcsXT2wFWTAhOuWOsUs=\n" | 563 "u:s.ytimg.com/safebrowsing/rd/goog-phish-shavar_s_6511-6520:6511-6520,9UQ
o-e7OkcsXT2wFWTAhOuWOsUs=\n" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 608 const std::string key("v_aDSz6jI92WeHCOoZ07QA=="); | 602 const std::string key("v_aDSz6jI92WeHCOoZ07QA=="); |
| 609 const std::string mac("W9Xp2fUcQ9V66If6Cvsrstpa4Kk="); | 603 const std::string mac("W9Xp2fUcQ9V66If6Cvsrstpa4Kk="); |
| 610 | 604 |
| 611 EXPECT_TRUE(parser.ParseChunk(reinterpret_cast<const char*>(chunk), | 605 EXPECT_TRUE(parser.ParseChunk(reinterpret_cast<const char*>(chunk), |
| 612 sizeof(chunk), key, mac, | 606 sizeof(chunk), key, mac, |
| 613 &re_key, &chunks)); | 607 &re_key, &chunks)); |
| 614 EXPECT_FALSE(re_key); | 608 EXPECT_FALSE(re_key); |
| 615 | 609 |
| 616 safe_browsing_util::FreeChunks(&chunks); | 610 safe_browsing_util::FreeChunks(&chunks); |
| 617 } | 611 } |
| 618 #endif // defined(OS_WIN) | |
| OLD | NEW |