mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-13 06:33:44 +01:00
Add tests for bug #40084
This commit is contained in:
parent
af48afe667
commit
157fe4597e
@ -1649,7 +1649,7 @@ handle_control_hspost(control_connection_t *conn,
|
|||||||
* On success (RSAE_OKAY), the address_out points to a newly allocated string
|
* On success (RSAE_OKAY), the address_out points to a newly allocated string
|
||||||
* containing the onion address without the .onion part. On error, address_out
|
* containing the onion address without the .onion part. On error, address_out
|
||||||
* is untouched. */
|
* is untouched. */
|
||||||
static hs_service_add_ephemeral_status_t
|
STATIC hs_service_add_ephemeral_status_t
|
||||||
add_onion_helper_add_service(int hs_version,
|
add_onion_helper_add_service(int hs_version,
|
||||||
add_onion_secret_key_t *pk,
|
add_onion_secret_key_t *pk,
|
||||||
smartlist_t *port_cfgs, int max_streams,
|
smartlist_t *port_cfgs, int max_streams,
|
||||||
@ -2010,7 +2010,6 @@ handle_control_add_onion(control_connection_t *conn,
|
|||||||
smartlist_free(auth_clients_v3_str);
|
smartlist_free(auth_clients_v3_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (auth_created_clients) {
|
if (auth_created_clients) {
|
||||||
// Do not free entries; they are the same as auth_clients
|
// Do not free entries; they are the same as auth_clients
|
||||||
smartlist_free(auth_created_clients);
|
smartlist_free(auth_created_clients);
|
||||||
|
@ -103,6 +103,17 @@ STATIC control_cmd_args_t *control_cmd_parse_args(
|
|||||||
size_t body_len,
|
size_t body_len,
|
||||||
const char *body,
|
const char *body,
|
||||||
char **error_out);
|
char **error_out);
|
||||||
|
#ifdef TOR_UNIT_TESTS
|
||||||
|
#include "feature/hs/hs_common.h"
|
||||||
|
|
||||||
|
STATIC hs_service_add_ephemeral_status_t
|
||||||
|
add_onion_helper_add_service(int hs_version,
|
||||||
|
add_onion_secret_key_t *pk,
|
||||||
|
smartlist_t *port_cfgs, int max_streams,
|
||||||
|
int max_streams_close_circuit, int auth_type,
|
||||||
|
smartlist_t *auth_clients,
|
||||||
|
smartlist_t *auth_clients_v3, char **address_out);
|
||||||
|
#endif /* defined(TOR_UNIT_TESTS) */
|
||||||
|
|
||||||
#endif /* defined(CONTROL_CMD_PRIVATE) */
|
#endif /* defined(CONTROL_CMD_PRIVATE) */
|
||||||
|
|
||||||
|
@ -3756,9 +3756,11 @@ hs_service_add_ephemeral(ed25519_secret_key_t *sk, smartlist_t *ports,
|
|||||||
if (service->config.clients == NULL) {
|
if (service->config.clients == NULL) {
|
||||||
service->config.clients = smartlist_new();
|
service->config.clients = smartlist_new();
|
||||||
}
|
}
|
||||||
SMARTLIST_FOREACH(auth_clients_v3, hs_service_authorized_client_t *, c,
|
SMARTLIST_FOREACH(auth_clients_v3, hs_service_authorized_client_t *, c, {
|
||||||
smartlist_add(service->config.clients, c));
|
if (c != NULL) {
|
||||||
|
smartlist_add(service->config.clients, c);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
/* Build the onion address for logging purposes but also the control port
|
/* Build the onion address for logging purposes but also the control port
|
||||||
* uses it for the HS_DESC event. */
|
* uses it for the HS_DESC event. */
|
||||||
|
@ -3818,6 +3818,7 @@ upload_service_descriptor(rend_service_t *service)
|
|||||||
smartlist_clear(client_cookies);
|
smartlist_clear(client_cookies);
|
||||||
switch (service->auth_type) {
|
switch (service->auth_type) {
|
||||||
case REND_NO_AUTH:
|
case REND_NO_AUTH:
|
||||||
|
case REND_V3_AUTH:
|
||||||
/* Do nothing here. */
|
/* Do nothing here. */
|
||||||
break;
|
break;
|
||||||
case REND_BASIC_AUTH:
|
case REND_BASIC_AUTH:
|
||||||
|
@ -7,15 +7,17 @@
|
|||||||
**/
|
**/
|
||||||
|
|
||||||
#define CONTROL_EVENTS_PRIVATE
|
#define CONTROL_EVENTS_PRIVATE
|
||||||
|
#define CONTROL_CMD_PRIVATE
|
||||||
#define HS_CLIENT_PRIVATE
|
#define HS_CLIENT_PRIVATE
|
||||||
|
#define HS_SERVICE_PRIVATE
|
||||||
|
|
||||||
#include "core/or/or.h"
|
#include "core/or/or.h"
|
||||||
#include "test/test.h"
|
#include "test/test.h"
|
||||||
#include "test/test_helpers.h"
|
#include "test/test_helpers.h"
|
||||||
#include "core/mainloop/connection.h"
|
#include "core/mainloop/connection.h"
|
||||||
#include "feature/control/control.h"
|
#include "feature/control/control.h"
|
||||||
#include "feature/control/control_events.h"
|
|
||||||
#include "feature/control/control_cmd.h"
|
#include "feature/control/control_cmd.h"
|
||||||
|
#include "feature/control/control_events.h"
|
||||||
#include "feature/control/control_fmt.h"
|
#include "feature/control/control_fmt.h"
|
||||||
#include "feature/control/control_connection_st.h"
|
#include "feature/control/control_connection_st.h"
|
||||||
#include "app/config/config.h"
|
#include "app/config/config.h"
|
||||||
@ -23,9 +25,11 @@
|
|||||||
#include "feature/hs/hs_client.h"
|
#include "feature/hs/hs_client.h"
|
||||||
#include "feature/hs/hs_control.h"
|
#include "feature/hs/hs_control.h"
|
||||||
#include "feature/nodelist/nodelist.h"
|
#include "feature/nodelist/nodelist.h"
|
||||||
|
#include "feature/rend/rendservice.h"
|
||||||
|
|
||||||
#include "feature/nodelist/node_st.h"
|
#include "feature/nodelist/node_st.h"
|
||||||
#include "feature/nodelist/routerstatus_st.h"
|
#include "feature/nodelist/routerstatus_st.h"
|
||||||
|
#include "lib/container/smartlist.h"
|
||||||
#include "lib/crypt_ops/crypto_format.h"
|
#include "lib/crypt_ops/crypto_format.h"
|
||||||
|
|
||||||
#ifdef HAVE_SYS_STAT_H
|
#ifdef HAVE_SYS_STAT_H
|
||||||
@ -735,6 +739,76 @@ test_hs_control_add_onion_with_bad_pubkey(void *arg)
|
|||||||
tor_free(conn.current_cmd);
|
tor_free(conn.current_cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Test that add_onion_helper_add_service can add the service. */
|
||||||
|
static void
|
||||||
|
test_hs_add_onion_helper_add_service(void *arg)
|
||||||
|
{
|
||||||
|
int hs_version_good, hs_version_bad;
|
||||||
|
add_onion_secret_key_t sk_good, sk_bad;
|
||||||
|
ed25519_public_key_t pk_good, pk_bad;
|
||||||
|
char *key_new_blob_good = NULL, *key_new_blob_bad = NULL;
|
||||||
|
const char *key_new_alg_good = NULL, *key_new_alg_bad = NULL;
|
||||||
|
hs_service_authorized_client_t *client_good, *client_bad;
|
||||||
|
smartlist_t *list_v2, *list_good, *list_bad;
|
||||||
|
hs_service_ht *global_map;
|
||||||
|
rend_service_port_config_t *portcfg;
|
||||||
|
smartlist_t *portcfgs;
|
||||||
|
char *address_out_good, *address_out_bad;
|
||||||
|
|
||||||
|
(void) arg;
|
||||||
|
|
||||||
|
hs_init();
|
||||||
|
global_map = get_hs_service_map();
|
||||||
|
|
||||||
|
portcfg = rend_service_parse_port_config("8080", ",", NULL);
|
||||||
|
portcfgs = smartlist_new();
|
||||||
|
smartlist_add(portcfgs, portcfg);
|
||||||
|
|
||||||
|
memset(&sk_good, 0, sizeof(sk_good));
|
||||||
|
memset(&sk_bad, 0, sizeof(sk_bad));
|
||||||
|
|
||||||
|
add_onion_helper_keyarg("NEW:ED25519-V3", 0, &key_new_alg_good,
|
||||||
|
&key_new_blob_good, &sk_good, &hs_version_good, NULL);
|
||||||
|
add_onion_helper_keyarg("NEW:ED25519-V3", 0, &key_new_alg_bad,
|
||||||
|
&key_new_blob_bad, &sk_bad, &hs_version_bad, NULL);
|
||||||
|
|
||||||
|
ed25519_public_key_generate(&pk_good, sk_good.v3);
|
||||||
|
ed25519_public_key_generate(&pk_bad, sk_bad.v3);
|
||||||
|
|
||||||
|
client_good = parse_authorized_client_key(
|
||||||
|
"N2NU7BSRL6YODZCYPN4CREB54TYLKGIE2KYOQWLFYC23ZJVCE5DQ");
|
||||||
|
client_bad = parse_authorized_client_key("dummy");
|
||||||
|
|
||||||
|
list_v2 = smartlist_new();
|
||||||
|
list_good = smartlist_new();
|
||||||
|
smartlist_add(list_good, client_good);
|
||||||
|
list_bad = smartlist_new();
|
||||||
|
smartlist_add(list_bad, client_bad);
|
||||||
|
|
||||||
|
add_onion_helper_add_service(HS_VERSION_THREE, &sk_good, portcfgs, 1, 1,
|
||||||
|
REND_V3_AUTH, list_v2, list_good, &address_out_good);
|
||||||
|
add_onion_helper_add_service(HS_VERSION_THREE, &sk_bad, portcfgs, 1, 1,
|
||||||
|
REND_V3_AUTH, list_v2, list_bad, &address_out_bad);
|
||||||
|
|
||||||
|
hs_service_t *srv_good = find_service(global_map, &pk_good);
|
||||||
|
hs_service_t *srv_bad = find_service(global_map, &pk_bad);
|
||||||
|
|
||||||
|
tt_int_op(smartlist_len(srv_good->config.clients), OP_EQ, 1);
|
||||||
|
tt_int_op(smartlist_len(srv_bad->config.clients), OP_EQ, 0);
|
||||||
|
|
||||||
|
done:
|
||||||
|
tor_free(key_new_blob_good);
|
||||||
|
tor_free(key_new_blob_bad);
|
||||||
|
tor_free(address_out_good);
|
||||||
|
tor_free(address_out_bad);
|
||||||
|
|
||||||
|
service_authorized_client_free(client_good);
|
||||||
|
|
||||||
|
smartlist_free(list_v2);
|
||||||
|
smartlist_free(list_good);
|
||||||
|
smartlist_free(list_bad);
|
||||||
|
}
|
||||||
|
|
||||||
struct testcase_t hs_control_tests[] = {
|
struct testcase_t hs_control_tests[] = {
|
||||||
{ "hs_desc_event", test_hs_desc_event, TT_FORK,
|
{ "hs_desc_event", test_hs_desc_event, TT_FORK,
|
||||||
NULL, NULL },
|
NULL, NULL },
|
||||||
@ -748,6 +822,8 @@ struct testcase_t hs_control_tests[] = {
|
|||||||
test_hs_control_store_permanent_creds, TT_FORK, NULL, NULL },
|
test_hs_control_store_permanent_creds, TT_FORK, NULL, NULL },
|
||||||
{ "hs_control_add_onion_with_bad_pubkey",
|
{ "hs_control_add_onion_with_bad_pubkey",
|
||||||
test_hs_control_add_onion_with_bad_pubkey, TT_FORK, NULL, NULL },
|
test_hs_control_add_onion_with_bad_pubkey, TT_FORK, NULL, NULL },
|
||||||
|
{ "hs_add_onion_helper_add_service",
|
||||||
|
test_hs_add_onion_helper_add_service, TT_FORK, NULL, NULL},
|
||||||
|
|
||||||
END_OF_TESTCASES
|
END_OF_TESTCASES
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user