blob: 749fec21850acf96758bab17ad447773e943eb1c [file] [log] [blame]
Benoit Goby2cc19e42012-04-12 12:23:49 -07001/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Dan Albertdb6fe642015-03-19 15:21:08 -070017#define TRACE_TAG TRACE_AUTH
18
19#include "sysdeps.h"
20#include "adb_auth.h"
21
Benoit Goby2cc19e42012-04-12 12:23:49 -070022#include <stdio.h>
Christopher Ferris054d1702014-11-06 14:34:24 -080023#include <stdlib.h>
Dan Albertdb6fe642015-03-19 15:21:08 -070024#include <string.h>
Benoit Goby2cc19e42012-04-12 12:23:49 -070025
26#ifdef _WIN32
Christopher Ferris054d1702014-11-06 14:34:24 -080027# ifndef WIN32_LEAN_AND_MEAN
28# define WIN32_LEAN_AND_MEAN
29# endif
Benoit Goby2cc19e42012-04-12 12:23:49 -070030# include "windows.h"
31# include "shlobj.h"
32#else
33# include <sys/types.h>
34# include <sys/stat.h>
35# include <unistd.h>
36#endif
Benoit Goby2cc19e42012-04-12 12:23:49 -070037
Benoit Goby2cc19e42012-04-12 12:23:49 -070038#include "adb.h"
Benoit Goby2cc19e42012-04-12 12:23:49 -070039
40/* HACK: we need the RSAPublicKey struct
41 * but RSA_verify conflits with openssl */
42#define RSA_verify RSA_verify_mincrypt
43#include "mincrypt/rsa.h"
44#undef RSA_verify
45
Elliott Hughesfb2ba512015-04-24 23:02:00 -070046#include <base/strings.h>
Benoit Goby2cc19e42012-04-12 12:23:49 -070047#include <cutils/list.h>
48
49#include <openssl/evp.h>
50#include <openssl/objects.h>
51#include <openssl/pem.h>
52#include <openssl/rsa.h>
53#include <openssl/sha.h>
54
Adam Langley29f6cdb2014-09-03 14:34:47 -070055#if defined(OPENSSL_IS_BORINGSSL)
56#include <openssl/base64.h>
57#endif
58
Dan Albert3d978e62015-07-09 20:35:09 +000059#define ANDROID_PATH ".android"
60#define ADB_KEY_FILE "adbkey"
Benoit Goby2cc19e42012-04-12 12:23:49 -070061
Benoit Goby2cc19e42012-04-12 12:23:49 -070062struct adb_private_key {
63 struct listnode node;
64 RSA *rsa;
65};
66
67static struct listnode key_list;
68
69
70/* Convert OpenSSL RSA private key to android pre-computed RSAPublicKey format */
71static int RSA_to_RSAPublicKey(RSA *rsa, RSAPublicKey *pkey)
72{
73 int ret = 1;
74 unsigned int i;
75
76 BN_CTX* ctx = BN_CTX_new();
77 BIGNUM* r32 = BN_new();
78 BIGNUM* rr = BN_new();
79 BIGNUM* r = BN_new();
80 BIGNUM* rem = BN_new();
81 BIGNUM* n = BN_new();
82 BIGNUM* n0inv = BN_new();
83
84 if (RSA_size(rsa) != RSANUMBYTES) {
85 ret = 0;
86 goto out;
87 }
88
89 BN_set_bit(r32, 32);
90 BN_copy(n, rsa->n);
91 BN_set_bit(r, RSANUMWORDS * 32);
92 BN_mod_sqr(rr, r, n, ctx);
93 BN_div(NULL, rem, n, r32, ctx);
94 BN_mod_inverse(n0inv, rem, r32, ctx);
95
96 pkey->len = RSANUMWORDS;
97 pkey->n0inv = 0 - BN_get_word(n0inv);
98 for (i = 0; i < RSANUMWORDS; i++) {
99 BN_div(rr, rem, rr, r32, ctx);
100 pkey->rr[i] = BN_get_word(rem);
101 BN_div(n, rem, n, r32, ctx);
102 pkey->n[i] = BN_get_word(rem);
103 }
104 pkey->exponent = BN_get_word(rsa->e);
105
106out:
107 BN_free(n0inv);
108 BN_free(n);
109 BN_free(rem);
110 BN_free(r);
111 BN_free(rr);
112 BN_free(r32);
113 BN_CTX_free(ctx);
114
115 return ret;
116}
117
118static void get_user_info(char *buf, size_t len)
119{
120 char hostname[1024], username[1024];
Nick Kralevich6183c962014-11-13 15:17:29 -0800121 int ret = -1;
122
123 if (getenv("HOSTNAME") != NULL) {
124 strncpy(hostname, getenv("HOSTNAME"), sizeof(hostname));
125 hostname[sizeof(hostname)-1] = '\0';
126 ret = 0;
127 }
Benoit Goby2cc19e42012-04-12 12:23:49 -0700128
129#ifndef _WIN32
Benoit Goby2cc19e42012-04-12 12:23:49 -0700130 if (ret < 0)
Nick Kralevich6183c962014-11-13 15:17:29 -0800131 ret = gethostname(hostname, sizeof(hostname));
Benoit Goby2cc19e42012-04-12 12:23:49 -0700132#endif
Nick Kralevich6183c962014-11-13 15:17:29 -0800133 if (ret < 0)
Benoit Goby2cc19e42012-04-12 12:23:49 -0700134 strcpy(hostname, "unknown");
135
Nick Kralevich6183c962014-11-13 15:17:29 -0800136 ret = -1;
137
138 if (getenv("LOGNAME") != NULL) {
139 strncpy(username, getenv("LOGNAME"), sizeof(username));
140 username[sizeof(username)-1] = '\0';
141 ret = 0;
142 }
143
Benoit Goby2cc19e42012-04-12 12:23:49 -0700144#if !defined _WIN32 && !defined ADB_HOST_ON_TARGET
Benoit Goby2cc19e42012-04-12 12:23:49 -0700145 if (ret < 0)
Nick Kralevich6183c962014-11-13 15:17:29 -0800146 ret = getlogin_r(username, sizeof(username));
Benoit Goby2cc19e42012-04-12 12:23:49 -0700147#endif
Nick Kralevich6183c962014-11-13 15:17:29 -0800148 if (ret < 0)
Benoit Goby2cc19e42012-04-12 12:23:49 -0700149 strcpy(username, "unknown");
150
151 ret = snprintf(buf, len, " %s@%s", username, hostname);
152 if (ret >= (signed)len)
153 buf[len - 1] = '\0';
154}
155
156static int write_public_keyfile(RSA *private_key, const char *private_key_path)
157{
158 RSAPublicKey pkey;
Adam Langley29f6cdb2014-09-03 14:34:47 -0700159 FILE *outfile = NULL;
Tamas Berghammera1c60c02015-07-13 19:12:28 +0100160 char path[PATH_MAX], info[MAX_PAYLOAD_V1];
Dan Albertf30d73c2015-02-25 17:51:28 -0800161 uint8_t* encoded = nullptr;
Adam Langley29f6cdb2014-09-03 14:34:47 -0700162 size_t encoded_length;
163 int ret = 0;
Benoit Goby2cc19e42012-04-12 12:23:49 -0700164
Adam Langley29f6cdb2014-09-03 14:34:47 -0700165 if (snprintf(path, sizeof(path), "%s.pub", private_key_path) >=
166 (int)sizeof(path)) {
Yabin Cui815ad882015-09-02 17:44:28 -0700167 D("Path too long while writing public key");
Benoit Goby2cc19e42012-04-12 12:23:49 -0700168 return 0;
Adam Langley29f6cdb2014-09-03 14:34:47 -0700169 }
Benoit Goby2cc19e42012-04-12 12:23:49 -0700170
Adam Langley29f6cdb2014-09-03 14:34:47 -0700171 if (!RSA_to_RSAPublicKey(private_key, &pkey)) {
Yabin Cui815ad882015-09-02 17:44:28 -0700172 D("Failed to convert to publickey");
Benoit Goby2cc19e42012-04-12 12:23:49 -0700173 return 0;
174 }
175
Spencer Low60bca2d2015-05-07 19:08:29 -0700176 outfile = fopen(path, "w");
Adam Langley29f6cdb2014-09-03 14:34:47 -0700177 if (!outfile) {
Yabin Cui815ad882015-09-02 17:44:28 -0700178 D("Failed to open '%s'", path);
Benoit Goby2cc19e42012-04-12 12:23:49 -0700179 return 0;
180 }
181
Yabin Cui815ad882015-09-02 17:44:28 -0700182 D("Writing public key to '%s'", path);
Benoit Goby2cc19e42012-04-12 12:23:49 -0700183
Adam Langley29f6cdb2014-09-03 14:34:47 -0700184#if defined(OPENSSL_IS_BORINGSSL)
185 if (!EVP_EncodedLength(&encoded_length, sizeof(pkey))) {
Yabin Cui815ad882015-09-02 17:44:28 -0700186 D("Public key too large to base64 encode");
Adam Langley29f6cdb2014-09-03 14:34:47 -0700187 goto out;
188 }
189#else
190 /* While we switch from OpenSSL to BoringSSL we have to implement
191 * |EVP_EncodedLength| here. */
192 encoded_length = 1 + ((sizeof(pkey) + 2) / 3 * 4);
193#endif
Benoit Goby2cc19e42012-04-12 12:23:49 -0700194
Elliott Hughesfb2ba512015-04-24 23:02:00 -0700195 encoded = new uint8_t[encoded_length];
Dan Albertf30d73c2015-02-25 17:51:28 -0800196 if (encoded == nullptr) {
Yabin Cui815ad882015-09-02 17:44:28 -0700197 D("Allocation failure");
Adam Langley29f6cdb2014-09-03 14:34:47 -0700198 goto out;
199 }
Benoit Goby2cc19e42012-04-12 12:23:49 -0700200
Adam Langley29f6cdb2014-09-03 14:34:47 -0700201 encoded_length = EVP_EncodeBlock(encoded, (uint8_t*) &pkey, sizeof(pkey));
Benoit Goby2cc19e42012-04-12 12:23:49 -0700202 get_user_info(info, sizeof(info));
Benoit Goby2cc19e42012-04-12 12:23:49 -0700203
Adam Langley29f6cdb2014-09-03 14:34:47 -0700204 if (fwrite(encoded, encoded_length, 1, outfile) != 1 ||
205 fwrite(info, strlen(info), 1, outfile) != 1) {
Yabin Cui815ad882015-09-02 17:44:28 -0700206 D("Write error while writing public key");
Adam Langley29f6cdb2014-09-03 14:34:47 -0700207 goto out;
208 }
209
210 ret = 1;
211
212 out:
213 if (outfile != NULL) {
214 fclose(outfile);
215 }
Elliott Hughesfb2ba512015-04-24 23:02:00 -0700216 delete[] encoded;
Adam Langley29f6cdb2014-09-03 14:34:47 -0700217 return ret;
Benoit Goby2cc19e42012-04-12 12:23:49 -0700218}
219
220static int generate_key(const char *file)
221{
222 EVP_PKEY* pkey = EVP_PKEY_new();
223 BIGNUM* exponent = BN_new();
224 RSA* rsa = RSA_new();
Benoit Gobycb37c502012-08-31 12:14:21 -0700225 mode_t old_mask;
Benoit Goby2cc19e42012-04-12 12:23:49 -0700226 FILE *f = NULL;
227 int ret = 0;
228
Yabin Cui815ad882015-09-02 17:44:28 -0700229 D("generate_key '%s'", file);
Benoit Goby2cc19e42012-04-12 12:23:49 -0700230
231 if (!pkey || !exponent || !rsa) {
Yabin Cui815ad882015-09-02 17:44:28 -0700232 D("Failed to allocate key");
Benoit Goby2cc19e42012-04-12 12:23:49 -0700233 goto out;
234 }
235
236 BN_set_word(exponent, RSA_F4);
237 RSA_generate_key_ex(rsa, 2048, exponent, NULL);
238 EVP_PKEY_set1_RSA(pkey, rsa);
239
Benoit Gobycb37c502012-08-31 12:14:21 -0700240 old_mask = umask(077);
241
Spencer Low60bca2d2015-05-07 19:08:29 -0700242 f = fopen(file, "w");
Benoit Goby2cc19e42012-04-12 12:23:49 -0700243 if (!f) {
Yabin Cui815ad882015-09-02 17:44:28 -0700244 D("Failed to open '%s'", file);
Benoit Gobycb37c502012-08-31 12:14:21 -0700245 umask(old_mask);
Benoit Goby2cc19e42012-04-12 12:23:49 -0700246 goto out;
247 }
248
Benoit Gobycb37c502012-08-31 12:14:21 -0700249 umask(old_mask);
250
Benoit Goby2cc19e42012-04-12 12:23:49 -0700251 if (!PEM_write_PrivateKey(f, pkey, NULL, NULL, 0, NULL, NULL)) {
Yabin Cui815ad882015-09-02 17:44:28 -0700252 D("Failed to write key");
Benoit Goby2cc19e42012-04-12 12:23:49 -0700253 goto out;
254 }
255
256 if (!write_public_keyfile(rsa, file)) {
Yabin Cui815ad882015-09-02 17:44:28 -0700257 D("Failed to write public key");
Benoit Goby2cc19e42012-04-12 12:23:49 -0700258 goto out;
259 }
260
261 ret = 1;
262
263out:
264 if (f)
265 fclose(f);
266 EVP_PKEY_free(pkey);
267 RSA_free(rsa);
268 BN_free(exponent);
269 return ret;
270}
271
272static int read_key(const char *file, struct listnode *list)
273{
Yabin Cui815ad882015-09-02 17:44:28 -0700274 D("read_key '%s'", file);
Benoit Goby2cc19e42012-04-12 12:23:49 -0700275
Spencer Low60bca2d2015-05-07 19:08:29 -0700276 FILE* fp = fopen(file, "r");
Elliott Hughesfb2ba512015-04-24 23:02:00 -0700277 if (!fp) {
Yabin Cui815ad882015-09-02 17:44:28 -0700278 D("Failed to open '%s': %s", file, strerror(errno));
Benoit Goby2cc19e42012-04-12 12:23:49 -0700279 return 0;
280 }
281
Elliott Hughesfb2ba512015-04-24 23:02:00 -0700282 adb_private_key* key = new adb_private_key;
Benoit Goby2cc19e42012-04-12 12:23:49 -0700283 key->rsa = RSA_new();
284
Elliott Hughesfb2ba512015-04-24 23:02:00 -0700285 if (!PEM_read_RSAPrivateKey(fp, &key->rsa, NULL, NULL)) {
Yabin Cui815ad882015-09-02 17:44:28 -0700286 D("Failed to read key");
Elliott Hughesfb2ba512015-04-24 23:02:00 -0700287 fclose(fp);
Benoit Goby2cc19e42012-04-12 12:23:49 -0700288 RSA_free(key->rsa);
Elliott Hughesfb2ba512015-04-24 23:02:00 -0700289 delete key;
Benoit Goby2cc19e42012-04-12 12:23:49 -0700290 return 0;
291 }
292
Elliott Hughesfb2ba512015-04-24 23:02:00 -0700293 fclose(fp);
Benoit Goby2cc19e42012-04-12 12:23:49 -0700294 list_add_tail(list, &key->node);
295 return 1;
296}
297
Dan Albert3d978e62015-07-09 20:35:09 +0000298static int get_user_keyfilepath(char *filename, size_t len)
299{
300 const char *format, *home;
301 char android_dir[PATH_MAX];
302 struct stat buf;
Benoit Goby2cc19e42012-04-12 12:23:49 -0700303#ifdef _WIN32
Spencer Low6815c072015-05-11 01:08:48 -0700304 std::string home_str;
Dan Albert3d978e62015-07-09 20:35:09 +0000305 home = getenv("ANDROID_SDK_HOME");
306 if (!home) {
Spencer Low6815c072015-05-11 01:08:48 -0700307 WCHAR path[MAX_PATH];
Spencer Low1711e012015-08-02 18:50:17 -0700308 const HRESULT hr = SHGetFolderPathW(NULL, CSIDL_PROFILE, NULL, 0, path);
309 if (FAILED(hr)) {
Yabin Cui815ad882015-09-02 17:44:28 -0700310 D("SHGetFolderPathW failed: %s",
Spencer Low1711e012015-08-02 18:50:17 -0700311 SystemErrorCodeToString(hr).c_str());
Spencer Low6815c072015-05-11 01:08:48 -0700312 return -1;
313 }
314 home_str = narrow(path);
315 home = home_str.c_str();
Benoit Goby2cc19e42012-04-12 12:23:49 -0700316 }
Dan Albert3d978e62015-07-09 20:35:09 +0000317 format = "%s\\%s";
Benoit Goby2cc19e42012-04-12 12:23:49 -0700318#else
Dan Albert3d978e62015-07-09 20:35:09 +0000319 home = getenv("HOME");
320 if (!home)
321 return -1;
322 format = "%s/%s";
Benoit Goby2cc19e42012-04-12 12:23:49 -0700323#endif
324
Yabin Cui815ad882015-09-02 17:44:28 -0700325 D("home '%s'", home);
Benoit Goby2cc19e42012-04-12 12:23:49 -0700326
Dan Albert3d978e62015-07-09 20:35:09 +0000327 if (snprintf(android_dir, sizeof(android_dir), format, home,
328 ANDROID_PATH) >= (int)sizeof(android_dir))
329 return -1;
Benoit Goby2cc19e42012-04-12 12:23:49 -0700330
Dan Albert3d978e62015-07-09 20:35:09 +0000331 if (stat(android_dir, &buf)) {
332 if (adb_mkdir(android_dir, 0750) < 0) {
Yabin Cui815ad882015-09-02 17:44:28 -0700333 D("Cannot mkdir '%s'", android_dir);
Dan Albert3d978e62015-07-09 20:35:09 +0000334 return -1;
Benoit Goby2cc19e42012-04-12 12:23:49 -0700335 }
336 }
337
Dan Albert3d978e62015-07-09 20:35:09 +0000338 return snprintf(filename, len, format, android_dir, ADB_KEY_FILE);
Benoit Goby2cc19e42012-04-12 12:23:49 -0700339}
340
341static int get_user_key(struct listnode *list)
342{
Dan Albert3d978e62015-07-09 20:35:09 +0000343 struct stat buf;
344 char path[PATH_MAX];
345 int ret;
346
347 ret = get_user_keyfilepath(path, sizeof(path));
348 if (ret < 0 || ret >= (signed)sizeof(path)) {
Yabin Cui815ad882015-09-02 17:44:28 -0700349 D("Error getting user key filename");
Benoit Goby2cc19e42012-04-12 12:23:49 -0700350 return 0;
351 }
352
Yabin Cui815ad882015-09-02 17:44:28 -0700353 D("user key '%s'", path);
Benoit Goby2cc19e42012-04-12 12:23:49 -0700354
Dan Albert3d978e62015-07-09 20:35:09 +0000355 if (stat(path, &buf) == -1) {
356 if (!generate_key(path)) {
Yabin Cui815ad882015-09-02 17:44:28 -0700357 D("Failed to generate new key");
Benoit Goby2cc19e42012-04-12 12:23:49 -0700358 return 0;
359 }
360 }
361
Dan Albert3d978e62015-07-09 20:35:09 +0000362 return read_key(path, list);
Benoit Goby2cc19e42012-04-12 12:23:49 -0700363}
364
Elliott Hughesfb2ba512015-04-24 23:02:00 -0700365static void get_vendor_keys(struct listnode* key_list) {
366 const char* adb_keys_path = getenv("ADB_VENDOR_KEYS");
367 if (adb_keys_path == nullptr) {
Benoit Goby2cc19e42012-04-12 12:23:49 -0700368 return;
Elliott Hughesfb2ba512015-04-24 23:02:00 -0700369 }
Benoit Goby2cc19e42012-04-12 12:23:49 -0700370
Elliott Hughesfb2ba512015-04-24 23:02:00 -0700371 for (auto& path : android::base::Split(adb_keys_path, ENV_PATH_SEPARATOR_STR)) {
372 if (!read_key(path.c_str(), key_list)) {
Yabin Cui815ad882015-09-02 17:44:28 -0700373 D("Failed to read '%s'", path.c_str());
Elliott Hughesfb2ba512015-04-24 23:02:00 -0700374 }
Benoit Goby2cc19e42012-04-12 12:23:49 -0700375 }
376}
377
Dan Albertf30d73c2015-02-25 17:51:28 -0800378int adb_auth_sign(void *node, const unsigned char* token, size_t token_size,
379 unsigned char* sig)
Benoit Goby2cc19e42012-04-12 12:23:49 -0700380{
381 unsigned int len;
382 struct adb_private_key *key = node_to_item(node, struct adb_private_key, node);
383
Sami Tolvanenb92a35c2015-01-27 16:48:35 +0000384 if (token_size != TOKEN_SIZE) {
Yabin Cui815ad882015-09-02 17:44:28 -0700385 D("Unexpected token size %zd", token_size);
Sami Tolvanenb92a35c2015-01-27 16:48:35 +0000386 return 0;
387 }
388
Benoit Goby2cc19e42012-04-12 12:23:49 -0700389 if (!RSA_sign(NID_sha1, token, token_size, sig, &len, key->rsa)) {
390 return 0;
391 }
392
Yabin Cui815ad882015-09-02 17:44:28 -0700393 D("adb_auth_sign len=%d", len);
Benoit Goby2cc19e42012-04-12 12:23:49 -0700394 return (int)len;
395}
396
397void *adb_auth_nextkey(void *current)
398{
399 struct listnode *item;
400
401 if (list_empty(&key_list))
402 return NULL;
403
404 if (!current)
405 return list_head(&key_list);
406
407 list_for_each(item, &key_list) {
408 if (item == current) {
409 /* current is the last item, we tried all the keys */
410 if (item->next == &key_list)
411 return NULL;
412 return item->next;
413 }
414 }
415
416 return NULL;
417}
418
419int adb_auth_get_userkey(unsigned char *data, size_t len)
420{
Dan Albert3d978e62015-07-09 20:35:09 +0000421 char path[PATH_MAX];
422 int ret = get_user_keyfilepath(path, sizeof(path) - 4);
423 if (ret < 0 || ret >= (signed)(sizeof(path) - 4)) {
Yabin Cui815ad882015-09-02 17:44:28 -0700424 D("Error getting user key filename");
Benoit Goby2cc19e42012-04-12 12:23:49 -0700425 return 0;
426 }
Dan Albert3d978e62015-07-09 20:35:09 +0000427 strcat(path, ".pub");
Benoit Goby2cc19e42012-04-12 12:23:49 -0700428
Dan Albertf30d73c2015-02-25 17:51:28 -0800429 // TODO(danalbert): ReadFileToString
Spencer Low3a2421b2015-05-22 20:09:06 -0700430 // Note that on Windows, load_file() does not do CR/LF translation, but
431 // ReadFileToString() uses the C Runtime which uses CR/LF translation by
432 // default (by is overridable with _setmode()).
Dan Albertf30d73c2015-02-25 17:51:28 -0800433 unsigned size;
Dan Albert3d978e62015-07-09 20:35:09 +0000434 char* file_data = reinterpret_cast<char*>(load_file(path, &size));
Dan Albertf30d73c2015-02-25 17:51:28 -0800435 if (file_data == nullptr) {
Yabin Cui815ad882015-09-02 17:44:28 -0700436 D("Can't load '%s'", path);
Benoit Goby2cc19e42012-04-12 12:23:49 -0700437 return 0;
438 }
439
Dan Albertf30d73c2015-02-25 17:51:28 -0800440 if (len < (size_t)(size + 1)) {
Yabin Cui815ad882015-09-02 17:44:28 -0700441 D("%s: Content too large ret=%d", path, size);
Dan Albertf30d73c2015-02-25 17:51:28 -0800442 free(file_data);
Benoit Goby2cc19e42012-04-12 12:23:49 -0700443 return 0;
444 }
445
Dan Albertf30d73c2015-02-25 17:51:28 -0800446 memcpy(data, file_data, size);
447 free(file_data);
448 file_data = nullptr;
449 data[size] = '\0';
Benoit Goby2cc19e42012-04-12 12:23:49 -0700450
Dan Albertf30d73c2015-02-25 17:51:28 -0800451 return size + 1;
Benoit Goby2cc19e42012-04-12 12:23:49 -0700452}
453
Nick Kralevich6183c962014-11-13 15:17:29 -0800454int adb_auth_keygen(const char* filename) {
455 adb_trace_mask |= (1 << TRACE_AUTH);
456 return (generate_key(filename) == 0);
457}
458
Benoit Goby2cc19e42012-04-12 12:23:49 -0700459void adb_auth_init(void)
460{
461 int ret;
462
Yabin Cui815ad882015-09-02 17:44:28 -0700463 D("adb_auth_init");
Benoit Goby2cc19e42012-04-12 12:23:49 -0700464
465 list_init(&key_list);
466
467 ret = get_user_key(&key_list);
468 if (!ret) {
Yabin Cui815ad882015-09-02 17:44:28 -0700469 D("Failed to get user key");
Benoit Goby2cc19e42012-04-12 12:23:49 -0700470 return;
471 }
472
473 get_vendor_keys(&key_list);
474}