aboutsummaryrefslogtreecommitdiff
path: root/crypto
diff options
context:
space:
mode:
authorJoshua Duong <joshuaduong@google.com>2020-07-30 16:34:29 -0700
committerJoshua Duong <joshuaduong@google.com>2020-08-03 18:55:17 -0700
commit93b407cd0f8fac9ae3429b32c285f36b11736fa8 (patch)
tree979f6d62cee1324e58b0ad4bc9bddb868d5dba4f /crypto
parentb5c3bec70e574e53a21e69540c913f74b535a62f (diff)
downloadadb-93b407cd0f8fac9ae3429b32c285f36b11736fa8.tar.gz
[adb] Correctly read host/user name on Windows.
Bug: 162111908 Test: On linux/mac: HOSTNAME="" adb keygen mykey; cat mykey.pub # Also LOGNAME HOSTNAME="测试" adb keygen mykey; cat mykey.pub HOSTNAME="test" adb keygen mykey; cat mykey.pub Test: On Windows: set COMPUTERNAME=&& adb keygen mykey && powershell -command "get-content -encoding utf8 mykey.pub" # Also USERNAME set COMPUTERNAME=测试&& adb keygen mykey && powershell -command "get-content -encoding utf8 mykey.pub" set COMPUTERNAME=test&& adb keygen mykey && powershell -command "get-content -encoding utf8 mykey.pub" Change-Id: I62c952c511a620286aa4e05b1763361406e9f89a
Diffstat (limited to 'crypto')
-rw-r--r--crypto/Android.bp2
-rw-r--r--crypto/rsa_2048_key.cpp28
-rw-r--r--crypto/tests/Android.bp1
3 files changed, 8 insertions, 23 deletions
diff --git a/crypto/Android.bp b/crypto/Android.bp
index 9d14b030..e2c27f1f 100644
--- a/crypto/Android.bp
+++ b/crypto/Android.bp
@@ -48,6 +48,7 @@ cc_defaults {
shared_libs: [
"libadb_protos",
+ "libadb_sysdeps",
"libbase",
"liblog",
"libcrypto",
@@ -76,5 +77,6 @@ cc_library_static {
static_libs: [
"libadb_protos_static",
+ "libadb_sysdeps",
],
}
diff --git a/crypto/rsa_2048_key.cpp b/crypto/rsa_2048_key.cpp
index 7911af95..6d9ee305 100644
--- a/crypto/rsa_2048_key.cpp
+++ b/crypto/rsa_2048_key.cpp
@@ -20,32 +20,11 @@
#include <crypto_utils/android_pubkey.h>
#include <openssl/bn.h>
#include <openssl/rsa.h>
+#include <sysdeps/env.h>
namespace adb {
namespace crypto {
-namespace {
-std::string get_user_info() {
- std::string hostname;
- if (getenv("HOSTNAME")) hostname = getenv("HOSTNAME");
-#if !defined(_WIN32)
- char buf[64];
- if (hostname.empty() && gethostname(buf, sizeof(buf)) != -1) hostname = buf;
-#endif
- if (hostname.empty()) hostname = "unknown";
-
- std::string username;
- if (getenv("LOGNAME")) username = getenv("LOGNAME");
-#if !defined(_WIN32)
- if (username.empty() && getlogin()) username = getlogin();
-#endif
- if (username.empty()) hostname = "unknown";
-
- return " " + username + "@" + hostname;
-}
-
-} // namespace
-
bool CalculatePublicKey(std::string* out, RSA* private_key) {
uint8_t binary_key_data[ANDROID_PUBKEY_ENCODED_SIZE];
if (!android_pubkey_encode(private_key, binary_key_data, sizeof(binary_key_data))) {
@@ -63,7 +42,10 @@ bool CalculatePublicKey(std::string* out, RSA* private_key) {
size_t actual_length = EVP_EncodeBlock(reinterpret_cast<uint8_t*>(out->data()), binary_key_data,
sizeof(binary_key_data));
out->resize(actual_length);
- out->append(get_user_info());
+ out->append(" ");
+ out->append(sysdeps::GetLoginNameUTF8());
+ out->append("@");
+ out->append(sysdeps::GetHostNameUTF8());
return true;
}
diff --git a/crypto/tests/Android.bp b/crypto/tests/Android.bp
index b32dcf73..b0410554 100644
--- a/crypto/tests/Android.bp
+++ b/crypto/tests/Android.bp
@@ -35,6 +35,7 @@ cc_test {
static_libs: [
"libadb_crypto_static",
"libadb_protos_static",
+ "libadb_sysdeps",
],
test_suites: ["device-tests"],