adb: add support for vendor key directories.
Allow directories to be specified in ADB_VENDOR_KEYS. On Linux, monitor
this directory for new keys to be added.
Additionally, deduplicate keys by hashing their public key.
Bug: http://b/29273531
Bug: http://b/30927527
Change-Id: I8d3312b216b7f2c11900f2235f1f1b1d1c7aa767
Test: manually tested by adding a key to a directory, and verifying
that devices became authorized after replugging.
diff --git a/adb/adb_auth.cpp b/adb/adb_auth.cpp
index 446c3df..33da4bd 100644
--- a/adb/adb_auth.cpp
+++ b/adb/adb_auth.cpp
@@ -69,7 +69,7 @@
}
void send_auth_response(uint8_t* token, size_t token_size, atransport* t) {
- RSA* key = t->NextKey();
+ std::shared_ptr<RSA> key = t->NextKey();
if (key == nullptr) {
// No more private keys to try, send the public key.
send_auth_publickey(t);
@@ -79,12 +79,7 @@
LOG(INFO) << "Calling send_auth_response";
apacket* p = get_apacket();
- int ret = adb_auth_sign(key, token, token_size, p->data);
-
- // Stop sharing this key.
- RSA_free(key);
- key = nullptr;
-
+ int ret = adb_auth_sign(key.get(), token, token_size, p->data);
if (!ret) {
D("Error signing the token");
put_apacket(p);