Use only one onion service

This commit is contained in:
Quentin 2020-02-01 23:33:45 +01:00
parent b8cf2cbcab
commit a8e0f6f827
7 changed files with 31 additions and 27 deletions

View file

@ -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]);

View file

@ -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 = {

View file

@ -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);

View file

@ -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);
}

View file

@ -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);

View file

@ -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);

View file

@ -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);