diff options
author | Charles Kerr <charles.kerr@canonical.com> | 2016-03-09 17:19:23 -0600 |
---|---|---|
committer | Charles Kerr <charles.kerr@canonical.com> | 2016-03-09 17:19:23 -0600 |
commit | 13a0b901492901638a7abc90bb2935a9c0387f75 (patch) | |
tree | 9a5fadd583ef37954bce7aac47c2ed0d947d34bb /src | |
parent | 68b671ce04b8b5d6b37025ad093c73a3e14d4d64 (diff) | |
download | ayatana-indicator-display-13a0b901492901638a7abc90bb2935a9c0387f75.tar.gz ayatana-indicator-display-13a0b901492901638a7abc90bb2935a9c0387f75.tar.bz2 ayatana-indicator-display-13a0b901492901638a7abc90bb2935a9c0387f75.zip |
add human-readable fingerprint extraction from the adb public keys
Diffstat (limited to 'src')
-rw-r--r-- | src/adbd-client.cpp | 39 | ||||
-rw-r--r-- | src/adbd-client.h | 1 | ||||
-rw-r--r-- | src/main.cpp | 2 | ||||
-rw-r--r-- | src/usb-snap.cpp | 4 |
4 files changed, 43 insertions, 3 deletions
diff --git a/src/adbd-client.cpp b/src/adbd-client.cpp index 38f202f..edd403c 100644 --- a/src/adbd-client.cpp +++ b/src/adbd-client.cpp @@ -22,6 +22,9 @@ #include <gio/gio.h> #include <gio/gunixsocketaddress.h> +#include <algorithm> +#include <cctype> +#include <cstring> #include <chrono> #include <condition_variable> #include <mutex> @@ -89,6 +92,7 @@ private: auto self = data->self; struct PKRequest req; req.public_key = data->public_key; + req.fingerprint = get_fingerprint(req.public_key); req.respond = [self](PKResponse response){self->on_public_key_response(response);}; self->m_on_pk_request(req); } @@ -219,6 +223,37 @@ private: } } + static std::string get_fingerprint(const std::string& public_key) + { + // The first token is base64-encoded data, so cut on the first whitespace + const std::string base64 ( + public_key.begin(), + std::find_if( + public_key.begin(), public_key.end(), + [](const std::string::value_type& ch){return std::isspace(ch);} + ) + ); + + gsize digest_len {}; + auto digest = g_base64_decode(base64.c_str(), &digest_len); + + auto checksum = g_compute_checksum_for_data(G_CHECKSUM_MD5, digest, digest_len); + const gsize checksum_len = checksum ? strlen(checksum) : 0; + + // insert ':' between character pairs; eg "ff27b5f3" --> "ff:27:b5:f3" + std::string fingerprint; + for (gsize i=0; i<checksum_len; ) { + fingerprint.append(checksum+i, checksum+i+2); + if (i < checksum_len-2) + fingerprint.append(":"); + i += 2; + } + + g_clear_pointer(&digest, g_free); + g_clear_pointer(&checksum, g_free); + return fingerprint; + } + const std::string m_socket_path; GCancellable* m_cancellable = nullptr; std::thread m_worker_thread; @@ -241,6 +276,10 @@ AdbdClient::~AdbdClient() { } +/*** +**** +***/ + GAdbdClient::GAdbdClient(const std::string& socket_path): impl{new Impl{socket_path}} { diff --git a/src/adbd-client.h b/src/adbd-client.h index aef7674..dcee2f1 100644 --- a/src/adbd-client.h +++ b/src/adbd-client.h @@ -44,6 +44,7 @@ public: struct PKRequest { std::string public_key; + std::string fingerprint; std::function<void(PKResponse)> respond; }; diff --git a/src/main.cpp b/src/main.cpp index 62eca62..151b642 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -61,7 +61,7 @@ main(int /*argc*/, char** /*argv*/) static constexpr char const * ADB_SOCKET_PATH {"/dev/socket/adb"}; GAdbdClient adbd_client{ADB_SOCKET_PATH}; adbd_client.on_pk_request().connect([](const AdbdClient::PKRequest& req){ - auto snap = new UsbSnap(req.public_key); + auto snap = new UsbSnap(req.fingerprint); snap->on_user_response().connect([req,snap](AdbdClient::PKResponse response, bool /*FIXME: remember_choice*/){ req.respond(response); g_idle_add([](gpointer gsnap){delete static_cast<UsbSnap*>(gsnap); return G_SOURCE_REMOVE;}, snap); // delete-later diff --git a/src/usb-snap.cpp b/src/usb-snap.cpp index 40f02a2..87f4673 100644 --- a/src/usb-snap.cpp +++ b/src/usb-snap.cpp @@ -217,8 +217,8 @@ private: m_notification_id = 0; } - static constexpr char const * ACTION_ALLOW{"allow"}; - static constexpr char const * ACTION_DENY{"deny"}; + static constexpr char const * ACTION_ALLOW {"allow"}; + static constexpr char const * ACTION_DENY {"deny"}; static constexpr char const * BUS_NAME {"org.freedesktop.Notifications" }; static constexpr char const * IFACE_NAME {"org.freedesktop.Notifications" }; |