Source release v3.5.0
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
#include <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "clock.h"
|
||||
#include "crypto_session.h"
|
||||
#include "initialization_data.h"
|
||||
@@ -34,6 +36,33 @@ const std::string kCryptoRequestId = a2bs_hex(
|
||||
"4341444542353737444337393044394330313030303030303030303030303030");
|
||||
const uint32_t kNonce = 0x49e81305;
|
||||
const int64_t kLicenseStartTime = 1413517500; // ~ 01/01/2013
|
||||
const std::string kEmptyServiceCertificate;
|
||||
const std::string kInvalidServiceCertificate = "0b";
|
||||
const std::string kDefaultServiceCertificate = a2bs_hex(
|
||||
"0ABF020803121028703454C008F63618ADE7443DB6C4C8188BE7F9900522"
|
||||
"8E023082010A0282010100B52112B8D05D023FCC5D95E2C251C1C649B417"
|
||||
"7CD8D2BEEF355BB06743DE661E3D2ABC3182B79946D55FDC08DFE9540781"
|
||||
"5E9A6274B322A2C7F5E067BB5F0AC07A89D45AEA94B2516F075B66EF811D"
|
||||
"0D26E1B9A6B894F2B9857962AA171C4F66630D3E4C602718897F5E1EF9B6"
|
||||
"AAF5AD4DBA2A7E14176DF134A1D3185B5A218AC05A4C41F081EFFF80A3A0"
|
||||
"40C50B09BBC740EEDCD8F14D675A91980F92CA7DDC646A06ADAD5101F74A"
|
||||
"0E498CC01F00532BAC217850BD905E90923656B7DFEFEF42486767F33EF6"
|
||||
"283D4F4254AB72589390BEE55808F1D668080D45D893C2BCA2F74D60A0C0"
|
||||
"D0A0993CEF01604703334C3638139486BC9DAF24FD67A07F9AD943020301"
|
||||
"00013A1273746167696E672E676F6F676C652E636F6D128003983E303526"
|
||||
"75F40BA715FC249BDAE5D4AC7249A2666521E43655739529721FF880E0AA"
|
||||
"EFC5E27BC980DAEADABF3FC386D084A02C82537848CC753FF497B011A7DA"
|
||||
"97788A00E2AA6B84CD7D71C07A48EBF61602CCA5A3F32030A7295C30DA91"
|
||||
"5B91DC18B9BC9593B8DE8BB50F0DEDC12938B8E9E039CDDE18FA82E81BB0"
|
||||
"32630FE955D85A566CE154300BF6D4C1BD126966356B287D657B18CE63D0"
|
||||
"EFD45FC5269E97EAB11CB563E55643B26FF49F109C2101AFCAF35B832F28"
|
||||
"8F0D9D45960E259E85FB5D24DBD2CF82764C5DD9BF727EFBE9C861F86932"
|
||||
"1F6ADE18905F4D92F9A6DA6536DB8475871D168E870BB2303CF70C6E9784"
|
||||
"C93D2DE845AD8262BE7E0D4E2E4A0759CEF82D109D2592C72429F8C01742"
|
||||
"BAE2B3DECADBC33C3E5F4BAF5E16ECB74EADBAFCB7C6705F7A9E3B6F3940"
|
||||
"383F9C5116D202A20C9229EE969C2519718303B50D0130C3352E06B014D8"
|
||||
"38540F8A0C227C0011E0F5B38E4E298ED2CB301EB4564965F55C5D79757A"
|
||||
"250A4EB9C84AB3E6539F6B6FDF56899EA29914");
|
||||
const std::string kToken = a2bs_hex(
|
||||
"0AAE02080212107E0A892DEEB021E7AF696B938BB1D5B1188B85AD9D05228E023082010A02"
|
||||
"82010100DBEDF2BFB0EC98213766E65049B9AB176FA4B1FBFBB2A0C96C87D9F2B895E0ED77"
|
||||
@@ -105,12 +134,21 @@ const std::string kSubSessionKeyID2 =
|
||||
const std::string kSubSessionKeyID3 =
|
||||
a2bs_hex("21cdec9b2105c6b643e71f68e5302c85");
|
||||
|
||||
const CryptoSession::SupportedCertificateTypes kDefaultSupportedCertTypes = {
|
||||
true,
|
||||
true,
|
||||
true
|
||||
};
|
||||
|
||||
class MockCryptoSession : public CryptoSession {
|
||||
public:
|
||||
MockCryptoSession(metrics::CryptoMetrics* crypto_metrics)
|
||||
: CryptoSession(crypto_metrics) { }
|
||||
MOCK_METHOD0(IsOpen, bool());
|
||||
MOCK_METHOD1(GenerateRequestId, bool(std::string*));
|
||||
MOCK_METHOD1(UsageInformationSupport, bool(bool*));
|
||||
MOCK_METHOD2(GetHdcpCapabilities, bool(HdcpCapability*, HdcpCapability*));
|
||||
MOCK_METHOD1(GetSupportedCertificateTypes, bool(SupportedCertificateTypes*));
|
||||
MOCK_METHOD1(GetApiVersion, bool(uint32_t*));
|
||||
MOCK_METHOD1(GenerateNonce, bool(uint32_t*));
|
||||
MOCK_METHOD3(PrepareRequest, bool(const std::string&, bool, std::string*));
|
||||
@@ -152,6 +190,7 @@ using ::testing::Eq;
|
||||
using ::testing::NotNull;
|
||||
using ::testing::Return;
|
||||
using ::testing::SetArgPointee;
|
||||
using ::testing::UnorderedElementsAre;
|
||||
|
||||
class CdmLicenseTest : public ::testing::Test {
|
||||
protected:
|
||||
@@ -159,9 +198,13 @@ class CdmLicenseTest : public ::testing::Test {
|
||||
: pssh_(pssh) {}
|
||||
virtual void SetUp() {
|
||||
clock_ = new MockClock();
|
||||
crypto_session_ = new testing::StrictMock<MockCryptoSession>();
|
||||
crypto_session_ = new MockCryptoSession(&crypto_metrics_);
|
||||
init_data_ = new MockInitializationData(CENC_INIT_DATA_FORMAT, pssh_);
|
||||
policy_engine_ = new MockPolicyEngine(crypto_session_);
|
||||
|
||||
ON_CALL(*crypto_session_, GetSupportedCertificateTypes(NotNull()))
|
||||
.WillByDefault(
|
||||
DoAll(SetArgPointee<0>(kDefaultSupportedCertTypes), Return(true)));
|
||||
}
|
||||
|
||||
virtual void TearDown() {
|
||||
@@ -179,10 +222,10 @@ class CdmLicenseTest : public ::testing::Test {
|
||||
|
||||
CdmLicense* cdm_license_;
|
||||
MockClock* clock_;
|
||||
metrics::CryptoMetrics crypto_metrics_;
|
||||
MockCryptoSession* crypto_session_;
|
||||
MockInitializationData* init_data_;
|
||||
MockPolicyEngine* policy_engine_;
|
||||
ServiceCertificate service_cert_;
|
||||
std::string pssh_;
|
||||
};
|
||||
|
||||
@@ -195,37 +238,60 @@ TEST_F(CdmLicenseTest, InitSuccess) {
|
||||
EXPECT_CALL(*crypto_session_, IsOpen()).WillOnce(Return(true));
|
||||
|
||||
CreateCdmLicense();
|
||||
EXPECT_TRUE(cdm_license_->Init(
|
||||
&service_cert_, kToken, kClientTokenDrmCert, kEmptyString,
|
||||
crypto_session_, policy_engine_));
|
||||
EXPECT_TRUE(cdm_license_->Init(kToken, kClientTokenDrmCert, kEmptyString,
|
||||
false, kEmptyServiceCertificate,
|
||||
crypto_session_, policy_engine_));
|
||||
}
|
||||
|
||||
TEST_F(CdmLicenseTest, InitFail_EmptyToken) {
|
||||
CreateCdmLicense();
|
||||
EXPECT_FALSE(cdm_license_->Init(&service_cert_, "", kClientTokenDrmCert,
|
||||
"", crypto_session_, policy_engine_));
|
||||
EXPECT_FALSE(cdm_license_->Init("", kClientTokenDrmCert, "", false,
|
||||
kEmptyServiceCertificate, crypto_session_,
|
||||
policy_engine_));
|
||||
}
|
||||
|
||||
TEST_F(CdmLicenseTest, InitFail_CryptoSessionNull) {
|
||||
CreateCdmLicense();
|
||||
EXPECT_FALSE(cdm_license_->Init(&service_cert_, kToken, kClientTokenDrmCert,
|
||||
"", NULL, policy_engine_));
|
||||
EXPECT_FALSE(cdm_license_->Init(kToken, kClientTokenDrmCert, "", false,
|
||||
kEmptyServiceCertificate, NULL,
|
||||
policy_engine_));
|
||||
}
|
||||
|
||||
TEST_F(CdmLicenseTest, InitFail_PolicyEngineNull) {
|
||||
EXPECT_CALL(*crypto_session_, IsOpen()).WillOnce(Return(true));
|
||||
|
||||
CreateCdmLicense();
|
||||
EXPECT_FALSE(cdm_license_->Init(&service_cert_, kToken, kClientTokenDrmCert,
|
||||
"", crypto_session_, NULL));
|
||||
EXPECT_FALSE(cdm_license_->Init(kToken, kClientTokenDrmCert, "", false,
|
||||
kEmptyServiceCertificate, crypto_session_,
|
||||
NULL));
|
||||
}
|
||||
|
||||
TEST_F(CdmLicenseTest, InitWithNullServiceCert) {
|
||||
TEST_F(CdmLicenseTest, InitWithEmptyServiceCert) {
|
||||
EXPECT_CALL(*crypto_session_, IsOpen()).WillOnce(Return(true));
|
||||
|
||||
CreateCdmLicense();
|
||||
EXPECT_TRUE(cdm_license_->Init(NULL, kToken, kClientTokenDrmCert,
|
||||
"", crypto_session_, policy_engine_));
|
||||
EXPECT_EQ(cdm_license_->Init(kToken, kClientTokenDrmCert, "", true,
|
||||
kEmptyServiceCertificate, crypto_session_,
|
||||
policy_engine_),
|
||||
Properties::allow_service_certificate_requests());
|
||||
}
|
||||
|
||||
TEST_F(CdmLicenseTest, InitWithInvalidServiceCert) {
|
||||
EXPECT_CALL(*crypto_session_, IsOpen()).WillOnce(Return(true));
|
||||
|
||||
CreateCdmLicense();
|
||||
EXPECT_FALSE(cdm_license_->Init(kToken, kClientTokenDrmCert, "", true,
|
||||
kInvalidServiceCertificate, crypto_session_,
|
||||
policy_engine_));
|
||||
}
|
||||
|
||||
TEST_F(CdmLicenseTest, InitWithServiceCert) {
|
||||
EXPECT_CALL(*crypto_session_, IsOpen()).WillOnce(Return(true));
|
||||
|
||||
CreateCdmLicense();
|
||||
EXPECT_TRUE(cdm_license_->Init(kToken, kClientTokenDrmCert, "", true,
|
||||
kDefaultServiceCertificate, crypto_session_,
|
||||
policy_engine_));
|
||||
}
|
||||
|
||||
TEST_F(CdmLicenseTest, PrepareKeyRequestValidation) {
|
||||
@@ -244,6 +310,7 @@ TEST_F(CdmLicenseTest, PrepareKeyRequestValidation) {
|
||||
EXPECT_CALL(*crypto_session_, GetHdcpCapabilities(NotNull(), NotNull()))
|
||||
.WillOnce(DoAll(SetArgPointee<0>(current_hdcp_version),
|
||||
SetArgPointee<1>(max_hdcp_version), Return(true)));
|
||||
EXPECT_CALL(*crypto_session_, GetSupportedCertificateTypes(NotNull()));
|
||||
EXPECT_CALL(*crypto_session_, GetApiVersion(NotNull()))
|
||||
.WillOnce(
|
||||
DoAll(SetArgPointee<0>(crypto_session_api_version), Return(true)));
|
||||
@@ -255,15 +322,12 @@ TEST_F(CdmLicenseTest, PrepareKeyRequestValidation) {
|
||||
DoAll(SetArgPointee<2>(kLicenseRequestSignature), Return(true)));
|
||||
|
||||
CreateCdmLicense();
|
||||
// TODO(gmorgan) fix below - no default service certificate
|
||||
//service_cert_.Init(kDefaultServiceCertificate);
|
||||
EXPECT_TRUE(cdm_license_->Init(
|
||||
&service_cert_, kToken, kClientTokenDrmCert, kEmptyString,
|
||||
crypto_session_, policy_engine_));
|
||||
kToken, kClientTokenDrmCert, kEmptyString, true,
|
||||
kDefaultServiceCertificate, crypto_session_, policy_engine_));
|
||||
|
||||
CdmAppParameterMap app_parameters;
|
||||
CdmKeyMessage signed_request;
|
||||
Properties::set_use_certificates_as_identification(true);
|
||||
std::string server_url;
|
||||
EXPECT_EQ(cdm_license_->PrepareKeyRequest(
|
||||
*init_data_, kLicenseTypeStreaming, app_parameters,
|
||||
@@ -315,6 +379,14 @@ TEST_F(CdmLicenseTest, PrepareKeyRequestValidation) {
|
||||
EXPECT_EQ(crypto_session_api_version,
|
||||
client_capabilities.oem_crypto_api_version());
|
||||
|
||||
EXPECT_THAT(
|
||||
client_capabilities.supported_certificate_key_type(),
|
||||
UnorderedElementsAre(
|
||||
video_widevine::
|
||||
ClientIdentification_ClientCapabilities_CertificateKeyType_RSA_2048,
|
||||
video_widevine::
|
||||
ClientIdentification_ClientCapabilities_CertificateKeyType_RSA_3072));
|
||||
|
||||
// Verify Content Identification
|
||||
const LicenseRequest_ContentIdentification& content_id =
|
||||
license_request.content_id();
|
||||
@@ -363,6 +435,7 @@ TEST_F(SubLicenseTest, VerifySubSessionData) {
|
||||
EXPECT_CALL(*crypto_session_, PrepareRequest(_, Eq(false), NotNull()))
|
||||
.WillOnce(
|
||||
DoAll(SetArgPointee<2>(kLicenseRequestSignature), Return(true)));
|
||||
EXPECT_CALL(*crypto_session_, GetSupportedCertificateTypes(NotNull()));
|
||||
|
||||
// SubLicense session data calls.
|
||||
// TODO(jfore): These calls are being invoked twice each. This should not
|
||||
@@ -381,14 +454,11 @@ TEST_F(SubLicenseTest, VerifySubSessionData) {
|
||||
DoAll(SetArgPointee<1>(true), SetArgPointee<2>(2), Return(true)));
|
||||
|
||||
CreateCdmLicense();
|
||||
// TODO(gmorgan) fix below - no default service certificate
|
||||
//service_cert_.Init(kDefaultServiceCertificate);
|
||||
EXPECT_TRUE(cdm_license_->Init(
|
||||
&service_cert_, kToken, kClientTokenDrmCert, kEmptyString,
|
||||
crypto_session_, policy_engine_));
|
||||
kToken, kClientTokenDrmCert, kEmptyString, true,
|
||||
kDefaultServiceCertificate, crypto_session_, policy_engine_));
|
||||
CdmAppParameterMap app_parameters;
|
||||
CdmKeyMessage signed_request;
|
||||
Properties::set_use_certificates_as_identification(true);
|
||||
std::string server_url;
|
||||
EXPECT_EQ(cdm_license_->PrepareKeyRequest(*init_data_, kLicenseTypeStreaming,
|
||||
app_parameters, &signed_request,
|
||||
@@ -405,7 +475,7 @@ TEST_F(SubLicenseTest, VerifySubSessionData) {
|
||||
for (int i = 0; i < license_request.sub_session_data().size(); ++i) {
|
||||
const video_widevine::LicenseRequest_SubSessionData& sl =
|
||||
license_request.sub_session_data(i);
|
||||
EXPECT_EQ(static_cast<uint32_t>(i), sl.nonce());
|
||||
EXPECT_EQ(static_cast<unsigned>(i), sl.nonce());
|
||||
switch (i) {
|
||||
case 0:
|
||||
EXPECT_EQ(kSubSessionKeyID1, sl.sub_session_key_id());
|
||||
|
||||
Reference in New Issue
Block a user