Assorted Key Session Code Cleanup

Merge from Widevine repo of http://go/wvgerrit/53202
and
Merge from Widevine repo of http://go/wvgerrit/53624

This change contains a variety of small tweaks to the
ContentKeySession and EntitlementKeySession classes that were
discovered while fixing b/78652567. There should be no change in
behavior from this patch. The fixes are:

1) Added missing headers and removed unnecessary headers.

2) Removed the unused keys_ member from EntitlementKeySession.

3) Renamed ContentKeySession's protected member function so that it is
not an overload of the public LoadKeys() function. This makes it
clearer what EntitlementKeySession::LoadKeys() is doing.

4) Added missing "virtual" and "OVERRIDE" keywords.

5) Added missing copyright headers.

6) Ran clang-format with Google style.

7) Correct missing OVERRIDE keywords.

Test: tested as part of http://go/ag/4674759

Change-Id: Icb0af886d7d3eb097b5dffbb716be6ac28f0916d
This commit is contained in:
Fred Gylys-Colwell
2018-07-01 11:57:58 -07:00
parent f573bfc7b0
commit 1d594f3140
5 changed files with 71 additions and 45 deletions

View File

@@ -1,7 +1,13 @@
// 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 WVCDM_CORE_CONTENT_KEY_SESSSION_H_ #ifndef WVCDM_CORE_CONTENT_KEY_SESSSION_H_
#define WVCDM_CORE_CONTENT_KEY_SESSSION_H_ #define WVCDM_CORE_CONTENT_KEY_SESSSION_H_
#include "key_session.h" #include "key_session.h"
#include "metrics_collections.h"
#include "override.h"
#include "timer_metric.h" #include "timer_metric.h"
namespace wvcdm { namespace wvcdm {
@@ -15,45 +21,49 @@ class ContentKeySession : public KeySession {
cipher_mode_(kCipherModeCtr) {} cipher_mode_(kCipherModeCtr) {}
virtual ~ContentKeySession() {} virtual ~ContentKeySession() {}
KeySessionType Type() { return kDefault; } virtual KeySessionType Type() OVERRIDE { return kDefault; }
// Generate Derived Keys for ContentKeySession // Generate Derived Keys for ContentKeySession
bool GenerateDerivedKeys(const std::string& message); virtual bool GenerateDerivedKeys(const std::string& message) OVERRIDE;
// Generate Derived Keys (from session key) for ContentKeySession // Generate Derived Keys (from session key) for ContentKeySession
bool GenerateDerivedKeys(const std::string& message, virtual bool GenerateDerivedKeys(const std::string& message,
const std::string& session_key); const std::string& session_key) OVERRIDE;
// Load Keys for ContentKeySession // Load Keys for ContentKeySession
OEMCryptoResult LoadKeys(const std::string& message, virtual OEMCryptoResult LoadKeys(const std::string& message,
const std::string& signature, const std::string& signature,
const std::string& mac_key_iv, const std::string& mac_key_iv,
const std::string& mac_key, const std::string& mac_key,
const std::vector<CryptoKey>& keys, const std::vector<CryptoKey>& keys,
const std::string& provider_session_token, const std::string& provider_session_token,
CdmCipherMode* cipher_mode, CdmCipherMode* cipher_mode,
const std::string& srm_requirement); const std::string& srm_requirement) OVERRIDE;
OEMCryptoResult LoadEntitledContentKeys(const std::vector<CryptoKey>&) { virtual OEMCryptoResult LoadEntitledContentKeys(
const std::vector<CryptoKey>&) OVERRIDE {
return OEMCrypto_ERROR_INVALID_CONTEXT; return OEMCrypto_ERROR_INVALID_CONTEXT;
} }
// Select Key for ContentKeySession // Select Key for ContentKeySession
OEMCryptoResult SelectKey(const std::string& key_id, virtual OEMCryptoResult SelectKey(const std::string& key_id,
CdmCipherMode cipher_mode); CdmCipherMode cipher_mode) OVERRIDE;
// Decrypt for ContentKeySession // Decrypt for ContentKeySession
OEMCryptoResult Decrypt(const CdmDecryptionParameters& params, virtual OEMCryptoResult Decrypt(
OEMCrypto_DestBufferDesc& buffer_descriptor, const CdmDecryptionParameters& params,
OEMCrypto_CENCEncryptPatternDesc& pattern_descriptor); OEMCrypto_DestBufferDesc& buffer_descriptor,
OEMCrypto_CENCEncryptPatternDesc& pattern_descriptor) OVERRIDE;
protected: protected:
OEMCryptoResult LoadKeys( virtual OEMCryptoResult LoadKeysAsLicenseType(
const std::string& message, const std::string& signature, const std::string& message, const std::string& signature,
const std::string& mac_key_iv, const std::string& mac_key, const std::string& mac_key_iv, const std::string& mac_key,
const std::vector<CryptoKey>& keys, const std::vector<CryptoKey>& keys,
const std::string& provider_session_token, CdmCipherMode* cipher_mode, const std::string& provider_session_token, CdmCipherMode* cipher_mode,
const std::string& srm_requirement, OEMCrypto_LicenseType license_type); const std::string& srm_requirement,
OEMCrypto_LicenseType license_type);
CryptoSessionId oec_session_id_; CryptoSessionId oec_session_id_;
private: private:

View File

@@ -1,8 +1,13 @@
// 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 WVCDM_CORE_ENTITLEMENT_KEY_SESSSION_H_ #ifndef WVCDM_CORE_ENTITLEMENT_KEY_SESSSION_H_
#define WVCDM_CORE_ENTITLEMENT_KEY_SESSSION_H_ #define WVCDM_CORE_ENTITLEMENT_KEY_SESSSION_H_
#include "content_key_session.h" #include "content_key_session.h"
#include "key_session.h" #include "metrics_collections.h"
#include "override.h"
namespace wvcdm { namespace wvcdm {
@@ -15,18 +20,16 @@ class EntitlementKeySession : public ContentKeySession {
KeySessionType Type() { return kEntitlement; } KeySessionType Type() { return kEntitlement; }
// Load Keys for ContentKeySession // Load Keys for ContentKeySession
OEMCryptoResult LoadKeys(const std::string& message, virtual OEMCryptoResult LoadKeys(const std::string& message,
const std::string& signature, const std::string& signature,
const std::string& mac_key_iv, const std::string& mac_key_iv,
const std::string& mac_key, const std::string& mac_key,
const std::vector<CryptoKey>& keys, const std::vector<CryptoKey>& keys,
const std::string& provider_session_token, const std::string& provider_session_token,
CdmCipherMode* cipher_mode, CdmCipherMode* cipher_mode,
const std::string& srm_requirement); const std::string& srm_requirement) OVERRIDE;
OEMCryptoResult LoadEntitledContentKeys(const std::vector<CryptoKey>& keys); virtual OEMCryptoResult LoadEntitledContentKeys(
const std::vector<CryptoKey>& keys) OVERRIDE;
private:
std::vector<CryptoKey> keys_;
}; };
} // namespace wvcdm } // namespace wvcdm

View File

@@ -1,3 +1,7 @@
// 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 WVCDM_CORE_KEY_SESSSION_H_ #ifndef WVCDM_CORE_KEY_SESSSION_H_
#define WVCDM_CORE_KEY_SESSSION_H_ #define WVCDM_CORE_KEY_SESSSION_H_

View File

@@ -1,3 +1,7 @@
// 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.
#include "content_key_session.h" #include "content_key_session.h"
#include "crypto_key.h" #include "crypto_key.h"
#include "crypto_session.h" #include "crypto_session.h"
@@ -65,9 +69,9 @@ OEMCryptoResult ContentKeySession::LoadKeys(
const std::vector<CryptoKey>& keys, const std::vector<CryptoKey>& keys,
const std::string& provider_session_token, CdmCipherMode* cipher_mode, const std::string& provider_session_token, CdmCipherMode* cipher_mode,
const std::string& srm_requirement) { const std::string& srm_requirement) {
return LoadKeys(message, signature, mac_key_iv, mac_key, keys, return LoadKeysAsLicenseType(message, signature, mac_key_iv, mac_key, keys,
provider_session_token, cipher_mode, srm_requirement, provider_session_token, cipher_mode,
OEMCrypto_ContentLicense); srm_requirement, OEMCrypto_ContentLicense);
} }
// Select Key for ContentKeySession // Select Key for ContentKeySession
@@ -87,9 +91,9 @@ OEMCryptoResult ContentKeySession::SelectKey(const std::string& key_id,
reinterpret_cast<const uint8_t*>(cached_key_id_.data()); reinterpret_cast<const uint8_t*>(cached_key_id_.data());
OEMCryptoResult sts; OEMCryptoResult sts;
M_TIME(sts = OEMCrypto_SelectKey( M_TIME(sts = OEMCrypto_SelectKey(oec_session_id_, key_id_string,
oec_session_id_, key_id_string, cached_key_id_.size(), cached_key_id_.size(),
ToOEMCryptoCipherMode(cipher_mode)), ToOEMCryptoCipherMode(cipher_mode)),
metrics_, oemcrypto_select_key_, sts); metrics_, oemcrypto_select_key_, sts);
if (OEMCrypto_SUCCESS != sts) { if (OEMCrypto_SUCCESS != sts) {
@@ -113,7 +117,7 @@ OEMCryptoResult ContentKeySession::Decrypt(
return sts; return sts;
} }
OEMCryptoResult ContentKeySession::LoadKeys( OEMCryptoResult ContentKeySession::LoadKeysAsLicenseType(
const std::string& message, const std::string& signature, const std::string& message, const std::string& signature,
const std::string& mac_key_iv, const std::string& mac_key, const std::string& mac_key_iv, const std::string& mac_key,
const std::vector<CryptoKey>& keys, const std::vector<CryptoKey>& keys,
@@ -127,7 +131,7 @@ OEMCryptoResult ContentKeySession::LoadKeys(
enc_mac_key = msg + GetOffset(message, mac_key); enc_mac_key = msg + GetOffset(message, mac_key);
enc_mac_key_iv = msg + GetOffset(message, mac_key_iv); enc_mac_key_iv = msg + GetOffset(message, mac_key_iv);
} else { } else {
LOGV("ContentKeySession::LoadKeys: enc_mac_key not set"); LOGV("enc_mac_key not set");
} }
std::vector<OEMCrypto_KeyObject_V13> load_keys(keys.size()); std::vector<OEMCrypto_KeyObject_V13> load_keys(keys.size());
for (size_t i = 0; i < keys.size(); ++i) { for (size_t i = 0; i < keys.size(); ++i) {
@@ -164,7 +168,7 @@ OEMCryptoResult ContentKeySession::LoadKeys(
srm_req = const_cast<uint8_t*>(msg) + GetOffset(message, srm_requirement); srm_req = const_cast<uint8_t*>(msg) + GetOffset(message, srm_requirement);
} }
LOGV("LoadKeys: id=%ld", (uint32_t)oec_session_id_); LOGV("id=%ld", (uint32_t)oec_session_id_);
OEMCryptoResult sts; OEMCryptoResult sts;
M_TIME( M_TIME(
sts = ::OEMCrypto_LoadKeys_Back_Compat( sts = ::OEMCrypto_LoadKeys_Back_Compat(

View File

@@ -1,3 +1,7 @@
// 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.
#include "entitlement_key_session.h" #include "entitlement_key_session.h"
#include "crypto_key.h" #include "crypto_key.h"
@@ -13,8 +17,9 @@ OEMCryptoResult EntitlementKeySession::LoadKeys(
const std::vector<CryptoKey>& keys, const std::vector<CryptoKey>& keys,
const std::string& provider_session_token, CdmCipherMode* cipher_mode, const std::string& provider_session_token, CdmCipherMode* cipher_mode,
const std::string& srm_requirement) { const std::string& srm_requirement) {
keys_.resize(keys.size()); // Call our superclass's LoadKeysAsLicenseType(), but set the license type to
return ContentKeySession::LoadKeys( // OEMCrypto_EntitlementLicense.
return ContentKeySession::LoadKeysAsLicenseType(
message, signature, mac_key_iv, mac_key, keys, provider_session_token, message, signature, mac_key_iv, mac_key, keys, provider_session_token,
cipher_mode, srm_requirement, OEMCrypto_EntitlementLicense); cipher_mode, srm_requirement, OEMCrypto_EntitlementLicense);
} }
@@ -51,4 +56,4 @@ OEMCryptoResult EntitlementKeySession::LoadEntitledContentKeys(
return result; return result;
} }
} // namespace wvcdm } // namespace wvcdm