From 64b3103017cb9038c5fb7e3601f51c6a458bed06 Mon Sep 17 00:00:00 2001 From: Benoit Goby Date: Fri, 31 Aug 2012 12:14:21 -0700 Subject: [PATCH] adb: Create private key with 0600 mode Changed key name to force generating new pairs. Bug: 7092477 Change-Id: I680cb9dd1896ae52b2b29d63533f966e033d823f --- adb/adb.h | 2 +- adb/adb_auth_host.c | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/adb/adb.h b/adb/adb.h index 5e9a0fb32..9da8af8bf 100644 --- a/adb/adb.h +++ b/adb/adb.h @@ -36,7 +36,7 @@ #define ADB_VERSION_MAJOR 1 // Used for help/version information #define ADB_VERSION_MINOR 0 // Used for help/version information -#define ADB_SERVER_VERSION 30 // Increment this when we want to force users to start a new adb server +#define ADB_SERVER_VERSION 31 // Increment this when we want to force users to start a new adb server typedef struct amessage amessage; typedef struct apacket apacket; diff --git a/adb/adb_auth_host.c b/adb/adb_auth_host.c index 99dcfcbab..9039d42eb 100644 --- a/adb/adb_auth_host.c +++ b/adb/adb_auth_host.c @@ -48,7 +48,7 @@ #define TRACE_TAG TRACE_AUTH #define ANDROID_PATH ".android" -#define ADB_KEY_FILE "adb_key" +#define ADB_KEY_FILE "adbkey" struct adb_private_key { @@ -176,6 +176,7 @@ static int generate_key(const char *file) EVP_PKEY* pkey = EVP_PKEY_new(); BIGNUM* exponent = BN_new(); RSA* rsa = RSA_new(); + mode_t old_mask; FILE *f = NULL; int ret = 0; @@ -190,12 +191,17 @@ static int generate_key(const char *file) RSA_generate_key_ex(rsa, 2048, exponent, NULL); EVP_PKEY_set1_RSA(pkey, rsa); + old_mask = umask(077); + f = fopen(file, "w"); if (!f) { D("Failed to open '%s'\n", file); + umask(old_mask); goto out; } + umask(old_mask); + if (!PEM_write_PrivateKey(f, pkey, NULL, NULL, 0, NULL, NULL)) { D("Failed to write key\n"); goto out;