| 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 <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 : key_added_cb_(key_added_cb), | 131 : key_added_cb_(key_added_cb), |
| 132 key_error_cb_(key_error_cb), | 132 key_error_cb_(key_error_cb), |
| 133 key_message_cb_(key_message_cb), | 133 key_message_cb_(key_message_cb), |
| 134 need_key_cb_(need_key_cb) { | 134 need_key_cb_(need_key_cb) { |
| 135 } | 135 } |
| 136 | 136 |
| 137 AesDecryptor::~AesDecryptor() { | 137 AesDecryptor::~AesDecryptor() { |
| 138 STLDeleteValues(&key_map_); | 138 STLDeleteValues(&key_map_); |
| 139 } | 139 } |
| 140 | 140 |
| 141 bool AesDecryptor::GenerateKeyRequest(const std::string& key_system, | 141 bool AesDecryptor::GenerateKeyRequest(const std::string& type, |
| 142 const std::string& type, | |
| 143 const uint8* init_data, | 142 const uint8* init_data, |
| 144 int init_data_length) { | 143 int init_data_length) { |
| 145 std::string session_id_string(base::UintToString(next_session_id_++)); | 144 std::string session_id_string(base::UintToString(next_session_id_++)); |
| 146 | 145 |
| 147 // For now, the AesDecryptor does not care about |key_system| and |type|; | 146 // For now, the AesDecryptor does not care about |type|; |
| 148 // just fire the event with the |init_data| as the request. | 147 // just fire the event with the |init_data| as the request. |
| 149 std::string message; | 148 std::string message; |
| 150 if (init_data && init_data_length) { | 149 if (init_data && init_data_length) { |
| 151 message = std::string(reinterpret_cast<const char*>(init_data), | 150 message = std::string(reinterpret_cast<const char*>(init_data), |
| 152 init_data_length); | 151 init_data_length); |
| 153 } | 152 } |
| 154 | 153 |
| 155 key_message_cb_.Run(key_system, session_id_string, message, std::string()); | 154 key_message_cb_.Run(session_id_string, message, std::string()); |
| 156 return true; | 155 return true; |
| 157 } | 156 } |
| 158 | 157 |
| 159 void AesDecryptor::AddKey(const std::string& key_system, | 158 void AesDecryptor::AddKey(const uint8* key, |
| 160 const uint8* key, | |
| 161 int key_length, | 159 int key_length, |
| 162 const uint8* init_data, | 160 const uint8* init_data, |
| 163 int init_data_length, | 161 int init_data_length, |
| 164 const std::string& session_id) { | 162 const std::string& session_id) { |
| 165 CHECK(key); | 163 CHECK(key); |
| 166 CHECK_GT(key_length, 0); | 164 CHECK_GT(key_length, 0); |
| 167 | 165 |
| 168 // TODO(xhwang): Add |session_id| check after we figure out how: | 166 // TODO(xhwang): Add |session_id| check after we figure out how: |
| 169 // https://www.w3.org/Bugs/Public/show_bug.cgi?id=16550 | 167 // https://www.w3.org/Bugs/Public/show_bug.cgi?id=16550 |
| 170 if (key_length != DecryptConfig::kDecryptionKeySize) { | 168 if (key_length != DecryptConfig::kDecryptionKeySize) { |
| 171 DVLOG(1) << "Invalid key length: " << key_length; | 169 DVLOG(1) << "Invalid key length: " << key_length; |
| 172 key_error_cb_.Run(key_system, session_id, MediaKeys::kUnknownError, 0); | 170 key_error_cb_.Run(session_id, MediaKeys::kUnknownError, 0); |
| 173 return; | 171 return; |
| 174 } | 172 } |
| 175 | 173 |
| 176 // TODO(xhwang): Fix the decryptor to accept no |init_data|. See | 174 // TODO(xhwang): Fix the decryptor to accept no |init_data|. See |
| 177 // http://crbug.com/123265. Until then, ensure a non-empty value is passed. | 175 // http://crbug.com/123265. Until then, ensure a non-empty value is passed. |
| 178 static const uint8 kDummyInitData[1] = { 0 }; | 176 static const uint8 kDummyInitData[1] = { 0 }; |
| 179 if (!init_data) { | 177 if (!init_data) { |
| 180 init_data = kDummyInitData; | 178 init_data = kDummyInitData; |
| 181 init_data_length = arraysize(kDummyInitData); | 179 init_data_length = arraysize(kDummyInitData); |
| 182 } | 180 } |
| 183 | 181 |
| 184 // TODO(xhwang): For now, use |init_data| for key ID. Make this more spec | 182 // TODO(xhwang): For now, use |init_data| for key ID. Make this more spec |
| 185 // compliant later (http://crbug.com/123262, http://crbug.com/123265). | 183 // compliant later (http://crbug.com/123262, http://crbug.com/123265). |
| 186 std::string key_id_string(reinterpret_cast<const char*>(init_data), | 184 std::string key_id_string(reinterpret_cast<const char*>(init_data), |
| 187 init_data_length); | 185 init_data_length); |
| 188 std::string key_string(reinterpret_cast<const char*>(key) , key_length); | 186 std::string key_string(reinterpret_cast<const char*>(key) , key_length); |
| 189 scoped_ptr<DecryptionKey> decryption_key(new DecryptionKey(key_string)); | 187 scoped_ptr<DecryptionKey> decryption_key(new DecryptionKey(key_string)); |
| 190 if (!decryption_key) { | 188 if (!decryption_key) { |
| 191 DVLOG(1) << "Could not create key."; | 189 DVLOG(1) << "Could not create key."; |
| 192 key_error_cb_.Run(key_system, session_id, MediaKeys::kUnknownError, 0); | 190 key_error_cb_.Run(session_id, MediaKeys::kUnknownError, 0); |
| 193 return; | 191 return; |
| 194 } | 192 } |
| 195 | 193 |
| 196 if (!decryption_key->Init()) { | 194 if (!decryption_key->Init()) { |
| 197 DVLOG(1) << "Could not initialize decryption key."; | 195 DVLOG(1) << "Could not initialize decryption key."; |
| 198 key_error_cb_.Run(key_system, session_id, MediaKeys::kUnknownError, 0); | 196 key_error_cb_.Run(session_id, MediaKeys::kUnknownError, 0); |
| 199 return; | 197 return; |
| 200 } | 198 } |
| 201 | 199 |
| 202 SetKey(key_id_string, decryption_key.Pass()); | 200 SetKey(key_id_string, decryption_key.Pass()); |
| 203 | 201 |
| 204 if (!new_audio_key_cb_.is_null()) | 202 if (!new_audio_key_cb_.is_null()) |
| 205 new_audio_key_cb_.Run(); | 203 new_audio_key_cb_.Run(); |
| 206 | 204 |
| 207 if (!new_video_key_cb_.is_null()) | 205 if (!new_video_key_cb_.is_null()) |
| 208 new_video_key_cb_.Run(); | 206 new_video_key_cb_.Run(); |
| 209 | 207 |
| 210 key_added_cb_.Run(key_system, session_id); | 208 key_added_cb_.Run(session_id); |
| 211 } | 209 } |
| 212 | 210 |
| 213 void AesDecryptor::CancelKeyRequest(const std::string& key_system, | 211 void AesDecryptor::CancelKeyRequest(const std::string& session_id) { |
| 214 const std::string& session_id) { | |
| 215 } | 212 } |
| 216 | 213 |
| 217 MediaKeys* AesDecryptor::GetMediaKeys() { | 214 MediaKeys* AesDecryptor::GetMediaKeys() { |
| 218 return this; | 215 return this; |
| 219 } | 216 } |
| 220 | 217 |
| 221 void AesDecryptor::RegisterNewKeyCB(StreamType stream_type, | 218 void AesDecryptor::RegisterNewKeyCB(StreamType stream_type, |
| 222 const NewKeyCB& new_key_cb) { | 219 const NewKeyCB& new_key_cb) { |
| 223 switch (stream_type) { | 220 switch (stream_type) { |
| 224 case kAudio: | 221 case kAudio: |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 bool AesDecryptor::DecryptionKey::Init() { | 329 bool AesDecryptor::DecryptionKey::Init() { |
| 333 CHECK(!secret_.empty()); | 330 CHECK(!secret_.empty()); |
| 334 decryption_key_.reset(crypto::SymmetricKey::Import( | 331 decryption_key_.reset(crypto::SymmetricKey::Import( |
| 335 crypto::SymmetricKey::AES, secret_)); | 332 crypto::SymmetricKey::AES, secret_)); |
| 336 if (!decryption_key_) | 333 if (!decryption_key_) |
| 337 return false; | 334 return false; |
| 338 return true; | 335 return true; |
| 339 } | 336 } |
| 340 | 337 |
| 341 } // namespace media | 338 } // namespace media |
| OLD | NEW |