Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(396)

Side by Side Diff: content/public/browser/media_device_id.cc

Issue 1369723003: Do not hash default and communications media device ID (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Tommi's comments Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
7 #include "base/strings/string_number_conversions.h"
8 #include "base/strings/string_util.h"
9 #include "content/browser/browser_main_loop.h" 6 #include "content/browser/browser_main_loop.h"
10 #include "content/browser/renderer_host/media/media_stream_manager.h" 7 #include "content/browser/renderer_host/media/media_stream_manager.h"
11 #include "crypto/hmac.h"
12 8
13 namespace content { 9 namespace content {
14 10
15 std::string GetHMACForMediaDeviceID(const ResourceContext::SaltCallback& sc, 11 std::string GetHMACForMediaDeviceID(const ResourceContext::SaltCallback& sc,
16 const GURL& security_origin, 12 const GURL& security_origin,
17 const std::string& raw_unique_id) { 13 const std::string& raw_unique_id) {
18 DCHECK(security_origin.is_valid()); 14 return MediaStreamManager::GetHMACForMediaDeviceID(sc, security_origin,
19 DCHECK(!raw_unique_id.empty()); 15 raw_unique_id);
20 crypto::HMAC hmac(crypto::HMAC::SHA256);
21 const size_t digest_length = hmac.DigestLength();
22 std::vector<uint8> digest(digest_length);
23 std::string salt = sc.Run();
24 bool result = hmac.Init(security_origin.spec()) &&
25 hmac.Sign(raw_unique_id + salt, &digest[0], digest.size());
26 DCHECK(result);
27 return base::ToLowerASCII(base::HexEncode(&digest[0], digest.size()));
28 } 16 }
29 17
30 bool DoesMediaDeviceIDMatchHMAC(const ResourceContext::SaltCallback& sc, 18 bool DoesMediaDeviceIDMatchHMAC(const ResourceContext::SaltCallback& sc,
31 const GURL& security_origin, 19 const GURL& security_origin,
32 const std::string& device_guid, 20 const std::string& device_guid,
33 const std::string& raw_unique_id) { 21 const std::string& raw_unique_id) {
34 DCHECK(security_origin.is_valid()); 22 return MediaStreamManager::DoesMediaDeviceIDMatchHMAC(
35 DCHECK(!raw_unique_id.empty()); 23 sc, security_origin, device_guid, raw_unique_id);
36 std::string guid_from_raw_device_id =
37 GetHMACForMediaDeviceID(sc, security_origin, raw_unique_id);
38 return guid_from_raw_device_id == device_guid;
39 } 24 }
40 25
41 bool GetMediaDeviceIDForHMAC(MediaStreamType stream_type, 26 bool GetMediaDeviceIDForHMAC(MediaStreamType stream_type,
42 const ResourceContext::SaltCallback& rc, 27 const ResourceContext::SaltCallback& rc,
43 const GURL& security_origin, 28 const GURL& security_origin,
44 const std::string& source_id, 29 const std::string& source_id,
45 std::string* device_id) { 30 std::string* device_id) {
46 content::MediaStreamManager* manager = 31 content::MediaStreamManager* manager =
47 content::BrowserMainLoop::GetInstance()->media_stream_manager(); 32 content::BrowserMainLoop::GetInstance()->media_stream_manager();
48 33
49 return manager->TranslateSourceIdToDeviceId( 34 return manager->TranslateSourceIdToDeviceId(
50 content::MEDIA_DEVICE_VIDEO_CAPTURE, 35 content::MEDIA_DEVICE_VIDEO_CAPTURE,
51 rc, 36 rc,
52 security_origin, 37 security_origin,
53 source_id, 38 source_id,
54 device_id); 39 device_id);
55 } 40 }
56 41
57 } // namespace content 42 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698