diff --git a/libwvdrmengine/oemcrypto/test/oemcrypto_basic_test.cpp b/libwvdrmengine/oemcrypto/test/oemcrypto_basic_test.cpp index d66f0b93..bdff8923 100644 --- a/libwvdrmengine/oemcrypto/test/oemcrypto_basic_test.cpp +++ b/libwvdrmengine/oemcrypto/test/oemcrypto_basic_test.cpp @@ -120,15 +120,39 @@ const char* HDCPCapabilityAsString(OEMCrypto_HDCP_Capability value) { // Return a printable string from data. If all the characters are printable, // then just use the string. Otherwise, convert to hex. std::string MaybeHex(const uint8_t* data, size_t length) { - for (size_t i = 0; i < length; i++) { + // Check for a early null termination. This is common for the device + // id in a keybox, which is padded with 0s. + const size_t c_len = strnlen(reinterpret_cast(data), length); + // If there is any nonzero after the first zero, then just use hex. + for (size_t i = c_len; i < length; i++) { + if (data[i] != 0) return "0x" + wvutil::HexEncode(data, length); + } + for (size_t i = 0; i < c_len; i++) { if (!isprint(data[i])) return "0x" + wvutil::HexEncode(data, length); } - return std::string(reinterpret_cast(data), length); + return std::string(reinterpret_cast(data), c_len); } + std::string MaybeHex(const std::vector& data) { return MaybeHex(data.data(), data.size()); } +// Get the Device's ID and return it in a printable format. +std::string GetDeviceId() { + OEMCryptoResult sts; + std::vector dev_id(128, 0); + size_t dev_id_len = dev_id.size(); + sts = OEMCrypto_GetDeviceID(dev_id.data(), &dev_id_len); + if (sts == OEMCrypto_ERROR_SHORT_BUFFER) { + if (dev_id_len <= 0) return "NO DEVICE ID"; + dev_id.resize(dev_id_len); + sts = OEMCrypto_GetDeviceID(dev_id.data(), &dev_id_len); + } + if (sts != OEMCrypto_SUCCESS) return "NO DEVICE ID"; + dev_id.resize(dev_id_len); + return MaybeHex(dev_id); +} + /// @addtogroup basic /// @{ @@ -175,6 +199,9 @@ TEST_F(OEMCryptoClientTest, VersionNumber) { uint32_t minor_version = OEMCrypto_MinorAPIVersion(); cout << " OEMCrypto API version is " << version << "." << minor_version << endl; + cout << " OEMCrypto Device ID is '" << GetDeviceId() << "'" + << endl; + if (OEMCrypto_SupportsUsageTable()) { cout << " OEMCrypto supports usage tables" << endl; } else { diff --git a/libwvdrmengine/oemcrypto/test/oemcrypto_cast_test.h b/libwvdrmengine/oemcrypto/test/oemcrypto_cast_test.h index fe18672d..9035da57 100644 --- a/libwvdrmengine/oemcrypto/test/oemcrypto_cast_test.h +++ b/libwvdrmengine/oemcrypto/test/oemcrypto_cast_test.h @@ -19,9 +19,6 @@ namespace wvoec { const char* HDCPCapabilityAsString(OEMCrypto_HDCP_Capability value); -std::string MaybeHex(const uint8_t* data, size_t length); -std::string MaybeHex(const std::vector& data); - // This test attempts to use alternate algorithms for loaded device certs. class OEMCryptoLoadsCertificateAlternates : public OEMCryptoLoadsCertificate { protected: