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" |
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(); |
| 24 DCHECK(!salt.empty()); |
20 bool result = hmac.Init(security_origin.spec()) && | 25 bool result = hmac.Init(security_origin.spec()) && |
21 hmac.Sign(raw_unique_id, &digest[0], digest.size()); | 26 hmac.Sign(raw_unique_id + salt, &digest[0], digest.size()); |
22 DCHECK(result); | 27 DCHECK(result); |
23 return StringToLowerASCII(base::HexEncode(&digest[0], digest.size())); | 28 return StringToLowerASCII(base::HexEncode(&digest[0], digest.size())); |
24 } | 29 } |
25 | 30 |
26 bool DoesMediaDeviceIDMatchHMAC(const GURL& security_origin, | 31 bool DoesMediaDeviceIDMatchHMAC(ResourceContext* rc, |
| 32 const GURL& security_origin, |
27 const std::string& device_guid, | 33 const std::string& device_guid, |
28 const std::string& raw_unique_id) { | 34 const std::string& raw_unique_id) { |
29 DCHECK(security_origin.is_valid()); | 35 DCHECK(security_origin.is_valid()); |
30 DCHECK(!raw_unique_id.empty()); | 36 DCHECK(!raw_unique_id.empty()); |
31 std::string guid_from_raw_device_id = | 37 std::string guid_from_raw_device_id = |
32 GetHMACForMediaDeviceID(security_origin, raw_unique_id); | 38 GetHMACForMediaDeviceID(rc, security_origin, raw_unique_id); |
33 return guid_from_raw_device_id == device_guid; | 39 return guid_from_raw_device_id == device_guid; |
34 } | 40 } |
35 | 41 |
36 } // namespace content | 42 } // namespace content |
OLD | NEW |