New CdmResponseType fields: oec_result & crypto_session_method

[ Merge of go/wvgerrit/163437 ]

Bug: 253271674
Test: cdm unit tests
Change-Id: I064e28af593e4a55c13d03115bb5181a879a1ed4
This commit is contained in:
Robert Shih
2022-12-11 10:16:37 -08:00
parent adf20ed758
commit 2384efde1e
5 changed files with 124 additions and 94 deletions

View File

@@ -12,6 +12,8 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "OEMCryptoCENC.h"
namespace wvcdm { namespace wvcdm {
using CdmKeySystem = std::string; using CdmKeySystem = std::string;
@@ -448,27 +450,44 @@ enum CdmResponseEnum : int32_t {
}; };
struct CdmResponseType { struct CdmResponseType {
CdmResponseType() : status_(NO_ERROR){}; explicit CdmResponseType(CdmResponseEnum status = NO_ERROR,
explicit CdmResponseType(CdmResponseEnum status) : status_(status){}; OEMCryptoResult oec_result = OEMCrypto_SUCCESS,
const char* crypto_session_method = nullptr)
: status_(status),
oec_result_(oec_result),
crypto_session_method_(crypto_session_method){};
explicit operator CdmResponseEnum() const { return status_; }; explicit operator CdmResponseEnum() const { return status_; };
explicit operator std::string() { explicit operator std::string() {
std::string str = "status = "; std::string str = "status = ";
str.append(std::to_string(static_cast<int>(status_))); str.append(std::to_string(static_cast<int>(status_)));
if (oec_result_) {
str.append("; oec_result = ");
str.append(std::to_string(static_cast<int>(oec_result_)));
}
if (crypto_session_method_) {
str.append("; crypto_session_method = ");
str.append(crypto_session_method_);
}
return str; return str;
} }
CdmResponseEnum Enum() const { return status_; }; CdmResponseEnum Enum() const { return status_; };
constexpr explicit operator int() const { return status_; }; constexpr explicit operator int() const { return status_; };
OEMCryptoResult getOEMCryptoResult() const { return oec_result_; }
const char* getCryptoSessionMethod() const { return crypto_session_method_; }
bool operator==(CdmResponseEnum other) const { return status_ == other; } bool operator==(CdmResponseEnum other) const { return status_ == other; }
bool operator!=(CdmResponseEnum other) const { return status_ != other; } bool operator!=(CdmResponseEnum other) const { return status_ != other; }
bool operator==(const CdmResponseType& other) const { bool operator==(const CdmResponseType& other) const {
return status_ == other.Enum(); return status_ == other.status_ && oec_result_ == other.oec_result_ &&
crypto_session_method_ == other.crypto_session_method_;
} }
bool operator!=(const CdmResponseType& other) const { bool operator!=(const CdmResponseType& other) const {
return status_ != other.Enum(); return !operator==(other);
} }
private: private:
CdmResponseEnum status_; CdmResponseEnum status_;
OEMCryptoResult oec_result_;
const char* crypto_session_method_;
// CORE_DISALLOW_COPY_AND_ASSIGN(CdmResponseType); // CORE_DISALLOW_COPY_AND_ASSIGN(CdmResponseType);
}; };

View File

@@ -65,6 +65,9 @@ OEMCryptoResult WrapIfNecessary(OEMCryptoResult ret_value) { return ret_value; }
return WrapIfNecessary(ret_value); \ return WrapIfNecessary(ret_value); \
} }
#define CRYPTO_ERROR(cdm_err, oem_err) \
CdmResponseType(cdm_err, oem_err, __func__)
#ifdef HAS_DUAL_KEY #ifdef HAS_DUAL_KEY
/** /**
* Internal only OEMCrypto method. This is called before parsing the license * Internal only OEMCrypto method. This is called before parsing the license
@@ -126,20 +129,27 @@ CdmResponseType MapOEMCryptoResult(OEMCryptoResult result,
static_cast<int>(result)); static_cast<int>(result));
} }
CdmResponseEnum status{};
switch (result) { switch (result) {
case OEMCrypto_SUCCESS: case OEMCrypto_SUCCESS:
return CdmResponseType(NO_ERROR); status = NO_ERROR;
break;
case OEMCrypto_ERROR_NOT_IMPLEMENTED: case OEMCrypto_ERROR_NOT_IMPLEMENTED:
return CdmResponseType(NOT_IMPLEMENTED_ERROR); status = NOT_IMPLEMENTED_ERROR;
break;
case OEMCrypto_ERROR_TOO_MANY_SESSIONS: case OEMCrypto_ERROR_TOO_MANY_SESSIONS:
return CdmResponseType(INSUFFICIENT_CRYPTO_RESOURCES); status = INSUFFICIENT_CRYPTO_RESOURCES;
break;
case OEMCrypto_ERROR_SESSION_LOST_STATE: case OEMCrypto_ERROR_SESSION_LOST_STATE:
return CdmResponseType(SESSION_LOST_STATE_ERROR); status = SESSION_LOST_STATE_ERROR;
break;
case OEMCrypto_ERROR_SYSTEM_INVALIDATED: case OEMCrypto_ERROR_SYSTEM_INVALIDATED:
return CdmResponseType(SYSTEM_INVALIDATED_ERROR); status = SYSTEM_INVALIDATED_ERROR;
break;
default: default:
return CdmResponseType(default_status); status = default_status;
} }
return CdmResponseType(status, result, crypto_session_method);
} }
void AdvanceDestBuffer(OEMCrypto_DestBufferDesc* dest_buffer, size_t bytes) { void AdvanceDestBuffer(OEMCrypto_DestBufferDesc* dest_buffer, size_t bytes) {
@@ -1007,7 +1017,7 @@ CdmResponseType CryptoSession::PrepareAndSignLicenseRequest(
if (static_cast<int>(sts) == kRsaSsaPssSignatureLengthError) { if (static_cast<int>(sts) == kRsaSsaPssSignatureLengthError) {
LOGE("OEMCrypto PrepareAndSignLicenseRequest result = %d", LOGE("OEMCrypto PrepareAndSignLicenseRequest result = %d",
static_cast<int>(sts)); static_cast<int>(sts));
return CdmResponseType(NEED_PROVISIONING); return CRYPTO_ERROR(NEED_PROVISIONING, sts);
} }
return MapOEMCryptoResult(sts, GENERATE_SIGNATURE_ERROR, return MapOEMCryptoResult(sts, GENERATE_SIGNATURE_ERROR,
"PrepareAndSignLicenseRequest"); "PrepareAndSignLicenseRequest");
@@ -1042,7 +1052,7 @@ CdmResponseType CryptoSession::PrepareAndSignLicenseRequest(
if (static_cast<int>(sts) == kRsaSsaPssSignatureLengthError) { if (static_cast<int>(sts) == kRsaSsaPssSignatureLengthError) {
LOGE("OEMCrypto PrepareAndSignLicenseRequest result = %d", LOGE("OEMCrypto PrepareAndSignLicenseRequest result = %d",
static_cast<int>(sts)); static_cast<int>(sts));
return CdmResponseType(NEED_PROVISIONING); return CRYPTO_ERROR(NEED_PROVISIONING, sts);
} }
return MapOEMCryptoResult(sts, GENERATE_SIGNATURE_ERROR, return MapOEMCryptoResult(sts, GENERATE_SIGNATURE_ERROR,
"PrepareAndSignLicenseRequest"); "PrepareAndSignLicenseRequest");
@@ -1088,10 +1098,10 @@ CdmResponseType CryptoSession::LoadLicense(const std::string& signed_message,
return CdmResponseType(KEY_ADDED); return CdmResponseType(KEY_ADDED);
case OEMCrypto_ERROR_BUFFER_TOO_LARGE: case OEMCrypto_ERROR_BUFFER_TOO_LARGE:
LOGE("LoadLicense buffer too large: size = %zu", combined_message.size()); LOGE("LoadLicense buffer too large: size = %zu", combined_message.size());
return CdmResponseType(LOAD_LICENSE_ERROR); return CRYPTO_ERROR(LOAD_LICENSE_ERROR, sts);
case OEMCrypto_ERROR_TOO_MANY_KEYS: case OEMCrypto_ERROR_TOO_MANY_KEYS:
LOGE("Too many keys in license"); LOGE("Too many keys in license");
return CdmResponseType(INSUFFICIENT_CRYPTO_RESOURCES); return CRYPTO_ERROR(INSUFFICIENT_CRYPTO_RESOURCES, sts);
default: default:
break; break;
} }
@@ -1180,7 +1190,7 @@ CdmResponseType CryptoSession::LoadRenewal(const std::string& signed_message,
} }
if (sts == OEMCrypto_ERROR_BUFFER_TOO_LARGE) { if (sts == OEMCrypto_ERROR_BUFFER_TOO_LARGE) {
LOGE("Buffer too large: size = %zu", combined_message.size()); LOGE("Buffer too large: size = %zu", combined_message.size());
return CdmResponseType(LOAD_RENEWAL_ERROR); return CRYPTO_ERROR(LOAD_RENEWAL_ERROR, sts);
} }
return MapOEMCryptoResult(sts, LOAD_RENEWAL_ERROR, "LoadRenewal"); return MapOEMCryptoResult(sts, LOAD_RENEWAL_ERROR, "LoadRenewal");
} }
@@ -1271,17 +1281,17 @@ CdmResponseType CryptoSession::LoadEntitledContentKeys(
case OEMCrypto_SUCCESS: case OEMCrypto_SUCCESS:
return CdmResponseType(KEY_ADDED); return CdmResponseType(KEY_ADDED);
case OEMCrypto_ERROR_INSUFFICIENT_RESOURCES: case OEMCrypto_ERROR_INSUFFICIENT_RESOURCES:
return CdmResponseType(INSUFFICIENT_CRYPTO_RESOURCES); return CRYPTO_ERROR(INSUFFICIENT_CRYPTO_RESOURCES, sts);
case OEMCrypto_ERROR_INVALID_CONTEXT: case OEMCrypto_ERROR_INVALID_CONTEXT:
return CdmResponseType(NOT_AN_ENTITLEMENT_SESSION); return CRYPTO_ERROR(NOT_AN_ENTITLEMENT_SESSION, sts);
case OEMCrypto_KEY_NOT_ENTITLED: case OEMCrypto_KEY_NOT_ENTITLED:
return CdmResponseType(NO_MATCHING_ENTITLEMENT_KEY); return CRYPTO_ERROR(NO_MATCHING_ENTITLEMENT_KEY, sts);
case OEMCrypto_ERROR_SESSION_LOST_STATE: case OEMCrypto_ERROR_SESSION_LOST_STATE:
return CdmResponseType(SESSION_LOST_STATE_ERROR); return CRYPTO_ERROR(SESSION_LOST_STATE_ERROR, sts);
case OEMCrypto_ERROR_SYSTEM_INVALIDATED: case OEMCrypto_ERROR_SYSTEM_INVALIDATED:
return CdmResponseType(SYSTEM_INVALIDATED_ERROR); return CRYPTO_ERROR(SYSTEM_INVALIDATED_ERROR, sts);
default: default:
return CdmResponseType(LOAD_ENTITLED_CONTENT_KEYS_ERROR); return CRYPTO_ERROR(LOAD_ENTITLED_CONTENT_KEYS_ERROR, sts);
} }
} }
@@ -1418,6 +1428,7 @@ CdmResponseType CryptoSession::GenerateCertificateKeyPair(
} else { } else {
LOGE("Unexpected key type returned from GenerateCertificateKeyPair: %d", LOGE("Unexpected key type returned from GenerateCertificateKeyPair: %d",
static_cast<int>(oemcrypto_key_type)); static_cast<int>(oemcrypto_key_type));
// TODO(b/261185349): add OEMCrypto_PrivateKeyType to CdmResponseType
return CdmResponseType(GENERATE_CERTIFICATE_KEY_PAIR_UNKNOWN_TYPE_ERROR); return CdmResponseType(GENERATE_CERTIFICATE_KEY_PAIR_UNKNOWN_TYPE_ERROR);
} }
@@ -1460,34 +1471,34 @@ CdmResponseType CryptoSession::SelectKey(const std::string& key_id,
case OEMCrypto_SUCCESS: case OEMCrypto_SUCCESS:
return CdmResponseType(NO_ERROR); return CdmResponseType(NO_ERROR);
case OEMCrypto_ERROR_KEY_EXPIRED: case OEMCrypto_ERROR_KEY_EXPIRED:
return CdmResponseType(NEED_KEY); return CRYPTO_ERROR(NEED_KEY, sts);
case OEMCrypto_ERROR_INVALID_SESSION: case OEMCrypto_ERROR_INVALID_SESSION:
return CdmResponseType(INVALID_SESSION_1); return CRYPTO_ERROR(INVALID_SESSION_1, sts);
case OEMCrypto_ERROR_NO_DEVICE_KEY: case OEMCrypto_ERROR_NO_DEVICE_KEY:
return CdmResponseType(NO_DEVICE_KEY_1); return CRYPTO_ERROR(NO_DEVICE_KEY_1, sts);
case OEMCrypto_ERROR_NO_CONTENT_KEY: case OEMCrypto_ERROR_NO_CONTENT_KEY:
return CdmResponseType(NO_CONTENT_KEY_2); return CRYPTO_ERROR(NO_CONTENT_KEY_2, sts);
case OEMCrypto_ERROR_CONTROL_INVALID: case OEMCrypto_ERROR_CONTROL_INVALID:
case OEMCrypto_ERROR_KEYBOX_INVALID: case OEMCrypto_ERROR_KEYBOX_INVALID:
return CdmResponseType(UNKNOWN_SELECT_KEY_ERROR_2); return CRYPTO_ERROR(UNKNOWN_SELECT_KEY_ERROR_2, sts);
case OEMCrypto_ERROR_INSUFFICIENT_RESOURCES: case OEMCrypto_ERROR_INSUFFICIENT_RESOURCES:
return CdmResponseType(INSUFFICIENT_CRYPTO_RESOURCES); return CRYPTO_ERROR(INSUFFICIENT_CRYPTO_RESOURCES, sts);
case OEMCrypto_ERROR_UNKNOWN_FAILURE: case OEMCrypto_ERROR_UNKNOWN_FAILURE:
return CdmResponseType(UNKNOWN_SELECT_KEY_ERROR_1); return CRYPTO_ERROR(UNKNOWN_SELECT_KEY_ERROR_1, sts);
case OEMCrypto_ERROR_ANALOG_OUTPUT: case OEMCrypto_ERROR_ANALOG_OUTPUT:
return CdmResponseType(ANALOG_OUTPUT_ERROR); return CRYPTO_ERROR(ANALOG_OUTPUT_ERROR, sts);
case OEMCrypto_ERROR_INSUFFICIENT_HDCP: case OEMCrypto_ERROR_INSUFFICIENT_HDCP:
return CdmResponseType(INSUFFICIENT_OUTPUT_PROTECTION); return CRYPTO_ERROR(INSUFFICIENT_OUTPUT_PROTECTION, sts);
// LoadEntitledContentKeys errors. // LoadEntitledContentKeys errors.
// |key_session_| may make calls to OEMCrypto_LoadEntitledContentKeys // |key_session_| may make calls to OEMCrypto_LoadEntitledContentKeys
// if the key selected has not yet been loaded. // if the key selected has not yet been loaded.
case OEMCrypto_ERROR_INVALID_CONTEXT: case OEMCrypto_ERROR_INVALID_CONTEXT:
return CdmResponseType(NOT_AN_ENTITLEMENT_SESSION); return CRYPTO_ERROR(NOT_AN_ENTITLEMENT_SESSION, sts);
case OEMCrypto_KEY_NOT_ENTITLED: case OEMCrypto_KEY_NOT_ENTITLED:
return CdmResponseType(NO_MATCHING_ENTITLEMENT_KEY); return CRYPTO_ERROR(NO_MATCHING_ENTITLEMENT_KEY, sts);
// Obsolete errors. // Obsolete errors.
case OEMCrypto_KEY_NOT_LOADED: case OEMCrypto_KEY_NOT_LOADED:
return CdmResponseType(NO_CONTENT_KEY_3); return CRYPTO_ERROR(NO_CONTENT_KEY_3, sts);
// Catch all else. // Catch all else.
default: default:
return MapOEMCryptoResult(sts, UNKNOWN_SELECT_KEY_ERROR_2, "SelectKey"); return MapOEMCryptoResult(sts, UNKNOWN_SELECT_KEY_ERROR_2, "SelectKey");
@@ -1752,26 +1763,26 @@ CdmResponseType CryptoSession::Decrypt(
case OEMCrypto_WARNING_MIXED_OUTPUT_PROTECTION: case OEMCrypto_WARNING_MIXED_OUTPUT_PROTECTION:
return CdmResponseType(NO_ERROR); return CdmResponseType(NO_ERROR);
case OEMCrypto_ERROR_INSUFFICIENT_RESOURCES: case OEMCrypto_ERROR_INSUFFICIENT_RESOURCES:
return CdmResponseType(INSUFFICIENT_CRYPTO_RESOURCES); return CRYPTO_ERROR(INSUFFICIENT_CRYPTO_RESOURCES, sts);
case OEMCrypto_ERROR_KEY_EXPIRED: case OEMCrypto_ERROR_KEY_EXPIRED:
return CdmResponseType(NEED_KEY); return CRYPTO_ERROR(NEED_KEY, sts);
case OEMCrypto_ERROR_INVALID_SESSION: case OEMCrypto_ERROR_INVALID_SESSION:
return CdmResponseType(INVALID_SESSION_2); return CRYPTO_ERROR(INVALID_SESSION_2, sts);
case OEMCrypto_ERROR_DECRYPT_FAILED: case OEMCrypto_ERROR_DECRYPT_FAILED:
case OEMCrypto_ERROR_UNKNOWN_FAILURE: case OEMCrypto_ERROR_UNKNOWN_FAILURE:
return CdmResponseType(DECRYPT_ERROR); return CRYPTO_ERROR(DECRYPT_ERROR, sts);
case OEMCrypto_ERROR_INSUFFICIENT_HDCP: case OEMCrypto_ERROR_INSUFFICIENT_HDCP:
return CdmResponseType(INSUFFICIENT_OUTPUT_PROTECTION); return CRYPTO_ERROR(INSUFFICIENT_OUTPUT_PROTECTION, sts);
case OEMCrypto_ERROR_ANALOG_OUTPUT: case OEMCrypto_ERROR_ANALOG_OUTPUT:
return CdmResponseType(ANALOG_OUTPUT_ERROR); return CRYPTO_ERROR(ANALOG_OUTPUT_ERROR, sts);
case OEMCrypto_ERROR_OUTPUT_TOO_LARGE: case OEMCrypto_ERROR_OUTPUT_TOO_LARGE:
return CdmResponseType(OUTPUT_TOO_LARGE_ERROR); return CRYPTO_ERROR(OUTPUT_TOO_LARGE_ERROR, sts);
case OEMCrypto_ERROR_SESSION_LOST_STATE: case OEMCrypto_ERROR_SESSION_LOST_STATE:
return CdmResponseType(SESSION_LOST_STATE_ERROR); return CRYPTO_ERROR(SESSION_LOST_STATE_ERROR, sts);
case OEMCrypto_ERROR_SYSTEM_INVALIDATED: case OEMCrypto_ERROR_SYSTEM_INVALIDATED:
return CdmResponseType(SYSTEM_INVALIDATED_ERROR); return CRYPTO_ERROR(SYSTEM_INVALIDATED_ERROR, sts);
default: default:
return CdmResponseType(UNKNOWN_ERROR); return CRYPTO_ERROR(UNKNOWN_ERROR, sts);
} }
} }
@@ -1836,13 +1847,13 @@ CdmResponseType CryptoSession::DeactivateUsageInformation(
case OEMCrypto_SUCCESS: case OEMCrypto_SUCCESS:
return CdmResponseType(NO_ERROR); return CdmResponseType(NO_ERROR);
case OEMCrypto_ERROR_INVALID_CONTEXT: case OEMCrypto_ERROR_INVALID_CONTEXT:
return CdmResponseType(KEY_CANCELED); return CRYPTO_ERROR(KEY_CANCELED, status);
case OEMCrypto_ERROR_SESSION_LOST_STATE: case OEMCrypto_ERROR_SESSION_LOST_STATE:
return CdmResponseType(SESSION_LOST_STATE_ERROR); return CRYPTO_ERROR(SESSION_LOST_STATE_ERROR, status);
case OEMCrypto_ERROR_SYSTEM_INVALIDATED: case OEMCrypto_ERROR_SYSTEM_INVALIDATED:
return CdmResponseType(SYSTEM_INVALIDATED_ERROR); return CRYPTO_ERROR(SYSTEM_INVALIDATED_ERROR, status);
default: default:
return CdmResponseType(DEACTIVATE_USAGE_ENTRY_ERROR); return CRYPTO_ERROR(DEACTIVATE_USAGE_ENTRY_ERROR, status);
} }
} }
@@ -2159,10 +2170,10 @@ CdmResponseType CryptoSession::GetSrmVersion(uint16_t* srm_version) {
return CdmResponseType(NO_ERROR); return CdmResponseType(NO_ERROR);
case OEMCrypto_LOCAL_DISPLAY_ONLY: case OEMCrypto_LOCAL_DISPLAY_ONLY:
LOGD("No SRM: Local display only"); LOGD("No SRM: Local display only");
return CdmResponseType(NO_SRM_VERSION); return CRYPTO_ERROR(NO_SRM_VERSION, status);
case OEMCrypto_ERROR_NOT_IMPLEMENTED: case OEMCrypto_ERROR_NOT_IMPLEMENTED:
LOGD("No SRM: Not implemented"); LOGD("No SRM: Not implemented");
return CdmResponseType(NO_SRM_VERSION); return CRYPTO_ERROR(NO_SRM_VERSION, status);
default: default:
return MapOEMCryptoResult(status, GET_SRM_VERSION_ERROR, return MapOEMCryptoResult(status, GET_SRM_VERSION_ERROR,
"GetCurrentSRMVersion"); "GetCurrentSRMVersion");
@@ -2387,13 +2398,13 @@ CdmResponseType CryptoSession::GetDecryptHashError(std::string* error_string) {
error_string->append(std::to_string(failed_frame_number)); error_string->append(std::to_string(failed_frame_number));
return CdmResponseType(NO_ERROR); return CdmResponseType(NO_ERROR);
case OEMCrypto_ERROR_SESSION_LOST_STATE: case OEMCrypto_ERROR_SESSION_LOST_STATE:
return CdmResponseType(SESSION_LOST_STATE_ERROR); return CRYPTO_ERROR(SESSION_LOST_STATE_ERROR, sts);
case OEMCrypto_ERROR_SYSTEM_INVALIDATED: case OEMCrypto_ERROR_SYSTEM_INVALIDATED:
return CdmResponseType(SYSTEM_INVALIDATED_ERROR); return CRYPTO_ERROR(SYSTEM_INVALIDATED_ERROR, sts);
case OEMCrypto_ERROR_UNKNOWN_FAILURE: case OEMCrypto_ERROR_UNKNOWN_FAILURE:
case OEMCrypto_ERROR_NOT_IMPLEMENTED: case OEMCrypto_ERROR_NOT_IMPLEMENTED:
default: default:
return CdmResponseType(GET_DECRYPT_HASH_ERROR); return CRYPTO_ERROR(GET_DECRYPT_HASH_ERROR, sts);
} }
} }
@@ -2443,18 +2454,18 @@ CdmResponseType CryptoSession::GenericEncrypt(const std::string& in_buffer,
case OEMCrypto_SUCCESS: case OEMCrypto_SUCCESS:
return CdmResponseType(NO_ERROR); return CdmResponseType(NO_ERROR);
case OEMCrypto_ERROR_KEY_EXPIRED: case OEMCrypto_ERROR_KEY_EXPIRED:
return CdmResponseType(NEED_KEY); return CRYPTO_ERROR(NEED_KEY, sts);
case OEMCrypto_ERROR_NO_CONTENT_KEY: case OEMCrypto_ERROR_NO_CONTENT_KEY:
case OEMCrypto_KEY_NOT_LOADED: // obsolete in v15. case OEMCrypto_KEY_NOT_LOADED: // obsolete in v15.
return CdmResponseType(KEY_NOT_FOUND_3); return CRYPTO_ERROR(KEY_NOT_FOUND_3, sts);
case OEMCrypto_ERROR_OUTPUT_TOO_LARGE: case OEMCrypto_ERROR_OUTPUT_TOO_LARGE:
return CdmResponseType(OUTPUT_TOO_LARGE_ERROR); return CRYPTO_ERROR(OUTPUT_TOO_LARGE_ERROR, sts);
case OEMCrypto_ERROR_SESSION_LOST_STATE: case OEMCrypto_ERROR_SESSION_LOST_STATE:
return CdmResponseType(SESSION_LOST_STATE_ERROR); return CRYPTO_ERROR(SESSION_LOST_STATE_ERROR, sts);
case OEMCrypto_ERROR_SYSTEM_INVALIDATED: case OEMCrypto_ERROR_SYSTEM_INVALIDATED:
return CdmResponseType(SYSTEM_INVALIDATED_ERROR); return CRYPTO_ERROR(SYSTEM_INVALIDATED_ERROR, sts);
default: default:
return CdmResponseType(UNKNOWN_ERROR); return CRYPTO_ERROR(UNKNOWN_ERROR, sts);
} }
} }
@@ -2504,18 +2515,18 @@ CdmResponseType CryptoSession::GenericDecrypt(const std::string& in_buffer,
case OEMCrypto_SUCCESS: case OEMCrypto_SUCCESS:
return CdmResponseType(NO_ERROR); return CdmResponseType(NO_ERROR);
case OEMCrypto_ERROR_KEY_EXPIRED: case OEMCrypto_ERROR_KEY_EXPIRED:
return CdmResponseType(NEED_KEY); return CRYPTO_ERROR(NEED_KEY, sts);
case OEMCrypto_ERROR_NO_CONTENT_KEY: case OEMCrypto_ERROR_NO_CONTENT_KEY:
case OEMCrypto_KEY_NOT_LOADED: // obsolete in v15. case OEMCrypto_KEY_NOT_LOADED: // obsolete in v15.
return CdmResponseType(KEY_NOT_FOUND_4); return CRYPTO_ERROR(KEY_NOT_FOUND_4, sts);
case OEMCrypto_ERROR_OUTPUT_TOO_LARGE: case OEMCrypto_ERROR_OUTPUT_TOO_LARGE:
return CdmResponseType(OUTPUT_TOO_LARGE_ERROR); return CRYPTO_ERROR(OUTPUT_TOO_LARGE_ERROR, sts);
case OEMCrypto_ERROR_SESSION_LOST_STATE: case OEMCrypto_ERROR_SESSION_LOST_STATE:
return CdmResponseType(SESSION_LOST_STATE_ERROR); return CRYPTO_ERROR(SESSION_LOST_STATE_ERROR, sts);
case OEMCrypto_ERROR_SYSTEM_INVALIDATED: case OEMCrypto_ERROR_SYSTEM_INVALIDATED:
return CdmResponseType(SYSTEM_INVALIDATED_ERROR); return CRYPTO_ERROR(SYSTEM_INVALIDATED_ERROR, sts);
default: default:
return CdmResponseType(UNKNOWN_ERROR); return CRYPTO_ERROR(UNKNOWN_ERROR, sts);
} }
} }
@@ -2571,18 +2582,18 @@ CdmResponseType CryptoSession::GenericSign(const std::string& message,
switch (sts) { switch (sts) {
case OEMCrypto_ERROR_KEY_EXPIRED: case OEMCrypto_ERROR_KEY_EXPIRED:
return CdmResponseType(NEED_KEY); return CRYPTO_ERROR(NEED_KEY, sts);
case OEMCrypto_ERROR_NO_CONTENT_KEY: case OEMCrypto_ERROR_NO_CONTENT_KEY:
case OEMCrypto_KEY_NOT_LOADED: // obsolete in v15. case OEMCrypto_KEY_NOT_LOADED: // obsolete in v15.
return CdmResponseType(KEY_NOT_FOUND_5); return CRYPTO_ERROR(KEY_NOT_FOUND_5, sts);
case OEMCrypto_ERROR_OUTPUT_TOO_LARGE: case OEMCrypto_ERROR_OUTPUT_TOO_LARGE:
return CdmResponseType(OUTPUT_TOO_LARGE_ERROR); return CRYPTO_ERROR(OUTPUT_TOO_LARGE_ERROR, sts);
case OEMCrypto_ERROR_SESSION_LOST_STATE: case OEMCrypto_ERROR_SESSION_LOST_STATE:
return CdmResponseType(SESSION_LOST_STATE_ERROR); return CRYPTO_ERROR(SESSION_LOST_STATE_ERROR, sts);
case OEMCrypto_ERROR_SYSTEM_INVALIDATED: case OEMCrypto_ERROR_SYSTEM_INVALIDATED:
return CdmResponseType(SYSTEM_INVALIDATED_ERROR); return CRYPTO_ERROR(SYSTEM_INVALIDATED_ERROR, sts);
default: default:
return CdmResponseType(UNKNOWN_ERROR); return CRYPTO_ERROR(UNKNOWN_ERROR, sts);
} }
} }
@@ -2623,18 +2634,18 @@ CdmResponseType CryptoSession::GenericVerify(const std::string& message,
case OEMCrypto_SUCCESS: case OEMCrypto_SUCCESS:
return CdmResponseType(NO_ERROR); return CdmResponseType(NO_ERROR);
case OEMCrypto_ERROR_KEY_EXPIRED: case OEMCrypto_ERROR_KEY_EXPIRED:
return CdmResponseType(NEED_KEY); return CRYPTO_ERROR(NEED_KEY, sts);
case OEMCrypto_ERROR_NO_CONTENT_KEY: case OEMCrypto_ERROR_NO_CONTENT_KEY:
case OEMCrypto_KEY_NOT_LOADED: // obsolete in v15. case OEMCrypto_KEY_NOT_LOADED: // obsolete in v15.
return CdmResponseType(KEY_NOT_FOUND_6); return CRYPTO_ERROR(KEY_NOT_FOUND_6, sts);
case OEMCrypto_ERROR_OUTPUT_TOO_LARGE: case OEMCrypto_ERROR_OUTPUT_TOO_LARGE:
return CdmResponseType(OUTPUT_TOO_LARGE_ERROR); return CRYPTO_ERROR(OUTPUT_TOO_LARGE_ERROR, sts);
case OEMCrypto_ERROR_SESSION_LOST_STATE: case OEMCrypto_ERROR_SESSION_LOST_STATE:
return CdmResponseType(SESSION_LOST_STATE_ERROR); return CRYPTO_ERROR(SESSION_LOST_STATE_ERROR, sts);
case OEMCrypto_ERROR_SYSTEM_INVALIDATED: case OEMCrypto_ERROR_SYSTEM_INVALIDATED:
return CdmResponseType(SYSTEM_INVALIDATED_ERROR); return CRYPTO_ERROR(SYSTEM_INVALIDATED_ERROR, sts);
default: default:
return CdmResponseType(UNKNOWN_ERROR); return CRYPTO_ERROR(UNKNOWN_ERROR, sts);
} }
} }
@@ -2707,16 +2718,16 @@ CdmResponseType CryptoSession::LoadUsageTableHeader(
case OEMCrypto_WARNING_GENERATION_SKEW: case OEMCrypto_WARNING_GENERATION_SKEW:
return CdmResponseType(NO_ERROR); return CdmResponseType(NO_ERROR);
case OEMCrypto_ERROR_GENERATION_SKEW: case OEMCrypto_ERROR_GENERATION_SKEW:
return CdmResponseType(LOAD_USAGE_HEADER_GENERATION_SKEW); return CRYPTO_ERROR(LOAD_USAGE_HEADER_GENERATION_SKEW, result);
case OEMCrypto_ERROR_SIGNATURE_FAILURE: case OEMCrypto_ERROR_SIGNATURE_FAILURE:
return CdmResponseType(LOAD_USAGE_HEADER_SIGNATURE_FAILURE); return CRYPTO_ERROR(LOAD_USAGE_HEADER_SIGNATURE_FAILURE, result);
case OEMCrypto_ERROR_BAD_MAGIC: case OEMCrypto_ERROR_BAD_MAGIC:
return CdmResponseType(LOAD_USAGE_HEADER_BAD_MAGIC); return CRYPTO_ERROR(LOAD_USAGE_HEADER_BAD_MAGIC, result);
case OEMCrypto_ERROR_SYSTEM_INVALIDATED: case OEMCrypto_ERROR_SYSTEM_INVALIDATED:
return CdmResponseType(SYSTEM_INVALIDATED_ERROR); return CRYPTO_ERROR(SYSTEM_INVALIDATED_ERROR, result);
case OEMCrypto_ERROR_UNKNOWN_FAILURE: case OEMCrypto_ERROR_UNKNOWN_FAILURE:
default: default:
return CdmResponseType(LOAD_USAGE_HEADER_UNKNOWN_ERROR); return CRYPTO_ERROR(LOAD_USAGE_HEADER_UNKNOWN_ERROR, result);
} }
} }
@@ -2753,7 +2764,7 @@ CdmResponseType CryptoSession::ShrinkUsageTableHeader(
usage_table_header->resize(usage_table_header_len); usage_table_header->resize(usage_table_header_len);
return CdmResponseType(NO_ERROR); return CdmResponseType(NO_ERROR);
case OEMCrypto_ERROR_ENTRY_IN_USE: case OEMCrypto_ERROR_ENTRY_IN_USE:
return CdmResponseType(SHRINK_USAGE_TABLE_HEADER_ENTRY_IN_USE); return CRYPTO_ERROR(SHRINK_USAGE_TABLE_HEADER_ENTRY_IN_USE, result);
default: default:
return MapOEMCryptoResult(result, SHRINK_USAGE_TABLE_HEADER_UNKNOWN_ERROR, return MapOEMCryptoResult(result, SHRINK_USAGE_TABLE_HEADER_UNKNOWN_ERROR,
"ShrinkUsageTableHeader"); "ShrinkUsageTableHeader");
@@ -2780,13 +2791,13 @@ CdmResponseType CryptoSession::CreateUsageEntry(uint32_t* entry_number) {
case OEMCrypto_SUCCESS: case OEMCrypto_SUCCESS:
return CdmResponseType(NO_ERROR); return CdmResponseType(NO_ERROR);
case OEMCrypto_ERROR_INSUFFICIENT_RESOURCES: case OEMCrypto_ERROR_INSUFFICIENT_RESOURCES:
return CdmResponseType(INSUFFICIENT_CRYPTO_RESOURCES); return CRYPTO_ERROR(INSUFFICIENT_CRYPTO_RESOURCES, result);
case OEMCrypto_ERROR_SESSION_LOST_STATE: case OEMCrypto_ERROR_SESSION_LOST_STATE:
return CdmResponseType(SESSION_LOST_STATE_ERROR); return CRYPTO_ERROR(SESSION_LOST_STATE_ERROR, result);
case OEMCrypto_ERROR_SYSTEM_INVALIDATED: case OEMCrypto_ERROR_SYSTEM_INVALIDATED:
return CdmResponseType(SYSTEM_INVALIDATED_ERROR); return CRYPTO_ERROR(SYSTEM_INVALIDATED_ERROR, result);
default: default:
return CdmResponseType(CREATE_USAGE_ENTRY_UNKNOWN_ERROR); return CRYPTO_ERROR(CREATE_USAGE_ENTRY_UNKNOWN_ERROR, result);
} }
} }
@@ -2821,11 +2832,11 @@ CdmResponseType CryptoSession::LoadUsageEntry(
// session ID is invalid (CDM internal bug), or that the entry // session ID is invalid (CDM internal bug), or that the entry
// being loaded is already in use in a different session. // being loaded is already in use in a different session.
// It is up to the caller to handle this. // It is up to the caller to handle this.
return CdmResponseType(LOAD_USAGE_ENTRY_INVALID_SESSION); return CRYPTO_ERROR(LOAD_USAGE_ENTRY_INVALID_SESSION, result);
case OEMCrypto_ERROR_GENERATION_SKEW: case OEMCrypto_ERROR_GENERATION_SKEW:
return CdmResponseType(LOAD_USAGE_ENTRY_GENERATION_SKEW); return CRYPTO_ERROR(LOAD_USAGE_ENTRY_GENERATION_SKEW, result);
case OEMCrypto_ERROR_SIGNATURE_FAILURE: case OEMCrypto_ERROR_SIGNATURE_FAILURE:
return CdmResponseType(LOAD_USAGE_ENTRY_SIGNATURE_FAILURE); return CRYPTO_ERROR(LOAD_USAGE_ENTRY_SIGNATURE_FAILURE, result);
default: default:
return MapOEMCryptoResult(result, LOAD_USAGE_ENTRY_UNKNOWN_ERROR, return MapOEMCryptoResult(result, LOAD_USAGE_ENTRY_UNKNOWN_ERROR,
"LoadUsageEntry"); "LoadUsageEntry");
@@ -2887,7 +2898,7 @@ CdmResponseType CryptoSession::MoveUsageEntry(uint32_t new_entry_number) {
case OEMCrypto_ERROR_ENTRY_IN_USE: case OEMCrypto_ERROR_ENTRY_IN_USE:
LOGW("OEMCrypto_MoveEntry failed: Destination index in use: index = %u", LOGW("OEMCrypto_MoveEntry failed: Destination index in use: index = %u",
new_entry_number); new_entry_number);
return CdmResponseType(MOVE_USAGE_ENTRY_DESTINATION_IN_USE); return CRYPTO_ERROR(MOVE_USAGE_ENTRY_DESTINATION_IN_USE, result);
default: default:
return MapOEMCryptoResult(result, MOVE_USAGE_ENTRY_UNKNOWN_ERROR, return MapOEMCryptoResult(result, MOVE_USAGE_ENTRY_UNKNOWN_ERROR,
"MoveUsageEntry"); "MoveUsageEntry");

View File

@@ -155,7 +155,7 @@ void LicenseHolder::DecryptSecure(const KeyId& key_id) {
} }
void LicenseHolder::FailDecrypt(const KeyId& key_id, void LicenseHolder::FailDecrypt(const KeyId& key_id,
CdmResponseType expected_status) { CdmResponseEnum expected_status) {
CdmResponseType status = Decrypt(key_id); CdmResponseType status = Decrypt(key_id);
// If the server knows we cannot handle the key, it would not have given us // If the server knows we cannot handle the key, it would not have given us
// the key. In that case, the status should indicate no key. // the key. In that case, the status should indicate no key.

View File

@@ -83,7 +83,7 @@ class LicenseHolder {
// Try to decrypt some random data, but expect failure. The failure may // Try to decrypt some random data, but expect failure. The failure may
// be either the expected_status, or NEED_KEY. We allow NEED_KEY in case // be either the expected_status, or NEED_KEY. We allow NEED_KEY in case
// the server recognized that we cannot support the given key. // the server recognized that we cannot support the given key.
void FailDecrypt(const KeyId& key_id, CdmResponseType expected_status); void FailDecrypt(const KeyId& key_id, CdmResponseEnum expected_status);
const std::string& content_id() const { return content_id_; } const std::string& content_id() const { return content_id_; }
void set_content_id(const std::string& content_id) { void set_content_id(const std::string& content_id) {

View File

@@ -84,7 +84,7 @@ TEST_F(CorePIGTest, OfflineHWSecureRequired) {
ASSERT_NO_FATAL_FAILURE(holder.LoadLicense()); ASSERT_NO_FATAL_FAILURE(holder.LoadLicense());
EXPECT_EQ(NO_ERROR, holder.Decrypt(sw_key_id)); EXPECT_EQ(NO_ERROR, holder.Decrypt(sw_key_id));
ASSERT_NO_FATAL_FAILURE( ASSERT_NO_FATAL_FAILURE(
holder.FailDecrypt(hw_key_id, CdmResponseType(DECRYPT_ERROR))); holder.FailDecrypt(hw_key_id, DECRYPT_ERROR));
// Next, if possible, we try to decrypt to a secure buffer, and verify // Next, if possible, we try to decrypt to a secure buffer, and verify
// success. // success.
if (wvoec::global_features.test_secure_buffers) { if (wvoec::global_features.test_secure_buffers) {
@@ -100,7 +100,7 @@ TEST_F(CorePIGTest, OfflineHWSecureRequired) {
ASSERT_NO_FATAL_FAILURE(holder.ReloadLicense()); ASSERT_NO_FATAL_FAILURE(holder.ReloadLicense());
EXPECT_EQ(NO_ERROR, holder.Decrypt(sw_key_id)); EXPECT_EQ(NO_ERROR, holder.Decrypt(sw_key_id));
ASSERT_NO_FATAL_FAILURE( ASSERT_NO_FATAL_FAILURE(
holder.FailDecrypt(hw_key_id, CdmResponseType(DECRYPT_ERROR))); holder.FailDecrypt(hw_key_id, DECRYPT_ERROR));
// Next, if possible, we try to decrypt to a secure buffer, and verify // Next, if possible, we try to decrypt to a secure buffer, and verify
// success. // success.
if (wvoec::global_features.test_secure_buffers) { if (wvoec::global_features.test_secure_buffers) {