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 <list> | 7 #include <list> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
13 #include "crypto/encryptor.h" | 13 #include "crypto/encryptor.h" |
14 #include "crypto/symmetric_key.h" | 14 #include "crypto/symmetric_key.h" |
15 #include "media/base/audio_decoder_config.h" | 15 #include "media/base/audio_decoder_config.h" |
16 #include "media/base/cdm_key_information.h" | 16 #include "media/base/cdm_key_information.h" |
17 #include "media/base/cdm_promise.h" | 17 #include "media/base/cdm_promise.h" |
18 #include "media/base/decoder_buffer.h" | 18 #include "media/base/decoder_buffer.h" |
19 #include "media/base/decrypt_config.h" | 19 #include "media/base/decrypt_config.h" |
20 #include "media/base/video_decoder_config.h" | 20 #include "media/base/video_decoder_config.h" |
21 #include "media/base/video_frame.h" | 21 #include "media/base/video_frame.h" |
22 #include "media/cdm/json_web_key.h" | 22 #include "media/cdm/json_web_key.h" |
23 | 23 |
24 #if defined(USE_PROPRIETARY_CODECS) | 24 #if defined(USE_PROPRIETARY_CODECS) |
25 #include "media/cdm/cenc_utils.h" | 25 #include "media/cdm/cenc_utils.h" |
26 #endif | 26 #endif |
27 | 27 |
28 namespace media { | 28 namespace media { |
29 | 29 |
| 30 // SystemID for the Common System. |
| 31 // https://w3c.github.io/encrypted-media/cenc-format.html#common-system |
| 32 const uint8_t kCommonSystemId[] = {0x10, 0x77, 0xef, 0xec, 0xc0, 0xb2, |
| 33 0x4d, 0x02, 0xac, 0xe3, 0x3c, 0x1e, |
| 34 0x52, 0xe2, 0xfb, 0x4b}; |
| 35 |
30 // Keeps track of the session IDs and DecryptionKeys. The keys are ordered by | 36 // Keeps track of the session IDs and DecryptionKeys. The keys are ordered by |
31 // insertion time (last insertion is first). It takes ownership of the | 37 // insertion time (last insertion is first). It takes ownership of the |
32 // DecryptionKeys. | 38 // DecryptionKeys. |
33 class AesDecryptor::SessionIdDecryptionKeyMap { | 39 class AesDecryptor::SessionIdDecryptionKeyMap { |
34 // Use a std::list to actually hold the data. Insertion is always done | 40 // Use a std::list to actually hold the data. Insertion is always done |
35 // at the front, so the "latest" decryption key is always the first one | 41 // at the front, so the "latest" decryption key is always the first one |
36 // in the list. | 42 // in the list. |
37 typedef std::list<std::pair<std::string, DecryptionKey*> > KeyList; | 43 typedef std::list<std::pair<std::string, DecryptionKey*> > KeyList; |
38 | 44 |
39 public: | 45 public: |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 // when prefixed EME is removed (http://crbug.com/249976). | 274 // when prefixed EME is removed (http://crbug.com/249976). |
269 if (!init_data.empty()) { | 275 if (!init_data.empty()) { |
270 std::vector<std::vector<uint8_t>> keys; | 276 std::vector<std::vector<uint8_t>> keys; |
271 switch (init_data_type) { | 277 switch (init_data_type) { |
272 case EmeInitDataType::WEBM: | 278 case EmeInitDataType::WEBM: |
273 // |init_data| is simply the key needed. | 279 // |init_data| is simply the key needed. |
274 keys.push_back(init_data); | 280 keys.push_back(init_data); |
275 break; | 281 break; |
276 case EmeInitDataType::CENC: | 282 case EmeInitDataType::CENC: |
277 #if defined(USE_PROPRIETARY_CODECS) | 283 #if defined(USE_PROPRIETARY_CODECS) |
| 284 { |
278 // |init_data| is a set of 0 or more concatenated 'pssh' boxes. | 285 // |init_data| is a set of 0 or more concatenated 'pssh' boxes. |
279 if (!GetKeyIdsForCommonSystemId(init_data, &keys)) { | 286 std::vector<uint8_t> common_system_id( |
| 287 kCommonSystemId, kCommonSystemId + arraysize(kCommonSystemId)); |
| 288 if (!GetKeyIds(init_data, common_system_id, &keys)) { |
280 promise->reject(NOT_SUPPORTED_ERROR, 0, | 289 promise->reject(NOT_SUPPORTED_ERROR, 0, |
281 "No supported PSSH box found."); | 290 "No supported PSSH box found."); |
282 return; | 291 return; |
283 } | 292 } |
284 break; | 293 } break; |
285 #else | 294 #else |
286 promise->reject(NOT_SUPPORTED_ERROR, 0, | 295 promise->reject(NOT_SUPPORTED_ERROR, 0, |
287 "Initialization data type CENC is not supported."); | 296 "Initialization data type CENC is not supported."); |
288 return; | 297 return; |
289 #endif | 298 #endif |
290 case EmeInitDataType::KEYIDS: { | 299 case EmeInitDataType::KEYIDS: { |
291 std::string init_data_string(init_data.begin(), init_data.end()); | 300 std::string init_data_string(init_data.begin(), init_data.end()); |
292 std::string error_message; | 301 std::string error_message; |
293 if (!ExtractKeyIdsFromKeyIdsInitData(init_data_string, &keys, | 302 if (!ExtractKeyIdsFromKeyIdsInitData(init_data_string, &keys, |
294 &error_message)) { | 303 &error_message)) { |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
604 bool AesDecryptor::DecryptionKey::Init() { | 613 bool AesDecryptor::DecryptionKey::Init() { |
605 CHECK(!secret_.empty()); | 614 CHECK(!secret_.empty()); |
606 decryption_key_.reset(crypto::SymmetricKey::Import( | 615 decryption_key_.reset(crypto::SymmetricKey::Import( |
607 crypto::SymmetricKey::AES, secret_)); | 616 crypto::SymmetricKey::AES, secret_)); |
608 if (!decryption_key_) | 617 if (!decryption_key_) |
609 return false; | 618 return false; |
610 return true; | 619 return true; |
611 } | 620 } |
612 | 621 |
613 } // namespace media | 622 } // namespace media |
OLD | NEW |