Snap for 4587185 from 4e5599d4ff to pi-release

Change-Id: I9b0f0c5e56203739a8cfcf29d5921630fa61548a
This commit is contained in:
android-build-team Robot
2018-02-06 08:22:59 +00:00
5 changed files with 46 additions and 29 deletions

View File

@@ -1,5 +1,6 @@
// Copyright 2017 Google Inc. All Rights Reserved. // Copyright 2017 Google Inc. All Rights Reserved.
#include <arpa/inet.h>
#include <string> #include <string>
#include <gtest/gtest.h> #include <gtest/gtest.h>
@@ -290,6 +291,17 @@ class CryptoSessionMetricsTest : public testing::Test {
return true; return true;
} }
uint32_t FindKeyboxSystemID() {
OEMCryptoResult sts;
uint8_t key_data[256];
size_t key_data_len = sizeof(key_data);
sts = OEMCrypto_GetKeyData(key_data, &key_data_len, kLevelDefault);
if (sts != OEMCrypto_SUCCESS) return 0;
uint32_t* data = reinterpret_cast<uint32_t*>(key_data);
uint32_t system_id = htonl(data[1]);
return system_id;
}
private: private:
static std::pair<std::string, drm_metrics::MetricsGroup::Metric> static std::pair<std::string, drm_metrics::MetricsGroup::Metric>
MakeMetricPair(const drm_metrics::MetricsGroup::Metric& metric) { MakeMetricPair(const drm_metrics::MetricsGroup::Metric& metric) {
@@ -337,9 +349,10 @@ TEST_F(CryptoSessionMetricsTest, OpenSessionValidMetrics) {
CdmClientTokenType token_type = session.GetPreProvisionTokenType(); CdmClientTokenType token_type = session.GetPreProvisionTokenType();
if (token_type == kClientTokenKeybox) { if (token_type == kClientTokenKeybox) {
uint32_t system_id = FindKeyboxSystemID();
EXPECT_TRUE(FindMetric( EXPECT_TRUE(FindMetric(
metric_map, "/drm/widevine/crypto_session/system_id", &metric)); metric_map, "/drm/widevine/crypto_session/system_id", &metric));
EXPECT_EQ(metric.value().int_value(), 4121); EXPECT_EQ(metric.value().int_value(), system_id);
EXPECT_TRUE(FindMetric( EXPECT_TRUE(FindMetric(
metric_map, metric_map,
@@ -363,7 +376,11 @@ TEST_F(CryptoSessionMetricsTest, OpenSessionValidMetrics) {
} else if (token_type == kClientTokenOemCert) { } else if (token_type == kClientTokenOemCert) {
EXPECT_TRUE(FindMetric( EXPECT_TRUE(FindMetric(
metric_map, "/drm/widevine/crypto_session/system_id", &metric)); metric_map, "/drm/widevine/crypto_session/system_id", &metric));
EXPECT_EQ(metric.value().int_value(), 7346); // Recent devices all have a system id between 1k and 6 or 7k. Errors we
// are trying to catch are 0, byte swapped 32 bit numbers, or garbage. These
// errors will most likely be outside the range of 1000 to 2^16.
EXPECT_LE(1000, metric.value().int_value());
EXPECT_GT(0x10000, metric.value().int_value());
EXPECT_TRUE(FindMetric( EXPECT_TRUE(FindMetric(
metric_map, metric_map,
@@ -417,7 +434,8 @@ TEST_F(CryptoSessionMetricsTest, GetProvisioningTokenValidMetrics) {
EXPECT_TRUE(FindMetric( EXPECT_TRUE(FindMetric(
metric_map, "/drm/widevine/crypto_session/system_id", metric_map, "/drm/widevine/crypto_session/system_id",
&metric)); &metric));
EXPECT_EQ(metric.value().int_value(), 4121); uint32_t system_id = FindKeyboxSystemID();
EXPECT_EQ(metric.value().int_value(), system_id);
EXPECT_TRUE(FindMetric( EXPECT_TRUE(FindMetric(
metric_map, metric_map,
"/drm/widevine/oemcrypto/get_key_data/time/count" "/drm/widevine/oemcrypto/get_key_data/time/count"
@@ -433,7 +451,11 @@ TEST_F(CryptoSessionMetricsTest, GetProvisioningTokenValidMetrics) {
EXPECT_TRUE(FindMetric( EXPECT_TRUE(FindMetric(
metric_map, "/drm/widevine/crypto_session/system_id", metric_map, "/drm/widevine/crypto_session/system_id",
&metric)); &metric));
EXPECT_EQ(metric.value().int_value(), 7346); // Recent devices all have a system id between 1k and 6 or 7k. Errors we
// are trying to catch are 0, byte swapped 32 bit numbers, or garbage. These
// errors will most likely be outside the range of 1000 to 2^16.
EXPECT_LE(1000, metric.value().int_value());
EXPECT_GT(0x10000, metric.value().int_value());
EXPECT_TRUE(FindMetric( EXPECT_TRUE(FindMetric(
metric_map, metric_map,
"/drm/widevine/oemcrypto/get_oem_public_certificate/count" "/drm/widevine/oemcrypto/get_oem_public_certificate/count"

View File

@@ -115,7 +115,7 @@ extern "C" OEMCryptoResult OEMCrypto_OpenSession(OEMCrypto_SESSION* session) {
SessionId sid = crypto_engine->CreateSession(); SessionId sid = crypto_engine->CreateSession();
*session = (OEMCrypto_SESSION)sid; *session = (OEMCrypto_SESSION)sid;
if (LogCategoryEnabled(kLoggingTraceOEMCryptoCalls)) { if (LogCategoryEnabled(kLoggingTraceOEMCryptoCalls)) {
LOGD("[OEMCrypto_OpenSession(): SID=%08x]", sid); LOGD("[OEMCrypto_OpenSession(): SID=%08X]", sid);
} }
return OEMCrypto_SUCCESS; return OEMCrypto_SUCCESS;
} }
@@ -238,7 +238,7 @@ extern "C" OEMCryptoResult OEMCrypto_GenerateNonce(OEMCrypto_SESSION session,
session_ctx->AddNonce(nonce_value); session_ctx->AddNonce(nonce_value);
*nonce = nonce_value; *nonce = nonce_value;
if (LogCategoryEnabled(kLoggingTraceOEMCryptoCalls)) { if (LogCategoryEnabled(kLoggingTraceOEMCryptoCalls)) {
LOGI("nonce = %08x\n", nonce_value); LOGI("nonce = %08X\n", nonce_value);
} }
return OEMCrypto_SUCCESS; return OEMCrypto_SUCCESS;
} }

View File

@@ -14,20 +14,19 @@
#include "oemcrypto_logging.h" #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 { 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() { void RSA_shared_ptr::reset() {
if (rsa_key_ && key_owned_) { if (rsa_key_ && key_owned_) {
RSA_free(rsa_key_); 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); pkcs8_pki = d2i_PKCS8_PRIV_KEY_INFO_bio(bio, NULL);
if (pkcs8_pki == NULL) { if (pkcs8_pki == NULL) {
LOGE("[LoadPkcs8RsaKey(): d2i_PKCS8_PRIV_KEY_INFO_bio returned NULL]"); LOGE("[LoadPkcs8RsaKey(): d2i_PKCS8_PRIV_KEY_INFO_bio returned NULL]");
dump_boringssl_error();
success = false; success = false;
} }
} }
@@ -60,6 +60,7 @@ bool RSA_shared_ptr::LoadPkcs8RsaKey(const uint8_t* buffer, size_t length) {
evp = EVP_PKCS82PKEY(pkcs8_pki); evp = EVP_PKCS82PKEY(pkcs8_pki);
if (evp == NULL) { if (evp == NULL) {
LOGE("[LoadPkcs8RsaKey(): EVP_PKCS82PKEY returned NULL]"); LOGE("[LoadPkcs8RsaKey(): EVP_PKCS82PKEY returned NULL]");
dump_boringssl_error();
success = false; success = false;
} }
} }
@@ -86,11 +87,11 @@ bool RSA_shared_ptr::LoadPkcs8RsaKey(const uint8_t* buffer, size_t length) {
return true; return true;
case 0: // not valid. case 0: // not valid.
LOGE("[LoadPkcs8RsaKey(): rsa key not valid]"); LOGE("[LoadPkcs8RsaKey(): rsa key not valid]");
dump_openssl_error(); dump_boringssl_error();
return false; return false;
default: // -1 == check failed. default: // -1 == check failed.
LOGE("[LoadPkcs8RsaKey(): error checking rsa key]"); LOGE("[LoadPkcs8RsaKey(): error checking rsa key]");
dump_openssl_error(); dump_boringssl_error();
return false; return false;
} }
} }

View File

@@ -32,6 +32,9 @@ class RSA_shared_ptr {
bool key_owned_; bool key_owned_;
}; };
// Log errors from BoringSSL.
void dump_boringssl_error();
} // namespace wvoec_mock } // namespace wvoec_mock
#endif // OEMCRYPTO_RSA_KEY_SHARED_H_ #endif // OEMCRYPTO_RSA_KEY_SHARED_H_

View File

@@ -43,15 +43,6 @@ void ctr128_inc64(uint8_t* counter) {
if (++counter[--n] != 0) return; if (++counter[--n] != 0) return;
} while (n > 8); } 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
namespace wvoec_mock { namespace wvoec_mock {