summaryrefslogtreecommitdiffstats
path: root/media/webm
diff options
context:
space:
mode:
authorvandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-01 19:12:54 +0000
committervandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-01 19:12:54 +0000
commit672f667ed68e59ec0aaf5c40167e890673ef3f7c (patch)
treec57d1749a75b5ce0268f637d63bdec7f8821230b /media/webm
parent359da1a97f59d417f84300b7254668920f9ca064 (diff)
downloadchromium_src-672f667ed68e59ec0aaf5c40167e890673ef3f7c.zip
chromium_src-672f667ed68e59ec0aaf5c40167e890673ef3f7c.tar.gz
chromium_src-672f667ed68e59ec0aaf5c40167e890673ef3f7c.tar.bz2
Revert 149449 - Add support for v0.3 of the encrypted WebM specification.
Asan didn't like this: http://build.chromium.org/p/chromium.memory/builders/Linux%20ASAN%20Tests%20%282%29/builds/414/steps/media_unittests/logs/stdio - Added code to handle the signal_byte contained within WebM encrypted Blocks. - Added a unittest to aes_decryptor to hanlde an encrypted WebM Block with an unencrypted frame. BUG=139876 TEST=Run media_unittests --gtest_filter=AesDecryptor* and all tests must pass. Review URL: https://chromiumcodereview.appspot.com/10823110 TBR=fgalligan@chromium.org Review URL: https://chromiumcodereview.appspot.com/10831115 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@149457 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/webm')
-rw-r--r--media/webm/webm_cluster_parser.cc61
-rw-r--r--media/webm/webm_constants.h1
2 files changed, 29 insertions, 33 deletions
diff --git a/media/webm/webm_cluster_parser.cc b/media/webm/webm_cluster_parser.cc
index 7878fa8..e9ef93e 100644
--- a/media/webm/webm_cluster_parser.cc
+++ b/media/webm/webm_cluster_parser.cc
@@ -14,11 +14,20 @@ 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);
- return counter_block;
+// Always returns a valid pointer to a buffer of kDecryptionKeySize bytes.
+static scoped_array<uint8> GenerateCounterBlock(uint64 iv) {
+ scoped_array<uint8> counter_block_data(
+ new uint8[DecryptConfig::kDecryptionKeySize]);
+
+ // Set the IV.
+ memcpy(counter_block_data.get(), &iv, sizeof(iv));
+
+ // Set block counter to all 0's.
+ memset(counter_block_data.get() + sizeof(iv),
+ 0,
+ DecryptConfig::kDecryptionKeySize - sizeof(iv));
+
+ return counter_block_data.Pass();
}
WebMClusterParser::WebMClusterParser(int64 timecode_scale,
@@ -211,14 +220,12 @@ bool WebMClusterParser::OnBlock(int track_num, int timecode,
// Every encrypted Block has an HMAC and IV prepended to it. Current encrypted
// WebM request for comments specification is here
// http://wiki.webmproject.org/encryption/webm-encryption-rfc
- bool is_track_encrypted = track_num == video_.track_num() &&
- video_encryption_key_id_.get();
-
- // If stream is encrypted skip past the HMAC. Encrypted buffers must include
- // the signal byte, the IV (if frame is encrypted) and
- // the frame because the decryptor will verify this data before decryption.
- // The HMAC and IV will be copied into DecryptConfig.
- int offset = (is_track_encrypted) ? kWebMHmacSize : 0;
+ bool encrypted = track_num == video_.track_num() &&
+ video_encryption_key_id_.get();
+ // If encrypted skip past the HMAC. Encrypted buffers must include the IV and
+ // the encrypted frame because the decryptor will verify this data before
+ // decryption. The HMAC and IV will be copied into DecryptConfig.
+ int offset = (encrypted) ? kWebMHmacSize : 0;
// The first bit of the flags is set when the block contains only keyframes.
// http://www.matroska.org/technical/specs/index.html
@@ -226,31 +233,21 @@ bool WebMClusterParser::OnBlock(int track_num, int timecode,
scoped_refptr<StreamParserBuffer> buffer =
StreamParserBuffer::CopyFrom(data + offset, size - offset, is_keyframe);
- if (is_track_encrypted) {
- uint8 signal_byte = data[kWebMHmacSize];
- int data_offset = sizeof(signal_byte);
-
- // Setting the DecryptConfig object of the buffer while leaving the
- // initialization vector empty will tell the decryptor that the frame is
- // unencrypted but integrity should still be checked.
- std::string counter_block;
-
- if (signal_byte & kWebMFlagEncryptedFrame) {
- uint64 network_iv;
- memcpy(&network_iv, data + kWebMHmacSize + data_offset,
- sizeof(network_iv));
- const uint64 iv = base::NetToHost64(network_iv);
- counter_block = GenerateCounterBlock(iv);
- data_offset += sizeof(iv);
- }
+ if (encrypted) {
+ uint64 network_iv;
+ memcpy(&network_iv, data + kWebMHmacSize, sizeof(network_iv));
+ const uint64 iv = base::NetToHost64(network_iv);
+ scoped_array<uint8> counter_block(GenerateCounterBlock(iv));
buffer->SetDecryptConfig(scoped_ptr<DecryptConfig>(new DecryptConfig(
std::string(
reinterpret_cast<const char*>(video_encryption_key_id_.get()),
video_encryption_key_id_size_),
- counter_block,
+ std::string(
+ reinterpret_cast<const char*>(counter_block.get()),
+ DecryptConfig::kDecryptionKeySize),
std::string(reinterpret_cast<const char*>(data), kWebMHmacSize),
- data_offset,
+ sizeof(iv),
std::vector<SubsampleEntry>())));
}
diff --git a/media/webm/webm_constants.h b/media/webm/webm_constants.h
index 7d6f3ed..93041b2 100644
--- a/media/webm/webm_constants.h
+++ b/media/webm/webm_constants.h
@@ -202,7 +202,6 @@ const uint8 kWebMFlagKeyframe = 0x80;
// The size is from the WebM encrypted specification. Current encrypted WebM
// request for comments specification is here
// http://wiki.webmproject.org/encryption/webm-encryption-rfc
-const uint8 kWebMFlagEncryptedFrame = 0x1;
const int kWebMHmacSize = 12;
} // namespace media