Initial Clear Key DRM Engine

Adds the initial pieces of a sample DRM Engine that accepts keys in the clear
through the decrypt call instead of using the DrmClientPlugin and its key
ladder.  This is to help unblock teams writing code that consumes DRM Engines
while Widevine continues working their real DRM engine.  This is based on the
in-progress Widevine DRM Engine.

This change contains the DRM Engine glue pieces (.so entry point,
DrmPluginFactory, etc.) and a CryptoPlugin implementation.  However, said
CryptoPlugin will not work until an implementation of OEMCrypto is provided
in a future checkin and the CryptoPlugin is hooked up to it.

For ease of loading, this library also implements the old CryptoFactory
interface and entry point.

If asked to create a CryptoPlugin with no data, it will defer to the old
Widevine Crypto Plugin.

Change-Id: I0bfbec7e32439a50a2956488dd970284f0075e61
This commit is contained in:
John "Juce" Bruce
2012-12-10 13:54:43 -08:00
committed by Jeff Tinker
parent d5aa1e41d3
commit 04bfbb0198
18 changed files with 1546 additions and 0 deletions

View File

@@ -0,0 +1,116 @@
/*
* Copyright 2012 Google Inc. All Rights Reserved.
*/
#include "utils/UniquePtr.h"
#include "WVDrmPluginFactory.h"
#include "OEMCryptoDASH.h"
#include "gtest/gtest.h"
using namespace wvclearkey;
const uint8_t kWidevineUUID[16] = {
0xED,0xEF,0x8B,0xA9,0x79,0xD6,0x4A,0xCE,
0xA3,0xC8,0x27,0xDC,0xD5,0x1D,0x21,0xED
};
const uint8_t kOldNetflixWidevineUUID[16] = {
0x29,0x70,0x1F,0xE4,0x3C,0xC7,0x4A,0x34,
0x8C,0x5B,0xAE,0x90,0xC7,0x43,0x9A,0x47
};
const uint8_t kUnknownUUID[16] = {
0x6A,0x7F,0xAA,0xB0,0x83,0xC7,0x9E,0x20,
0x08,0xBC,0xEF,0x32,0x34,0x1A,0x9A,0x26
};
TEST(WVDrmPluginFactoryTest, SupportsSupportedCryptoSchemes) {
UniquePtr<WVDrmPluginFactory> factory = new WVDrmPluginFactory();
EXPECT_TRUE(factory->isCryptoSchemeSupported(kWidevineUUID)) <<
"WVDrmPluginFactory does not support Widevine's UUID";
EXPECT_TRUE(factory->isCryptoSchemeSupported(kOldNetflixWidevineUUID)) <<
"WVDrmPluginFactory does not support the old Netflix Widevine UUID";
}
TEST(WVDrmPluginFactoryTest, DoesNotSupportUnsupportedCryptoSchemes) {
UniquePtr<WVDrmPluginFactory> factory = new WVDrmPluginFactory();
EXPECT_FALSE(factory->isCryptoSchemeSupported(kUnknownUUID)) <<
"WVDrmPluginFactory incorrectly claims to support an unknown UUID";
}
TEST(WVDrmPluginFactoryTest, CreatesCryptoPlugins) {
UniquePtr<WVDrmPluginFactory> factory = new WVDrmPluginFactory();
UniquePtr<android::CryptoPlugin> plugin;
status_t result = factory->createCryptoPlugin(kWidevineUUID, NULL, 0, &plugin);
EXPECT_EQ(android::OK, result) <<
"WVDrmPluginFactory returned error from createCryptoPlugin()";
EXPECT_NE((android::CryptoPlugin *)NULL, plugin) <<
"WVDrmPluginFactory's createCryptoPlugin() did not create a plugin";
}
TEST(WVDrmPluginFactoryTest, DoesNotCreateDrmClientPlugins) {
UniquePtr<WVDrmPluginFactory> factory = new WVDrmPluginFactory();
UniquePtr<android::DrmClientPlugin> plugin;
status_t result = factory->createDrmClientPlugin(kWidevineUUID, NULL, 0, &plugin);
EXPECT_EQ(-EPERM, result) <<
"WVDrmPluginFactory did not indicate that createDrmClientPlugin() is not implemented";
EXPECT_EQ((android::DrmClientPlugin *)NULL, plugin) <<
"WVDrmPluginFactory's createDrmClientPlugin() created a plugin (?!?)";
}
TEST(WVDrmPluginFactoryTest, RefusesToCreateWithUnsupportedCryptoScheme) {
UniquePtr<WVDrmPluginFactory> factory = new WVDrmPluginFactory();
UniquePtr<android::CryptoPlugin> cryptoPlugin;
UniquePtr<android::DrmClientPlugin> drmClientPlugin;
status_t result;
result = factory->createCryptoPlugin(kUnknownUUID, NULL, 0, &cryptoPlugin);
EXPECT_EQ(android::BAD_VALUE, result) <<
"WVDrmPluginFactory did not reject unknown UUID when creating a CryptoPlugin";
EXPECT_EQ((android::CryptoPlugin *)NULL, cryptoPlugin) <<
"WVDrmPluginFactory created a CryptoPlugin despite having an unknown UUID";
result = factory->createDrmClientPlugin(kUnknownUUID, NULL, 0, &drmClientPlugin);
EXPECT_EQ(android::BAD_VALUE, result) <<
"WVDrmPluginFactory did not reject unknown UUID when creating a DrmClientPlugin";
EXPECT_EQ((android::DrmClientPlugin *)NULL, drmClientPlugin) <<
"WVDrmPluginFactory created a DrmClientPlugin despite having an unknown UUID";
}
bool oemCryptoInitialized;
bool oemCryptoTerminated;
extern "C" {
OEMCryptoResult OEMCrypto_Initialize(void) {
oemCryptoInitialized = true;
return OEMCrypto_SUCCESS;
}
OEMCryptoResult OEMCrypto_Terminate(void) {
oemCryptoTerminated = true;
return OEMCrypto_SUCCESS;
}
}
TEST(WVDrmPluginFactoryTest, CallsOemCrypto) {
oemCryptoInitialized = false;
oemCryptoTerminated = false;
WVDrmPluginFactory *factory = new WVDrmPluginFactory();
EXPECT_EQ(true, oemCryptoInitialized) <<
"WVDrmPluginFactory did not call OEMCrypto_Initialize()";
delete factory;
EXPECT_EQ(true, oemCryptoTerminated) <<
"WVDrmPluginFactory did not call OEMCrypto_Terminate()";
}