Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1018)

Side by Side Diff: chrome/browser/safe_browsing/protocol_parser.h

Issue 10069031: Replace SafeBrowsing MAC with downloads over SSL. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #ifndef CHROME_BROWSER_SAFE_BROWSING_PROTOCOL_PARSER_H_ 5 #ifndef CHROME_BROWSER_SAFE_BROWSING_PROTOCOL_PARSER_H_
6 #define CHROME_BROWSER_SAFE_BROWSING_PROTOCOL_PARSER_H_ 6 #define CHROME_BROWSER_SAFE_BROWSING_PROTOCOL_PARSER_H_
7 #pragma once 7 #pragma once
8 8
9 // Parse the data returned from the chunk response. 9 // Parse the data returned from the chunk response.
10 // 10 //
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 #include "chrome/browser/safe_browsing/safe_browsing_util.h" 49 #include "chrome/browser/safe_browsing/safe_browsing_util.h"
50 50
51 51
52 class SafeBrowsingProtocolParser { 52 class SafeBrowsingProtocolParser {
53 public: 53 public:
54 SafeBrowsingProtocolParser(); 54 SafeBrowsingProtocolParser();
55 55
56 // Parse the response of an update request. Results for chunk deletions (both 56 // Parse the response of an update request. Results for chunk deletions (both
57 // add-del and sub-del are returned in 'chunk_deletes', and new chunk URLs to 57 // add-del and sub-del are returned in 'chunk_deletes', and new chunk URLs to
58 // download are contained in 'chunk_urls'. The next time the client is allowed 58 // download are contained in 'chunk_urls'. The next time the client is allowed
59 // to request another update is returned in 'next_update_sec'. If the service 59 // to request another update is returned in 'next_update_sec'. 'reset' will
60 // wants us to retrieve new MAC keys, 're_key' will be set to true. If we are 60 // be set to true if the SafeBrowsing service wants us to dump our database.
61 // using MACs to verify responses, the 'key' must be set to the private key
62 // returned from the SafeBrowsing servers. 'reset' will be set to true if the
63 // SafeBrowsing service wants us to dump our database.
64 // Returns 'true'if it was able to decode the chunk properly, 'false' if not 61 // Returns 'true'if it was able to decode the chunk properly, 'false' if not
65 // decoded properly and the results should be ignored. 62 // decoded properly and the results should be ignored.
66 bool ParseUpdate(const char* chunk_data, 63 bool ParseUpdate(const char* chunk_data,
67 int chunk_len, 64 int chunk_len,
68 const std::string& key,
69 int* next_update_sec, 65 int* next_update_sec,
70 bool* re_key,
71 bool* reset, 66 bool* reset,
72 std::vector<SBChunkDelete>* chunk_deletes, 67 std::vector<SBChunkDelete>* chunk_deletes,
73 std::vector<ChunkUrl>* chunk_urls); 68 std::vector<ChunkUrl>* chunk_urls);
74 69
75 // Parse the response from a chunk URL request and returns the hosts/prefixes 70 // Parse the response from a chunk URL request and returns the hosts/prefixes
76 // for adds and subs in "chunks". Returns 'true' on successful parsing, 71 // for adds and subs in "chunks". Returns 'true' on successful parsing,
77 // 'false' otherwise. Any result should be ignored when a parse has failed. 72 // 'false' otherwise. Any result should be ignored when a parse has failed.
78 bool ParseChunk(const std::string& list_name, 73 bool ParseChunk(const std::string& list_name,
79 const char* chunk_data, 74 const char* chunk_data,
80 int chunk_len, 75 int chunk_len,
81 const std::string& key,
82 const std::string& mac,
83 bool* re_key,
84 SBChunkList* chunks); 76 SBChunkList* chunks);
85 77
86 // Parse the result of a GetHash request, returning the list of full hashes. 78 // Parse the result of a GetHash request, returning the list of full hashes.
87 // If we are checking for valid MACs, the caller should populate 'key'.
88 bool ParseGetHash(const char* chunk_data, 79 bool ParseGetHash(const char* chunk_data,
89 int chunk_len, 80 int chunk_len,
90 const std::string& key,
91 bool* re_key,
92 std::vector<SBFullHashResult>* full_hashes); 81 std::vector<SBFullHashResult>* full_hashes);
93 82
94 // Convert a list of partial hashes into a proper GetHash request. 83 // Convert a list of partial hashes into a proper GetHash request.
95 void FormatGetHash(const std::vector<SBPrefix>& prefixes, 84 void FormatGetHash(const std::vector<SBPrefix>& prefixes,
96 std::string* request); 85 std::string* request);
97 86
98 // Parse the keys used for subsequent communications with the SafeBrowsing
99 // servers. Returns true on successful parse, false on parse error.
100 bool ParseNewKey(const char* chunk_data,
101 int chunk_length,
102 std::string* client_key,
103 std::string* wrapped_key);
104
105 private: 87 private:
106 bool ParseAddChunk(const std::string& list_name, 88 bool ParseAddChunk(const std::string& list_name,
107 const char* data, 89 const char* data,
108 int data_len, 90 int data_len,
109 int hash_len, 91 int hash_len,
110 std::deque<SBChunkHost>* hosts); 92 std::deque<SBChunkHost>* hosts);
111 bool ParseSubChunk(const std::string& list_name, 93 bool ParseSubChunk(const std::string& list_name,
112 const char* data, 94 const char* data,
113 int data_len, 95 int data_len,
114 int hash_len, 96 int hash_len,
115 std::deque<SBChunkHost>* hosts); 97 std::deque<SBChunkHost>* hosts);
116 98
117 // Helper functions used by ParseAddChunk and ParseSubChunk. 99 // Helper functions used by ParseAddChunk and ParseSubChunk.
118 static bool ReadHostAndPrefixCount(const char** data, 100 static bool ReadHostAndPrefixCount(const char** data,
119 int* remaining, 101 int* remaining,
120 SBPrefix* host, 102 SBPrefix* host,
121 int* count); 103 int* count);
122 static bool ReadChunkId(const char** data, int* remaining, int* chunk_id); 104 static bool ReadChunkId(const char** data, int* remaining, int* chunk_id);
123 static bool ReadPrefixes( 105 static bool ReadPrefixes(
124 const char** data, int* remaining, SBEntry* entry, int count); 106 const char** data, int* remaining, SBEntry* entry, int count);
125 107
126 // The name of the current list 108 // The name of the current list
127 std::string list_name_; 109 std::string list_name_;
128 110
129 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingProtocolParser); 111 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingProtocolParser);
130 }; 112 };
131 113
132 114
133 #endif // CHROME_BROWSER_SAFE_BROWSING_PROTOCOL_PARSER_H_ 115 #endif // CHROME_BROWSER_SAFE_BROWSING_PROTOCOL_PARSER_H_
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/protocol_manager_unittest.cc ('k') | chrome/browser/safe_browsing/protocol_parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698