Add Detail Error Messages
Reworks the error message reporting that was just added to WVCryptoPlugin so that it reports detailed error messages to the app (because the error codes cannot be relied upon to reach the app intact) and so that it always reports custom errors so that the detailed error message is passed to the app. Bug: 8621516 Merge of https://widevine-internal-review.googlesource.com/#/c/5031/ from widevine git to android git. Change-Id: Id7a517fb6e4e772ffea4c779a8ee52b357345a08
This commit is contained in:
@@ -10,12 +10,19 @@
|
||||
namespace wvdrm {
|
||||
|
||||
using android::ERROR_DRM_VENDOR_MIN;
|
||||
using android::ERROR_DRM_VENDOR_MAX;
|
||||
|
||||
enum {
|
||||
kErrorNeedProvisioning = ERROR_DRM_VENDOR_MIN,
|
||||
kErrorDeviceRevoked = ERROR_DRM_VENDOR_MIN + 1,
|
||||
kErrorIncorrectBufferSize = ERROR_DRM_VENDOR_MIN + 2,
|
||||
kErrorCDMGeneric = ERROR_DRM_VENDOR_MIN + 3,
|
||||
kErrorNeedProvisioning = ERROR_DRM_VENDOR_MIN,
|
||||
kErrorDeviceRevoked = ERROR_DRM_VENDOR_MIN + 1,
|
||||
kErrorIncorrectBufferSize = ERROR_DRM_VENDOR_MIN + 2,
|
||||
kErrorCDMGeneric = ERROR_DRM_VENDOR_MIN + 3,
|
||||
kErrorUnsupportedCrypto = ERROR_DRM_VENDOR_MIN + 4,
|
||||
kErrorCannotGuaranteeSecurity = ERROR_DRM_VENDOR_MIN + 5,
|
||||
kErrorExpectedUnencrypted = ERROR_DRM_VENDOR_MIN + 6,
|
||||
|
||||
// Used by crypto test mode
|
||||
kErrorTestMode = ERROR_DRM_VENDOR_MAX,
|
||||
};
|
||||
|
||||
} // namespace wvdrm
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include "utils/Errors.h"
|
||||
#include "utils/String8.h"
|
||||
#include "wv_cdm_constants.h"
|
||||
#include "WVErrors.h"
|
||||
|
||||
namespace wvdrm {
|
||||
|
||||
@@ -71,7 +72,8 @@ ssize_t WVCryptoPlugin::decrypt(bool secure, const uint8_t key[KEY_ID_SIZE],
|
||||
size_t numSubSamples, void* dstPtr,
|
||||
AString* errorDetailMsg) {
|
||||
if (mode != kMode_Unencrypted && mode != kMode_AES_CTR) {
|
||||
return ERROR_DRM_CANNOT_HANDLE;
|
||||
errorDetailMsg->setTo("Encryption mode is not supported by Widevine CDM.");
|
||||
return kErrorUnsupportedCrypto;
|
||||
}
|
||||
|
||||
// If the caller requested secure decrypt, verify that we can comply.
|
||||
@@ -82,10 +84,12 @@ ssize_t WVCryptoPlugin::decrypt(bool secure, const uint8_t key[KEY_ID_SIZE],
|
||||
|
||||
if (!isCdmResponseTypeSuccess(res)) {
|
||||
ALOGE("Error querying CDM status: %u", res);
|
||||
return ERROR_DRM_CANNOT_HANDLE;
|
||||
errorDetailMsg->setTo("Unable to verify ability to decode securely.");
|
||||
return kErrorCannotGuaranteeSecurity;
|
||||
} else if (status[QUERY_KEY_SECURITY_LEVEL] !=
|
||||
QUERY_VALUE_SECURITY_LEVEL_L1) {
|
||||
return ERROR_DRM_CANNOT_HANDLE;
|
||||
errorDetailMsg->setTo("Secure decode is not supported on this device.");
|
||||
return kErrorCannotGuaranteeSecurity;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,7 +107,9 @@ ssize_t WVCryptoPlugin::decrypt(bool secure, const uint8_t key[KEY_ID_SIZE],
|
||||
const SubSample &subSample = subSamples[i];
|
||||
|
||||
if (mode == kMode_Unencrypted && subSample.mNumBytesOfEncryptedData != 0) {
|
||||
return ERROR_DRM_DECRYPT;
|
||||
errorDetailMsg->setTo("Encrypted subsamples found in allegedly "
|
||||
"unencrypted data.");
|
||||
return kErrorExpectedUnencrypted;
|
||||
}
|
||||
|
||||
// "Decrypt" any unencrypted data. Per the ISO-CENC standard, clear data
|
||||
@@ -117,7 +123,8 @@ ssize_t WVCryptoPlugin::decrypt(bool secure, const uint8_t key[KEY_ID_SIZE],
|
||||
if (!isCdmResponseTypeSuccess(res)) {
|
||||
ALOGE("Decrypt error result in session %s during unencrypted block: %d",
|
||||
mSessionId.c_str(), res);
|
||||
return mapCdmResponseType(res);
|
||||
errorDetailMsg->setTo("Error decrypting data.");
|
||||
return kErrorCDMGeneric;
|
||||
}
|
||||
|
||||
offset += subSample.mNumBytesOfClearData;
|
||||
@@ -134,7 +141,8 @@ ssize_t WVCryptoPlugin::decrypt(bool secure, const uint8_t key[KEY_ID_SIZE],
|
||||
if (!isCdmResponseTypeSuccess(res)) {
|
||||
ALOGE("Decrypt error result in session %s during encrypted block: %d",
|
||||
mSessionId.c_str(), res);
|
||||
return mapCdmResponseType(res);
|
||||
errorDetailMsg->setTo("Error decrypting data.");
|
||||
return kErrorCDMGeneric;
|
||||
}
|
||||
|
||||
offset += subSample.mNumBytesOfEncryptedData;
|
||||
@@ -158,8 +166,8 @@ ssize_t WVCryptoPlugin::decrypt(bool secure, const uint8_t key[KEY_ID_SIZE],
|
||||
buf.appendFormat("%02x", digest[i]);
|
||||
}
|
||||
|
||||
*errorDetailMsg = AString(buf.string());
|
||||
return ERROR_DRM_VENDOR_MIN;
|
||||
errorDetailMsg->setTo(buf.string());
|
||||
return kErrorTestMode;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -107,12 +107,17 @@ TEST_F(WVCryptoPluginTest, RejectsSecureDecodeOnL3) {
|
||||
.WillOnce(DoAll(SetArgPointee<0>(l3Map),
|
||||
Return(wvcdm::NO_ERROR)));
|
||||
|
||||
ssize_t res = plugin.decrypt(true, keyId, iv, CryptoPlugin::kMode_AES_CTR,
|
||||
in, subSamples, kSubSampleCount, out, NULL);
|
||||
AString errorDetailMessage;
|
||||
|
||||
EXPECT_LT(res, static_cast<ssize_t>(0)) <<
|
||||
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) {
|
||||
@@ -144,9 +149,14 @@ TEST_F(WVCryptoPluginTest, AttemptsToDecrypt) {
|
||||
.WillOnce(Return(wvcdm::NO_ERROR));
|
||||
}
|
||||
|
||||
AString errorDetailMessage;
|
||||
|
||||
ssize_t res = plugin.decrypt(false, keyId, iv, CryptoPlugin::kMode_AES_CTR,
|
||||
in, subSamples, kSubSampleCount, out, NULL);
|
||||
in, subSamples, kSubSampleCount, out,
|
||||
&errorDetailMessage);
|
||||
|
||||
EXPECT_EQ(static_cast<ssize_t>(kDataSize), res) <<
|
||||
"WVCryptoPlugin decrypted the wrong number of bytes";
|
||||
EXPECT_EQ(0u, errorDetailMessage.size()) <<
|
||||
"WVCryptoPlugin reported a detailed error message.";
|
||||
}
|
||||
Reference in New Issue
Block a user