diff --git a/libwvdrmengine/cdm/core/include/crypto_session.h b/libwvdrmengine/cdm/core/include/crypto_session.h index f5ca67bb..f435829a 100644 --- a/libwvdrmengine/cdm/core/include/crypto_session.h +++ b/libwvdrmengine/cdm/core/include/crypto_session.h @@ -94,6 +94,9 @@ class CryptoSession { KeyId key_id_; + uint64_t request_id_base_; + static uint64_t request_id_index_; + CORE_DISALLOW_COPY_AND_ASSIGN(CryptoSession); }; diff --git a/libwvdrmengine/cdm/core/src/crypto_session.cpp b/libwvdrmengine/cdm/core/src/crypto_session.cpp index b14d5f0e..f531763e 100644 --- a/libwvdrmengine/cdm/core/src/crypto_session.cpp +++ b/libwvdrmengine/cdm/core/src/crypto_session.cpp @@ -31,11 +31,13 @@ namespace wvcdm { Lock CryptoSession::crypto_lock_; bool CryptoSession::initialized_ = false; int CryptoSession::session_count_ = 0; +uint64_t CryptoSession::request_id_index_ = 0; CryptoSession::CryptoSession() : open_(false), is_destination_buffer_type_valid_(false), - requested_security_level_(kLevelDefault) { + requested_security_level_(kLevelDefault), + request_id_base_(0) { Init(); } @@ -227,7 +229,12 @@ CdmResponseType CryptoSession::Open(SecurityLevel requested_security_level) { } else if (OEMCrypto_ERROR_TOO_MANY_SESSIONS == sts) { return INSUFFICIENT_CRYPTO_RESOURCES; } - return open_ ? NO_ERROR : UNKNOWN_ERROR; + if (!open_) return UNKNOWN_ERROR; + + OEMCrypto_GetRandom(reinterpret_cast(&request_id_base_), + sizeof(request_id_base_)); + ++request_id_index_; + return NO_ERROR; } void CryptoSession::Close() { @@ -243,8 +250,10 @@ void CryptoSession::Close() { void CryptoSession::GenerateRequestId(std::string& req_id_str) { LOGV("CryptoSession::GenerateRequestId: Lock"); AutoLock auto_lock(crypto_lock_); - // TODO(gmorgan): Get unique ID from OEMCrypto - req_id_str.assign("987654321"); + req_id_str = HexEncode(reinterpret_cast(&request_id_base_), + sizeof(request_id_base_)) + + HexEncode(reinterpret_cast(&request_id_index_), + sizeof(request_id_index_)); } bool CryptoSession::PrepareRequest(const std::string& message, @@ -275,8 +284,9 @@ bool CryptoSession::PrepareRenewalRequest(const std::string& message, AutoLock auto_lock(crypto_lock_); if (!signature) { - LOGE("CryptoSession::PrepareRenewalRequest : No output destination " - "provided."); + LOGE( + "CryptoSession::PrepareRenewalRequest : No output destination " + "provided."); return false; } @@ -306,8 +316,9 @@ void CryptoSession::GenerateMacContext(const std::string& input_context, void CryptoSession::GenerateEncryptContext(const std::string& input_context, std::string* deriv_context) { if (!deriv_context) { - LOGE("CryptoSession::GenerateEncryptContext : No output destination " - "provided."); + LOGE( + "CryptoSession::GenerateEncryptContext : No output destination " + "provided."); return; }