| 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/resource_context.h" | |
| 10 #include "crypto/hmac.h" | 9 #include "crypto/hmac.h" |
| 11 | 10 |
| 12 namespace content { | 11 namespace content { |
| 13 | 12 |
| 14 std::string GetHMACForMediaDeviceID(ResourceContext* rc, | 13 std::string GetHMACForMediaDeviceID(const ResourceContext::SaltCallback& sc, |
| 15 const GURL& security_origin, | 14 const GURL& security_origin, |
| 16 const std::string& raw_unique_id) { | 15 const std::string& raw_unique_id) { |
| 17 DCHECK(security_origin.is_valid()); | 16 DCHECK(security_origin.is_valid()); |
| 18 DCHECK(!raw_unique_id.empty()); | 17 DCHECK(!raw_unique_id.empty()); |
| 19 crypto::HMAC hmac(crypto::HMAC::SHA256); | 18 crypto::HMAC hmac(crypto::HMAC::SHA256); |
| 20 const size_t digest_length = hmac.DigestLength(); | 19 const size_t digest_length = hmac.DigestLength(); |
| 21 std::vector<uint8> digest(digest_length); | 20 std::vector<uint8> digest(digest_length); |
| 22 std::string salt = rc->GetMediaDeviceIDSalt(); | 21 std::string salt = sc.Run(); |
| 23 bool result = hmac.Init(security_origin.spec()) && | 22 bool result = hmac.Init(security_origin.spec()) && |
| 24 hmac.Sign(raw_unique_id + salt, &digest[0], digest.size()); | 23 hmac.Sign(raw_unique_id + salt, &digest[0], digest.size()); |
| 25 DCHECK(result); | 24 DCHECK(result); |
| 26 return StringToLowerASCII(base::HexEncode(&digest[0], digest.size())); | 25 return StringToLowerASCII(base::HexEncode(&digest[0], digest.size())); |
| 27 } | 26 } |
| 28 | 27 |
| 29 bool DoesMediaDeviceIDMatchHMAC(ResourceContext* rc, | 28 bool DoesMediaDeviceIDMatchHMAC(const ResourceContext::SaltCallback& sc, |
| 30 const GURL& security_origin, | 29 const GURL& security_origin, |
| 31 const std::string& device_guid, | 30 const std::string& device_guid, |
| 32 const std::string& raw_unique_id) { | 31 const std::string& raw_unique_id) { |
| 33 DCHECK(security_origin.is_valid()); | 32 DCHECK(security_origin.is_valid()); |
| 34 DCHECK(!raw_unique_id.empty()); | 33 DCHECK(!raw_unique_id.empty()); |
| 35 std::string guid_from_raw_device_id = | 34 std::string guid_from_raw_device_id = |
| 36 GetHMACForMediaDeviceID(rc, security_origin, raw_unique_id); | 35 GetHMACForMediaDeviceID(sc, security_origin, raw_unique_id); |
| 37 return guid_from_raw_device_id == device_guid; | 36 return guid_from_raw_device_id == device_guid; |
| 38 } | 37 } |
| 39 | 38 |
| 40 } // namespace content | 39 } // namespace content |
| OLD | NEW |