From 36aeacde48f1f3eb68d17c3247e011e97058c2ff Mon Sep 17 00:00:00 2001 From: Jeff Tinker Date: Fri, 19 Apr 2013 16:34:57 -0700 Subject: [PATCH] Optimize Status Queries in WVCryptoPlugin By Deleting Them Removes the status query from WVCryptoPlugin's decrypt method. It was not providing any additional security since it was not cryptographically secure, and querying status is an expensive operation on some devices. It should not be done on a frequent basis, such as in every decrypt call. Bug: 8667365 Merge of https://widevine-internal-review.googlesource.com/#/c/5121/ from widevine CDM repository to android repository. Change-Id: Id9a877c5655cb8dbee7e97f983d43ec2ab6acc6e --- libwvdrmengine/include/WVErrors.h | 3 +- .../mediacrypto/src/WVCryptoPlugin.cpp | 17 ----------- .../mediacrypto/test/WVCryptoPlugin_test.cpp | 29 ------------------- 3 files changed, 1 insertion(+), 48 deletions(-) diff --git a/libwvdrmengine/include/WVErrors.h b/libwvdrmengine/include/WVErrors.h index 50550d3c..f795b68e 100644 --- a/libwvdrmengine/include/WVErrors.h +++ b/libwvdrmengine/include/WVErrors.h @@ -16,8 +16,7 @@ enum { kErrorIncorrectBufferSize = ERROR_DRM_VENDOR_MIN, kErrorCDMGeneric = ERROR_DRM_VENDOR_MIN + 1, kErrorUnsupportedCrypto = ERROR_DRM_VENDOR_MIN + 2, - kErrorCannotGuaranteeSecurity = ERROR_DRM_VENDOR_MIN + 3, - kErrorExpectedUnencrypted = ERROR_DRM_VENDOR_MIN + 4, + kErrorExpectedUnencrypted = ERROR_DRM_VENDOR_MIN + 3, // Used by crypto test mode kErrorTestMode = ERROR_DRM_VENDOR_MAX, diff --git a/libwvdrmengine/mediacrypto/src/WVCryptoPlugin.cpp b/libwvdrmengine/mediacrypto/src/WVCryptoPlugin.cpp index a8ae4511..965fbdcd 100644 --- a/libwvdrmengine/mediacrypto/src/WVCryptoPlugin.cpp +++ b/libwvdrmengine/mediacrypto/src/WVCryptoPlugin.cpp @@ -76,23 +76,6 @@ ssize_t WVCryptoPlugin::decrypt(bool secure, const uint8_t key[KEY_ID_SIZE], return kErrorUnsupportedCrypto; } - // If the caller requested secure decrypt, verify that we can comply. - if (secure) { - CdmQueryMap status; - - CdmResponseType res = mCDM->QueryStatus(&status); - - if (!isCdmResponseTypeSuccess(res)) { - ALOGE("Error querying CDM status: %u", res); - errorDetailMsg->setTo("Unable to verify ability to decode securely."); - return kErrorCannotGuaranteeSecurity; - } else if (status[QUERY_KEY_SECURITY_LEVEL] != - QUERY_VALUE_SECURITY_LEVEL_L1) { - errorDetailMsg->setTo("Secure decode is not supported on this device."); - return kErrorCannotGuaranteeSecurity; - } - } - // Convert parameters to the form the CDM wishes to consume them in. const KeyId keyId(reinterpret_cast(key), KEY_ID_SIZE); const vector ivVector(iv, iv + KEY_IV_SIZE); diff --git a/libwvdrmengine/mediacrypto/test/WVCryptoPlugin_test.cpp b/libwvdrmengine/mediacrypto/test/WVCryptoPlugin_test.cpp index 936b2414..73eee75a 100644 --- a/libwvdrmengine/mediacrypto/test/WVCryptoPlugin_test.cpp +++ b/libwvdrmengine/mediacrypto/test/WVCryptoPlugin_test.cpp @@ -91,35 +91,6 @@ TEST_F(WVCryptoPluginTest, CorrectlyReportsSecureBuffers) { "WVCryptoPlugin incorrectly expects a secure audio decoder"; } -TEST_F(WVCryptoPluginTest, RejectsSecureDecodeOnL3) { - MockCDM cdm; - WVCryptoPlugin plugin(sessionId, kSessionIdSize, &cdm); - - CdmQueryMap l3Map; - l3Map[QUERY_KEY_SECURITY_LEVEL] = QUERY_VALUE_SECURITY_LEVEL_L3; - - // Decrypt should not be called because we specified an unsupported - // security level - EXPECT_CALL(cdm, Decrypt(_, _, _, _, _, _, _, _)) - .Times(0); - - EXPECT_CALL(cdm, QueryStatus(_)) - .WillOnce(DoAll(SetArgPointee<0>(l3Map), - Return(wvcdm::NO_ERROR))); - - AString errorDetailMessage; - - ssize_t res = plugin.decrypt(true, keyId, iv, CryptoPlugin::kMode_AES_CTR, - in, subSamples, kSubSampleCount, out, - &errorDetailMessage); - - EXPECT_LT(res, 0) << - "WVCryptoPlugin allowed decryption to proceed despite being asked for an " - "unsupported security level"; - EXPECT_GT(errorDetailMessage.size(), 0u) << - "WVCryptoPlugin did not report a detailed error message."; -} - TEST_F(WVCryptoPluginTest, AttemptsToDecrypt) { MockCDM cdm; WVCryptoPlugin plugin(sessionId, kSessionIdSize, &cdm);