Note that this version does not have Widevine Provisioning 4.0 support. It is only suitable for device upgrades. A new patch with provisioning 4.0 support will be made later.
114 lines
3.9 KiB
C++
114 lines
3.9 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_SESSION_H
|
|
#define WIDEVINE_CAS_SESSION_H
|
|
|
|
#include <memory>
|
|
#include <mutex>
|
|
#include <set>
|
|
#include <string>
|
|
|
|
#include "cas_types.h"
|
|
#include "crypto_session.h"
|
|
#include "ecm_parser.h"
|
|
#include "media_cas.pb.h"
|
|
|
|
namespace wvcas {
|
|
|
|
class WidevineCasSession;
|
|
typedef std::shared_ptr<WidevineCasSession> CasSessionPtr;
|
|
|
|
class CasKeySlotData {
|
|
public:
|
|
CasKeySlotData() {}
|
|
~CasKeySlotData() {}
|
|
|
|
KeySlot& operator[](KeySlotId slot_id);
|
|
const KeySlot& operator[](KeySlotId slot_id) const;
|
|
|
|
private:
|
|
KeySlot keys_[2]; // Odd and even key slots.
|
|
};
|
|
|
|
enum class ScramblingControl {
|
|
kScrambling_Unscrambled = 0,
|
|
kScrambling_Reserved = 1,
|
|
kScrambling_EvenKey = 2,
|
|
kScrambling_OddKey = 3,
|
|
};
|
|
|
|
// WidevineCasSession represents an encryption context for a single ECM key
|
|
// stream. It processes ECMs for the stream and maintains the key information.
|
|
class WidevineCasSession {
|
|
public:
|
|
WidevineCasSession() {}
|
|
virtual ~WidevineCasSession();
|
|
|
|
CasStatus initialize(std::shared_ptr<CryptoSession> crypto_session,
|
|
CasEventListener* event_listener,
|
|
WvCasSessionId* session_id);
|
|
|
|
CasStatus resetCryptoSession(std::shared_ptr<CryptoSession> crypto_session);
|
|
|
|
// Process an ecm and extract the key slot data. Extracted data will be used
|
|
// to update |current_ecm_| and |entitlement_key_id_| and |keys_|.
|
|
// |parental_control_age| (if non-zero) must be greater or equal to the
|
|
// age_restriction field specified in |ecm|. Otherwise, ECM will not be
|
|
// processed and error will be returned.
|
|
// |license_group_id| if non empty, processEcm will decrypt content keys that
|
|
// are specified by |license_group_id|.
|
|
virtual CasStatus processEcm(const CasEcm& ecm, uint8_t parental_control_age,
|
|
const std::string& license_group_id);
|
|
|
|
// Returns the security level retrieved from OEMCrypto.
|
|
const char* securityLevel();
|
|
|
|
// Returns current ecm age restriction value.
|
|
uint8_t GetEcmAgeRestriction() const { return ecm_age_restriction_; }
|
|
// Returns the entitlement period index specified in the last received ECM.
|
|
uint32_t GetEntitlementPeriodIndex() const {
|
|
return entitlement_period_index_;
|
|
}
|
|
// Returns the entitlement rotation window left value specified in the last
|
|
// received ECM.
|
|
uint32_t GetEntitlementRotationWindowLeft() const {
|
|
return entitlement_rotation_window_left_;
|
|
}
|
|
|
|
WidevineCasSession(const WidevineCasSession&) = delete;
|
|
WidevineCasSession& operator=(const WidevineCasSession&) = delete;
|
|
|
|
private:
|
|
// Creates an EcmParser.
|
|
virtual std::unique_ptr<EcmParser> getEcmParser(const CasEcm& ecm) const;
|
|
|
|
CasKeySlotData keys_; // Odd and even key slots.
|
|
std::string entitlement_key_id_;
|
|
std::mutex crypto_lock_;
|
|
CasEcm current_ecm_;
|
|
uint8_t ecm_age_restriction_ = 0;
|
|
std::shared_ptr<CryptoSession> crypto_session_;
|
|
// Id of the entitled key session in OEMCrypto associated with this session.
|
|
uint32_t key_session_id_;
|
|
// This is the session id returned to the app. It is actually the OEM key
|
|
// token.
|
|
std::vector<uint8_t> external_key_session_id_;
|
|
CasEventListener* event_listener_ = nullptr;
|
|
// Fingerprinting events sent in processing last ECM/EMM. Used to avoid
|
|
// sending a same event again.
|
|
std::vector<uint8_t> last_fingerprinting_message_;
|
|
// Service blocking events sent in processing last ECM/EMM. Used to avoid
|
|
// sending a same event again.
|
|
std::vector<uint8_t> last_service_blocking_message_;
|
|
// The entitlement period index in the last received ECM.
|
|
uint32_t entitlement_period_index_;
|
|
// The entitlement rotation window left in the last received ECM.
|
|
uint32_t entitlement_rotation_window_left_;
|
|
};
|
|
|
|
} // namespace wvcas
|
|
|
|
#endif // WIDEVINE_CAS_SESSION_H
|