Allow Apps to Voluntarily Downgrade to L3 Crypto
This merges the following changes from the Widevine CDM repository: 564f4cc Add CdmClientPropertySet to CDM Adds an interface to the CDM that allows it to query its client for certain properties. In this case, this includes the ability to specify what security level is desired, as well as support for service ceritifcate privacy mode. 9cfbd3e Force Level 3 fallback Adds support for voluntarily invoking L3 crypto to the OEMCrypto wrapper. 95d12c1 Add pointer to CdmClientPropertySet class to OpenSession. Adds support for storing the property set on a session-by-session basis and choosing the appropriate crypto level. 17de442 Add Settable Properties for Clank to Android Adds support for setting the aforementioned properties to the DrmEngine bbe704d Fixes to force fallback to level three security Corrections to invoke provisioning, OEMCrypto API with configured security level rather than the default. Unit tests were also revised. Note that some parts of this are also support for the ability to use a service certificate-based privacy mode. The remaining code for supporting this mode is still forthcoming. Bug: 10109249 Change-Id: I2755e4dea1de3e8a56cff237360298f7b7f1bddc
This commit is contained in:
@@ -23,7 +23,6 @@ LOCAL_STATIC_LIBRARIES := \
|
||||
libgmock \
|
||||
libgmock_main \
|
||||
libgtest \
|
||||
libwvwrapper \
|
||||
libwvlevel3 \
|
||||
libprotobuf-cpp-2.3.0-lite \
|
||||
libwvdrmdrmplugin \
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <string.h>
|
||||
#include <string>
|
||||
|
||||
#include "cdm_client_property_set.h"
|
||||
#include "gmock/gmock.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "media/stagefright/foundation/ABase.h"
|
||||
@@ -23,7 +24,8 @@ using namespace wvdrm;
|
||||
|
||||
class MockCDM : public WvContentDecryptionModule {
|
||||
public:
|
||||
MOCK_METHOD2(OpenSession, CdmResponseType(const CdmKeySystem&,
|
||||
MOCK_METHOD3(OpenSession, CdmResponseType(const CdmKeySystem&,
|
||||
const CdmClientPropertySet*,
|
||||
CdmSessionId*));
|
||||
|
||||
MOCK_METHOD1(CloseSession, CdmResponseType(const CdmSessionId&));
|
||||
@@ -133,8 +135,8 @@ TEST_F(WVDrmPluginTest, OpensSessions) {
|
||||
StrictMock<MockCrypto> crypto;
|
||||
WVDrmPlugin plugin(&cdm, &crypto);
|
||||
|
||||
EXPECT_CALL(cdm, OpenSession(StrEq("com.widevine"), _))
|
||||
.WillOnce(DoAll(SetArgPointee<1>(cdmSessionId),
|
||||
EXPECT_CALL(cdm, OpenSession(StrEq("com.widevine"), _, _))
|
||||
.WillOnce(DoAll(SetArgPointee<2>(cdmSessionId),
|
||||
Return(wvcdm::NO_ERROR)));
|
||||
|
||||
// Provide expected behavior when plugin requests session control info
|
||||
@@ -633,9 +635,9 @@ TEST_F(WVDrmPluginTest, FailsGenericMethodsWithoutAnAlgorithmSet) {
|
||||
bool match;
|
||||
|
||||
// Provide expected behavior to support session creation
|
||||
EXPECT_CALL(cdm, OpenSession(StrEq("com.widevine"), _))
|
||||
EXPECT_CALL(cdm, OpenSession(StrEq("com.widevine"), _, _))
|
||||
.Times(AtLeast(1))
|
||||
.WillRepeatedly(DoAll(SetArgPointee<1>(cdmSessionId),
|
||||
.WillRepeatedly(DoAll(SetArgPointee<2>(cdmSessionId),
|
||||
Return(wvcdm::NO_ERROR)));
|
||||
|
||||
EXPECT_CALL(cdm, QueryKeyControlInfo(cdmSessionId, _))
|
||||
@@ -719,9 +721,9 @@ TEST_F(WVDrmPluginTest, CallsGenericEncrypt) {
|
||||
}
|
||||
|
||||
// Provide expected behavior to support session creation
|
||||
EXPECT_CALL(cdm, OpenSession(StrEq("com.widevine"), _))
|
||||
EXPECT_CALL(cdm, OpenSession(StrEq("com.widevine"), _, _))
|
||||
.Times(AtLeast(1))
|
||||
.WillRepeatedly(DoAll(SetArgPointee<1>(cdmSessionId),
|
||||
.WillRepeatedly(DoAll(SetArgPointee<2>(cdmSessionId),
|
||||
Return(wvcdm::NO_ERROR)));
|
||||
|
||||
EXPECT_CALL(cdm, QueryKeyControlInfo(cdmSessionId, _))
|
||||
@@ -786,9 +788,9 @@ TEST_F(WVDrmPluginTest, CallsGenericDecrypt) {
|
||||
}
|
||||
|
||||
// Provide expected behavior to support session creation
|
||||
EXPECT_CALL(cdm, OpenSession(StrEq("com.widevine"), _))
|
||||
EXPECT_CALL(cdm, OpenSession(StrEq("com.widevine"), _, _))
|
||||
.Times(AtLeast(1))
|
||||
.WillRepeatedly(DoAll(SetArgPointee<1>(cdmSessionId),
|
||||
.WillRepeatedly(DoAll(SetArgPointee<2>(cdmSessionId),
|
||||
Return(wvcdm::NO_ERROR)));
|
||||
|
||||
EXPECT_CALL(cdm, QueryKeyControlInfo(cdmSessionId, _))
|
||||
@@ -855,9 +857,9 @@ TEST_F(WVDrmPluginTest, CallsGenericSign) {
|
||||
}
|
||||
|
||||
// Provide expected behavior to support session creation
|
||||
EXPECT_CALL(cdm, OpenSession(StrEq("com.widevine"), _))
|
||||
EXPECT_CALL(cdm, OpenSession(StrEq("com.widevine"), _, _))
|
||||
.Times(AtLeast(1))
|
||||
.WillRepeatedly(DoAll(SetArgPointee<1>(cdmSessionId),
|
||||
.WillRepeatedly(DoAll(SetArgPointee<2>(cdmSessionId),
|
||||
Return(wvcdm::NO_ERROR)));
|
||||
|
||||
EXPECT_CALL(cdm, QueryKeyControlInfo(cdmSessionId, _))
|
||||
@@ -934,9 +936,9 @@ TEST_F(WVDrmPluginTest, CallsGenericVerify) {
|
||||
}
|
||||
|
||||
// Provide expected behavior to support session creation
|
||||
EXPECT_CALL(cdm, OpenSession(StrEq("com.widevine"), _))
|
||||
EXPECT_CALL(cdm, OpenSession(StrEq("com.widevine"), _, _))
|
||||
.Times(AtLeast(1))
|
||||
.WillRepeatedly(DoAll(SetArgPointee<1>(cdmSessionId),
|
||||
.WillRepeatedly(DoAll(SetArgPointee<2>(cdmSessionId),
|
||||
Return(wvcdm::NO_ERROR)));
|
||||
|
||||
EXPECT_CALL(cdm, QueryKeyControlInfo(cdmSessionId, _))
|
||||
@@ -977,9 +979,9 @@ TEST_F(WVDrmPluginTest, RegistersForEvents) {
|
||||
.Times(1);
|
||||
|
||||
// Provide expected behavior to support session creation
|
||||
EXPECT_CALL(cdm, OpenSession(StrEq("com.widevine"), _))
|
||||
EXPECT_CALL(cdm, OpenSession(StrEq("com.widevine"), _, _))
|
||||
.Times(AtLeast(1))
|
||||
.WillRepeatedly(DoAll(SetArgPointee<1>(cdmSessionId),
|
||||
.WillRepeatedly(DoAll(SetArgPointee<2>(cdmSessionId),
|
||||
Return(wvcdm::NO_ERROR)));
|
||||
|
||||
EXPECT_CALL(cdm, QueryKeyControlInfo(cdmSessionId, _))
|
||||
@@ -1014,10 +1016,10 @@ TEST_F(WVDrmPluginTest, UnregistersForAllEventsOnDestruction) {
|
||||
CdmSessionId cdmSessionId1(sessionIdRaw1, sessionIdRaw1 + kSessionIdSize);
|
||||
CdmSessionId cdmSessionId2(sessionIdRaw2, sessionIdRaw2 + kSessionIdSize);
|
||||
|
||||
EXPECT_CALL(cdm, OpenSession(StrEq("com.widevine"), _))
|
||||
.WillOnce(DoAll(SetArgPointee<1>(cdmSessionId1),
|
||||
EXPECT_CALL(cdm, OpenSession(StrEq("com.widevine"), _, _))
|
||||
.WillOnce(DoAll(SetArgPointee<2>(cdmSessionId1),
|
||||
Return(wvcdm::NO_ERROR)))
|
||||
.WillOnce(DoAll(SetArgPointee<1>(cdmSessionId2),
|
||||
.WillOnce(DoAll(SetArgPointee<2>(cdmSessionId2),
|
||||
Return(wvcdm::NO_ERROR)));
|
||||
|
||||
EXPECT_CALL(cdm, QueryKeyControlInfo(cdmSessionId1, _))
|
||||
@@ -1071,9 +1073,9 @@ TEST_F(WVDrmPluginTest, MarshalsEvents) {
|
||||
}
|
||||
|
||||
// Provide expected behavior to support session creation
|
||||
EXPECT_CALL(cdm, OpenSession(StrEq("com.widevine"), _))
|
||||
EXPECT_CALL(cdm, OpenSession(StrEq("com.widevine"), _, _))
|
||||
.Times(AtLeast(1))
|
||||
.WillRepeatedly(DoAll(SetArgPointee<1>(cdmSessionId),
|
||||
.WillRepeatedly(DoAll(SetArgPointee<2>(cdmSessionId),
|
||||
Return(wvcdm::NO_ERROR)));
|
||||
|
||||
EXPECT_CALL(cdm, QueryKeyControlInfo(cdmSessionId, _))
|
||||
@@ -1099,3 +1101,217 @@ TEST_F(WVDrmPluginTest, MarshalsEvents) {
|
||||
plugin.onEvent(cdmSessionId, LICENSE_EXPIRED_EVENT);
|
||||
plugin.onEvent(cdmSessionId, LICENSE_RENEWAL_NEEDED_EVENT);
|
||||
}
|
||||
|
||||
TEST_F(WVDrmPluginTest, ProvidesExpectedDefaultPropertiesToCdm) {
|
||||
StrictMock<MockCDM> cdm;
|
||||
StrictMock<MockCrypto> crypto;
|
||||
WVDrmPlugin plugin(&cdm, &crypto);
|
||||
|
||||
const CdmClientPropertySet* propertySet = NULL;
|
||||
|
||||
// Provide expected mock behavior
|
||||
{
|
||||
// Provide expected behavior in response to OpenSession and store the
|
||||
// property set
|
||||
EXPECT_CALL(cdm, OpenSession(_, _, _))
|
||||
.WillRepeatedly(DoAll(SetArgPointee<2>(cdmSessionId),
|
||||
SaveArg<1>(&propertySet),
|
||||
Return(wvcdm::NO_ERROR)));
|
||||
|
||||
// Provide expected behavior when plugin requests session control info
|
||||
EXPECT_CALL(cdm, QueryKeyControlInfo(cdmSessionId, _))
|
||||
.WillRepeatedly(Invoke(setSessionIdOnMap<4>));
|
||||
|
||||
// Let gMock know these calls will happen but we aren't interested in them.
|
||||
EXPECT_CALL(cdm, AttachEventListener(_, _))
|
||||
.Times(AtLeast(0));
|
||||
|
||||
EXPECT_CALL(cdm, DetachEventListener(_, _))
|
||||
.Times(AtLeast(0));
|
||||
|
||||
EXPECT_CALL(cdm, CloseSession(_))
|
||||
.Times(AtLeast(0));
|
||||
}
|
||||
|
||||
plugin.openSession(sessionId);
|
||||
|
||||
ASSERT_THAT(propertySet, NotNull());
|
||||
EXPECT_STREQ("", propertySet->security_level().c_str());
|
||||
EXPECT_FALSE(propertySet->use_privacy_mode());
|
||||
EXPECT_EQ(0u, propertySet->service_certificate().size());
|
||||
}
|
||||
|
||||
TEST_F(WVDrmPluginTest, CanSetSecurityLevel) {
|
||||
StrictMock<MockCDM> cdm;
|
||||
StrictMock<MockCrypto> crypto;
|
||||
WVDrmPlugin plugin(&cdm, &crypto);
|
||||
|
||||
const CdmClientPropertySet* propertySet = NULL;
|
||||
|
||||
// Provide expected mock behavior
|
||||
{
|
||||
// Provide expected behavior in response to OpenSession and store the
|
||||
// property set
|
||||
EXPECT_CALL(cdm, OpenSession(_, _, _))
|
||||
.WillRepeatedly(DoAll(SetArgPointee<2>(cdmSessionId),
|
||||
SaveArg<1>(&propertySet),
|
||||
Return(wvcdm::NO_ERROR)));
|
||||
|
||||
// Provide expected behavior when plugin requests session control info
|
||||
EXPECT_CALL(cdm, QueryKeyControlInfo(cdmSessionId, _))
|
||||
.WillRepeatedly(Invoke(setSessionIdOnMap<4>));
|
||||
|
||||
// Let gMock know these calls will happen but we aren't interested in them.
|
||||
EXPECT_CALL(cdm, AttachEventListener(_, _))
|
||||
.Times(AtLeast(0));
|
||||
|
||||
EXPECT_CALL(cdm, DetachEventListener(_, _))
|
||||
.Times(AtLeast(0));
|
||||
|
||||
EXPECT_CALL(cdm, CloseSession(_))
|
||||
.Times(AtLeast(0));
|
||||
}
|
||||
|
||||
status_t res;
|
||||
|
||||
// Test forcing L3
|
||||
res = plugin.setPropertyString(String8("securityLevel"), String8("L3"));
|
||||
ASSERT_EQ(OK, res);
|
||||
|
||||
plugin.openSession(sessionId);
|
||||
ASSERT_THAT(propertySet, NotNull());
|
||||
EXPECT_STREQ("L3", propertySet->security_level().c_str());
|
||||
plugin.closeSession(sessionId);
|
||||
|
||||
// Test forcing L1 (Should Fail)
|
||||
res = plugin.setPropertyString(String8("securityLevel"), String8("L1"));
|
||||
ASSERT_NE(OK, res);
|
||||
|
||||
// Test un-forcing a level
|
||||
res = plugin.setPropertyString(String8("securityLevel"), String8(""));
|
||||
ASSERT_EQ(OK, res);
|
||||
|
||||
plugin.openSession(sessionId);
|
||||
ASSERT_THAT(propertySet, NotNull());
|
||||
EXPECT_STREQ("", propertySet->security_level().c_str());
|
||||
plugin.closeSession(sessionId);
|
||||
|
||||
// Test nonsense (Should Fail)
|
||||
res = plugin.setPropertyString(String8("securityLevel"), String8("nonsense"));
|
||||
ASSERT_NE(OK, res);
|
||||
|
||||
// Test attempting to force a level with a session open (Should Fail)
|
||||
plugin.openSession(sessionId);
|
||||
res = plugin.setPropertyString(String8("securityLevel"), String8("L3"));
|
||||
ASSERT_NE(OK, res);
|
||||
}
|
||||
|
||||
TEST_F(WVDrmPluginTest, CanSetPrivacyMode) {
|
||||
StrictMock<MockCDM> cdm;
|
||||
StrictMock<MockCrypto> crypto;
|
||||
WVDrmPlugin plugin(&cdm, &crypto);
|
||||
|
||||
const CdmClientPropertySet* propertySet = NULL;
|
||||
|
||||
// Provide expected mock behavior
|
||||
{
|
||||
// Provide expected behavior in response to OpenSession and store the
|
||||
// property set
|
||||
EXPECT_CALL(cdm, OpenSession(_, _, _))
|
||||
.WillRepeatedly(DoAll(SetArgPointee<2>(cdmSessionId),
|
||||
SaveArg<1>(&propertySet),
|
||||
Return(wvcdm::NO_ERROR)));
|
||||
|
||||
// Provide expected behavior when plugin requests session control info
|
||||
EXPECT_CALL(cdm, QueryKeyControlInfo(cdmSessionId, _))
|
||||
.WillRepeatedly(Invoke(setSessionIdOnMap<4>));
|
||||
|
||||
// Let gMock know these calls will happen but we aren't interested in them.
|
||||
EXPECT_CALL(cdm, AttachEventListener(_, _))
|
||||
.Times(AtLeast(0));
|
||||
|
||||
EXPECT_CALL(cdm, DetachEventListener(_, _))
|
||||
.Times(AtLeast(0));
|
||||
|
||||
EXPECT_CALL(cdm, CloseSession(_))
|
||||
.Times(AtLeast(0));
|
||||
}
|
||||
|
||||
plugin.openSession(sessionId);
|
||||
ASSERT_THAT(propertySet, NotNull());
|
||||
|
||||
status_t res;
|
||||
|
||||
// Test turning on privacy mode
|
||||
res = plugin.setPropertyString(String8("privacyMode"), String8("enable"));
|
||||
ASSERT_EQ(OK, res);
|
||||
EXPECT_TRUE(propertySet->use_privacy_mode());
|
||||
|
||||
// Test turning off privacy mode
|
||||
res = plugin.setPropertyString(String8("privacyMode"), String8("disable"));
|
||||
ASSERT_EQ(OK, res);
|
||||
EXPECT_FALSE(propertySet->use_privacy_mode());
|
||||
|
||||
// Test nonsense (Should Fail)
|
||||
res = plugin.setPropertyString(String8("privacyMode"), String8("nonsense"));
|
||||
ASSERT_NE(OK, res);
|
||||
}
|
||||
|
||||
TEST_F(WVDrmPluginTest, CanSetServiceCertificate) {
|
||||
StrictMock<MockCDM> cdm;
|
||||
StrictMock<MockCrypto> crypto;
|
||||
WVDrmPlugin plugin(&cdm, &crypto);
|
||||
|
||||
const CdmClientPropertySet* propertySet = NULL;
|
||||
|
||||
static const size_t kPrivacyCertSize = 256;
|
||||
uint8_t privacyCertRaw[kPrivacyCertSize];
|
||||
|
||||
FILE* fp = fopen("/dev/urandom", "r");
|
||||
fread(privacyCertRaw, sizeof(uint8_t), kPrivacyCertSize, fp);
|
||||
fclose(fp);
|
||||
|
||||
Vector<uint8_t> privacyCert;
|
||||
privacyCert.appendArray(privacyCertRaw, kPrivacyCertSize);
|
||||
Vector<uint8_t> emptyVector;
|
||||
|
||||
// Provide expected mock behavior
|
||||
{
|
||||
// Provide expected behavior in response to OpenSession and store the
|
||||
// property set
|
||||
EXPECT_CALL(cdm, OpenSession(_, _, _))
|
||||
.WillRepeatedly(DoAll(SetArgPointee<2>(cdmSessionId),
|
||||
SaveArg<1>(&propertySet),
|
||||
Return(wvcdm::NO_ERROR)));
|
||||
|
||||
// Provide expected behavior when plugin requests session control info
|
||||
EXPECT_CALL(cdm, QueryKeyControlInfo(cdmSessionId, _))
|
||||
.WillRepeatedly(Invoke(setSessionIdOnMap<4>));
|
||||
|
||||
// Let gMock know these calls will happen but we aren't interested in them.
|
||||
EXPECT_CALL(cdm, AttachEventListener(_, _))
|
||||
.Times(AtLeast(0));
|
||||
|
||||
EXPECT_CALL(cdm, DetachEventListener(_, _))
|
||||
.Times(AtLeast(0));
|
||||
|
||||
EXPECT_CALL(cdm, CloseSession(_))
|
||||
.Times(AtLeast(0));
|
||||
}
|
||||
|
||||
plugin.openSession(sessionId);
|
||||
ASSERT_THAT(propertySet, NotNull());
|
||||
|
||||
status_t res;
|
||||
|
||||
// Test setting a certificate
|
||||
res = plugin.setPropertyByteArray(String8("serviceCertificate"), privacyCert);
|
||||
ASSERT_EQ(OK, res);
|
||||
EXPECT_THAT(propertySet->service_certificate(),
|
||||
ElementsAreArray(privacyCertRaw, kPrivacyCertSize));
|
||||
|
||||
// Test clearing a certificate
|
||||
res = plugin.setPropertyByteArray(String8("serviceCertificate"), emptyVector);
|
||||
ASSERT_EQ(OK, res);
|
||||
EXPECT_EQ(0u, propertySet->service_certificate().size());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user