Add build info API to OEMCrypto

Merge from master branch of Widevine repo of http://go/wvgerrit/66065
Merge from oemcrypto-v15 branch of Widevine repo of http://go/wvgerrit/63080

This is for the reference code, the unit tests, and the oemcrypto adapter.

Bug: 116414218
Test: unit tests
Test: tested as part of http://go/ag/5501993

Change-Id: I05a631f6cfcf1584a748b3a0c9ae48633893589f
This commit is contained in:
Fred Gylys-Colwell
2018-11-12 14:11:55 -08:00
parent f2edb8f2dd
commit f3e9d84484
4 changed files with 39 additions and 2 deletions

View File

@@ -56,6 +56,7 @@ OEMCryptoResult OEMCrypto_CreateOldUsageEntry(SecurityLevel level,
uint8_t* server_mac_key, uint8_t* client_mac_key, const uint8_t* pst, uint8_t* server_mac_key, uint8_t* client_mac_key, const uint8_t* pst,
size_t pst_length); size_t pst_length);
uint32_t OEMCrypto_GetAnalogOutputFlags(SecurityLevel level); uint32_t OEMCrypto_GetAnalogOutputFlags(SecurityLevel level);
const char* OEMCrypto_BuildInformation(SecurityLevel level);
} // namespace wvcdm } // namespace wvcdm
/* The following functions are deprecated in OEMCrypto v13. They are defined /* The following functions are deprecated in OEMCrypto v13. They are defined

View File

@@ -264,6 +264,7 @@ typedef OEMCryptoResult (*L1_CreateOldUsageEntry_t)(
uint8_t* server_mac_key, uint8_t* client_mac_key, const uint8_t* pst, uint8_t* server_mac_key, uint8_t* client_mac_key, const uint8_t* pst,
size_t pst_length); size_t pst_length);
typedef uint32_t (*L1_GetAnalogOutputFlags_t)(void); typedef uint32_t (*L1_GetAnalogOutputFlags_t)(void);
typedef const char* (*L1_BuildInformation_t)(void);
struct FunctionPointers { struct FunctionPointers {
uint32_t version; uint32_t version;
@@ -330,6 +331,7 @@ struct FunctionPointers {
L1_CopyOldUsageEntry_t CopyOldUsageEntry; L1_CopyOldUsageEntry_t CopyOldUsageEntry;
L1_CreateOldUsageEntry_t CreateOldUsageEntry; L1_CreateOldUsageEntry_t CreateOldUsageEntry;
L1_GetAnalogOutputFlags_t GetAnalogOutputFlags; L1_GetAnalogOutputFlags_t GetAnalogOutputFlags;
L1_BuildInformation_t BuildInformation;
L1_LoadKeys_V8_t LoadKeys_V8; L1_LoadKeys_V8_t LoadKeys_V8;
L1_GenerateRSASignature_V8_t GenerateRSASignature_V8; L1_GenerateRSASignature_V8_t GenerateRSASignature_V8;
@@ -567,6 +569,10 @@ class Adapter {
WatchDog *watcher = new WatchDog(); WatchDog *watcher = new WatchDog();
watcher->CheckForPreviousFailure(&metrics); watcher->CheckForPreviousFailure(&metrics);
watcher->StartThread(); watcher->StartThread();
if (level3_.BuildInformation) {
LOGI("Level 3 Build Info (v%d): %s", level3_.version,
level3_.BuildInformation());
}
OEMCryptoResult result = watcher->WaitForStatusAndCleanUp(); OEMCryptoResult result = watcher->WaitForStatusAndCleanUp();
if (Level3_IsInApp()) { if (Level3_IsInApp()) {
metrics.SetInitializationMode( metrics.SetInitializationMode(
@@ -599,6 +605,10 @@ class Adapter {
} }
if (LoadLevel1(&metrics)) { if (LoadLevel1(&metrics)) {
LOGD("OEMCrypto_Initialize Level 1 success. I will use level 1."); LOGD("OEMCrypto_Initialize Level 1 success. I will use level 1.");
if (level1_.BuildInformation) {
LOGI("Level 1 Build Info (v%d): %s", level1_.version,
level1_.BuildInformation());
}
} else { } else {
level1_ = FunctionPointers(); // revert to all null pointers. level1_ = FunctionPointers(); // revert to all null pointers.
level1_valid_ = false; level1_valid_ = false;
@@ -677,6 +687,7 @@ class Adapter {
LOOKUP( 9, 9, GetHDCPCapability_V9, OEMCrypto_GetHDCPCapability_V9); LOOKUP( 9, 9, GetHDCPCapability_V9, OEMCrypto_GetHDCPCapability_V9);
LOOKUP_ALL(10, GetHDCPCapability, OEMCrypto_GetHDCPCapability); LOOKUP_ALL(10, GetHDCPCapability, OEMCrypto_GetHDCPCapability);
LOOKUP_ALL(14, GetAnalogOutputFlags, OEMCrypto_GetAnalogOutputFlags); LOOKUP_ALL(14, GetAnalogOutputFlags, OEMCrypto_GetAnalogOutputFlags);
LOOKUP_ALL(15, BuildInformation, OEMCrypto_BuildInformation);
LOOKUP_ALL( 8, GetKeyData, OEMCrypto_GetKeyData); LOOKUP_ALL( 8, GetKeyData, OEMCrypto_GetKeyData);
LOOKUP_ALL(10, GetMaxNumberOfSessions, OEMCrypto_GetMaxNumberOfSessions); LOOKUP_ALL(10, GetMaxNumberOfSessions, OEMCrypto_GetMaxNumberOfSessions);
LOOKUP_ALL(10, GetNumberOfOpenSessions, OEMCrypto_GetNumberOfOpenSessions); LOOKUP_ALL(10, GetNumberOfOpenSessions, OEMCrypto_GetNumberOfOpenSessions);
@@ -820,6 +831,7 @@ class Adapter {
level3_.SecurityLevel = Level3_SecurityLevel; level3_.SecurityLevel = Level3_SecurityLevel;
level3_.GetHDCPCapability = Level3_GetHDCPCapability; level3_.GetHDCPCapability = Level3_GetHDCPCapability;
level3_.GetAnalogOutputFlags = Level3_GetAnalogOutputFlags; level3_.GetAnalogOutputFlags = Level3_GetAnalogOutputFlags;
// TODO(srujzs) level3_.BuildInformation = Level3_BuildInformation;
level3_.SupportsUsageTable = Level3_SupportsUsageTable; level3_.SupportsUsageTable = Level3_SupportsUsageTable;
level3_.IsAntiRollbackHwPresent = Level3_IsAntiRollbackHwPresent; level3_.IsAntiRollbackHwPresent = Level3_IsAntiRollbackHwPresent;
level3_.GetNumberOfOpenSessions = Level3_GetNumberOfOpenSessions; level3_.GetNumberOfOpenSessions = Level3_GetNumberOfOpenSessions;
@@ -1066,6 +1078,15 @@ uint32_t OEMCrypto_GetAnalogOutputFlags(SecurityLevel level) {
return fcn->GetAnalogOutputFlags(); return fcn->GetAnalogOutputFlags();
} }
const char* OEMCrypto_BuildInformation(SecurityLevel level) {
if (!gAdapter.get()) return "<not initialized>";
const FunctionPointers* fcn = gAdapter->GetFunctionPointers(level);
if (!fcn) return "<not initialized>";
if (fcn->version < 14) return "pre v15";
if (fcn->BuildInformation == NULL) return "unknown";
return fcn->BuildInformation();
}
bool OEMCrypto_SupportsUsageTable(SecurityLevel level) { bool OEMCrypto_SupportsUsageTable(SecurityLevel level) {
if (!gAdapter.get()) return false; if (!gAdapter.get()) return false;
const FunctionPointers* fcn = gAdapter->GetFunctionPointers(level); const FunctionPointers* fcn = gAdapter->GetFunctionPointers(level);
@@ -1231,6 +1252,10 @@ extern "C" uint32_t OEMCrypto_GetAnalogOutputFlags() {
return OEMCrypto_GetAnalogOutputFlags(kLevelDefault); return OEMCrypto_GetAnalogOutputFlags(kLevelDefault);
} }
extern "C" const char* OEMCrypto_BuildInformation(){
return OEMCrypto_BuildInformation(kLevelDefault);
}
extern "C" OEMCryptoResult OEMCrypto_LoadKeys_Back_Compat( extern "C" OEMCryptoResult OEMCrypto_LoadKeys_Back_Compat(
OEMCrypto_SESSION session, const uint8_t* message, size_t message_length, OEMCrypto_SESSION session, const uint8_t* message, size_t message_length,
const uint8_t* signature, size_t signature_length, const uint8_t* signature, size_t signature_length,

View File

@@ -1148,6 +1148,10 @@ extern "C" uint32_t OEMCrypto_GetAnalogOutputFlags() {
return crypto_engine->analog_output_flags(); return crypto_engine->analog_output_flags();
} }
extern "C" const char* OEMCrypto_BuildInformation() {
return "OEMCrypto Ref Code " __DATE__ " " __TIME__;
}
extern "C" bool OEMCrypto_SupportsUsageTable() { extern "C" bool OEMCrypto_SupportsUsageTable() {
if (!crypto_engine) { if (!crypto_engine) {
LOGE("OEMCrypto_SupportsUsageTable: OEMCrypto Not Initialized."); LOGE("OEMCrypto_SupportsUsageTable: OEMCrypto Not Initialized.");

View File

@@ -112,6 +112,13 @@ TEST_F(OEMCryptoClientTest, VersionNumber) {
} else { } else {
cout << " OEMCrypto does not support usage tables." << endl; cout << " OEMCrypto does not support usage tables." << endl;
} }
if (version >= 15) {
const char* build_info = OEMCrypto_BuildInformation();
ASSERT_TRUE(build_info != NULL);
ASSERT_TRUE(strnlen(build_info, 256) <= 256)
<< "BuildInformation should be a short printable string.";
cout << " BuildInformation: " << build_info << endl;
}
ASSERT_GE(version, 8u); ASSERT_GE(version, 8u);
ASSERT_LE(version, 15u); ASSERT_LE(version, 15u);
} }