(This is a merge of http://go/wvgerrit/81628. Although it is primarily to support a CE CDM feature, this patch touched shared code and so must be merged.) The problem that has long stopped the OEMCrypto Testbed from working with the CE CDM build is that the OEMCrypto Testbed sometimes accesses the storage via the normal filesystem APIs rather than the FileSystem abstraction. Furthermore, when doing this, it assumes that FileSystem abstraction is just a wrapper around direct filesystem access and thus it should use the same paths in both kinds of filesystem access. However, this is not true on the CE CDM where FileSystem wraps an opaque key/value store. This patch adds a property that allows a platform to indicate if its FileSystem base path represents a real file system path and sets it appropriately. ("true" for all platforms except CE CDM) It also adds code to the OEMCrypto Testbed that makes use of this property to modify its behavior. When running on a device where the FileSystem base path is not a real file system path, it will instead use the directory of the current executable as its base path when accessing the filesystem directly. Bug: 129311942 Test: CE CDM Build with Fake L1 Test: Android Build Change-Id: Iadb3cc57d3bbc8ce0d49224b7df31c46bd5ea56c
154 lines
5.7 KiB
C++
154 lines
5.7 KiB
C++
// Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary
|
|
// source code may only be used and distributed under the Widevine Master
|
|
// License Agreement.
|
|
|
|
#ifndef WVCDM_CORE_PROPERTIES_H_
|
|
#define WVCDM_CORE_PROPERTIES_H_
|
|
|
|
#include <map>
|
|
#include <memory>
|
|
#include <mutex>
|
|
#include <string>
|
|
|
|
#include "cdm_client_property_set.h"
|
|
#include "disallow_copy_and_assign.h"
|
|
#include "wv_cdm_types.h"
|
|
|
|
#if defined(UNIT_TEST)
|
|
#include <gtest/gtest_prod.h>
|
|
#endif
|
|
|
|
namespace wvcdm {
|
|
|
|
using CdmClientPropertySetMap = std::map<CdmSessionId, CdmClientPropertySet*>;
|
|
|
|
// This class saves information about features and properties enabled
|
|
// for a given platform. At initialization it initializes properties from
|
|
// property_configuration.h. That file specifies features selected for each
|
|
// platform. Core CDM can then query enabled features though specific getter
|
|
// methods.
|
|
// Setter methods are provided but their only planned use is for testing.
|
|
class Properties {
|
|
public:
|
|
static void Init() {
|
|
std::unique_lock<std::mutex> lock(init_mutex_);
|
|
|
|
if (!is_initialized_) {
|
|
InitOnce();
|
|
is_initialized_ = true;
|
|
}
|
|
}
|
|
|
|
static inline bool oem_crypto_use_secure_buffers() {
|
|
return oem_crypto_use_secure_buffers_;
|
|
}
|
|
static inline bool oem_crypto_use_fifo() { return oem_crypto_use_fifo_; }
|
|
static inline bool oem_crypto_use_userspace_buffers() {
|
|
return oem_crypto_use_userspace_buffers_;
|
|
}
|
|
static inline bool provisioning_messages_are_binary() {
|
|
return provisioning_messages_are_binary_;
|
|
}
|
|
static inline bool allow_service_certificate_requests() {
|
|
return allow_service_certificate_requests_;
|
|
}
|
|
static inline bool device_files_is_a_real_filesystem() {
|
|
return device_files_is_a_real_filesystem_;
|
|
}
|
|
static void set_provisioning_messages_are_binary(bool flag) {
|
|
provisioning_messages_are_binary_ = flag;
|
|
}
|
|
static bool GetCompanyName(std::string* company_name);
|
|
static bool GetModelName(std::string* model_name);
|
|
static bool GetArchitectureName(std::string* arch_name);
|
|
static bool GetDeviceName(std::string* device_name);
|
|
static bool GetProductName(std::string* product_name);
|
|
static bool GetBuildInfo(std::string* build_info);
|
|
static bool GetWVCdmVersion(std::string* version);
|
|
// Gets the base path for the device non-secure storage. Note that, depending
|
|
// on the value of device_files_is_a_real_filesystem, this may or may not be
|
|
// a real filesystem path.
|
|
static bool GetDeviceFilesBasePath(CdmSecurityLevel security_level,
|
|
std::string* base_path);
|
|
static bool GetFactoryKeyboxPath(std::string* keybox);
|
|
static bool GetOEMCryptoPath(std::string* library_name);
|
|
static bool GetSandboxId(std::string* sandbox_id);
|
|
static bool AlwaysUseKeySetIds();
|
|
static bool UseProviderIdInProvisioningRequest();
|
|
|
|
static bool GetSecurityLevelDirectories(std::vector<std::string>* dirs);
|
|
static bool GetApplicationId(const CdmSessionId& session_id,
|
|
std::string* app_id);
|
|
static bool GetServiceCertificate(const CdmSessionId& session_id,
|
|
std::string* service_certificate);
|
|
static bool SetServiceCertificate(const CdmSessionId& session_id,
|
|
const std::string& service_certificate);
|
|
static bool UsePrivacyMode(const CdmSessionId& session_id);
|
|
static uint32_t GetSessionSharingId(const CdmSessionId& session_id);
|
|
|
|
static bool AddSessionPropertySet(const CdmSessionId& session_id,
|
|
CdmClientPropertySet* property_set);
|
|
static bool RemoveSessionPropertySet(const CdmSessionId& session_id);
|
|
|
|
protected:
|
|
// This function always runs the code in |Init()| (and subsequently
|
|
// |InitOnce()|) even if Properties have already been initialized. This is
|
|
// needed by certain tests that are dependent on controlling the mutable state
|
|
// of Properties. Should not be used in general, as most tests rely on
|
|
// Properties' normal guarantee about |Init()| being safe to call multiple
|
|
// times without destroying mutable state.
|
|
static void ForceReinit() {
|
|
{
|
|
std::unique_lock<std::mutex> lock(init_mutex_);
|
|
is_initialized_ = false;
|
|
}
|
|
Init();
|
|
}
|
|
|
|
private:
|
|
static CdmClientPropertySet* GetCdmClientPropertySet(
|
|
const CdmSessionId& session_id);
|
|
static void set_oem_crypto_use_secure_buffers(bool flag) {
|
|
oem_crypto_use_secure_buffers_ = flag;
|
|
}
|
|
static void set_oem_crypto_use_fifo(bool flag) {
|
|
oem_crypto_use_fifo_ = flag;
|
|
}
|
|
static void set_oem_crypto_use_userspace_buffers(bool flag) {
|
|
oem_crypto_use_userspace_buffers_ = flag;
|
|
}
|
|
static void set_use_certificates_as_identification(bool flag) {
|
|
use_certificates_as_identification_ = flag;
|
|
}
|
|
|
|
#if defined(UNIT_TEST)
|
|
FRIEND_TEST(CdmSessionTest, InitWithBuiltInCertificate);
|
|
FRIEND_TEST(CdmSessionTest, InitWithCertificate);
|
|
FRIEND_TEST(CdmSessionTest, InitWithKeybox);
|
|
FRIEND_TEST(CdmSessionTest, ReInitFail);
|
|
FRIEND_TEST(CdmSessionTest, InitFailCryptoError);
|
|
FRIEND_TEST(CdmSessionTest, InitNeedsProvisioning);
|
|
FRIEND_TEST(CdmLicenseTest, PrepareKeyRequestValidation);
|
|
#endif
|
|
|
|
// Called at least once before any properties are used.
|
|
static void InitOnce();
|
|
|
|
static std::mutex init_mutex_;
|
|
static bool is_initialized_;
|
|
static bool oem_crypto_use_secure_buffers_;
|
|
static bool oem_crypto_use_fifo_;
|
|
static bool oem_crypto_use_userspace_buffers_;
|
|
static bool use_certificates_as_identification_;
|
|
static bool provisioning_messages_are_binary_;
|
|
static bool allow_service_certificate_requests_;
|
|
static bool device_files_is_a_real_filesystem_;
|
|
static std::unique_ptr<CdmClientPropertySetMap> session_property_set_;
|
|
|
|
CORE_DISALLOW_COPY_AND_ASSIGN(Properties);
|
|
};
|
|
|
|
} // namespace wvcdm
|
|
|
|
#endif // WVCDM_CORE_PROPERTIES_H_
|