Permalink
Browse files

adb: Create private key with 0600 mode

Changed key name to force generating new pairs.

Bug: 7092477
Change-Id: I680cb9dd1896ae52b2b29d63533f966e033d823f
  • Loading branch information...
1 parent 84ac402 commit 64b3103017cb9038c5fb7e3601f51c6a458bed06 @benoitgoby benoitgoby committed Aug 31, 2012
Showing with 8 additions and 2 deletions.
  1. +1 −1 adb/adb.h
  2. +7 −1 adb/adb_auth_host.c
View
@@ -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;
View
@@ -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;

0 comments on commit 64b3103

Please sign in to comment.