From 0be4815edc4c13ceeb53f5b90e8fc54010289481 Mon Sep 17 00:00:00 2001 From: Ramji Chandramouli Date: Thu, 16 Oct 2014 09:18:30 -0700 Subject: [PATCH] Use only the first 16 bytes of the asset key. Bug: 18003864 Change-Id: I65b08c4766a4c2ab08b09660b1540630387ab36c --- .../media/formats/wvm/wvm_media_parser.cc | 15 ++++++++++++++- .../formats/wvm/wvm_media_parser_unittest.cc | 19 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/packager/media/formats/wvm/wvm_media_parser.cc b/packager/media/formats/wvm/wvm_media_parser.cc index 9f30e66106..dbdc2a56c1 100644 --- a/packager/media/formats/wvm/wvm_media_parser.cc +++ b/packager/media/formats/wvm/wvm_media_parser.cc @@ -61,6 +61,7 @@ namespace { const uint32_t kEcmFlagsSizeBytes = kEcmCCIFlagsSizeBytes + kEcmDCPFlagsSizeBytes; const uint32_t kEcmPaddingSizeBytes = 12; + const uint32_t kAssetKeySizeBytes = 16; enum Type { Type_void = 0, @@ -963,9 +964,21 @@ bool WvmMediaParser::ProcessEcm() { if (!GetAssetKey(asset_id, &encryption_key)) { return false; } + if (encryption_key.key.size() < kAssetKeySizeBytes) { + LOG(ERROR) << "Asset Key size of " << encryption_key.key.size() + << " for AssetID = " << asset_id + << " is less than minimum asset key size."; + return false; + } + // Legacy WVM content may have asset keys > 16 bytes. + // Use only the first 16 bytes of the asset key to get + // the content key. + std::vector asset_key( + encryption_key.key.begin(), + encryption_key.key.begin() + kAssetKeySizeBytes); std::vector iv(kInitializationVectorSizeBytes); AesCbcCtsDecryptor asset_decryptor; - if (!asset_decryptor.InitializeWithIv(encryption_key.key, iv)) { + if (!asset_decryptor.InitializeWithIv(asset_key, iv)) { LOG(ERROR) << "Failed to initialize asset_decryptor."; return false; } diff --git a/packager/media/formats/wvm/wvm_media_parser_unittest.cc b/packager/media/formats/wvm/wvm_media_parser_unittest.cc index c97ace7ff2..a86552c805 100644 --- a/packager/media/formats/wvm/wvm_media_parser_unittest.cc +++ b/packager/media/formats/wvm/wvm_media_parser_unittest.cc @@ -30,6 +30,11 @@ const int kExpectedVideoFrameCount = 6665; const int kExpectedAudioFrameCount = 11964; const uint8_t kExpectedAssetKey[] = "\x06\x81\x7f\x48\x6b\xf2\x7f\x3e\xc7\x39\xa8\x3f\x12\x0a\xd2\xfc"; +const uint8_t k64ByteAssetKey[] = + "\x06\x81\x7f\x48\x6b\xf2\x7f\x3e\xc7\x39\xa8\x3f\x12\x0a\xd2\xfc" + "\x06\x81\x7f\x48\x6b\xf2\x7f\x3e\xc7\x39\xa8\x3f\x12\x0a\xd2\xfc" + "\x06\x81\x7f\x48\x6b\xf2\x7f\x3e\xc7\x39\xa8\x3f\x12\x0a\xd2\xfc" + "\x06\x81\x7f\x48\x6b\xf2\x7f\x3e\xc7\x39\xa8\x3f\x12\x0a\xd2\xfc"; const size_t kInitDataSize = 0x4000; } // namespace @@ -65,6 +70,7 @@ class WvmMediaParserTest : public testing::Test { current_track_id_(-1) { parser_.reset(new WvmMediaParser()); key_source_.reset(new MockKeySource()); + encryption_key_.key.resize(16); encryption_key_.key.assign(kExpectedAssetKey, kExpectedAssetKey + 16); } @@ -169,6 +175,19 @@ TEST_F(WvmMediaParserTest, ParseWvm) { EXPECT_EQ(kExpectedAudioFrameCount, audio_frame_count_); } +TEST_F(WvmMediaParserTest, ParseWvmWith64ByteAssetKey) { + EXPECT_CALL(*key_source_, FetchKeys(_)).WillOnce(Return(Status::OK)); + // WVM uses only the first 16 bytes of the asset key. + encryption_key_.key.resize(64); + encryption_key_.key.assign(k64ByteAssetKey, k64ByteAssetKey + 64); + EXPECT_CALL(*key_source_, GetKey(_, _)) + .WillOnce(DoAll(SetArgPointee<1>(encryption_key_), Return(Status::OK))); + Parse(kWvmFile); + EXPECT_EQ(kExpectedStreams, stream_map_.size()); + EXPECT_EQ(kExpectedVideoFrameCount, video_frame_count_); + EXPECT_EQ(kExpectedAudioFrameCount, audio_frame_count_); +} + } // namespace wvm } // namespace media } // namespace edash_packager