Refactor key sessions to move them out of crypto session.
Merge from Widevine repo of http://go/wvgerrit/41833 Bug: 64003606 Test: in child CL Change-Id: I3e1d36d0b0944dce0fb1515257bc15243d76f397
This commit is contained in:
committed by
Rahul Frias
parent
8de7caf788
commit
8251aab9f6
51
libwvdrmengine/cdm/core/include/content_key_session.h
Normal file
51
libwvdrmengine/cdm/core/include/content_key_session.h
Normal file
@@ -0,0 +1,51 @@
|
||||
#ifndef WVCDM_CORE_CONTENT_KEY_SESSSION_H_
|
||||
#define WVCDM_CORE_CONTENT_KEY_SESSSION_H_
|
||||
|
||||
#include "key_session.h"
|
||||
#include "timer_metric.h"
|
||||
|
||||
namespace wvcdm {
|
||||
|
||||
class DefaultKeySession : public KeySession {
|
||||
public:
|
||||
DefaultKeySession(CryptoSessionId oec_session_id,
|
||||
metrics::CryptoMetrics* metrics)
|
||||
: KeySession(metrics), oec_session_id_(oec_session_id) {}
|
||||
virtual ~DefaultKeySession() {}
|
||||
|
||||
KeySessionType Type() { return kDefault; }
|
||||
|
||||
// Generate Derived Keys for DefaultKeySession
|
||||
bool GenerateDerivedKeys(const std::string& message);
|
||||
|
||||
// Generate Derived Keys (from session key) for DefaultKeySession
|
||||
bool GenerateDerivedKeys(const std::string& message,
|
||||
const std::string& session_key);
|
||||
|
||||
// Load Keys for DefaultKeySession
|
||||
OEMCryptoResult LoadKeys(const std::string& message,
|
||||
const std::string& signature,
|
||||
const std::string& mac_key_iv,
|
||||
const std::string& mac_key,
|
||||
const std::vector<CryptoKey>& keys,
|
||||
const std::string& provider_session_token,
|
||||
CdmCipherMode* cipher_mode,
|
||||
const std::string& srm_requirement);
|
||||
|
||||
// Select Key for DefaultKeySession
|
||||
OEMCryptoResult SelectKey(const std::string& key_id,
|
||||
CdmCipherMode cipher_mode);
|
||||
|
||||
// Decrypt for DefaultKeySession
|
||||
OEMCryptoResult Decrypt(const CdmDecryptionParameters& params,
|
||||
OEMCrypto_DestBufferDesc& buffer_descriptor,
|
||||
OEMCrypto_CENCEncryptPatternDesc& pattern_descriptor);
|
||||
|
||||
private:
|
||||
CryptoSessionId oec_session_id_;
|
||||
KeyId cached_key_id_;
|
||||
};
|
||||
|
||||
} // namespace wvcdm
|
||||
|
||||
#endif // WVCDM_CORE_CONTENT_KEY_SESSSION_H_
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "OEMCryptoCENC.h"
|
||||
#include "key_session.h"
|
||||
#include "lock.h"
|
||||
#include "metrics_collections.h"
|
||||
#include "oemcrypto_adapter.h"
|
||||
@@ -22,37 +23,13 @@ class CryptoKey;
|
||||
class UsageTableHeader;
|
||||
|
||||
typedef std::map<std::string, CryptoKey*> CryptoKeyMap;
|
||||
typedef std::map<std::string, CryptoSessionId> SubLicenseSessionMap;
|
||||
|
||||
class KeySession {
|
||||
protected:
|
||||
KeySession(metrics::CryptoMetrics* metrics) : metrics_(metrics) {}
|
||||
|
||||
public:
|
||||
typedef enum { kDefault, kSubLicense } KeySessionType;
|
||||
virtual ~KeySession() {}
|
||||
virtual KeySessionType Type() = 0;
|
||||
virtual bool GenerateDerivedKeys(const std::string& message) = 0;
|
||||
virtual bool GenerateDerivedKeys(const std::string& message,
|
||||
const std::string& session_key) = 0;
|
||||
virtual OEMCryptoResult LoadKeys(const std::string& message,
|
||||
const std::string& signature,
|
||||
const std::string& mac_key_iv,
|
||||
const std::string& mac_key,
|
||||
const std::vector<CryptoKey>& keys,
|
||||
const std::string& provider_session_token,
|
||||
CdmCipherMode* cipher_mode,
|
||||
const std::string& srm_requirement) = 0;
|
||||
virtual OEMCryptoResult SelectKey(const std::string& key_id,
|
||||
CdmCipherMode cipher_mode) = 0;
|
||||
virtual OEMCryptoResult Decrypt(
|
||||
const CdmDecryptionParameters& params,
|
||||
OEMCrypto_DestBufferDesc& buffer_descriptor,
|
||||
OEMCrypto_CENCEncryptPatternDesc& pattern_descriptor) = 0;
|
||||
|
||||
protected:
|
||||
metrics::CryptoMetrics* metrics_;
|
||||
};
|
||||
// Crypto session utility functions used by KeySession implementations.
|
||||
void GenerateMacContext(const std::string& input_context,
|
||||
std::string* deriv_context);
|
||||
void GenerateEncryptContext(const std::string& input_context,
|
||||
std::string* deriv_context);
|
||||
size_t GetOffset(std::string message, std::string field);
|
||||
|
||||
class CryptoSession {
|
||||
public:
|
||||
|
||||
44
libwvdrmengine/cdm/core/include/key_session.h
Normal file
44
libwvdrmengine/cdm/core/include/key_session.h
Normal file
@@ -0,0 +1,44 @@
|
||||
#ifndef WVCDM_CORE_KEY_SESSSION_H_
|
||||
#define WVCDM_CORE_KEY_SESSSION_H_
|
||||
|
||||
#include "metrics_collections.h"
|
||||
|
||||
namespace wvcdm {
|
||||
|
||||
class CryptoKey;
|
||||
|
||||
class KeySession {
|
||||
protected:
|
||||
KeySession(metrics::CryptoMetrics* metrics) : metrics_(metrics) {}
|
||||
|
||||
public:
|
||||
typedef enum { kDefault, kSubLicense } KeySessionType;
|
||||
virtual ~KeySession() {}
|
||||
virtual KeySessionType Type() = 0;
|
||||
virtual bool GenerateDerivedKeys(const std::string& message) = 0;
|
||||
virtual bool GenerateDerivedKeys(const std::string& message,
|
||||
const std::string& session_key) = 0;
|
||||
virtual OEMCryptoResult LoadKeys(const std::string& message,
|
||||
const std::string& signature,
|
||||
const std::string& mac_key_iv,
|
||||
const std::string& mac_key,
|
||||
const std::vector<CryptoKey>& keys,
|
||||
const std::string& provider_session_token,
|
||||
CdmCipherMode* cipher_mode,
|
||||
const std::string& srm_requirement) = 0;
|
||||
virtual OEMCryptoResult SelectKey(const std::string& key_id,
|
||||
CdmCipherMode cipher_mode) = 0;
|
||||
virtual OEMCryptoResult Decrypt(
|
||||
const CdmDecryptionParameters& params,
|
||||
OEMCrypto_DestBufferDesc& buffer_descriptor,
|
||||
OEMCrypto_CENCEncryptPatternDesc& pattern_descriptor) = 0;
|
||||
|
||||
protected:
|
||||
metrics::CryptoMetrics* metrics_;
|
||||
};
|
||||
|
||||
typedef std::map<std::string, CryptoSessionId> SubLicenseSessionMap;
|
||||
|
||||
} // namespace wvcdm
|
||||
|
||||
#endif // WVCDM_CORE_KEY_SESSSION_H_
|
||||
91
libwvdrmengine/cdm/core/include/sublicense_key_session.h
Normal file
91
libwvdrmengine/cdm/core/include/sublicense_key_session.h
Normal file
@@ -0,0 +1,91 @@
|
||||
#ifndef WVCDM_CORE_SUBLICENSE_KEY_SESSSION_H_
|
||||
#define WVCDM_CORE_SUBLICENSE_KEY_SESSSION_H_
|
||||
|
||||
#include "crypto_key.h"
|
||||
#include "key_session.h"
|
||||
|
||||
namespace wvcdm {
|
||||
|
||||
class SubLicenseKeySession : public KeySession {
|
||||
typedef enum {
|
||||
kInitializing,
|
||||
kInitialLicenseLoaded,
|
||||
kInitialLicenseFailed,
|
||||
} SubLicenseState;
|
||||
|
||||
public:
|
||||
SubLicenseKeySession(SubLicenseSessionMap& sub_license_oec_sessions,
|
||||
metrics::CryptoMetrics* metrics,
|
||||
const std::string& wrapped_private_device_key,
|
||||
SecurityLevel requested_security_level,
|
||||
const std::string& group_master_key_id);
|
||||
|
||||
virtual ~SubLicenseKeySession();
|
||||
|
||||
KeySessionType Type() { return kSubLicense; }
|
||||
|
||||
// This version of GenerateDerivedKeys is for devices using keyboxes. It is
|
||||
// not supported using sub licenses.
|
||||
bool GenerateDerivedKeys(const std::string&) { return false; }
|
||||
|
||||
// GenerateDerivedKeys is called for each open oemcrypto session and is only
|
||||
// called once.
|
||||
bool GenerateDerivedKeys(const std::string& message,
|
||||
const std::string& session_key);
|
||||
|
||||
// Load the keys in |keys|. The initial keys are saved for key rotation.
|
||||
OEMCryptoResult LoadKeys(const std::string& message,
|
||||
const std::string& signature,
|
||||
const std::string& mac_key_iv,
|
||||
const std::string& mac_key,
|
||||
const std::vector<CryptoKey>& keys,
|
||||
const std::string& provider_session_token,
|
||||
CdmCipherMode* cipher_mode,
|
||||
const std::string& srm_requirement);
|
||||
|
||||
// Each oemcrypto session contains a single key. Find the right sub session
|
||||
// and save it's id as the selected oemcrypto session.
|
||||
OEMCryptoResult SelectKey(const std::string& key_id,
|
||||
CdmCipherMode cipher_mode);
|
||||
|
||||
// Decrypt performs the decryption using the selected oemcrypto session.
|
||||
// TODO(jfore): Support DecryptInChunks.
|
||||
OEMCryptoResult Decrypt(const CdmDecryptionParameters& params,
|
||||
OEMCrypto_DestBufferDesc& buffer_descriptor,
|
||||
OEMCrypto_CENCEncryptPatternDesc& pattern_descriptor);
|
||||
|
||||
private:
|
||||
// Destroy each open oemcrypto session and relace them with new ones.
|
||||
OEMCryptoResult ResetCryptoSessions();
|
||||
|
||||
// DoLoadKeys loads a single key into each oemcrypto session.
|
||||
OEMCryptoResult DoLoadKeys(const std::string& message,
|
||||
const std::string& signature,
|
||||
const std::string& mac_key_iv,
|
||||
const std::string& mac_key,
|
||||
const std::vector<CryptoKey>& keys,
|
||||
const std::string& provider_session_token,
|
||||
CdmCipherMode* cipher_mode,
|
||||
const std::string& srm_requirement);
|
||||
|
||||
// DoLoadKeys loads a single key into each oemcrypto session.
|
||||
OEMCryptoResult DoSubLicenseLoadKeys(
|
||||
const std::string& message, const std::string& signature,
|
||||
const std::string& mac_key_iv, const std::string& mac_key,
|
||||
const CryptoKey& key, const std::string& provider_session_token,
|
||||
CdmCipherMode*, const std::string& srm_requirement);
|
||||
|
||||
SubLicenseState state_;
|
||||
std::string cached_sub_session_key_id_;
|
||||
std::string wrapped_private_device_key_;
|
||||
std::string message_;
|
||||
std::string session_key_;
|
||||
std::vector<CryptoKey> keys_;
|
||||
SubLicenseSessionMap& sub_license_oec_sessions_;
|
||||
SecurityLevel requested_security_level_;
|
||||
KeyId group_master_key_id_;
|
||||
};
|
||||
|
||||
} // namespace wvcdm
|
||||
|
||||
#endif // WVCDM_CORE_SUBLICENSE_KEY_SESSSION_H_
|
||||
Reference in New Issue
Block a user