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

Side by Side Diff: media/cdm/ppapi/external_clear_key/clear_key_cdm.cc

Issue 2582463003: media: Verify CDM Host files (Closed)
Patch Set: Polished! Created 3 years, 11 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 4
5 #include "media/cdm/ppapi/external_clear_key/clear_key_cdm.h" 5 #include "media/cdm/ppapi/external_clear_key/clear_key_cdm.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cstring> 8 #include <cstring>
9 #include <sstream> 9 #include <sstream>
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/files/file.h"
13 #include "base/logging.h" 14 #include "base/logging.h"
14 #include "base/macros.h" 15 #include "base/macros.h"
15 #include "base/time/time.h" 16 #include "base/time/time.h"
16 #include "base/trace_event/trace_event.h" 17 #include "base/trace_event/trace_event.h"
17 #include "media/base/cdm_callback_promise.h" 18 #include "media/base/cdm_callback_promise.h"
18 #include "media/base/cdm_key_information.h" 19 #include "media/base/cdm_key_information.h"
19 #include "media/base/decoder_buffer.h" 20 #include "media/base/decoder_buffer.h"
20 #include "media/base/decrypt_config.h" 21 #include "media/base/decrypt_config.h"
22 #include "media/cdm/api/content_decryption_module_ext.h"
21 #include "media/cdm/json_web_key.h" 23 #include "media/cdm/json_web_key.h"
22 #include "media/cdm/ppapi/cdm_file_io_test.h" 24 #include "media/cdm/ppapi/cdm_file_io_test.h"
23 #include "media/cdm/ppapi/external_clear_key/cdm_video_decoder.h" 25 #include "media/cdm/ppapi/external_clear_key/cdm_video_decoder.h"
24 #include "url/gurl.h" 26 #include "url/gurl.h"
25 27
26 #if defined(CLEAR_KEY_CDM_USE_FAKE_AUDIO_DECODER) 28 #if defined(CLEAR_KEY_CDM_USE_FAKE_AUDIO_DECODER)
27 const int64_t kNoTimestamp = INT64_MIN; 29 const int64_t kNoTimestamp = INT64_MIN;
28 #endif // CLEAR_KEY_CDM_USE_FAKE_AUDIO_DECODER 30 #endif // CLEAR_KEY_CDM_USE_FAKE_AUDIO_DECODER
29 31
30 #if defined(CLEAR_KEY_CDM_USE_FFMPEG_DECODER) 32 #if defined(CLEAR_KEY_CDM_USE_FFMPEG_DECODER)
(...skipping 26 matching lines...) Expand all
57 const char kExternalClearKeyRenewalKeySystem[] = 59 const char kExternalClearKeyRenewalKeySystem[] =
58 "org.chromium.externalclearkey.renewal"; 60 "org.chromium.externalclearkey.renewal";
59 const char kExternalClearKeyFileIOTestKeySystem[] = 61 const char kExternalClearKeyFileIOTestKeySystem[] =
60 "org.chromium.externalclearkey.fileiotest"; 62 "org.chromium.externalclearkey.fileiotest";
61 const char kExternalClearKeyOutputProtectionTestKeySystem[] = 63 const char kExternalClearKeyOutputProtectionTestKeySystem[] =
62 "org.chromium.externalclearkey.outputprotectiontest"; 64 "org.chromium.externalclearkey.outputprotectiontest";
63 const char kExternalClearKeyPlatformVerificationTestKeySystem[] = 65 const char kExternalClearKeyPlatformVerificationTestKeySystem[] =
64 "org.chromium.externalclearkey.platformverificationtest"; 66 "org.chromium.externalclearkey.platformverificationtest";
65 const char kExternalClearKeyCrashKeySystem[] = 67 const char kExternalClearKeyCrashKeySystem[] =
66 "org.chromium.externalclearkey.crash"; 68 "org.chromium.externalclearkey.crash";
69 const char kExternalClearKeyVerifyHostFilesTestKeySystem[] =
70 "org.chromium.externalclearkey.verifyhostfilestest";
67 71
68 // Constants for the enumalted session that can be loaded by LoadSession(). 72 // Constants for the enumalted session that can be loaded by LoadSession().
69 // These constants need to be in sync with 73 // These constants need to be in sync with
70 // chrome/test/data/media/encrypted_media_utils.js 74 // chrome/test/data/media/encrypted_media_utils.js
71 const char kLoadableSessionId[] = "LoadableSession"; 75 const char kLoadableSessionId[] = "LoadableSession";
72 const uint8_t kLoadableSessionKeyId[] = "0123456789012345"; 76 const uint8_t kLoadableSessionKeyId[] = "0123456789012345";
73 const uint8_t kLoadableSessionKey[] = {0xeb, 0xdd, 0x62, 0xf1, 0x68, 0x14, 77 const uint8_t kLoadableSessionKey[] = {0xeb, 0xdd, 0x62, 0xf1, 0x68, 0x14,
74 0xd2, 0x7b, 0x68, 0xef, 0x12, 0x2a, 78 0xd2, 0x7b, 0x68, 0xef, 0x12, 0x2a,
75 0xfc, 0xe4, 0xae, 0x3c}; 79 0xfc, 0xe4, 0xae, 0x3c};
76 80
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 void* user_data) { 231 void* user_data) {
228 DVLOG(1) << "CreateCdmInstance()"; 232 DVLOG(1) << "CreateCdmInstance()";
229 233
230 std::string key_system_string(key_system, key_system_size); 234 std::string key_system_string(key_system, key_system_size);
231 if (key_system_string != kExternalClearKeyKeySystem && 235 if (key_system_string != kExternalClearKeyKeySystem &&
232 key_system_string != kExternalClearKeyDecryptOnlyKeySystem && 236 key_system_string != kExternalClearKeyDecryptOnlyKeySystem &&
233 key_system_string != kExternalClearKeyRenewalKeySystem && 237 key_system_string != kExternalClearKeyRenewalKeySystem &&
234 key_system_string != kExternalClearKeyFileIOTestKeySystem && 238 key_system_string != kExternalClearKeyFileIOTestKeySystem &&
235 key_system_string != kExternalClearKeyOutputProtectionTestKeySystem && 239 key_system_string != kExternalClearKeyOutputProtectionTestKeySystem &&
236 key_system_string != kExternalClearKeyPlatformVerificationTestKeySystem && 240 key_system_string != kExternalClearKeyPlatformVerificationTestKeySystem &&
237 key_system_string != kExternalClearKeyCrashKeySystem) { 241 key_system_string != kExternalClearKeyCrashKeySystem &&
242 key_system_string != kExternalClearKeyVerifyHostFilesTestKeySystem) {
238 DVLOG(1) << "Unsupported key system:" << key_system_string; 243 DVLOG(1) << "Unsupported key system:" << key_system_string;
239 return NULL; 244 return NULL;
240 } 245 }
241 246
242 if (cdm_interface_version != media::ClearKeyCdmInterface::kVersion) 247 if (cdm_interface_version != media::ClearKeyCdmInterface::kVersion)
243 return NULL; 248 return NULL;
244 249
245 media::ClearKeyCdmHost* host = static_cast<media::ClearKeyCdmHost*>( 250 media::ClearKeyCdmHost* host = static_cast<media::ClearKeyCdmHost*>(
246 get_cdm_host_func(media::ClearKeyCdmHost::kVersion, user_data)); 251 get_cdm_host_func(media::ClearKeyCdmHost::kVersion, user_data));
247 if (!host) 252 if (!host)
248 return NULL; 253 return NULL;
249 254
250 // TODO(jrummell): Obtain the proper origin for this instance. 255 // TODO(jrummell): Obtain the proper origin for this instance.
251 GURL empty_origin; 256 GURL empty_origin;
252 return new media::ClearKeyCdm(host, key_system_string, empty_origin); 257 return new media::ClearKeyCdm(host, key_system_string, empty_origin);
253 } 258 }
254 259
255 const char* GetCdmVersion() { 260 const char* GetCdmVersion() {
256 return kClearKeyCdmVersion; 261 return kClearKeyCdmVersion;
257 } 262 }
258 263
264 static bool g_verify_host_files_result = false;
265
266 // Makes sure files and corresponding signature files are readable but not
267 // writable.
268 void VerifyHostFiles(const cdm::HostFile* host_files, uint32_t num_files) {
269 DVLOG(1) << __func__;
270
271 // We should always have the CDM and CDM adapter.
272 // We might not have any common CDM host file (e.g. chrome) since we are
273 // running in browser_tests.
274 if (num_files < 2) {
275 LOG(ERROR) << "Too few host files: " << num_files;
276 g_verify_host_files_result = false;
277 return;
278 }
279
280 for (uint32_t i = 0; i < num_files; ++i) {
281 const int kBytesToRead = 10;
282 std::vector<char> buffer(kBytesToRead);
283
284 base::File file(static_cast<base::PlatformFile>(host_files[i].file));
285 int bytes_read = file.Read(0, buffer.data(), buffer.size());
286 if (bytes_read != kBytesToRead) {
287 LOG(ERROR) << "File bytes read: " << bytes_read;
288 g_verify_host_files_result = false;
289 return;
290 }
291
292 const char kDataToWrite[] = "Data to write into file.";
293 int bytes_written = file.Write(0, kDataToWrite, 1);
Greg K 2017/01/19 04:13:07 Isn't it extremely dangerous to check that a file
xhwang 2017/01/19 08:30:51 Good point. At least on Linux, we should be able t
Greg K 2017/01/25 06:15:32 Yeah please make that a TODO, I'm not comfortable
xhwang 2017/01/25 06:51:54 Thanks for the review!!! A TODO is already added
294 if (bytes_written != -1) {
295 LOG(ERROR) << "File is writable (" << bytes_written << " bytes written).";
296 g_verify_host_files_result = false;
297 return;
298 }
299
300 // TODO(xhwang): Also verify the signature file when it's available.
301 }
302
303 g_verify_host_files_result = true;
304 }
305
259 namespace media { 306 namespace media {
260 307
261 ClearKeyCdm::ClearKeyCdm(ClearKeyCdmHost* host, 308 ClearKeyCdm::ClearKeyCdm(ClearKeyCdmHost* host,
262 const std::string& key_system, 309 const std::string& key_system,
263 const GURL& origin) 310 const GURL& origin)
264 : decryptor_(new AesDecryptor( 311 : decryptor_(new AesDecryptor(
265 origin, 312 origin,
266 base::Bind(&ClearKeyCdm::OnSessionMessage, base::Unretained(this)), 313 base::Bind(&ClearKeyCdm::OnSessionMessage, base::Unretained(this)),
267 base::Bind(&ClearKeyCdm::OnSessionClosed, base::Unretained(this)), 314 base::Bind(&ClearKeyCdm::OnSessionClosed, base::Unretained(this)),
268 base::Bind(&ClearKeyCdm::OnSessionKeysChange, 315 base::Bind(&ClearKeyCdm::OnSessionKeysChange,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 std::vector<uint8_t>(init_data, init_data + init_data_size), 357 std::vector<uint8_t>(init_data, init_data + init_data_size),
311 std::move(promise)); 358 std::move(promise));
312 359
313 if (key_system_ == kExternalClearKeyFileIOTestKeySystem) { 360 if (key_system_ == kExternalClearKeyFileIOTestKeySystem) {
314 StartFileIOTest(); 361 StartFileIOTest();
315 } else if (key_system_ == kExternalClearKeyOutputProtectionTestKeySystem) { 362 } else if (key_system_ == kExternalClearKeyOutputProtectionTestKeySystem) {
316 StartOutputProtectionTest(); 363 StartOutputProtectionTest();
317 } else if (key_system_ == 364 } else if (key_system_ ==
318 kExternalClearKeyPlatformVerificationTestKeySystem) { 365 kExternalClearKeyPlatformVerificationTestKeySystem) {
319 StartPlatformVerificationTest(); 366 StartPlatformVerificationTest();
367 } else if (key_system_ == kExternalClearKeyVerifyHostFilesTestKeySystem) {
368 VerifyHostFilesTest();
320 } 369 }
321 } 370 }
322 371
323 // Loads a emulated stored session. Currently only |kLoadableSessionId| 372 // Loads a emulated stored session. Currently only |kLoadableSessionId|
324 // (containing a |kLoadableSessionKey| for |kLoadableSessionKeyId|) is 373 // (containing a |kLoadableSessionKey| for |kLoadableSessionKeyId|) is
325 // supported. 374 // supported.
326 void ClearKeyCdm::LoadSession(uint32_t promise_id, 375 void ClearKeyCdm::LoadSession(uint32_t promise_id,
327 cdm::SessionType session_type, 376 cdm::SessionType session_type,
328 const char* session_id, 377 const char* session_id,
329 uint32_t session_id_length) { 378 uint32_t session_id_length) {
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after
975 DVLOG(1) << __func__; 1024 DVLOG(1) << __func__;
976 is_running_platform_verification_test_ = true; 1025 is_running_platform_verification_test_ = true;
977 1026
978 std::string service_id = "test_service_id"; 1027 std::string service_id = "test_service_id";
979 std::string challenge = "test_challenge"; 1028 std::string challenge = "test_challenge";
980 1029
981 host_->SendPlatformChallenge(service_id.data(), service_id.size(), 1030 host_->SendPlatformChallenge(service_id.data(), service_id.size(),
982 challenge.data(), challenge.size()); 1031 challenge.data(), challenge.size());
983 } 1032 }
984 1033
1034 void ClearKeyCdm::VerifyHostFilesTest() {
1035 // VerifyHostFiles() should have already been called and test result stored
1036 // in |g_verify_host_files_result|.
1037 OnUnitTestComplete(g_verify_host_files_result);
1038 }
1039
985 } // namespace media 1040 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698