This CL merges the following changes from the Widevine repository: Avoid CdmSession reinitialization https://widevine-internal-review.googlesource.com/#/c/10530/ Fix timer-related unit tests. https://widevine-internal-review.googlesource.com/#/c/10510/ Correct return statement bug: 15590802 https://widevine-internal-review.googlesource.com/#/c/10553/ Usage reporting fixes bug/15388863 https://widevine-internal-review.googlesource.com/#/c/10460/ Make public methods virtual https://widevine-internal-review.googlesource.com/#/c/10500/ Fix the SetTimer contract in the CDM. https://widevine-internal-review.googlesource.com/#/c/10493/ Move inline CDM methods, add OVERRIDE. https://widevine-internal-review.googlesource.com/#/c/10475/ Simplify storage APIs related cleanup. https://widevine-internal-review.googlesource.com/#/c/10473/ Duration values are not correctly reported when queried b/15592374 https://widevine-internal-review.googlesource.com/#/c/10437/ Propagate IsKeyValid() through ContentDecryptionModule. https://widevine-internal-review.googlesource.com/#/c/10483/ Minor clean up in config_test_env. https://widevine-internal-review.googlesource.com/#/c/10440/ General clean up. https://widevine-internal-review.googlesource.com/#/c/10441/ Refactor HttpSocket and simplify UrlRequest interface. https://widevine-internal-review.googlesource.com/#/c/10410/ Install good keybox at end of unit tests b/15385981 https://widevine-internal-review.googlesource.com/#/c/10374/ Privacy crypto fixes b/15475012 https://widevine-internal-review.googlesource.com/#/c/10383/ Incorporate header files to resolve build issued based on customers feedback. https://widevine-internal-review.googlesource.com/#/c/10420/ Support unprovisioning b/12247651 https://widevine-internal-review.googlesource.com/#/c/10356/ Correct usage of Host::Allocate and Cdm::Decrypt. https://widevine-internal-review.googlesource.com/#/c/10378/ Fix logging bug, arguments in wrong order. https://widevine-internal-review.googlesource.com/#/c/10380/ Rename types that look like constants. https://widevine-internal-review.googlesource.com/#/c/10379/ Fix offline test failures b/13909635 https://widevine-internal-review.googlesource.com/#/c/10348/ Add -DUNIT_TEST to the unit test makefile for Android https://widevine-internal-review.googlesource.com/#/c/10375/ Refactor privacy-crypto and add dummy version. https://widevine-internal-review.googlesource.com/#/c/10353/ Remove References to Apiary https://widevine-internal-review.googlesource.com/#/c/9924/ Delete oldest entry in usage table when full bug: 15184824 https://widevine-internal-review.googlesource.com/#/c/10295/ Port DeviceFiles to iOS. https://widevine-internal-review.googlesource.com/#/c/10355/ Make testing functions in DeviceFiles private. https://widevine-internal-review.googlesource.com/#/c/10354/ Add RSA encryption to haystack https://widevine-internal-review.googlesource.com/#/c/10280/ Add string and vector includes to CDM header. https://widevine-internal-review.googlesource.com/#/c/10352/ First version of oemcrypto logging https://widevine-internal-review.googlesource.com/#/c/10252/ Update Names of Secure Stop Methods bug: 11987015 https://widevine-internal-review.googlesource.com/#/c/10152/ Adjust timing on the Usage Table unit test https://widevine-internal-review.googlesource.com/#/c/10307/ Fix all compiler warnings in CDM source release. https://widevine-internal-review.googlesource.com/#/c/10293/ Fix memset bug: args in wrong order https://widevine-internal-review.googlesource.com/#/c/10292/ Partial revert of 'Remove refs to test prov server, Level3 support...' https://widevine-internal-review.googlesource.com/#/c/10281/ Pack structure OEMCrypto_PST_Report https://widevine-internal-review.googlesource.com/#/c/10243/ Remove refs to test prov server, Level3 support; remove dead code https://widevine-internal-review.googlesource.com/#/c/10220/ Partial revert of 'Document data strings; clean up license server parameters.' https://widevine-internal-review.googlesource.com/#/c/10188/ Document data strings; clean up license server parameters. https://widevine-internal-review.googlesource.com/#/c/10120/ Fix broken build after partner branch merge. https://widevine-internal-review.googlesource.com/#/c/10181/ TODO Cleanup - core/src, core/include https://widevine-internal-review.googlesource.com/#/c/9965/ TODO Cleanup - cdm, chromium, core/test. https://widevine-internal-review.googlesource.com/#/c/9419/ Remove unneeded properties. https://widevine-internal-review.googlesource.com/#/c/10162/ Change-Id: If2bb9d743a562a3875bebb91933c0aaadea286b2
122 lines
4.3 KiB
C++
122 lines
4.3 KiB
C++
// Copyright 2013 Google Inc. All Rights Reserved.
|
|
|
|
#ifndef WVCDM_CORE_POLICY_ENGINE_H_
|
|
#define WVCDM_CORE_POLICY_ENGINE_H_
|
|
|
|
#include <string>
|
|
|
|
#include "license_protocol.pb.h"
|
|
#include "wv_cdm_types.h"
|
|
|
|
namespace wvcdm {
|
|
|
|
using video_widevine_server::sdk::LicenseIdentification;
|
|
|
|
class Clock;
|
|
class PolicyEngineTest;
|
|
|
|
// This acts as an oracle that basically says "Yes(true) you may still decrypt
|
|
// or no(false) you may not decrypt this data anymore."
|
|
class PolicyEngine {
|
|
public:
|
|
PolicyEngine();
|
|
virtual ~PolicyEngine();
|
|
|
|
// The value returned should be taken as a hint rather than an absolute
|
|
// status. It is computed during the last call to either SetLicense/
|
|
// UpdateLicense/OnTimerEvent/BeginDecryption and may be out of sync
|
|
// depending on the amount of time elapsed. The current decryption
|
|
// status is not calculated to avoid overhead in the decryption path.
|
|
virtual bool can_decrypt() { return can_decrypt_; }
|
|
|
|
// OnTimerEvent is called when a timer fires. It notifies the Policy Engine
|
|
// that the timer has fired and that it should check whether any events have
|
|
// occurred since the last timer event. If so, it sets event_occurred to true
|
|
// and sets event to point to the event that occurred. If not, it sets
|
|
// event_occurred to false.
|
|
virtual void OnTimerEvent(bool* event_occurred, CdmEventType* event);
|
|
|
|
// SetLicense is used in handling the initial license response. It stores
|
|
// an exact copy of the policy information stored in the license.
|
|
// The license state transitions to kLicenseStateCanPlay if the license
|
|
// permits playback.
|
|
virtual void SetLicense(const video_widevine_server::sdk::License& license);
|
|
|
|
// Call this on first decrypt to set the start of playback.
|
|
virtual void BeginDecryption(void);
|
|
|
|
// UpdateLicense is used in handling a license response for a renewal request.
|
|
// The response may only contain any policy fields that have changed. In this
|
|
// case an exact copy is not what we want to happen. We also will receive an
|
|
// updated license_start_time from the server. The license will transition to
|
|
// kLicenseStateCanPlay if the license permits playback.
|
|
virtual void UpdateLicense(
|
|
const video_widevine_server::sdk::License& license);
|
|
|
|
virtual CdmResponseType Query(CdmQueryMap* key_info);
|
|
|
|
virtual const LicenseIdentification& license_id() { return license_id_; }
|
|
|
|
private:
|
|
typedef enum {
|
|
kLicenseStateInitial,
|
|
kLicenseStateCanPlay,
|
|
kLicenseStateNeedRenewal,
|
|
kLicenseStateWaitingLicenseUpdate,
|
|
kLicenseStateExpired
|
|
} LicenseState;
|
|
|
|
void Init(Clock* clock);
|
|
|
|
bool IsLicenseDurationExpired(int64_t current_time);
|
|
int64_t GetLicenseDurationRemaining(int64_t current_time);
|
|
bool IsPlaybackDurationExpired(int64_t current_time);
|
|
int64_t GetPlaybackDurationRemaining(int64_t current_time);
|
|
|
|
bool IsRenewalDelayExpired(int64_t current_time);
|
|
bool IsRenewalRecoveryDurationExpired(int64_t current_time);
|
|
bool IsRenewalRetryIntervalExpired(int64_t current_time);
|
|
|
|
void UpdateRenewalRequest(int64_t current_time);
|
|
|
|
LicenseState license_state_;
|
|
bool can_decrypt_;
|
|
|
|
// This is the current policy information for this license. This gets updated
|
|
// as license renewals occur.
|
|
video_widevine_server::sdk::License::Policy policy_;
|
|
|
|
// This is the license id field from server response. This data gets passed
|
|
// back to the server in each renewal request. When we get a renewal response
|
|
// from the license server we will get an updated id field.
|
|
video_widevine_server::sdk::LicenseIdentification license_id_;
|
|
|
|
// This is the license start time that gets sent from the server in each
|
|
// license request or renewal.
|
|
int64_t license_start_time_;
|
|
|
|
// This is the time at which the license was received and playback was
|
|
// started. These times are based off the local clock in case there is a
|
|
// discrepency between local and server time.
|
|
int64_t license_received_time_;
|
|
int64_t playback_start_time_;
|
|
|
|
// This is used as a reference point for policy management. This value
|
|
// represents an offset from license_received_time_. This is used to
|
|
// calculate the time where renewal retries should occur.
|
|
int64_t next_renewal_time_;
|
|
int64_t policy_max_duration_seconds_;
|
|
|
|
Clock* clock_;
|
|
|
|
// For testing
|
|
friend class PolicyEngineTest;
|
|
PolicyEngine(Clock* clock);
|
|
|
|
CORE_DISALLOW_COPY_AND_ASSIGN(PolicyEngine);
|
|
};
|
|
|
|
} // wvcdm
|
|
|
|
#endif // WVCDM_CORE_POLICY_ENGINE_H_
|