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/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/sys_byteorder.h" |
9 #include "media/base/decoder_buffer.h" | 10 #include "media/base/decoder_buffer.h" |
10 #include "media/base/decrypt_config.h" | 11 #include "media/base/decrypt_config.h" |
11 #include "media/base/mock_filters.h" | 12 #include "media/base/mock_filters.h" |
12 #include "media/crypto/aes_decryptor.h" | 13 #include "media/crypto/aes_decryptor.h" |
| 14 #include "media/webm/webm_constants.h" |
13 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
15 | 17 |
16 using ::testing::_; | 18 using ::testing::_; |
17 using ::testing::Gt; | 19 using ::testing::Gt; |
18 using ::testing::IsNull; | 20 using ::testing::IsNull; |
19 using ::testing::NotNull; | 21 using ::testing::NotNull; |
20 using ::testing::SaveArg; | 22 using ::testing::SaveArg; |
21 using ::testing::StrNe; | 23 using ::testing::StrNe; |
22 | 24 |
23 namespace media { | 25 namespace media { |
24 | 26 |
| 27 // |encrypted_data| is encrypted from |plain_text| using |key|. |key_id| is |
| 28 // used to distinguish |key|. |
| 29 struct WebmEncryptedData { |
| 30 uint8 plain_text[32]; |
| 31 int plain_text_size; |
| 32 uint8 key_id[32]; |
| 33 int key_id_size; |
| 34 uint8 key[32]; |
| 35 int key_size; |
| 36 uint8 encrypted_data[64]; |
| 37 int encrypted_data_size; |
| 38 }; |
| 39 |
25 static const char kClearKeySystem[] = "org.w3.clearkey"; | 40 static const char kClearKeySystem[] = "org.w3.clearkey"; |
26 static const uint8 kInitData[] = { 0x69, 0x6e, 0x69, 0x74 }; | 41 |
27 // |kEncryptedData| is encrypted from |kOriginalData| using |kRightKey|. | 42 // Frames 0 & 1 are encrypted with the same key. Frame 2 is encrypted with a |
28 // Modifying any of these independently would fail the test. | 43 // different key. |
29 static const uint8 kOriginalData[] = { | 44 const WebmEncryptedData kWebmEncryptedFrames[] = { |
30 0x4f, 0x72, 0x69, 0x67, 0x69, 0x6e, 0x61, 0x6c, | 45 { |
31 0x20, 0x64, 0x61, 0x74, 0x61, 0x2e | 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 }, |
32 }; | 105 }; |
33 static const uint8 kEncryptedData[] = { | 106 |
34 0x82, 0x3A, 0x76, 0x92, 0xEC, 0x7F, 0xF8, 0x85, | 107 static const uint8 kWebmWrongKey[] = { |
35 0xEC, 0x23, 0x52, 0xFB, 0x19, 0xB1, 0xB9, 0x09 | |
36 }; | |
37 static const uint8 kRightKey[] = { | |
38 0x41, 0x20, 0x77, 0x6f, 0x6e, 0x64, 0x65, 0x72, | |
39 0x66, 0x75, 0x6c, 0x20, 0x6b, 0x65, 0x79, 0x21 | |
40 }; | |
41 static const uint8 kWrongKey[] = { | |
42 0x49, 0x27, 0x6d, 0x20, 0x61, 0x20, 0x77, 0x72, | 108 0x49, 0x27, 0x6d, 0x20, 0x61, 0x20, 0x77, 0x72, |
43 0x6f, 0x6e, 0x67, 0x20, 0x6b, 0x65, 0x79, 0x2e | 109 0x6f, 0x6e, 0x67, 0x20, 0x6b, 0x65, 0x79, 0x2e |
44 }; | 110 }; |
45 static const uint8 kWrongSizedKey[] = { 0x20, 0x20 }; | 111 static const uint8 kWebmWrongSizedKey[] = { 0x20, 0x20 }; |
46 static const uint8 kKeyId1[] = { | 112 |
47 0x4b, 0x65, 0x79, 0x20, 0x49, 0x44, 0x20, 0x31 | 113 // This is the encrypted data from frame 0 of |kWebmEncryptedFrames| except |
| 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 |
48 }; | 122 }; |
49 static const uint8 kKeyId2[] = { | 123 |
50 0x4b, 0x65, 0x79, 0x20, 0x49, 0x44, 0x20, 0x32 | 124 // This is the encrypted data from frame 0 of |kWebmEncryptedFrames| except |
| 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 |
51 }; | 144 }; |
52 | 145 |
53 class AesDecryptorTest : public testing::Test { | 146 class AesDecryptorTest : public testing::Test { |
54 public: | 147 public: |
55 AesDecryptorTest() | 148 AesDecryptorTest() |
56 : decryptor_(&client_), | 149 : decryptor_(&client_), |
57 decrypt_cb_(base::Bind(&AesDecryptorTest::BufferDecrypted, | 150 decrypt_cb_(base::Bind(&AesDecryptorTest::BufferDecrypted, |
58 base::Unretained(this))) { | 151 base::Unretained(this))) { |
59 encrypted_data_ = DecoderBuffer::CopyFrom(kEncryptedData, | |
60 arraysize(kEncryptedData)); | |
61 } | 152 } |
62 | 153 |
63 protected: | 154 protected: |
64 void GenerateKeyRequest() { | 155 // Returns a 16 byte CTR counter block. The CTR counter block format is a |
| 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) { |
65 EXPECT_CALL(client_, KeyMessageMock(kClearKeySystem, StrNe(std::string()), | 202 EXPECT_CALL(client_, KeyMessageMock(kClearKeySystem, StrNe(std::string()), |
66 NotNull(), Gt(0), "")) | 203 NotNull(), Gt(0), "")) |
67 .WillOnce(SaveArg<1>(&session_id_string_)); | 204 .WillOnce(SaveArg<1>(&session_id_string_)); |
68 decryptor_.GenerateKeyRequest(kClearKeySystem, | 205 decryptor_.GenerateKeyRequest(kClearKeySystem, key_id, key_id_size); |
69 kInitData, arraysize(kInitData)); | |
70 } | 206 } |
71 | 207 |
72 template <int KeyIdSize, int KeySize> | 208 void AddKeyAndExpectToSucceed(const uint8* key_id, int key_id_size, |
73 void AddKeyAndExpectToSucceed(const uint8 (&key_id)[KeyIdSize], | 209 const uint8* key, int key_size) { |
74 const uint8 (&key)[KeySize]) { | |
75 EXPECT_CALL(client_, KeyAdded(kClearKeySystem, session_id_string_)); | 210 EXPECT_CALL(client_, KeyAdded(kClearKeySystem, session_id_string_)); |
76 decryptor_.AddKey(kClearKeySystem, key, KeySize, key_id, KeyIdSize, | 211 decryptor_.AddKey(kClearKeySystem, key, key_size, key_id, key_id_size, |
77 session_id_string_); | 212 session_id_string_); |
78 } | 213 } |
79 | 214 |
80 template <int KeyIdSize, int KeySize> | 215 void AddKeyAndExpectToFail(const uint8* key_id, int key_id_size, |
81 void AddKeyAndExpectToFail(const uint8 (&key_id)[KeyIdSize], | 216 const uint8* key, int key_size) { |
82 const uint8 (&key)[KeySize]) { | |
83 EXPECT_CALL(client_, KeyError(kClearKeySystem, session_id_string_, | 217 EXPECT_CALL(client_, KeyError(kClearKeySystem, session_id_string_, |
84 Decryptor::kUnknownError, 0)); | 218 Decryptor::kUnknownError, 0)); |
85 decryptor_.AddKey(kClearKeySystem, key, KeySize, key_id, KeyIdSize, | 219 decryptor_.AddKey(kClearKeySystem, key, key_size, key_id, key_id_size, |
86 session_id_string_); | 220 session_id_string_); |
87 } | 221 } |
88 | 222 |
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 | |
95 MOCK_METHOD2(BufferDecrypted, void(Decryptor::DecryptStatus, | 223 MOCK_METHOD2(BufferDecrypted, void(Decryptor::DecryptStatus, |
96 const scoped_refptr<DecoderBuffer>&)); | 224 const scoped_refptr<DecoderBuffer>&)); |
97 | 225 |
98 void DecryptAndExpectToSucceed() { | 226 void DecryptAndExpectToSucceed(const uint8* data, int data_size, |
| 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); |
99 scoped_refptr<DecoderBuffer> decrypted; | 232 scoped_refptr<DecoderBuffer> decrypted; |
100 EXPECT_CALL(*this, BufferDecrypted(AesDecryptor::kSuccess, NotNull())) | 233 EXPECT_CALL(*this, BufferDecrypted(AesDecryptor::kSuccess, NotNull())) |
101 .WillOnce(SaveArg<1>(&decrypted)); | 234 .WillOnce(SaveArg<1>(&decrypted)); |
102 | 235 |
103 decryptor_.Decrypt(encrypted_data_, decrypt_cb_); | 236 decryptor_.Decrypt(encrypted_data, decrypt_cb_); |
104 ASSERT_TRUE(decrypted); | 237 ASSERT_TRUE(decrypted); |
105 int data_length = sizeof(kOriginalData); | 238 ASSERT_EQ(plain_text_size, decrypted->GetDataSize()); |
106 ASSERT_EQ(data_length, decrypted->GetDataSize()); | 239 EXPECT_EQ(0, memcmp(plain_text, decrypted->GetData(), plain_text_size)); |
107 EXPECT_EQ(0, memcmp(kOriginalData, decrypted->GetData(), data_length)); | |
108 } | 240 } |
109 | 241 |
110 void DecryptAndExpectToFail() { | 242 void DecryptAndExpectToFail(const uint8* data, int data_size, |
| 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); |
111 EXPECT_CALL(*this, BufferDecrypted(AesDecryptor::kError, IsNull())); | 247 EXPECT_CALL(*this, BufferDecrypted(AesDecryptor::kError, IsNull())); |
112 decryptor_.Decrypt(encrypted_data_, decrypt_cb_); | 248 decryptor_.Decrypt(encrypted_data, decrypt_cb_); |
113 } | 249 } |
114 | 250 |
115 scoped_refptr<DecoderBuffer> encrypted_data_; | 251 scoped_refptr<DecoderBuffer> encrypted_data_; |
116 MockDecryptorClient client_; | 252 MockDecryptorClient client_; |
117 AesDecryptor decryptor_; | 253 AesDecryptor decryptor_; |
118 std::string session_id_string_; | 254 std::string session_id_string_; |
119 AesDecryptor::DecryptCB decrypt_cb_; | 255 AesDecryptor::DecryptCB decrypt_cb_; |
120 }; | 256 }; |
121 | 257 |
122 TEST_F(AesDecryptorTest, NormalDecryption) { | 258 TEST_F(AesDecryptorTest, NormalDecryption) { |
123 GenerateKeyRequest(); | 259 const WebmEncryptedData& frame = kWebmEncryptedFrames[0]; |
124 AddKeyAndExpectToSucceed(kKeyId1, kRightKey); | 260 GenerateKeyRequest(frame.key_id, frame.key_id_size); |
125 SetKeyIdForEncryptedData(kKeyId1); | 261 AddKeyAndExpectToSucceed(frame.key_id, frame.key_id_size, |
126 ASSERT_NO_FATAL_FAILURE(DecryptAndExpectToSucceed()); | 262 frame.key, frame.key_size); |
| 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)); |
127 } | 269 } |
128 | 270 |
129 TEST_F(AesDecryptorTest, WrongKey) { | 271 TEST_F(AesDecryptorTest, WrongKey) { |
130 GenerateKeyRequest(); | 272 const WebmEncryptedData& frame = kWebmEncryptedFrames[0]; |
131 AddKeyAndExpectToSucceed(kKeyId1, kWrongKey); | 273 GenerateKeyRequest(frame.key_id, frame.key_id_size); |
132 SetKeyIdForEncryptedData(kKeyId1); | 274 AddKeyAndExpectToSucceed(frame.key_id, frame.key_id_size, |
133 ASSERT_NO_FATAL_FAILURE(DecryptAndExpectToFail()); | 275 kWebmWrongKey, arraysize(kWebmWrongKey)); |
134 } | 276 ASSERT_NO_FATAL_FAILURE(DecryptAndExpectToFail(frame.encrypted_data, |
135 | 277 frame.encrypted_data_size, |
136 TEST_F(AesDecryptorTest, MultipleKeys) { | 278 frame.plain_text, |
137 GenerateKeyRequest(); | 279 frame.plain_text_size, |
138 AddKeyAndExpectToSucceed(kKeyId1, kRightKey); | 280 frame.key_id, |
139 AddKeyAndExpectToSucceed(kKeyId2, kWrongKey); | 281 frame.key_id_size)); |
140 SetKeyIdForEncryptedData(kKeyId1); | |
141 ASSERT_NO_FATAL_FAILURE(DecryptAndExpectToSucceed()); | |
142 } | 282 } |
143 | 283 |
144 TEST_F(AesDecryptorTest, KeyReplacement) { | 284 TEST_F(AesDecryptorTest, KeyReplacement) { |
145 GenerateKeyRequest(); | 285 const WebmEncryptedData& frame = kWebmEncryptedFrames[0]; |
146 SetKeyIdForEncryptedData(kKeyId1); | 286 GenerateKeyRequest(frame.key_id, frame.key_id_size); |
147 AddKeyAndExpectToSucceed(kKeyId1, kWrongKey); | 287 AddKeyAndExpectToSucceed(frame.key_id, frame.key_id_size, |
148 ASSERT_NO_FATAL_FAILURE(DecryptAndExpectToFail()); | 288 kWebmWrongKey, arraysize(kWebmWrongKey)); |
149 AddKeyAndExpectToSucceed(kKeyId1, kRightKey); | 289 ASSERT_NO_FATAL_FAILURE(DecryptAndExpectToFail(frame.encrypted_data, |
150 ASSERT_NO_FATAL_FAILURE(DecryptAndExpectToSucceed()); | 290 frame.encrypted_data_size, |
| 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)); |
151 } | 303 } |
152 | 304 |
153 TEST_F(AesDecryptorTest, WrongSizedKey) { | 305 TEST_F(AesDecryptorTest, WrongSizedKey) { |
154 GenerateKeyRequest(); | 306 const WebmEncryptedData& frame = kWebmEncryptedFrames[0]; |
155 AddKeyAndExpectToFail(kKeyId1, kWrongSizedKey); | 307 GenerateKeyRequest(frame.key_id, frame.key_id_size); |
| 308 AddKeyAndExpectToFail(frame.key_id, frame.key_id_size, |
| 309 kWebmWrongSizedKey, arraysize(kWebmWrongSizedKey)); |
156 } | 310 } |
157 | 311 |
158 } // media | 312 TEST_F(AesDecryptorTest, MultipleKeysAndFrames) { |
| 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 |
OLD | NEW |