134 lines
5.3 KiB
C++
134 lines
5.3 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);
|
||
|
||
// Processes the entitlement |response| to a entitlement license request.
|
||
virtual CasStatus handleEntitlementResponse(
|
||
const std::string& response, std::string& license_id);
|
||
|
||
// 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 in used license. If successful content id is returned.
|
||
virtual CasStatus RemoveLicense(const std::string file_name);
|
||
|
||
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;
|
||
}; // namespace wvcas
|
||
|
||
} // namespace wvcas
|
||
|
||
#endif // WIDEVINE_CAS_API_H
|