OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/crypto/aes_decryptor.h" | 5 #include "media/crypto/aes_decryptor.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
10 #include "base/string_piece.h" | 10 #include "base/string_piece.h" |
11 #include "crypto/encryptor.h" | 11 #include "crypto/encryptor.h" |
12 #include "crypto/symmetric_key.h" | 12 #include "crypto/symmetric_key.h" |
13 #include "media/base/decoder_buffer.h" | 13 #include "media/base/decoder_buffer.h" |
14 #include "media/base/decrypt_config.h" | 14 #include "media/base/decrypt_config.h" |
15 #include "media/crypto/decryptor_client.h" | 15 #include "media/base/decryptor_client.h" |
16 | 16 |
17 namespace media { | 17 namespace media { |
18 | 18 |
19 // TODO(xhwang): Get real IV from frames. | 19 // TODO(xhwang): Get real IV from frames. |
20 static const char kInitialCounter[] = "0000000000000000"; | 20 static const char kInitialCounter[] = "0000000000000000"; |
21 | 21 |
22 uint32 AesDecryptor::next_session_id_ = 1; | 22 uint32 AesDecryptor::next_session_id_ = 1; |
23 | 23 |
24 // Decrypt |input| using |key|. | 24 // Decrypt |input| using |key|. |
25 // Return a DecoderBuffer with the decrypted data if decryption succeeded. | 25 // Return a DecoderBuffer with the decrypted data if decryption succeeded. |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 const std::string& session_id) { | 82 const std::string& session_id) { |
83 CHECK(key); | 83 CHECK(key); |
84 CHECK_GT(key_length, 0); | 84 CHECK_GT(key_length, 0); |
85 | 85 |
86 // TODO(xhwang): Add |session_id| check after we figure out how: | 86 // TODO(xhwang): Add |session_id| check after we figure out how: |
87 // https://www.w3.org/Bugs/Public/show_bug.cgi?id=16550 | 87 // https://www.w3.org/Bugs/Public/show_bug.cgi?id=16550 |
88 | 88 |
89 const int kSupportedKeyLength = 16; // 128-bit key. | 89 const int kSupportedKeyLength = 16; // 128-bit key. |
90 if (key_length != kSupportedKeyLength) { | 90 if (key_length != kSupportedKeyLength) { |
91 DVLOG(1) << "Invalid key length: " << key_length; | 91 DVLOG(1) << "Invalid key length: " << key_length; |
92 client_->KeyError(key_system, session_id, kUnknownError, 0); | 92 client_->KeyError(key_system, session_id, Decryptor::kUnknownError, 0); |
93 return; | 93 return; |
94 } | 94 } |
95 | 95 |
96 // TODO(xhwang): Fix the decryptor to accept no |init_data|. See | 96 // TODO(xhwang): Fix the decryptor to accept no |init_data|. See |
97 // http://crbug.com/123265. Until then, ensure a non-empty value is passed. | 97 // http://crbug.com/123265. Until then, ensure a non-empty value is passed. |
98 static const uint8 kDummyInitData[1] = { 0 }; | 98 static const uint8 kDummyInitData[1] = { 0 }; |
99 if (!init_data) { | 99 if (!init_data) { |
100 init_data = kDummyInitData; | 100 init_data = kDummyInitData; |
101 init_data_length = arraysize(kDummyInitData); | 101 init_data_length = arraysize(kDummyInitData); |
102 } | 102 } |
103 | 103 |
104 // TODO(xhwang): For now, use |init_data| for key ID. Make this more spec | 104 // TODO(xhwang): For now, use |init_data| for key ID. Make this more spec |
105 // compliant later (http://crbug.com/123262, http://crbug.com/123265). | 105 // compliant later (http://crbug.com/123262, http://crbug.com/123265). |
106 std::string key_id_string(reinterpret_cast<const char*>(init_data), | 106 std::string key_id_string(reinterpret_cast<const char*>(init_data), |
107 init_data_length); | 107 init_data_length); |
108 std::string key_string(reinterpret_cast<const char*>(key) , key_length); | 108 std::string key_string(reinterpret_cast<const char*>(key) , key_length); |
109 crypto::SymmetricKey* symmetric_key = crypto::SymmetricKey::Import( | 109 crypto::SymmetricKey* symmetric_key = crypto::SymmetricKey::Import( |
110 crypto::SymmetricKey::AES, key_string); | 110 crypto::SymmetricKey::AES, key_string); |
111 if (!symmetric_key) { | 111 if (!symmetric_key) { |
112 DVLOG(1) << "Could not import key."; | 112 DVLOG(1) << "Could not import key."; |
113 client_->KeyError(key_system, session_id, kUnknownError, 0); | 113 client_->KeyError(key_system, session_id, Decryptor::kUnknownError, 0); |
114 return; | 114 return; |
115 } | 115 } |
116 | 116 |
117 { | 117 { |
118 base::AutoLock auto_lock(key_map_lock_); | 118 base::AutoLock auto_lock(key_map_lock_); |
119 KeyMap::iterator found = key_map_.find(key_id_string); | 119 KeyMap::iterator found = key_map_.find(key_id_string); |
120 if (found != key_map_.end()) { | 120 if (found != key_map_.end()) { |
121 delete found->second; | 121 delete found->second; |
122 key_map_.erase(found); | 122 key_map_.erase(found); |
123 } | 123 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 | 155 |
156 if (decrypted) { | 156 if (decrypted) { |
157 decrypted->SetTimestamp(encrypted->GetTimestamp()); | 157 decrypted->SetTimestamp(encrypted->GetTimestamp()); |
158 decrypted->SetDuration(encrypted->GetDuration()); | 158 decrypted->SetDuration(encrypted->GetDuration()); |
159 } | 159 } |
160 | 160 |
161 return decrypted; | 161 return decrypted; |
162 } | 162 } |
163 | 163 |
164 } // namespace media | 164 } // namespace media |
OLD | NEW |