Files
android/libwvdrmengine/cdm/core/include/initialization_data.h
Fred Gylys-Colwell 9ae7489938 Add basic handling for entitlement keys in a license.
Merge from Widevine repo of http://go/wvgerrit/41834

Key rotation is not yet supported.

The key statuses are updated from a license. The
mechanism expects content keys tro come in a license.
For entitlement licenses, the content keys come in the
init_data.

This code does not yet support the key rotation event.
(A new pssh with wrapped keys is a passed to the cdm)
The policy engine/key status mechanism needs to be
updated to handle updated from the init_data.

For now, the cdm builds a license with a key container
with the content keys and used that to call
PolicyEngine::SetLicense to setup the policy engine
and key statuses.

Bug: 64003606
Bug: 70334840

Test: In child CL
Change-Id: Ibf46a18f5321cab4ff6f1778ba30527942c8021f
2018-01-30 00:11:04 -08:00

85 lines
3.1 KiB
C++

// Copyright 2014 Google Inc. All Rights Reserved.
#ifndef CORE_INCLUDE_INITIALIZATION_DATA_H_
#define CORE_INCLUDE_INITIALIZATION_DATA_H_
#include <string>
#include "license_protocol.pb.h"
#include "wv_cdm_types.h"
namespace wvcdm {
class WvCdmEngineTest;
class InitializationData {
public:
InitializationData(const std::string& type = std::string(),
const CdmInitData& data = CdmInitData());
bool is_supported() const { return is_cenc_ || is_webm_ || is_hls_; }
bool is_cenc() const { return is_cenc_; }
bool is_hls() const { return is_hls_; }
bool is_webm() const { return is_webm_; }
bool IsEmpty() const { return data_.empty(); }
const std::string& type() const { return type_; }
const CdmInitData& data() const { return data_; }
std::vector<uint8_t> hls_iv() const { return hls_iv_; }
CdmHlsMethod hls_method() const { return hls_method_; }
// TODO(jfore): Perhaps this should be a generic structure with the ids for
// any type of licensing?
std::vector<video_widevine::SubLicense> ExtractSublicenseKeys() const;
std::vector<video_widevine::WrappedKey> ExtractWrappedKeys() const;
private:
// Parse a blob of multiple concatenated PSSH atoms to extract the first
// Widevine PSSH.
bool ExtractWidevinePssh(const CdmInitData& init_data, CdmInitData* output);
bool ExtractHlsAttributes(const std::string& attribute_list,
CdmHlsMethod* method, std::vector<uint8_t>* iv,
std::string* uri);
static bool ConstructWidevineInitData(CdmHlsMethod method,
const std::string& uri,
CdmInitData* output);
static bool ExtractQuotedAttribute(const std::string& attribute_list,
const std::string& key,
std::string* value);
static bool ExtractHexAttribute(const std::string& attribute_list,
const std::string& key,
std::vector<uint8_t>* value);
static bool ExtractAttribute(const std::string& attribute_list,
const std::string& key, std::string* value);
static std::vector<std::string> ExtractKeyFormatVersions(
const std::string& key_format_versions);
// For testing only:
#if defined(UNIT_TEST)
FRIEND_TEST(HlsAttributeExtractionTest, ExtractAttribute);
FRIEND_TEST(HlsConstructionTest, InitData);
FRIEND_TEST(HlsInitDataConstructionTest, InvalidUriDataFormat);
FRIEND_TEST(HlsInitDataConstructionTest, InvalidUriBase64Encode);
FRIEND_TEST(HlsHexAttributeExtractionTest, ExtractHexAttribute);
FRIEND_TEST(HlsKeyFormatVersionsExtractionTest, ExtractKeyFormatVersions);
FRIEND_TEST(HlsParseTest, Parse);
FRIEND_TEST(HlsQuotedAttributeExtractionTest, ExtractQuotedAttribute);
FRIEND_TEST(HlsTest, ExtractHlsAttributes);
#endif
std::string type_;
CdmInitData data_;
bool is_cenc_;
bool is_hls_;
bool is_webm_;
std::vector<uint8_t> hls_iv_;
CdmHlsMethod hls_method_;
};
} // namespace wvcdm
#endif // CORE_INCLUDE_INITIALIZATION_DATA_H_