Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(591)

Side by Side Diff: media/crypto/aes_decryptor_unittest.cc

Issue 10807003: Revert 147169 - Add support for encrypted WebM files as defined in the RFC. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « media/crypto/aes_decryptor.cc ('k') | media/filters/ffmpeg_video_decoder_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/sys_byteorder.h"
10 #include "media/base/decoder_buffer.h" 9 #include "media/base/decoder_buffer.h"
11 #include "media/base/decrypt_config.h" 10 #include "media/base/decrypt_config.h"
12 #include "media/base/mock_filters.h" 11 #include "media/base/mock_filters.h"
13 #include "media/crypto/aes_decryptor.h" 12 #include "media/crypto/aes_decryptor.h"
14 #include "media/webm/webm_constants.h"
15 #include "testing/gmock/include/gmock/gmock.h" 13 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
17 15
18 using ::testing::_; 16 using ::testing::_;
19 using ::testing::Gt; 17 using ::testing::Gt;
20 using ::testing::IsNull; 18 using ::testing::IsNull;
21 using ::testing::NotNull; 19 using ::testing::NotNull;
22 using ::testing::SaveArg; 20 using ::testing::SaveArg;
23 using ::testing::StrNe; 21 using ::testing::StrNe;
24 22
25 namespace media { 23 namespace media {
26 24
27 // |encrypted_data| is encrypted from |plain_text| using |key|. |key_id| is 25 static const char kClearKeySystem[] = "org.w3.clearkey";
28 // used to distinguish |key|. 26 static const uint8 kInitData[] = { 0x69, 0x6e, 0x69, 0x74 };
29 struct WebmEncryptedData { 27 // |kEncryptedData| is encrypted from |kOriginalData| using |kRightKey|.
30 uint8 plain_text[32]; 28 // Modifying any of these independently would fail the test.
31 int plain_text_size; 29 static const uint8 kOriginalData[] = {
32 uint8 key_id[32]; 30 0x4f, 0x72, 0x69, 0x67, 0x69, 0x6e, 0x61, 0x6c,
33 int key_id_size; 31 0x20, 0x64, 0x61, 0x74, 0x61, 0x2e
34 uint8 key[32];
35 int key_size;
36 uint8 encrypted_data[64];
37 int encrypted_data_size;
38 }; 32 };
39 33 static const uint8 kEncryptedData[] = {
40 static const char kClearKeySystem[] = "org.w3.clearkey"; 34 0x82, 0x3A, 0x76, 0x92, 0xEC, 0x7F, 0xF8, 0x85,
41 35 0xEC, 0x23, 0x52, 0xFB, 0x19, 0xB1, 0xB9, 0x09
42 // Frames 0 & 1 are encrypted with the same key. Frame 2 is encrypted with a
43 // different key.
44 const WebmEncryptedData kWebmEncryptedFrames[] = {
45 {
46 // plaintext
47 "Original data.", 14,
48 // key_id
49 { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
50 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
51 0x10, 0x11, 0x12, 0x13,
52 }, 20,
53 // key
54 { 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b,
55 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23,
56 }, 16,
57 // encrypted_data
58 { 0xfb, 0xe7, 0x1d, 0xbb, 0x4c, 0x23, 0xce, 0xba,
59 0xcc, 0xf8, 0xda, 0xc0, 0xff, 0xff, 0xff, 0xff,
60 0xff, 0xff, 0xff, 0xff, 0x99, 0xaa, 0xff, 0xb7,
61 0x74, 0x02, 0x4e, 0x1c, 0x75, 0x3d, 0xee, 0xcb,
62 0x64, 0xf7,
63 }, 34,
64 },
65 {
66 // plaintext
67 "Changed Original data.", 22,
68 // key_id
69 { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
70 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
71 0x10, 0x11, 0x12, 0x13,
72 }, 20,
73 // key
74 { 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b,
75 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23,
76 }, 16,
77 // encrypted_data
78 { 0x43, 0xe4, 0x78, 0x7a, 0x43, 0xe1, 0x49, 0xbb,
79 0x44, 0x38, 0xdf, 0xfc, 0x00, 0x00, 0x00, 0x00,
80 0x00, 0x00, 0x00, 0x00, 0xec, 0x8e, 0x87, 0x21,
81 0xd3, 0xb9, 0x1c, 0x61, 0xf6, 0x5a, 0x60, 0xaa,
82 0x07, 0x0e, 0x96, 0xd0, 0x54, 0x5d, 0x35, 0x9a,
83 0x4a, 0xd3,
84 }, 42,
85 },
86 {
87 // plaintext
88 "Original data.", 14,
89 // key_id
90 { 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b,
91 0x2c, 0x2d, 0x2e, 0x2f, 0x30,
92 }, 13,
93 // key
94 { 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38,
95 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40,
96 }, 16,
97 // encrypted_data
98 { 0xd9, 0x43, 0x30, 0xfd, 0x82, 0x77, 0x62, 0x04,
99 0x08, 0xc2, 0x48, 0x89, 0x00, 0x00, 0x00, 0x00,
100 0x00, 0x00, 0x00, 0x01, 0x48, 0x5e, 0x4a, 0x41,
101 0x2a, 0x8b, 0xf4, 0xc6, 0x47, 0x54, 0x90, 0x34,
102 0xf4, 0x8b,
103 }, 34,
104 },
105 }; 36 };
106 37 static const uint8 kRightKey[] = {
107 static const uint8 kWebmWrongKey[] = { 38 0x41, 0x20, 0x77, 0x6f, 0x6e, 0x64, 0x65, 0x72,
39 0x66, 0x75, 0x6c, 0x20, 0x6b, 0x65, 0x79, 0x21
40 };
41 static const uint8 kWrongKey[] = {
108 0x49, 0x27, 0x6d, 0x20, 0x61, 0x20, 0x77, 0x72, 42 0x49, 0x27, 0x6d, 0x20, 0x61, 0x20, 0x77, 0x72,
109 0x6f, 0x6e, 0x67, 0x20, 0x6b, 0x65, 0x79, 0x2e 43 0x6f, 0x6e, 0x67, 0x20, 0x6b, 0x65, 0x79, 0x2e
110 }; 44 };
111 static const uint8 kWebmWrongSizedKey[] = { 0x20, 0x20 }; 45 static const uint8 kWrongSizedKey[] = { 0x20, 0x20 };
112 46 static const uint8 kKeyId1[] = {
113 // This is the encrypted data from frame 0 of |kWebmEncryptedFrames| except 47 0x4b, 0x65, 0x79, 0x20, 0x49, 0x44, 0x20, 0x31
114 // byte 0 is changed from 0xfb to 0xfc. Bytes 0-11 of WebM encrypted data
115 // contains the HMAC.
116 static const unsigned char kWebmFrame0HmacDataChanged[] = {
117 0xfc, 0xe7, 0x1d, 0xbb, 0x4c, 0x23, 0xce, 0xba,
118 0xcc, 0xf8, 0xda, 0xc0, 0xff, 0xff, 0xff, 0xff,
119 0xff, 0xff, 0xff, 0xff, 0x99, 0xaa, 0xff, 0xb7,
120 0x74, 0x02, 0x4e, 0x1c, 0x75, 0x3d, 0xee, 0xcb,
121 0x64, 0xf7
122 }; 48 };
123 49 static const uint8 kKeyId2[] = {
124 // This is the encrypted data from frame 0 of |kWebmEncryptedFrames| except 50 0x4b, 0x65, 0x79, 0x20, 0x49, 0x44, 0x20, 0x32
125 // byte 12 is changed from 0xff to 0x0f. Bytes 12-19 of WebM encrypted data
126 // contains the IV.
127 static const unsigned char kWebmFrame0IvDataChanged[] = {
128 0xfb, 0xe7, 0x1d, 0xbb, 0x4c, 0x23, 0xce, 0xba,
129 0xcc, 0xf8, 0xda, 0xc0, 0x0f, 0xff, 0xff, 0xff,
130 0xff, 0xff, 0xff, 0xff, 0x99, 0xaa, 0xff, 0xb7,
131 0x74, 0x02, 0x4e, 0x1c, 0x75, 0x3d, 0xee, 0xcb,
132 0x64, 0xf7
133 };
134
135 // This is the encrypted data from frame 0 of |kWebmEncryptedFrames| except
136 // byte 33 is changed from 0xf7 to 0xf8. Bytes 20+ of WebM encrypted data
137 // contains the encrypted frame.
138 static const unsigned char kWebmFrame0FrameDataChanged[] = {
139 0xfb, 0xe7, 0x1d, 0xbb, 0x4c, 0x23, 0xce, 0xba,
140 0xcc, 0xf8, 0xda, 0xc0, 0xff, 0xff, 0xff, 0xff,
141 0xff, 0xff, 0xff, 0xff, 0x99, 0xaa, 0xff, 0xb7,
142 0x74, 0x02, 0x4e, 0x1c, 0x75, 0x3d, 0xee, 0xcb,
143 0x64, 0xf8
144 }; 51 };
145 52
146 class AesDecryptorTest : public testing::Test { 53 class AesDecryptorTest : public testing::Test {
147 public: 54 public:
148 AesDecryptorTest() 55 AesDecryptorTest()
149 : decryptor_(&client_), 56 : decryptor_(&client_),
150 decrypt_cb_(base::Bind(&AesDecryptorTest::BufferDecrypted, 57 decrypt_cb_(base::Bind(&AesDecryptorTest::BufferDecrypted,
151 base::Unretained(this))) { 58 base::Unretained(this))) {
59 encrypted_data_ = DecoderBuffer::CopyFrom(kEncryptedData,
60 arraysize(kEncryptedData));
152 } 61 }
153 62
154 protected: 63 protected:
155 // Returns a 16 byte CTR counter block. The CTR counter block format is a 64 void GenerateKeyRequest() {
156 // CTR IV appended with a CTR block counter. |iv| is a CTR IV. |iv_size| is
157 // the size of |iv| in bytes.
158 static std::string GenerateCounterBlock(const uint8* iv, int iv_size) {
159 const int kDecryptionKeySize = 16;
160 CHECK_GT(iv_size, 0);
161 CHECK_LE(iv_size, kDecryptionKeySize);
162 char counter_block_data[kDecryptionKeySize];
163
164 // Set the IV.
165 memcpy(counter_block_data, iv, iv_size);
166
167 // Set block counter to all 0's.
168 memset(counter_block_data + iv_size, 0, kDecryptionKeySize - iv_size);
169
170 return std::string(counter_block_data, kDecryptionKeySize);
171 }
172
173 // Creates a WebM encrypted buffer that the demuxer would pass to the
174 // decryptor. |data| is the payload of a WebM encrypted Block. |key_id| is
175 // initialization data from the WebM file. Every encrypted Block has
176 // an HMAC and IV prepended to an encrypted frame. Current encrypted WebM
177 // request for comments specification is here
178 // http://wiki.webmproject.org/encryption/webm-encryption-rfc
179 scoped_refptr<DecoderBuffer> CreateWebMEncryptedBuffer(const uint8* data,
180 int data_size,
181 const uint8* key_id,
182 int key_id_size) {
183 scoped_refptr<DecoderBuffer> encrypted_buffer = DecoderBuffer::CopyFrom(
184 data + kWebMHmacSize, data_size - kWebMHmacSize);
185 CHECK(encrypted_buffer);
186
187 uint64 network_iv;
188 memcpy(&network_iv, data + kWebMHmacSize, sizeof(network_iv));
189 const uint64 iv = base::NetToHost64(network_iv);
190 std::string webm_iv =
191 GenerateCounterBlock(reinterpret_cast<const uint8*>(&iv), sizeof(iv));
192 encrypted_buffer->SetDecryptConfig(
193 scoped_ptr<DecryptConfig>(new DecryptConfig(
194 key_id, key_id_size,
195 reinterpret_cast<const uint8*>(webm_iv.data()), webm_iv.size(),
196 data, kWebMHmacSize,
197 sizeof(iv))));
198 return encrypted_buffer;
199 }
200
201 void GenerateKeyRequest(const uint8* key_id, int key_id_size) {
202 EXPECT_CALL(client_, KeyMessageMock(kClearKeySystem, StrNe(std::string()), 65 EXPECT_CALL(client_, KeyMessageMock(kClearKeySystem, StrNe(std::string()),
203 NotNull(), Gt(0), "")) 66 NotNull(), Gt(0), ""))
204 .WillOnce(SaveArg<1>(&session_id_string_)); 67 .WillOnce(SaveArg<1>(&session_id_string_));
205 decryptor_.GenerateKeyRequest(kClearKeySystem, key_id, key_id_size); 68 decryptor_.GenerateKeyRequest(kClearKeySystem,
69 kInitData, arraysize(kInitData));
206 } 70 }
207 71
208 void AddKeyAndExpectToSucceed(const uint8* key_id, int key_id_size, 72 template <int KeyIdSize, int KeySize>
209 const uint8* key, int key_size) { 73 void AddKeyAndExpectToSucceed(const uint8 (&key_id)[KeyIdSize],
74 const uint8 (&key)[KeySize]) {
210 EXPECT_CALL(client_, KeyAdded(kClearKeySystem, session_id_string_)); 75 EXPECT_CALL(client_, KeyAdded(kClearKeySystem, session_id_string_));
211 decryptor_.AddKey(kClearKeySystem, key, key_size, key_id, key_id_size, 76 decryptor_.AddKey(kClearKeySystem, key, KeySize, key_id, KeyIdSize,
212 session_id_string_); 77 session_id_string_);
213 } 78 }
214 79
215 void AddKeyAndExpectToFail(const uint8* key_id, int key_id_size, 80 template <int KeyIdSize, int KeySize>
216 const uint8* key, int key_size) { 81 void AddKeyAndExpectToFail(const uint8 (&key_id)[KeyIdSize],
82 const uint8 (&key)[KeySize]) {
217 EXPECT_CALL(client_, KeyError(kClearKeySystem, session_id_string_, 83 EXPECT_CALL(client_, KeyError(kClearKeySystem, session_id_string_,
218 Decryptor::kUnknownError, 0)); 84 Decryptor::kUnknownError, 0));
219 decryptor_.AddKey(kClearKeySystem, key, key_size, key_id, key_id_size, 85 decryptor_.AddKey(kClearKeySystem, key, KeySize, key_id, KeyIdSize,
220 session_id_string_); 86 session_id_string_);
221 } 87 }
222 88
89 template <int KeyIdSize>
90 void SetKeyIdForEncryptedData(const uint8 (&key_id)[KeyIdSize]) {
91 encrypted_data_->SetDecryptConfig(
92 scoped_ptr<DecryptConfig>(new DecryptConfig(key_id, KeyIdSize)));
93 }
94
223 MOCK_METHOD2(BufferDecrypted, void(Decryptor::DecryptStatus, 95 MOCK_METHOD2(BufferDecrypted, void(Decryptor::DecryptStatus,
224 const scoped_refptr<DecoderBuffer>&)); 96 const scoped_refptr<DecoderBuffer>&));
225 97
226 void DecryptAndExpectToSucceed(const uint8* data, int data_size, 98 void DecryptAndExpectToSucceed() {
227 const uint8* plain_text,
228 int plain_text_size,
229 const uint8* key_id, int key_id_size) {
230 scoped_refptr<DecoderBuffer> encrypted_data =
231 CreateWebMEncryptedBuffer(data, data_size, key_id, key_id_size);
232 scoped_refptr<DecoderBuffer> decrypted; 99 scoped_refptr<DecoderBuffer> decrypted;
233 EXPECT_CALL(*this, BufferDecrypted(AesDecryptor::kSuccess, NotNull())) 100 EXPECT_CALL(*this, BufferDecrypted(AesDecryptor::kSuccess, NotNull()))
234 .WillOnce(SaveArg<1>(&decrypted)); 101 .WillOnce(SaveArg<1>(&decrypted));
235 102
236 decryptor_.Decrypt(encrypted_data, decrypt_cb_); 103 decryptor_.Decrypt(encrypted_data_, decrypt_cb_);
237 ASSERT_TRUE(decrypted); 104 ASSERT_TRUE(decrypted);
238 ASSERT_EQ(plain_text_size, decrypted->GetDataSize()); 105 int data_length = sizeof(kOriginalData);
239 EXPECT_EQ(0, memcmp(plain_text, decrypted->GetData(), plain_text_size)); 106 ASSERT_EQ(data_length, decrypted->GetDataSize());
107 EXPECT_EQ(0, memcmp(kOriginalData, decrypted->GetData(), data_length));
240 } 108 }
241 109
242 void DecryptAndExpectToFail(const uint8* data, int data_size, 110 void DecryptAndExpectToFail() {
243 const uint8* plain_text, int plain_text_size,
244 const uint8* key_id, int key_id_size) {
245 scoped_refptr<DecoderBuffer> encrypted_data =
246 CreateWebMEncryptedBuffer(data, data_size, key_id, key_id_size);
247 EXPECT_CALL(*this, BufferDecrypted(AesDecryptor::kError, IsNull())); 111 EXPECT_CALL(*this, BufferDecrypted(AesDecryptor::kError, IsNull()));
248 decryptor_.Decrypt(encrypted_data, decrypt_cb_); 112 decryptor_.Decrypt(encrypted_data_, decrypt_cb_);
249 } 113 }
250 114
251 scoped_refptr<DecoderBuffer> encrypted_data_; 115 scoped_refptr<DecoderBuffer> encrypted_data_;
252 MockDecryptorClient client_; 116 MockDecryptorClient client_;
253 AesDecryptor decryptor_; 117 AesDecryptor decryptor_;
254 std::string session_id_string_; 118 std::string session_id_string_;
255 AesDecryptor::DecryptCB decrypt_cb_; 119 AesDecryptor::DecryptCB decrypt_cb_;
256 }; 120 };
257 121
258 TEST_F(AesDecryptorTest, NormalDecryption) { 122 TEST_F(AesDecryptorTest, NormalDecryption) {
259 const WebmEncryptedData& frame = kWebmEncryptedFrames[0]; 123 GenerateKeyRequest();
260 GenerateKeyRequest(frame.key_id, frame.key_id_size); 124 AddKeyAndExpectToSucceed(kKeyId1, kRightKey);
261 AddKeyAndExpectToSucceed(frame.key_id, frame.key_id_size, 125 SetKeyIdForEncryptedData(kKeyId1);
262 frame.key, frame.key_size); 126 ASSERT_NO_FATAL_FAILURE(DecryptAndExpectToSucceed());
263 ASSERT_NO_FATAL_FAILURE(DecryptAndExpectToSucceed(frame.encrypted_data,
264 frame.encrypted_data_size,
265 frame.plain_text,
266 frame.plain_text_size,
267 frame.key_id,
268 frame.key_id_size));
269 } 127 }
270 128
271 TEST_F(AesDecryptorTest, WrongKey) { 129 TEST_F(AesDecryptorTest, WrongKey) {
272 const WebmEncryptedData& frame = kWebmEncryptedFrames[0]; 130 GenerateKeyRequest();
273 GenerateKeyRequest(frame.key_id, frame.key_id_size); 131 AddKeyAndExpectToSucceed(kKeyId1, kWrongKey);
274 AddKeyAndExpectToSucceed(frame.key_id, frame.key_id_size, 132 SetKeyIdForEncryptedData(kKeyId1);
275 kWebmWrongKey, arraysize(kWebmWrongKey)); 133 ASSERT_NO_FATAL_FAILURE(DecryptAndExpectToFail());
276 ASSERT_NO_FATAL_FAILURE(DecryptAndExpectToFail(frame.encrypted_data, 134 }
277 frame.encrypted_data_size, 135
278 frame.plain_text, 136 TEST_F(AesDecryptorTest, MultipleKeys) {
279 frame.plain_text_size, 137 GenerateKeyRequest();
280 frame.key_id, 138 AddKeyAndExpectToSucceed(kKeyId1, kRightKey);
281 frame.key_id_size)); 139 AddKeyAndExpectToSucceed(kKeyId2, kWrongKey);
140 SetKeyIdForEncryptedData(kKeyId1);
141 ASSERT_NO_FATAL_FAILURE(DecryptAndExpectToSucceed());
282 } 142 }
283 143
284 TEST_F(AesDecryptorTest, KeyReplacement) { 144 TEST_F(AesDecryptorTest, KeyReplacement) {
285 const WebmEncryptedData& frame = kWebmEncryptedFrames[0]; 145 GenerateKeyRequest();
286 GenerateKeyRequest(frame.key_id, frame.key_id_size); 146 SetKeyIdForEncryptedData(kKeyId1);
287 AddKeyAndExpectToSucceed(frame.key_id, frame.key_id_size, 147 AddKeyAndExpectToSucceed(kKeyId1, kWrongKey);
288 kWebmWrongKey, arraysize(kWebmWrongKey)); 148 ASSERT_NO_FATAL_FAILURE(DecryptAndExpectToFail());
289 ASSERT_NO_FATAL_FAILURE(DecryptAndExpectToFail(frame.encrypted_data, 149 AddKeyAndExpectToSucceed(kKeyId1, kRightKey);
290 frame.encrypted_data_size, 150 ASSERT_NO_FATAL_FAILURE(DecryptAndExpectToSucceed());
291 frame.plain_text,
292 frame.plain_text_size,
293 frame.key_id,
294 frame.key_id_size));
295 AddKeyAndExpectToSucceed(frame.key_id, frame.key_id_size,
296 frame.key, frame.key_size);
297 ASSERT_NO_FATAL_FAILURE(DecryptAndExpectToSucceed(frame.encrypted_data,
298 frame.encrypted_data_size,
299 frame.plain_text,
300 frame.plain_text_size,
301 frame.key_id,
302 frame.key_id_size));
303 } 151 }
304 152
305 TEST_F(AesDecryptorTest, WrongSizedKey) { 153 TEST_F(AesDecryptorTest, WrongSizedKey) {
306 const WebmEncryptedData& frame = kWebmEncryptedFrames[0]; 154 GenerateKeyRequest();
307 GenerateKeyRequest(frame.key_id, frame.key_id_size); 155 AddKeyAndExpectToFail(kKeyId1, kWrongSizedKey);
308 AddKeyAndExpectToFail(frame.key_id, frame.key_id_size,
309 kWebmWrongSizedKey, arraysize(kWebmWrongSizedKey));
310 } 156 }
311 157
312 TEST_F(AesDecryptorTest, MultipleKeysAndFrames) { 158 } // media
313 const WebmEncryptedData& frame = kWebmEncryptedFrames[0];
314 GenerateKeyRequest(frame.key_id, frame.key_id_size);
315 AddKeyAndExpectToSucceed(frame.key_id, frame.key_id_size,
316 frame.key, frame.key_size);
317 ASSERT_NO_FATAL_FAILURE(DecryptAndExpectToSucceed(frame.encrypted_data,
318 frame.encrypted_data_size,
319 frame.plain_text,
320 frame.plain_text_size,
321 frame.key_id,
322 frame.key_id_size));
323
324 const WebmEncryptedData& frame2 = kWebmEncryptedFrames[2];
325 GenerateKeyRequest(frame2.key_id, frame2.key_id_size);
326 AddKeyAndExpectToSucceed(frame2.key_id, frame2.key_id_size,
327 frame2.key, frame2.key_size);
328
329 const WebmEncryptedData& frame1 = kWebmEncryptedFrames[1];
330 ASSERT_NO_FATAL_FAILURE(DecryptAndExpectToSucceed(frame1.encrypted_data,
331 frame1.encrypted_data_size,
332 frame1.plain_text,
333 frame1.plain_text_size,
334 frame1.key_id,
335 frame1.key_id_size));
336
337 ASSERT_NO_FATAL_FAILURE(DecryptAndExpectToSucceed(frame2.encrypted_data,
338 frame2.encrypted_data_size,
339 frame2.plain_text,
340 frame2.plain_text_size,
341 frame2.key_id,
342 frame2.key_id_size));
343 }
344
345 TEST_F(AesDecryptorTest, HmacCheckFailure) {
346 const WebmEncryptedData& frame = kWebmEncryptedFrames[0];
347 GenerateKeyRequest(frame.key_id, frame.key_id_size);
348 AddKeyAndExpectToSucceed(frame.key_id, frame.key_id_size,
349 frame.key, frame.key_size);
350 ASSERT_NO_FATAL_FAILURE(DecryptAndExpectToFail(kWebmFrame0HmacDataChanged,
351 frame.encrypted_data_size,
352 frame.plain_text,
353 frame.plain_text_size,
354 frame.key_id,
355 frame.key_id_size));
356 }
357
358 TEST_F(AesDecryptorTest, IvCheckFailure) {
359 const WebmEncryptedData& frame = kWebmEncryptedFrames[0];
360 GenerateKeyRequest(frame.key_id, frame.key_id_size);
361 AddKeyAndExpectToSucceed(frame.key_id, frame.key_id_size,
362 frame.key, frame.key_size);
363 ASSERT_NO_FATAL_FAILURE(DecryptAndExpectToFail(kWebmFrame0IvDataChanged,
364 frame.encrypted_data_size,
365 frame.plain_text,
366 frame.plain_text_size,
367 frame.key_id,
368 frame.key_id_size));
369 }
370
371 TEST_F(AesDecryptorTest, DataCheckFailure) {
372 const WebmEncryptedData& frame = kWebmEncryptedFrames[0];
373 GenerateKeyRequest(frame.key_id, frame.key_id_size);
374 AddKeyAndExpectToSucceed(frame.key_id, frame.key_id_size,
375 frame.key, frame.key_size);
376 ASSERT_NO_FATAL_FAILURE(DecryptAndExpectToFail(kWebmFrame0FrameDataChanged,
377 frame.encrypted_data_size,
378 frame.plain_text,
379 frame.plain_text_size,
380 frame.key_id,
381 frame.key_id_size));
382 }
383
384 } // namespace media
OLDNEW
« no previous file with comments | « media/crypto/aes_decryptor.cc ('k') | media/filters/ffmpeg_video_decoder_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698