Merge latest oemcrypto-v17 change

No-Typo-Check: Not related to this change.

Bug: 161477208
Change-Id: I99e4780f6855b7045aa0cd5a49c13d2d0d51ed64
This commit is contained in:
Kyle Zhang
2022-01-21 05:58:12 +00:00
committed by Fred Gylys-Colwell
parent c924960962
commit 642965c678
176 changed files with 301013 additions and 296749 deletions

View File

@@ -54,7 +54,7 @@ class MockWvCdmEventListener : public WvCdmEventListener {
class MockCdmEngineImpl : public CdmEngine {
public:
MockCdmEngineImpl(FileSystem* file_system,
MockCdmEngineImpl(wvutil::FileSystem* file_system,
std::shared_ptr<EngineMetrics> metrics)
: CdmEngine(file_system, metrics) {}
MOCK_METHOD(CdmResponseType, OpenSession,
@@ -114,7 +114,7 @@ class MockCdmEngineImpl : public CdmEngine {
class WvCdmEngineMetricsImplTest : public ::testing::Test {
public:
void SetUp() override {
file_system_.reset(new FileSystem);
file_system_.reset(new wvutil::FileSystem);
std::shared_ptr<EngineMetrics> engine_metrics(new EngineMetrics);
test_cdm_metrics_engine_.reset(
new CdmEngineMetricsImpl<StrictMock<MockCdmEngineImpl>>(
@@ -122,7 +122,7 @@ class WvCdmEngineMetricsImplTest : public ::testing::Test {
}
protected:
std::unique_ptr<FileSystem> file_system_;
std::unique_ptr<wvutil::FileSystem> file_system_;
std::unique_ptr<CdmEngineMetricsImpl<StrictMock<MockCdmEngineImpl>>>
test_cdm_metrics_engine_;
};

View File

@@ -6,13 +6,14 @@
// This is because we need a valid RSA certificate, and will attempt to connect
// to the provisioning server to request one if we don't.
#include "cdm_engine.h"
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <string>
#include "OEMCryptoCENC.h"
#include "cdm_engine.h"
#include "config_test_env.h"
#include "device_files.h"
#include "file_store.h"
@@ -107,7 +108,7 @@ class WvCdmEnginePreProvTest : public WvCdmTestBaseWithEngine {
license_request.GetDrmMessage(http_response, *response);
LOGV("response: size = %zu, string =\n%s\n", response->size(),
Base64SafeEncode(*response).c_str());
wvutil::Base64SafeEncode(*response).c_str());
return true;
}
@@ -169,7 +170,7 @@ class WvCdmEngineTest : public WvCdmEnginePreProvTest {
CdmKeySetId key_set_id;
InitializationData init_data(init_data_type_string, key_id);
if (g_cutoff >= LOG_DEBUG) init_data.DumpToLogs();
if (wvutil::g_cutoff >= wvutil::LOG_DEBUG) init_data.DumpToLogs();
CdmKeyRequest key_request;
@@ -234,8 +235,8 @@ class WvCdmEngineTest : public WvCdmEnginePreProvTest {
LicenseRequest lic_request;
lic_request.GetDrmMessage(response, drm_msg);
LOGV("drm msg: %zu bytes\r\n%s", drm_msg.size(),
HexEncode(reinterpret_cast<const uint8_t*>(drm_msg.data()),
drm_msg.size())
wvutil::HexEncode(reinterpret_cast<const uint8_t*>(drm_msg.data()),
drm_msg.size())
.c_str());
return drm_msg;
}
@@ -291,7 +292,7 @@ class WvCdmEngineTest : public WvCdmEnginePreProvTest {
ASSERT_TRUE(metrics_proto.SerializeToString(&serialized_metrics));
EXPECT_TRUE(has_request_type)
<< "Expected request type " << key_request_type << " was not found. "
<< "metrics: " << wvcdm::b2a_hex(serialized_metrics);
<< "metrics: " << wvutil::b2a_hex(serialized_metrics);
}
std::string server_url_;
@@ -442,7 +443,7 @@ TEST_F(WvCdmEngineTest, ParseDecryptHashStringTest) {
std::vector<uint8_t> binary_hash{0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0xFF};
const std::string test_valid_decoded_hash(binary_hash.begin(),
binary_hash.end());
const std::string test_valid_hash = b2a_hex(binary_hash);
const std::string test_valid_hash = wvutil::b2a_hex(binary_hash);
const std::string test_invalid_hash_string = "sample hash string";
const std::string test_valid_hash_string = test_session_id + kComma +
test_frame_number_string + kComma +

View File

@@ -2,12 +2,13 @@
// source code may only be used and distributed under the Widevine License
// Agreement.
#include <memory>
#include "cdm_session.h"
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "cdm_session.h"
#include <memory>
#include "crypto_key.h"
#include "crypto_wrapped_key.h"
#include "properties.h"
@@ -36,7 +37,7 @@ namespace {
const std::string kEmptyString;
const std::string kToken = a2bs_hex(
const std::string kToken = wvutil::a2bs_hex(
"0AAE02080212107E0A892DEEB021E7AF696B938BB1D5B1188B85AD9D05228E023082010A02"
"82010100DBEDF2BFB0EC98213766E65049B9AB176FA4B1FBFBB2A0C96C87D9F2B895E0ED77"
"93BDA057E6BC3E0CA2348BC6831E03609445CA4D418CB98EAC98FFC87AB2364CE76BA26BEE"
@@ -72,7 +73,7 @@ const std::string kToken = a2bs_hex(
"8CD5A9DF6E3D3A99B806F6D60991358C5BE77117D4F3168F3348E9A048539F892F4D783152"
"C7A8095224AA56B78C5CF7BD1AB1B179C0C0D11E3C3BAC84C141A00191321E3ACC17242E68"
"3C");
const std::string kWrappedKeyData = a2bs_hex(
const std::string kWrappedKeyData = wvutil::a2bs_hex(
"3B84252DD84F1A710365014A114507FFFA3DD404625D61D1EEC7C3A39D72CB8D9318ADE9DA"
"05D69F9776DAFDA49A97BC30E84CA275925DFD98CA04F7DB23465103A224852192DE232902"
"99FF82024F5CCA7716ACA9BE0B56348BA16B9E3136D73789C842CB2ECA4820DDAAF59CCB9B"
@@ -141,8 +142,8 @@ class MockCryptoSession : public TestCryptoSession {
.WillByDefault(
Invoke(this, &MockCryptoSession::BaseHasUsageInfoSupport));
}
MOCK_METHOD(CdmResponseType, GetProvisioningToken, (std::string*),
(override));
MOCK_METHOD(CdmResponseType, GetProvisioningToken,
(std::string*, std::string*), (override));
MOCK_METHOD(CdmClientTokenType, GetPreProvisionTokenType, (), (override));
MOCK_METHOD(CdmSecurityLevel, GetSecurityLevel, (), (override));
MOCK_METHOD(CdmResponseType, Open, (), (override));
@@ -319,7 +320,7 @@ TEST_F(CdmSessionTest, UpdateUsageEntry) {
metrics.crypto_metrics().usage_table_header_update_entry_time_us().size(),
0)
<< "Missing update usage entry metric. Metrics: "
<< wvcdm::b2a_hex(serialized_metrics);
<< wvutil::b2a_hex(serialized_metrics);
}
} // namespace wvcdm

View File

@@ -16,34 +16,34 @@
namespace {
const std::string kSignedDeviceCertificate = wvcdm::a2bs_hex(
const std::string kSignedDeviceCertificate = wvutil::a2bs_hex(
"0A3D0802121B7769646576696E655F746573745F73657269616C5F6E756D62657218C09A0C"
"28D2093A11746573742E7769646576696E652E636F6D6080B51812097369676E617475726"
"5");
const std::string kSignedDeviceCertificateCreationTimeUnlimited =
wvcdm::a2bs_hex(
wvutil::a2bs_hex(
"0A370802121B7769646576696E655F746573745F73657269616C5F6E756D6265721800"
"28D2093A11746573742E7769646576696E652E636F6D12097369676E6174757265");
const std::string kSignedDeviceCertificateExpirationTimeInvalid =
wvcdm::a2bs_hex(
wvutil::a2bs_hex(
"0A390802121B7769646576696E655F746573745F73657269616C5F6E756D62657218C0"
"9A0C28D2093A11746573742E7769646576696E652E636F6D12097369676E617475726"
"5");
const std::string kSignedDeviceCertificateExpirationTimeUnlimited =
wvcdm::a2bs_hex(
wvutil::a2bs_hex(
"0A3B0802121B7769646576696E655F746573745F73657269616C5F6E756D62657218C0"
"9A0C28D2093A11746573742E7769646576696E652E636F6D600012097369676E617475"
"7265");
const std::string kSignedDeviceCertificateInvalid = wvcdm::a2bs_hex(
const std::string kSignedDeviceCertificateInvalid = wvutil::a2bs_hex(
"76340802121B7769646576696E655F746573745F73657269616C5F6E756D62657228D2093A"
"11746573742E7769646576696E652E636F6D12097369676E6174757265");
const std::string kSignedDeviceCertificateInvalidCertificateType =
wvcdm::a2bs_hex(
wvutil::a2bs_hex(
"0A350801121B7769646576696E655F746573745F73657269616C5F6E756D62657228D2"
"093A11746573742E7769646576696E652E636F6D12097369676E6174757265");
const std::string kSignedDeviceCertificateNoDrmCertificate =
wvcdm::a2bs_hex("12097369676E6174757265");
const std::string kSignedDeviceCertificateTimesInvalid = wvcdm::a2bs_hex(
wvutil::a2bs_hex("12097369676E6174757265");
const std::string kSignedDeviceCertificateTimesInvalid = wvutil::a2bs_hex(
"0A350802121B7769646576696E655F746573745F73657269616C5F6E756D62657228D2093A"
"11746573742E7769646576696E652E636F6D12097369676E6174757265");
const int64_t kCreationTime = 200000;

View File

@@ -3,6 +3,7 @@
// Agreement.
#include "config_test_env.h"
#include "string_conversions.h"
// Holds the data needed to talk to the various provisioning and
@@ -344,21 +345,21 @@ void ConfigTestEnv::Init(ServerConfigurationId server_id) {
renewal_server_.clear();
provisioning_server_ = license_servers[server_id].provisioning_server_url;
license_service_certificate_ =
a2bs_hex(license_servers[server_id].license_service_certificate);
provisioning_service_certificate_ =
a2bs_hex(license_servers[server_id].provisioning_service_certificate);
wvutil::a2bs_hex(license_servers[server_id].license_service_certificate);
provisioning_service_certificate_ = wvutil::a2bs_hex(
license_servers[server_id].provisioning_service_certificate);
}
const CdmInitData ConfigTestEnv::GetInitData(ContentId content_id) {
switch (content_id) {
case kContentIdStreaming:
return wvcdm::a2bs_hex(kCpKeyId);
return wvutil::a2bs_hex(kCpKeyId);
case kContentIdOffline:
return wvcdm::a2bs_hex(kCpOfflineKeyId);
return wvutil::a2bs_hex(kCpOfflineKeyId);
case kContentIdStagingSrmOuputProtectionRequested:
return wvcdm::a2bs_hex(kCpStagingSrmOuputProtectionRequested);
return wvutil::a2bs_hex(kCpStagingSrmOuputProtectionRequested);
case kContentIdStagingSrmOuputProtectionRequired:
return wvcdm::a2bs_hex(kCpStagingSrmOuputProtectionRequired);
return wvutil::a2bs_hex(kCpStagingSrmOuputProtectionRequired);
default:
return kEmptyData;
}
@@ -381,7 +382,7 @@ const std::string& ConfigTestEnv::GetLicenseServerUrl(
}
std::string ConfigTestEnv::QAProvisioningServiceCertificate() {
return a2bs_hex(kCpQAProvisioningServiceCertificate);
return wvutil::a2bs_hex(kCpQAProvisioningServiceCertificate);
}
} // namespace wvcdm

View File

@@ -322,8 +322,8 @@ TEST_F(CryptoSessionMetricsTest, OpenSessionValidMetrics) {
if (token_type == kClientTokenKeybox) {
const uint32_t expected_system_id = FindKeyboxSystemID();
const uint32_t recorded_system_id =
metrics_proto.crypto_session_system_id().int_value();
const uint32_t recorded_system_id = static_cast<uint32_t>(
metrics_proto.crypto_session_system_id().int_value());
EXPECT_EQ(expected_system_id, recorded_system_id);
EXPECT_EQ(OEMCrypto_Keybox,
metrics_proto.oemcrypto_provisioning_method().int_value());
@@ -366,8 +366,10 @@ TEST_F(CryptoSessionMetricsTest, GetProvisioningTokenValidMetrics) {
// DRM Certificate provisioning method does not support a provisioning
// token. Otherwise, we should be able to fetch the token.
std::string token;
std::string additional_token;
if (token_type != kClientTokenDrmCert) {
ASSERT_EQ(NO_ERROR, session->GetProvisioningToken(&token));
ASSERT_EQ(NO_ERROR,
session->GetProvisioningToken(&token, &additional_token));
}
drm_metrics::WvCdmMetrics::CryptoMetrics metrics_proto;
@@ -378,8 +380,8 @@ TEST_F(CryptoSessionMetricsTest, GetProvisioningTokenValidMetrics) {
EXPECT_EQ(1, metrics_proto.crypto_session_get_token(0).count());
const uint32_t expected_system_id = FindKeyboxSystemID();
const uint32_t recorded_system_id =
metrics_proto.crypto_session_system_id().int_value();
const uint32_t recorded_system_id = static_cast<uint32_t>(
metrics_proto.crypto_session_system_id().int_value());
EXPECT_EQ(expected_system_id, recorded_system_id);
if (recorded_system_id != kNullSystemId) {
EXPECT_EQ(1, metrics_proto.oemcrypto_get_key_data_time_us().size());

View File

@@ -24,10 +24,17 @@
namespace wvcdm {
namespace {
using wvutil::a2bs_hex;
using wvutil::ArraySize;
using wvutil::b2a_hex;
using wvutil::CdmRandom;
using wvutil::File;
using wvutil::FileSystem;
const uint32_t kCertificateLen = 700;
const uint32_t kWrappedKeyLen = 500;
constexpr size_t kZero = 0;
const std::string kOemCertificate = "an oem certificate";
const std::string kDrmCertificate = "a drm certificate";
const std::string kAnotherDrmCertificate = "another drm certificate";
const std::string kWrappedPrivateKey = "a wrapped private key";
@@ -3742,6 +3749,12 @@ const std::vector<std::string> kHashedUsageInfoFileWithSingleKeySetList = {
const std::vector<std::string> kHashedUsageInfoFileKeySetList = {
"key_set_id_1", "key_set_id_2", "key_set_id_3"};
// Contains kOemCertificate and kCryptoWrappedKey
const std::string kFakeOemCertificateFile = a2bs_hex(
"0A33080710014A2D0A12616E206F656D206365727469666963617465121561207772617070"
"65642070726976617465206B6579180012201C910430EBCEDD66BF0FBFE52917A71C6B66D5"
"DF1E01EA43D3A375B0703E1E1B");
class MockFile : public File {
public:
MockFile() {}
@@ -3751,7 +3764,7 @@ class MockFile : public File {
MOCK_METHOD(ssize_t, Write, (const char*, size_t), (override));
};
class MockFileSystem : public FileSystem {
class MockFileSystem : public wvutil::FileSystem {
public:
MockFileSystem() {}
~MockFileSystem() override {}
@@ -3856,7 +3869,7 @@ class DeviceFilesDeleteMultipleUsageInfoTest
: public DeviceFilesTest,
public ::testing::WithParamInterface<int> {};
MATCHER(IsCreateFileFlagSet, "") { return FileSystem::kCreate & arg; }
MATCHER(IsCreateFileFlagSet, "") { return wvutil::FileSystem::kCreate & arg; }
MATCHER_P(StrAndLenEq, str, "") {
const std::string data(std::get<0>(arg), std::get<1>(arg));
return data == str;
@@ -5008,7 +5021,7 @@ TEST_P(DeviceFilesDeleteMultipleUsageInfoTest, DeleteAllButOne) {
// File read expectations.
MockFile* file_in = new MockFile();
EXPECT_CALL(file_system, Open(file_path, FileSystem::kReadOnly))
EXPECT_CALL(file_system, Open(file_path, wvutil::FileSystem::kReadOnly))
.WillOnce(Return(ByMove(std::unique_ptr<File>(file_in))));
Expectation read_original =
EXPECT_CALL(*file_in, Read(NotNull(), _))
@@ -5020,8 +5033,8 @@ TEST_P(DeviceFilesDeleteMultipleUsageInfoTest, DeleteAllButOne) {
// File write expectations.
MockFile* file_out = new MockFile();
EXPECT_CALL(file_system,
Open(file_path, FileSystem::kCreate | FileSystem::kTruncate))
EXPECT_CALL(file_system, Open(file_path, wvutil::FileSystem::kCreate |
wvutil::FileSystem::kTruncate))
.WillOnce(Return(ByMove(std::unique_ptr<File>(file_out))));
EXPECT_CALL(*file_out, Write(StrEq(result_hashed_usage_info_file), _))
.After(read_original)
@@ -5062,7 +5075,7 @@ TEST_F(DeviceFilesDeleteMultipleUsageInfoTest, DeleteAllKeySetIds) {
EXPECT_CALL(file_system, Exists(_)).WillRepeatedly(Return(true));
EXPECT_CALL(file_system, FileSize(file_path))
.WillOnce(Return(kHashedUsageInfoFileWithThreeKeySetIds.size()));
EXPECT_CALL(file_system, Open(file_path, FileSystem::kReadOnly))
EXPECT_CALL(file_system, Open(file_path, wvutil::FileSystem::kReadOnly))
.WillOnce(Return(ByMove(std::unique_ptr<File>(file_in))));
EXPECT_CALL(*file_in, Read(NotNull(), _))
.WillOnce(DoAll(
@@ -5099,7 +5112,7 @@ TEST_F(DeviceFilesDeleteMultipleUsageInfoTest, DeleteNone) {
MockFile* file_in = new MockFile();
EXPECT_CALL(file_system, FileSize(file_path))
.WillOnce(Return(kHashedUsageInfoFileWithThreeKeySetIds.size()));
EXPECT_CALL(file_system, Open(file_path, FileSystem::kReadOnly))
EXPECT_CALL(file_system, Open(file_path, wvutil::FileSystem::kReadOnly))
.WillOnce(Return(ByMove(std::unique_ptr<File>(file_in))));
EXPECT_CALL(*file_in, Read(NotNull(), _))
.WillOnce(DoAll(
@@ -5135,7 +5148,7 @@ TEST_F(DeviceFilesDeleteMultipleUsageInfoTest, DeleteOne) {
// File read expectations.
MockFile* file_in = new MockFile();
EXPECT_CALL(file_system, Open(file_path, FileSystem::kReadOnly))
EXPECT_CALL(file_system, Open(file_path, wvutil::FileSystem::kReadOnly))
.WillOnce(Return(ByMove(std::unique_ptr<File>(file_in))));
Expectation read_original =
EXPECT_CALL(*file_in, Read(NotNull(), _))
@@ -5146,8 +5159,8 @@ TEST_F(DeviceFilesDeleteMultipleUsageInfoTest, DeleteOne) {
// File write expectations.
MockFile* file_out = new MockFile();
EXPECT_CALL(file_system,
Open(file_path, FileSystem::kCreate | FileSystem::kTruncate))
EXPECT_CALL(file_system, Open(file_path, wvutil::FileSystem::kCreate |
wvutil::FileSystem::kTruncate))
.WillOnce(Return(ByMove(std::unique_ptr<File>(file_out))));
EXPECT_CALL(*file_out, Write(StrEq(kHashedUsageInfoFileWithKeySet1), _))
.After(read_original)
@@ -5186,7 +5199,7 @@ TEST_F(DeviceFilesDeleteMultipleUsageInfoTest, BadFile) {
EXPECT_CALL(file_system, Exists(_)).WillRepeatedly(Return(true));
EXPECT_CALL(file_system, FileSize(file_path))
.WillOnce(Return(kHashlessUsageInfoFile.size()));
EXPECT_CALL(file_system, Open(file_path, FileSystem::kReadOnly))
EXPECT_CALL(file_system, Open(file_path, wvutil::FileSystem::kReadOnly))
.WillOnce(Return(ByMove(std::unique_ptr<File>(file_in))));
EXPECT_CALL(*file_in, Read(NotNull(), _))
.WillOnce(DoAll(SetArrayArgument<0>(kHashlessUsageInfoFile.cbegin(),
@@ -5697,7 +5710,8 @@ TEST_P(DeviceFilesHlsAttributesTest, Read) {
ASSERT_TRUE(device_files.RetrieveHlsAttributes(param->key_set_id, &method,
&media_segment_iv));
EXPECT_EQ(param->method, method);
EXPECT_EQ(b2a_hex(param->media_segment_iv), b2a_hex(media_segment_iv));
EXPECT_EQ(b2a_hex(param->media_segment_iv),
wvutil::b2a_hex(media_segment_iv));
}
TEST_P(DeviceFilesHlsAttributesTest, Store) {
@@ -5863,4 +5877,160 @@ TEST_F(DeviceFilesUsageTableTest, ReadWithoutLruData) {
EXPECT_TRUE(lru_upgrade);
}
TEST_F(DeviceFilesTest, StoreOemCertificateSuccess) {
MockFileSystem file_system;
const std::string oem_certificate_path =
device_base_path_ + wvutil::kOemCertificateFileName;
// Call to Open will return a unique_ptr, freeing this object.
MockFile* file = new MockFile();
EXPECT_CALL(file_system,
Open(StrEq(oem_certificate_path), IsCreateFileFlagSet()))
.WillOnce(Return(ByMove(std::unique_ptr<File>(file))));
EXPECT_CALL(*file, Write(_, _))
.With(AllArgs(StrAndLenContains(
std::vector<std::string>{kOemCertificate, kCryptoWrappedKey.key()})))
.WillOnce(ReturnArg<1>());
EXPECT_CALL(*file, Read(_, _)).Times(0);
DeviceFiles device_files(&file_system);
ASSERT_TRUE(device_files.Init(kSecurityLevelL1));
EXPECT_TRUE(
device_files.StoreOemCertificate(kOemCertificate, kCryptoWrappedKey));
}
TEST_F(DeviceFilesTest, StoreOemCertificateEmptyCertFail) {
MockFileSystem file_system;
const CryptoWrappedKey private_key(CryptoWrappedKey::kRsa,
CdmRandom::RandomData(kWrappedKeyLen));
EXPECT_CALL(file_system, Open(_, _)).Times(0);
DeviceFiles device_files(&file_system);
ASSERT_TRUE(device_files.Init(kSecurityLevelL1));
EXPECT_FALSE(
device_files.StoreOemCertificate(/*certificate=*/"", private_key));
}
TEST_F(DeviceFilesTest, StoreOemCertificateUninitializedKeyTypeFail) {
MockFileSystem file_system;
const std::string& certificate = "fake_oem_cert";
const CryptoWrappedKey private_key(CryptoWrappedKey::kUninitialized,
CdmRandom::RandomData(kWrappedKeyLen));
EXPECT_CALL(file_system, Open(_, _)).Times(0);
DeviceFiles device_files(&file_system);
ASSERT_TRUE(device_files.Init(kSecurityLevelL1));
EXPECT_FALSE(device_files.StoreOemCertificate(certificate, private_key));
}
TEST_F(DeviceFilesTest, StoreOemCertificateEmptyKeyFail) {
MockFileSystem file_system;
const std::string& certificate = "fake_oem_cert";
const CryptoWrappedKey private_key(CryptoWrappedKey::kRsa, "");
EXPECT_CALL(file_system, Open(_, _)).Times(0);
DeviceFiles device_files(&file_system);
ASSERT_TRUE(device_files.Init(kSecurityLevelL1));
EXPECT_FALSE(device_files.StoreOemCertificate(certificate, private_key));
}
TEST_F(DeviceFilesTest, HasOemCertificate) {
MockFileSystem file_system;
const std::string device_certificate_path =
device_base_path_ + wvutil::kOemCertificateFileName;
EXPECT_CALL(file_system, Exists(StrEq(device_certificate_path)))
.Times(AtLeast(1))
.WillRepeatedly(Return(true));
DeviceFiles device_files(&file_system);
ASSERT_TRUE(device_files.Init(kSecurityLevelL1));
EXPECT_TRUE(device_files.HasOemCertificate());
}
TEST_F(DeviceFilesTest, HasNoOemCertificate) {
MockFileSystem file_system;
const std::string device_certificate_path =
device_base_path_ + wvutil::kOemCertificateFileName;
EXPECT_CALL(file_system, Exists(StrEq(device_certificate_path)))
.Times(AtLeast(1))
.WillRepeatedly(Return(false));
DeviceFiles device_files(&file_system);
ASSERT_TRUE(device_files.Init(kSecurityLevelL1));
EXPECT_FALSE(device_files.HasOemCertificate());
}
TEST_F(DeviceFilesTest, RetrieveOemCertificateSuccess) {
MockFileSystem file_system;
const std::string device_certificate_path =
device_base_path_ + wvutil::kOemCertificateFileName;
// Call to Open will return a unique_ptr, freeing this object.
MockFile* read_file = new MockFile();
EXPECT_CALL(file_system, Exists(StrEq(device_certificate_path)))
.Times(AtLeast(1))
.WillRepeatedly(Return(true));
EXPECT_CALL(file_system, FileSize(StrEq(device_certificate_path)))
.WillOnce(Return(kFakeOemCertificateFile.size()));
EXPECT_CALL(file_system, Open(StrEq(device_certificate_path), _))
.WillOnce(Return(ByMove(std::unique_ptr<File>(read_file))));
EXPECT_CALL(*read_file, Read(NotNull(), Eq(kFakeOemCertificateFile.size())))
.WillOnce(DoAll(SetArrayArgument<0>(kFakeOemCertificateFile.begin(),
kFakeOemCertificateFile.end()),
Return(kFakeOemCertificateFile.size())));
EXPECT_CALL(*read_file, Write(_, _)).Times(0);
DeviceFiles device_files(&file_system);
EXPECT_TRUE(device_files.Init(kSecurityLevelL1));
std::string certificate;
CryptoWrappedKey private_key;
ASSERT_EQ(device_files.RetrieveOemCertificate(&certificate, &private_key),
DeviceFiles::kCertificateValid);
EXPECT_EQ(certificate, kOemCertificate);
EXPECT_EQ(private_key, kCryptoWrappedKey);
}
TEST_F(DeviceFilesTest, RetrieveOemCertificateRandomCertFail) {
MockFileSystem file_system;
const std::string device_certificate_path =
device_base_path_ + wvutil::kOemCertificateFileName;
std::string ramdom_cert = "random_cert";
// Call to Open will return a unique_ptr, freeing this object.
MockFile* read_file = new MockFile();
EXPECT_CALL(file_system, Exists(StrEq(device_certificate_path)))
.Times(AtLeast(1))
.WillRepeatedly(Return(true));
EXPECT_CALL(file_system, FileSize(StrEq(device_certificate_path)))
.WillOnce(Return(ramdom_cert.size()));
EXPECT_CALL(file_system, Open(StrEq(device_certificate_path), _))
.WillOnce(Return(ByMove(std::unique_ptr<File>(read_file))));
EXPECT_CALL(*read_file, Read(NotNull(), Eq(ramdom_cert.size())))
.WillOnce(
DoAll(SetArrayArgument<0>(ramdom_cert.begin(), ramdom_cert.end()),
Return(ramdom_cert.size())));
EXPECT_CALL(*read_file, Write(_, _)).Times(0);
DeviceFiles device_files(&file_system);
EXPECT_TRUE(device_files.Init(kSecurityLevelL1));
std::string certificate;
CryptoWrappedKey private_key;
EXPECT_EQ(device_files.RetrieveOemCertificate(&certificate, &private_key),
DeviceFiles::kCertificateNotFound);
}
TEST_F(DeviceFilesTest, RetrieveOemCertificateNotFoundFail) {
MockFileSystem file_system;
const std::string device_certificate_path =
device_base_path_ + wvutil::kOemCertificateFileName;
EXPECT_CALL(file_system, Exists(StrEq(device_certificate_path)))
.Times(AtLeast(1))
.WillRepeatedly(Return(false));
DeviceFiles device_files(&file_system);
EXPECT_TRUE(device_files.Init(kSecurityLevelL1));
std::string certificate;
CryptoWrappedKey private_key;
EXPECT_EQ(device_files.RetrieveOemCertificate(&certificate, &private_key),
DeviceFiles::kCertificateNotFound);
}
} // namespace wvcdm

View File

@@ -6,15 +6,14 @@
// would, but in parallel, attempting to create as many collisions in the CDM
// code as possible.
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <inttypes.h>
#include <algorithm>
#include <string>
#include <vector>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "cdm_engine.h"
#include "clock.h"
#include "config_test_env.h"
@@ -83,6 +82,7 @@ const RenewalPolicy kLDLRenewal = {"CDM_LimitedDurationLicense_renewal", 0, 0};
const RenewalPolicy kInfiniteRenewal = {"CDM_InfiniteRenewal_renewal", 0, 0};
const RenewalPolicy kLicenseDurationWithRenewal = {
"CDM_LicenseDurationWithRenewal_renewal", 10, 0};
const RenewalPolicy kHeartbeatRenewal = {"CDM_Heartbeat_renewal", 10, 30};
// Key ID in all duration tests.
const KeyId kKeyId = "Duration_Key====";
@@ -162,7 +162,7 @@ class CdmDurationTest : public WvCdmTestBaseWithEngine,
license_type_ = kLicenseTypeStreaming;
}
// All times in the license are relative to the rental clock.
start_of_rental_clock_ = wvcdm::Clock().GetCurrentTime();
start_of_rental_clock_ = wvutil::Clock().GetCurrentTime();
FetchLicense();
}
@@ -172,7 +172,7 @@ class CdmDurationTest : public WvCdmTestBaseWithEngine,
// these tests took over three hours. If we want to improve that, we need to
// track these times.
static uint64_t first_time = start_of_rental_clock_;
uint64_t delta = wvcdm::Clock().GetCurrentTime() - first_time;
uint64_t delta = wvutil::Clock().GetCurrentTime() - first_time;
uint64_t sec = delta % 60;
delta = delta / 60;
uint64_t min = delta % 60;
@@ -209,7 +209,7 @@ class CdmDurationTest : public WvCdmTestBaseWithEngine,
if (desired_rental_time >= rental_time) {
const unsigned int sleep_time =
static_cast<unsigned int>(desired_rental_time - rental_time);
TestSleep::Sleep(sleep_time);
wvutil::TestSleep::Sleep(sleep_time);
} else {
LOGW("Test Clock skew sleeping from rental clock time %" PRIu64
" to %" PRIu64,
@@ -219,7 +219,7 @@ class CdmDurationTest : public WvCdmTestBaseWithEngine,
}
uint64_t CurrentRentalTime() {
const uint64_t now = wvcdm::Clock().GetCurrentTime();
const uint64_t now = wvutil::Clock().GetCurrentTime();
return now - start_of_rental_clock_;
}
@@ -1235,7 +1235,7 @@ TEST_P(CdmUseCase_LicenseWithRenewal, Case3) {
RenewAndTerminate(start, load_time, cutoff, kShortRenewal);
}
// We are late requesting the renewal.
TestSleep::Sleep(kRoundTripTime);
wvutil::TestSleep::Sleep(kRoundTripTime);
// But after we request the renewal, we should be able to start playing again.
{
RequestRenewal(kShortRenewal);
@@ -1439,7 +1439,7 @@ TEST_P(CdmUseCase_LicenseWithRenewalPlayback, Case3) {
RenewAndTerminate(start, load_time, cutoff, kShortRenewal);
}
// We are late requesting the renewal.
TestSleep::Sleep(kRoundTripTime);
wvutil::TestSleep::Sleep(kRoundTripTime);
// But after we request the renewal, we should be able to start playing again.
{
RequestRenewal(kShortRenewal);
@@ -1649,6 +1649,85 @@ TEST_P(CdmUseCase_LimitedDurationLicense, Case5) {
FailDecrypt();
}
// Renewal loaded before playback starts.
TEST_P(CdmUseCase_LimitedDurationLicense, Case6) {
LoadLicense();
RequestRenewal(kLDLRenewal);
LoadRenewal(start_of_playback_ - 2 * kFudge, kLDLRenewal);
const uint64_t end_of_play = renewal_load_time_ + kPlayDuration;
AllowPlayback(start_of_playback_, end_of_play);
}
// Heartbeat Playback Window License. (See above for notes on Use Case tests).
// This is similar to the renewal, but the renewal recovery is larger than the
// renewal delay.
class CdmUseCase_Heartbeat : public RenewalTest {
public:
CdmUseCase_Heartbeat() : RenewalTest("CDM_Heartbeat") {
timer_limits_.rental_duration_seconds = 0;
initial_policy_.renewal_delay = 10u;
initial_policy_.renewal_recovery_duration = 30u;
timer_limits_.initial_renewal_duration_seconds =
initial_policy_.renewal_delay +
initial_policy_.renewal_recovery_duration;
}
void SetUp() override {
RenewalTest::SetUp();
const uint64_t next_renewal =
start_of_playback_ + initial_policy_.renewal_delay;
// Allow playback within the initial renewal window.
SleepUntil(start_of_playback_);
LoadLicense();
// Play until just before we expect a renewal to be generated.
current_cutoff_ = next_renewal + initial_policy_.renewal_recovery_duration;
AllowPlayback(start_of_playback_, next_renewal);
}
protected:
RenewalPolicy initial_policy_;
};
// Playback within rental duration and renewal duration.
TEST_P(CdmUseCase_Heartbeat, Case1) {
for (int i = 0; i < 4; i++) {
SleepUntilRenewalNeeded();
RequestRenewal(kHeartbeatRenewal);
const uint64_t start = CurrentRentalTime();
const uint64_t load_time = start + kRoundTripTime;
const uint64_t stop = load_time + kHeartbeatRenewal.renewal_delay;
RenewAndContinue(start, load_time, stop, kHeartbeatRenewal);
}
}
// Playback within rental duration, last playback attempt exceeds renewal
// duration.
TEST_P(CdmUseCase_Heartbeat, Case2) {
for (int i = 0; i < 4; i++) {
SleepUntilRenewalNeeded();
RequestRenewal(kHeartbeatRenewal);
const uint64_t start = CurrentRentalTime();
const uint64_t load_time = start + kRoundTripTime;
const uint64_t stop = load_time + kHeartbeatRenewal.renewal_delay;
RenewAndContinue(start, load_time, stop, kHeartbeatRenewal);
}
// We attempt to continue playing beyond the renewal cutoff.
SleepUntilRenewalNeeded();
RequestRenewal(kHeartbeatRenewal);
const uint64_t start = CurrentRentalTime();
const uint64_t load_time = start + kRoundTripTime;
// For v16 and beyond, we restart the renewal timer when the renewal was
// loaded. For v15 and earlier, we restart the renewal when the renewal was
// granted, which is close to when the renewal was requested.
const uint64_t timer_start =
(wvoec::global_features.api_version < wvoec::kCoreMessagesAPI)
? start
: load_time;
const uint64_t cutoff = timer_start + kHeartbeatRenewal.renewal_delay +
kHeartbeatRenewal.renewal_recovery_duration;
RenewAndTerminate(start, load_time, cutoff, kHeartbeatRenewal);
}
/*****************************************************************************/
// The unlimited streaming case has no limits on license use. This use case is
// not in the documentation because it is not recommended.
@@ -1826,5 +1905,7 @@ INSTANTIATE_TEST_SUITE_P(Both, CdmUseCase_LicenseDuration,
::testing::Values(false, true));
INSTANTIATE_TEST_SUITE_P(Both, CdmUseCase_LicenseDurationWithRenewal,
::testing::Values(false, true));
INSTANTIATE_TEST_SUITE_P(Both, CdmUseCase_Heartbeat,
::testing::Values(false, true));
} // namespace wvcdm

View File

@@ -10,7 +10,7 @@
#include "crypto_session.h"
#include "license_protocol.pb.h"
#include "log.h"
#include "oec_session_util.h"
#include "oec_key_deriver.h"
#include "oec_test_data.h"
#include "privacy_crypto.h"
#include "service_certificate.h"
@@ -34,7 +34,7 @@ namespace {
// This is a sample RSA private key, it pairs with the public fake service
// certificate below.
// From file test_rsa_key_2_carmichael.pk8 in team shared drive. Size is 1216.
const std::string kPrivateKeyFakeServiceCert = a2bs_hex(
const std::string kPrivateKeyFakeServiceCert = wvutil::a2bs_hex(
"308204bc020100300d06092a864886f70d0101010500048204a6308204a2020100028201"
"0100a700366065dcbd545a2a40b4e1159458114f9458dddea71f3c2ce08809296157675e"
"567eee278f59349a2aaa9db44efaa76ad4c97a53c14e9fe334f73db7c910474f28da3fce"
@@ -73,7 +73,7 @@ const std::string kPrivateKeyFakeServiceCert = a2bs_hex(
// This is a fake service certificate.
// From the team shared drive file
// oem-7913-leaf-and-intermediate-certs-test-key-2-carmichael.p7b, size 2353.
const std::string kPublicFakeServiceCert = a2bs_hex(
const std::string kPublicFakeServiceCert = wvutil::a2bs_hex(
"3082092d06092a864886f70d010702a082091e3082091a0201013100300f06092a864886"
"f70d010701a0020400a08208fe3082037130820259a003020102021100c28d2022828b9e"
"639d15892ca98fd95d300d06092a864886f70d01010b0500306b310b3009060355040613"
@@ -142,7 +142,7 @@ const std::string kPublicFakeServiceCert = a2bs_hex(
"30eb823b06ab3c397dd0683100");
// This is a private RSA key that is paired with the DRM certificate below.
const std::string kPrivateKeySampleDRMCert = a2bs_hex(
const std::string kPrivateKeySampleDRMCert = wvutil::a2bs_hex(
"308204BC020100300D06092A864886F70D0101010500048204A6308204A202010002820101"
"00E68EAD7C67ED983A72C89BC55054D26821C3399702E7906B77C7E09AE607D40B0013484B"
"0C557A810E19A814B4F14D55E60456EE21BC19F29EFFDA416BC9CBF0CE2C684E5A44F77008"
@@ -179,7 +179,7 @@ const std::string kPrivateKeySampleDRMCert = a2bs_hex(
// This is a DRM certificate that was intercepted from a provisioning response
// from the production server to a device with the test keybox.
const std::string kPublicSampleDRMCert = a2bs_hex(
const std::string kPublicSampleDRMCert = wvutil::a2bs_hex(
"0ABC02080212107CB49F987A635E1E0A52184694582D6E18A2C99EEC05228E023082010A02"
"82010100E68EAD7C67ED983A72C89BC55054D26821C3399702E7906B77C7E09AE607D40B00"
"13484B0C557A810E19A814B4F14D55E60456EE21BC19F29EFFDA416BC9CBF0CE2C684E5A44"
@@ -333,6 +333,7 @@ bool FakeProvisioningServer::MakeResponse(
}
std::string core_response;
oemcrypto_core_message::serialize::CreateCoreProvisioningResponseFromProto(
oemcrypto_core_message::features::CoreMessageFeatures::kDefaultFeatures,
message, core_request_data, &core_response);
signed_response.set_oemcrypto_core_message(core_response);
// Also, the signature should be over the concatenation of the core message
@@ -355,7 +356,7 @@ bool FakeProvisioningServer::MakeResponse(
static const std::string kJsonStart = "{ \"signedResponse\": \"";
static const std::string kJsonEnd = "\" }";
*json_response = kJsonStart;
json_response->append(Base64SafeEncode(response_data));
json_response->append(wvutil::Base64SafeEncode(response_data));
json_response->append(kJsonEnd);
return true;
}

View File

@@ -45,7 +45,7 @@ const std::string kJsonKeyIds = "key_ids";
const uint32_t kFourCcCbc1 = 0x63626331;
const uint32_t kFourCcCbcs = 0x63626373;
const std::string kWidevinePssh = a2bs_hex(
const std::string kWidevinePssh = wvutil::a2bs_hex(
// Widevine PSSH box
"00000042" // atom size
"70737368" // atom type="pssh"
@@ -55,7 +55,7 @@ const std::string kWidevinePssh = a2bs_hex(
// data:
"08011a0d7769646576696e655f74657374220f73747265616d696e675f636c697031");
const std::string kWidevinePsshFirst = a2bs_hex(
const std::string kWidevinePsshFirst = wvutil::a2bs_hex(
// first PSSH box, Widevine
"00000042" // atom size
"70737368" // atom type "pssh"
@@ -74,7 +74,7 @@ const std::string kWidevinePsshFirst = a2bs_hex(
// arbitrary data:
"0102030405060708");
const std::string kWidevinePsshAfterV0Pssh = a2bs_hex(
const std::string kWidevinePsshAfterV0Pssh = wvutil::a2bs_hex(
// first PSSH box, Playready [1]
"00000028" // atom size
"70737368" // atom type "pssh"
@@ -93,7 +93,7 @@ const std::string kWidevinePsshAfterV0Pssh = a2bs_hex(
// data:
"08011a0d7769646576696e655f74657374220f73747265616d696e675f636c697031");
const std::string kWidevinePsshAfterNonZeroFlags = a2bs_hex(
const std::string kWidevinePsshAfterNonZeroFlags = wvutil::a2bs_hex(
// first PSSH box, Playready [1]
"00000028" // atom size
"70737368" // atom type "pssh"
@@ -112,7 +112,7 @@ const std::string kWidevinePsshAfterNonZeroFlags = a2bs_hex(
// data:
"08011a0d7769646576696e655f74657374220f73747265616d696e675f636c697031");
const std::string kWidevinePsshAfterV1Pssh = a2bs_hex(
const std::string kWidevinePsshAfterV1Pssh = wvutil::a2bs_hex(
// first PSSH box, generic CENC [2]
"00000044" // atom size
"70737368" // atom type "pssh"
@@ -132,7 +132,7 @@ const std::string kWidevinePsshAfterV1Pssh = a2bs_hex(
// data:
"08011a0d7769646576696e655f74657374220f73747265616d696e675f636c697031");
const std::string kWidevineV1Pssh = a2bs_hex(
const std::string kWidevineV1Pssh = wvutil::a2bs_hex(
// Widevine PSSH box, v1 format
"00000066" // atom size
"70737368" // atom type "pssh"
@@ -145,7 +145,7 @@ const std::string kWidevineV1Pssh = a2bs_hex(
// data:
"08011a0d7769646576696e655f74657374220f73747265616d696e675f636c697031");
const std::string kOtherBoxFirst = a2bs_hex(
const std::string kOtherBoxFirst = wvutil::a2bs_hex(
// first box, not a PSSH box
"00000018" // atom size
"77686174" // atom type "what"
@@ -160,7 +160,7 @@ const std::string kOtherBoxFirst = a2bs_hex(
// data:
"08011a0d7769646576696e655f74657374220f73747265616d696e675f636c697031");
const std::string kZeroSizedPsshBox = a2bs_hex(
const std::string kZeroSizedPsshBox = wvutil::a2bs_hex(
// Widevine PSSH box
"00000000" // atom size (whole buffer)
"70737368" // atom type="pssh"
@@ -170,7 +170,7 @@ const std::string kZeroSizedPsshBox = a2bs_hex(
// data:
"08011a0d7769646576696e655f74657374220f73747265616d696e675f636c697031");
const std::string kMultipleWidevinePsshBox = a2bs_hex(
const std::string kMultipleWidevinePsshBox = wvutil::a2bs_hex(
// first PSSH box, Widevine with single keys
"00000042" // atom size
"70737368" // atom type "pssh"
@@ -219,9 +219,9 @@ const std::string kMultipleWidevinePsshBox = a2bs_hex(
"d543101cc842bbec2d0b30");
// These are the data payloads of the two PSSH boxes in
// kMultipleWidevinePsshBox.
const CdmInitData kSingleKeyWidevinePsshBoxData = a2bs_hex(
const CdmInitData kSingleKeyWidevinePsshBoxData = wvutil::a2bs_hex(
"08011a0d7769646576696e655f74657374220f73747265616d696e675f636c697031");
const CdmInitData kEntitledKeysWidevinePsshBoxData = a2bs_hex(
const CdmInitData kEntitledKeysWidevinePsshBoxData = wvutil::a2bs_hex(
"220b47726f7570563254657374381448"
"e3dc959b065002580272580a10668093"
"381a8c5be48a0168ce372726ac1210c8"
@@ -342,7 +342,7 @@ std::string GenerateHlsUriData(const std::string& provider,
const std::string& content_id,
const std::vector<std::string>& key_ids) {
const std::string json = GenerateJsonInitData(provider, content_id, key_ids);
return kHlsTestUriDataFormat + Base64Encode(json);
return kHlsTestUriDataFormat + wvutil::Base64Encode(json);
}
std::string CreateHlsAttributeList(const std::string& method,
@@ -644,7 +644,7 @@ TEST_P(HlsHexAttributeExtractionTest, ExtractHexAttribute) {
if (param.success_) {
EXPECT_TRUE(InitializationData::ExtractHexAttribute(param.attribute_list_,
param.key_, &value));
EXPECT_EQ(param.value_, b2a_hex(value));
EXPECT_EQ(param.value_, wvutil::b2a_hex(value));
} else {
EXPECT_FALSE(InitializationData::ExtractHexAttribute(param.attribute_list_,
param.key_, &value));
@@ -724,14 +724,15 @@ TEST_P(HlsConstructionTest, InitData) {
bool key_id_found = false;
if (param.key_ids_[i].size() != 32) continue;
for (int j = 0; j < cenc_header.key_ids_size(); ++j) {
if (param.key_ids_[i] == b2a_hex(cenc_header.key_ids(j))) {
if (param.key_ids_[i] == wvutil::b2a_hex(cenc_header.key_ids(j))) {
key_id_found = true;
break;
}
}
EXPECT_TRUE(key_id_found);
}
std::vector<uint8_t> param_content_id_vec(Base64Decode(param.content_id_));
std::vector<uint8_t> param_content_id_vec(
wvutil::Base64Decode(param.content_id_));
EXPECT_EQ(
std::string(param_content_id_vec.begin(), param_content_id_vec.end()),
cenc_header.content_id());
@@ -788,7 +789,7 @@ TEST_F(HlsInitDataConstructionTest, InvalidUriDataFormat) {
VectorOfStrings(kHlsTestKeyId1).Generate());
std::string value;
EXPECT_FALSE(InitializationData::ConstructWidevineInitData(
kHlsMethodAes128, Base64Encode(json), &value));
kHlsMethodAes128, wvutil::Base64Encode(json), &value));
}
TEST_F(HlsInitDataConstructionTest, InvalidUriBase64Encode) {
@@ -829,11 +830,11 @@ TEST_P(HlsParseTest, Parse) {
} else if (param.key_.compare(kJsonContentId) == 0) {
EXPECT_EQ(param.value_, cenc_header.content_id());
} else if (param.key_.compare(kJsonKeyIds) == 0) {
EXPECT_EQ(param.value_, b2a_hex(cenc_header.key_ids(0)));
EXPECT_EQ(param.value_, wvutil::b2a_hex(cenc_header.key_ids(0)));
}
CORE_UTIL_RESTORE_WARNINGS
EXPECT_EQ(kHlsIvHexValue, b2a_hex(init_data.hls_iv()));
EXPECT_EQ(kHlsIvHexValue, wvutil::b2a_hex(init_data.hls_iv()));
} else {
EXPECT_TRUE(init_data.is_hls());
EXPECT_TRUE(init_data.IsEmpty());

View File

@@ -53,7 +53,7 @@ class CdmOtaKeyboxTest : public ::testing::Test {
cert_type, cert_authority, config.provisioning_service_certificate(),
kLevelDefault, &prov_request, &provisioning_server_url);
if (result == CERT_PROVISIONING_NONCE_GENERATION_ERROR) {
TestSleep::Sleep(2);
wvutil::TestSleep::Sleep(2);
continue;
}
break;
@@ -87,16 +87,17 @@ class CdmOtaKeyboxTest : public ::testing::Test {
TEST_F(CdmOtaKeyboxTest, TestThatTheBuildFilesWork) { ASSERT_TRUE(true); }
/** Verify that the CDM can open a session with at most two provisioning
* steps. Unlike almost all of the other Widevine CDM tests, this test does
* **not** install a test keybox before running. For that reason, this test is
* expected to fail if the device does not either support Keybox OTA recover or
* have an existing keybox or OEM Certificate. For those devices, this test
* should be skipped.
*/
TEST_F(CdmOtaKeyboxTest, BasicTest) {
FileSystem file_system;
wvutil::FileSystem file_system;
TestCdmEngine cdm_engine(&file_system,
std::shared_ptr<EngineMetrics>(new EngineMetrics));
// Create a singleton crypto session to prevent OEMCrypto from being
// terminated. This is really only needed when running the test against the
// testbed OEMCrypto which does save its keybox across init/terminate.
metrics::CryptoMetrics crypto_metrics;
std::unique_ptr<CryptoSession> crypto_session(
CryptoSession::MakeCryptoSession(&crypto_metrics));
// Remove any existing certificate.
cdm_engine.Unprovision(kSecurityLevelL1);
std::string system_id;

View File

@@ -24,6 +24,7 @@
namespace wvcdm {
namespace {
using wvutil::a2bs_hex;
const std::string kEmptyString;
const std::string kAesKey = a2bs_hex("000102030405060708090a0b0c0d0e0f");
@@ -192,7 +193,7 @@ using ::testing::Values;
class CdmLicenseTestPeer : public CdmLicense {
public:
CdmLicenseTestPeer(const CdmSessionId& session_id, Clock* clock)
CdmLicenseTestPeer(const CdmSessionId& session_id, wvutil::Clock* clock)
: CdmLicense(session_id, clock) {}
using CdmLicense::HandleNewEntitledKeys;
@@ -231,12 +232,12 @@ class CdmLicenseTest : public WvCdmTestBase {
clock_ = nullptr;
}
CdmLicenseTestPeer* cdm_license_;
MockClock* clock_;
CdmLicenseTestPeer* cdm_license_ = nullptr;
MockClock* clock_ = nullptr;
metrics::CryptoMetrics crypto_metrics_;
MockCryptoSession* crypto_session_;
InitializationData* init_data_;
MockPolicyEngine* policy_engine_;
MockCryptoSession* crypto_session_ = nullptr;
InitializationData* init_data_ = nullptr;
MockPolicyEngine* policy_engine_ = nullptr;
std::string pssh_;
};

View File

@@ -5,12 +5,13 @@
#ifndef CDM_TEST_MOCK_CLOCK_H_
#define CDM_TEST_MOCK_CLOCK_H_
#include "clock.h"
#include <gmock/gmock.h>
#include "clock.h"
namespace wvcdm {
class MockClock : public Clock {
class MockClock : public wvutil::Clock {
public:
MOCK_METHOD(int64_t, GetCurrentTime, (), (override));
};
@@ -18,7 +19,7 @@ class MockClock : public Clock {
// Frozen clock will always return the same value for the current time.
// Intended to be used for testing where using the actual time would
// cause flaky tests.
class FrozenClock : public Clock {
class FrozenClock : public wvutil::Clock {
int64_t always_time_;
public:
@@ -27,6 +28,6 @@ class FrozenClock : public Clock {
void SetTime(int64_t new_time) { always_time_ = new_time; }
};
} // wvcdm
} // namespace wvcdm
#endif // CDM_TEST_MOCK_CLOCK_H_

View File

@@ -177,7 +177,7 @@ void MakeSignedOtaProvisioningResponseEx(ProvisioningType provisioning_type,
return;
}
response->assign("{\n\"signedResponse\": \"");
response->append(Base64SafeEncodeNoPad(ToVector(proto_response)));
response->append(wvutil::Base64SafeEncodeNoPad(ToVector(proto_response)));
response->append("\"\n}\n");
}
@@ -194,7 +194,8 @@ bool RequestContains(const std::string& request, const std::string& part) {
const auto request_pos = request.find(part);
return request_pos != std::string::npos;
}
const std::string decoded_request = FromVector(Base64SafeDecode(request));
const std::string decoded_request =
FromVector(wvutil::Base64SafeDecode(request));
if (decoded_request.empty()) return false;
const auto request_pos = decoded_request.find(part);
return request_pos != std::string::npos;

View File

@@ -167,23 +167,24 @@ class CorePIGTest : public WvCdmTestBaseWithEngine {
int secure_buffer_fid;
OEMCrypto_DestBufferDesc output_descriptor;
output_descriptor.type = OEMCrypto_BufferType_Secure;
output_descriptor.buffer.secure.handle_length = buffer_size;
output_descriptor.buffer.secure.secure_buffer_length = buffer_size;
ASSERT_EQ(
OEMCrypto_AllocateSecureBuffer(oec_session_id, buffer_size,
&output_descriptor, &secure_buffer_fid),
OEMCrypto_SUCCESS);
ASSERT_NE(output_descriptor.buffer.secure.handle, nullptr);
ASSERT_NE(output_descriptor.buffer.secure.secure_buffer, nullptr);
// It is OK if OEMCrypto changes the maximum size, but there must
// still be enough room for our data.
ASSERT_GE(output_descriptor.buffer.secure.handle_length, buffer_size);
ASSERT_GE(output_descriptor.buffer.secure.secure_buffer_length,
buffer_size);
output_descriptor.buffer.secure.offset = 0;
// Now create a sample array for the CDM layer.
CdmDecryptionParametersV16 params(key_id);
params.is_secure = true;
CdmDecryptionSample sample(input.data(),
output_descriptor.buffer.secure.handle, 0,
output_descriptor.buffer.secure.secure_buffer, 0,
input.size(), iv);
CdmDecryptionSubsample subsample(0, input.size());
sample.subsamples.push_back(subsample);

View File

@@ -12,6 +12,10 @@
#include "log.h"
using wvutil::a2b_hex;
using wvutil::b2a_hex;
using wvutil::FileSystem;
namespace wvcdm {
FileSystem* RebootTest::file_system_;
@@ -29,11 +33,11 @@ std::string EncodeString(const std::string& data) {
// If there are any unprintable characters, except whitespace, or if we
// close a brace before we open it, then just use hex.
if (!printable || braces_count < 0) {
return "0x" + wvcdm::b2a_hex(data) + ",";
return "0x" + b2a_hex(data) + ",";
}
}
// If we left any braces open, then use hex.
if (braces_count != 0) return "0x" + wvcdm::b2a_hex(data) + ",";
if (braces_count != 0) return "0x" + b2a_hex(data) + ",";
return "{" + data + "},";
}
@@ -47,12 +51,12 @@ std::string EncodeKey(const std::string& data) {
}
// When decoding, we assume that a key starting with "0x" is in hex. So we
// can't have any keys that start with "0x".
if (data.substr(0, 2) == "0x") return "0x" + wvcdm::b2a_hex(data) + ":";
if (data.substr(0, 2) == "0x") return "0x" + b2a_hex(data) + ":";
// If the key is just is not printable, or if it has unmatched braces, then
// we use hex. Otherwise, we surround the whole string with braces.
for (size_t i = 0; i < data.length(); i++) {
if (!isprint(data[i]) || (data[i] == ':')) {
return "0x" + wvcdm::b2a_hex(data) + ":";
return "0x" + b2a_hex(data) + ":";
}
}
return data + ":";
@@ -107,8 +111,7 @@ std::string DecodeString(const std::string& encoded, size_t* index) {
while (*index < encoded.length()) {
if (encoded[*index] == ',') {
size_t end = *index;
std::vector<uint8_t> result =
wvcdm::a2b_hex(encoded.substr(start, end - start));
std::vector<uint8_t> result = a2b_hex(encoded.substr(start, end - start));
(*index)++; // absorb the comma.
return std::string(result.begin(), result.end());
}
@@ -134,8 +137,7 @@ std::string DecodeKey(const std::string& encoded, size_t* index) {
size_t start = *index + 2;
while (*index < encoded.length() && encoded[*index] != ':') (*index)++;
size_t end = *index;
std::vector<uint8_t> result =
wvcdm::a2b_hex(encoded.substr(start, end - start));
std::vector<uint8_t> result = a2b_hex(encoded.substr(start, end - start));
(*index)++; // skip the colon.
return std::string(result.begin(), result.end());
}

View File

@@ -19,7 +19,7 @@ class RebootTest : public WvCdmTestBaseWithEngine {
public:
// The main test driver may inject the file system for saving persistent test
// data.
static void set_file_system(FileSystem* file_system) {
static void set_file_system(wvutil::FileSystem* file_system) {
file_system_ = file_system;
}
// Dump a map to a std string in an almost human readable way so that the map
@@ -41,7 +41,7 @@ class RebootTest : public WvCdmTestBaseWithEngine {
void TearDown() override;
// This is used to store each test's persistent data.
static FileSystem* file_system_;
static wvutil::FileSystem* file_system_;
// The persistent data for the current test.
std::map<std::string, std::string> persistent_data_;

View File

@@ -2,6 +2,11 @@
// source code may only be used and distributed under the Widevine License
// Agreement.
#include "rw_lock.h"
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <atomic>
#include <chrono>
#include <condition_variable>
@@ -9,14 +14,9 @@
#include <mutex>
#include <thread>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "rw_lock.h"
using std::this_thread::sleep_for;
namespace wvcdm {
namespace wvutil {
namespace {
@@ -290,4 +290,4 @@ TEST(SharedMutexUnitTests, LargeVolumeOfThreadsSortsItselfOutEventually) {
}
}
} // namespace wvcdm
} // namespace wvutil

View File

@@ -3,9 +3,12 @@
// Agreement.
#include "service_certificate.h"
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <string>
#include "properties.h"
#include "string_conversions.h"
#include "wv_cdm_constants.h"
@@ -19,7 +22,7 @@ const CdmSessionId kTestSessionId1 = "sid1";
const CdmSessionId kTestSessionId2 = "sid2";
const std::string kAppId = "com.example.test";
const std::string kTestSignedCertificate = a2bs_hex(
const std::string kTestSignedCertificate = wvutil::a2bs_hex(
"0AC102080312101705B917CC1204868B06333A2F772A8C1882B4829205228E023082010A02"
"8201010099ED5B3B327DAB5E24EFC3B62A95B598520AD5BCCB37503E0645B814D876B8DF40"
"510441AD8CE3ADB11BB88C4E725A5E4A9E0795291D58584023A7E1AF0E38A9127939300861"

View File

@@ -236,7 +236,7 @@ CdmResponseType TestCryptoSession::GenerateNonce(uint32_t* nonce) {
for (int i = 0; status != NO_ERROR; i++) {
LOGV("Recovering from nonce flood.");
if (i > 2) return status;
TestSleep::Sleep(1);
wvutil::TestSleep::Sleep(1);
status = CryptoSession::GenerateNonce(nonce);
}
return NO_ERROR;
@@ -295,6 +295,9 @@ void WvCdmTestBase::InstallTestRootOfTrust() {
case wvoec::DeviceFeatures::TEST_PROVISION_30:
// Can use oem certificate to install test rsa key.
break;
case wvoec::DeviceFeatures::TEST_PROVISION_40:
// OEM certificate is retrieved from the server.
break;
default:
FAIL() << "Cannot run test without test keybox or RSA key installed.";
}
@@ -316,7 +319,7 @@ void WvCdmTestBase::Provision() {
std::string cert, wrapped_key;
CdmSessionId session_id;
FileSystem file_system;
wvutil::FileSystem file_system;
if (config_.provisioning_server() == "fake") {
LOGD("Using fake provisioning server.");
@@ -329,7 +332,8 @@ void WvCdmTestBase::Provision() {
&prov_request, &provisioning_server_url);
ASSERT_EQ(NO_ERROR, result);
if (!binary_provisioning_) {
std::vector<uint8_t> prov_request_v = Base64SafeDecode(prov_request);
std::vector<uint8_t> prov_request_v =
wvutil::Base64SafeDecode(prov_request);
prov_request = std::string(prov_request_v.begin(), prov_request_v.end());
}
std::string response;
@@ -349,7 +353,7 @@ void WvCdmTestBase::Provision() {
ASSERT_EQ(NO_ERROR, result);
if (binary_provisioning_) {
prov_request = Base64SafeEncodeNoPad(prov_request);
prov_request = wvutil::Base64SafeEncodeNoPad(prov_request);
}
LOGV("Provisioning request: req = %s", prov_request.c_str());
@@ -390,7 +394,7 @@ void WvCdmTestBase::Provision() {
// base64 decode response to yield binary protobuf
const std::vector<uint8_t> response_vec(
Base64SafeDecode(protobuf_response));
wvutil::Base64SafeDecode(protobuf_response));
ASSERT_FALSE(response_vec.empty())
<< "Failed to decode base64 of response: response = "
<< protobuf_response;
@@ -415,7 +419,7 @@ void WvCdmTestBase::Provision() {
// that certificate from the provisioning request.
void WvCdmTestBase::EnsureProvisioned() {
CdmSessionId session_id;
FileSystem file_system;
wvutil::FileSystem file_system;
// OpenSession will check if a DRM certificate exists, while
// GenerateKeyRequest will actually load the wrapped private key.
// Either may return a NEED_PROVISIONING error, so both have to be checked.
@@ -468,7 +472,7 @@ bool WvCdmTestBase::Initialize(int argc, const char* const argv[],
} else if (arg == "--cast") {
is_cast_receiver = true;
} else if (arg == "--fake_sleep") {
wvcdm::TestSleep::set_real_sleep(false);
wvutil::TestSleep::set_real_sleep(false);
} else if (arg == "--qa_provisioning") {
use_qa_test_keybox_ = true;
default_config_.set_provisioning_service_certificate(
@@ -502,10 +506,10 @@ bool WvCdmTestBase::Initialize(int argc, const char* const argv[],
} else if (arg_prefix == "--keyid") {
default_config_.set_key_id(arg_value);
} else if (arg_prefix == "--service_certificate") {
const std::string certificate(a2bs_hex(arg_value));
const std::string certificate(wvutil::a2bs_hex(arg_value));
default_config_.set_license_service_certificate(certificate);
} else if (arg_prefix == "--provisioning_certificate") {
const std::string certificate(a2bs_hex(arg_value));
const std::string certificate(wvutil::a2bs_hex(arg_value));
default_config_.set_provisioning_service_certificate(certificate);
} else if (arg_prefix == "--license_server_url") {
default_config_.set_license_server(arg_value);
@@ -532,7 +536,7 @@ bool WvCdmTestBase::Initialize(int argc, const char* const argv[],
return false;
}
g_cutoff = static_cast<LogPriority>(verbosity);
wvutil::g_cutoff = static_cast<wvutil::LogPriority>(verbosity);
// Displays server url, port and key Id being used
std::cout << std::endl;
@@ -560,6 +564,7 @@ bool WvCdmTestBase::Initialize(int argc, const char* const argv[],
TestLicenseHolder::TestLicenseHolder(CdmEngine* cdm_engine)
: cdm_engine_(cdm_engine),
oemcrypto_api_(0),
session_opened_(false),
// Keys are initialized with simple values, and the correct size:
derived_mac_key_server_(MAC_KEY_SIZE, 'a'),
@@ -593,7 +598,7 @@ void TestLicenseHolder::GenerateKeyRequest(
CdmAppParameterMap app_parameters;
CdmKeySetId key_set_id;
InitializationData init_data(init_data_type_string, key_id);
if (g_cutoff >= LOG_DEBUG) init_data.DumpToLogs();
if (wvutil::g_cutoff >= wvutil::LOG_DEBUG) init_data.DumpToLogs();
CdmKeyRequest key_request;
CdmResponseType result = cdm_engine_->GenerateKeyRequest(
session_id_, key_set_id, init_data, kLicenseTypeStreaming, app_parameters,
@@ -615,6 +620,20 @@ void TestLicenseHolder::CreateDefaultLicense() {
video_widevine::ClientIdentification_TokenType_DRM_DEVICE_CERTIFICATE,
client_id.type());
oemcrypto_api_ =
(client_id.has_client_capabilities() &&
client_id.client_capabilities().has_oem_crypto_api_version())
? client_id.client_capabilities().oem_crypto_api_version()
: 0;
std::string signed_buffer = license_request_data_;
std::string core_message = signed_message.has_oemcrypto_core_message()
? signed_message.oemcrypto_core_message()
: "";
if (oemcrypto_api_ >= 17) {
signed_buffer = signed_message.oemcrypto_core_message() + signed_buffer;
}
// Extract the RSA key from the DRM certificate.
std::string token = client_id.token();
video_widevine::SignedDrmCertificate signed_drm_cert;
@@ -622,8 +641,8 @@ void TestLicenseHolder::CreateDefaultLicense() {
video_widevine::DrmCertificate drm_cert;
EXPECT_TRUE(drm_cert.ParseFromString(signed_drm_cert.drm_certificate()));
EXPECT_TRUE(rsa_key_.Init(drm_cert.public_key()));
EXPECT_TRUE(rsa_key_.VerifySignature(signed_message.msg(),
signed_message.signature()));
EXPECT_TRUE(
rsa_key_.VerifySignature(signed_buffer, signed_message.signature()));
DeriveKeysFromSessionKey();
@@ -685,15 +704,26 @@ video_widevine::License_KeyContainer* TestLicenseHolder::AddKey(
std::string padding(CONTENT_KEY_SIZE, '-');
key_container->set_key(encrypted_key_data + padding);
std::vector<uint8_t> block_v(
reinterpret_cast<const uint8_t*>(&block),
reinterpret_cast<const uint8_t*>(&block) + sizeof(block));
std::vector<uint8_t> block_iv(KEY_IV_SIZE, 'w');
std::string block_iv_s(block_iv.begin(), block_iv.end());
std::string encrypted_block =
WvCdmTestBase::Aes128CbcEncrypt(key_data, block_v, block_iv);
key_container->mutable_key_control()->set_iv(block_iv_s);
key_container->mutable_key_control()->set_key_control_block(encrypted_block);
// TODO(b/192700112): This mock license server should parse the core message
// request, and only encrypt the key control block if the API is greater than
// or equal to 16.5. For now, we can pass tests on the v17 branch by checking
// against v17.0.
if (oemcrypto_api_ >= 17) {
std::string block_s(reinterpret_cast<const char*>(&block),
reinterpret_cast<const char*>(&block) + sizeof(block));
key_container->mutable_key_control()->set_key_control_block(block_s);
} else {
std::vector<uint8_t> block_v(
reinterpret_cast<const uint8_t*>(&block),
reinterpret_cast<const uint8_t*>(&block) + sizeof(block));
std::vector<uint8_t> block_iv(KEY_IV_SIZE, 'w');
std::string block_iv_s(block_iv.begin(), block_iv.end());
std::string encrypted_block =
WvCdmTestBase::Aes128CbcEncrypt(key_data, block_v, block_iv);
key_container->mutable_key_control()->set_iv(block_iv_s);
key_container->mutable_key_control()->set_key_control_block(
encrypted_block);
}
return key_container;
}
@@ -805,11 +835,11 @@ std::string MakePSSH(const std::string& serialized_header) {
size_t data_size = serialized_header.size();
size_t atom_size = data_size + system_id_size + 4 * 4;
std::string pssh = EncodeUint32(static_cast<uint32_t>(atom_size));
std::string pssh = wvutil::EncodeUint32(static_cast<uint32_t>(atom_size));
pssh.append("pssh");
pssh.append(EncodeUint32(version));
pssh.append(wvutil::EncodeUint32(version));
pssh.append(system_id);
pssh.append(EncodeUint32(static_cast<uint32_t>(data_size)));
pssh.append(wvutil::EncodeUint32(static_cast<uint32_t>(data_size)));
pssh.append(serialized_header);
return pssh;
}

View File

@@ -5,16 +5,16 @@
#ifndef WVCDM_CORE_TEST_BASE_H_
#define WVCDM_CORE_TEST_BASE_H_
#include <gtest/gtest.h>
#include <string>
#include <vector>
#include <gtest/gtest.h>
#include "cdm_engine.h"
#include "config_test_env.h"
#include "crypto_session.h"
#include "metrics_collections.h"
#include "oec_session_util.h"
#include "oemcrypto_types.h"
#include "string_conversions.h"
namespace wvcdm {
@@ -26,7 +26,7 @@ class WvCdmTestBase : public ::testing::Test {
~WvCdmTestBase() override {}
void SetUp() override;
virtual std::string binary_key_id() const {
return a2bs_hex(config_.key_id());
return wvutil::a2bs_hex(config_.key_id());
}
// Returns true if the test program should continue, if false, the caller
@@ -83,7 +83,7 @@ class WvCdmTestBase : public ::testing::Test {
// metrics and file system.
class TestCdmEngine : public CdmEngine {
public:
TestCdmEngine(FileSystem* file_system,
TestCdmEngine(wvutil::FileSystem* file_system,
std::shared_ptr<metrics::EngineMetrics> metrics)
: CdmEngine(file_system, metrics) {}
};
@@ -95,8 +95,8 @@ class WvCdmTestBaseWithEngine : public WvCdmTestBase {
cdm_engine_(&file_system_, dummy_engine_metrics_) {}
protected:
FileSystem file_system_;
shared_ptr<metrics::EngineMetrics> dummy_engine_metrics_;
wvutil::FileSystem file_system_;
std::shared_ptr<metrics::EngineMetrics> dummy_engine_metrics_;
TestCdmEngine cdm_engine_;
};
@@ -156,6 +156,7 @@ class TestLicenseHolder {
void AddMacKey();
CdmEngine* cdm_engine_;
uint32_t oemcrypto_api_;
std::string signed_license_request_data_;
std::string license_request_data_;
std::string session_id_;

View File

@@ -946,6 +946,51 @@ void PrintTo(const enum CdmResponseType& value, ::std::ostream* os) {
case PROVISIONING_NOT_ALLOWED_FOR_ATSC:
*os << "PROVISIONING_NOT_ALLOWED_FOR_ATSC";
break;
case PROVISIONING_TYPE_IS_NOT_BOOT_CERTIFICATE_CHAIN_ERROR:
*os << "PROVISIONING_TYPE_IS_NOT_BOOT_CERTIFICATE_CHAIN_ERROR";
break;
case GET_BOOT_CERTIFICATE_CHAIN_ERROR:
*os << "GET_BOOT_CERTIFICATE_CHAIN_ERROR";
break;
case GENERATE_CERTIFICATE_KEY_PAIR_ERROR:
*os << "GENERATE_CERTIFICATE_KEY_PAIR_ERROR";
break;
case GENERATE_CERTIFICATE_KEY_PAIR_UNKNOWN_TYPE_ERROR:
*os << "GENERATE_CERTIFICATE_KEY_PAIR_ERROR";
break;
case LOAD_OEM_CERTIFICATE_PRIVATE_KEY_ERROR:
*os << "GENERATE_CERTIFICATE_KEY_PAIR_ERROR";
break;
case PROVISIONING_4_CRYPTO_SESSION_NOT_OPEN:
*os << "PROVISIONING_4_CRYPTO_SESSION_NOT_OPEN";
break;
case PROVISIONING_4_FILE_SYSTEM_IS_NULL:
*os << "PROVISIONING_4_FILE_SYSTEM_IS_NULL";
break;
case PROVISIONING_4_FAILED_TO_INITIALIZE_DEVICE_FILES:
*os << "PROVISIONING_4_FAILED_TO_INITIALIZE_DEVICE_FILES";
break;
case PROVISIONING_4_RESPONSE_FAILED_TO_PARSE_MESSAGE:
*os << "PROVISIONING_4_RESPONSE_FAILED_TO_PARSE_MESSAGE";
break;
case PROVISIONING_4_RESPONSE_HAS_ERROR_STATUS:
*os << "PROVISIONING_4_RESPONSE_HAS_ERROR_STATUS";
break;
case PROVISIONING_4_RESPONSE_HAS_NO_CERTIFICATE:
*os << "PROVISIONING_4_RESPONSE_HAS_NO_CERTIFICATE";
break;
case PROVISIONING_4_NO_PRIVATE_KEY:
*os << "PROVISIONING_4_NO_PRIVATE_KEY";
break;
case PROVISIONING_4_FAILED_TO_INITIALIZE_DEVICE_FILES_2:
*os << "PROVISIONING_4_FAILED_TO_INITIALIZE_DEVICE_FILES_2";
break;
case PROVISIONING_4_FAILED_TO_STORE_OEM_CERTIFICATE:
*os << "PROVISIONING_4_FAILED_TO_STORE_OEM_CERTIFICATE";
break;
case PROVISIONING_4_FAILED_TO_STORE_DRM_CERTIFICATE:
*os << "PROVISIONING_4_FAILED_TO_STORE_DRM_CERTIFICATE";
break;
default:
*os << "Unknown CdmResponseType";
break;
@@ -1189,11 +1234,20 @@ void PrintTo(const enum OEMCryptoResult& value, ::std::ostream* os) {
*os << "MIXED_OUTPUT_PROTECTION";
break;
case OEMCrypto_ERROR_INVALID_ENTITLED_KEY_SESSION:
*os << "OEMCrypto_ERROR_INVALID_ENTITLED_KEY_SESSION";
*os << "INVALID_ENTITLED_KEY_SESSION";
break;
case OEMCrypto_ERROR_NEEDS_KEYBOX_PROVISIONING:
*os << "NEEDS_KEYBOX_PROVISIONING";
break;
case OEMCrypto_ERROR_UNSUPPORTED_CIPHER:
*os << "OEMCrypto_ERROR_UNSUPPORTED_CIPHER";
break;
case OEMCrypto_ERROR_DVR_FORBIDDEN:
*os << "OEMCrypto_ERROR_DVR_FORBIDDEN";
break;
case OEMCrypto_ERROR_INSUFFICIENT_PRIVILEGE:
*os << "OEMCrypto_ERROR_INSUFFICIENT_PRIVILEGE";
break;
case OEMCrypto_ERROR_INVALID_KEY:
*os << "INVALID_KEY";
break;

View File

@@ -5,6 +5,7 @@
#include "url_request.h"
#include <errno.h>
#include <sstream>
#include "http_socket.h"
@@ -205,7 +206,8 @@ bool UrlRequest::PostRequestWithPath(const std::string& path,
const int ret = socket_.WriteAndLogErrors(
request.c_str(), static_cast<int>(request.size()), kWriteTimeoutMs);
LOGV("HTTP request: (%zu): %s", request.size(), b2a_hex(request).c_str());
LOGV("HTTP request: (%zu): %s", request.size(),
wvutil::b2a_hex(request).c_str());
return ret != -1;
}

View File

@@ -156,7 +156,7 @@ const std::string kLicenseArray[] = {
kUsageEntryInfoOfflineLicense2.key_set_id,
kUsageEntryInfoOfflineLicense3.key_set_id,
};
const size_t kLicenseArraySize = ArraySize(kLicenseArray);
const size_t kLicenseArraySize = wvutil::ArraySize(kLicenseArray);
std::vector<std::string> kLicenseList;
const std::vector<std::string> kEmptyUsageInfoFilesList;
@@ -166,7 +166,7 @@ const std::string kUsageInfoFileArray[] = {
kUsageEntryInfoSecureStop2.usage_info_file_name,
kUsageEntryInfoSecureStop3.usage_info_file_name,
};
const size_t kUsageInfoFileArraySize = ArraySize(kUsageInfoFileArray);
const size_t kUsageInfoFileArraySize = wvutil::ArraySize(kUsageInfoFileArray);
std::vector<std::string> kUsageInfoFileList;
const DeviceFiles::CdmUsageData kCdmUsageData1 = {
@@ -257,12 +257,12 @@ std::vector<CdmUsageEntryInfo> kUpgradableUsageEntryInfoList;
// license_duration_seconds = 259200 (3 days)
// rental_duration_seconds = 604800 (7 days)
// playback_duration_seconds = 86400 (1 day)
const CdmKeyResponse kUpgradableLicenseInfo1 = a2bs_hex(
const CdmKeyResponse kUpgradableLicenseInfo1 = wvutil::a2bs_hex(
"08021214120C2080F5242880A3053080E90F20D8A6BEE9051A20D5F7ACE8D84A166C69BB"
"27523C84C019464B90AA9BF06B8332004839119BFD14");
// Streaming license 2.
// license_start_time = 1563399000
const CdmKeyResponse kUpgradableLicenseInfo2 = a2bs_hex(
const CdmKeyResponse kUpgradableLicenseInfo2 = wvutil::a2bs_hex(
"0802120620D8A6BEE9051A201956F2FD69E5E96DA8C65FDD04A3C294E484F219F2B1A8DD"
"C2B0737F6EF5BD22");
// Offline license 3.
@@ -270,16 +270,16 @@ const CdmKeyResponse kUpgradableLicenseInfo2 = a2bs_hex(
// license_duration_seconds = 0 (unlimited)
// rental_duration_seconds = 604800 (7 days)
// playback_duration_seconds = 86400 (1 day)
const CdmKeyResponse kUpgradableLicenseInfo3 = a2bs_hex(
const CdmKeyResponse kUpgradableLicenseInfo3 = wvutil::a2bs_hex(
"08021212120A2080F5242880A305300020D8A6BEE9051A207B09896F46C4EE443170E215"
"B2D8D5F072951027B152F4758AC3A339D7C7B4CE");
std::vector<CdmKeyResponse> kUpgradableLicenseInfoList;
std::vector<DeviceFiles::CdmLicenseData> kUpgradableLicenseDataList;
// Same as Offline license 1, but without signature.
const CdmKeyResponse kUnsignedUpgradableLicenseInfo1 =
a2bs_hex("08021214120C2080F5242880A3053080E90F20D8A6BEE905");
wvutil::a2bs_hex("08021214120C2080F5242880A3053080E90F20D8A6BEE905");
// Same as streaming license 2, but message type is certificate, not license.
const CdmKeyResponse kWrongTypedUpgradableLicenseInfo2 = a2bs_hex(
const CdmKeyResponse kWrongTypedUpgradableLicenseInfo2 = wvutil::a2bs_hex(
"0805120620D8A6BEE9051A201956F2FD69E5E96DA8C65FDD04A3C294E484F219F2B1A8DD"
"C2B0737F6EF5BD22");
@@ -427,7 +427,7 @@ class MockDeviceFiles : public DeviceFiles {
(std::vector<std::string> * usage_info_files), (override));
private:
FileSystem file_system_;
wvutil::FileSystem file_system_;
};
class MockCryptoSession : public TestCryptoSession {
@@ -590,7 +590,7 @@ class UsageTableHeaderTest : public WvCdmTestBase {
metrics::CryptoMetrics crypto_metrics_;
MockCryptoSession* crypto_session_;
UsageTableHeader* usage_table_header_;
std::unique_ptr<Clock> test_clock_;
std::unique_ptr<wvutil::Clock> test_clock_;
};
TEST_F(UsageTableHeaderTest, InitError) {
@@ -4301,7 +4301,7 @@ TEST_F(UsageTableHeaderTest,
std::vector<uint32_t> expired_license_numbers;
while (expired_license_numbers.size() < 3) {
const uint32_t i =
static_cast<uint32_t>(CdmRandom::RandomInRange(kSetSize - 1));
static_cast<uint32_t>(wvutil::CdmRandom::RandomInRange(kSetSize - 1));
CdmUsageEntryInfo& usage_entry_info = usage_entry_info_list[i];
// Skip already expired ones
if (usage_entry_info.key_set_id != "nothing_unusual") continue;
@@ -4356,8 +4356,8 @@ TEST_F(UsageTableHeaderTest, DetermineLicenseToRemove_LargeMixedSet) {
// Select a streaming license to be more stale than the rest.
uint32_t modified_usage_info_number = kInvalidEntry;
while (modified_usage_info_number == kInvalidEntry) {
const uint32_t i =
static_cast<uint32_t>(CdmRandom::RandomInRange(kLargeSetSize - 1));
const uint32_t i = static_cast<uint32_t>(
wvutil::CdmRandom::RandomInRange(kLargeSetSize - 1));
CdmUsageEntryInfo& usage_entry_info = usage_entry_info_list[i];
// Skip offline licenses.
if (usage_entry_info.storage_type != kStorageUsageInfo) continue;
@@ -4369,8 +4369,8 @@ TEST_F(UsageTableHeaderTest, DetermineLicenseToRemove_LargeMixedSet) {
// Select a offline license to be even more stale, but unexpired.
uint32_t modified_offline_license_number = kInvalidEntry;
while (modified_offline_license_number == kInvalidEntry) {
const uint32_t i =
static_cast<uint32_t>(CdmRandom::RandomInRange(kLargeSetSize - 1));
const uint32_t i = static_cast<uint32_t>(
wvutil::CdmRandom::RandomInRange(kLargeSetSize - 1));
CdmUsageEntryInfo& usage_entry_info = usage_entry_info_list[i];
// Skip streaming licenses.
if (usage_entry_info.storage_type != kStorageLicense) continue;