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

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

Issue 77413005: Remove support for non-JSON keys in AesDecryptor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add pipeline_integration_tests Created 7 years, 1 month 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
« no previous file with comments | « media/cdm/aes_decryptor.cc ('k') | media/filters/pipeline_integration_test.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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 20 matching lines...) Expand all
31 31
32 // In the examples below, 'k'(key) has to be 16 bytes, and will always require 32 // In the examples below, 'k'(key) has to be 16 bytes, and will always require
33 // 2 bytes of padding. 'kid'(keyid) is variable length, and may require 0, 1, 33 // 2 bytes of padding. 'kid'(keyid) is variable length, and may require 0, 1,
34 // or 2 bytes of padding. 34 // or 2 bytes of padding.
35 35
36 const uint8 kKeyId[] = { 36 const uint8 kKeyId[] = {
37 // base64 equivalent is AAECAw 37 // base64 equivalent is AAECAw
38 0x00, 0x01, 0x02, 0x03 38 0x00, 0x01, 0x02, 0x03
39 }; 39 };
40 40
41 const uint8 kKey[] = { 41 // Key is 0x0405060708090a0b0c0d0e0f10111213,
42 // base64 equivalent is BAUGBwgJCgsMDQ4PEBESEw 42 // base64 equivalent is BAUGBwgJCgsMDQ4PEBESEw.
43 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
44 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13
45 };
46
47 const char kKeyAsJWK[] = 43 const char kKeyAsJWK[] =
48 "{" 44 "{"
49 " \"keys\": [" 45 " \"keys\": ["
50 " {" 46 " {"
51 " \"kty\": \"oct\"," 47 " \"kty\": \"oct\","
52 " \"kid\": \"AAECAw\"," 48 " \"kid\": \"AAECAw\","
53 " \"k\": \"BAUGBwgJCgsMDQ4PEBESEw\"" 49 " \"k\": \"BAUGBwgJCgsMDQ4PEBESEw\""
54 " }" 50 " }"
55 " ]" 51 " ]"
56 "}"; 52 "}";
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 EXPECT_CALL(*this, KeyMessage(reference_id_, key_id, "")); 214 EXPECT_CALL(*this, KeyMessage(reference_id_, key_id, ""));
219 EXPECT_TRUE(decryptor_.GenerateKeyRequest( 215 EXPECT_TRUE(decryptor_.GenerateKeyRequest(
220 reference_id_, std::string(), &key_id[0], key_id.size())); 216 reference_id_, std::string(), &key_id[0], key_id.size()));
221 } 217 }
222 218
223 enum AddKeyExpectation { 219 enum AddKeyExpectation {
224 KEY_ADDED, 220 KEY_ADDED,
225 KEY_ERROR 221 KEY_ERROR
226 }; 222 };
227 223
228 void AddRawKeyAndExpect(const std::vector<uint8>& key_id,
229 const std::vector<uint8>& key,
230 AddKeyExpectation result) {
231 // TODO(jrummell): Remove once raw keys no longer supported.
232 DCHECK(!key_id.empty());
233 DCHECK(!key.empty());
234
235 if (result == KEY_ADDED) {
236 EXPECT_CALL(*this, KeyAdded(reference_id_));
237 } else if (result == KEY_ERROR) {
238 EXPECT_CALL(*this, KeyError(reference_id_, MediaKeys::kUnknownError, 0));
239 } else {
240 NOTREACHED();
241 }
242
243 decryptor_.AddKey(
244 reference_id_, &key[0], key.size(), &key_id[0], key_id.size());
245 }
246
247 void AddKeyAndExpect(const std::string& key, AddKeyExpectation result) { 224 void AddKeyAndExpect(const std::string& key, AddKeyExpectation result) {
248 DCHECK(!key.empty()); 225 DCHECK(!key.empty());
249 226
250 if (result == KEY_ADDED) { 227 if (result == KEY_ADDED) {
251 EXPECT_CALL(*this, KeyAdded(reference_id_)); 228 EXPECT_CALL(*this, KeyAdded(reference_id_));
252 } else if (result == KEY_ERROR) { 229 } else if (result == KEY_ERROR) {
253 EXPECT_CALL(*this, KeyError(reference_id_, MediaKeys::kUnknownError, 0)); 230 EXPECT_CALL(*this, KeyError(reference_id_, MediaKeys::kUnknownError, 0));
254 } else { 231 } else {
255 NOTREACHED(); 232 NOTREACHED();
256 } 233 }
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 encrypted_buffer, original_data_, DATA_MISMATCH)); 386 encrypted_buffer, original_data_, DATA_MISMATCH));
410 387
411 AddKeyAndExpect(kKeyAsJWK, KEY_ADDED); 388 AddKeyAndExpect(kKeyAsJWK, KEY_ADDED);
412 ASSERT_NO_FATAL_FAILURE( 389 ASSERT_NO_FATAL_FAILURE(
413 DecryptAndExpect(encrypted_buffer, original_data_, SUCCESS)); 390 DecryptAndExpect(encrypted_buffer, original_data_, SUCCESS));
414 } 391 }
415 392
416 TEST_F(AesDecryptorTest, WrongSizedKey) { 393 TEST_F(AesDecryptorTest, WrongSizedKey) {
417 GenerateKeyRequest(key_id_); 394 GenerateKeyRequest(key_id_);
418 AddKeyAndExpect(kWrongSizedKeyAsJWK, KEY_ERROR); 395 AddKeyAndExpect(kWrongSizedKeyAsJWK, KEY_ERROR);
419
420 // Repeat for a raw key. Use "-1" to create a wrong sized key.
421 std::vector<uint8> wrong_sized_key(kKey, kKey + arraysize(kKey) - 1);
422 AddRawKeyAndExpect(key_id_, wrong_sized_key, KEY_ERROR);
423 } 396 }
424 397
425 TEST_F(AesDecryptorTest, MultipleKeysAndFrames) { 398 TEST_F(AesDecryptorTest, MultipleKeysAndFrames) {
426 GenerateKeyRequest(key_id_); 399 GenerateKeyRequest(key_id_);
427 AddKeyAndExpect(kKeyAsJWK, KEY_ADDED); 400 AddKeyAndExpect(kKeyAsJWK, KEY_ADDED);
428 scoped_refptr<DecoderBuffer> encrypted_buffer = CreateEncryptedBuffer( 401 scoped_refptr<DecoderBuffer> encrypted_buffer = CreateEncryptedBuffer(
429 encrypted_data_, key_id_, iv_, 10, no_subsample_entries_); 402 encrypted_data_, key_id_, iv_, 10, no_subsample_entries_);
430 ASSERT_NO_FATAL_FAILURE( 403 ASSERT_NO_FATAL_FAILURE(
431 DecryptAndExpect(encrypted_buffer, original_data_, SUCCESS)); 404 DecryptAndExpect(encrypted_buffer, original_data_, SUCCESS));
432 405
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 " {" 653 " {"
681 " \"kty\": \"oct\"," 654 " \"kty\": \"oct\","
682 " \"kid\": \"\"," 655 " \"kid\": \"\","
683 " \"k\": \"BAUGBwgJCgsMDQ4PEBESEw\"" 656 " \"k\": \"BAUGBwgJCgsMDQ4PEBESEw\""
684 " }" 657 " }"
685 " ]" 658 " ]"
686 "}"; 659 "}";
687 AddKeyAndExpect(key8, KEY_ERROR); 660 AddKeyAndExpect(key8, KEY_ERROR);
688 } 661 }
689 662
690 TEST_F(AesDecryptorTest, RawKey) {
691 // Verify that v0.1b keys (raw key) is still supported. Raw keys are
692 // 16 bytes long. Use the undecoded value of |kKey|.
693 GenerateKeyRequest(key_id_);
694 AddRawKeyAndExpect(
695 key_id_, std::vector<uint8>(kKey, kKey + arraysize(kKey)), KEY_ADDED);
696 scoped_refptr<DecoderBuffer> encrypted_buffer = CreateEncryptedBuffer(
697 encrypted_data_, key_id_, iv_, 0, no_subsample_entries_);
698 DecryptAndExpect(encrypted_buffer, original_data_, SUCCESS);
699 }
700
701 } // namespace media 663 } // namespace media
OLDNEW
« no previous file with comments | « media/cdm/aes_decryptor.cc ('k') | media/filters/pipeline_integration_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698