Files
wvpl_license_sdk/centos/cc_header/wvpl_sdk_session.h

348 lines
11 KiB
C++

// Copyright 2018 Google LLC. All rights reserved.
#ifndef VIDEO_WIDEVINE_EXPORT_SDK_EXTERNAL_COMMON_WVPL_WVPL_SDK_SESSION_H_
#define VIDEO_WIDEVINE_EXPORT_SDK_EXTERNAL_COMMON_WVPL_WVPL_SDK_SESSION_H_
#include <memory>
#include "common/security_profile_list.h"
#include "sdk/external/common/wvpl/wvpl_types.h"
#include "protos/public/device_certificate_status.pb.h"
namespace video_widevine {
class ClientIdentification;
class DrmRootCertificate;
class LicenseRequest;
class License_KeyContainer_OutputProtection;
class License_KeyContainer;
class License_Policy;
class ProvisionedDeviceInfo;
class SessionInit;
class SessionState;
class SignedMessage;
} // namespace video_widevine
namespace video_widevine_server {
namespace wv_pl_sdk {
class WvPLSDKSession {
public:
explicit WvPLSDKSession(
const video_widevine::DrmRootCertificate* drm_root_certificate);
WvPLSDKSession(
const video_widevine::DrmRootCertificate* drm_root_certificate,
const video_widevine::SecurityProfileList* security_profile_list);
virtual ~WvPLSDKSession();
public:
// Add WvPLKey.
virtual WvPLStatus AddKey(const WvPLKey& key);
// Get the WvPLKey.
virtual const std::vector<WvPLKey>& keys() const { return keys_; }
// Set the license policy.
virtual void set_policy(const WvPLPlaybackPolicy& policy) {
policy_ = policy;
has_policy_ = true;
}
// Get the license policy.
virtual const WvPLPlaybackPolicy& policy() const { return policy_; }
// Set the Session Init.
virtual void set_session_init(const WvPLSessionInit& session_init) {
session_init_ = session_init;
}
// Get the Session Init.
virtual const WvPLSessionInit& session_init() const { return session_init_; }
virtual bool IsChromeCDM() const;
/**
* Returns the Widevine PSSH data for the license request handled by this
* session.
*
* @param wvpl_widevine_pssh_data.
* @return WvPLStatus - Status::OK if success, else error.
*/
virtual WvPLStatus GetPsshData(
WvPLWidevinePsshData* wvpl_widevine_pssh_data) const;
/**
* Returns the ClientIdentification information for the license request
* handled by this session.
*
* @param client_info
* @return WvPLStatus - Status::OK if success, else error.
*/
virtual WvPLStatus GetClientInfo(WvPLClientInfo* client_info) const;
/**
* Returns the WvPL Client Capabilities information for the license request
* handled by this session.
*
* @param client_capabilities.
* @return WvPLStatus - Status::OK if success, else error.
*/
virtual WvPLStatus GetClientCapabilities(
WvPLClientCapabilities* client_capabilities) const;
/**
* Returns the WvPLDeviceInfo information for the license request
* handled by this session.
*
* @param device_info
* @return WvPLStatus - Status::OK if success, else error.
*/
virtual WvPLStatus GetDeviceInfo(WvPLDeviceInfo* device_info) const;
virtual PlatformVerificationStatus VerifyPlatform() = 0;
virtual WvPLRequestType GetRequestType() const { return request_type_; }
/**
* Returns true if the license type is offline, otherwise return false.
*
* @return bool.
*/
virtual bool is_offline_license() const;
/**
* Returns the license request contains client id or not.
*
* @return bool.
*/
virtual bool has_client_id() const { return has_client_id_; }
/**
* Returns true if license request has encrypted_client_id. Otherwise return
* false.
*
* @return bool.
*/
virtual bool has_encrypted_client_id() { return has_encrypted_client_id_; }
/**
* If set to true, allow generation of licenses with
* PlatformVerificationStatus = PLATFORM_UNVERIFIED.
*/
virtual void set_allow_unverified_platform(bool allow_unverified_platform) {
allow_unverified_platform_ = allow_unverified_platform;
}
/**
* Retrieves the setting of whether license generation is allowed if
* PlatformVerificationStatus = PLATFORM_UNVERIFIED.
*/
virtual bool allow_unverified_platform() const {
return allow_unverified_platform_;
}
/**
* If set to false, SDK can reject licensing behaviors to unknown make
* model. Default value is false.
*/
virtual void set_reject_unknown_make_model(bool reject_unknown_make_model) {
reject_unknown_make_model_ = reject_unknown_make_model;
}
/**
* Retrieves the setting of whether unknown make model is rejected.
*/
virtual bool reject_unknown_make_model() const {
return reject_unknown_make_model_;
}
/**
* If set to true, allow generation of licenses with
* PlatformVerificationStatus = PLATFORM_TAMPERED.
*/
virtual void set_allow_tampered_platform(bool allow_tampered_platform) {
allow_tampered_platform_ = allow_tampered_platform;
}
/**
* Retrieves the setting of whether license generation is allowed if
* PlatformVerificationStatus = PLATFORM_TAMPERED.
*/
virtual bool allow_tampered_platform() const {
return allow_tampered_platform_;
}
/**
* Retrieves Widevine Security Profile DrmInfo of the device.
* Returns true if |drm_info| was successully populated.
*/
virtual bool GetDrmInfo(WvPLSecurityProfile::DrmInfo* drm_info) const;
/**
* Retrieves qualifying Widevine Default Security Profile names.
*/
virtual WvPLStatus GetQualifiedDefaultDeviceSecurityProfiles(
std::vector<std::string>* default_qualified_profile_names) const;
/**
* Retrieves qualifying Custom Security Profiles names given the owner name.
*/
virtual WvPLStatus GetQualifiedCustomDeviceSecurityProfiles(
const std::string& owner_name,
std::vector<std::string>* custom_qualified_profile_names) const;
// Return ok status if get content id information successful and |content_id|
// would be set, else return failure and |content_id| would not be set
WvPLStatus GetContentId(std::string* content_id) const;
protected:
void set_license_request_from_cdm(const std::string& request_from_cdm) {
license_request_from_cdm_ = request_from_cdm;
}
const video_widevine::DrmRootCertificate* drm_root_certificate_;
std::string user_agent_;
std::string device_id_;
std::string content_id_;
std::vector<WvPLKey> keys_;
WvPLPlaybackPolicy policy_;
WvPLSessionInit session_init_;
WvPLWidevinePsshData pssh_data_;
std::unique_ptr<video_widevine::ClientIdentification> client_id_;
std::unique_ptr<video_widevine::ProvisionedDeviceInfo>
provisioned_device_info_;
bool has_pssh_data_ = false;
bool has_client_id_ = false;
PlatformVerificationStatus platform_verification_status_ =
PLATFORM_NO_VERIFICATION;
std::unique_ptr<video_widevine::SignedMessage>
signed_message_request_from_cdm_;
std::string license_request_from_cdm_;
std::string remote_attestation_cert_serial_number_;
std::unique_ptr<video_widevine::LicenseRequest> sdk_license_request_;
WvPLRequestType request_type_;
bool has_session_state_ = false;
bool has_encrypted_client_id_ = false;
std::string provider_;
std::string provider_iv_;
std::string provider_key_;
virtual WvPLStatus VerifyRemoteAttestation();
// Returns the WvPL Client Capabilities information for the license request
// handled by this session.
WvPLStatus GetWvPLClientCapabilities(
const video_widevine::ClientIdentification& client_id,
WvPLClientCapabilities* client_capabilities) const;
// Copy and translates the Key fields from a WvPL Key into an SDK
// key container.
// Copies
// (1) key id
// (2) key
// (3) video_resolution_constraints
// (4) output protection using CopyOutputProtection
// (5) security_level using CopySecurityLevel
// Translates
// (1) key type
void CopyKey(const WvPLKey& wvpl_key,
video_widevine::License_KeyContainer* sdk_key_container);
// Copies/translates output_protection in WvPL Key into an SDK key container.
virtual void CopyOutputProtection(
const WvPLOutputProtection& wvpl_output_protection,
video_widevine::License_KeyContainer_OutputProtection* output_protection);
// Copies/translatessecurity_level in WvPL Key into an SDK key container.
virtual void CopySecurityLevel(
const WvPLOutputProtection& output_protection, TrackType track_type,
video_widevine::License_KeyContainer* key_container);
// Copies/translates the policy from a WvPL policy into an SDK policy. A
// helper function for GenerateLicenseRequestAsJSON.
virtual void CopyPlaybackPolicy(const WvPLPlaybackPolicy& wvpl_policy,
video_widevine::License_Policy* sdk_policy);
// Copy the |hdcp_value| into the key container.
virtual void CopyHDCP(
HDCP hdcp_value,
video_widevine::License_KeyContainer_OutputProtection* output_protection);
// Copy the WvPLSession Init into Session Init.
virtual void CopySessionInit(const WvPLSessionInit& wvpl_session_init,
video_widevine::SessionInit* session_init);
// Copy the WvPLDeviceInfo into ProvisionedDeviceInfo.
virtual void CopyProvisionedDeviceInfo(
const WvPLDeviceInfo& wvpl_device_info,
video_widevine::ProvisionedDeviceInfo* device_info);
// Populate deviceInfo, clientIdentification and psshdata for license request.
WvPLStatus ParseLicenseRequest();
// Copy the WvPLSessionState to SessionState.
void CopySessionState(const WvPLSessionState& wvpl_session_state,
video_widevine::SessionState* session_state);
// Set system_id value. Only used for test case.
virtual void SetSystemId(uint32_t system_id);
// Return has_system_id_ value. True if session has system id.
virtual bool HasSystemId() const;
// Return system_id value in uint32_t. The function will crash if it does not
// have system_id.
virtual uint32_t GetSystemId() const;
// Set drm serial number. Only used for test case.
virtual void SetDrmSerialNumber(const std::string& drm_serial_number);
// Return drm serial number.
virtual std::string GetDrmSerialNumber() const;
/**
* Use system_id to loop up device info.
*
* @return WvPLStatus - Status::OK if success, else error.
*/
virtual WvPLStatus LookupDeviceInfo(
uint32_t system_id,
video_widevine::ProvisionedDeviceInfo* provisioned_device_info) const;
virtual const std::string TrackTypeToString(TrackType track_type) const;
virtual bool has_policy() { return has_policy_; }
virtual const video_widevine::SecurityProfileList*
device_security_profile_list() {
return device_security_profile_list_;
}
// Set the provider which hosts this service.
virtual void set_provider(const std::string& provider) {
provider_ = provider;
}
// Set the iv specified for the provider.
virtual void set_provider_iv(const std::string& provider_iv) {
provider_iv_ = provider_iv;
}
// Set the key specified for the provider.
virtual void set_provider_key(const std::string& provider_key) {
provider_key_ = provider_key;
}
DeviceStatus GetDeviceStatus(video_widevine::DeviceCertificateStatus::Status
device_certificate_status) const;
private:
std::unique_ptr<uint32_t> system_id_;
bool has_policy_ = false;
bool allow_unverified_platform_ = true;
bool allow_tampered_platform_ = true;
bool reject_unknown_make_model_ = false;
const video_widevine::SecurityProfileList* device_security_profile_list_ =
nullptr;
};
} // namespace wv_pl_sdk
} // namespace video_widevine_server
#endif // VIDEO_WIDEVINE_EXPORT_SDK_EXTERNAL_COMMON_WVPL_WVPL_SDK_SESSION_H_