154 lines
6.5 KiB
C++
154 lines
6.5 KiB
C++
// Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary
|
||
// source code may only be used and distributed under the Widevine Master
|
||
// License Agreement.
|
||
|
||
#ifndef WIDEVINE_CAS_API_H
|
||
#define WIDEVINE_CAS_API_H
|
||
|
||
#include <memory>
|
||
#include <mutex>
|
||
|
||
#include "cas_license.h"
|
||
#include "cas_media_id.h"
|
||
#include "cas_status.h"
|
||
#include "cas_types.h"
|
||
#include "crypto_session.h"
|
||
#include "file_store.h"
|
||
#include "timer.h"
|
||
#include "widevine_cas_session.h"
|
||
|
||
namespace wvcas {
|
||
|
||
// TODO(jfore): Fix the function name inconsistency in this class. These
|
||
// functions were migrated from the android plugin api implementation. They
|
||
// should not follow Android's style.
|
||
class WidevineCas : public wvutil::TimerHandler {
|
||
public:
|
||
WidevineCas() {}
|
||
virtual ~WidevineCas() {}
|
||
|
||
virtual CasStatus initialize(CasEventListener* event_listener);
|
||
|
||
// Open a session for descrambling a program, or one or more elementary
|
||
// streams.
|
||
virtual CasStatus openSession(WvCasSessionId* sessionId);
|
||
|
||
// Close a previously opened session.
|
||
virtual CasStatus closeSession(WvCasSessionId sessionId);
|
||
|
||
// Process an ECM from the ECM stream for this session’s elementary
|
||
// stream.
|
||
virtual CasStatus processEcm(WvCasSessionId sessionId, const CasEcm& ecm);
|
||
|
||
// Generates a device provisioning request message in |provisioning_request|.
|
||
virtual CasStatus generateDeviceProvisioningRequest(
|
||
std::string* provisioning_request);
|
||
|
||
// Processes a |response| to provisioning request.
|
||
virtual CasStatus handleProvisioningResponse(const std::string& response);
|
||
|
||
// Generates an entitlement license request in |entitlement_request| for the
|
||
// media described in |init_data|.
|
||
virtual CasStatus generateEntitlementRequest(const std::string& init_data,
|
||
std::string* entitlement_request,
|
||
std::string& license_id);
|
||
|
||
// Processes the entitlement |response| to a entitlement license request.
|
||
// |license_id| is the id of the license installed. Can be used to select
|
||
// which license to install.
|
||
// |multi_content_license_info| contains the message that can be sent to the
|
||
// app if the installed license is a multi content license.
|
||
// |group_license_info| contains the message that can be sent to the app if
|
||
// the installed license is a group license.
|
||
virtual CasStatus handleEntitlementResponse(
|
||
const std::string& response, std::string& license_id,
|
||
std::string& multi_content_license_info, std::string& group_license_info);
|
||
|
||
// Generates an entitlement license request in |entitlement_request| for the
|
||
// media described in |init_data|.
|
||
virtual CasStatus generateEntitlementRenewalRequest(
|
||
std::string* entitlement_renewal_request);
|
||
|
||
// Processes the entitlement renewal |response| to a entitlement license
|
||
// request.
|
||
virtual CasStatus handleEntitlementRenewalResponse(
|
||
const std::string& response, std::string& license_id);
|
||
|
||
// Returns true if the device has been provisioned with a device certificate.
|
||
virtual bool is_provisioned() const;
|
||
|
||
// Processes the CAS |private_data| from a CAT table. If successful a
|
||
// serialized pssh data is retured in |init_data|.
|
||
virtual CasStatus ProcessCAPrivateData(const CasData& private_data,
|
||
std::string* init_data);
|
||
|
||
// Processes the CAS |private_data| from a PMT table. If successful a
|
||
// serialized pssh data is retured in |init_data|. The CA private data can be
|
||
// unique to the ecm session indicated by |session_id|.
|
||
virtual CasStatus ProcessSessionCAPrivateData(WvCasSessionId session_id,
|
||
const CasData& private_data,
|
||
std::string* init_data);
|
||
// Returns the device unique identifier.
|
||
virtual CasStatus GetUniqueID(std::string* buffer);
|
||
|
||
// Set the minimum age required to process ECM.
|
||
virtual CasStatus HandleSetParentalControlAge(const CasData& data);
|
||
|
||
// Remove the license file given the filename user provides.
|
||
virtual CasStatus RemoveLicense(const std::string& file_name);
|
||
|
||
// Record the license id that user provides.
|
||
virtual CasStatus RecordLicenseId(const std::string& license_id);
|
||
|
||
void OnTimerEvent() override;
|
||
|
||
private:
|
||
virtual CasStatus HandleStoredDrmCert(const std::string& certificate);
|
||
virtual CasStatus HandleProcessEcm(const WvCasSessionId& sessionId,
|
||
const CasEcm& ecm);
|
||
virtual CasStatus HandleDeferredECMs();
|
||
|
||
virtual std::shared_ptr<CryptoSession> getCryptoSession();
|
||
virtual std::unique_ptr<CasLicense> getCasLicense();
|
||
virtual std::unique_ptr<wvutil::FileSystem> getFileSystem();
|
||
virtual std::shared_ptr<WidevineCasSession> newCasSession();
|
||
|
||
// The CryptoSession will be shared by the all cas sessions. It is also needed
|
||
// by the cas api to generate EMM requests.
|
||
std::shared_ptr<CryptoSession> crypto_session_;
|
||
std::unique_ptr<CasLicense> cas_license_;
|
||
std::unique_ptr<wvutil::FileSystem> file_system_;
|
||
std::string device_certificate_;
|
||
std::string wrapped_rsa_key_;
|
||
CasEventListener* event_listener_ = nullptr;
|
||
std::mutex lock_;
|
||
wvutil::Timer policy_timer_;
|
||
LicenseType license_type_;
|
||
std::unique_ptr<CasMediaId> media_id_;
|
||
// Sometimes delays in receiving a license or the format in which the content
|
||
// is encoded my result in ecms being processed before a valid license has
|
||
// been loaded. In this cas |has_license_| will be false and the ecm will be
|
||
// stored in |deferred_ecms_|. Once a license has been loaded, the stored ecms
|
||
// are processed to set the current content keys.
|
||
std::map<WvCasSessionId, const CasEcm> deferred_ecms_;
|
||
// The value |has_license_| will be false when the plugin is created. Once a
|
||
// license is loaded, |has_license_| will be set to true.
|
||
bool has_license_ = false;
|
||
// The age_restriction field in ECM must be greater or equal to
|
||
// |parental_control_min_age|. Otherwise, ECM will stop being processed.
|
||
uint parental_control_age_ = 0;
|
||
// The assigned_license_id helps to indicate which license file current
|
||
// content will use if multiple licenses exist.
|
||
std::string assigned_license_id_;
|
||
// The current in use license_id.
|
||
std::string license_id_;
|
||
// The group id of a Group license. Empty if the license is not a Group
|
||
// license (multi content license is not a group license). Used in processECM
|
||
// to select group keys that can be decrypted by the license.
|
||
std::string license_group_id_;
|
||
}; // namespace wvcas
|
||
|
||
} // namespace wvcas
|
||
|
||
#endif // WIDEVINE_CAS_API_H
|