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

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: Addressing comments. 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"
11 #include "media/base/decoder_buffer.h" 10 #include "media/base/decoder_buffer.h"
12 #include "media/base/decrypt_config.h" 11 #include "media/base/decrypt_config.h"
13 #include "media/base/mock_filters.h" 12 #include "media/base/mock_filters.h"
14 #include "media/crypto/aes_decryptor.h" 13 #include "media/crypto/aes_decryptor.h"
15 #include "media/webm/webm_constants.h" 14 #include "media/webm/webm_constants.h"
16 #include "testing/gmock/include/gmock/gmock.h" 15 #include "testing/gmock/include/gmock/gmock.h"
17 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
18 17
19 using ::testing::_; 18 using ::testing::_;
20 using ::testing::Gt; 19 using ::testing::Gt;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 "Original data.", 14, 84 "Original data.", 14,
86 // key_id 85 // key_id
87 { 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 86 { 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b,
88 0x2c, 0x2d, 0x2e, 0x2f, 0x30 87 0x2c, 0x2d, 0x2e, 0x2f, 0x30
89 }, 13, 88 }, 13,
90 // key 89 // key
91 { 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 90 { 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38,
92 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40 91 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40
93 }, 16, 92 }, 16,
94 // encrypted_data 93 // encrypted_data
95 { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 94 { 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
96 0x01, 0x9c, 0x71, 0x26, 0x57, 0x3e, 0x25, 0x37, 95 0x00, 0x9c, 0x71, 0x26, 0x57, 0x3e, 0x25, 0x37,
97 0xf7, 0x31, 0x81, 0x19, 0x64, 0xce, 0xbc 96 0xf7, 0x31, 0x81, 0x19, 0x64, 0xce, 0xbc
98 }, 23 97 }, 23
99 }, 98 },
100 { 99 {
101 // plaintext 100 // plaintext
102 "Changed Original data.", 22, 101 "Changed Original data.", 22,
103 // key_id 102 // key_id
104 { 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 103 { 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b,
105 0x2c, 0x2d, 0x2e, 0x2f, 0x30 104 0x2c, 0x2d, 0x2e, 0x2f, 0x30
106 }, 13, 105 }, 13,
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 156
158 static const SubsampleEntry kSubsampleEntries[] = { 157 static const SubsampleEntry kSubsampleEntries[] = {
159 { 2, 7 }, 158 { 2, 7 },
160 { 3, 11 }, 159 { 3, 11 },
161 { 1, 0 } 160 { 1, 0 }
162 }; 161 };
163 162
164 // Returns a 16 byte CTR counter block. The CTR counter block format is a 163 // 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 164 // CTR IV appended with a CTR block counter. |iv| is a CTR IV. |iv_size| is
166 // the size of |iv| in bytes. 165 // the size of |iv| in bytes.
167 static std::string GenerateCounterBlock(const uint8* iv, int iv_size) { 166 static std::string GenerateCounterBlock(const uint8* iv, size_t iv_size) {
168 const int kDecryptionKeySize = 16; 167 CHECK_GT(iv_size, 0UL);
169 CHECK_GT(iv_size, 0); 168 CHECK_LE(iv_size, static_cast<size_t>(DecryptConfig::kDecryptionKeySize));
170 CHECK_LE(iv_size, kDecryptionKeySize);
171 169
172 std::string counter_block(reinterpret_cast<const char*>(iv), iv_size); 170 std::string counter_block(reinterpret_cast<const char*>(iv), iv_size);
173 counter_block.append(kDecryptionKeySize - iv_size, 0); 171 counter_block.append(DecryptConfig::kDecryptionKeySize - iv_size, 0);
174 return counter_block; 172 return counter_block;
175 } 173 }
176 174
177 // Creates a WebM encrypted buffer that the demuxer would pass to the 175 // 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 176 // decryptor. |data| is the payload of a WebM encrypted Block. |key_id| is
179 // initialization data from the WebM file. Every encrypted Block has 177 // 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 178 // 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 179 // prepended to the Block. Current encrypted WebM request for comments
182 // specification is here 180 // specification is here
183 // http://wiki.webmproject.org/encryption/webm-encryption-rfc 181 // http://wiki.webmproject.org/encryption/webm-encryption-rfc
184 static scoped_refptr<DecoderBuffer> CreateWebMEncryptedBuffer( 182 static scoped_refptr<DecoderBuffer> CreateWebMEncryptedBuffer(
185 const uint8* data, int data_size, 183 const uint8* data, int data_size,
186 const uint8* key_id, int key_id_size) { 184 const uint8* key_id, int key_id_size) {
187 scoped_refptr<DecoderBuffer> encrypted_buffer = DecoderBuffer::CopyFrom( 185 scoped_refptr<DecoderBuffer> encrypted_buffer = DecoderBuffer::CopyFrom(
188 data, data_size); 186 data, data_size);
189 CHECK(encrypted_buffer); 187 CHECK(encrypted_buffer);
190 188
191 uint8 signal_byte = data[0]; 189 uint8 signal_byte = data[0];
192 int data_offset = sizeof(signal_byte); 190 int data_offset = sizeof(signal_byte);
193 191
194 // Setting the DecryptConfig object of the buffer while leaving the 192 // Setting the DecryptConfig object of the buffer while leaving the
195 // initialization vector empty will tell the decryptor that the frame is 193 // initialization vector empty will tell the decryptor that the frame is
196 // unencrypted. 194 // unencrypted.
197 std::string counter_block_str; 195 std::string counter_block_str;
198 196
199 if (signal_byte & kWebMFlagEncryptedFrame) { 197 if (signal_byte & kWebMFlagEncryptedFrame) {
200 uint64 network_iv; 198 counter_block_str = GenerateCounterBlock(data + data_offset, kWebMIvSize);
201 memcpy(&network_iv, data + data_offset, sizeof(network_iv)); 199 data_offset += kWebMIvSize;
202 const uint64 iv = base::NetToHost64(network_iv);
203 counter_block_str =
204 GenerateCounterBlock(reinterpret_cast<const uint8*>(&iv), sizeof(iv));
205 data_offset += sizeof(iv);
206 } 200 }
207 201
208 encrypted_buffer->SetDecryptConfig( 202 encrypted_buffer->SetDecryptConfig(
209 scoped_ptr<DecryptConfig>(new DecryptConfig( 203 scoped_ptr<DecryptConfig>(new DecryptConfig(
210 std::string(reinterpret_cast<const char*>(key_id), key_id_size), 204 std::string(reinterpret_cast<const char*>(key_id), key_id_size),
211 counter_block_str, 205 counter_block_str,
212 data_offset, 206 data_offset,
213 std::vector<SubsampleEntry>()))); 207 std::vector<SubsampleEntry>())));
214 return encrypted_buffer; 208 return encrypted_buffer;
215 } 209 }
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 scoped_refptr<DecoderBuffer> encrypted_data = CreateSubsampleEncryptedBuffer( 580 scoped_refptr<DecoderBuffer> encrypted_data = CreateSubsampleEncryptedBuffer(
587 kSubsampleData, arraysize(kSubsampleData), 581 kSubsampleData, arraysize(kSubsampleData),
588 kSubsampleKeyId, arraysize(kSubsampleKeyId), 582 kSubsampleKeyId, arraysize(kSubsampleKeyId),
589 kSubsampleIv, arraysize(kSubsampleIv), 583 kSubsampleIv, arraysize(kSubsampleIv),
590 0, 584 0,
591 entries); 585 entries);
592 ASSERT_NO_FATAL_FAILURE(DecryptAndExpectToFail(encrypted_data)); 586 ASSERT_NO_FATAL_FAILURE(DecryptAndExpectToFail(encrypted_data));
593 } 587 }
594 588
595 } // namespace media 589 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698