Commit 5718f38c authored by Nick Mathewson's avatar Nick Mathewson 🥄
Browse files

Add ed25519 identities to relay descriptions.

(Or at least, to all those relay descriptions that derive from
format_node_description()).

Closes #22668.
parent 93e7661f
o Minor features (logging):
- When describing a relay in th elogs, we now include its ed25519 identity.
Closes ticket 22668.
...@@ -14,6 +14,10 @@ ...@@ -14,6 +14,10 @@
#include "core/or/or.h" #include "core/or/or.h"
#include "core/or/extendinfo.h" #include "core/or/extendinfo.h"
#include "feature/nodelist/describe.h" #include "feature/nodelist/describe.h"
#include "feature/nodelist/nodelist.h"
#include "feature/nodelist/routerinfo.h"
#include "lib/crypt_ops/crypto_ed25519.h"
#include "lib/crypt_ops/crypto_format.h"
#include "core/or/extend_info_st.h" #include "core/or/extend_info_st.h"
#include "feature/nodelist/node_st.h" #include "feature/nodelist/node_st.h"
...@@ -34,7 +38,8 @@ ...@@ -34,7 +38,8 @@
*/ */
STATIC const char * STATIC const char *
format_node_description(char *buf, format_node_description(char *buf,
const char *id_digest, const char *rsa_id_digest,
const ed25519_public_key_t *ed25519_id,
const char *nickname, const char *nickname,
const tor_addr_t *ipv4_addr, const tor_addr_t *ipv4_addr,
const tor_addr_t *ipv6_addr) const tor_addr_t *ipv6_addr)
...@@ -48,7 +53,7 @@ format_node_description(char *buf, ...@@ -48,7 +53,7 @@ format_node_description(char *buf,
memset(buf, 0, NODE_DESC_BUF_LEN); memset(buf, 0, NODE_DESC_BUF_LEN);
if (!id_digest) { if (!rsa_id_digest) {
/* strlcpy() returns the length of the source string it attempted to copy, /* strlcpy() returns the length of the source string it attempted to copy,
* ignoring any required truncation due to the buffer length. */ * ignoring any required truncation due to the buffer length. */
rv = strlcpy(buf, "<NULL ID DIGEST>", NODE_DESC_BUF_LEN); rv = strlcpy(buf, "<NULL ID DIGEST>", NODE_DESC_BUF_LEN);
...@@ -66,7 +71,7 @@ format_node_description(char *buf, ...@@ -66,7 +71,7 @@ format_node_description(char *buf,
memset(hex_digest, 0, sizeof(hex_digest)); memset(hex_digest, 0, sizeof(hex_digest));
base16_encode(hex_digest, sizeof(hex_digest), base16_encode(hex_digest, sizeof(hex_digest),
id_digest, DIGEST_LEN); rsa_id_digest, DIGEST_LEN);
rv = strlcat(buf, hex_digest, NODE_DESC_BUF_LEN); rv = strlcat(buf, hex_digest, NODE_DESC_BUF_LEN);
tor_assert_nonfatal(rv < NODE_DESC_BUF_LEN); tor_assert_nonfatal(rv < NODE_DESC_BUF_LEN);
} }
...@@ -77,6 +82,16 @@ format_node_description(char *buf, ...@@ -77,6 +82,16 @@ format_node_description(char *buf,
rv = strlcat(buf, nickname, NODE_DESC_BUF_LEN); rv = strlcat(buf, nickname, NODE_DESC_BUF_LEN);
tor_assert_nonfatal(rv < NODE_DESC_BUF_LEN); tor_assert_nonfatal(rv < NODE_DESC_BUF_LEN);
} }
if (ed25519_id) {
char ed_base64[ED25519_BASE64_LEN+1];
ed25519_public_to_base64(ed_base64, ed25519_id);
rv = strlcat(buf, " [", NODE_DESC_BUF_LEN);
tor_assert_nonfatal(rv < NODE_DESC_BUF_LEN);
rv = strlcat(buf, ed_base64, NODE_DESC_BUF_LEN);
tor_assert_nonfatal(rv < NODE_DESC_BUF_LEN);
rv = strlcat(buf, "]", NODE_DESC_BUF_LEN);
tor_assert_nonfatal(rv < NODE_DESC_BUF_LEN);
}
if (ipv4_addr || has_ipv6) { if (ipv4_addr || has_ipv6) {
rv = strlcat(buf, " at ", NODE_DESC_BUF_LEN); rv = strlcat(buf, " at ", NODE_DESC_BUF_LEN);
tor_assert_nonfatal(rv < NODE_DESC_BUF_LEN); tor_assert_nonfatal(rv < NODE_DESC_BUF_LEN);
...@@ -126,8 +141,11 @@ router_describe(const routerinfo_t *ri) ...@@ -126,8 +141,11 @@ router_describe(const routerinfo_t *ri)
if (!ri) if (!ri)
return "<null>"; return "<null>";
const ed25519_public_key_t *ed25519_id = routerinfo_get_ed25519_id(ri);
return format_node_description(buf, return format_node_description(buf,
ri->cache_info.identity_digest, ri->cache_info.identity_digest,
ed25519_id,
ri->nickname, ri->nickname,
&ri->ipv4_addr, &ri->ipv4_addr,
&ri->ipv6_addr); &ri->ipv6_addr);
...@@ -166,8 +184,11 @@ node_describe(const node_t *node) ...@@ -166,8 +184,11 @@ node_describe(const node_t *node)
return "<null rs and ri>"; return "<null rs and ri>";
} }
const ed25519_public_key_t *ed25519_id = node_get_ed25519_id(node);
return format_node_description(buf, return format_node_description(buf,
node->identity, node->identity,
ed25519_id,
nickname, nickname,
ipv4_addr, ipv4_addr,
ipv6_addr); ipv6_addr);
...@@ -188,6 +209,7 @@ routerstatus_describe(const routerstatus_t *rs) ...@@ -188,6 +209,7 @@ routerstatus_describe(const routerstatus_t *rs)
return format_node_description(buf, return format_node_description(buf,
rs->identity_digest, rs->identity_digest,
NULL,
rs->nickname, rs->nickname,
&rs->ipv4_addr, &rs->ipv4_addr,
&rs->ipv6_addr); &rs->ipv6_addr);
...@@ -211,8 +233,13 @@ extend_info_describe(const extend_info_t *ei) ...@@ -211,8 +233,13 @@ extend_info_describe(const extend_info_t *ei)
const tor_addr_t *addr4 = ap4 ? &ap4->addr : NULL; const tor_addr_t *addr4 = ap4 ? &ap4->addr : NULL;
const tor_addr_t *addr6 = ap6 ? &ap6->addr : NULL; const tor_addr_t *addr6 = ap6 ? &ap6->addr : NULL;
const ed25519_public_key_t *ed25519_id = &ei->ed_identity;
if (ed25519_public_key_is_zero(ed25519_id))
ed25519_id = NULL;
return format_node_description(buf, return format_node_description(buf,
ei->identity_digest, ei->identity_digest,
ed25519_id,
ei->nickname, ei->nickname,
addr4, addr4,
addr6); addr6);
......
...@@ -35,22 +35,28 @@ void router_get_verbose_nickname(char *buf, const routerinfo_t *router); ...@@ -35,22 +35,28 @@ void router_get_verbose_nickname(char *buf, const routerinfo_t *router);
/** /**
* Longest allowed output of format_node_description, plus 1 character for * Longest allowed output of format_node_description, plus 1 character for
* NUL. This allows space for: * NUL. This allows space for:
* "$FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF~xxxxxxxxxxxxxxxxxxx at" * "$FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF~xxxxxxxxxxxxxxxxxxx "
* "[+++++++++++++++++++++++++++++++++++++++++++] at"
* " 255.255.255.255 and [ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255]" * " 255.255.255.255 and [ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255]"
* plus a terminating NUL. * plus a terminating NUL.
*/ */
#define NODE_DESC_BUF_LEN \ #define NODE_DESC_BUF_LEN \
(MAX_VERBOSE_NICKNAME_LEN+4+IPV4_BUF_LEN_NO_NUL+5+TOR_ADDR_BUF_LEN) (MAX_VERBOSE_NICKNAME_LEN+4 \
+ ED25519_BASE64_LEN+3 \
+ IPV4_BUF_LEN_NO_NUL+5 \
+ TOR_ADDR_BUF_LEN)
#endif /* defined(DESCRIBE_PRIVATE) || defined(TOR_UNIT_TESTS) */ #endif /* defined(DESCRIBE_PRIVATE) || defined(TOR_UNIT_TESTS) */
#ifdef TOR_UNIT_TESTS #ifdef TOR_UNIT_TESTS
struct ed25519_public_key_t;
STATIC const char *format_node_description(char *buf, STATIC const char *format_node_description(char *buf,
const char *id_digest, const char *rsa_id_digest,
const char *nickname, const struct ed25519_public_key_t *ed25519_id,
const tor_addr_t *ipv4_addr, const char *nickname,
const tor_addr_t *ipv6_addr); const tor_addr_t *ipv4_addr,
const tor_addr_t *ipv6_addr);
#endif /* defined(TOR_UNIT_TESTS) */ #endif /* defined(TOR_UNIT_TESTS) */
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "core/or/or.h" #include "core/or/or.h"
#include "lib/crypt_ops/crypto_rand.h" #include "lib/crypt_ops/crypto_rand.h"
#include "lib/crypt_ops/crypto_format.h"
#include "feature/nodelist/describe.h" #include "feature/nodelist/describe.h"
#include "feature/nodelist/networkstatus.h" #include "feature/nodelist/networkstatus.h"
#include "feature/nodelist/nodefamily.h" #include "feature/nodelist/nodefamily.h"
...@@ -657,6 +658,7 @@ test_nodelist_format_node_description(void *arg) ...@@ -657,6 +658,7 @@ test_nodelist_format_node_description(void *arg)
tor_addr_t mock_null_ip; tor_addr_t mock_null_ip;
tor_addr_t mock_ipv4; tor_addr_t mock_ipv4;
tor_addr_t mock_ipv6; tor_addr_t mock_ipv6;
ed25519_public_key_t ed_id;
char ndesc[NODE_DESC_BUF_LEN]; char ndesc[NODE_DESC_BUF_LEN];
const char *rv = NULL; const char *rv = NULL;
...@@ -685,6 +687,7 @@ test_nodelist_format_node_description(void *arg) ...@@ -685,6 +687,7 @@ test_nodelist_format_node_description(void *arg)
mock_digest, mock_digest,
NULL, NULL,
NULL, NULL,
NULL,
NULL); NULL);
tt_ptr_op(rv, OP_EQ, ndesc); tt_ptr_op(rv, OP_EQ, ndesc);
tt_str_op(ndesc, OP_EQ, "$AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"); tt_str_op(ndesc, OP_EQ, "$AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
...@@ -692,6 +695,7 @@ test_nodelist_format_node_description(void *arg) ...@@ -692,6 +695,7 @@ test_nodelist_format_node_description(void *arg)
/* format node description should use ~ because named is deprecated */ /* format node description should use ~ because named is deprecated */
rv = format_node_description(ndesc, rv = format_node_description(ndesc,
mock_digest, mock_digest,
NULL,
mock_nickname, mock_nickname,
NULL, NULL,
NULL); NULL);
...@@ -702,6 +706,7 @@ test_nodelist_format_node_description(void *arg) ...@@ -702,6 +706,7 @@ test_nodelist_format_node_description(void *arg)
/* Try a null IP address, rather than NULL */ /* Try a null IP address, rather than NULL */
rv = format_node_description(ndesc, rv = format_node_description(ndesc,
mock_digest, mock_digest,
NULL,
mock_nickname, mock_nickname,
NULL, NULL,
&mock_null_ip); &mock_null_ip);
...@@ -713,6 +718,7 @@ test_nodelist_format_node_description(void *arg) ...@@ -713,6 +718,7 @@ test_nodelist_format_node_description(void *arg)
rv = format_node_description(ndesc, rv = format_node_description(ndesc,
mock_digest, mock_digest,
NULL, NULL,
NULL,
&mock_ipv4, &mock_ipv4,
NULL); NULL);
tt_ptr_op(rv, OP_EQ, ndesc); tt_ptr_op(rv, OP_EQ, ndesc);
...@@ -721,6 +727,7 @@ test_nodelist_format_node_description(void *arg) ...@@ -721,6 +727,7 @@ test_nodelist_format_node_description(void *arg)
rv = format_node_description(ndesc, rv = format_node_description(ndesc,
mock_digest, mock_digest,
NULL,
mock_nickname, mock_nickname,
NULL, NULL,
&mock_ipv6); &mock_ipv6);
...@@ -731,6 +738,7 @@ test_nodelist_format_node_description(void *arg) ...@@ -731,6 +738,7 @@ test_nodelist_format_node_description(void *arg)
rv = format_node_description(ndesc, rv = format_node_description(ndesc,
mock_digest, mock_digest,
NULL,
mock_nickname, mock_nickname,
&mock_ipv4, &mock_ipv4,
&mock_ipv6); &mock_ipv6);
...@@ -739,11 +747,26 @@ test_nodelist_format_node_description(void *arg) ...@@ -739,11 +747,26 @@ test_nodelist_format_node_description(void *arg)
"$AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA~TestOR7890123456789 at " "$AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA~TestOR7890123456789 at "
"111.222.233.244 and [1111:2222:3333:4444:5555:6666:7777:8888]"); "111.222.233.244 and [1111:2222:3333:4444:5555:6666:7777:8888]");
/* Try some ed25519 keys. */
int n = ed25519_public_from_base64(&ed_id,
"+wBP6WVZzqKK+eTdwU7Hhb80xEm40FSZDBMNozTJpDE");
tt_int_op(n,OP_EQ,0);
rv = format_node_description(ndesc,
mock_digest,
&ed_id,
mock_nickname,
&mock_ipv4,
&mock_ipv6);
tt_str_op(ndesc, OP_EQ,
"$AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA~TestOR7890123456789 "
"[+wBP6WVZzqKK+eTdwU7Hhb80xEm40FSZDBMNozTJpDE] at "
"111.222.233.244 and [1111:2222:3333:4444:5555:6666:7777:8888]");
/* test NULL handling */ /* test NULL handling */
rv = format_node_description(NULL, NULL, NULL, NULL, NULL); rv = format_node_description(NULL, NULL, NULL, NULL, NULL, NULL);
tt_str_op(rv, OP_EQ, "<NULL BUFFER>"); tt_str_op(rv, OP_EQ, "<NULL BUFFER>");
rv = format_node_description(ndesc, NULL, NULL, NULL, NULL); rv = format_node_description(ndesc, NULL, NULL, NULL, NULL, NULL);
tt_ptr_op(rv, OP_EQ, ndesc); tt_ptr_op(rv, OP_EQ, ndesc);
tt_str_op(rv, OP_EQ, "<NULL ID DIGEST>"); tt_str_op(rv, OP_EQ, "<NULL ID DIGEST>");
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment