X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=src%2Fprotocol_key.c;h=8ab1325c23d701982a29a7163e871869e9d7757c;hb=7dbb65e77ec5fd815c64e1484279d63279679e65;hp=5cfa060b2f6a1b37ebcfccbf27f4ebf29e04b6a3;hpb=fb7b6e7a0c966a88a682f656ca1caeb9a0583c5b;p=meshlink diff --git a/src/protocol_key.c b/src/protocol_key.c index 5cfa060b..8ab1325c 100644 --- a/src/protocol_key.c +++ b/src/protocol_key.c @@ -19,10 +19,9 @@ #include "system.h" -#include "cipher.h" #include "connection.h" -#include "crypto.h" #include "logger.h" +#include "meshlink_internal.h" #include "net.h" #include "netutl.h" #include "node.h" @@ -35,11 +34,11 @@ static bool mykeyused = false; void send_key_changed(void) { - send_request(everyone, "%d %x %s", KEY_CHANGED, rand(), myself->name); + send_request(mesh->everyone, "%d %x %s", KEY_CHANGED, rand(), mesh->self->name); /* Force key exchange for connections using SPTPS */ - for splay_each(node_t, n, node_tree) + for splay_each(node_t, n, mesh->nodes) if(n->status.reachable && n->status.validkey) sptps_force_kex(&n->sptps); } @@ -77,27 +76,27 @@ static bool send_initial_sptps_data(void *handle, uint8_t type, const char *data to->sptps.send_data = send_sptps_data; char buf[len * 4 / 3 + 5]; b64encode(data, buf, len); - return send_request(to->nexthop->connection, "%d %s %s %d %s", REQ_KEY, myself->name, to->name, REQ_KEY, buf); + return send_request(to->nexthop->connection, "%d %s %s %d %s", REQ_KEY, mesh->self->name, to->name, REQ_KEY, buf); } bool send_req_key(node_t *to) { if(!node_read_ecdsa_public_key(to)) { logger(DEBUG_PROTOCOL, LOG_DEBUG, "No ECDSA key known for %s (%s)", to->name, to->hostname); - send_request(to->nexthop->connection, "%d %s %s %d", REQ_KEY, myself->name, to->name, REQ_PUBKEY); + send_request(to->nexthop->connection, "%d %s %s %d", REQ_KEY, mesh->self->name, to->name, REQ_PUBKEY); return true; } if(to->sptps.label) logger(DEBUG_ALWAYS, LOG_DEBUG, "send_req_key(%s) called while sptps->label != NULL!", to->name); - char label[25 + strlen(myself->name) + strlen(to->name)]; - snprintf(label, sizeof label, "tinc UDP key expansion %s %s", myself->name, to->name); + char label[25 + strlen(mesh->self->name) + strlen(to->name)]; + snprintf(label, sizeof label, "tinc UDP key expansion %s %s", mesh->self->name, to->name); sptps_stop(&to->sptps); to->status.validkey = false; to->status.waitingforkey = true; to->last_req_key = now.tv_sec; - to->incompression = myself->incompression; - return sptps_start(&to->sptps, to, true, true, myself->connection->ecdsa, to->ecdsa, label, sizeof label, send_initial_sptps_data, receive_sptps_record); + to->incompression = mesh->self->incompression; + return sptps_start(&to->sptps, to, true, true, mesh->self->connection->ecdsa, to->ecdsa, label, sizeof label, send_initial_sptps_data, receive_sptps_record); } /* REQ_KEY is overloaded to allow arbitrary requests to be routed between two nodes. */ @@ -105,8 +104,8 @@ bool send_req_key(node_t *to) { static bool req_key_ext_h(connection_t *c, const char *request, node_t *from, int reqno) { switch(reqno) { case REQ_PUBKEY: { - char *pubkey = ecdsa_get_base64_public_key(myself->connection->ecdsa); - send_request(from->nexthop->connection, "%d %s %s %d %s", REQ_KEY, myself->name, from->name, ANS_PUBKEY, pubkey); + char *pubkey = ecdsa_get_base64_public_key(mesh->self->connection->ecdsa); + send_request(from->nexthop->connection, "%d %s %s %d %s", REQ_KEY, mesh->self->name, from->name, ANS_PUBKEY, pubkey); free(pubkey); return true; } @@ -131,7 +130,7 @@ static bool req_key_ext_h(connection_t *c, const char *request, node_t *from, in case REQ_KEY: { if(!node_read_ecdsa_public_key(from)) { logger(DEBUG_PROTOCOL, LOG_DEBUG, "No ECDSA key known for %s (%s)", from->name, from->hostname); - send_request(from->nexthop->connection, "%d %s %s %d", REQ_KEY, myself->name, from->name, REQ_PUBKEY); + send_request(from->nexthop->connection, "%d %s %s %d", REQ_KEY, mesh->self->name, from->name, REQ_PUBKEY); return true; } @@ -146,13 +145,13 @@ static bool req_key_ext_h(connection_t *c, const char *request, node_t *from, in return true; } - char label[25 + strlen(from->name) + strlen(myself->name)]; - snprintf(label, sizeof label, "tinc UDP key expansion %s %s", from->name, myself->name); + char label[25 + strlen(from->name) + strlen(mesh->self->name)]; + snprintf(label, sizeof label, "tinc UDP key expansion %s %s", from->name, mesh->self->name); sptps_stop(&from->sptps); from->status.validkey = false; from->status.waitingforkey = true; from->last_req_key = now.tv_sec; - sptps_start(&from->sptps, from, false, true, myself->connection->ecdsa, from->ecdsa, label, sizeof label, send_sptps_data, receive_sptps_record); + sptps_start(&from->sptps, from, false, true, mesh->self->connection->ecdsa, from->ecdsa, label, sizeof label, send_sptps_data, receive_sptps_record); sptps_receive_data(&from->sptps, buf, len); return true; } @@ -214,7 +213,7 @@ bool req_key_h(connection_t *c, const char *request) { /* Check if this key request is for us */ - if(to == myself) { /* Yes */ + if(to == mesh->self) { /* Yes */ /* Is this an extended REQ_KEY message? */ if(reqno) return req_key_ext_h(c, request, from, reqno); @@ -278,7 +277,7 @@ bool ans_key_h(connection_t *c, const char *request) { /* Forward it if necessary */ - if(to != myself) { + if(to != mesh->self) { if(!to->status.reachable) { logger(DEBUG_ALWAYS, LOG_WARNING, "Got %s from %s (%s) destination %s which is not reachable", "ANS_KEY", c->name, c->hostname, to_name);