| 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 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 // what should happen when a frame fails the integrity check. | 278 // what should happen when a frame fails the integrity check. |
| 279 // http://wiki.webmproject.org/encryption/webm-encryption-rfc | 279 // http://wiki.webmproject.org/encryption/webm-encryption-rfc |
| 280 if (checksum_size > 0 && | 280 if (checksum_size > 0 && |
| 281 !key->hmac_key().empty() && | 281 !key->hmac_key().empty() && |
| 282 !CheckData(*encrypted, key->hmac_key())) { | 282 !CheckData(*encrypted, key->hmac_key())) { |
| 283 DVLOG(1) << "Integrity check failed."; | 283 DVLOG(1) << "Integrity check failed."; |
| 284 decrypt_cb.Run(kError, NULL); | 284 decrypt_cb.Run(kError, NULL); |
| 285 return; | 285 return; |
| 286 } | 286 } |
| 287 | 287 |
| 288 scoped_refptr<DecoderBuffer> decrypted; | 288 // TODO(strobe): Currently, presence of checksum is used to indicate the use |
| 289 // An empty iv string signals that the frame is unencrypted. | 289 // of normal or WebM decryption keys. Consider a more explicit signaling |
| 290 if (encrypted->GetDecryptConfig()->iv().empty()) { | 290 // mechanism and the removal of the webm_decryption_key member. |
| 291 int data_offset = encrypted->GetDecryptConfig()->data_offset(); | 291 crypto::SymmetricKey* decryption_key = (checksum_size > 0) ? |
| 292 decrypted = DecoderBuffer::CopyFrom(encrypted->GetData() + data_offset, | 292 key->webm_decryption_key() : key->decryption_key(); |
| 293 encrypted->GetDataSize() - data_offset); | 293 scoped_refptr<DecoderBuffer> decrypted = |
| 294 } else { | 294 DecryptData(*encrypted, decryption_key); |
| 295 // TODO(strobe): Currently, presence of checksum is used to indicate the use | 295 if (!decrypted) { |
| 296 // of normal or WebM decryption keys. Consider a more explicit signaling | 296 DVLOG(1) << "Decryption failed."; |
| 297 // mechanism and the removal of the webm_decryption_key member. | 297 decrypt_cb.Run(kError, NULL); |
| 298 crypto::SymmetricKey* decryption_key = (checksum_size > 0) ? | 298 return; |
| 299 key->webm_decryption_key() : key->decryption_key(); | |
| 300 decrypted = DecryptData(*encrypted, decryption_key); | |
| 301 if (!decrypted) { | |
| 302 DVLOG(1) << "Decryption failed."; | |
| 303 decrypt_cb.Run(kError, NULL); | |
| 304 return; | |
| 305 } | |
| 306 } | 299 } |
| 307 | 300 |
| 308 decrypted->SetTimestamp(encrypted->GetTimestamp()); | 301 decrypted->SetTimestamp(encrypted->GetTimestamp()); |
| 309 decrypted->SetDuration(encrypted->GetDuration()); | 302 decrypted->SetDuration(encrypted->GetDuration()); |
| 310 decrypt_cb.Run(kSuccess, decrypted); | 303 decrypt_cb.Run(kSuccess, decrypted); |
| 311 } | 304 } |
| 312 | 305 |
| 313 void AesDecryptor::SetKey(const std::string& key_id, | 306 void AesDecryptor::SetKey(const std::string& key_id, |
| 314 scoped_ptr<DecryptionKey> decryption_key) { | 307 scoped_ptr<DecryptionKey> decryption_key) { |
| 315 base::AutoLock auto_lock(key_map_lock_); | 308 base::AutoLock auto_lock(key_map_lock_); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 return false; | 349 return false; |
| 357 | 350 |
| 358 hmac_key_ = DeriveKey(secret_, kWebmHmacSeed, kWebmSha1DigestSize); | 351 hmac_key_ = DeriveKey(secret_, kWebmHmacSeed, kWebmSha1DigestSize); |
| 359 if (hmac_key_.empty()) | 352 if (hmac_key_.empty()) |
| 360 return false; | 353 return false; |
| 361 | 354 |
| 362 return true; | 355 return true; |
| 363 } | 356 } |
| 364 | 357 |
| 365 } // namespace media | 358 } // namespace media |
| OLD | NEW |