Merge changes Iacbbd51a,Id925ddcc

* changes:
  Add policy handling for v16
  More policy engine/timers refactoring
This commit is contained in:
Rahul Frias
2020-02-19 15:37:35 +00:00
committed by Android (Google) Code Review
14 changed files with 2058 additions and 257 deletions

View File

@@ -58,7 +58,8 @@ class PolicyEngine {
// 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::License& license);
virtual void SetLicense(const video_widevine::License& license,
bool supports_core_messages);
// Used to update the currently loaded entitled content keys.
virtual void SetEntitledLicenseKeys(
@@ -66,7 +67,8 @@ class PolicyEngine {
// SetLicenseForRelease is used when releasing a license. The keys in this
// license will be ignored, and any old keys will be expired.
virtual void SetLicenseForRelease(const video_widevine::License& license);
virtual void SetLicenseForRelease(const video_widevine::License& license,
bool supports_core_messages);
// Call this on first decrypt to set the start of playback.
virtual bool BeginDecryption(void);
@@ -105,8 +107,8 @@ class PolicyEngine {
bool IsLicenseForFuture() { return license_state_ == kLicenseStatePending; }
bool HasLicenseOrPlaybackDurationExpired(int64_t current_time);
int64_t GetLicenseOrPlaybackDurationRemaining();
bool HasLicenseOrRentalOrPlaybackDurationExpired(int64_t current_time);
int64_t GetLicenseOrRentalOrPlaybackDurationRemaining();
bool CanRenew() const;
@@ -177,7 +179,7 @@ class PolicyEngine {
uint32_t current_resolution_;
CryptoSession* crypto_session_;
std::unique_ptr<PolicyTimers> policy_timers;
std::unique_ptr<PolicyTimers> policy_timers_;
std::unique_ptr<Clock> clock_;
CORE_DISALLOW_COPY_AND_ASSIGN(PolicyEngine);

View File

@@ -28,9 +28,10 @@ class PolicyTimers {
// SetLicense is used in handling the initial license response.
virtual void SetLicense(const video_widevine::License& license);
// UpdateLicense is used in handling a license response for a renewal request.
// The response may only contain policy fields that have changed. In this
// case an exact copy is not what we want to happen.
// UpdateLicense is used in handling a license response, a renewal response,
// or when restoring or releasing a persistent license.
// In a renewal the response may only contain policy fields that have
// changed. In this case an exact copy is not what we want to happen.
virtual bool UpdateLicense(int64_t current_time,
const video_widevine::License& license) = 0;
@@ -49,13 +50,17 @@ class PolicyTimers {
int64_t grace_period_end_time) = 0;
virtual bool HasPlaybackStarted(int64_t current_time) = 0;
virtual bool HasLicenseOrPlaybackDurationExpired(int64_t current_time) = 0;
virtual bool HasLicenseOrRentalOrPlaybackDurationExpired(
int64_t current_time) = 0;
virtual bool HasPassedGracePeriod(int64_t current_time) = 0;
virtual int64_t GetLicenseOrPlaybackDurationRemaining(
virtual int64_t GetLicenseOrRentalOrPlaybackDurationRemaining(
int64_t current_time) = 0;
virtual int64_t GetLicenseOrRentalDurationRemaining(int64_t current_time) = 0;
virtual int64_t GetPlaybackDurationRemaining(int64_t current_time) = 0;
// This is only used in Query. This should return |playback_duration_seconds|
// before playback begins or the time remaining on
// |playback_duration_seconds| after playback begins.
virtual int64_t GetPlaybackDurationRemaining(int64_t current_time);
virtual bool GetSecondsSinceStarted(int64_t current_time,
int64_t* seconds_since_started);
@@ -89,6 +94,8 @@ class PolicyTimers {
virtual int64_t GetExpiryTime(int64_t current_time,
bool ignore_soft_enforce_playback_duration) = 0;
virtual int64_t GetRenewalStartTime() = 0;
// This is the current policy information for this license. This gets updated
// as license renewals occur.
video_widevine::License::Policy policy_;

View File

@@ -29,11 +29,17 @@ class PolicyTimersV15 : public PolicyTimers {
public:
PolicyTimersV15() : grace_period_end_time_(0) {}
virtual ~PolicyTimersV15(){};
virtual ~PolicyTimersV15() {}
// 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.
// UpdateLicense is used in handling a license response, a renewal response,
// or when restoring or releasing a persistent license.
// In a renewal the response may only contain policy fields that have
// changed. In this case an exact copy is not what we want to happen.
// |license_start_time_| is updated to the time mentioned in the renewal
// response.
// UpdateLicense will return false if |license_start_time| is not
// present or playback is not allowed due to policy or timer duration
// expiration.
bool UpdateLicense(int64_t current_time,
const video_widevine::License& license) override;
@@ -49,17 +55,21 @@ class PolicyTimersV15 : public PolicyTimers {
int64_t grace_period_end_time) override;
bool HasPlaybackStarted(int64_t current_time) override;
bool HasLicenseOrPlaybackDurationExpired(int64_t current_time) override;
bool HasLicenseOrRentalOrPlaybackDurationExpired(
int64_t current_time) override;
bool HasPassedGracePeriod(int64_t current_time) override;
int64_t GetLicenseOrPlaybackDurationRemaining(int64_t current_time) override;
// This returns
// * for streaming licenses: the time remaining on |license_duration_seconds|
// * for persistent licenses: the time remaining on |rental_duration_seconds|
// before playback begins or the time remaining on
// |playback_duration_seconds| after.
int64_t GetLicenseOrRentalOrPlaybackDurationRemaining(
int64_t current_time) override;
// This is only used in Query. This should return the time remaining on
// license_duration_seconds for streaming licenses and rental_duration_seconds
// for offline licenses.
// |license_duration_seconds| for streaming licenses and
// |rental_duration_seconds| for persistent licenses.
int64_t GetLicenseOrRentalDurationRemaining(int64_t current_time) override;
// This is only used in Query. This should return playback_duration_seconds,
// or the time remaining on it if playing.
int64_t GetPlaybackDurationRemaining(int64_t current_time) override;
protected:
// Gets the clock time that the license expires based on whether we have
@@ -67,6 +77,8 @@ class PolicyTimersV15 : public PolicyTimers {
int64_t GetExpiryTime(int64_t current_time,
bool ignore_soft_enforce_playback_duration) override;
int64_t GetRenewalStartTime() override { return license_start_time_; }
private:
// Gets the clock time that the license expires. This is the hard limit that
// all license types must obey at all times.

View File

@@ -0,0 +1,111 @@
// Copyright 2020 Google LLC. All Rights Reserved. This file and proprietary
// source code may only be used and distributed under the Widevine Master
// License Agreement.
#ifndef WVCDM_CORE_POLICY_TIMERS_V16_H_
#define WVCDM_CORE_POLICY_TIMERS_V16_H_
#include "disallow_copy_and_assign.h"
#include "license_protocol.pb.h"
#include "policy_timers.h"
#include "wv_cdm_types.h"
namespace wvcdm {
// OEMCrypto v16 and core messages introduced changes to how duration values
// and clocks should be evaluated. This class provides backward compatibility
// for licenses that do not include a core message. Durations are handled
// in the same way as in earlier releases.
//
// Backward compatibility may be needed if
// * OEMCrypto has not been upgraded to v16
// * Licenses were persisted before the device was upgraded to v16
// * License service does not yet support core messages
class PolicyTimersV16 : public PolicyTimers {
public:
PolicyTimersV16() {}
virtual ~PolicyTimersV16() {}
// UpdateLicense is used in handling a license response, a renewal response,
// or when restoring or releasing a persistent license.
// In a renewal the response may only contain policy fields that have
// changed. In this case an exact copy is not what we want to happen.
// |renewal_start_time_| is set to the time mentioned in the renewal
// response.
// UpdateLicense will return false if |license_start_time| is not
// present or playback is not allowed due to policy or timer duration
// expiration.
bool UpdateLicense(int64_t current_time,
const video_widevine::License& license) override;
// Call this on first decrypt to set the start of playback.
void BeginDecryption(int64_t current_time) override;
// This is a legacy field for offline licenses. Since no grace period is
// supported return a default value.
int64_t GetGracePeriodEndTime() override { return 0; }
// For offline save and restore.
void RestorePlaybackTimes(int64_t current_time, int64_t playback_start_time,
int64_t last_playback_time,
int64_t grace_period_end_time) override;
bool HasPlaybackStarted(int64_t /* current_time */) override {
return playback_start_time_ != 0;
}
// For licenses that support core messages, evaluation of only rental and
// playback durations are needed.
bool HasLicenseOrRentalOrPlaybackDurationExpired(
int64_t current_time) override {
return HasRentalOrPlaybackDurationExpired(current_time);
}
bool HasPassedGracePeriod(int64_t /* current_time */) override {
return true;
}
// This returns
// * before playback begins: the time remaining on |rental_duration_seconds|
// * after playback begins:
// - |soft_enforce_playback_duration| is true: the time remaining on
// |playback_duration_seconds|
// - |soft_enforce_playback_duration| is false: the minimum
// of the time remaining on |rental_duration_seconds| or
// |playback_duration_seconds|
//
// |license_duration_seconds| is ignored with the introduction of core
// messages
int64_t GetLicenseOrRentalOrPlaybackDurationRemaining(
int64_t current_time) override;
// This is only used in Query. This should return the time remaining on
// |rental_duration_seconds|.
int64_t GetLicenseOrRentalDurationRemaining(int64_t current_time) override {
return GetRentalDurationRemaining(current_time);
};
protected:
// Gets the clock time that the license expires based on whether we have
// started playing. This takes into account GetHardLicenseExpiryTime.
int64_t GetExpiryTime(int64_t current_time,
bool ignore_soft_enforce_playback_duration) override;
int64_t GetRenewalStartTime() override { return renewal_start_time_; }
private:
// Gets the clock time that the rental duration or playback will expire.
int64_t GetRentalExpiryTime(int64_t current_time);
int64_t GetPlaybackExpiryTime(int64_t current_time,
bool ignore_soft_enforce_playback_duration);
bool HasRentalOrPlaybackDurationExpired(int64_t current_time);
int64_t GetRentalDurationRemaining(int64_t current_time);
int64_t renewal_start_time_ = 0;
CORE_DISALLOW_COPY_AND_ASSIGN(PolicyTimersV16);
};
} // namespace wvcdm
#endif // WVCDM_CORE_POLICY_TIMERS_V16_H_

View File

@@ -25,6 +25,7 @@ static const size_t CERTIFICATE_DATA_SIZE = 4 * 1024;
// Use 0 to represent never expired license as specified in EME spec
// (NaN in JS translates to 0 in unix timestamp).
static const int64_t NEVER_EXPIRES = 0;
static const int64_t UNLIMITED_DURATION = 0;
// This is the lower limit. For OEMCrypto v16+ one can query and find how many
// are supported