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

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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 0xfa, 0x9d, 0x18, 0x43, 0x1e, 0x96, 0x71, 0xb5, 153 0xfa, 0x9d, 0x18, 0x43, 0x1e, 0x96, 0x71, 0xb5,
155 0xbf, 0xf5, 0x30, 0x53, 0x9a, 0x20, 0xdf, 0x95 154 0xbf, 0xf5, 0x30, 0x53, 0x9a, 0x20, 0xdf, 0x95
156 }; 155 };
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 // Generates 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 an 8 byte CTR IV.
166 // the size of |iv| in bytes. 165 // |iv_size| is the size of |iv| in btyes. Returns a string of
166 // kDecryptionKeySize bytes.
167 static std::string GenerateCounterBlock(const uint8* iv, int iv_size) { 167 static std::string GenerateCounterBlock(const uint8* iv, int iv_size) {
168 const int kDecryptionKeySize = 16;
169 CHECK_GT(iv_size, 0); 168 CHECK_GT(iv_size, 0);
170 CHECK_LE(iv_size, kDecryptionKeySize); 169 CHECK_LE(iv_size, DecryptConfig::kDecryptionKeySize);
171 170
172 std::string counter_block(reinterpret_cast<const char*>(iv), iv_size); 171 std::string counter_block(reinterpret_cast<const char*>(iv), iv_size);
173 counter_block.append(kDecryptionKeySize - iv_size, 0); 172 counter_block.append(DecryptConfig::kDecryptionKeySize - iv_size, 0);
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);
189 DCHECK_EQ(kWebMSignalByteSize, 1);
190 190
191 uint8 signal_byte = data[0]; 191 uint8 signal_byte = data[0];
192 int data_offset = sizeof(signal_byte); 192 int data_offset = kWebMSignalByteSize;
193 193
194 // Setting the DecryptConfig object of the buffer while leaving the 194 // Setting the DecryptConfig object of the buffer while leaving the
195 // initialization vector empty will tell the decryptor that the frame is 195 // initialization vector empty will tell the decryptor that the frame is
196 // unencrypted. 196 // unencrypted.
197 std::string counter_block_str; 197 std::string counter_block_str;
198 198
199 if (signal_byte & kWebMFlagEncryptedFrame) { 199 if (signal_byte & kWebMFlagEncryptedFrame) {
200 uint64 network_iv; 200 counter_block_str = GenerateCounterBlock(data + data_offset, kWebMIvSize);
201 memcpy(&network_iv, data + data_offset, sizeof(network_iv)); 201 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 } 202 }
207 203
208 encrypted_buffer->SetDecryptConfig( 204 encrypted_buffer->SetDecryptConfig(
209 scoped_ptr<DecryptConfig>(new DecryptConfig( 205 scoped_ptr<DecryptConfig>(new DecryptConfig(
210 std::string(reinterpret_cast<const char*>(key_id), key_id_size), 206 std::string(reinterpret_cast<const char*>(key_id), key_id_size),
211 counter_block_str, 207 counter_block_str,
212 data_offset, 208 data_offset,
213 std::vector<SubsampleEntry>()))); 209 std::vector<SubsampleEntry>())));
214 return encrypted_buffer; 210 return encrypted_buffer;
215 } 211 }
(...skipping 370 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 | « content/browser/encrypted_media_browsertest.cc ('k') | media/filters/pipeline_integration_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698