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

Unified Diff: components/safe_browsing_db/v4_protocol_manager_util.cc

Issue 2495783003: Implement support for checking bad IPs aka MatchMalwareIP (Closed)
Patch Set: Add a comma after the last enum value Created 4 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: components/safe_browsing_db/v4_protocol_manager_util.cc
diff --git a/components/safe_browsing_db/v4_protocol_manager_util.cc b/components/safe_browsing_db/v4_protocol_manager_util.cc
index 5d2511551bff93aca15624094772c25f7ff5dcdc..072f8d1c99bb3c197737f234a334448cca1c9cde 100644
--- a/components/safe_browsing_db/v4_protocol_manager_util.cc
+++ b/components/safe_browsing_db/v4_protocol_manager_util.cc
@@ -7,10 +7,12 @@
#include "base/base64.h"
#include "base/metrics/histogram_macros.h"
#include "base/rand_util.h"
+#include "base/sha1.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "crypto/sha2.h"
#include "net/base/escape.h"
+#include "net/base/ip_address.h"
#include "net/http/http_request_headers.h"
#include "url/url_util.h"
@@ -85,6 +87,10 @@ return LINUX_PLATFORM;
#endif
}
+const ListIdentifier GetAnyIpMalwareId() {
+ return ListIdentifier(ANY_PLATFORM, IP_RANGE, MALWARE_THREAT);
+}
+
const ListIdentifier GetChromeUrlApiId() {
return ListIdentifier(CHROME_PLATFORM, URL, API_ABUSE);
}
@@ -528,4 +534,37 @@ void V4ProtocolManagerUtil::SetClientInfoFromConfig(
client_info->set_client_version(config.version);
}
+// static
+bool V4ProtocolManagerUtil::GetIPV6AddressFromString(
+ const std::string& ip_address,
+ net::IPAddress* address) {
+ DCHECK(address);
+ if (!address->AssignFromIPLiteral(ip_address))
+ return false;
+ if (address->IsIPv4())
+ *address = net::ConvertIPv4ToIPv4MappedIPv6(*address);
+ return address->IsIPv6();
+}
+
+// static
+bool V4ProtocolManagerUtil::IPAddressToEncodedIPV6Hash(
+ const std::string& ip_address,
+ FullHash* hashed_encoded_ip) {
+ net::IPAddress address;
+ if (!GetIPV6AddressFromString(ip_address, &address)) {
+ return false;
+ }
+ std::string packed_ip = net::IPAddressToPackedString(address);
+ if (packed_ip.empty()) {
+ return false;
+ }
+
+ const std::string hash = base::SHA1HashString(packed_ip);
+ DCHECK_EQ(20u, hash.size());
+ hashed_encoded_ip->resize(hash.size() + 1);
+ hashed_encoded_ip->replace(0, hash.size(), hash);
+ (*hashed_encoded_ip)[hash.size()] = static_cast<unsigned char>(128);
+ return true;
+}
+
} // namespace safe_browsing

Powered by Google App Engine
This is Rietveld 408576698