Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
|
Nikita (slow)
2013/02/11 17:09:03
nit: 2013
dzhioev (left Google)
2013/02/11 23:32:56
Done.
| |
| 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)) { | |
|
Nikita (slow)
2013/02/11 17:09:03
nit: Drop {}
dzhioev (left Google)
2013/02/11 23:32:56
Done.
| |
| 46 return true; | |
| 47 } | |
| 48 if (!base::chromeos::IsRunningOnChromeOS()) { | |
|
Nikita (slow)
2013/02/11 17:09:03
nit: Drop {}
dzhioev (left Google)
2013/02/11 23:32:56
Done.
| |
| 49 return true; | |
| 50 } | |
| 51 std::string hwid; | |
| 52 chromeos::system::StatisticsProvider* stats = | |
| 53 chromeos::system::StatisticsProvider::GetInstance(); | |
| 54 return stats->GetMachineStatistic("hardware_class", &hwid) && | |
|
Nikita (slow)
2013/02/11 17:09:03
Please verify that GetMachineStatistic() call does
Nikita (slow)
2013/02/11 17:09:03
nit: Add LOG(ERROR) when stats->GetMachineStatisti
dzhioev (left Google)
2013/02/11 23:32:56
Done.
| |
| 55 chromeos::IsHWIDCorrect(hwid); | |
|
Nikita (slow)
2013/02/11 17:09:03
Please add LOG(ERROR) with the hwid value if IsHWI
dzhioev (left Google)
2013/02/11 23:32:56
Done.
| |
| 56 } | |
| 57 | |
| 58 } // namespace chromeos | |
| 59 | |
| OLD | NEW |