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

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

Issue 11434025: Encrypted Media: Handle empty init_data in AesDecryptor::GenerateKeyRequest(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove KeyMessage in AesDecryptor::GKR() Created 8 years 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') | no next file » | 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 #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"
11 #include "media/base/decrypt_config.h" 11 #include "media/base/decrypt_config.h"
12 #include "media/base/mock_filters.h" 12 #include "media/base/mock_filters.h"
13 #include "media/crypto/aes_decryptor.h" 13 #include "media/crypto/aes_decryptor.h"
14 #include "media/webm/webm_constants.h" 14 #include "media/webm/webm_constants.h"
15 #include "testing/gmock/include/gmock/gmock.h" 15 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
17 17
18 using ::testing::_; 18 using ::testing::_;
19 using ::testing::Gt; 19 using ::testing::Gt;
20 using ::testing::IsNull; 20 using ::testing::IsNull;
21 using ::testing::NotNull; 21 using ::testing::NotNull;
22 using ::testing::SaveArg; 22 using ::testing::SaveArg;
23 using ::testing::StrNe; 23 using ::testing::StrNe;
24 24
25 namespace media { 25 namespace media {
26 26
27 MATCHER_P2(ArrayEq, array, size, "") {
28 return !memcmp(arg, array, size);
29 }
30
27 // |encrypted_data| is encrypted from |plain_text| using |key|. |key_id| is 31 // |encrypted_data| is encrypted from |plain_text| using |key|. |key_id| is
28 // used to distinguish |key|. 32 // used to distinguish |key|.
29 struct WebmEncryptedData { 33 struct WebmEncryptedData {
30 uint8 plain_text[32]; 34 uint8 plain_text[32];
31 int plain_text_size; 35 int plain_text_size;
32 uint8 key_id[32]; 36 uint8 key_id[32];
33 int key_id_size; 37 int key_id_size;
34 uint8 key[32]; 38 uint8 key[32];
35 int key_size; 39 int key_size;
36 uint8 encrypted_data[64]; 40 uint8 encrypted_data[64];
(...skipping 15 matching lines...) Expand all
52 }, 20, 56 }, 20,
53 // key 57 // key
54 { 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 58 { 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b,
55 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23 59 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23
56 }, 16, 60 }, 16,
57 // encrypted_data 61 // encrypted_data
58 { 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 62 { 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
59 0xff, 0xf0, 0xd1, 0x12, 0xd5, 0x24, 0x81, 0x96, 63 0xff, 0xf0, 0xd1, 0x12, 0xd5, 0x24, 0x81, 0x96,
60 0x55, 0x1b, 0x68, 0x9f, 0x38, 0x91, 0x85 64 0x55, 0x1b, 0x68, 0x9f, 0x38, 0x91, 0x85
61 }, 23 65 }, 23
62 }, 66 }, {
63 {
64 // plaintext 67 // plaintext
65 "Changed Original data.", 22, 68 "Changed Original data.", 22,
66 // key_id 69 // key_id
67 { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 70 { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
68 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 71 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
69 0x10, 0x11, 0x12, 0x13 72 0x10, 0x11, 0x12, 0x13
70 }, 20, 73 }, 20,
71 // key 74 // key
72 { 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 75 { 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b,
73 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23 76 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23
74 }, 16, 77 }, 16,
75 // encrypted_data 78 // encrypted_data
76 { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 79 { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
77 0x00, 0x57, 0x66, 0xf4, 0x12, 0x1a, 0xed, 0xb5, 80 0x00, 0x57, 0x66, 0xf4, 0x12, 0x1a, 0xed, 0xb5,
78 0x79, 0x1c, 0x8e, 0x25, 0xd7, 0x17, 0xe7, 0x5e, 81 0x79, 0x1c, 0x8e, 0x25, 0xd7, 0x17, 0xe7, 0x5e,
79 0x16, 0xe3, 0x40, 0x08, 0x27, 0x11, 0xe9 82 0x16, 0xe3, 0x40, 0x08, 0x27, 0x11, 0xe9
80 }, 31 83 }, 31
81 }, 84 }, {
82 {
83 // plaintext 85 // plaintext
84 "Original data.", 14, 86 "Original data.", 14,
85 // key_id 87 // key_id
86 { 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 88 { 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b,
87 0x2c, 0x2d, 0x2e, 0x2f, 0x30 89 0x2c, 0x2d, 0x2e, 0x2f, 0x30
88 }, 13, 90 }, 13,
89 // key 91 // key
90 { 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 92 { 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38,
91 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40 93 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40
92 }, 16, 94 }, 16,
93 // encrypted_data 95 // encrypted_data
94 { 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 96 { 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
95 0x00, 0x9c, 0x71, 0x26, 0x57, 0x3e, 0x25, 0x37, 97 0x00, 0x9c, 0x71, 0x26, 0x57, 0x3e, 0x25, 0x37,
96 0xf7, 0x31, 0x81, 0x19, 0x64, 0xce, 0xbc 98 0xf7, 0x31, 0x81, 0x19, 0x64, 0xce, 0xbc
97 }, 23 99 }, 23
98 }, 100 }, {
99 {
100 // plaintext 101 // plaintext
101 "Changed Original data.", 22, 102 "Changed Original data.", 22,
102 // key_id 103 // key_id
103 { 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 104 { 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b,
104 0x2c, 0x2d, 0x2e, 0x2f, 0x30 105 0x2c, 0x2d, 0x2e, 0x2f, 0x30
105 }, 13, 106 }, 13,
106 // key 107 // key
107 { 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 108 { 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38,
108 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40 109 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40
109 }, 16, 110 }, 16,
110 // encrypted_data 111 // encrypted_data
111 { 0x00, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x64, 112 { 0x00, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x64,
112 0x20, 0x4f, 0x72, 0x69, 0x67, 0x69, 0x6e, 0x61, 113 0x20, 0x4f, 0x72, 0x69, 0x67, 0x69, 0x6e, 0x61,
113 0x6c, 0x20, 0x64, 0x61, 0x74, 0x61, 0x2e 114 0x6c, 0x20, 0x64, 0x61, 0x74, 0x61, 0x2e
114 }, 23 115 }, 23
115 } 116 }
116 }; 117 };
117 118
118
119
120 static const uint8 kWebmWrongSizedKey[] = { 0x20, 0x20 }; 119 static const uint8 kWebmWrongSizedKey[] = { 0x20, 0x20 };
121 120
122 static const uint8 kSubsampleOriginalData[] = "Original subsample data."; 121 static const uint8 kSubsampleOriginalData[] = "Original subsample data.";
123 static const int kSubsampleOriginalDataSize = 24; 122 static const int kSubsampleOriginalDataSize = 24;
124 123
125 static const uint8 kSubsampleKeyId[] = { 0x00, 0x01, 0x02, 0x03 }; 124 static const uint8 kSubsampleKeyId[] = { 0x00, 0x01, 0x02, 0x03 };
126 125
127 static const uint8 kSubsampleKey[] = { 126 static const uint8 kSubsampleKey[] = {
128 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 127 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
129 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13 128 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 : decryptor_(&client_), 233 : decryptor_(&client_),
235 decrypt_cb_(base::Bind(&AesDecryptorTest::BufferDecrypted, 234 decrypt_cb_(base::Bind(&AesDecryptorTest::BufferDecrypted,
236 base::Unretained(this))), 235 base::Unretained(this))),
237 subsample_entries_(kSubsampleEntries, 236 subsample_entries_(kSubsampleEntries,
238 kSubsampleEntries + arraysize(kSubsampleEntries)) { 237 kSubsampleEntries + arraysize(kSubsampleEntries)) {
239 } 238 }
240 239
241 protected: 240 protected:
242 void GenerateKeyRequest(const uint8* key_id, int key_id_size) { 241 void GenerateKeyRequest(const uint8* key_id, int key_id_size) {
243 EXPECT_CALL(client_, KeyMessageMock(kClearKeySystem, StrNe(""), 242 EXPECT_CALL(client_, KeyMessageMock(kClearKeySystem, StrNe(""),
244 NotNull(), Gt(0), "")) 243 ArrayEq(key_id, key_id_size),
244 key_id_size, ""))
245 .WillOnce(SaveArg<1>(&session_id_string_)); 245 .WillOnce(SaveArg<1>(&session_id_string_));
246 EXPECT_TRUE(decryptor_.GenerateKeyRequest(kClearKeySystem, "", 246 EXPECT_TRUE(decryptor_.GenerateKeyRequest(kClearKeySystem, "",
247 key_id, key_id_size)); 247 key_id, key_id_size));
248 } 248 }
249 249
250 void AddKeyAndExpectToSucceed(const uint8* key_id, int key_id_size, 250 void AddKeyAndExpectToSucceed(const uint8* key_id, int key_id_size,
251 const uint8* key, int key_size) { 251 const uint8* key, int key_size) {
252 EXPECT_CALL(client_, KeyAdded(kClearKeySystem, session_id_string_)); 252 EXPECT_CALL(client_, KeyAdded(kClearKeySystem, session_id_string_));
253 decryptor_.AddKey(kClearKeySystem, key, key_size, key_id, key_id_size, 253 decryptor_.AddKey(kClearKeySystem, key, key_size, key_id, key_id_size,
254 session_id_string_); 254 session_id_string_);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 decryptor_.Decrypt(Decryptor::kVideo, encrypted, decrypt_cb_); 308 decryptor_.Decrypt(Decryptor::kVideo, encrypted, decrypt_cb_);
309 } 309 }
310 310
311 MockDecryptorClient client_; 311 MockDecryptorClient client_;
312 AesDecryptor decryptor_; 312 AesDecryptor decryptor_;
313 std::string session_id_string_; 313 std::string session_id_string_;
314 AesDecryptor::DecryptCB decrypt_cb_; 314 AesDecryptor::DecryptCB decrypt_cb_;
315 std::vector<SubsampleEntry> subsample_entries_; 315 std::vector<SubsampleEntry> subsample_entries_;
316 }; 316 };
317 317
318 TEST_F(AesDecryptorTest, GenerateKeyRequestWithNullInitData) {
319 EXPECT_FALSE(decryptor_.GenerateKeyRequest(kClearKeySystem, "", NULL, 0));
320 }
321
318 TEST_F(AesDecryptorTest, NormalWebMDecryption) { 322 TEST_F(AesDecryptorTest, NormalWebMDecryption) {
319 const WebmEncryptedData& frame = kWebmEncryptedFrames[0]; 323 const WebmEncryptedData& frame = kWebmEncryptedFrames[0];
320 GenerateKeyRequest(frame.key_id, frame.key_id_size); 324 GenerateKeyRequest(frame.key_id, frame.key_id_size);
321 AddKeyAndExpectToSucceed(frame.key_id, frame.key_id_size, 325 AddKeyAndExpectToSucceed(frame.key_id, frame.key_id_size,
322 frame.key, frame.key_size); 326 frame.key, frame.key_size);
323 scoped_refptr<DecoderBuffer> encrypted_data = 327 scoped_refptr<DecoderBuffer> encrypted_data =
324 CreateWebMEncryptedBuffer(frame.encrypted_data, 328 CreateWebMEncryptedBuffer(frame.encrypted_data,
325 frame.encrypted_data_size, 329 frame.encrypted_data_size,
326 frame.key_id, frame.key_id_size); 330 frame.key_id, frame.key_id_size);
327 ASSERT_NO_FATAL_FAILURE(DecryptAndExpectToSucceed(encrypted_data, 331 ASSERT_NO_FATAL_FAILURE(DecryptAndExpectToSucceed(encrypted_data,
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 scoped_refptr<DecoderBuffer> encrypted_data = CreateSubsampleEncryptedBuffer( 586 scoped_refptr<DecoderBuffer> encrypted_data = CreateSubsampleEncryptedBuffer(
583 kSubsampleData, arraysize(kSubsampleData), 587 kSubsampleData, arraysize(kSubsampleData),
584 kSubsampleKeyId, arraysize(kSubsampleKeyId), 588 kSubsampleKeyId, arraysize(kSubsampleKeyId),
585 kSubsampleIv, arraysize(kSubsampleIv), 589 kSubsampleIv, arraysize(kSubsampleIv),
586 0, 590 0,
587 entries); 591 entries);
588 ASSERT_NO_FATAL_FAILURE(DecryptAndExpectToFail(encrypted_data)); 592 ASSERT_NO_FATAL_FAILURE(DecryptAndExpectToFail(encrypted_data));
589 } 593 }
590 594
591 } // namespace media 595 } // namespace media
OLDNEW
« no previous file with comments | « media/crypto/aes_decryptor.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698