From ee43f9b411d9debf35c7629748cad120e5678958 Mon Sep 17 00:00:00 2001 From: Fred Gylys-Colwell Date: Mon, 5 Feb 2018 11:53:27 -0800 Subject: [PATCH] Clean symbol export on mod mock Merge from Widevine repo of http://go/wvgerrit/42281 This cleans up some of the oemcrypto mock code. This code is only used for testing. bug: 72831885 bug: 69271232 Change-Id: I8add162839d6febe56a89df84e8ae0cf0b97a2d9 --- .../oemcrypto/mock/src/oemcrypto_mock.cpp | 4 +-- .../mock/src/oemcrypto_rsa_key_shared.cpp | 29 ++++++++++--------- .../mock/src/oemcrypto_rsa_key_shared.h | 3 ++ .../oemcrypto/mock/src/oemcrypto_session.cpp | 9 ------ 4 files changed, 20 insertions(+), 25 deletions(-) diff --git a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_mock.cpp b/libwvdrmengine/oemcrypto/mock/src/oemcrypto_mock.cpp index 09f1ada6..ad1dd824 100644 --- a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_mock.cpp +++ b/libwvdrmengine/oemcrypto/mock/src/oemcrypto_mock.cpp @@ -115,7 +115,7 @@ extern "C" OEMCryptoResult OEMCrypto_OpenSession(OEMCrypto_SESSION* session) { SessionId sid = crypto_engine->CreateSession(); *session = (OEMCrypto_SESSION)sid; if (LogCategoryEnabled(kLoggingTraceOEMCryptoCalls)) { - LOGD("[OEMCrypto_OpenSession(): SID=%08x]", sid); + LOGD("[OEMCrypto_OpenSession(): SID=%08X]", sid); } return OEMCrypto_SUCCESS; } @@ -238,7 +238,7 @@ extern "C" OEMCryptoResult OEMCrypto_GenerateNonce(OEMCrypto_SESSION session, session_ctx->AddNonce(nonce_value); *nonce = nonce_value; if (LogCategoryEnabled(kLoggingTraceOEMCryptoCalls)) { - LOGI("nonce = %08x\n", nonce_value); + LOGI("nonce = %08X\n", nonce_value); } return OEMCrypto_SUCCESS; } diff --git a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_rsa_key_shared.cpp b/libwvdrmengine/oemcrypto/mock/src/oemcrypto_rsa_key_shared.cpp index ff65577f..ebba9341 100644 --- a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_rsa_key_shared.cpp +++ b/libwvdrmengine/oemcrypto/mock/src/oemcrypto_rsa_key_shared.cpp @@ -14,20 +14,19 @@ #include "oemcrypto_logging.h" -namespace { - -void dump_openssl_error() { - while (unsigned long err = ERR_get_error()) { - char buffer[120]; - LOGE("openssl error -- %lu -- %s", - err, ERR_error_string(err, buffer)); - } -} - -} // namespace - namespace wvoec_mock { +void dump_boringssl_error() { + int count = 0; + while (unsigned long err = ERR_get_error()) { + count++; + char buffer[120]; + ERR_error_string_n(err, buffer, sizeof(buffer)); + LOGE("BoringSSL Error %d -- %lu -- %s", count, err, buffer); + } + LOGE("Reported %d BoringSSL Errors", count); +} + void RSA_shared_ptr::reset() { if (rsa_key_ && key_owned_) { RSA_free(rsa_key_); @@ -52,6 +51,7 @@ bool RSA_shared_ptr::LoadPkcs8RsaKey(const uint8_t* buffer, size_t length) { pkcs8_pki = d2i_PKCS8_PRIV_KEY_INFO_bio(bio, NULL); if (pkcs8_pki == NULL) { LOGE("[LoadPkcs8RsaKey(): d2i_PKCS8_PRIV_KEY_INFO_bio returned NULL]"); + dump_boringssl_error(); success = false; } } @@ -60,6 +60,7 @@ bool RSA_shared_ptr::LoadPkcs8RsaKey(const uint8_t* buffer, size_t length) { evp = EVP_PKCS82PKEY(pkcs8_pki); if (evp == NULL) { LOGE("[LoadPkcs8RsaKey(): EVP_PKCS82PKEY returned NULL]"); + dump_boringssl_error(); success = false; } } @@ -86,11 +87,11 @@ bool RSA_shared_ptr::LoadPkcs8RsaKey(const uint8_t* buffer, size_t length) { return true; case 0: // not valid. LOGE("[LoadPkcs8RsaKey(): rsa key not valid]"); - dump_openssl_error(); + dump_boringssl_error(); return false; default: // -1 == check failed. LOGE("[LoadPkcs8RsaKey(): error checking rsa key]"); - dump_openssl_error(); + dump_boringssl_error(); return false; } } diff --git a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_rsa_key_shared.h b/libwvdrmengine/oemcrypto/mock/src/oemcrypto_rsa_key_shared.h index 4a815e99..913b0216 100644 --- a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_rsa_key_shared.h +++ b/libwvdrmengine/oemcrypto/mock/src/oemcrypto_rsa_key_shared.h @@ -32,6 +32,9 @@ class RSA_shared_ptr { bool key_owned_; }; +// Log errors from BoringSSL. +void dump_boringssl_error(); + } // namespace wvoec_mock #endif // OEMCRYPTO_RSA_KEY_SHARED_H_ diff --git a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_session.cpp b/libwvdrmengine/oemcrypto/mock/src/oemcrypto_session.cpp index 4a809853..3750d6fd 100644 --- a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_session.cpp +++ b/libwvdrmengine/oemcrypto/mock/src/oemcrypto_session.cpp @@ -43,15 +43,6 @@ void ctr128_inc64(uint8_t* counter) { if (++counter[--n] != 0) return; } while (n > 8); } - -void dump_boringssl_error() { - while (unsigned long err = ERR_get_error()) { - char buffer[120]; - ERR_error_string_n(err, buffer, sizeof(buffer)); - LOGE("BoringSSL Error -- %lu -- %s", err, buffer); - } -} - } // namespace namespace wvoec_mock {