Files
media_cas_client/plugin/include/widevine_cas_session.h
2021-03-05 16:09:59 -08:00

95 lines
3.0 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, uint32_t* session_id);
// 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() { return ecm_age_restriction_; }
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 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_;
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_;
};
} // namespace wvcas
#endif // WIDEVINE_CAS_SESSION_H