Index: content/browser/renderer_host/media/media_stream_manager.cc |
diff --git a/content/browser/renderer_host/media/media_stream_manager.cc b/content/browser/renderer_host/media/media_stream_manager.cc |
index 8e4c7ca211e76a7d427d6f343a42d725ddbccf27..fa521ecb14795b6e2239e921e43293393d7813ff 100644 |
--- a/content/browser/renderer_host/media/media_stream_manager.cc |
+++ b/content/browser/renderer_host/media/media_stream_manager.cc |
@@ -177,6 +177,11 @@ |
return output_string; |
} |
+// Needed for MediaStreamManager::GenerateStream below. |
+std::string ReturnEmptySalt() { |
+ return std::string(); |
+} |
+ |
// Clears the MediaStreamDevice.name from all devices in |devices|. |
void ClearDeviceLabels(content::StreamDeviceInfoArray* devices) { |
for (content::StreamDeviceInfo& device_info : *devices) |
@@ -213,7 +218,7 @@ |
bool user_gesture, |
MediaStreamRequestType request_type, |
const StreamControls& controls, |
- const std::string& salt) |
+ const ResourceContext::SaltCallback& salt_callback) |
: requester(requester), |
requesting_process_id(requesting_process_id), |
requesting_frame_id(requesting_frame_id), |
@@ -222,7 +227,7 @@ |
user_gesture(user_gesture), |
request_type(request_type), |
controls(controls), |
- salt(salt), |
+ salt_callback(salt_callback), |
state_(NUM_MEDIA_TYPES, MEDIA_REQUEST_STATE_NOT_REQUESTED), |
audio_type_(MEDIA_NO_SERVICE), |
video_type_(MEDIA_NO_SERVICE), |
@@ -341,7 +346,7 @@ |
const StreamControls controls; |
- const std::string salt; |
+ ResourceContext::SaltCallback salt_callback; |
StreamDeviceInfoArray devices; |
@@ -461,11 +466,11 @@ |
// TODO(perkj): The argument list with NULL parameters to DeviceRequest |
// suggests that this is the wrong design. Can this be refactored? |
- DeviceRequest* request = |
- new DeviceRequest(NULL, render_process_id, render_frame_id, |
- page_request_id, security_origin, |
- false, // user gesture |
- MEDIA_DEVICE_ACCESS, controls, std::string()); |
+ DeviceRequest* request = new DeviceRequest( |
+ NULL, render_process_id, render_frame_id, page_request_id, |
+ security_origin, |
+ false, // user gesture |
+ MEDIA_DEVICE_ACCESS, controls, base::Bind(&ReturnEmptySalt)); |
const std::string& label = AddRequest(request); |
@@ -485,7 +490,7 @@ |
void MediaStreamManager::GenerateStream(MediaStreamRequester* requester, |
int render_process_id, |
int render_frame_id, |
- const std::string& salt, |
+ const ResourceContext::SaltCallback& sc, |
int page_request_id, |
const StreamControls& controls, |
const url::Origin& security_origin, |
@@ -495,7 +500,7 @@ |
DeviceRequest* request = new DeviceRequest( |
requester, render_process_id, render_frame_id, page_request_id, |
- security_origin, user_gesture, MEDIA_GENERATE_STREAM, controls, salt); |
+ security_origin, user_gesture, MEDIA_GENERATE_STREAM, controls, sc); |
const std::string& label = AddRequest(request); |
@@ -680,7 +685,7 @@ |
MediaStreamRequester* requester, |
int render_process_id, |
int render_frame_id, |
- const std::string& salt, |
+ const ResourceContext::SaltCallback& sc, |
int page_request_id, |
MediaStreamType type, |
const url::Origin& security_origin) { |
@@ -694,7 +699,7 @@ |
new DeviceRequest(requester, render_process_id, render_frame_id, |
page_request_id, security_origin, |
false, // user gesture |
- MEDIA_ENUMERATE_DEVICES, StreamControls(), salt); |
+ MEDIA_ENUMERATE_DEVICES, StreamControls(), sc); |
if (IsAudioInputMediaType(type) || type == MEDIA_DEVICE_AUDIO_OUTPUT) |
request->SetAudioType(type); |
else if (IsVideoMediaType(type)) |
@@ -796,7 +801,7 @@ |
void MediaStreamManager::OpenDevice(MediaStreamRequester* requester, |
int render_process_id, |
int render_frame_id, |
- const std::string& salt, |
+ const ResourceContext::SaltCallback& sc, |
int page_request_id, |
const std::string& device_id, |
MediaStreamType type, |
@@ -819,7 +824,7 @@ |
new DeviceRequest(requester, render_process_id, render_frame_id, |
page_request_id, security_origin, |
false, // user gesture |
- MEDIA_OPEN_DEVICE_PEPPER_ONLY, controls, salt); |
+ MEDIA_OPEN_DEVICE_PEPPER_ONLY, controls, sc); |
const std::string& label = AddRequest(request); |
// Post a task and handle the request asynchronously. The reason is that the |
@@ -835,7 +840,7 @@ |
bool MediaStreamManager::TranslateSourceIdToDeviceId( |
MediaStreamType stream_type, |
- const std::string& salt, |
+ const ResourceContext::SaltCallback& sc, |
const url::Origin& security_origin, |
const std::string& source_id, |
std::string* device_id) const { |
@@ -854,7 +859,7 @@ |
return false; |
for (const StreamDeviceInfo& device_info : cache->devices) { |
- if (DoesMediaDeviceIDMatchHMAC(salt, security_origin, source_id, |
+ if (DoesMediaDeviceIDMatchHMAC(sc, security_origin, source_id, |
device_info.device.id)) { |
*device_id = device_info.device.id; |
return true; |
@@ -897,7 +902,7 @@ |
const DeviceRequest* request = labeled_request.second; |
for (const StreamDeviceInfo& device_info : request->devices) { |
const std::string source_id = GetHMACForMediaDeviceID( |
- request->salt, request->security_origin, device.id); |
+ request->salt_callback, request->security_origin, device.id); |
if (device_info.device.id == source_id && |
device_info.device.type == device.type) { |
session_ids.push_back(device_info.session_id); |
@@ -986,19 +991,20 @@ |
// Pick the first valid (translatable) device ID from lists of required |
// and optional IDs. |
-bool MediaStreamManager::PickDeviceId(MediaStreamType type, |
- const std::string& salt, |
- const url::Origin& security_origin, |
- const TrackControls& controls, |
- std::string* device_id) const { |
+bool MediaStreamManager::PickDeviceId( |
+ MediaStreamType type, |
+ const ResourceContext::SaltCallback& salt_callback, |
+ const url::Origin& security_origin, |
+ const TrackControls& controls, |
+ std::string* device_id) const { |
if (!controls.device_ids.empty()) { |
if (controls.device_ids.size() > 1) { |
LOG(ERROR) << "Only one required device ID is supported"; |
return false; |
} |
const std::string& candidate_id = controls.device_ids[0]; |
- if (!TranslateSourceIdToDeviceId(type, salt, security_origin, candidate_id, |
- device_id)) { |
+ if (!TranslateSourceIdToDeviceId(type, salt_callback, security_origin, |
+ candidate_id, device_id)) { |
LOG(WARNING) << "Invalid mandatory capture ID = " << candidate_id; |
return false; |
} |
@@ -1006,8 +1012,8 @@ |
} |
// We don't have a required ID. Look at the alternates. |
for (const std::string& candidate_id : controls.alternate_device_ids) { |
- if (TranslateSourceIdToDeviceId(type, salt, security_origin, candidate_id, |
- device_id)) { |
+ if (TranslateSourceIdToDeviceId(type, salt_callback, security_origin, |
+ candidate_id, device_id)) { |
return true; |
} else { |
LOG(WARNING) << "Invalid optional capture ID = " << candidate_id; |
@@ -1021,11 +1027,13 @@ |
MediaStreamType type, |
std::string* device_id) const { |
if (type == MEDIA_DEVICE_AUDIO_CAPTURE) { |
- return PickDeviceId(type, request->salt, request->security_origin, |
- request->controls.audio, device_id); |
+ return PickDeviceId(type, request->salt_callback, request->security_origin, |
+ request->controls.audio, |
+ device_id); |
} else if (type == MEDIA_DEVICE_VIDEO_CAPTURE) { |
- return PickDeviceId(type, request->salt, request->security_origin, |
- request->controls.video, device_id); |
+ return PickDeviceId(type, request->salt_callback, request->security_origin, |
+ request->controls.video, |
+ device_id); |
} else { |
NOTREACHED(); |
} |
@@ -1038,7 +1046,7 @@ |
if (request->audio_type() == MEDIA_DEVICE_AUDIO_CAPTURE || |
request->audio_type() == MEDIA_DEVICE_AUDIO_OUTPUT || |
request->video_type() == MEDIA_DEVICE_VIDEO_CAPTURE) { |
- device->id = GetHMACForMediaDeviceID(request->salt, |
+ device->id = GetHMACForMediaDeviceID(request->salt_callback, |
request->security_origin, device->id); |
} |
} |
@@ -1380,8 +1388,9 @@ |
DCHECK(existing_device_info); |
DCHECK(existing_request_state); |
- std::string source_id = GetHMACForMediaDeviceID( |
- new_request.salt, new_request.security_origin, new_device_info.id); |
+ std::string source_id = |
+ GetHMACForMediaDeviceID(new_request.salt_callback, |
+ new_request.security_origin, new_device_info.id); |
for (const LabeledDeviceRequest& labeled_request : requests_) { |
const DeviceRequest* request = labeled_request.second; |
@@ -2124,7 +2133,7 @@ |
// static |
std::string MediaStreamManager::GetHMACForMediaDeviceID( |
- const std::string& salt, |
+ const ResourceContext::SaltCallback& sc, |
const url::Origin& security_origin, |
const std::string& raw_unique_id) { |
DCHECK(!raw_unique_id.empty()); |
@@ -2136,6 +2145,7 @@ |
crypto::HMAC hmac(crypto::HMAC::SHA256); |
const size_t digest_length = hmac.DigestLength(); |
std::vector<uint8_t> digest(digest_length); |
+ std::string salt = sc.Run(); |
bool result = hmac.Init(security_origin.Serialize()) && |
hmac.Sign(raw_unique_id + salt, &digest[0], digest.size()); |
DCHECK(result); |
@@ -2144,13 +2154,13 @@ |
// static |
bool MediaStreamManager::DoesMediaDeviceIDMatchHMAC( |
- const std::string& salt, |
+ const ResourceContext::SaltCallback& sc, |
const url::Origin& security_origin, |
const std::string& device_guid, |
const std::string& raw_unique_id) { |
DCHECK(!raw_unique_id.empty()); |
std::string guid_from_raw_device_id = |
- GetHMACForMediaDeviceID(salt, security_origin, raw_unique_id); |
+ GetHMACForMediaDeviceID(sc, security_origin, raw_unique_id); |
return guid_from_raw_device_id == device_guid; |
} |