| 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 <string> | 5 #include <string> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "media/base/decoder_buffer.h" | 10 #include "media/base/decoder_buffer.h" |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 // initialization data from the WebM file. Every encrypted Block has | 174 // initialization data from the WebM file. Every encrypted Block has |
| 175 // a signal byte prepended to a frame. If the frame is encrypted then an IV is | 175 // a signal byte prepended to a frame. If the frame is encrypted then an IV is |
| 176 // prepended to the Block. Current encrypted WebM request for comments | 176 // prepended to the Block. Current encrypted WebM request for comments |
| 177 // specification is here | 177 // specification is here |
| 178 // http://wiki.webmproject.org/encryption/webm-encryption-rfc | 178 // http://wiki.webmproject.org/encryption/webm-encryption-rfc |
| 179 static scoped_refptr<DecoderBuffer> CreateWebMEncryptedBuffer( | 179 static scoped_refptr<DecoderBuffer> CreateWebMEncryptedBuffer( |
| 180 const uint8* data, int data_size, | 180 const uint8* data, int data_size, |
| 181 const uint8* key_id, int key_id_size) { | 181 const uint8* key_id, int key_id_size) { |
| 182 scoped_refptr<DecoderBuffer> encrypted_buffer = DecoderBuffer::CopyFrom( | 182 scoped_refptr<DecoderBuffer> encrypted_buffer = DecoderBuffer::CopyFrom( |
| 183 data, data_size); | 183 data, data_size); |
| 184 CHECK(encrypted_buffer); | 184 CHECK(encrypted_buffer.get()); |
| 185 DCHECK_EQ(kWebMSignalByteSize, 1); | 185 DCHECK_EQ(kWebMSignalByteSize, 1); |
| 186 | 186 |
| 187 uint8 signal_byte = data[0]; | 187 uint8 signal_byte = data[0]; |
| 188 int data_offset = kWebMSignalByteSize; | 188 int data_offset = kWebMSignalByteSize; |
| 189 | 189 |
| 190 // Setting the DecryptConfig object of the buffer while leaving the | 190 // Setting the DecryptConfig object of the buffer while leaving the |
| 191 // initialization vector empty will tell the decryptor that the frame is | 191 // initialization vector empty will tell the decryptor that the frame is |
| 192 // unencrypted. | 192 // unencrypted. |
| 193 std::string counter_block_str; | 193 std::string counter_block_str; |
| 194 | 194 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 207 } | 207 } |
| 208 | 208 |
| 209 static scoped_refptr<DecoderBuffer> CreateSubsampleEncryptedBuffer( | 209 static scoped_refptr<DecoderBuffer> CreateSubsampleEncryptedBuffer( |
| 210 const uint8* data, int data_size, | 210 const uint8* data, int data_size, |
| 211 const uint8* key_id, int key_id_size, | 211 const uint8* key_id, int key_id_size, |
| 212 const uint8* iv, int iv_size, | 212 const uint8* iv, int iv_size, |
| 213 int data_offset, | 213 int data_offset, |
| 214 const std::vector<SubsampleEntry>& subsample_entries) { | 214 const std::vector<SubsampleEntry>& subsample_entries) { |
| 215 scoped_refptr<DecoderBuffer> encrypted_buffer = | 215 scoped_refptr<DecoderBuffer> encrypted_buffer = |
| 216 DecoderBuffer::CopyFrom(data, data_size); | 216 DecoderBuffer::CopyFrom(data, data_size); |
| 217 CHECK(encrypted_buffer); | 217 CHECK(encrypted_buffer.get()); |
| 218 encrypted_buffer->SetDecryptConfig( | 218 encrypted_buffer->SetDecryptConfig( |
| 219 scoped_ptr<DecryptConfig>(new DecryptConfig( | 219 scoped_ptr<DecryptConfig>(new DecryptConfig( |
| 220 std::string(reinterpret_cast<const char*>(key_id), key_id_size), | 220 std::string(reinterpret_cast<const char*>(key_id), key_id_size), |
| 221 std::string(reinterpret_cast<const char*>(iv), iv_size), | 221 std::string(reinterpret_cast<const char*>(iv), iv_size), |
| 222 data_offset, | 222 data_offset, |
| 223 subsample_entries))); | 223 subsample_entries))); |
| 224 return encrypted_buffer; | 224 return encrypted_buffer; |
| 225 } | 225 } |
| 226 | 226 |
| 227 class AesDecryptorTest : public testing::Test { | 227 class AesDecryptorTest : public testing::Test { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 MOCK_METHOD2(BufferDecrypted, void(Decryptor::Status, | 269 MOCK_METHOD2(BufferDecrypted, void(Decryptor::Status, |
| 270 const scoped_refptr<DecoderBuffer>&)); | 270 const scoped_refptr<DecoderBuffer>&)); |
| 271 | 271 |
| 272 void DecryptAndExpectToSucceed(const scoped_refptr<DecoderBuffer>& encrypted, | 272 void DecryptAndExpectToSucceed(const scoped_refptr<DecoderBuffer>& encrypted, |
| 273 const uint8* plain_text, int plain_text_size) { | 273 const uint8* plain_text, int plain_text_size) { |
| 274 scoped_refptr<DecoderBuffer> decrypted; | 274 scoped_refptr<DecoderBuffer> decrypted; |
| 275 EXPECT_CALL(*this, BufferDecrypted(AesDecryptor::kSuccess, NotNull())) | 275 EXPECT_CALL(*this, BufferDecrypted(AesDecryptor::kSuccess, NotNull())) |
| 276 .WillOnce(SaveArg<1>(&decrypted)); | 276 .WillOnce(SaveArg<1>(&decrypted)); |
| 277 | 277 |
| 278 decryptor_.Decrypt(Decryptor::kVideo, encrypted, decrypt_cb_); | 278 decryptor_.Decrypt(Decryptor::kVideo, encrypted, decrypt_cb_); |
| 279 ASSERT_TRUE(decrypted); | 279 ASSERT_TRUE(decrypted.get()); |
| 280 ASSERT_EQ(plain_text_size, decrypted->GetDataSize()); | 280 ASSERT_EQ(plain_text_size, decrypted->GetDataSize()); |
| 281 EXPECT_EQ(0, memcmp(plain_text, decrypted->GetData(), plain_text_size)); | 281 EXPECT_EQ(0, memcmp(plain_text, decrypted->GetData(), plain_text_size)); |
| 282 } | 282 } |
| 283 | 283 |
| 284 void DecryptAndExpectDataMismatch( | 284 void DecryptAndExpectDataMismatch( |
| 285 const scoped_refptr<DecoderBuffer>& encrypted, | 285 const scoped_refptr<DecoderBuffer>& encrypted, |
| 286 const uint8* plain_text, int plain_text_size) { | 286 const uint8* plain_text, int plain_text_size) { |
| 287 scoped_refptr<DecoderBuffer> decrypted; | 287 scoped_refptr<DecoderBuffer> decrypted; |
| 288 EXPECT_CALL(*this, BufferDecrypted(AesDecryptor::kSuccess, NotNull())) | 288 EXPECT_CALL(*this, BufferDecrypted(AesDecryptor::kSuccess, NotNull())) |
| 289 .WillOnce(SaveArg<1>(&decrypted)); | 289 .WillOnce(SaveArg<1>(&decrypted)); |
| 290 | 290 |
| 291 decryptor_.Decrypt(Decryptor::kVideo, encrypted, decrypt_cb_); | 291 decryptor_.Decrypt(Decryptor::kVideo, encrypted, decrypt_cb_); |
| 292 ASSERT_TRUE(decrypted); | 292 ASSERT_TRUE(decrypted.get()); |
| 293 ASSERT_EQ(plain_text_size, decrypted->GetDataSize()); | 293 ASSERT_EQ(plain_text_size, decrypted->GetDataSize()); |
| 294 EXPECT_NE(0, memcmp(plain_text, decrypted->GetData(), plain_text_size)); | 294 EXPECT_NE(0, memcmp(plain_text, decrypted->GetData(), plain_text_size)); |
| 295 } | 295 } |
| 296 | 296 |
| 297 void DecryptAndExpectSizeDataMismatch( | 297 void DecryptAndExpectSizeDataMismatch( |
| 298 const scoped_refptr<DecoderBuffer>& encrypted, | 298 const scoped_refptr<DecoderBuffer>& encrypted, |
| 299 const uint8* plain_text, int plain_text_size) { | 299 const uint8* plain_text, int plain_text_size) { |
| 300 scoped_refptr<DecoderBuffer> decrypted; | 300 scoped_refptr<DecoderBuffer> decrypted; |
| 301 EXPECT_CALL(*this, BufferDecrypted(AesDecryptor::kSuccess, NotNull())) | 301 EXPECT_CALL(*this, BufferDecrypted(AesDecryptor::kSuccess, NotNull())) |
| 302 .WillOnce(SaveArg<1>(&decrypted)); | 302 .WillOnce(SaveArg<1>(&decrypted)); |
| 303 | 303 |
| 304 decryptor_.Decrypt(Decryptor::kVideo, encrypted, decrypt_cb_); | 304 decryptor_.Decrypt(Decryptor::kVideo, encrypted, decrypt_cb_); |
| 305 ASSERT_TRUE(decrypted); | 305 ASSERT_TRUE(decrypted.get()); |
| 306 EXPECT_NE(plain_text_size, decrypted->GetDataSize()); | 306 EXPECT_NE(plain_text_size, decrypted->GetDataSize()); |
| 307 EXPECT_NE(0, memcmp(plain_text, decrypted->GetData(), plain_text_size)); | 307 EXPECT_NE(0, memcmp(plain_text, decrypted->GetData(), plain_text_size)); |
| 308 } | 308 } |
| 309 | 309 |
| 310 void DecryptAndExpectToFail(const scoped_refptr<DecoderBuffer>& encrypted) { | 310 void DecryptAndExpectToFail(const scoped_refptr<DecoderBuffer>& encrypted) { |
| 311 EXPECT_CALL(*this, BufferDecrypted(AesDecryptor::kError, IsNull())); | 311 EXPECT_CALL(*this, BufferDecrypted(AesDecryptor::kError, IsNull())); |
| 312 decryptor_.Decrypt(Decryptor::kVideo, encrypted, decrypt_cb_); | 312 decryptor_.Decrypt(Decryptor::kVideo, encrypted, decrypt_cb_); |
| 313 } | 313 } |
| 314 | 314 |
| 315 MOCK_METHOD2(KeyAdded, void(const std::string&, const std::string&)); | 315 MOCK_METHOD2(KeyAdded, void(const std::string&, const std::string&)); |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 599 scoped_refptr<DecoderBuffer> encrypted_data = CreateSubsampleEncryptedBuffer( | 599 scoped_refptr<DecoderBuffer> encrypted_data = CreateSubsampleEncryptedBuffer( |
| 600 kSubsampleData, arraysize(kSubsampleData), | 600 kSubsampleData, arraysize(kSubsampleData), |
| 601 kSubsampleKeyId, arraysize(kSubsampleKeyId), | 601 kSubsampleKeyId, arraysize(kSubsampleKeyId), |
| 602 kSubsampleIv, arraysize(kSubsampleIv), | 602 kSubsampleIv, arraysize(kSubsampleIv), |
| 603 0, | 603 0, |
| 604 entries); | 604 entries); |
| 605 ASSERT_NO_FATAL_FAILURE(DecryptAndExpectToFail(encrypted_data)); | 605 ASSERT_NO_FATAL_FAILURE(DecryptAndExpectToFail(encrypted_data)); |
| 606 } | 606 } |
| 607 | 607 |
| 608 } // namespace media | 608 } // namespace media |
| OLD | NEW |