Merge changes I295f66f9,I142f286c into rvc-dev am: 05fbb3dd87 am: 0db9b974c2 am: 1c6633d408 am: 7b0fe07c8a

Original change: https://googleplex-android-review.googlesource.com/c/platform/vendor/widevine/+/11620164

Change-Id: If47d215914fbb11d2d33cd01b635d4fe16112957
This commit is contained in:
Rahul Frias
2020-06-16 09:22:07 +00:00
committed by Automerger Merge Worker
24 changed files with 399 additions and 120 deletions

View File

@@ -38,6 +38,8 @@ class MockCdmClientPropertySet : public CdmClientPropertySet {
MOCK_CONST_METHOD0(is_session_sharing_enabled, bool());
MOCK_CONST_METHOD0(session_sharing_id, uint32_t());
MOCK_METHOD1(set_session_sharing_id, void(uint32_t));
MOCK_CONST_METHOD0(use_atsc_mode, bool());
MOCK_METHOD1(set_use_atsc_mode, void(bool));
MOCK_CONST_METHOD0(app_id, const std::string&());
};

View File

@@ -114,8 +114,8 @@ class MockDeviceFiles : public DeviceFiles {
MockDeviceFiles() : DeviceFiles(nullptr) {}
MOCK_METHOD1(Init, bool(CdmSecurityLevel));
MOCK_METHOD4(RetrieveCertificate,
bool(std::string*, std::string*, std::string*, uint32_t*));
MOCK_METHOD5(RetrieveCertificate,
bool(bool, std::string*, std::string*, std::string*, uint32_t*));
};
class MockUsageTableHeader : public UsageTableHeader {
@@ -217,8 +217,8 @@ TEST_F(CdmSessionTest, InitWithBuiltInCertificate) {
EXPECT_CALL(*crypto_session_, GetPreProvisionTokenType())
.WillOnce(Return(kClientTokenDrmCert));
EXPECT_CALL(*file_handle_,
RetrieveCertificate(NotNull(), NotNull(), NotNull(), _))
.WillOnce(DoAll(SetArgPointee<0>(kToken), SetArgPointee<1>(kWrappedKey),
RetrieveCertificate(false, NotNull(), NotNull(), NotNull(), _))
.WillOnce(DoAll(SetArgPointee<1>(kToken), SetArgPointee<2>(kWrappedKey),
Return(true)));
EXPECT_CALL(*crypto_session_, LoadCertificatePrivateKey(StrEq(kWrappedKey)))
.InSequence(crypto_session_seq)
@@ -245,8 +245,8 @@ TEST_F(CdmSessionTest, InitWithCertificate) {
.WillOnce(Return(kClientTokenKeybox));
EXPECT_CALL(*file_handle_, Init(Eq(level))).WillOnce(Return(true));
EXPECT_CALL(*file_handle_,
RetrieveCertificate(NotNull(), NotNull(), NotNull(), _))
.WillOnce(DoAll(SetArgPointee<0>(kToken), SetArgPointee<1>(kWrappedKey),
RetrieveCertificate(false, NotNull(), NotNull(), NotNull(), _))
.WillOnce(DoAll(SetArgPointee<1>(kToken), SetArgPointee<2>(kWrappedKey),
Return(true)));
EXPECT_CALL(*crypto_session_, LoadCertificatePrivateKey(StrEq(kWrappedKey)))
.InSequence(crypto_session_seq)
@@ -272,8 +272,8 @@ TEST_F(CdmSessionTest, ReInitFail) {
.WillOnce(Return(kClientTokenKeybox));
EXPECT_CALL(*file_handle_, Init(Eq(level))).WillOnce(Return(true));
EXPECT_CALL(*file_handle_,
RetrieveCertificate(NotNull(), NotNull(), NotNull(), _))
.WillOnce(DoAll(SetArgPointee<0>(kToken), SetArgPointee<1>(kWrappedKey),
RetrieveCertificate(false, NotNull(), NotNull(), NotNull(), _))
.WillOnce(DoAll(SetArgPointee<1>(kToken), SetArgPointee<2>(kWrappedKey),
Return(true)));
EXPECT_CALL(*crypto_session_, LoadCertificatePrivateKey(StrEq(kWrappedKey)))
.InSequence(crypto_session_seq)
@@ -307,7 +307,7 @@ TEST_F(CdmSessionTest, InitNeedsProvisioning) {
.WillOnce(Return(kClientTokenKeybox));
EXPECT_CALL(*file_handle_, Init(Eq(level))).WillOnce(Return(true));
EXPECT_CALL(*file_handle_,
RetrieveCertificate(NotNull(), NotNull(), NotNull(), _))
RetrieveCertificate(false, NotNull(), NotNull(), NotNull(), _))
.WillOnce(Return(false));
ASSERT_EQ(NEED_PROVISIONING, cdm_session_->Init(nullptr));
@@ -327,8 +327,8 @@ TEST_F(CdmSessionTest, UpdateUsageEntry) {
.WillOnce(Return(kClientTokenKeybox));
EXPECT_CALL(*file_handle_, Init(Eq(level))).WillOnce(Return(true));
EXPECT_CALL(*file_handle_,
RetrieveCertificate(NotNull(), NotNull(), NotNull(), _))
.WillOnce(DoAll(SetArgPointee<0>(kToken), SetArgPointee<1>(kWrappedKey),
RetrieveCertificate(false, NotNull(), NotNull(), NotNull(), _))
.WillOnce(DoAll(SetArgPointee<1>(kToken), SetArgPointee<2>(kWrappedKey),
Return(true)));
EXPECT_CALL(*crypto_session_, LoadCertificatePrivateKey(StrEq(kWrappedKey)))
.InSequence(crypto_session_seq)

View File

@@ -32,27 +32,26 @@ const std::string kEmptyString;
// Structurally valid test certificate.
// The data elements in this module are used to test the storage and
// retrieval of certificates and licenses
const std::string kTestCertificate =
"124B035F3D256A656F0E505A085E7A6C482B61035E0C4A540F7803137F4C3B45206B7F33"
"347F4D7A005E56400F0955011F4E07072D0D46781817460974326A516E3944385760280E"
"4F166B380F033D045231201E6146041C3A6F01345C59300D32592732192C0F2310586306"
"7B31467B1477010D6F1D1944272509572A26217E1E6F7B666F46153E7749106E48760468"
"19467E164A731773155B3236537D5128682014174D125063380E48356A370B5015416A7F"
"672F132E37364E154B41540F440E47092775531508495F1E55576F363C0C190C3A332179"
"415B343905563E37645E68007053315A1A20286E7C3B4320424A5F7F36635558686C3565"
"762122237D344A411C0F00342135776753461D105C21111E5024434E5E0F275D12061658"
"4435410F210E5228532D214F505D0F0B3C34032C7C597F6159665E664C682C5A6C03212E"
"71333C3A642D796A65642E151827086E2D671C130B172C43192C792D294440630163526D"
"0658537A073E0F32231E7426593230692A4468386D3511542F1A6F71440128466E510445"
"294F4465113D1B1A711D4D67691363093B680854322B041C2F72524A513E5F0E407C6233"
"1728520E6C0C09107C26737B78287231661952283619647A6241391940297D2067036D44"
"3C64766918236C51175A636F000A2E5A4C5B725D5500652B1C39283037723F0255092976"
"6F2D204F0E616F1233206B75661B0F755E1E3807491079663A191C0B2D5E363B3768663A"
"4E222A1D32015D3D783E5148313F05713B140347231C59243648313C23770F554E012715"
"3350597775274A580306202E65265957291F490F642A2E7C6700716400617C7E6A303266"
"523B102906195E003C2D111A7D4740122C6941003726602B59263B5C09473D4E025E3541"
"701B122D340A3D145436137002687E4C470D2F6F4C357A3245384D737B734E2274301179"
"402473486311156E5A0C78644C593273";
const std::string kTestCertificate = a2bs_hex(
"0A98030802120D73657269616C5F6E756D62657218B4B2CDE00422E8024D49494243674B43"
"415145412B78475A2F77637A39756746705030374E73706F365531376C3059684669467078"
"78553470546B334C69667A3952337A734973754552777461372B66574966784F6F32303865"
"74742F6A68736B69566F645345743351424768345842697079576F704B775A393348486144"
"565A41414C692F32412B785442745764456F37584755756A4B447643322F615A4B756B666A"
"704F6955493841684C41666A6D6C63442F555A31515068306D4873676C524E436D7043776D"
"7753584139564E6D687A2B5069422B446D6C3457576E4B572F56486F32756A54587871372B"
"65664D55344832666E79335365334B594F73465046475A31544E5153596C46755368577248"
"5074694C6D5564506F50364356326D4D4C31746B2B6C3744494971587251684C554B444143"
"654D35726F4D78306B4C6855574238502B30756A31434E6C4E4E344A525A6C433778466671"
"694D62465255395A344E3659774944415141422899203A11746573742E7769646576696E65"
"2E636F6D128202307836353063396632653637303165336665373364333035343930346139"
"61346262646239363733336631633463373433656635373361643661633134633561336266"
"38613437333166366536323736666165613532343733303336373766623864626466323466"
"66373865353363323530353263646361383765656366656538353437366263623861303563"
"62396131656665663763623837646436383232336531313763653830306163343631373731"
"37323534343735376134383762653332663561623866653038373966613861646437386265"
"34363565613866386435616366393737653966316165333664346434373831366561366564"
"343133373262");
// A Wrapped Private Key
// The data elements in this module are used to test the storage and
@@ -76,42 +75,54 @@ const std::string kTestWrappedPrivateKey =
// The test certificate in file storage format.
// The data elements in this module are used to test the storage and
// retrieval of certificates and licenses
const std::string kTestCertificateFileData =
"0ABD09080110011AB6090ABC05124B035F3D256A656F0E505A085E7A6C482B61035E0C4A"
"540F7803137F4C3B45206B7F33347F4D7A005E56400F0955011F4E07072D0D4678181746"
"0974326A516E3944385760280E4F166B380F033D045231201E6146041C3A6F01345C5930"
"0D32592732192C0F23105863067B31467B1477010D6F1D1944272509572A26217E1E6F7B"
"666F46153E7749106E4876046819467E164A731773155B3236537D5128682014174D1250"
"63380E48356A370B5015416A7F672F132E37364E154B41540F440E47092775531508495F"
"1E55576F363C0C190C3A332179415B343905563E37645E68007053315A1A20286E7C3B43"
"20424A5F7F36635558686C3565762122237D344A411C0F00342135776753461D105C2111"
"1E5024434E5E0F275D120616584435410F210E5228532D214F505D0F0B3C34032C7C597F"
"6159665E664C682C5A6C03212E71333C3A642D796A65642E151827086E2D671C130B172C"
"43192C792D294440630163526D0658537A073E0F32231E7426593230692A4468386D3511"
"542F1A6F71440128466E510445294F4465113D1B1A711D4D67691363093B680854322B04"
"1C2F72524A513E5F0E407C62331728520E6C0C09107C26737B7828723166195228361964"
"7A6241391940297D2067036D443C64766918236C51175A636F000A2E5A4C5B725D550065"
"2B1C39283037723F02550929766F2D204F0E616F1233206B75661B0F755E1E3807491079"
"663A191C0B2D5E363B3768663A4E222A1D32015D3D783E5148313F05713B140347231C59"
"243648313C23770F554E0127153350597775274A580306202E65265957291F490F642A2E"
"7C6700716400617C7E6A303266523B102906195E003C2D111A7D4740122C694100372660"
"2B59263B5C09473D4E025E3541701B122D340A3D145436137002687E4C470D2F6F4C357A"
"3245384D737B734E2274301179402473486311156E5A0C78644C59327312F4034F724B06"
"5326371A2F5F6F51467C2E26555C453B5C7C1B4F2738454B782E3E7B5340435A66374D06"
"12052C521A233D7A67194871751C78575E5177070130264C4F037633320E667B1A491929"
"24491338693D106E6113014A733A241A1A033E28352178146B4F543D38104A5919120325"
"502C31365506096D59585E08774B5B567A7B5D03451E6B11633E52672C226103104B3E4C"
"031A6403050F3A574D2C501711773802741F7F3A0D364757101D02181C7D4D3520716750"
"6A424C094E4A72316F791F162D76657D2B5D3C2D7B273A2869277175613165187E552824"
"30491467086425432347701C3116446D21645C756B2D3D0F797C3220322D622A254D0B7D"
"4F1D5D0C0A36755D1246741A34783C45157247091C78232B7D2E0E1F637A2A3739085D76"
"166747034350613969072F5B5C5B21657E470C7E513B3F091D74455A3A0737057B7E3B53"
"37191D4E7536087C334B6028530F3F5B23380B6A076031294501003D6D1F240F63053D5D"
"0B271B6A0F26185650731308660B0447566041684F584C22216E567D3B7755695F7F3D6B"
"64525E7227165948101540243C19495C4C702F37490F2661335379782562414326304302"
"0E1E6760123D51056F2F1E482F2E3D021B27677D3E7E3C0C11757C3448275E08382E1112"
"63644C6D224714706D760A054A586E17505C3429575A41043F1842091220F8D0A23D4B1B"
"C7B23A38B921BC1EA8938D1FD22FF9A389B58DA856A3E2625F27";
const std::string kTestCertificateFileData = a2bs_hex(
"0A950D080110011A8E0D0AA0050A98030802120D73657269616C5F6E756D62657218B4B2CD"
"E00422E8024D49494243674B43415145412B78475A2F77637A39756746705030374E73706F"
"365531376C305968466946707878553470546B334C69667A3952337A734973754552777461"
"372B66574966784F6F3230386574742F6A68736B69566F6453457433514247683458426970"
"79576F704B775A393348486144565A41414C692F32412B785442745764456F37584755756A"
"4B447643322F615A4B756B666A704F6955493841684C41666A6D6C63442F555A3151506830"
"6D4873676C524E436D7043776D7753584139564E6D687A2B5069422B446D6C3457576E4B57"
"2F56486F32756A54587871372B65664D55344832666E79335365334B594F73465046475A31"
"544E5153596C467553685772485074694C6D5564506F50364356326D4D4C31746B2B6C3744"
"494971587251684C554B444143654D35726F4D78306B4C6855574238502B30756A31434E6C"
"4E4E344A525A6C433778466671694D62465255395A344E3659774944415141422899203A11"
"746573742E7769646576696E652E636F6D1282023078363530633966326536373031653366"
"65373364333035343930346139613462626462393637333366316334633734336566353733"
"61643661633134633561336266386134373331663665363237366661656135323437333033"
"36373766623864626466323466663738653533633235303532636463613837656563666565"
"38353437366263623861303563623961316566656637636238376464363832323365313137"
"63653830306163343631373731373235343437353761343837626533326635616238666530"
"38373966613861646437386265343635656138663864356163663937376539663161653336"
"6434643437383136656136656434313337326212E807344637323442303635333236333731"
"41324635463646353134363743324532363535354334353342354337433142344632373338"
"34353442373832453345374235333430343335413636333734443036313230353243353231"
"41323333443741363731393438373137353143373835373545353137373037303133303236"
"34433446303337363333333230453636374231413439313932393234343931333338363933"
"44313036453631313330313441373333413234314131413033334532383335323137383134"
"36423446353433443338313034413539313931323033323535303243333133363535303630"
"39364435393538354530383737344235423536374137423544303334353145364231313633"
"33453532363732433232363130333130344233453443303331413634303330353046334135"
"37344432433530313731313737333830323734314637463341304433363437353731303144"
"30323138314337443444333532303731363735303641343234433039344534413732333136"
"46373931463136324437363635374432423544334332443742323733413238363932373731"
"37353631333136353138374535353238323433303439313436373038363432353433323334"
"37373031433331313634343644323136343543373536423244334430463739374333323230"
"33323244363232413235344430423744344631443544304330413336373535443132343637"
"34314133343738334334353135373234373039314337383233324237443245304531463633"
"37413241333733393038354437363136363734373033343335303631333936393037324635"
"42354335423231363537453437304337453531334233463039314437343435354133413037"
"33373035374237453342353333373139314434453735333630383743333334423630323835"
"33304633463542323333383042364130373630333132393435303130303344364431463234"
"30463633303533443544304232373142364130463236313835363530373331333038363630"
"42303434373536363034313638344635383443323232313645353637443342373735353639"
"35463746334436423634353235453732323731363539343831303135343032343343313934"
"39354334433730324633373439304632363631333335333739373832353632343134333236"
"33303433303230453145363736303132334435313035364632463145343832463245334430"
"32314232373637374433453745334330433131373537433334343832373545303833383245"
"31313132363336343443364432323437313437303644373630413035344135383645313735"
"303543333432393537354134313034334631383432303912205C6993E9656F73A41739773A"
"0FCBA8AE232CD8856ACE585FF6BFB2A09C20061E");
struct LicenseInfo {
std::string key_set_id;
@@ -2075,9 +2086,9 @@ class DeviceFilesTest : public ::testing::Test {
class DeviceFilesStoreTest : public DeviceFilesTest,
public ::testing::WithParamInterface<bool> {};
class DeviceCertificateStoreTest : public DeviceFilesTest {};
class DeviceCertificateTest : public DeviceFilesTest {};
class DeviceCertificateTest
: public DeviceFilesTest,
public ::testing::WithParamInterface<bool /* atsc mode */> {};
class DeviceFilesSecurityLevelTest
: public DeviceFilesTest,
@@ -2185,12 +2196,12 @@ MATCHER_P8(Contains, str1, str2, str3, str4, str5, str6, map7, str8, "") {
data.find(str8) != std::string::npos);
}
TEST_F(DeviceCertificateStoreTest, StoreCertificate) {
TEST_F(DeviceCertificateTest, StoreCertificate) {
MockFileSystem file_system;
std::string certificate(CdmRandom::RandomData(kCertificateLen));
std::string wrapped_private_key(CdmRandom::RandomData(kWrappedKeyLen));
std::string device_certificate_path =
device_base_path_ + DeviceFiles::GetCertificateFileName();
device_base_path_ + DeviceFiles::GetCertificateFileName(false);
// Call to Open will return a unique_ptr, freeing this object.
MockFile* file = new MockFile();
@@ -2207,12 +2218,12 @@ TEST_F(DeviceCertificateStoreTest, StoreCertificate) {
EXPECT_TRUE(device_files.StoreCertificate(certificate, wrapped_private_key));
}
// TODO(tinskip): Fix. kTestCertificateFileData appears to be incorect.
TEST_F(DeviceCertificateTest, DISABLED_ReadCertificate) {
TEST_P(DeviceCertificateTest, ReadCertificate) {
MockFileSystem file_system;
const bool atsc_mode = GetParam();
std::string device_certificate_path =
device_base_path_ + DeviceFiles::GetCertificateFileName();
std::string data = a2bs_hex(kTestCertificateFileData);
device_base_path_ + DeviceFiles::GetCertificateFileName(atsc_mode);
std::string data = kTestCertificateFileData;
// Call to Open will return a unique_ptr, freeing this object.
MockFile* file = new MockFile();
@@ -2233,16 +2244,18 @@ TEST_F(DeviceCertificateTest, DISABLED_ReadCertificate) {
std::string certificate, wrapped_private_key;
std::string serial_number;
uint32_t system_id = 0;
ASSERT_TRUE(device_files.RetrieveCertificate(
&certificate, &wrapped_private_key, &serial_number, &system_id));
EXPECT_EQ(kTestCertificate, b2a_hex(certificate));
EXPECT_EQ(kTestWrappedPrivateKey, b2a_hex(wrapped_private_key));
ASSERT_TRUE(device_files.RetrieveCertificate(atsc_mode, &certificate,
&wrapped_private_key,
&serial_number, &system_id));
EXPECT_EQ(kTestCertificate, certificate);
EXPECT_EQ(kTestWrappedPrivateKey, wrapped_private_key);
}
TEST_F(DeviceCertificateTest, HasCertificate) {
TEST_P(DeviceCertificateTest, HasCertificate) {
MockFileSystem file_system;
bool atsc_mode = GetParam();
std::string device_certificate_path =
device_base_path_ + DeviceFiles::GetCertificateFileName();
device_base_path_ + DeviceFiles::GetCertificateFileName(atsc_mode);
EXPECT_CALL(file_system, Exists(StrEq(device_certificate_path)))
.WillOnce(Return(false))
@@ -2253,11 +2266,14 @@ TEST_F(DeviceCertificateTest, HasCertificate) {
ASSERT_TRUE(device_files.Init(kSecurityLevelL1));
// MockFile returns false.
EXPECT_FALSE(device_files.HasCertificate());
EXPECT_FALSE(device_files.HasCertificate(atsc_mode));
// MockFile returns true.
EXPECT_TRUE(device_files.HasCertificate());
EXPECT_TRUE(device_files.HasCertificate(atsc_mode));
}
INSTANTIATE_TEST_CASE_P(AtscMode, DeviceCertificateTest,
::testing::Values(false, true));
TEST_P(DeviceFilesSecurityLevelTest, SecurityLevel) {
MockFileSystem file_system;
std::string certificate(CdmRandom::RandomData(kCertificateLen));
@@ -2268,7 +2284,7 @@ TEST_P(DeviceFilesSecurityLevelTest, SecurityLevel) {
ASSERT_TRUE(
Properties::GetDeviceFilesBasePath(security_level, &device_base_path));
std::string device_certificate_path =
device_base_path + DeviceFiles::GetCertificateFileName();
device_base_path + DeviceFiles::GetCertificateFileName(false);
// Call to Open will return a unique_ptr, freeing this object.
MockFile* file = new MockFile();

View File

@@ -15,8 +15,8 @@ namespace wvcdm {
// Google license servers.
class LicenseRequest {
public:
LicenseRequest() {};
~LicenseRequest() {};
LicenseRequest() {}
~LicenseRequest() {}
void GetDrmMessage(const std::string& response, std::string& drm_msg);

View File

@@ -79,6 +79,7 @@ class StubCdmClientPropertySet : public CdmClientPropertySet {
}
uint32_t session_sharing_id() const override { return session_sharing_id_; }
virtual bool use_atsc_mode() const { return false; }
void set_session_sharing_id(uint32_t id) override {
session_sharing_id_ = id;

View File

@@ -935,6 +935,9 @@ void PrintTo(const enum CdmResponseType& value, ::std::ostream* os) {
case WEBM_INIT_DATA_UNAVAILABLE:
*os << "WEBM_INIT_DATA_UNAVAILABLE";
break;
case PROVISIONING_NOT_ALLOWED_FOR_ATSC:
*os << "PROVISIONING_NOT_ALLOWED_FOR_ATSC";
break;
default:
*os << "Unknown CdmResponseType";
break;