Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 02ef15f1 authored by Elliott Hughes's avatar Elliott Hughes Committed by Gerrit Code Review
Browse files

Merge "Introduce "adb keygen""

parents 3f760827 bea3f9c3
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -18,6 +18,7 @@
#define __ADB_AUTH_H
#define __ADB_AUTH_H


void adb_auth_init(void);
void adb_auth_init(void);
int adb_auth_keygen(const char* filename);
void adb_auth_verified(atransport *t);
void adb_auth_verified(atransport *t);


void send_auth_request(atransport *t);
void send_auth_request(atransport *t);
+24 −3
Original line number Original line Diff line number Diff line
@@ -114,18 +114,34 @@ out:
static void get_user_info(char *buf, size_t len)
static void get_user_info(char *buf, size_t len)
{
{
    char hostname[1024], username[1024];
    char hostname[1024], username[1024];
    int ret;
    int ret = -1;

    if (getenv("HOSTNAME") != NULL) {
        strncpy(hostname, getenv("HOSTNAME"), sizeof(hostname));
        hostname[sizeof(hostname)-1] = '\0';
        ret = 0;
    }


#ifndef _WIN32
#ifndef _WIN32
    ret = gethostname(hostname, sizeof(hostname));
    if (ret < 0)
    if (ret < 0)
        ret = gethostname(hostname, sizeof(hostname));
#endif
#endif
    if (ret < 0)
        strcpy(hostname, "unknown");
        strcpy(hostname, "unknown");


    ret = -1;

    if (getenv("LOGNAME") != NULL) {
        strncpy(username, getenv("LOGNAME"), sizeof(username));
        username[sizeof(username)-1] = '\0';
        ret = 0;
    }

#if !defined _WIN32 && !defined ADB_HOST_ON_TARGET
#if !defined _WIN32 && !defined ADB_HOST_ON_TARGET
    ret = getlogin_r(username, sizeof(username));
    if (ret < 0)
    if (ret < 0)
        ret = getlogin_r(username, sizeof(username));
#endif
#endif
    if (ret < 0)
        strcpy(username, "unknown");
        strcpy(username, "unknown");


    ret = snprintf(buf, len, " %s@%s", username, hostname);
    ret = snprintf(buf, len, " %s@%s", username, hostname);
@@ -436,6 +452,11 @@ int adb_auth_get_userkey(unsigned char *data, size_t len)
    return ret + 1;
    return ret + 1;
}
}


int adb_auth_keygen(const char* filename) {
    adb_trace_mask |= (1 << TRACE_AUTH);
    return (generate_key(filename) == 0);
}

void adb_auth_init(void)
void adb_auth_init(void)
{
{
    int ret;
    int ret;
+9 −0
Original line number Original line Diff line number Diff line
@@ -36,6 +36,7 @@
#define  TRACE_TAG  TRACE_ADB
#define  TRACE_TAG  TRACE_ADB
#include "adb.h"
#include "adb.h"
#include "adb_client.h"
#include "adb_client.h"
#include "adb_auth.h"
#include "file_sync_service.h"
#include "file_sync_service.h"


static int do_cmd(transport_type ttype, char* serial, char *cmd, ...);
static int do_cmd(transport_type ttype, char* serial, char *cmd, ...);
@@ -189,6 +190,9 @@ void help()
        "\n"
        "\n"
        "  adb restore <file>           - restore device contents from the <file> backup archive\n"
        "  adb restore <file>           - restore device contents from the <file> backup archive\n"
        "\n"
        "\n"
        "  adb keygen <file>            - generate adb public/private key. The private key is stored in <file>,\n"
        "                                 and the public key is stored in <file>.pub. Any existing files\n"
        "                                 are overwritten.\n"
        "  adb help                     - show this help message\n"
        "  adb help                     - show this help message\n"
        "  adb version                  - show version num\n"
        "  adb version                  - show version num\n"
        "\n"
        "\n"
@@ -1725,6 +1729,11 @@ top:
        return restore(argc, argv);
        return restore(argc, argv);
    }
    }


    if (!strcmp(argv[0], "keygen")) {
        if (argc < 2) return usage();
        return adb_auth_keygen(argv[1]);
    }

    if (!strcmp(argv[0], "jdwp")) {
    if (!strcmp(argv[0], "jdwp")) {
        int  fd = adb_connect("jdwp");
        int  fd = adb_connect("jdwp");
        if (fd >= 0) {
        if (fd >= 0) {