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

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

Issue 11139008: Change WebM parser to treat IVs from encrypted WebM as raw data. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 2 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
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 "base/sys_byteorder.h" 10 #include "base/sys_byteorder.h"
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 "Original data.", 14, 85 "Original data.", 14,
86 // key_id 86 // key_id
87 { 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 87 { 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b,
88 0x2c, 0x2d, 0x2e, 0x2f, 0x30 88 0x2c, 0x2d, 0x2e, 0x2f, 0x30
89 }, 13, 89 }, 13,
90 // key 90 // key
91 { 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 91 { 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38,
92 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40 92 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40
93 }, 16, 93 }, 16,
94 // encrypted_data 94 // encrypted_data
95 { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 95 { 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
96 0x01, 0x9c, 0x71, 0x26, 0x57, 0x3e, 0x25, 0x37, 96 0x00, 0x9c, 0x71, 0x26, 0x57, 0x3e, 0x25, 0x37,
97 0xf7, 0x31, 0x81, 0x19, 0x64, 0xce, 0xbc 97 0xf7, 0x31, 0x81, 0x19, 0x64, 0xce, 0xbc
98 }, 23 98 }, 23
99 }, 99 },
100 { 100 {
101 // plaintext 101 // plaintext
102 "Changed Original data.", 22, 102 "Changed Original data.", 22,
103 // key_id 103 // key_id
104 { 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 104 { 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b,
105 0x2c, 0x2d, 0x2e, 0x2f, 0x30 105 0x2c, 0x2d, 0x2e, 0x2f, 0x30
106 }, 13, 106 }, 13,
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 157
158 static const SubsampleEntry kSubsampleEntries[] = { 158 static const SubsampleEntry kSubsampleEntries[] = {
159 { 2, 7 }, 159 { 2, 7 },
160 { 3, 11 }, 160 { 3, 11 },
161 { 1, 0 } 161 { 1, 0 }
162 }; 162 };
163 163
164 // Returns a 16 byte CTR counter block. The CTR counter block format is a 164 // Returns a 16 byte CTR counter block. The CTR counter block format is a
165 // CTR IV appended with a CTR block counter. |iv| is a CTR IV. |iv_size| is 165 // CTR IV appended with a CTR block counter. |iv| is a CTR IV. |iv_size| is
166 // the size of |iv| in bytes. 166 // the size of |iv| in bytes.
167 static std::string GenerateCounterBlock(const uint8* iv, int iv_size) { 167 static std::string GenerateCounterBlock(const std::string& iv) {
168 const int kDecryptionKeySize = 16; 168 CHECK_GT(iv.size(), 0UL);
169 CHECK_GT(iv_size, 0); 169 CHECK_LE(iv.size(), static_cast<size_t>(DecryptConfig::kDecryptionKeySize));
170 CHECK_LE(iv_size, kDecryptionKeySize);
171 170
172 std::string counter_block(reinterpret_cast<const char*>(iv), iv_size); 171 std::string counter_block(iv);
173 counter_block.append(kDecryptionKeySize - iv_size, 0); 172 counter_block.append(DecryptConfig::kDecryptionKeySize - iv.size(), 0);
ddorwin 2012/10/13 00:26:17 Why wasn't the scoping necessary before?
fgalligan1 2012/10/13 06:20:31 The old version defined the value at the top of th
174 return counter_block; 173 return counter_block;
175 } 174 }
176 175
177 // Creates a WebM encrypted buffer that the demuxer would pass to the 176 // Creates a WebM encrypted buffer that the demuxer would pass to the
178 // decryptor. |data| is the payload of a WebM encrypted Block. |key_id| is 177 // decryptor. |data| is the payload of a WebM encrypted Block. |key_id| is
179 // initialization data from the WebM file. Every encrypted Block has 178 // initialization data from the WebM file. Every encrypted Block has
180 // a signal byte prepended to a frame. If the frame is encrypted then an IV is 179 // a signal byte prepended to a frame. If the frame is encrypted then an IV is
181 // prepended to the Block. Current encrypted WebM request for comments 180 // prepended to the Block. Current encrypted WebM request for comments
182 // specification is here 181 // specification is here
183 // http://wiki.webmproject.org/encryption/webm-encryption-rfc 182 // http://wiki.webmproject.org/encryption/webm-encryption-rfc
184 static scoped_refptr<DecoderBuffer> CreateWebMEncryptedBuffer( 183 static scoped_refptr<DecoderBuffer> CreateWebMEncryptedBuffer(
185 const uint8* data, int data_size, 184 const uint8* data, int data_size,
186 const uint8* key_id, int key_id_size) { 185 const uint8* key_id, int key_id_size) {
187 scoped_refptr<DecoderBuffer> encrypted_buffer = DecoderBuffer::CopyFrom( 186 scoped_refptr<DecoderBuffer> encrypted_buffer = DecoderBuffer::CopyFrom(
188 data, data_size); 187 data, data_size);
189 CHECK(encrypted_buffer); 188 CHECK(encrypted_buffer);
190 189
191 uint8 signal_byte = data[0]; 190 uint8 signal_byte = data[0];
192 int data_offset = sizeof(signal_byte); 191 int data_offset = sizeof(signal_byte);
193 192
194 // Setting the DecryptConfig object of the buffer while leaving the 193 // Setting the DecryptConfig object of the buffer while leaving the
195 // initialization vector empty will tell the decryptor that the frame is 194 // initialization vector empty will tell the decryptor that the frame is
196 // unencrypted. 195 // unencrypted.
197 std::string counter_block_str; 196 std::string counter_block_str;
198 197
199 if (signal_byte & kWebMFlagEncryptedFrame) { 198 if (signal_byte & kWebMFlagEncryptedFrame) {
200 uint64 network_iv; 199 const std::string iv(reinterpret_cast<const char*>(data + data_offset),
201 memcpy(&network_iv, data + data_offset, sizeof(network_iv)); 200 kWebMIvSize);
202 const uint64 iv = base::NetToHost64(network_iv); 201 data_offset += kWebMIvSize;
203 counter_block_str = 202 counter_block_str = GenerateCounterBlock(iv);
204 GenerateCounterBlock(reinterpret_cast<const uint8*>(&iv), sizeof(iv));
205 data_offset += sizeof(iv);
206 } 203 }
207 204
208 encrypted_buffer->SetDecryptConfig( 205 encrypted_buffer->SetDecryptConfig(
209 scoped_ptr<DecryptConfig>(new DecryptConfig( 206 scoped_ptr<DecryptConfig>(new DecryptConfig(
210 std::string(reinterpret_cast<const char*>(key_id), key_id_size), 207 std::string(reinterpret_cast<const char*>(key_id), key_id_size),
211 counter_block_str, 208 counter_block_str,
212 data_offset, 209 data_offset,
213 std::vector<SubsampleEntry>()))); 210 std::vector<SubsampleEntry>())));
214 return encrypted_buffer; 211 return encrypted_buffer;
215 } 212 }
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 frame2.key, frame2.key_size); 424 frame2.key, frame2.key_size);
428 425
429 const WebmEncryptedData& frame1 = kWebmEncryptedFrames[1]; 426 const WebmEncryptedData& frame1 = kWebmEncryptedFrames[1];
430 scoped_refptr<DecoderBuffer> encrypted_data1 = 427 scoped_refptr<DecoderBuffer> encrypted_data1 =
431 CreateWebMEncryptedBuffer(frame1.encrypted_data, 428 CreateWebMEncryptedBuffer(frame1.encrypted_data,
432 frame1.encrypted_data_size, 429 frame1.encrypted_data_size,
433 frame1.key_id, frame1.key_id_size); 430 frame1.key_id, frame1.key_id_size);
434 ASSERT_NO_FATAL_FAILURE(DecryptAndExpectToSucceed(encrypted_data1, 431 ASSERT_NO_FATAL_FAILURE(DecryptAndExpectToSucceed(encrypted_data1,
435 frame1.plain_text, 432 frame1.plain_text,
436 frame1.plain_text_size)); 433 frame1.plain_text_size));
437
438 scoped_refptr<DecoderBuffer> encrypted_data2 = 434 scoped_refptr<DecoderBuffer> encrypted_data2 =
ddorwin 2012/10/13 00:26:17 Is there a reason the empty line was removed?
fgalligan1 2012/10/13 06:20:31 No. I'll put it back to make less noise.
439 CreateWebMEncryptedBuffer(frame2.encrypted_data, 435 CreateWebMEncryptedBuffer(frame2.encrypted_data,
440 frame2.encrypted_data_size, 436 frame2.encrypted_data_size,
441 frame2.key_id, frame2.key_id_size); 437 frame2.key_id, frame2.key_id_size);
442 ASSERT_NO_FATAL_FAILURE(DecryptAndExpectToSucceed(encrypted_data2, 438 ASSERT_NO_FATAL_FAILURE(DecryptAndExpectToSucceed(encrypted_data2,
443 frame2.plain_text, 439 frame2.plain_text,
444 frame2.plain_text_size)); 440 frame2.plain_text_size));
445 } 441 }
446 442
447 TEST_F(AesDecryptorTest, CorruptedIv) { 443 TEST_F(AesDecryptorTest, CorruptedIv) {
448 const WebmEncryptedData& frame = kWebmEncryptedFrames[0]; 444 const WebmEncryptedData& frame = kWebmEncryptedFrames[0];
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 scoped_refptr<DecoderBuffer> encrypted_data = CreateSubsampleEncryptedBuffer( 582 scoped_refptr<DecoderBuffer> encrypted_data = CreateSubsampleEncryptedBuffer(
587 kSubsampleData, arraysize(kSubsampleData), 583 kSubsampleData, arraysize(kSubsampleData),
588 kSubsampleKeyId, arraysize(kSubsampleKeyId), 584 kSubsampleKeyId, arraysize(kSubsampleKeyId),
589 kSubsampleIv, arraysize(kSubsampleIv), 585 kSubsampleIv, arraysize(kSubsampleIv),
590 0, 586 0,
591 entries); 587 entries);
592 ASSERT_NO_FATAL_FAILURE(DecryptAndExpectToFail(encrypted_data)); 588 ASSERT_NO_FATAL_FAILURE(DecryptAndExpectToFail(encrypted_data));
593 } 589 }
594 590
595 } // namespace media 591 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | media/filters/pipeline_integration_test.cc » ('j') | media/webm/webm_cluster_parser.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698