diff options
author | fgalligan@chromium.org <fgalligan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-16 00:17:14 +0000 |
---|---|---|
committer | fgalligan@chromium.org <fgalligan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-16 00:17:14 +0000 |
commit | 1804c33f0d9234d240117afc87e46272e0761466 (patch) | |
tree | 9e191247534f4dc0274677077f3fc233a5dcca07 /media | |
parent | 61b98c6d9eb9e7aa6095f730b5f89d151930a2a5 (diff) | |
download | chromium_src-1804c33f0d9234d240117afc87e46272e0761466.zip chromium_src-1804c33f0d9234d240117afc87e46272e0761466.tar.gz chromium_src-1804c33f0d9234d240117afc87e46272e0761466.tar.bz2 |
Change WebM parser to treat IVs from encrypted WebM as raw data.
The encrypted WebM spec RFC changed to treat IVs as raw data.
BUG=155641
TEST=All media_unittests pass.
TBR=sky
Review URL: https://chromiumcodereview.appspot.com/11139008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@162012 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
-rw-r--r-- | media/crypto/aes_decryptor_unittest.cc | 28 | ||||
-rw-r--r-- | media/filters/pipeline_integration_test.cc | 4 | ||||
-rw-r--r-- | media/webm/webm_cluster_parser.cc | 26 | ||||
-rw-r--r-- | media/webm/webm_constants.h | 2 |
4 files changed, 32 insertions, 28 deletions
diff --git a/media/crypto/aes_decryptor_unittest.cc b/media/crypto/aes_decryptor_unittest.cc index 1b9d52e..0f3537e 100644 --- a/media/crypto/aes_decryptor_unittest.cc +++ b/media/crypto/aes_decryptor_unittest.cc @@ -7,7 +7,6 @@ #include "base/basictypes.h" #include "base/bind.h" -#include "base/sys_byteorder.h" #include "media/base/decoder_buffer.h" #include "media/base/decrypt_config.h" #include "media/base/mock_filters.h" @@ -92,8 +91,8 @@ const WebmEncryptedData kWebmEncryptedFrames[] = { 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40 }, 16, // encrypted_data - { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x9c, 0x71, 0x26, 0x57, 0x3e, 0x25, 0x37, + { 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x9c, 0x71, 0x26, 0x57, 0x3e, 0x25, 0x37, 0xf7, 0x31, 0x81, 0x19, 0x64, 0xce, 0xbc }, 23 }, @@ -161,16 +160,16 @@ static const SubsampleEntry kSubsampleEntries[] = { { 1, 0 } }; -// Returns a 16 byte CTR counter block. The CTR counter block format is a -// CTR IV appended with a CTR block counter. |iv| is a CTR IV. |iv_size| is -// the size of |iv| in bytes. +// Generates a 16 byte CTR counter block. The CTR counter block format is a +// CTR IV appended with a CTR block counter. |iv| is an 8 byte CTR IV. +// |iv_size| is the size of |iv| in btyes. Returns a string of +// kDecryptionKeySize bytes. static std::string GenerateCounterBlock(const uint8* iv, int iv_size) { - const int kDecryptionKeySize = 16; CHECK_GT(iv_size, 0); - CHECK_LE(iv_size, kDecryptionKeySize); + CHECK_LE(iv_size, DecryptConfig::kDecryptionKeySize); std::string counter_block(reinterpret_cast<const char*>(iv), iv_size); - counter_block.append(kDecryptionKeySize - iv_size, 0); + counter_block.append(DecryptConfig::kDecryptionKeySize - iv_size, 0); return counter_block; } @@ -187,9 +186,10 @@ static scoped_refptr<DecoderBuffer> CreateWebMEncryptedBuffer( scoped_refptr<DecoderBuffer> encrypted_buffer = DecoderBuffer::CopyFrom( data, data_size); CHECK(encrypted_buffer); + DCHECK_EQ(kWebMSignalByteSize, 1); uint8 signal_byte = data[0]; - int data_offset = sizeof(signal_byte); + int data_offset = kWebMSignalByteSize; // Setting the DecryptConfig object of the buffer while leaving the // initialization vector empty will tell the decryptor that the frame is @@ -197,12 +197,8 @@ static scoped_refptr<DecoderBuffer> CreateWebMEncryptedBuffer( std::string counter_block_str; if (signal_byte & kWebMFlagEncryptedFrame) { - uint64 network_iv; - memcpy(&network_iv, data + data_offset, sizeof(network_iv)); - const uint64 iv = base::NetToHost64(network_iv); - counter_block_str = - GenerateCounterBlock(reinterpret_cast<const uint8*>(&iv), sizeof(iv)); - data_offset += sizeof(iv); + counter_block_str = GenerateCounterBlock(data + data_offset, kWebMIvSize); + data_offset += kWebMIvSize; } encrypted_buffer->SetDecryptConfig( diff --git a/media/filters/pipeline_integration_test.cc b/media/filters/pipeline_integration_test.cc index 77d3bf3..ffafb0e 100644 --- a/media/filters/pipeline_integration_test.cc +++ b/media/filters/pipeline_integration_test.cc @@ -368,9 +368,7 @@ TEST_F(PipelineIntegrationTest, BasicPlayback_16x9AspectRatio) { ASSERT_TRUE(WaitUntilOnEnded()); } -// TODO(fgalligan): Enable after WebM parser has been updated. -// http://crbug.com/155641 -TEST_F(PipelineIntegrationTest, DISABLED_EncryptedPlayback) { +TEST_F(PipelineIntegrationTest, EncryptedPlayback) { MockMediaSource source("bear-320x240-encrypted.webm", kWebM, 219816); FakeDecryptorClient encrypted_media; StartPipelineWithEncryptedMedia(&source, &encrypted_media); diff --git a/media/webm/webm_cluster_parser.cc b/media/webm/webm_cluster_parser.cc index fb1c69b..477f668 100644 --- a/media/webm/webm_cluster_parser.cc +++ b/media/webm/webm_cluster_parser.cc @@ -7,7 +7,6 @@ #include <vector> #include "base/logging.h" -#include "base/sys_byteorder.h" #include "media/base/data_buffer.h" #include "media/base/decrypt_config.h" #include "media/webm/webm_constants.h" @@ -16,10 +15,11 @@ namespace media { // Generates a 16 byte CTR counter block. The CTR counter block format is a // CTR IV appended with a CTR block counter. |iv| is an 8 byte CTR IV. -// Returns a string of kDecryptionKeySize bytes. -static std::string GenerateCounterBlock(uint64 iv) { - std::string counter_block(reinterpret_cast<char*>(&iv), sizeof(iv)); - counter_block.append(DecryptConfig::kDecryptionKeySize - sizeof(iv), 0); +// |iv_size| is the size of |iv| in btyes. Returns a string of +// kDecryptionKeySize bytes. +static std::string GenerateCounterBlock(const uint8* iv, int iv_size) { + std::string counter_block(reinterpret_cast<const char*>(iv), iv_size); + counter_block.append(DecryptConfig::kDecryptionKeySize - iv_size, 0); return counter_block; } @@ -185,6 +185,7 @@ bool WebMClusterParser::OnBlock(int track_num, int timecode, int block_duration, int flags, const uint8* data, int size) { + DCHECK_GE(size, 0); if (cluster_timecode_ == -1) { DVLOG(1) << "Got a block before cluster timecode."; return false; @@ -228,6 +229,11 @@ bool WebMClusterParser::OnBlock(int track_num, int timecode, // encrypted WebM request for comments specification is here // http://wiki.webmproject.org/encryption/webm-encryption-rfc if (!encryption_key_id.empty()) { + DCHECK_EQ(kWebMSignalByteSize, 1); + if (size < kWebMSignalByteSize) { + DVLOG(1) << "Got a block from an encrypted stream with no data."; + return false; + } uint8 signal_byte = data[0]; int data_offset = sizeof(signal_byte); @@ -237,10 +243,12 @@ bool WebMClusterParser::OnBlock(int track_num, int timecode, std::string counter_block; if (signal_byte & kWebMFlagEncryptedFrame) { - uint64 network_iv; - memcpy(&network_iv, data + data_offset, sizeof(network_iv)); - data_offset += sizeof(network_iv); - counter_block = GenerateCounterBlock(base::NetToHost64(network_iv)); + if (size < kWebMSignalByteSize + kWebMIvSize) { + DVLOG(1) << "Got an encrypted block with not enough data " << size; + return false; + } + counter_block = GenerateCounterBlock(data + data_offset, kWebMIvSize); + data_offset += kWebMIvSize; } // TODO(fgalligan): Revisit if DecryptConfig needs to be set on unencrypted diff --git a/media/webm/webm_constants.h b/media/webm/webm_constants.h index 463b15a..7e5e3b1 100644 --- a/media/webm/webm_constants.h +++ b/media/webm/webm_constants.h @@ -202,6 +202,8 @@ const uint8 kWebMFlagKeyframe = 0x80; // Current encrypted WebM request for comments specification is here // http://wiki.webmproject.org/encryption/webm-encryption-rfc const uint8 kWebMFlagEncryptedFrame = 0x1; +const int kWebMIvSize = 8; +const int kWebMSignalByteSize = 1; } // namespace media |