X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmeshlink.c;h=4aadaaa9b0ef9c557ab4cb17a3bce030be82fdce;hb=084a3acaa0a62ea1f096ec1916e2adabe6af9d86;hp=ce69e86d486d63eb144b1ab2851d985e2809b854;hpb=3e8459f81c4e7e18d645cc2f4b7e24900ed33e04;p=meshlink diff --git a/src/meshlink.c b/src/meshlink.c index ce69e86d..4aadaaa9 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -341,18 +341,6 @@ static char *get_value(const char *data, const char *var) { return NULL; return val; } -static FILE *fopenmask(const char *filename, const char *mode, mode_t perms) { - mode_t mask = umask(0); - perms &= ~mask; - umask(~perms); - FILE *f = fopen(filename, mode); -#ifdef HAVE_FCHMOD - if((perms & 0444) && f) - fchmod(fileno(f), perms); -#endif - umask(mask); - return f; -} static bool try_bind(int port) { struct addrinfo *ai = NULL; @@ -536,38 +524,27 @@ static bool finalize_join(meshlink_handle_t *mesh) { fclose(f); } - // Generate our key and send a copy to the server - ecdsa_t *key = ecdsa_generate(); - if(!key) - return false; - - char *b64key = ecdsa_get_base64_public_key(key); + char *b64key = ecdsa_get_base64_public_key(mesh->self->connection->ecdsa); if(!b64key) return false; - snprintf(filename, sizeof filename, "%s" SLASH "ecdsa_key.priv", mesh->confbase); - f = fopenmask(filename, "w", 0600); - - if(!ecdsa_write_pem_private_key(key, f)) { - fprintf(stderr, "Error writing private key!\n"); - ecdsa_free(key); - fclose(f); - return false; - } - - fclose(f); - fprintf(fh, "ECDSAPublicKey = %s\n", b64key); + fprintf(fh, "Port = %s\n", mesh->myport); + + fclose(fh); sptps_send_record(&(mesh->sptps), 1, b64key, strlen(b64key)); free(b64key); - ecdsa_free(key); - - check_port(mesh); + free(mesh->self->name); + free(mesh->self->connection->name); + mesh->self->name = xstrdup(name); + mesh->self->connection->name = xstrdup(name); fprintf(stderr, "Configuration stored in: %s\n", mesh->confbase); + load_all_nodes(mesh); + return true; } @@ -1141,7 +1118,7 @@ bool meshlink_join(meshlink_handle_t *mesh, const char *invitation) { *port++ = 0; } - if(!mesh->myport || !*port) + if(!*port) port = "655"; if(!b64decode(slash, mesh->hash, 18) || !b64decode(slash + 24, mesh->cookie, 18))