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

Unified Diff: chrome/browser/chromeos/login/hwid_checker.cc

Issue 12213110: Implemented screen notifying users about malformed HWID. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Merge conflicts resolved. Created 7 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/login/hwid_checker.cc
diff --git a/chrome/browser/chromeos/login/hwid_checker.cc b/chrome/browser/chromeos/login/hwid_checker.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ddbd6c22bc6dc73ba4405d61ab417d50211fbcfd
--- /dev/null
+++ b/chrome/browser/chromeos/login/hwid_checker.cc
@@ -0,0 +1,64 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/chromeos/login/hwid_checker.h"
+
+#include <cstdio>
+
+#include "base/chromeos/chromeos_version.h"
+#include "base/command_line.h"
+#include "base/logging.h"
+#include "chrome/browser/chromeos/system/statistics_provider.h"
+#include "chrome/common/chrome_switches.h"
+#include "third_party/re2/re2/re2.h"
+#include "third_party/zlib/zlib.h"
+
+namespace chromeos {
+
+std::string CalculateHWIDChecksum(const std::string& data) {
+ unsigned crc32_checksum = static_cast<unsigned>(crc32(
+ 0,
+ reinterpret_cast<const Bytef*>(data.c_str()),
+ data.length()));
+ // We take four least significant decimal digits of CRC-32.
+ char checksum[5];
+ int snprintf_result =
+ snprintf(checksum, 5, "%04u", crc32_checksum % 10000);
+ LOG_ASSERT(snprintf_result == 4);
+ return checksum;
+}
+
+bool IsHWIDCorrect(const std::string& hwid) {
+ // TODO(dzhioev): add support of HWID v3 format.
+ std::string body;
+ std::string checksum;
+ if (!RE2::FullMatch(hwid, "([\\s\\S]*) (\\d{4})", &body, &checksum))
+ return false;
+ return CalculateHWIDChecksum(body) == checksum;
+}
+
+bool IsMachineHWIDCorrect() {
+#if !defined(GOOGLE_CHROME_BUILD)
+ return true;
+#endif
+ if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType))
+ return true;
+ if (!base::chromeos::IsRunningOnChromeOS())
+ return true;
+ std::string hwid;
+ chromeos::system::StatisticsProvider* stats =
+ chromeos::system::StatisticsProvider::GetInstance();
+ if (!stats->GetMachineStatistic("hardware_class", &hwid)) {
+ LOG(ERROR) << "Couldn't get machine statistic `hardware_class'.";
+ return false;
+ }
+ if (!chromeos::IsHWIDCorrect(hwid)) {
+ LOG(ERROR) << "Machine has malformed HWID `" << hwid << "'.";
Nikita (slow) 2013/02/12 07:51:50 nit: Use same style quotes.
dzhioev (left Google) 2013/02/12 13:57:51 Done.
+ return false;
+ }
+ return true;
+}
+
+} // namespace chromeos
+

Powered by Google App Engine
This is Rietveld 408576698