From ad94e69d033fccc7661895e8998a3bf9b9e44620 Mon Sep 17 00:00:00 2001 From: Fred Gylys-Colwell Date: Wed, 26 Apr 2017 20:00:30 -0700 Subject: [PATCH 1/3] OEMCrypto Logging Merge from Widevine repo of http://go/wvgerrit/26521 This CL adds some missing logging when TraceOEMCryptoCalls is set. Several SRM functions were not properly logged. It also changes SelectKey from the TraceOEMCryptoCalls flag to the TraceDecryptCalls. This reduces flooding the logs when content is actually playing. b/37751139 Change-Id: Ie92379dc295c83d8ec9bacb2445b1ef47377e4cf --- .../oemcrypto/mock/src/oemcrypto_mock.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_mock.cpp b/libwvdrmengine/oemcrypto/mock/src/oemcrypto_mock.cpp index 794db8f5..d888a3f8 100644 --- a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_mock.cpp +++ b/libwvdrmengine/oemcrypto/mock/src/oemcrypto_mock.cpp @@ -509,7 +509,7 @@ extern "C" OEMCryptoResult OEMCrypto_QueryKeyControl( extern "C" OEMCryptoResult OEMCrypto_SelectKey(const OEMCrypto_SESSION session, const uint8_t* key_id, size_t key_id_length) { - if (LogCategoryEnabled(kLoggingTraceOEMCryptoCalls)) { + if (LogCategoryEnabled(kLoggingTraceDecryptCalls)) { LOGI("-- OEMCryptoResult OEMCrypto_SelectKey(%d, id=%s)", session, wvcdm::HexEncode(key_id, key_id_length).c_str()); } @@ -1630,6 +1630,9 @@ extern "C" OEMCryptoResult OEMCrypto_DeleteOldUsageTable() { } extern "C" bool OEMCrypto_IsSRMUpdateSupported() { + if (LogCategoryEnabled(kLoggingTraceOEMCryptoCalls)) { + LOGI("-- OEMCryptoResult OEMCrypto_IsSRMUpdateSupported()\n"); + } if (!crypto_engine) { LOGE("OEMCrypto_IsSRMUpdateSupported: OEMCrypto Not Initialized."); return false; @@ -1638,6 +1641,9 @@ extern "C" bool OEMCrypto_IsSRMUpdateSupported() { } extern "C" OEMCryptoResult OEMCrypto_GetCurrentSRMVersion(uint16_t* version) { + if (LogCategoryEnabled(kLoggingTraceOEMCryptoCalls)) { + LOGI("-- OEMCryptoResult OEMCrypto_GetCurrentSRMVersion()\n"); + } if (!crypto_engine) { LOGE("OEMCrypto_GetCurrentSRMVersion: OEMCrypto Not Initialized."); return OEMCrypto_ERROR_UNKNOWN_FAILURE; @@ -1650,6 +1656,9 @@ extern "C" OEMCryptoResult OEMCrypto_GetCurrentSRMVersion(uint16_t* version) { extern "C" OEMCryptoResult OEMCrypto_LoadSRM(const uint8_t* buffer, size_t buffer_length) { + if (LogCategoryEnabled(kLoggingTraceOEMCryptoCalls)) { + LOGI("-- OEMCryptoResult OEMCrypto_LoadSRM(length=%d)\n", buffer_length); + } if (!crypto_engine) { LOGE("OEMCrypto_LoadSRM: OEMCrypto Not Initialized."); return OEMCrypto_ERROR_UNKNOWN_FAILURE; @@ -1658,6 +1667,9 @@ extern "C" OEMCryptoResult OEMCrypto_LoadSRM(const uint8_t* buffer, } extern "C" OEMCryptoResult OEMCrypto_RemoveSRM() { + if (LogCategoryEnabled(kLoggingTraceOEMCryptoCalls)) { + LOGI("-- OEMCryptoResult OEMCrypto_RemoveSRM()\n"); + } if (!crypto_engine) { LOGE("OEMCrypto_RemoveSRM: OEMCrypto Not Initialized."); return OEMCrypto_ERROR_UNKNOWN_FAILURE; From 1e451340ba37e4b53448efe7377a9795416821a0 Mon Sep 17 00:00:00 2001 From: Fred Gylys-Colwell Date: Wed, 26 Apr 2017 20:01:20 -0700 Subject: [PATCH 2/3] Fix SRM Version in mock Merge from Widevine repo of http://go/wvgerrit/26522 The modifiable OEMCrypto mock did not use the correct initial SRM version as specified in the options file. This CL fixes that. b/37713658 Change-Id: I5ab5f5549dd7815edd4a3d69b804440faedeb657 --- ...oemcrypto_engine_device_properties_mod.cpp | 6 +++++- .../oemcrypto/mock/src/oemcrypto_session.cpp | 19 ++++++++++--------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_engine_device_properties_mod.cpp b/libwvdrmengine/oemcrypto/mock/src/oemcrypto_engine_device_properties_mod.cpp index fe2be840..9f7551cf 100644 --- a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_engine_device_properties_mod.cpp +++ b/libwvdrmengine/oemcrypto/mock/src/oemcrypto_engine_device_properties_mod.cpp @@ -346,14 +346,18 @@ class AndroidModifiableCryptoEngine : public CryptoEngine { OEMCryptoResult current_srm_version(uint16_t *version) { if (srm_loaded_) { + LOGV("SRM loaded. version used is %d.", srm_version_); *version = srm_version_; return OEMCrypto_SUCCESS; } int value = GetOption("srm_initial_version", -1); if (value > 0) { - *version = srm_version_; + LOGV("SRM version from get option: %d.", value); + srm_version_ = value; + *version = value; return OEMCrypto_SUCCESS; } else { + LOGI("SRM initial version is %d -- reporting not implemented.", value); return OEMCrypto_ERROR_NOT_IMPLEMENTED; } } diff --git a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_session.cpp b/libwvdrmengine/oemcrypto/mock/src/oemcrypto_session.cpp index 80a304fb..93e66832 100644 --- a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_session.cpp +++ b/libwvdrmengine/oemcrypto/mock/src/oemcrypto_session.cpp @@ -410,17 +410,18 @@ OEMCryptoResult SessionContext::LoadKeys( uint32_t minimum_version = htonl(*reinterpret_cast(srm_requirement + 8)); uint16_t current_version = 0; - if (OEMCrypto_SUCCESS == ce_->current_srm_version(¤t_version) && - current_version >= minimum_version) { - srm_requirements_status_ = ValidSRMVersion; - if (ce_->srm_blacklisted_device_attached()) { - LOGW("[LoadKeys: SRM blacklisted device attached]"); - srm_requirements_status_ = InvalidSRMVersion; - } - } else { - LOGW("[LoadKeys: SRM Version too small %d, required: %d", + if (OEMCrypto_SUCCESS != ce_->current_srm_version(¤t_version)) { + LOGW("[LoadKeys: SRM Version not available."); + srm_requirements_status_ = InvalidSRMVersion; + } else if (current_version < minimum_version) { + LOGW("[LoadKeys: SRM Version is too small %d, required: %d", current_version, minimum_version); srm_requirements_status_ = InvalidSRMVersion; + } else if (ce_->srm_blacklisted_device_attached()) { + LOGW("[LoadKeys: SRM blacklisted device attached]"); + srm_requirements_status_ = InvalidSRMVersion; + } else { + srm_requirements_status_ = ValidSRMVersion; } } From fb10272f5597f97b1c9c46c8828410688788bde6 Mon Sep 17 00:00:00 2001 From: Fred Gylys-Colwell Date: Mon, 1 May 2017 14:49:10 -0700 Subject: [PATCH 3/3] OEMCrypto Mock should not downgrade SRM Merge from Widevine repo of http://go/wvgerrit/26560 With this CL, the modifiable oemcrypto mock will only update the SRM version number if the new number is greater than or equal to the current one. b/37744957 Change-Id: I10721146ca0ce24b1087657e18569a434e5d53b8 --- .../mock/src/oemcrypto_engine_device_properties_mod.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_engine_device_properties_mod.cpp b/libwvdrmengine/oemcrypto/mock/src/oemcrypto_engine_device_properties_mod.cpp index 9f7551cf..4e37a591 100644 --- a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_engine_device_properties_mod.cpp +++ b/libwvdrmengine/oemcrypto/mock/src/oemcrypto_engine_device_properties_mod.cpp @@ -374,6 +374,11 @@ class AndroidModifiableCryptoEngine : public CryptoEngine { } int new_version = GetOption("srm_load_version", -1); if (new_version >= 0) { + if (new_version < srm_version_) { + LOGE("New SRM version is lower than existing SRM version: %d < %d", + new_version, srm_version_); + return OEMCrypto_ERROR_INVALID_CONTEXT; + } srm_version_ = new_version; LOGI("OEMCrypto mock told to change SRM version to %d.", srm_version_); srm_loaded_ = true;