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