From a8e0f6f827ee653a6dd4ed7d2408d6851bb86272 Mon Sep 17 00:00:00 2001 From: Quentin Date: Sat, 1 Feb 2020 23:33:45 +0100 Subject: [PATCH] Use only one onion service --- src/donar_client.c | 11 +++++------ src/donar_server.c | 8 ++++---- src/meas_lat.c | 4 ++-- src/net_tools.c | 2 +- src/tor_ctl.c | 27 ++++++++++++++++----------- src/tor_ctl.h | 2 +- src/tor_echo.c | 4 ++-- 7 files changed, 31 insertions(+), 27 deletions(-) diff --git a/src/donar_client.c b/src/donar_client.c index 4f1f598..781f673 100644 --- a/src/donar_client.c +++ b/src/donar_client.c @@ -7,12 +7,11 @@ void load_onion_services(struct donar_client_ctx* ctx, char* onion_file, int por void init_socks5_client(struct donar_client_ctx* app_ctx, int pos) { char target_host[255]; - if (strlen(app_ctx->tos.keys[pos].pub) > 254) { - fprintf(stderr, "Domain name is too long\n"); - exit(EXIT_FAILURE); - } - sprintf(target_host, "%s.onion", app_ctx->tos.keys[pos].pub); - + if (strlen(app_ctx->tos.keys[0].pub) > 254) { + fprintf(stderr, "Domain name is too long\n"); + exit(EXIT_FAILURE); + } + sprintf(target_host, "%s.onion", app_ctx->tos.keys[0].pub); app_ctx->ports[pos] = 7500 + pos; socks5_create_dns_client (&app_ctx->evts, "127.0.0.1", "9050", target_host, app_ctx->ports[pos]); diff --git a/src/donar_server.c b/src/donar_server.c index 64e06b1..44c1987 100644 --- a/src/donar_server.c +++ b/src/donar_server.c @@ -1,7 +1,7 @@ #include "donar_server.h" void create_onion_services(struct tor_os_str* tos, struct tor_ctl* tctl, uint16_t* ports, int ports_count, enum TOR_ONION_FLAGS tof) { - tor_os_create (tos, "onion_services.pub", "onion_services.txt", ports_count); + tor_os_create (tos, "onion_services.pub", "onion_services.txt", 1); tor_os_read (tos); int err = 0; @@ -10,7 +10,7 @@ void create_onion_services(struct tor_os_str* tos, struct tor_ctl* tctl, uint16_ fprintf(stderr, "Unable to open Tor Socket\n"); exit(EXIT_FAILURE); } - err = tor_ctl_add_onion (tctl, tos, ports, tof); + err = tor_ctl_add_onion (tctl, tos, ports, ports_count, tof); if (err != 0) { fprintf(stderr, "Unable to create Onion Services (error: %d)\n", err); exit(EXIT_FAILURE); @@ -82,7 +82,7 @@ struct donar_server_os_republish_params { struct donar_server_ctx* dctx; struct donar_params* dp; }; - +/* void republish_tor_os(struct evt_core_ctx* ctx, void* user_data) { struct donar_server_os_republish_params* dsorp = user_data; @@ -94,7 +94,7 @@ void republish_tor_os(struct evt_core_ctx* ctx, void* user_data) { exit(EXIT_FAILURE); } printf("Republish Tor OS\n"); -} +}*/ void donar_server(struct donar_server_ctx* ctx, struct donar_params* dp) { struct algo_params ap = { diff --git a/src/meas_lat.c b/src/meas_lat.c index ed5af9e..a8ff328 100644 --- a/src/meas_lat.c +++ b/src/meas_lat.c @@ -350,7 +350,7 @@ void spawn_tor_server(struct evt_core_ctx* evts, uint16_t *ports) { } void measlat_create_onion_services(struct tor_os_str* tos, struct tor_ctl* tctl, uint16_t* ports, int ports_count, enum TOR_ONION_FLAGS tof) { - tor_os_create (tos, "onion_services.pub", "onion_services.txt", ports_count); + tor_os_create (tos, "onion_services.pub", "onion_services.txt", 1); tor_os_read (tos); int err = 0; @@ -359,7 +359,7 @@ void measlat_create_onion_services(struct tor_os_str* tos, struct tor_ctl* tctl, fprintf(stderr, "Unable to open Tor Socket\n"); exit(EXIT_FAILURE); } - err = tor_ctl_add_onion (tctl, tos, ports, tof); + err = tor_ctl_add_onion (tctl, tos, ports, ports_count, tof); if (err != 0) { fprintf(stderr, "Unable to create Onion Services (error: %d)\n", err); exit(EXIT_FAILURE); diff --git a/src/net_tools.c b/src/net_tools.c index 0b01658..4a44e14 100644 --- a/src/net_tools.c +++ b/src/net_tools.c @@ -34,7 +34,7 @@ int create_ip_client(char* host, char* service, int type) { } if (cursor == NULL) { - fprintf(stderr, "No connect worked\n"); + fprintf(stderr, "No connect worked for %s:%s\n", host, service); exit(EXIT_FAILURE); } diff --git a/src/tor_ctl.c b/src/tor_ctl.c index 093d16b..cf04583 100644 --- a/src/tor_ctl.c +++ b/src/tor_ctl.c @@ -51,7 +51,7 @@ void tor_ctl_list_onions(struct tor_ctl* ctx) { } } -int tor_ctl_add_onion(struct tor_ctl* ctx, struct tor_os_str* tos, uint16_t* port, enum TOR_ONION_FLAGS flags) { +int tor_ctl_add_onion(struct tor_ctl* ctx, struct tor_os_str* tos, uint16_t* port, uint64_t port_per_os, enum TOR_ONION_FLAGS flags) { int err = 0; char buffer1[1024] = {0}; char buffer2[1024] = {0}; @@ -59,12 +59,14 @@ int tor_ctl_add_onion(struct tor_ctl* ctx, struct tor_os_str* tos, uint16_t* por /* Add onion services loaded from file */ for (int i = 0; i < tos->filled; i++) { - if (flags == TOR_ONION_FLAG_NONE) - fprintf(ctx->wsock, "add_onion %s Port=%d,127.13.3.7:%d\n", tos->keys[i].priv, port[i], port[i]); + fprintf(ctx->wsock, "add_onion %s ", tos->keys[i].priv); + for (int j = 0; j < port_per_os; j++) { + fprintf(ctx->wsock, "Port=%d,127.13.3.7:%d ", port[i*port_per_os+j], port[i*port_per_os+j]); + } + if (flags == TOR_ONION_FLAG_NONE) fprintf(ctx->wsock, "\n"); else { - fprintf(ctx->wsock, "add_onion %s Port=%d,127.13.3.7:%d Flags=", tos->keys[i].priv, port[i], port[i]); - if (flags & TOR_ONION_FLAG_NON_ANONYMOUS) - fprintf(ctx->wsock, "NonAnonymous,"); + fprintf(ctx->wsock, "Flags="); + if (flags & TOR_ONION_FLAG_NON_ANONYMOUS) fprintf(ctx->wsock, "NonAnonymous,"); fprintf(ctx->wsock, "\n"); } @@ -80,14 +82,17 @@ int tor_ctl_add_onion(struct tor_ctl* ctx, struct tor_os_str* tos, uint16_t* por /* Complete by creating new onion services */ for (int i = tos->filled; i < tos->size; i++) { - if (flags == TOR_ONION_FLAG_NONE) - fprintf(ctx->wsock, "add_onion NEW:ED25519-V3 Port=%d\n", port[i]); + fprintf(ctx->wsock, "add_onion NEW:ED25519-V3 "); + for (int j = 0; j < port_per_os; j++) { + fprintf(ctx->wsock, "Port=%d,127.13.3.7:%d ", port[i*port_per_os+j], port[i*port_per_os+j]); + } + if (flags == TOR_ONION_FLAG_NONE) fprintf(ctx->wsock, "\n"); else { - fprintf(ctx->wsock, "add_onion NEW:ED25519-V3 Port=%d Flags=", port[i]); - if (flags & TOR_ONION_FLAG_NON_ANONYMOUS) - fprintf(ctx->wsock, "NonAnonymous,"); + fprintf(ctx->wsock, "Flags="); + if (flags & TOR_ONION_FLAG_NON_ANONYMOUS) fprintf(ctx->wsock, "NonAnonymous,"); fprintf(ctx->wsock, "\n"); } + //fprintf(ctx->wsock, "add_onion NEW:RSA1024 Port=%d\n", port[i]); fscanf(ctx->rsock, "%d", &err); diff --git a/src/tor_ctl.h b/src/tor_ctl.h index 3f85eb4..e1c6c86 100644 --- a/src/tor_ctl.h +++ b/src/tor_ctl.h @@ -20,6 +20,6 @@ enum TOR_ONION_FLAGS { }; int tor_ctl_connect(struct tor_ctl* ctx, char* addr, char* service); -int tor_ctl_add_onion(struct tor_ctl* ctx, struct tor_os_str* tos, uint16_t* port, enum TOR_ONION_FLAGS flags); +int tor_ctl_add_onion(struct tor_ctl* ctx, struct tor_os_str* tos, uint16_t* port, uint64_t port_per_os, enum TOR_ONION_FLAGS flags); void tor_ctl_list_onions(struct tor_ctl* ctx); void tor_ctl_close(struct tor_ctl* ctx); diff --git a/src/tor_echo.c b/src/tor_echo.c index 7c33600..98dd874 100644 --- a/src/tor_echo.c +++ b/src/tor_echo.c @@ -14,7 +14,7 @@ struct torecho_ctx { }; void te_create_onion_services(struct tor_os_str* tos, struct tor_ctl* tctl, uint16_t* ports, int ports_count, enum TOR_ONION_FLAGS tof) { - tor_os_create (tos, "onion_services.pub", "onion_services.txt", ports_count); + tor_os_create (tos, "onion_services.pub", "onion_services.txt", 1); tor_os_read (tos); int err = 0; @@ -23,7 +23,7 @@ void te_create_onion_services(struct tor_os_str* tos, struct tor_ctl* tctl, uint fprintf(stderr, "Unable to open Tor Socket\n"); exit(EXIT_FAILURE); } - err = tor_ctl_add_onion (tctl, tos, ports, tof); + err = tor_ctl_add_onion (tctl, tos, ports, ports_count, tof); if (err != 0) { fprintf(stderr, "Unable to create Onion Services (error: %d)\n", err); exit(EXIT_FAILURE);