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/browser/browser_main_loop.h" | 9 #include "content/browser/browser_main_loop.h" |
10 #include "content/browser/renderer_host/media/media_stream_manager.h" | 10 #include "content/browser/renderer_host/media/media_stream_manager.h" |
11 #include "crypto/hmac.h" | 11 #include "crypto/hmac.h" |
12 | 12 |
13 namespace content { | 13 namespace content { |
14 | 14 |
15 std::string GetHMACForMediaDeviceID(const ResourceContext::SaltCallback& sc, | 15 std::string GetHMACForMediaDeviceID(const ResourceContext::SaltCallback& sc, |
16 const GURL& security_origin, | 16 const GURL& security_origin, |
17 const std::string& raw_unique_id) { | 17 const std::string& raw_unique_id) { |
18 DCHECK(security_origin.is_valid()); | 18 DCHECK(security_origin.is_valid()); |
19 DCHECK(!raw_unique_id.empty()); | 19 DCHECK(!raw_unique_id.empty()); |
20 crypto::HMAC hmac(crypto::HMAC::SHA256); | 20 crypto::HMAC hmac(crypto::HMAC::SHA256); |
21 const size_t digest_length = hmac.DigestLength(); | 21 const size_t digest_length = hmac.DigestLength(); |
22 std::vector<uint8> digest(digest_length); | 22 std::vector<uint8> digest(digest_length); |
23 std::string salt = sc.Run(); | 23 std::string salt = sc.Run(); |
24 bool result = hmac.Init(security_origin.spec()) && | 24 bool result = hmac.Init(security_origin.spec()) && |
25 hmac.Sign(raw_unique_id + salt, &digest[0], digest.size()); | 25 hmac.Sign(raw_unique_id + salt, &digest[0], digest.size()); |
26 DCHECK(result); | 26 DCHECK(result); |
27 return base::StringToLowerASCII(base::HexEncode(&digest[0], digest.size())); | 27 return base::ToLowerASCII(base::HexEncode(&digest[0], digest.size())); |
28 } | 28 } |
29 | 29 |
30 bool DoesMediaDeviceIDMatchHMAC(const ResourceContext::SaltCallback& sc, | 30 bool DoesMediaDeviceIDMatchHMAC(const ResourceContext::SaltCallback& sc, |
31 const GURL& security_origin, | 31 const GURL& security_origin, |
32 const std::string& device_guid, | 32 const std::string& device_guid, |
33 const std::string& raw_unique_id) { | 33 const std::string& raw_unique_id) { |
34 DCHECK(security_origin.is_valid()); | 34 DCHECK(security_origin.is_valid()); |
35 DCHECK(!raw_unique_id.empty()); | 35 DCHECK(!raw_unique_id.empty()); |
36 std::string guid_from_raw_device_id = | 36 std::string guid_from_raw_device_id = |
37 GetHMACForMediaDeviceID(sc, security_origin, raw_unique_id); | 37 GetHMACForMediaDeviceID(sc, security_origin, raw_unique_id); |
(...skipping 10 matching lines...) Expand all Loading... |
48 | 48 |
49 return manager->TranslateSourceIdToDeviceId( | 49 return manager->TranslateSourceIdToDeviceId( |
50 content::MEDIA_DEVICE_VIDEO_CAPTURE, | 50 content::MEDIA_DEVICE_VIDEO_CAPTURE, |
51 rc, | 51 rc, |
52 security_origin, | 52 security_origin, |
53 source_id, | 53 source_id, |
54 device_id); | 54 device_id); |
55 } | 55 } |
56 | 56 |
57 } // namespace content | 57 } // namespace content |
OLD | NEW |