am 59680145: Merge "adb: Create private key with 0600 mode" into jb-mr1-dev
* commit '59680145c85522e8b4b8cc928a48e105d966a44b': adb: Create private key with 0600 mode
This commit is contained in:
commit
07f6564551
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue