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/aes_decryptor.h" | 5 #include "media/cdm/aes_decryptor.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <list> | 8 #include <list> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 DCHECK(!session_keys_change_cb_.is_null()); | 244 DCHECK(!session_keys_change_cb_.is_null()); |
245 } | 245 } |
246 | 246 |
247 AesDecryptor::~AesDecryptor() { | 247 AesDecryptor::~AesDecryptor() { |
248 key_map_.clear(); | 248 key_map_.clear(); |
249 } | 249 } |
250 | 250 |
251 void AesDecryptor::SetServerCertificate( | 251 void AesDecryptor::SetServerCertificate( |
252 const std::vector<uint8_t>& certificate, | 252 const std::vector<uint8_t>& certificate, |
253 std::unique_ptr<SimpleCdmPromise> promise) { | 253 std::unique_ptr<SimpleCdmPromise> promise) { |
254 promise->reject( | 254 promise->reject(CdmPromise::NOT_SUPPORTED_ERROR, 0, |
255 NOT_SUPPORTED_ERROR, 0, "SetServerCertificate() is not supported."); | 255 "SetServerCertificate() is not supported."); |
256 } | 256 } |
257 | 257 |
258 void AesDecryptor::CreateSessionAndGenerateRequest( | 258 void AesDecryptor::CreateSessionAndGenerateRequest( |
259 SessionType session_type, | 259 SessionType session_type, |
260 EmeInitDataType init_data_type, | 260 EmeInitDataType init_data_type, |
261 const std::vector<uint8_t>& init_data, | 261 const std::vector<uint8_t>& init_data, |
262 std::unique_ptr<NewSessionCdmPromise> promise) { | 262 std::unique_ptr<NewSessionCdmPromise> promise) { |
263 std::string session_id(base::UintToString(next_session_id_++)); | 263 std::string session_id(base::UintToString(next_session_id_++)); |
264 valid_sessions_.insert(session_id); | 264 valid_sessions_.insert(session_id); |
265 | 265 |
266 // For now, the AesDecryptor does not care about |session_type|. | 266 // For now, the AesDecryptor does not care about |session_type|. |
267 // TODO(jrummell): Validate |session_type|. | 267 // TODO(jrummell): Validate |session_type|. |
268 | 268 |
269 std::vector<uint8_t> message; | 269 std::vector<uint8_t> message; |
270 std::vector<std::vector<uint8_t>> keys; | 270 std::vector<std::vector<uint8_t>> keys; |
271 switch (init_data_type) { | 271 switch (init_data_type) { |
272 case EmeInitDataType::WEBM: | 272 case EmeInitDataType::WEBM: |
273 // |init_data| is simply the key needed. | 273 // |init_data| is simply the key needed. |
274 if (init_data.size() < limits::kMinKeyIdLength || | 274 if (init_data.size() < limits::kMinKeyIdLength || |
275 init_data.size() > limits::kMaxKeyIdLength) { | 275 init_data.size() > limits::kMaxKeyIdLength) { |
276 promise->reject(NOT_SUPPORTED_ERROR, 0, "Incorrect length"); | 276 promise->reject(CdmPromise::NOT_SUPPORTED_ERROR, 0, "Incorrect length"); |
277 return; | 277 return; |
278 } | 278 } |
279 keys.push_back(init_data); | 279 keys.push_back(init_data); |
280 break; | 280 break; |
281 case EmeInitDataType::CENC: | 281 case EmeInitDataType::CENC: |
282 #if defined(USE_PROPRIETARY_CODECS) | 282 #if defined(USE_PROPRIETARY_CODECS) |
283 // |init_data| is a set of 0 or more concatenated 'pssh' boxes. | 283 // |init_data| is a set of 0 or more concatenated 'pssh' boxes. |
284 if (!GetKeyIdsForCommonSystemId(init_data, &keys)) { | 284 if (!GetKeyIdsForCommonSystemId(init_data, &keys)) { |
285 promise->reject(NOT_SUPPORTED_ERROR, 0, "No supported PSSH box found."); | 285 promise->reject(CdmPromise::NOT_SUPPORTED_ERROR, 0, |
| 286 "No supported PSSH box found."); |
286 return; | 287 return; |
287 } | 288 } |
288 break; | 289 break; |
289 #else | 290 #else |
290 promise->reject(NOT_SUPPORTED_ERROR, 0, | 291 promise->reject(CdmPromise::NOT_SUPPORTED_ERROR, 0, |
291 "Initialization data type CENC is not supported."); | 292 "Initialization data type CENC is not supported."); |
292 return; | 293 return; |
293 #endif | 294 #endif |
294 case EmeInitDataType::KEYIDS: { | 295 case EmeInitDataType::KEYIDS: { |
295 std::string init_data_string(init_data.begin(), init_data.end()); | 296 std::string init_data_string(init_data.begin(), init_data.end()); |
296 std::string error_message; | 297 std::string error_message; |
297 if (!ExtractKeyIdsFromKeyIdsInitData(init_data_string, &keys, | 298 if (!ExtractKeyIdsFromKeyIdsInitData(init_data_string, &keys, |
298 &error_message)) { | 299 &error_message)) { |
299 promise->reject(NOT_SUPPORTED_ERROR, 0, error_message); | 300 promise->reject(CdmPromise::NOT_SUPPORTED_ERROR, 0, error_message); |
300 return; | 301 return; |
301 } | 302 } |
302 break; | 303 break; |
303 } | 304 } |
304 default: | 305 default: |
305 NOTREACHED(); | 306 NOTREACHED(); |
306 promise->reject(NOT_SUPPORTED_ERROR, 0, "init_data_type not supported."); | 307 promise->reject(CdmPromise::NOT_SUPPORTED_ERROR, 0, |
| 308 "init_data_type not supported."); |
307 return; | 309 return; |
308 } | 310 } |
309 CreateLicenseRequest(keys, session_type, &message); | 311 CreateLicenseRequest(keys, session_type, &message); |
310 | 312 |
311 promise->resolve(session_id); | 313 promise->resolve(session_id); |
312 | 314 |
313 session_message_cb_.Run(session_id, LICENSE_REQUEST, message); | 315 session_message_cb_.Run(session_id, LICENSE_REQUEST, message); |
314 } | 316 } |
315 | 317 |
316 void AesDecryptor::LoadSession(SessionType session_type, | 318 void AesDecryptor::LoadSession(SessionType session_type, |
317 const std::string& session_id, | 319 const std::string& session_id, |
318 std::unique_ptr<NewSessionCdmPromise> promise) { | 320 std::unique_ptr<NewSessionCdmPromise> promise) { |
319 // TODO(xhwang): Change this to NOTREACHED() when blink checks for key systems | 321 // TODO(xhwang): Change this to NOTREACHED() when blink checks for key systems |
320 // that do not support loadSession. See http://crbug.com/342481 | 322 // that do not support loadSession. See http://crbug.com/342481 |
321 promise->reject(NOT_SUPPORTED_ERROR, 0, "LoadSession() is not supported."); | 323 promise->reject(CdmPromise::NOT_SUPPORTED_ERROR, 0, |
| 324 "LoadSession() is not supported."); |
322 } | 325 } |
323 | 326 |
324 void AesDecryptor::UpdateSession(const std::string& session_id, | 327 void AesDecryptor::UpdateSession(const std::string& session_id, |
325 const std::vector<uint8_t>& response, | 328 const std::vector<uint8_t>& response, |
326 std::unique_ptr<SimpleCdmPromise> promise) { | 329 std::unique_ptr<SimpleCdmPromise> promise) { |
327 CHECK(!response.empty()); | 330 CHECK(!response.empty()); |
328 | 331 |
329 // TODO(jrummell): Convert back to a DCHECK once prefixed EME is removed. | 332 // TODO(jrummell): Convert back to a DCHECK once prefixed EME is removed. |
330 if (valid_sessions_.find(session_id) == valid_sessions_.end()) { | 333 if (valid_sessions_.find(session_id) == valid_sessions_.end()) { |
331 promise->reject(INVALID_ACCESS_ERROR, 0, "Session does not exist."); | 334 promise->reject(CdmPromise::INVALID_ACCESS_ERROR, 0, |
| 335 "Session does not exist."); |
332 return; | 336 return; |
333 } | 337 } |
334 | 338 |
335 std::string key_string(response.begin(), response.end()); | 339 std::string key_string(response.begin(), response.end()); |
336 | 340 |
337 KeyIdAndKeyPairs keys; | 341 KeyIdAndKeyPairs keys; |
338 SessionType session_type = MediaKeys::TEMPORARY_SESSION; | 342 SessionType session_type = MediaKeys::TEMPORARY_SESSION; |
339 if (!ExtractKeysFromJWKSet(key_string, &keys, &session_type)) { | 343 if (!ExtractKeysFromJWKSet(key_string, &keys, &session_type)) { |
340 promise->reject( | 344 promise->reject(CdmPromise::INVALID_ACCESS_ERROR, 0, |
341 INVALID_ACCESS_ERROR, 0, "Response is not a valid JSON Web Key Set."); | 345 "Response is not a valid JSON Web Key Set."); |
342 return; | 346 return; |
343 } | 347 } |
344 | 348 |
345 // Make sure that at least one key was extracted. | 349 // Make sure that at least one key was extracted. |
346 if (keys.empty()) { | 350 if (keys.empty()) { |
347 promise->reject( | 351 promise->reject(CdmPromise::INVALID_ACCESS_ERROR, 0, |
348 INVALID_ACCESS_ERROR, 0, "Response does not contain any keys."); | 352 "Response does not contain any keys."); |
349 return; | 353 return; |
350 } | 354 } |
351 | 355 |
352 bool key_added = false; | 356 bool key_added = false; |
353 for (KeyIdAndKeyPairs::iterator it = keys.begin(); it != keys.end(); ++it) { | 357 for (KeyIdAndKeyPairs::iterator it = keys.begin(); it != keys.end(); ++it) { |
354 if (it->second.length() != | 358 if (it->second.length() != |
355 static_cast<size_t>(DecryptConfig::kDecryptionKeySize)) { | 359 static_cast<size_t>(DecryptConfig::kDecryptionKeySize)) { |
356 DVLOG(1) << "Invalid key length: " << it->second.length(); | 360 DVLOG(1) << "Invalid key length: " << it->second.length(); |
357 promise->reject(INVALID_ACCESS_ERROR, 0, "Invalid key length."); | 361 promise->reject(CdmPromise::INVALID_ACCESS_ERROR, 0, |
| 362 "Invalid key length."); |
358 return; | 363 return; |
359 } | 364 } |
360 | 365 |
361 // If this key_id doesn't currently exist in this session, | 366 // If this key_id doesn't currently exist in this session, |
362 // a new key is added. | 367 // a new key is added. |
363 if (!HasKey(session_id, it->first)) | 368 if (!HasKey(session_id, it->first)) |
364 key_added = true; | 369 key_added = true; |
365 | 370 |
366 if (!AddDecryptionKey(session_id, it->first, it->second)) { | 371 if (!AddDecryptionKey(session_id, it->first, it->second)) { |
367 promise->reject(INVALID_ACCESS_ERROR, 0, "Unable to add key."); | 372 promise->reject(CdmPromise::INVALID_ACCESS_ERROR, 0, |
| 373 "Unable to add key."); |
368 return; | 374 return; |
369 } | 375 } |
370 } | 376 } |
371 | 377 |
372 { | 378 { |
373 base::AutoLock auto_lock(new_key_cb_lock_); | 379 base::AutoLock auto_lock(new_key_cb_lock_); |
374 | 380 |
375 if (!new_audio_key_cb_.is_null()) | 381 if (!new_audio_key_cb_.is_null()) |
376 new_audio_key_cb_.Run(); | 382 new_audio_key_cb_.Run(); |
377 | 383 |
(...skipping 30 matching lines...) Expand all Loading... |
408 DeleteKeysForSession(session_id); | 414 DeleteKeysForSession(session_id); |
409 promise->resolve(); | 415 promise->resolve(); |
410 | 416 |
411 // Resolve the closed attribute. | 417 // Resolve the closed attribute. |
412 session_closed_cb_.Run(session_id); | 418 session_closed_cb_.Run(session_id); |
413 } | 419 } |
414 | 420 |
415 void AesDecryptor::RemoveSession(const std::string& session_id, | 421 void AesDecryptor::RemoveSession(const std::string& session_id, |
416 std::unique_ptr<SimpleCdmPromise> promise) { | 422 std::unique_ptr<SimpleCdmPromise> promise) { |
417 NOTIMPLEMENTED() << "Need to address https://crbug.com/616166."; | 423 NOTIMPLEMENTED() << "Need to address https://crbug.com/616166."; |
418 promise->reject(INVALID_ACCESS_ERROR, 0, "Session does not exist."); | 424 promise->reject(CdmPromise::INVALID_ACCESS_ERROR, 0, |
| 425 "Session does not exist."); |
419 } | 426 } |
420 | 427 |
421 CdmContext* AesDecryptor::GetCdmContext() { | 428 CdmContext* AesDecryptor::GetCdmContext() { |
422 return this; | 429 return this; |
423 } | 430 } |
424 | 431 |
425 Decryptor* AesDecryptor::GetDecryptor() { | 432 Decryptor* AesDecryptor::GetDecryptor() { |
426 return this; | 433 return this; |
427 } | 434 } |
428 | 435 |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
592 bool AesDecryptor::DecryptionKey::Init() { | 599 bool AesDecryptor::DecryptionKey::Init() { |
593 CHECK(!secret_.empty()); | 600 CHECK(!secret_.empty()); |
594 decryption_key_ = | 601 decryption_key_ = |
595 crypto::SymmetricKey::Import(crypto::SymmetricKey::AES, secret_); | 602 crypto::SymmetricKey::Import(crypto::SymmetricKey::AES, secret_); |
596 if (!decryption_key_) | 603 if (!decryption_key_) |
597 return false; | 604 return false; |
598 return true; | 605 return true; |
599 } | 606 } |
600 | 607 |
601 } // namespace media | 608 } // namespace media |
OLD | NEW |