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

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

Issue 54863002: Implement a salt for MediaSource IDs that can be cleared by a user. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed jois nit. Created 7 years 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 | Annotate | Revision Log
« no previous file with comments | « content/public/browser/media_device_id.h ('k') | content/public/browser/resource_context.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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" 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"
9 #include "crypto/hmac.h" 10 #include "crypto/hmac.h"
10 11
11 namespace content { 12 namespace content {
12 13
13 std::string GetHMACForMediaDeviceID(const GURL& security_origin, 14 std::string GetHMACForMediaDeviceID(ResourceContext* rc,
15 const GURL& security_origin,
14 const std::string& raw_unique_id) { 16 const std::string& raw_unique_id) {
15 DCHECK(security_origin.is_valid()); 17 DCHECK(security_origin.is_valid());
16 DCHECK(!raw_unique_id.empty()); 18 DCHECK(!raw_unique_id.empty());
17 crypto::HMAC hmac(crypto::HMAC::SHA256); 19 crypto::HMAC hmac(crypto::HMAC::SHA256);
18 const size_t digest_length = hmac.DigestLength(); 20 const size_t digest_length = hmac.DigestLength();
19 std::vector<uint8> digest(digest_length); 21 std::vector<uint8> digest(digest_length);
22 std::string salt = rc->GetMediaDeviceIDSalt();
20 bool result = hmac.Init(security_origin.spec()) && 23 bool result = hmac.Init(security_origin.spec()) &&
21 hmac.Sign(raw_unique_id, &digest[0], digest.size()); 24 hmac.Sign(raw_unique_id + salt, &digest[0], digest.size());
22 DCHECK(result); 25 DCHECK(result);
23 return StringToLowerASCII(base::HexEncode(&digest[0], digest.size())); 26 return StringToLowerASCII(base::HexEncode(&digest[0], digest.size()));
24 } 27 }
25 28
26 bool DoesMediaDeviceIDMatchHMAC(const GURL& security_origin, 29 bool DoesMediaDeviceIDMatchHMAC(ResourceContext* rc,
30 const GURL& security_origin,
27 const std::string& device_guid, 31 const std::string& device_guid,
28 const std::string& raw_unique_id) { 32 const std::string& raw_unique_id) {
29 DCHECK(security_origin.is_valid()); 33 DCHECK(security_origin.is_valid());
30 DCHECK(!raw_unique_id.empty()); 34 DCHECK(!raw_unique_id.empty());
31 std::string guid_from_raw_device_id = 35 std::string guid_from_raw_device_id =
32 GetHMACForMediaDeviceID(security_origin, raw_unique_id); 36 GetHMACForMediaDeviceID(rc, security_origin, raw_unique_id);
33 return guid_from_raw_device_id == device_guid; 37 return guid_from_raw_device_id == device_guid;
34 } 38 }
35 39
36 } // namespace content 40 } // namespace content
OLDNEW
« no previous file with comments | « content/public/browser/media_device_id.h ('k') | content/public/browser/resource_context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698