| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 // Parse the data returned from the SafeBrowsing v2.1 protocol response. | 5 // Parse the data returned from the SafeBrowsing v2.1 protocol response. |
| 6 | 6 |
| 7 #include "chrome/browser/safe_browsing/protocol_parser.h" | 7 #include "chrome/browser/safe_browsing/protocol_parser.h" |
| 8 | 8 |
| 9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 10 | 10 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 | 76 |
| 77 while (length > 0) { | 77 while (length > 0) { |
| 78 if (!GetLine(data, length, &line)) | 78 if (!GetLine(data, length, &line)) |
| 79 return false; | 79 return false; |
| 80 | 80 |
| 81 offset = static_cast<int>(line.size()) + 1; | 81 offset = static_cast<int>(line.size()) + 1; |
| 82 data += offset; | 82 data += offset; |
| 83 length -= offset; | 83 length -= offset; |
| 84 | 84 |
| 85 std::vector<std::string> cmd_parts; | 85 std::vector<std::string> cmd_parts; |
| 86 SplitString(line, ':', &cmd_parts); | 86 base::SplitString(line, ':', &cmd_parts); |
| 87 if (cmd_parts.size() != 3) | 87 if (cmd_parts.size() != 3) |
| 88 return false; | 88 return false; |
| 89 | 89 |
| 90 SBFullHashResult full_hash; | 90 SBFullHashResult full_hash; |
| 91 full_hash.list_name = cmd_parts[0]; | 91 full_hash.list_name = cmd_parts[0]; |
| 92 full_hash.add_chunk_id = atoi(cmd_parts[1].c_str()); | 92 full_hash.add_chunk_id = atoi(cmd_parts[1].c_str()); |
| 93 int full_hash_len = atoi(cmd_parts[2].c_str()); | 93 int full_hash_len = atoi(cmd_parts[2].c_str()); |
| 94 | 94 |
| 95 // Ignore hash results from lists we don't recognize. | 95 // Ignore hash results from lists we don't recognize. |
| 96 if (safe_browsing_util::GetListId(full_hash.list_name) < 0) { | 96 if (safe_browsing_util::GetListId(full_hash.list_name) < 0) { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 | 144 |
| 145 // Populated below. | 145 // Populated below. |
| 146 std::string list_name; | 146 std::string list_name; |
| 147 | 147 |
| 148 while (length > 0) { | 148 while (length > 0) { |
| 149 std::string cmd_line; | 149 std::string cmd_line; |
| 150 if (!GetLine(data, length, &cmd_line)) | 150 if (!GetLine(data, length, &cmd_line)) |
| 151 return false; // Error: bad list format! | 151 return false; // Error: bad list format! |
| 152 | 152 |
| 153 std::vector<std::string> cmd_parts; | 153 std::vector<std::string> cmd_parts; |
| 154 SplitString(cmd_line, ':', &cmd_parts); | 154 base::SplitString(cmd_line, ':', &cmd_parts); |
| 155 if (cmd_parts.empty()) | 155 if (cmd_parts.empty()) |
| 156 return false; | 156 return false; |
| 157 const std::string& command = cmd_parts[0]; | 157 const std::string& command = cmd_parts[0]; |
| 158 if (cmd_parts.size() != 2 && command[0] != 'u') | 158 if (cmd_parts.size() != 2 && command[0] != 'u') |
| 159 return false; | 159 return false; |
| 160 | 160 |
| 161 const int consumed = static_cast<int>(cmd_line.size()) + 1; | 161 const int consumed = static_cast<int>(cmd_line.size()) + 1; |
| 162 data += consumed; | 162 data += consumed; |
| 163 length -= consumed; | 163 length -= consumed; |
| 164 if (length < 0) | 164 if (length < 0) |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 return false; | 259 return false; |
| 260 } | 260 } |
| 261 | 261 |
| 262 while (remaining > 0) { | 262 while (remaining > 0) { |
| 263 std::string cmd_line; | 263 std::string cmd_line; |
| 264 if (!GetLine(chunk_data, length, &cmd_line)) | 264 if (!GetLine(chunk_data, length, &cmd_line)) |
| 265 return false; // Error: bad chunk format! | 265 return false; // Error: bad chunk format! |
| 266 | 266 |
| 267 const int line_len = static_cast<int>(cmd_line.length()) + 1; | 267 const int line_len = static_cast<int>(cmd_line.length()) + 1; |
| 268 std::vector<std::string> cmd_parts; | 268 std::vector<std::string> cmd_parts; |
| 269 SplitString(cmd_line, ':', &cmd_parts); | 269 base::SplitString(cmd_line, ':', &cmd_parts); |
| 270 | 270 |
| 271 // Handle a possible re-key command. | 271 // Handle a possible re-key command. |
| 272 if (cmd_parts.size() != 4) { | 272 if (cmd_parts.size() != 4) { |
| 273 if (cmd_parts.size() == 2 && | 273 if (cmd_parts.size() == 2 && |
| 274 cmd_parts[0] == "e" && | 274 cmd_parts[0] == "e" && |
| 275 cmd_parts[1] == "pleaserekey") { | 275 cmd_parts[1] == "pleaserekey") { |
| 276 *re_key = true; | 276 *re_key = true; |
| 277 chunk_data += line_len; | 277 chunk_data += line_len; |
| 278 remaining -= line_len; | 278 remaining -= line_len; |
| 279 continue; | 279 continue; |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 | 460 |
| 461 const char* data = chunk_data; | 461 const char* data = chunk_data; |
| 462 int remaining = chunk_length; | 462 int remaining = chunk_length; |
| 463 | 463 |
| 464 while (remaining > 0) { | 464 while (remaining > 0) { |
| 465 std::string line; | 465 std::string line; |
| 466 if (!GetLine(data, remaining, &line)) | 466 if (!GetLine(data, remaining, &line)) |
| 467 return false; | 467 return false; |
| 468 | 468 |
| 469 std::vector<std::string> cmd_parts; | 469 std::vector<std::string> cmd_parts; |
| 470 SplitString(line, ':', &cmd_parts); | 470 base::SplitString(line, ':', &cmd_parts); |
| 471 if (cmd_parts.size() != 3) | 471 if (cmd_parts.size() != 3) |
| 472 return false; | 472 return false; |
| 473 | 473 |
| 474 if (static_cast<int>(cmd_parts[2].size()) != atoi(cmd_parts[1].c_str())) | 474 if (static_cast<int>(cmd_parts[2].size()) != atoi(cmd_parts[1].c_str())) |
| 475 return false; | 475 return false; |
| 476 | 476 |
| 477 if (cmd_parts[0] == "clientkey") { | 477 if (cmd_parts[0] == "clientkey") { |
| 478 client_key->assign(cmd_parts[2]); | 478 client_key->assign(cmd_parts[2]); |
| 479 } else if (cmd_parts[0] == "wrappedkey") { | 479 } else if (cmd_parts[0] == "wrappedkey") { |
| 480 wrapped_key->assign(cmd_parts[2]); | 480 wrapped_key->assign(cmd_parts[2]); |
| 481 } else { | 481 } else { |
| 482 return false; | 482 return false; |
| 483 } | 483 } |
| 484 | 484 |
| 485 data += line.size() + 1; | 485 data += line.size() + 1; |
| 486 remaining -= static_cast<int>(line.size()) + 1; | 486 remaining -= static_cast<int>(line.size()) + 1; |
| 487 } | 487 } |
| 488 | 488 |
| 489 if (client_key->empty() || wrapped_key->empty()) | 489 if (client_key->empty() || wrapped_key->empty()) |
| 490 return false; | 490 return false; |
| 491 | 491 |
| 492 return true; | 492 return true; |
| 493 } | 493 } |
| OLD | NEW |