X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=src%2Fprotocol_auth.c;h=487f34c96ebef3f640ea2339540dc7607100fe62;hb=dd2cf09a9ac438b65a1f4c9dcff8d87a2b504538;hp=610cbaf8593d0c415033a8ca945468b3002ce7a8;hpb=b67296418c51784d39a24c3041e2cb199bee06f2;p=meshlink diff --git a/src/protocol_auth.c b/src/protocol_auth.c index 610cbaf8..487f34c9 100644 --- a/src/protocol_auth.c +++ b/src/protocol_auth.c @@ -136,9 +136,6 @@ static bool send_proxyrequest(meshlink_handle_t *mesh, connection_t *c) { logger(mesh, MESHLINK_ERROR, "Proxy type not implemented yet"); return false; - case PROXY_EXEC: - return true; - default: logger(mesh, MESHLINK_ERROR, "Unknown proxy type"); return false; @@ -154,7 +151,7 @@ bool send_id(meshlink_handle_t *mesh, connection_t *c) { return false; } - return send_request(mesh, c, "%d %s %d.%d", ID, mesh->self->connection->name, mesh->self->connection->protocol_major, minor); + return send_request(mesh, c, "%d %s %d.%d %s", ID, mesh->self->connection->name, mesh->self->connection->protocol_major, minor, mesh->appname); } static bool finalize_invitation(meshlink_handle_t *mesh, connection_t *c, const void *data, uint16_t len) { @@ -242,6 +239,24 @@ static bool receive_invitation_sptps(void *handle, uint8_t type, const void *dat if(!f) { logger(mesh, MESHLINK_ERROR, "Error trying to open invitation %s\n", cookie); + unlink(usedname); + return false; + } + + // Check the timestamp + struct stat st; + + if(fstat(fileno(f), &st)) { + logger(mesh, MESHLINK_ERROR, "Could not stat invitation file %s\n", usedname); + fclose(f); + unlink(usedname); + return false; + } + + if(time(NULL) > st.st_mtime + mesh->invitation_timeout) { + logger(mesh, MESHLINK_ERROR, "Peer %s tried to use an outdated invitation file %s\n", c->name, usedname); + fclose(f); + unlink(usedname); return false; } @@ -372,6 +387,14 @@ bool id_h(meshlink_handle_t *mesh, connection_t *c, const char *request) { } } + bool blacklisted = false; + get_config_bool(lookup_config(c->config_tree, "blacklisted"), &blacklisted); + + if(blacklisted) { + logger(mesh, MESHLINK_EPEER, "Peer %s is blacklisted", c->name); + return false; + } + read_ecdsa_public_key(mesh, c); if(!ecdsa_active(c->ecdsa)) { @@ -379,7 +402,7 @@ bool id_h(meshlink_handle_t *mesh, connection_t *c, const char *request) { node_t *n = lookup_node(mesh, c->name); - if(n && !n->status.waitingforkey) { + if(n && n->status.reachable && !n->status.waitingforkey) { logger(mesh, MESHLINK_INFO, "Requesting key from peer %s", c->name); send_req_key(mesh, n); } @@ -423,7 +446,7 @@ static void send_everything(meshlink_handle_t *mesh, connection_t *c) { for splay_each(node_t, n, mesh->nodes) { for splay_each(edge_t, e, n->edge_tree) { - send_add_edge(mesh, c, e); + send_add_edge(mesh, c, e, 0); } } } @@ -518,7 +541,7 @@ bool ack_h(meshlink_handle_t *mesh, connection_t *c, const char *request) { /* Notify everyone of the new edge */ - send_add_edge(mesh, mesh->everyone, c->edge); + send_add_edge(mesh, mesh->everyone, c->edge, 0); /* Run MST and SSSP algorithms */