Chromium Code Reviews| 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 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 261 EmeInitDataType init_data_type, | 261 EmeInitDataType init_data_type, |
| 262 const std::vector<uint8_t>& init_data, | 262 const std::vector<uint8_t>& init_data, |
| 263 std::unique_ptr<NewSessionCdmPromise> promise) { | 263 std::unique_ptr<NewSessionCdmPromise> promise) { |
| 264 std::string session_id(base::UintToString(next_session_id_++)); | 264 std::string session_id(base::UintToString(next_session_id_++)); |
| 265 valid_sessions_.insert(session_id); | 265 valid_sessions_.insert(session_id); |
| 266 | 266 |
| 267 // For now, the AesDecryptor does not care about |session_type|. | 267 // For now, the AesDecryptor does not care about |session_type|. |
| 268 // TODO(jrummell): Validate |session_type|. | 268 // TODO(jrummell): Validate |session_type|. |
| 269 | 269 |
| 270 std::vector<uint8_t> message; | 270 std::vector<uint8_t> message; |
| 271 // TODO(jrummell): Since unprefixed will never send NULL, remove this check | 271 std::vector<std::vector<uint8_t>> keys; |
|
ddorwin
2016/06/23 01:06:47
I think we could have removed this before when we
| |
| 272 // when prefixed EME is removed (http://crbug.com/249976). | 272 switch (init_data_type) { |
| 273 if (!init_data.empty()) { | 273 case EmeInitDataType::WEBM: |
| 274 std::vector<std::vector<uint8_t>> keys; | 274 // |init_data| is simply the key needed. |
| 275 switch (init_data_type) { | 275 keys.push_back(init_data); |
| 276 case EmeInitDataType::WEBM: | 276 break; |
| 277 // |init_data| is simply the key needed. | 277 case EmeInitDataType::CENC: |
| 278 keys.push_back(init_data); | |
| 279 break; | |
| 280 case EmeInitDataType::CENC: | |
| 281 #if defined(USE_PROPRIETARY_CODECS) | 278 #if defined(USE_PROPRIETARY_CODECS) |
| 282 // |init_data| is a set of 0 or more concatenated 'pssh' boxes. | 279 // |init_data| is a set of 0 or more concatenated 'pssh' boxes. |
| 283 if (!GetKeyIdsForCommonSystemId(init_data, &keys)) { | 280 if (!GetKeyIdsForCommonSystemId(init_data, &keys)) { |
| 284 promise->reject(NOT_SUPPORTED_ERROR, 0, | 281 promise->reject(NOT_SUPPORTED_ERROR, 0, "No supported PSSH box found."); |
| 285 "No supported PSSH box found."); | 282 return; |
| 286 return; | 283 } |
| 287 } | 284 break; |
| 288 break; | |
| 289 #else | 285 #else |
| 290 promise->reject(NOT_SUPPORTED_ERROR, 0, | 286 promise->reject(NOT_SUPPORTED_ERROR, 0, |
| 291 "Initialization data type CENC is not supported."); | 287 "Initialization data type CENC is not supported."); |
| 288 return; | |
| 289 #endif | |
| 290 case EmeInitDataType::KEYIDS: { | |
| 291 std::string init_data_string(init_data.begin(), init_data.end()); | |
| 292 std::string error_message; | |
| 293 if (!ExtractKeyIdsFromKeyIdsInitData(init_data_string, &keys, | |
| 294 &error_message)) { | |
| 295 promise->reject(NOT_SUPPORTED_ERROR, 0, error_message); | |
| 292 return; | 296 return; |
| 293 #endif | |
| 294 case EmeInitDataType::KEYIDS: { | |
| 295 std::string init_data_string(init_data.begin(), init_data.end()); | |
| 296 std::string error_message; | |
| 297 if (!ExtractKeyIdsFromKeyIdsInitData(init_data_string, &keys, | |
| 298 &error_message)) { | |
| 299 promise->reject(NOT_SUPPORTED_ERROR, 0, error_message); | |
| 300 return; | |
| 301 } | |
| 302 break; | |
| 303 } | 297 } |
| 304 default: | 298 break; |
| 305 NOTREACHED(); | |
| 306 promise->reject(NOT_SUPPORTED_ERROR, 0, | |
| 307 "init_data_type not supported."); | |
| 308 return; | |
| 309 } | 299 } |
| 310 CreateLicenseRequest(keys, session_type, &message); | 300 default: |
| 301 NOTREACHED(); | |
| 302 promise->reject(NOT_SUPPORTED_ERROR, 0, "init_data_type not supported."); | |
| 303 return; | |
| 311 } | 304 } |
| 305 CreateLicenseRequest(keys, session_type, &message); | |
| 312 | 306 |
| 313 promise->resolve(session_id); | 307 promise->resolve(session_id); |
| 314 | 308 |
| 315 // No URL needed for license requests. | 309 // No URL needed for license requests. |
| 316 GURL empty_gurl; | 310 GURL empty_gurl; |
| 317 session_message_cb_.Run(session_id, LICENSE_REQUEST, message, empty_gurl); | 311 session_message_cb_.Run(session_id, LICENSE_REQUEST, message, empty_gurl); |
| 318 } | 312 } |
| 319 | 313 |
| 320 void AesDecryptor::LoadSession(SessionType session_type, | 314 void AesDecryptor::LoadSession(SessionType session_type, |
| 321 const std::string& session_id, | 315 const std::string& session_id, |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 409 valid_sessions_.erase(it); | 403 valid_sessions_.erase(it); |
| 410 | 404 |
| 411 // Close the session. | 405 // Close the session. |
| 412 DeleteKeysForSession(session_id); | 406 DeleteKeysForSession(session_id); |
| 413 promise->resolve(); | 407 promise->resolve(); |
| 414 session_closed_cb_.Run(session_id); | 408 session_closed_cb_.Run(session_id); |
| 415 } | 409 } |
| 416 | 410 |
| 417 void AesDecryptor::RemoveSession(const std::string& session_id, | 411 void AesDecryptor::RemoveSession(const std::string& session_id, |
| 418 std::unique_ptr<SimpleCdmPromise> promise) { | 412 std::unique_ptr<SimpleCdmPromise> promise) { |
| 419 // AesDecryptor doesn't keep any persistent data, so this should be | 413 NOTREACHED() << "AesDecryptor doesn't support persistent sessions."; |
| 420 // NOT_REACHED(). | |
| 421 // TODO(jrummell): Make sure persistent session types are rejected. | |
| 422 // http://crbug.com/384152. | |
| 423 // | |
| 424 // However, v0.1b calls to CancelKeyRequest() will call this, so close the | |
| 425 // session, if it exists. | |
| 426 // TODO(jrummell): Remove the close() call when prefixed EME is removed. | |
| 427 // http://crbug.com/249976. | |
| 428 if (valid_sessions_.find(session_id) != valid_sessions_.end()) { | |
| 429 CloseSession(session_id, std::move(promise)); | |
| 430 return; | |
| 431 } | |
| 432 | |
| 433 promise->reject(INVALID_ACCESS_ERROR, 0, "Session does not exist."); | 414 promise->reject(INVALID_ACCESS_ERROR, 0, "Session does not exist."); |
| 434 } | 415 } |
| 435 | 416 |
| 436 CdmContext* AesDecryptor::GetCdmContext() { | 417 CdmContext* AesDecryptor::GetCdmContext() { |
| 437 return this; | 418 return this; |
| 438 } | 419 } |
| 439 | 420 |
| 440 Decryptor* AesDecryptor::GetDecryptor() { | 421 Decryptor* AesDecryptor::GetDecryptor() { |
| 441 return this; | 422 return this; |
| 442 } | 423 } |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 608 bool AesDecryptor::DecryptionKey::Init() { | 589 bool AesDecryptor::DecryptionKey::Init() { |
| 609 CHECK(!secret_.empty()); | 590 CHECK(!secret_.empty()); |
| 610 decryption_key_.reset(crypto::SymmetricKey::Import( | 591 decryption_key_.reset(crypto::SymmetricKey::Import( |
| 611 crypto::SymmetricKey::AES, secret_)); | 592 crypto::SymmetricKey::AES, secret_)); |
| 612 if (!decryption_key_) | 593 if (!decryption_key_) |
| 613 return false; | 594 return false; |
| 614 return true; | 595 return true; |
| 615 } | 596 } |
| 616 | 597 |
| 617 } // namespace media | 598 } // namespace media |
| OLD | NEW |