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

Side by Side 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: Implemented wizard controller test. 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/chromeos/login/hwid_checker.h"
6
7 #include <cstdio>
8
9 #include "base/chromeos/chromeos_version.h"
10 #include "base/command_line.h"
11 #include "base/logging.h"
12 #include "chrome/browser/chromeos/system/statistics_provider.h"
13 #include "chrome/common/chrome_switches.h"
14 #include "third_party/re2/re2/re2.h"
15 #include "third_party/zlib/zlib.h"
16
17 namespace chromeos {
18
19 std::string CalculateHWIDChecksum(const std::string& data) {
20 unsigned crc32_checksum = static_cast<unsigned>(crc32(
21 0,
22 reinterpret_cast<const Bytef*>(data.c_str()),
23 data.length()));
24 // We take four least significant decimal digits of CRC-32.
25 char checksum[5];
26 int snprintf_result =
27 snprintf(checksum, 5, "%04u", crc32_checksum % 10000);
28 LOG_ASSERT(snprintf_result == 4);
29 return checksum;
30 }
31
32 bool IsHWIDCorrect(const std::string& hwid) {
33 // TODO(dzhioev): add support of HWID v3 format.
34 std::string body;
35 std::string checksum;
36 if (!RE2::FullMatch(hwid, "([\\s\\S]*) (\\d{4})", &body, &checksum))
37 return false;
38 return CalculateHWIDChecksum(body) == checksum;
39 }
40
41 bool IsMachineHWIDCorrect() {
42 #if !defined(GOOGLE_CHROME_BUILD)
43 return true;
44 #endif
45 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType))
46 return true;
47 if (!base::chromeos::IsRunningOnChromeOS())
48 return true;
49 std::string hwid;
50 chromeos::system::StatisticsProvider* stats =
51 chromeos::system::StatisticsProvider::GetInstance();
52 if (!stats->GetMachineStatistic("hardware_class", &hwid)) {
53 LOG(ERROR) << "Couldn't get machine statistic 'hardware_class'.";
54 return false;
55 }
56 if (!chromeos::IsHWIDCorrect(hwid)) {
57 LOG(ERROR) << "Machine has malformed HWID '" << hwid << "'.";
58 return false;
59 }
60 return true;
61 }
62
63 } // namespace chromeos
64
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/hwid_checker.h ('k') | chrome/browser/chromeos/login/hwid_checker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698