From cbcb7c1e64318a80dd72e5b09b45ab16e56e47de Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Wed, 30 Jul 2014 18:18:09 +0200 Subject: [PATCH] Add meshlink_get_fingerprint(). This function returns a (fingerprint of a) node's public key in printable ASCII. --- src/meshlink.c | 21 +++++++++++++++++++++ src/meshlink.h | 12 ++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/meshlink.c b/src/meshlink.c index 84bf4e10..9fc80153 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -1013,6 +1013,27 @@ ssize_t meshlink_get_pmtu(meshlink_handle_t *mesh, meshlink_node_t *destination) return MTU; } +char *meshlink_get_fingerprint(meshlink_handle_t *mesh, meshlink_node_t *node) { + if(!mesh || !node) { + meshlink_errno = MESHLINK_EINVAL; + return NULL; + } + + node_t *n = (node_t *)node; + + if(!node_read_ecdsa_public_key(mesh, n) || !n->ecdsa) { + meshlink_errno = MESHLINK_EINTERNAL; + return false; + } + + char *fingerprint = ecdsa_get_base64_public_key(n->ecdsa); + + if(!fingerprint) + meshlink_errno = MESHLINK_EINTERNAL; + + return fingerprint; +} + meshlink_node_t *meshlink_get_node(meshlink_handle_t *mesh, const char *name) { if(!mesh || !name) { meshlink_errno = MESHLINK_EINVAL; diff --git a/src/meshlink.h b/src/meshlink.h index 6672b67d..ee2c3f0a 100644 --- a/src/meshlink.h +++ b/src/meshlink.h @@ -277,6 +277,18 @@ extern ssize_t meshlink_get_pmtu(meshlink_handle_t *mesh, meshlink_node_t *desti */ extern meshlink_node_t *meshlink_get_node(meshlink_handle_t *mesh, const char *name); +/// Get the fingerprint of a node's public key. +/** This function returns a fingerprint of the node's public key. + * It should be treated as an opaque blob. + * + * @param mesh A handle which represents an instance of MeshLink. + * @param node A pointer to a meshlink_node_t describing the node. + * + * @return A nul-terminated C string containing the fingerprint of the node's public key in a printable ASCII format. + * The application should call free() after it is done using this string. + */ +extern char *meshlink_get_fingerprint(meshlink_handle_t *mesh, meshlink_node_t *node); + /// Get a list of all nodes. /** This function returns a list with handles for all known nodes. * -- 2.39.2