Add end-to-end decryption test with vectors
Added a test_mode flag to the libwvdrmengine plugin to support verifying decryption results. Change-Id: I9edbd6279d54fc495b5bbad8273c179106cad474
This commit is contained in:
@@ -7,6 +7,7 @@ LOCAL_SRC_FILES := \
|
||||
LOCAL_C_INCLUDES := \
|
||||
bionic \
|
||||
external/stlport/stlport \
|
||||
external/openssl/include \
|
||||
frameworks/av/include \
|
||||
frameworks/native/include \
|
||||
vendor/widevine/libwvdrmengine/cdm/core/include \
|
||||
|
||||
@@ -29,7 +29,8 @@ class WVCryptoPlugin : public android::CryptoPlugin {
|
||||
DISALLOW_EVIL_CONSTRUCTORS(WVCryptoPlugin);
|
||||
|
||||
wvcdm::WvContentDecryptionModule* const mCDM;
|
||||
const wvcdm::CdmSessionId mSessionId;
|
||||
wvcdm::CdmSessionId mSessionId;
|
||||
bool mTestMode;
|
||||
};
|
||||
|
||||
} // namespace wvdrm
|
||||
|
||||
@@ -10,9 +10,12 @@
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <openssl/sha.h>
|
||||
|
||||
#include "utils/Errors.h"
|
||||
#include "utils/String8.h"
|
||||
#include "wv_cdm_constants.h"
|
||||
#include "media/stagefright/MediaErrors.h"
|
||||
|
||||
namespace wvdrm {
|
||||
|
||||
@@ -23,7 +26,14 @@ using namespace wvcdm;
|
||||
WVCryptoPlugin::WVCryptoPlugin(const void* data, size_t size,
|
||||
WvContentDecryptionModule* cdm)
|
||||
: mCDM(cdm),
|
||||
mSessionId(static_cast<const char*>(data), size) {}
|
||||
mSessionId(static_cast<const char*>(data), size),
|
||||
mTestMode(false) {
|
||||
size_t index = mSessionId.find("test_mode");
|
||||
if (index != string::npos) {
|
||||
mSessionId = mSessionId.substr(0, index);
|
||||
mTestMode = true;
|
||||
}
|
||||
}
|
||||
|
||||
bool WVCryptoPlugin::requiresSecureDecoderComponent(const char *mime) const {
|
||||
// TODO: Determine if we are using L1 or L3 and return an appropriate value.
|
||||
@@ -100,6 +110,27 @@ ssize_t WVCryptoPlugin::decrypt(bool secure, const uint8_t key[KEY_ID_SIZE],
|
||||
}
|
||||
}
|
||||
|
||||
// In test mode, we return an error that causes a detailed error
|
||||
// message string containing a SHA256 hash of the decrypted data
|
||||
// to get passed to the java app via CryptoException. The test app
|
||||
// can then use the hash to verify that decryption was successful.
|
||||
|
||||
if (mTestMode) {
|
||||
SHA256_CTX ctx;
|
||||
uint8_t digest[SHA256_DIGEST_LENGTH];
|
||||
SHA256_Init(&ctx);
|
||||
SHA256_Update(&ctx, dstPtr, offset);
|
||||
SHA256_Final(digest, &ctx);
|
||||
String8 buf;
|
||||
for (size_t i = 0; i < sizeof(digest); i++) {
|
||||
buf.appendFormat("%02x", digest[i]);
|
||||
}
|
||||
|
||||
*errorDetailMsg = AString(buf.string());
|
||||
return ERROR_DRM_VENDOR_MIN;
|
||||
}
|
||||
|
||||
|
||||
return static_cast<ssize_t>(offset);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user