Clean up logging of device id
It helps in debugging and scanning logs if the device id is human readable. Bug: 299108238 Change-Id: Ib358b71514b2ddcc61bc6239ff802d87dad7d3ef
This commit is contained in:
committed by
Robert Shih
parent
7bb0b06c03
commit
b99d1213df
@@ -120,15 +120,39 @@ const char* HDCPCapabilityAsString(OEMCrypto_HDCP_Capability value) {
|
|||||||
// Return a printable string from data. If all the characters are printable,
|
// Return a printable string from data. If all the characters are printable,
|
||||||
// then just use the string. Otherwise, convert to hex.
|
// then just use the string. Otherwise, convert to hex.
|
||||||
std::string MaybeHex(const uint8_t* data, size_t length) {
|
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<const char*>(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);
|
if (!isprint(data[i])) return "0x" + wvutil::HexEncode(data, length);
|
||||||
}
|
}
|
||||||
return std::string(reinterpret_cast<const char*>(data), length);
|
return std::string(reinterpret_cast<const char*>(data), c_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string MaybeHex(const std::vector<uint8_t>& data) {
|
std::string MaybeHex(const std::vector<uint8_t>& data) {
|
||||||
return MaybeHex(data.data(), data.size());
|
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<uint8_t> 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
|
/// @addtogroup basic
|
||||||
/// @{
|
/// @{
|
||||||
|
|
||||||
@@ -175,6 +199,9 @@ TEST_F(OEMCryptoClientTest, VersionNumber) {
|
|||||||
uint32_t minor_version = OEMCrypto_MinorAPIVersion();
|
uint32_t minor_version = OEMCrypto_MinorAPIVersion();
|
||||||
cout << " OEMCrypto API version is " << version << "."
|
cout << " OEMCrypto API version is " << version << "."
|
||||||
<< minor_version << endl;
|
<< minor_version << endl;
|
||||||
|
cout << " OEMCrypto Device ID is '" << GetDeviceId() << "'"
|
||||||
|
<< endl;
|
||||||
|
|
||||||
if (OEMCrypto_SupportsUsageTable()) {
|
if (OEMCrypto_SupportsUsageTable()) {
|
||||||
cout << " OEMCrypto supports usage tables" << endl;
|
cout << " OEMCrypto supports usage tables" << endl;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -19,9 +19,6 @@ namespace wvoec {
|
|||||||
|
|
||||||
const char* HDCPCapabilityAsString(OEMCrypto_HDCP_Capability value);
|
const char* HDCPCapabilityAsString(OEMCrypto_HDCP_Capability value);
|
||||||
|
|
||||||
std::string MaybeHex(const uint8_t* data, size_t length);
|
|
||||||
std::string MaybeHex(const std::vector<uint8_t>& data);
|
|
||||||
|
|
||||||
// This test attempts to use alternate algorithms for loaded device certs.
|
// This test attempts to use alternate algorithms for loaded device certs.
|
||||||
class OEMCryptoLoadsCertificateAlternates : public OEMCryptoLoadsCertificate {
|
class OEMCryptoLoadsCertificateAlternates : public OEMCryptoLoadsCertificate {
|
||||||
protected:
|
protected:
|
||||||
|
|||||||
Reference in New Issue
Block a user