diff --git a/libwvdrmengine/level3/arm/libwvlevel3.a b/libwvdrmengine/level3/arm/libwvlevel3.a index 3e3f87d9..ffa38071 100644 Binary files a/libwvdrmengine/level3/arm/libwvlevel3.a and b/libwvdrmengine/level3/arm/libwvlevel3.a differ diff --git a/libwvdrmengine/level3/x86/libwvlevel3.a b/libwvdrmengine/level3/x86/libwvlevel3.a index 29acc17f..72767f46 100644 Binary files a/libwvdrmengine/level3/x86/libwvlevel3.a and b/libwvdrmengine/level3/x86/libwvlevel3.a differ diff --git a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_mock.cpp b/libwvdrmengine/oemcrypto/mock/src/oemcrypto_mock.cpp index da06aa2d..58fb0392 100644 --- a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_mock.cpp +++ b/libwvdrmengine/oemcrypto/mock/src/oemcrypto_mock.cpp @@ -80,6 +80,10 @@ OEMCryptoResult OEMCrypto_OpenSession(OEMCrypto_SESSION* session) { LOGI("-- OEMCryptoResult OEMCrypto_OpenSession" "(OEMCrypto_SESSION *session)\n"); } + if (!crypto_engine) { + LOGE("OEMCrypto_OpenSession: OEMCrypto Not Initialized."); + return OEMCrypto_ERROR_UNKNOWN_FAILURE; + } if (crypto_engine->GetNumberOfOpenSessions() >= crypto_engine->GetMaxNumberOfSessions()) { LOGE("[OEMCrypto_OpenSession(): failed due to too many sessions]"); @@ -99,6 +103,10 @@ OEMCryptoResult OEMCrypto_CloseSession(OEMCrypto_SESSION session) { LOGI("-- OEMCryptoResult OEMCrypto_CloseSession" "(OEMCrypto_SESSION session)\n"); } + if (!crypto_engine) { + LOGE("OEMCrypto_CloseSession: OEMCrypto Not Initialized."); + return OEMCrypto_ERROR_UNKNOWN_FAILURE; + } if (!crypto_engine->DestroySession((SessionId)session)) { if (LogCategoryEnabled(kLoggingTraceOEMCryptoCalls)) { LOGD("[OEMCrypto_CloseSession(SID=%08X): failed]", session); @@ -127,6 +135,10 @@ OEMCryptoResult OEMCrypto_GenerateDerivedKeys(OEMCrypto_SESSION session, (size_t)enc_key_context_length); } } + if (!crypto_engine) { + LOGE("OEMCrypto_GenerateDerivedKeys: OEMCrypto Not Initialized."); + return OEMCrypto_ERROR_UNKNOWN_FAILURE; + } if (!crypto_engine->supports_keybox()) { return OEMCrypto_ERROR_NOT_IMPLEMENTED; } @@ -171,6 +183,10 @@ OEMCryptoResult OEMCrypto_GenerateNonce(OEMCrypto_SESSION session, LOGI("-- OEMCryptoResult OEMCrypto_GenerateNonce" "(OEMCrypto_SESSION session,\n"); } + if (!crypto_engine) { + LOGE("OEMCrypto_GenerateNonce: OEMCrypto Not Initialized."); + return OEMCrypto_ERROR_UNKNOWN_FAILURE; + } SessionContext* session_ctx = crypto_engine->FindSession(session); if (!session_ctx || !session_ctx->isValid()) { LOGE("[OEMCrypto_GenerateNonce(): ERROR_INVALID_SESSION]"); @@ -221,6 +237,10 @@ OEMCryptoResult OEMCrypto_GenerateSignature( dump_hex("message", message, message_length); } } + if (!crypto_engine) { + LOGE("OEMCrypto_GenerateSignature: OEMCrypto Not Initialized."); + return OEMCrypto_ERROR_UNKNOWN_FAILURE; + } if (*signature_length < SHA256_DIGEST_LENGTH) { *signature_length = SHA256_DIGEST_LENGTH; @@ -276,6 +296,10 @@ OEMCryptoResult OEMCrypto_LoadKeys(OEMCrypto_SESSION session, const OEMCrypto_KeyObject* key_array, const uint8_t* pst, size_t pst_length) { + if (!crypto_engine) { + LOGE("OEMCrypto_LoadKeys: OEMCrypto Not Initialized."); + return OEMCrypto_ERROR_UNKNOWN_FAILURE; + } if (LogCategoryEnabled(kLoggingTraceOEMCryptoCalls)) { LOGI("-- OEMCryptoResult OEMCrypto_LoadKeys(OEMCrypto_SESSION session,\n"); if (wvcdm::g_cutoff >= wvcdm::LOG_VERBOSE) { @@ -370,6 +394,10 @@ OEMCryptoResult OEMCrypto_RefreshKeys( LOGI("-- OEMCryptoResult OEMCrypto_RefreshKeys(num_keys=%zu)\n", num_keys); } + if (!crypto_engine) { + LOGE("OEMCrypto_RefreshKeys: OEMCrypto Not Initialized."); + return OEMCrypto_ERROR_UNKNOWN_FAILURE; + } if (NO_ERROR != crypto_engine->ValidateKeybox()) { LOGE("[OEMCrypto_RefreshKeys(): ERROR_KEYBOX_INVALID]"); @@ -459,6 +487,10 @@ extern "C" OEMCryptoResult OEMCrypto_QueryKeyControl( dump_hex("key_id", key_id, key_id_length); } } + if (!crypto_engine) { + LOGE("OEMCrypto_QueryKeyControl: OEMCrypto Not Initialized."); + return OEMCrypto_ERROR_UNKNOWN_FAILURE; + } uint32_t* block = reinterpret_cast(key_control_block); if ((key_control_block_length == NULL) || (*key_control_block_length < wvcdm::KEY_CONTROL_SIZE)) { @@ -568,6 +600,10 @@ OEMCryptoResult OEMCrypto_DecryptCTR(OEMCrypto_SESSION session, LOGI("-- OEMCryptoResult OEMCrypto_DecryptCTR" "(OEMCrypto_SESSION session,\n"); } + if (!crypto_engine) { + LOGE("OEMCrypto_DecryptCTR: OEMCrypto Not Initialized."); + return OEMCrypto_ERROR_UNKNOWN_FAILURE; + } if (data_addr == NULL || data_length == 0 || iv == NULL || out_buffer == NULL) { LOGE("[OEMCrypto_DecryptCTR(): OEMCrypto_ERROR_INVALID_CONTEXT]"); @@ -605,6 +641,10 @@ OEMCryptoResult OEMCrypto_CopyBuffer(const uint8_t *data_addr, if (LogCategoryEnabled(kLoggingTraceOEMCryptoCalls)) { LOGI("-- OEMCryptoResult OEMCrypto_CopyBuffer(..)\n"); } + if (!crypto_engine) { + LOGE("OEMCrypto_CopyBuffer: OEMCrypto Not Initialized."); + return OEMCrypto_ERROR_UNKNOWN_FAILURE; + } if (data_addr == NULL || out_buffer == NULL) { LOGE("[OEMCrypto_CopyBuffer(): OEMCrypto_ERROR_INVALID_CONTEXT]"); return OEMCrypto_ERROR_INVALID_CONTEXT; @@ -648,6 +688,10 @@ OEMCryptoResult OEMCrypto_InstallKeybox(const uint8_t* keybox, if (LogCategoryEnabled(kLoggingTraceOEMCryptoCalls)) { LOGI("-- OEMCryptoResult OEMCrypto_InstallKeybox(const uint8_t *keybox,\n"); } + if (!crypto_engine) { + LOGE("OEMCrypto_InstallKeybox: OEMCrypto Not Initialized."); + return OEMCrypto_ERROR_UNKNOWN_FAILURE; + } if (!crypto_engine->supports_keybox()) { return OEMCrypto_ERROR_NOT_IMPLEMENTED; } @@ -662,6 +706,10 @@ OEMCryptoResult OEMCrypto_LoadTestKeybox() { if (LogCategoryEnabled(kLoggingTraceOEMCryptoCalls)) { LOGI("-- OEMCryptoResult OEMCrypto_LoadTestKeybox()\n"); } + if (!crypto_engine) { + LOGE("OEMCrypto_LoadTestKeybox: OEMCrypto Not Initialized."); + return OEMCrypto_ERROR_UNKNOWN_FAILURE; + } if (!crypto_engine->supports_keybox()) { return OEMCrypto_ERROR_NOT_IMPLEMENTED; } @@ -674,6 +722,10 @@ OEMCryptoResult OEMCrypto_IsKeyboxValid(void) { if (LogCategoryEnabled(kLoggingTraceOEMCryptoCalls)) { LOGI("-- OEMCryptoResult OEMCrypto_IsKeyboxValid(void) {\n"); } + if (!crypto_engine) { + LOGE("OEMCrypto_IsKeyboxValid: OEMCrypto Not Initialized."); + return OEMCrypto_ERROR_UNKNOWN_FAILURE; + } if (!crypto_engine->supports_keybox()) { return OEMCrypto_ERROR_NOT_IMPLEMENTED; } @@ -692,6 +744,10 @@ OEMCryptoResult OEMCrypto_GetDeviceID(uint8_t* deviceID, if (LogCategoryEnabled(kLoggingTraceOEMCryptoCalls)) { LOGI("-- OEMCryptoResult OEMCrypto_GetDeviceID(uint8_t* deviceID,\n"); } + if (!crypto_engine) { + LOGE("OEMCrypto_GetDeviceID: OEMCrypto Not Initialized."); + return OEMCrypto_ERROR_UNKNOWN_FAILURE; + } // Devices that do not support a keybox should use some other method to // store the device id. std::vector dev_id_string = crypto_engine->keybox().device_id(); @@ -721,6 +777,10 @@ OEMCryptoResult OEMCrypto_GetKeyData(uint8_t* keyData, if (LogCategoryEnabled(kLoggingTraceOEMCryptoCalls)) { LOGI("-- OEMCryptoResult OEMCrypto_GetKeyData(uint8_t* keyData,\n"); } + if (!crypto_engine) { + LOGE("OEMCrypto_GetKeyData: OEMCrypto Not Initialized."); + return OEMCrypto_ERROR_UNKNOWN_FAILURE; + } if (!crypto_engine->supports_keybox()) { return OEMCrypto_ERROR_NOT_IMPLEMENTED; } @@ -786,6 +846,10 @@ OEMCryptoResult OEMCrypto_RewrapDeviceRSAKey(OEMCrypto_SESSION session, dump_hex("enc_rsa_key_iv", enc_rsa_key_iv, wvcdm::KEY_IV_SIZE); } } + if (!crypto_engine) { + LOGE("OEMCrypto_RewrapDeviceRSAKey: OEMCrypto Not Initialized."); + return OEMCrypto_ERROR_UNKNOWN_FAILURE; + } if (!crypto_engine->supports_keybox()) { return OEMCrypto_ERROR_NOT_IMPLEMENTED; } @@ -925,6 +989,10 @@ OEMCryptoResult OEMCrypto_LoadDeviceRSAKey(OEMCrypto_SESSION session, LOGE("[OEMCrypto_LoadDeviceRSAKey(): OEMCrypto_ERROR_INVALID_CONTEXT]"); return OEMCrypto_ERROR_INVALID_CONTEXT; } + if (!crypto_engine) { + LOGE("OEMCrypto_LoadDeviceRSAKey: OEMCrypto Not Initialized."); + return OEMCrypto_ERROR_UNKNOWN_FAILURE; + } if (!crypto_engine->supports_keybox()) { return OEMCrypto_ERROR_NOT_IMPLEMENTED; } @@ -992,6 +1060,10 @@ OEMCryptoResult OEMCrypto_LoadTestRSAKey() { if (LogCategoryEnabled(kLoggingTraceOEMCryptoCalls)) { LOGI("-- OEMCryptoResult OEMCrypto_LoadTestRSAKey()\n"); } + if (!crypto_engine) { + LOGE("OEMCrypto_LoadTestRSAKey: OEMCrypto Not Initialized."); + return OEMCrypto_ERROR_UNKNOWN_FAILURE; + } if (crypto_engine->LoadTestRSAKey()) return OEMCrypto_SUCCESS; return OEMCrypto_ERROR_UNKNOWN_FAILURE; } @@ -1011,6 +1083,10 @@ OEMCryptoResult OEMCrypto_GenerateRSASignature( dump_hex("message", message, message_length); } } + if (!crypto_engine) { + LOGE("OEMCrypto_GenerateRSASignature: OEMCrypto Not Initialized."); + return OEMCrypto_ERROR_UNKNOWN_FAILURE; + } if (NO_ERROR != crypto_engine->ValidateKeybox()) { LOGE("[OEMCrypto_GenerateRSASignature(): ERROR_KEYBOX_INVALID]"); return OEMCrypto_ERROR_KEYBOX_INVALID; @@ -1073,6 +1149,10 @@ OEMCryptoResult OEMCrypto_DeriveKeysFromSessionKey( (size_t)enc_key_context_length); } } + if (!crypto_engine) { + LOGE("OEMCrypto_DeriveKeysFromSessionKey: OEMCrypto Not Initialized."); + return OEMCrypto_ERROR_UNKNOWN_FAILURE; + } if (NO_ERROR != crypto_engine->ValidateKeybox()) { LOGE("[OEMCrypto_GenerateDerivedKeys(): ERROR_KEYBOX_INVALID]"); return OEMCrypto_ERROR_KEYBOX_INVALID; @@ -1135,6 +1215,10 @@ OEMCryptoResult OEMCrypto_GetHDCPCapability( LOGI("-- OEMCryptoResult OEMCrypto_GetHDCPCapability(%p, %p)\n", current, maximum); } + if (!crypto_engine) { + LOGE("OEMCrypto_GetHDCPCapability: OEMCrypto Not Initialized."); + return OEMCrypto_ERROR_UNKNOWN_FAILURE; + } if (current == NULL) return OEMCrypto_ERROR_UNKNOWN_FAILURE; if (maximum == NULL) return OEMCrypto_ERROR_UNKNOWN_FAILURE; *current = crypto_engine->current_hdcp_capability(); @@ -1157,6 +1241,10 @@ OEMCryptoResult OEMCrypto_GetNumberOfOpenSessions(size_t* count) { if (LogCategoryEnabled(kLoggingTraceOEMCryptoCalls)) { LOGI("-- OEMCryptoResult OEMCrypto_GetNumberOfOpenSessions(%p)\n", count); } + if (!crypto_engine) { + LOGE("OEMCrypto_GetNumberOfOpenSessions: OEMCrypto Not Initialized."); + return OEMCrypto_ERROR_UNKNOWN_FAILURE; + } if (count == NULL) return OEMCrypto_ERROR_UNKNOWN_FAILURE; *count = crypto_engine->GetNumberOfOpenSessions(); return OEMCrypto_SUCCESS; @@ -1167,6 +1255,10 @@ OEMCryptoResult OEMCrypto_GetMaxNumberOfSessions(size_t* maximum) { if (LogCategoryEnabled(kLoggingTraceOEMCryptoCalls)) { LOGI("-- OEMCryptoResult OEMCrypto_GetMaxNumberOfSessions(%p)\n", maximum); } + if (!crypto_engine) { + LOGE("OEMCrypto_GetMaxNumberOfSessions: OEMCrypto Not Initialized."); + return OEMCrypto_ERROR_UNKNOWN_FAILURE; + } if (maximum == NULL) return OEMCrypto_ERROR_UNKNOWN_FAILURE; *maximum = crypto_engine->GetMaxNumberOfSessions(); return OEMCrypto_SUCCESS; @@ -1198,6 +1290,10 @@ OEMCryptoResult OEMCrypto_Generic_Encrypt(OEMCrypto_SESSION session, dump_hex("iv", iv, wvcdm::KEY_IV_SIZE); } } + if (!crypto_engine) { + LOGE("OEMCrypto_Generic_Encrypt: OEMCrypto Not Initialized."); + return OEMCrypto_ERROR_UNKNOWN_FAILURE; + } if (NO_ERROR != crypto_engine->ValidateKeybox()) { LOGE("[OEMCrypto_Generic_Enrypt(): ERROR_KEYBOX_INVALID]"); return OEMCrypto_ERROR_KEYBOX_INVALID; @@ -1238,6 +1334,10 @@ OEMCryptoResult OEMCrypto_Generic_Decrypt(OEMCrypto_SESSION session, dump_hex("iv", iv, wvcdm::KEY_IV_SIZE); } } + if (!crypto_engine) { + LOGE("OEMCrypto_Generic_Decrypt: OEMCrypto Not Initialized."); + return OEMCrypto_ERROR_UNKNOWN_FAILURE; + } if (NO_ERROR != crypto_engine->ValidateKeybox()) { LOGE("[OEMCrypto_Generic_Decrypt(): ERROR_KEYBOX_INVALID]"); return OEMCrypto_ERROR_KEYBOX_INVALID; @@ -1277,6 +1377,10 @@ OEMCryptoResult OEMCrypto_Generic_Sign(OEMCrypto_SESSION session, dump_hex("in_buffer", in_buffer, buffer_length); } } + if (!crypto_engine) { + LOGE("OEMCrypto_Generic_Sign: OEMCrypto Not Initialized."); + return OEMCrypto_ERROR_UNKNOWN_FAILURE; + } if (NO_ERROR != crypto_engine->ValidateKeybox()) { LOGE("[OEMCrypto_Generic_Sign(): ERROR_KEYBOX_INVALID]"); return OEMCrypto_ERROR_KEYBOX_INVALID; @@ -1320,6 +1424,10 @@ OEMCryptoResult OEMCrypto_Generic_Verify(OEMCrypto_SESSION session, dump_hex("signature", signature, signature_length); } } + if (!crypto_engine) { + LOGE("OEMCrypto_Generic_Verify: OEMCrypto Not Initialized."); + return OEMCrypto_ERROR_UNKNOWN_FAILURE; + } if (NO_ERROR != crypto_engine->ValidateKeybox()) { LOGE("[OEMCrypto_Generic_Verify(): ERROR_KEYBOX_INVALID]"); return OEMCrypto_ERROR_KEYBOX_INVALID; @@ -1345,6 +1453,10 @@ OEMCryptoResult OEMCrypto_UpdateUsageTable() { if (LogCategoryEnabled(kLoggingTraceOEMCryptoCalls)) { LOGI("-- OEMCryptoResult OEMCrypto_UpdateUsageTable();\n"); } + if (!crypto_engine) { + LOGE("OEMCrypto_UpdateUsageTable: OEMCrypto Not Initialized."); + return OEMCrypto_ERROR_UNKNOWN_FAILURE; + } if (!crypto_engine->supports_storage()) { return OEMCrypto_ERROR_NOT_IMPLEMENTED; } @@ -1360,6 +1472,10 @@ OEMCryptoResult OEMCrypto_DeactivateUsageEntry(const uint8_t *pst, dump_hex("pst", pst, pst_length); } } + if (!crypto_engine) { + LOGE("OEMCrypto_DeactivateUsageEntry: OEMCrypto Not Initialized."); + return OEMCrypto_ERROR_UNKNOWN_FAILURE; + } if (!crypto_engine->supports_storage()) { return OEMCrypto_ERROR_NOT_IMPLEMENTED; } @@ -1379,6 +1495,10 @@ OEMCryptoResult OEMCrypto_ReportUsage(OEMCrypto_SESSION session, dump_hex("pst", pst, pst_length); } } + if (!crypto_engine) { + LOGE("OEMCrypto_ReportUsage: OEMCrypto Not Initialized."); + return OEMCrypto_ERROR_UNKNOWN_FAILURE; + } if (!crypto_engine->supports_storage()) { return OEMCrypto_ERROR_NOT_IMPLEMENTED; } @@ -1421,6 +1541,10 @@ OEMCryptoResult OEMCrypto_DeleteUsageEntry(OEMCrypto_SESSION session, dump_hex("signature", signature, signature_length); } } + if (!crypto_engine) { + LOGE("OEMCrypto_DeleteUsageEntry: OEMCrypto Not Initialized."); + return OEMCrypto_ERROR_UNKNOWN_FAILURE; + } if (!crypto_engine->supports_storage()) { return OEMCrypto_ERROR_NOT_IMPLEMENTED; } @@ -1460,6 +1584,10 @@ OEMCryptoResult OEMCrypto_ForceDeleteUsageEntry(const uint8_t* pst, dump_hex("pst", pst, pst_length); } } + if (!crypto_engine) { + LOGE("OEMCrypto_ForceDeleteUsageEntry: OEMCrypto Not Initialized."); + return OEMCrypto_ERROR_UNKNOWN_FAILURE; + } if (!crypto_engine->supports_storage()) { return OEMCrypto_ERROR_NOT_IMPLEMENTED; } @@ -1475,6 +1603,10 @@ OEMCryptoResult OEMCrypto_DeleteUsageTable() { if (LogCategoryEnabled(kLoggingTraceOEMCryptoCalls)) { LOGI("-- OEMCryptoResult OEMCrypto_DeleteUsageTable()\n"); } + if (!crypto_engine) { + LOGE("OEMCrypto_DeleteUsageTable: OEMCrypto Not Initialized."); + return OEMCrypto_ERROR_UNKNOWN_FAILURE; + } if (!crypto_engine->supports_storage()) { return OEMCrypto_ERROR_NOT_IMPLEMENTED; }