// Copyright 2017 Google LLC. All rights reserved. #ifndef VIDEO_WIDEVINE_EXPORT_SDK_EXTERNAL_CPP_WVDRM_LICENSE_SERVER_SDK_SESSION_H_ #define VIDEO_WIDEVINE_EXPORT_SDK_EXTERNAL_CPP_WVDRM_LICENSE_SERVER_SDK_SESSION_H_ #include #include #include #include #include #include "absl/strings/string_view.h" #include "absl/synchronization/mutex.h" #include "common/status.h" #include "protos/public/client_identification.pb.h" #include "protos/public/device_certificate_status.pb.h" #include "protos/public/drm_certificate.pb.h" #include "protos/public/external_license.pb.h" #include "protos/public/license_protocol.pb.h" #include "protos/public/license_server_sdk.pb.h" #include "protos/public/oem_key_container.pb.h" #include "protos/public/security_profile.pb.h" #include "protos/public/provider_key.pb.h" namespace video_widevine { class ClientIdentification; class ContentInfo; class DrmRootCertificate; class ExternalPlayReadySessionImpl; class License; class LicenseRequest; class ProvisionedDeviceInfo; class SecurityProfile; class SecurityProfileList; class SessionImpl; class EnvironmentImpl; class SessionInit; class SessionState; class SessionUsage; // TODO(tinskip): Rename this to LicenseSession and add LicenseEngine to hold // global settings and create new sessions. class Session { public: virtual ~Session(); virtual const LicenseRequest& request() const; virtual const std::string& GetSessionId(); // Return list of Widevine profiles meeting the DRM requirements for this // session. virtual Status GetQualifiedDefaultDeviceSecurityProfiles( std::vector* qualified_profiles) const; // Retrieves qualifying Custom Security Profiles names given the owner name. virtual Status GetQualifiedCustomDeviceSecurityProfiles( absl::string_view owner_name, std::vector* custom_qualified_profile_names) const; // Returns true if a provisioned device info exists. Caller // owns |provisioned_device_info| and it must not be null. virtual bool GetProvisionedDeviceInfo( video_widevine::ProvisionedDeviceInfo* device_info); // Accessor for request_id field which may be encoded in one of multiple // places in the liciense request protcol buffer. Use this method instead // of accessing directly. |request_id| is a pointer to a std::string to contain // the request ID upon successful return. virtual Status GetRequestId(std::string* request_id) const; // Accessor for license_type field which may be encoded in one of multiple // places in the license request protocol buffer. Use this method instead // of accessing directly. |license_type| is a pointer to a value to contain // the license type upon successful return. virtual Status GetLicenseType(LicenseType* license_type) const; // Method used to get ContentIdentification in a consistent message regardless // of the type or version of initialization data contained in the content_id // field of the license request. Use this method instead of accessing the // fields of ContentIdentification directly. |content_info| is a pointer to a // message to contain the parsed values from content_id upon successful // return. virtual Status GetContentInfo(ContentInfo* content_info) const; // Returns the serial number of certificate associated with this device and // content provider. virtual std::string GetDrmDeviceId() const; // Copies the session usage table from license request to |usage_report|. // Returns true if session usage exist in the license request, otherwise // returns false. bool GetSessionUsage(SessionUsage* usage_report) const; // Returns true if client info exists, otherwise returns false. Populate the // specified |client_info| structure. virtual bool GetClientInfo(ClientIdentification* client_info) const; // Generates a serialized signed License response, emptying |policy| and // |key_container|, encrypting the keys therein. |session_init| and // |session_state| are returned to be cached and provided in subsequent // calls to the function. If no additional PolicyItem or KeyContainer objects // are necessary to fulfill the request (such as the case with license // renewal), |policy| and/or |key_container| may be NULL. // The response is expected to be sent to the Widevine CDM. virtual Status GenerateSignedLicense( /*IN*/ const License::Policy* policy, /*IN*/ const std::list* key_container, /*IN*/ const SessionInit* session_init, /*INOUT*/ SessionState* session_state, /*OUT*/ std::string* signed_message_bytes); virtual PlatformVerificationStatus GetPlatformVerificationStatus() const; // Returns the service id of the provider that owns the device certificate. virtual std::string GetDrmDeviceServiceId() const; // Returns true, if the license request for this session included a key // control nonce, else false. virtual bool HasKeyControlNonce() const; // If set to 'true', allow licenses to be generated even if VMP data was // determined to be video_widevine::PLATFORM_UNVERIFIED. virtual void set_allow_unverified_platform(bool allow_unverified_platform); // Return the setting of whether licenses are allowed to be generated even // when VMP data was determined to be video_widevine::PLATFORM_UNVERIFIED. virtual bool allow_unverified_platform() const; // If set to 'true', allow licenses to be generated even if VMP data was // determined to be video_widevine::PLATFORM_TAMPERED. virtual void set_allow_tampered_platform(bool allow_tampered_platform); /** * If set to true, reject WvDrm SDK to reject licensing behaviors to unknown * make model. Default value is false. */ virtual void set_reject_unknown_make_model(bool reject_unknown_make_model); /** * Retrieves the setting of whether unknown make model is rejected. */ virtual bool reject_unknown_make_model() const; // Return the setting of whether licenses are allowed to be generated even // when VMP data was determined to be video_widevine::PLATFORM_TAMPERED. virtual bool allow_tampered_platform() const; virtual void SetKeys(std::list* oem_key_container); // 'Provider' making the request. virtual void set_provider(const std::string& provider); // Return the device status such as as RELEASED or REVOKED. virtual DeviceCertificateStatus::Status GetDeviceStatus() const; // Returns message type such as LICENSE_REQUEST, SERVICE_CERTIFICATE_REQUEST // or EXTERNAL_LICENSE_REQUEST. virtual SignedMessage::MessageType message_type() const; // Retrieves Widevine Security Profile DrmInfo of the device. // Returns true if |drm_info| was successully populated, else false. virtual bool GetDrmInfo(SecurityProfile::DrmInfo* drm_info) const; // Retrieves the ContentIdentification from the request. Returns OK, if // successful, else failure. virtual Status GetContentId( LicenseRequest::ContentIdentification* content_id) const; // Retrieves the request type. virtual LicenseRequest::RequestType request_type() const; protected: Session(std::shared_ptr env_impl, std::unique_ptr impl); Session(std::shared_ptr env_impl, std::unique_ptr external_playready_session_impl); // For testing only. This allows unit tests to define a mock Session class. Session(); friend class Environment; private: #ifndef SWIG Session(const Session&) = delete; Session& operator=(const Session&) = delete; #endif std::shared_ptr env_impl_; std::unique_ptr impl_; std::unique_ptr external_playready_session_impl_; }; } // namespace video_widevine #endif // VIDEO_WIDEVINE_EXPORT_SDK_EXTERNAL_CPP_WVDRM_LICENSE_SERVER_SDK_SESSION_H_