From 7fb14071252d7fcaab028dc3cbbe2bbc0a4f6c51 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Mon, 7 Oct 2019 08:21:58 -0700 Subject: [PATCH] adb: log more detail on failure to read keys. Before we just got "Failed to read key". After: adb E 10-07 08:20:14 258249 258249 auth.cpp:176] Failed to read key \ from '/usr/local/google/home/enh/.android/adbkey' 94390117965240:error:0900006e:PEM routines:OPENSSL_internal:NO_START_LINE:\ external/boringssl/src/crypto/pem/pem_lib.c:622:Expecting: ANY PRIVATE KEY Also fix the misleading "Failed to generate" message from adb_auth_init. Bug: http://b/141715453 Test: manually corrupted key; see above Change-Id: I6732ee6b683c8548d596d7c22eeddab8ce9a3cea --- adb/client/auth.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/adb/client/auth.cpp b/adb/client/auth.cpp index ed6a9a8aa..e8be784cd 100644 --- a/adb/client/auth.cpp +++ b/adb/client/auth.cpp @@ -173,7 +173,8 @@ static std::shared_ptr read_key_file(const std::string& file) { RSA* key = RSA_new(); if (!PEM_read_RSAPrivateKey(fp.get(), &key, nullptr, nullptr)) { - LOG(ERROR) << "Failed to read key"; + LOG(ERROR) << "Failed to read key from '" << file << "'"; + ERR_print_errors_fp(stderr); RSA_free(key); return nullptr; } @@ -249,7 +250,7 @@ static std::string get_user_key_path() { return adb_get_android_dir_path() + OS_PATH_SEPARATOR + "adbkey"; } -static bool generate_userkey() { +static bool load_userkey() { std::string path = get_user_key_path(); if (path.empty()) { PLOG(ERROR) << "Error getting user key filename"; @@ -435,8 +436,8 @@ static void adb_auth_inotify_init(const std::set& paths) { void adb_auth_init() { LOG(INFO) << "adb_auth_init..."; - if (!generate_userkey()) { - LOG(ERROR) << "Failed to generate user key"; + if (!load_userkey()) { + LOG(ERROR) << "Failed to load (or generate) user key"; return; }