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 // TODO(strobe): Currently, presence of checksum is used to indicate the use | 288 scoped_refptr<DecoderBuffer> decrypted; |
289 // of normal or WebM decryption keys. Consider a more explicit signaling | 289 // An empty iv string signals that the frame is unencrypted. |
290 // mechanism and the removal of the webm_decryption_key member. | 290 if (encrypted->GetDecryptConfig()->iv().empty()) { |
291 crypto::SymmetricKey* decryption_key = (checksum_size > 0) ? | 291 int data_offset = encrypted->GetDecryptConfig()->data_offset(); |
292 key->webm_decryption_key() : key->decryption_key(); | 292 const uint8* frame = |
293 scoped_refptr<DecoderBuffer> decrypted = | 293 reinterpret_cast<const uint8*>(encrypted->GetData() + data_offset); |
294 DecryptData(*encrypted, decryption_key); | 294 int frame_size = encrypted->GetDataSize() - data_offset; |
295 if (!decrypted) { | 295 decrypted = DecoderBuffer::CopyFrom(frame, frame_size); |
xhwang
2012/08/01 00:45:41
decrypted = DecoderBuffer::CopyFrom(encrypted->Get
fgalligan1
2012/08/01 01:36:10
Done.
| |
296 DVLOG(1) << "Decryption failed."; | 296 } else { |
297 decrypt_cb.Run(kError, NULL); | 297 // TODO(strobe): Currently, presence of checksum is used to indicate the use |
298 return; | 298 // of normal or WebM decryption keys. Consider a more explicit signaling |
299 // mechanism and the removal of the webm_decryption_key member. | |
300 crypto::SymmetricKey* decryption_key = (checksum_size > 0) ? | |
301 key->webm_decryption_key() : key->decryption_key(); | |
302 decrypted = DecryptData(*encrypted, decryption_key); | |
303 if (!decrypted) { | |
304 DVLOG(1) << "Decryption failed."; | |
305 decrypt_cb.Run(kError, NULL); | |
306 return; | |
307 } | |
299 } | 308 } |
300 | 309 |
301 decrypted->SetTimestamp(encrypted->GetTimestamp()); | 310 decrypted->SetTimestamp(encrypted->GetTimestamp()); |
302 decrypted->SetDuration(encrypted->GetDuration()); | 311 decrypted->SetDuration(encrypted->GetDuration()); |
303 decrypt_cb.Run(kSuccess, decrypted); | 312 decrypt_cb.Run(kSuccess, decrypted); |
304 } | 313 } |
305 | 314 |
306 void AesDecryptor::SetKey(const std::string& key_id, | 315 void AesDecryptor::SetKey(const std::string& key_id, |
307 scoped_ptr<DecryptionKey> decryption_key) { | 316 scoped_ptr<DecryptionKey> decryption_key) { |
308 base::AutoLock auto_lock(key_map_lock_); | 317 base::AutoLock auto_lock(key_map_lock_); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
349 return false; | 358 return false; |
350 | 359 |
351 hmac_key_ = DeriveKey(secret_, kWebmHmacSeed, kWebmSha1DigestSize); | 360 hmac_key_ = DeriveKey(secret_, kWebmHmacSeed, kWebmSha1DigestSize); |
352 if (hmac_key_.empty()) | 361 if (hmac_key_.empty()) |
353 return false; | 362 return false; |
354 | 363 |
355 return true; | 364 return true; |
356 } | 365 } |
357 | 366 |
358 } // namespace media | 367 } // namespace media |
OLD | NEW |