Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #include "content/public/browser/media_device_id.h" | 4 #include "content/public/browser/media_device_id.h" |
| 5 | 5 |
| 6 #include "base/logging.h" | 6 #include "base/logging.h" |
| 7 #include "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
| 8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "content/public/browser/content_browser_client.h" | |
| 10 #include "content/public/common/content_client.h" | |
|
jam
2013/11/06 00:20:03
nit: remove these two
perkj_chrome
2013/11/28 21:42:14
Done.
| |
| 9 #include "crypto/hmac.h" | 11 #include "crypto/hmac.h" |
| 10 | 12 |
| 11 namespace content { | 13 namespace content { |
| 12 | 14 |
| 13 std::string GetHMACForMediaDeviceID(const GURL& security_origin, | 15 std::string GetHMACForMediaDeviceID(ResourceContext* rc, |
| 16 const GURL& security_origin, | |
| 14 const std::string& raw_unique_id) { | 17 const std::string& raw_unique_id) { |
| 15 DCHECK(security_origin.is_valid()); | 18 DCHECK(security_origin.is_valid()); |
| 16 DCHECK(!raw_unique_id.empty()); | 19 DCHECK(!raw_unique_id.empty()); |
| 17 crypto::HMAC hmac(crypto::HMAC::SHA256); | 20 crypto::HMAC hmac(crypto::HMAC::SHA256); |
| 18 const size_t digest_length = hmac.DigestLength(); | 21 const size_t digest_length = hmac.DigestLength(); |
| 19 std::vector<uint8> digest(digest_length); | 22 std::vector<uint8> digest(digest_length); |
| 23 std::string salt = rc->GetMediaDeviceIDSalt(); | |
| 20 bool result = hmac.Init(security_origin.spec()) && | 24 bool result = hmac.Init(security_origin.spec()) && |
| 21 hmac.Sign(raw_unique_id, &digest[0], digest.size()); | 25 hmac.Sign(raw_unique_id + salt, &digest[0], digest.size()); |
| 22 DCHECK(result); | 26 DCHECK(result); |
| 23 return StringToLowerASCII(base::HexEncode(&digest[0], digest.size())); | 27 return StringToLowerASCII(base::HexEncode(&digest[0], digest.size())); |
| 24 } | 28 } |
| 25 | 29 |
| 26 bool DoesMediaDeviceIDMatchHMAC(const GURL& security_origin, | 30 bool DoesMediaDeviceIDMatchHMAC(ResourceContext* rc, |
| 31 const GURL& security_origin, | |
| 27 const std::string& device_guid, | 32 const std::string& device_guid, |
| 28 const std::string& raw_unique_id) { | 33 const std::string& raw_unique_id) { |
| 29 DCHECK(security_origin.is_valid()); | 34 DCHECK(security_origin.is_valid()); |
| 30 DCHECK(!raw_unique_id.empty()); | 35 DCHECK(!raw_unique_id.empty()); |
| 31 std::string guid_from_raw_device_id = | 36 std::string guid_from_raw_device_id = |
| 32 GetHMACForMediaDeviceID(security_origin, raw_unique_id); | 37 GetHMACForMediaDeviceID(rc, security_origin, raw_unique_id); |
| 33 return guid_from_raw_device_id == device_guid; | 38 return guid_from_raw_device_id == device_guid; |
| 34 } | 39 } |
| 35 | 40 |
| 36 } // namespace content | 41 } // namespace content |
| OLD | NEW |