commit 234436f88737e1b1e740a36fd9ce27b4cc94d0f3 Author: Widevine Buildbot Date: Mon Oct 1 23:46:31 2018 +0000 Export media_cas_packager_sdk diff --git a/libmedia_cas_packager_sdk.so b/libmedia_cas_packager_sdk.so new file mode 100755 index 0000000..ccfd6ae Binary files /dev/null and b/libmedia_cas_packager_sdk.so differ diff --git a/media_cas_packager_sdk/public/ecm_generator.h b/media_cas_packager_sdk/public/ecm_generator.h new file mode 100644 index 0000000..a95733d --- /dev/null +++ b/media_cas_packager_sdk/public/ecm_generator.h @@ -0,0 +1,95 @@ +//////////////////////////////////////////////////////////////////////////////// +// Copyright 2018 Google LLC. +// +// This software is licensed under the terms defined in the Widevine Master +// License Agreement. For a copy of this agreement, please contact +// widevine-licensing@google.com. +//////////////////////////////////////////////////////////////////////////////// + +#ifndef MEDIA_CAS_PACKAGER_SDK_PUBLIC_ECM_GENERATOR_H_ +#define MEDIA_CAS_PACKAGER_SDK_PUBLIC_ECM_GENERATOR_H_ + +#include +#include +#include +#include +#include + +#include +#include "util/status.h" +#include "media_cas_packager_sdk/internal/ecm.h" + +namespace widevine { +namespace cas { + +// KeyParameters carries key information for a single encryption key. +// Instances of this struct are owned by an EcmParameters struct. +struct KeyParameters { + std::string key_id; + std::string key_data; + std::string wrapped_key_data; + std::string wrapped_key_iv; + std::vector content_ivs; +}; + +// EcmParameters holds information that is needed by the EcmGenerator. It is +// partially set up with data from a KeyGenerator (obtained via GenerateKey()). +// IVs are added later. +// TODO(user): may need a starting crypto period index. +struct EcmParameters { + static constexpr int kDefaultIVSize = 8; + int iv_size = kDefaultIVSize; + bool current_key_even = true; + uint32_t current_key_index = 0; + std::string entitlement_key_id; + bool rotation_enabled = true; + uint32_t rotation_periods; + std::vector key_params; + uint16_t program_id; + uint64_t rotation_period_microseconds; + // For video, this is zero. For audio, this is the size of the audio frame, + // which is a constant in the audio track. + uint16_t offset = 0; +}; + +// ECM Generator for Widevine/MediaCAS entitled keys. +class CasEcmGenerator { + public: + CasEcmGenerator() = default; + virtual ~CasEcmGenerator() = default; + + virtual std::string GenerateEcm(const EcmParameters& params); + + // Query the state of this ECM Generator + bool initialized() { return initialized_; } + bool rotation_enabled() { return rotation_enabled_; } + + void set_ecm(std::unique_ptr ecm) { ecm_ = std::move(ecm); } + + private: + friend class CasEcmGeneratorTest; + + util::Status ProcessEcmParameters(const EcmParameters& ecm_params, + std::vector* keys); + + util::Status ProcessEcmParameters(const EcmParameters& ecm_params); + util::Status ValidateKeyId(const std::string& id); + util::Status ValidateKeyData(const std::string& key_data); + util::Status ValidateWrappedKeyIv(const std::string& iv); + util::Status ValidateIv(const std::string& iv, size_t required_size); + util::Status ValidateContentIv(const std::string& iv); + util::Status ValidateKeyParameters(const KeyParameters& key_params); + + bool initialized_ = false; + uint32_t generation_ = 0; + bool rotation_enabled_ = false; + uint32_t current_key_index_ = 0; + bool current_key_even_ = true; + uint32_t content_iv_size_ = 0; + std::unique_ptr ecm_; +}; + +} // namespace cas +} // namespace widevine + +#endif // MEDIA_CAS_PACKAGER_SDK_PUBLIC_ECM_GENERATOR_H_