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

Side by Side Diff: content/browser/renderer_host/media/media_source_id_factory.cc

Issue 34393006: Refactor MediaStreamManager to never output real device id. It now always output sourceId in the fo… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Clean up unneccessary test setup that just caused confusion. Created 7 years, 1 month 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "content/browser/renderer_host/media/media_source_id_factory.h"
6
7 #include "base/strings/string_number_conversions.h"
8 #include "base/strings/string_util.h"
9 #include "crypto/hmac.h"
10
11 namespace content {
12
13 bool MediaSourceIdFactory::DoesSourceIdMatchDeviceId(
14 const GURL& security_origin,
15 const std::string& source_id,
16 const std::string& device_id) {
17 crypto::HMAC hmac(crypto::HMAC::SHA256);
18 bool result = hmac.Init(security_origin.spec());
19 DCHECK(result);
20 std::vector<uint8> converted_guid;
21 if (!base::HexStringToBytes(source_id, &converted_guid))
22 return false;
23 return hmac.Verify(
24 device_id,
25 base::StringPiece(reinterpret_cast<const char*>(&converted_guid[0]),
26 converted_guid.size()));
27 }
28
29 void MediaSourceIdFactory::GenerateSourceId(const GURL& origin,
30 const std::string& device_id,
31 std::string* source_id) {
32 // TODO(perkj): Add a random salt to this HMAC that is dependent on current
33 // user profile. This salt should be regenerated if the cache is cleared.
34 crypto::HMAC hmac(crypto::HMAC::SHA256);
35 const size_t digest_length = hmac.DigestLength();
36 std::vector<uint8> digest(digest_length);
37 bool result = hmac.Init(origin.spec()) &&
38 hmac.Sign(device_id, &digest[0], digest.size());
39 CHECK(result);
40
41 *source_id = StringToLowerASCII(base::HexEncode(&digest[0], digest.size()));
42 }
43
44 void MediaSourceIdFactory::GenerateSourceIds(
45 const GURL& origin,
46 const StreamDeviceInfoArray& raw_devices,
47 StreamDeviceInfoArray* devices_with_sourceid) {
48 DCHECK(devices_with_sourceid);
49
50 // Replace raw ids with hmac'd ids.
51 for (StreamDeviceInfoArray::const_iterator device_itr = raw_devices.begin();
52 device_itr != raw_devices.end();
53 ++device_itr) {
54 StreamDeviceInfo current_device_info = *device_itr;
55 GenerateSourceId(origin,
56 device_itr->device.id,
57 &current_device_info.device.id);
58 devices_with_sourceid->push_back(current_device_info);
59 }
60 }
61
62 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698