OEMCrypto v17.2

Version 17.2 includes udpates to support MediaCAS. See the
CHANGELOG for full details.
This commit is contained in:
Fred Gylys-Colwell
2023-09-07 13:32:55 -07:00
parent f998d6c4ae
commit 31f24774e8
189 changed files with 6390 additions and 3411 deletions

View File

@@ -28,7 +28,7 @@ static const std::string kOemCertificateFileName = "oemcert.bin";
static const std::string kOemCertificateFileNamePrefix = "oemcert_";
// File class. The implementation is platform dependent.
class CORE_UTIL_EXPORT File {
class File {
public:
File() {}
virtual ~File() {}
@@ -39,7 +39,7 @@ class CORE_UTIL_EXPORT File {
CORE_DISALLOW_COPY_AND_ASSIGN(File);
};
class CORE_UTIL_EXPORT FileSystem {
class FileSystem {
public:
FileSystem();
FileSystem(const std::string& origin, void* extra_data);

View File

@@ -77,31 +77,34 @@ struct LoggingUidSetter {
// This function is supplied for cases where the system layer does not
// initialize logging. This is also needed to initialize logging in
// unit tests.
CORE_UTIL_EXPORT void InitLogging();
void InitLogging();
#ifdef __GNUC__
[[gnu::format(printf, 5, 6)]] CORE_UTIL_EXPORT void Log(const char* file,
const char* function,
int line,
LogPriority level,
const char* fmt, ...);
#else
CORE_UTIL_EXPORT void Log(const char* file, const char* function, int line,
LogPriority level, const char* fmt, ...);
[[gnu::format(printf, 5, 6)]]
#endif
void Log(const char* file, const char* function, int line,
LogPriority level, const char* fmt, ...);
// Log APIs
#ifndef LOGE
# define LOGE(...) \
#ifdef CDM_DISABLE_LOGGING
# define LOGE(...) (void)0
# define LOGW(...) (void)0
# define LOGI(...) (void)0
# define LOGD(...) (void)0
# define LOGV(...) (void)0
#else
# ifndef LOGE
# define LOGE(...) \
Log(__FILE__, __func__, __LINE__, wvutil::CDM_LOG_ERROR, __VA_ARGS__)
# define LOGW(...) \
# define LOGW(...) \
Log(__FILE__, __func__, __LINE__, wvutil::CDM_LOG_WARN, __VA_ARGS__)
# define LOGI(...) \
# define LOGI(...) \
Log(__FILE__, __func__, __LINE__, wvutil::CDM_LOG_INFO, __VA_ARGS__)
# define LOGD(...) \
# define LOGD(...) \
Log(__FILE__, __func__, __LINE__, wvutil::CDM_LOG_DEBUG, __VA_ARGS__)
# define LOGV(...) \
# define LOGV(...) \
Log(__FILE__, __func__, __LINE__, wvutil::CDM_LOG_VERBOSE, __VA_ARGS__)
# endif
#endif
} // namespace wvutil

View File

@@ -21,7 +21,7 @@
using ssize_t = SSIZE_T;
inline void sleep(int seconds) { Sleep(seconds * 1000); }
CORE_UTIL_EXPORT int setenv(const char* key, const char* value, int overwrite);
int setenv(const char* key, const char* value, int overwrite);
#else
# include <arpa/inet.h>
# include <sys/types.h>

View File

@@ -16,7 +16,7 @@
namespace wvutil {
// A simple reader-writer mutex implementation that mimics the one from C++17
class CORE_UTIL_EXPORT shared_mutex {
class shared_mutex {
public:
shared_mutex() : reader_count_(0), has_writer_(false) {}
~shared_mutex();

View File

@@ -15,53 +15,46 @@
namespace wvutil {
// ASCII hex to Binary conversion.
CORE_UTIL_EXPORT std::vector<uint8_t> a2b_hex(const std::string& b);
CORE_UTIL_EXPORT std::vector<uint8_t> a2b_hex(const std::string& label,
const std::string& b);
CORE_UTIL_EXPORT std::string a2bs_hex(const std::string& b);
std::vector<uint8_t> a2b_hex(const std::string& b);
std::vector<uint8_t> a2b_hex(const std::string& label,
const std::string& b);
std::string a2bs_hex(const std::string& b);
// Binary to ASCII hex conversion. The default versions limit output to 2k to
// protect us from log spam. The unlimited version has no length limit.
CORE_UTIL_EXPORT std::string b2a_hex(const std::vector<uint8_t>& b);
CORE_UTIL_EXPORT std::string unlimited_b2a_hex(const std::vector<uint8_t>& b);
CORE_UTIL_EXPORT std::string b2a_hex(const std::string& b);
CORE_UTIL_EXPORT std::string unlimited_b2a_hex(const std::string& b);
CORE_UTIL_EXPORT std::string HexEncode(const uint8_t* bytes, size_t size);
CORE_UTIL_EXPORT std::string UnlimitedHexEncode(const uint8_t* bytes,
size_t size);
std::string b2a_hex(const std::vector<uint8_t>& b);
std::string unlimited_b2a_hex(const std::vector<uint8_t>& b);
std::string b2a_hex(const std::string& b);
std::string unlimited_b2a_hex(const std::string& b);
std::string HexEncode(const uint8_t* bytes, size_t size);
std::string UnlimitedHexEncode(const uint8_t* bytes, size_t size);
// Base64 encoding/decoding.
// Converts binary data into the ASCII Base64 character set and vice
// versa using the encoding rules defined in RFC4648 section 4.
CORE_UTIL_EXPORT std::string Base64Encode(
const std::vector<uint8_t>& bin_input);
CORE_UTIL_EXPORT std::string Base64Encode(const std::string& bin_input);
CORE_UTIL_EXPORT std::vector<uint8_t> Base64Decode(
const std::string& bin_input);
std::string Base64Encode(const std::vector<uint8_t>& bin_input);
std::string Base64Encode(const std::string& bin_input);
std::vector<uint8_t> Base64Decode(const std::string& bin_input);
// URL-Safe Base64 encoding/decoding.
// Converts binary data into the URL/Filename safe ASCII Base64
// character set and vice versa using the encoding rules defined in
// RFC4648 section 5.
CORE_UTIL_EXPORT std::string Base64SafeEncode(
const std::vector<uint8_t>& bin_input);
CORE_UTIL_EXPORT std::string Base64SafeEncode(const std::string& bin_input);
CORE_UTIL_EXPORT std::vector<uint8_t> Base64SafeDecode(
const std::string& bin_input);
std::string Base64SafeEncode(const std::vector<uint8_t>& bin_input);
std::string Base64SafeEncode(const std::string& bin_input);
std::vector<uint8_t> Base64SafeDecode(const std::string& bin_input);
// URL-Safe Base64 encoding without padding.
// Similar to Base64SafeEncode(), without any padding character '='
// at the end.
CORE_UTIL_EXPORT std::string Base64SafeEncodeNoPad(
const std::vector<uint8_t>& bin_input);
CORE_UTIL_EXPORT std::string Base64SafeEncodeNoPad(
const std::string& bin_input);
std::string Base64SafeEncodeNoPad(const std::vector<uint8_t>& bin_input);
std::string Base64SafeEncodeNoPad(const std::string& bin_input);
// Host to Network/Network to Host conversion.
CORE_UTIL_EXPORT int64_t htonll64(int64_t x);
CORE_UTIL_EXPORT inline int64_t ntohll64(int64_t x) { return htonll64(x); }
int64_t htonll64(int64_t x);
inline int64_t ntohll64(int64_t x) { return htonll64(x); }
// Encode unsigned integer into a big endian formatted string.
CORE_UTIL_EXPORT std::string EncodeUint32(uint32_t u);
std::string EncodeUint32(uint32_t u);
} // namespace wvutil

View File

@@ -9,23 +9,11 @@
#ifdef _WIN32
# ifdef CORE_UTIL_IMPLEMENTATION
# define CORE_UTIL_EXPORT __declspec(dllexport)
# else
# define CORE_UTIL_EXPORT __declspec(dllimport)
# endif
# define CORE_UTIL_IGNORE_DEPRECATED
# define CORE_UTIL_RESTORE_WARNINGS
#else
# ifdef CORE_UTIL_IMPLEMENTATION
# define CORE_UTIL_EXPORT __attribute__((visibility("default")))
# else
# define CORE_UTIL_EXPORT
# endif
# ifdef __GNUC__
# define CORE_UTIL_IGNORE_DEPRECATED \
_Pragma("GCC diagnostic push") \

View File

@@ -3,17 +3,15 @@
# Agreement.
{
'conditions': [
[
'privacy_crypto_impl=="openssl"', {
'libraries': [
'-lcrypto',
],
}, # privacy_crypto_impl=="openssl"
'privacy_crypto_impl=="boringssl" or privacy_crypto_impl=="apple"', {
'dependencies': [
'<(boringssl_libcrypto_path)',
], # dependencies
}, # privacy_crypto_impl=="boringssl" or privacy_crypto_impl=="apple"
],
['privacy_crypto_impl=="openssl"', {
'libraries': [
'-lcrypto',
],
}],
['privacy_crypto_impl=="boringssl" or privacy_crypto_impl=="apple"', {
'dependencies': [
'<(boringssl_libcrypto_path)',
], # dependencies
}],
], # conditions
}

View File

@@ -3,18 +3,16 @@
# Agreement.
{
'conditions': [
[
'privacy_crypto_impl=="openssl"', {
'libraries': [
'-lcrypto',
'-lssl',
],
}, # privacy_crypto_impl=="openssl"
'privacy_crypto_impl=="boringssl" or privacy_crypto_impl=="apple"', {
'dependencies': [
'<(boringssl_libssl_path)',
], # dependencies
}, # privacy_crypto_impl=="boringssl" or privacy_crypto_impl=="apple"
],
['privacy_crypto_impl=="openssl"', {
'libraries': [
'-lcrypto',
'-lssl',
],
}],
['privacy_crypto_impl=="boringssl" or privacy_crypto_impl=="apple"', {
'dependencies': [
'<(boringssl_libssl_path)',
], # dependencies
}],
], # conditions
}

View File

@@ -2,7 +2,9 @@
// source code may only be used and distributed under the Widevine License
// Agreement.
//
// Clock - A fake clock just for running tests.
// Clock - A fake clock just for running tests. This is used when running
// OEMCrypto unit tests. It is not used when tests include the CE CDM source
// code because that uses the clock in cdm/test_host.cpp instead.
#include <chrono>

View File

@@ -14,6 +14,7 @@
#endif
#include <errno.h>
#include <inttypes.h>
#include <string.h>
#include <unistd.h>
@@ -53,6 +54,18 @@ void TestSleep::Sleep(unsigned int seconds) {
if (callback_ != nullptr) callback_->ElapseTime(milliseconds);
}
void TestSleep::SleepUntil(int64_t desired_time) {
SyncFakeClock();
const int64_t now = Clock().GetCurrentTime();
if (desired_time < now) {
LOGE("Test Clock skew sleeping from time %" PRId64 " to %" PRId64, now,
desired_time);
return;
}
const unsigned int sleep_time = static_cast<unsigned int>(desired_time - now);
TestSleep::Sleep(sleep_time);
}
void TestSleep::SyncFakeClock() {
// Syncing can be done by sleeping 0 seconds.
Sleep(0);

View File

@@ -13,7 +13,9 @@ namespace wvutil {
class TestSleep {
public:
// The callback is called when the clock should be advanced.
// The callback is called when the test clock should be advanced. If the
// system uses a real clock, it is used to sync the real and test
// clock. Otherwise it is used to simulate sleep in the test clock.
class CallBack {
public:
virtual void ElapseTime(int64_t milliseconds) = 0;
@@ -27,6 +29,9 @@ class TestSleep {
// callback exists, this calls the callback.
static void Sleep(unsigned int seconds);
// Like sleep, above, except it sleeps until the specified time.
static void SleepUntil(int64_t desired_time);
// If we are using a real clock and a fake clock, then the real clock advances
// a little while we are doing work, but the fake one only advances when we
// sleep. This function advances the fake clock to be in sync with the real