Files
media_cas_client/plugin/include/widevine_cas_session.h
Lu Chen 00785b2ccd Regular update
Plugin:
1. Process ECM v3 and send fingerprinting/service_blocking events
2. Rmove unused function Ctr128Add
3. Add support for ECM v3

OEMCrypto:
1. Update API description of OEMCrypto_LoadCasECMKeys
2. Fix android build files for ODK
3. Load content keys to shared memory
4. Move KCB check to LoadCasKeys call
5. Support even/odd content keys to share entitlement key
2021-01-05 10:16:26 -08:00

97 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);
// Get the current key information. This method will be used by a descrambler
// plugin to obtain the current key information.
const KeySlot& key(KeySlotId slot_id) const;
// 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.
virtual CasStatus processEcm(const CasEcm& ecm, uint8_t parental_control_age);
// 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<const 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