OLD | NEW |
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 Loading... |
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 kExternalClearKeyVerifyCdmHostTestKeySystem[] = |
| 70 "org.chromium.externalclearkey.verifycdmhosttest"; |
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 Loading... |
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 != kExternalClearKeyVerifyCdmHostTestKeySystem) { |
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 bool VerifyCdmHost_0(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 true; |
| 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 true; |
| 290 } |
| 291 |
| 292 // TODO(xhwang): Check that the files are not writable. |
| 293 // TODO(xhwang): Also verify the signature file when it's available. |
| 294 } |
| 295 |
| 296 g_verify_host_files_result = true; |
| 297 return true; |
| 298 } |
| 299 |
259 namespace media { | 300 namespace media { |
260 | 301 |
261 ClearKeyCdm::ClearKeyCdm(ClearKeyCdmHost* host, | 302 ClearKeyCdm::ClearKeyCdm(ClearKeyCdmHost* host, |
262 const std::string& key_system, | 303 const std::string& key_system, |
263 const GURL& origin) | 304 const GURL& origin) |
264 : decryptor_(new AesDecryptor( | 305 : decryptor_(new AesDecryptor( |
265 origin, | 306 origin, |
266 base::Bind(&ClearKeyCdm::OnSessionMessage, base::Unretained(this)), | 307 base::Bind(&ClearKeyCdm::OnSessionMessage, base::Unretained(this)), |
267 base::Bind(&ClearKeyCdm::OnSessionClosed, base::Unretained(this)), | 308 base::Bind(&ClearKeyCdm::OnSessionClosed, base::Unretained(this)), |
268 base::Bind(&ClearKeyCdm::OnSessionKeysChange, | 309 base::Bind(&ClearKeyCdm::OnSessionKeysChange, |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 std::vector<uint8_t>(init_data, init_data + init_data_size), | 351 std::vector<uint8_t>(init_data, init_data + init_data_size), |
311 std::move(promise)); | 352 std::move(promise)); |
312 | 353 |
313 if (key_system_ == kExternalClearKeyFileIOTestKeySystem) { | 354 if (key_system_ == kExternalClearKeyFileIOTestKeySystem) { |
314 StartFileIOTest(); | 355 StartFileIOTest(); |
315 } else if (key_system_ == kExternalClearKeyOutputProtectionTestKeySystem) { | 356 } else if (key_system_ == kExternalClearKeyOutputProtectionTestKeySystem) { |
316 StartOutputProtectionTest(); | 357 StartOutputProtectionTest(); |
317 } else if (key_system_ == | 358 } else if (key_system_ == |
318 kExternalClearKeyPlatformVerificationTestKeySystem) { | 359 kExternalClearKeyPlatformVerificationTestKeySystem) { |
319 StartPlatformVerificationTest(); | 360 StartPlatformVerificationTest(); |
| 361 } else if (key_system_ == kExternalClearKeyVerifyCdmHostTestKeySystem) { |
| 362 VerifyCdmHostTest(); |
320 } | 363 } |
321 } | 364 } |
322 | 365 |
323 // Loads a emulated stored session. Currently only |kLoadableSessionId| | 366 // Loads a emulated stored session. Currently only |kLoadableSessionId| |
324 // (containing a |kLoadableSessionKey| for |kLoadableSessionKeyId|) is | 367 // (containing a |kLoadableSessionKey| for |kLoadableSessionKeyId|) is |
325 // supported. | 368 // supported. |
326 void ClearKeyCdm::LoadSession(uint32_t promise_id, | 369 void ClearKeyCdm::LoadSession(uint32_t promise_id, |
327 cdm::SessionType session_type, | 370 cdm::SessionType session_type, |
328 const char* session_id, | 371 const char* session_id, |
329 uint32_t session_id_length) { | 372 uint32_t session_id_length) { |
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
975 DVLOG(1) << __func__; | 1018 DVLOG(1) << __func__; |
976 is_running_platform_verification_test_ = true; | 1019 is_running_platform_verification_test_ = true; |
977 | 1020 |
978 std::string service_id = "test_service_id"; | 1021 std::string service_id = "test_service_id"; |
979 std::string challenge = "test_challenge"; | 1022 std::string challenge = "test_challenge"; |
980 | 1023 |
981 host_->SendPlatformChallenge(service_id.data(), service_id.size(), | 1024 host_->SendPlatformChallenge(service_id.data(), service_id.size(), |
982 challenge.data(), challenge.size()); | 1025 challenge.data(), challenge.size()); |
983 } | 1026 } |
984 | 1027 |
| 1028 void ClearKeyCdm::VerifyCdmHostTest() { |
| 1029 // VerifyCdmHost() should have already been called and test result stored |
| 1030 // in |g_verify_host_files_result|. |
| 1031 OnUnitTestComplete(g_verify_host_files_result); |
| 1032 } |
| 1033 |
985 } // namespace media | 1034 } // namespace media |
OLD | NEW |