X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=src%2Fprotocol_auth.c;h=404a81c88de8ec09fddc65f58d926a09f4935eda;hb=7d0d06e82233623ce90c70dac2803a7f299c673e;hp=65736253020c08cf49d6c6758b4c37187aaee749;hpb=3b13c8881100e12d5a4bf184611188bcb57e7144;p=meshlink diff --git a/src/protocol_auth.c b/src/protocol_auth.c index 65736253..404a81c8 100644 --- a/src/protocol_auth.c +++ b/src/protocol_auth.c @@ -36,8 +36,10 @@ #include "utils.h" #include "xalloc.h" #include "ed25519/sha512.h" - -extern bool node_write_dclass(meshlink_handle_t *mesh, node_t *n); + +#include + +extern bool node_write_devclass(meshlink_handle_t *mesh, node_t *n); static bool send_proxyrequest(meshlink_handle_t *mesh, connection_t *c) { switch(mesh->proxytype) { @@ -327,11 +329,20 @@ bool id_h(meshlink_handle_t *mesh, connection_t *c, const char *request) { logger(mesh, MESHLINK_ERROR, "Peer %s had unknown identity (%s)", c->hostname, c->name); return false; } + } - read_ecdsa_public_key(mesh, c); - } else { - if(c->protocol_minor && !ecdsa_active(c->ecdsa)) - c->protocol_minor = 1; + read_ecdsa_public_key(mesh, c); + + if(!ecdsa_active(c->ecdsa)) { + logger(mesh, MESHLINK_ERROR, "No key known for peer %s (%s)", c->name, c->hostname); + + node_t *n = lookup_node(mesh, c->name); + if(n && !n->status.waitingforkey) { + logger(mesh, MESHLINK_INFO, "Requesting key from peer %s (%s)", c->name, c->hostname); + send_req_key(mesh, n); + } + + return false; } /* Forbid version rollback for nodes whose ECDSA key we know */ @@ -360,7 +371,7 @@ bool send_ack(meshlink_handle_t *mesh, connection_t *c) { if(mesh->self->options & OPTION_PMTU_DISCOVERY) c->options |= OPTION_PMTU_DISCOVERY; - return send_request(mesh, c, "%d %s %d %x", ACK, mesh->myport, mesh->dclass, (c->options & 0xffffff) | (PROT_MINOR << 24)); + return send_request(mesh, c, "%d %s %d %x", ACK, mesh->myport, mesh->devclass, (c->options & 0xffffff) | (PROT_MINOR << 24)); } static void send_everything(meshlink_handle_t *mesh, connection_t *c) { @@ -375,16 +386,22 @@ static void send_everything(meshlink_handle_t *mesh, connection_t *c) { bool ack_h(meshlink_handle_t *mesh, connection_t *c, const char *request) { char hisport[MAX_STRING_SIZE]; char *hisaddress; - int dclass; + int devclass; uint32_t options; node_t *n; - if(sscanf(request, "%*d " MAX_STRING " %d %x", hisport, &dclass, &options) != 3) { + if(sscanf(request, "%*d " MAX_STRING " %d %x", hisport, &devclass, &options) != 3) { logger(mesh, MESHLINK_ERROR, "Got bad %s from %s (%s)", "ACK", c->name, c->hostname); return false; } + if(devclass < 0 || devclass > _DEV_CLASS_MAX) { + logger(mesh, MESHLINK_ERROR, "Got bad %s from %s (%s): %s", "ACK", c->name, + c->hostname, "devclass invalid"); + return false; + } + /* Check if we already have a node_t for him */ n = lookup_node(mesh, c->name); @@ -413,8 +430,10 @@ bool ack_h(meshlink_handle_t *mesh, connection_t *c, const char *request) { } } - n->dclass = dclass; - node_write_dclass(mesh, n); + n->devclass = devclass; + node_write_devclass(mesh, n); + + n->last_successfull_connection = time(NULL); n->connection = c; c->node = n; @@ -438,13 +457,15 @@ bool ack_h(meshlink_handle_t *mesh, connection_t *c, const char *request) { /* Create an edge_t for this connection */ + assert(devclass >= 0 && devclass <= _DEV_CLASS_MAX); + c->edge = new_edge(); c->edge->from = mesh->self; c->edge->to = n; sockaddr2str(&c->address, &hisaddress, NULL); c->edge->address = str2sockaddr(hisaddress, hisport); free(hisaddress); - c->edge->weight = cweight_from_dclass(dclass); + c->edge->weight = dev_class_traits[devclass].edge_weight; c->edge->connection = c; c->edge->options = c->options;