From f74a80dc3b2ada940e72cd174af5779cac3c3948 Mon Sep 17 00:00:00 2001 From: George Kadianakis Date: Mon, 8 Apr 2019 13:01:18 +0300 Subject: Hiding crypt_path_t: Move init functions to crypt_path.c. This commit only moves code. --- src/feature/rend/rendservice.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/feature/rend') diff --git a/src/feature/rend/rendservice.c b/src/feature/rend/rendservice.c index 996e7b9a28..5c267f8e34 100644 --- a/src/feature/rend/rendservice.c +++ b/src/feature/rend/rendservice.c @@ -18,6 +18,7 @@ #include "core/or/circuituse.h" #include "core/or/policies.h" #include "core/or/relay.h" +#include "core/or/crypt_path.h" #include "feature/client/circpathbias.h" #include "feature/control/control_events.h" #include "feature/dirclient/dirclient.h" -- cgit v1.2.3-54-g00ecf From f5635989b06260710b282e75be7b731e2846f700 Mon Sep 17 00:00:00 2001 From: George Kadianakis Date: Mon, 8 Apr 2019 16:18:44 +0300 Subject: Hiding crypt_path_t: Create a constructor for crypt_path_t. We are using an opaque pointer so the structure needs to be allocated on the heap. This means we now need a constructor for crypt_path_t. Also modify all places initializing a crypt_path_t to use the constructor. --- src/core/or/crypt_path.c | 15 +++++++++++++-- src/core/or/crypt_path.h | 2 ++ src/core/or/crypt_path_st.h | 5 ++--- src/feature/hs/hs_circuit.c | 3 +-- src/feature/rend/rendclient.c | 5 ++--- src/feature/rend/rendservice.c | 3 +-- src/test/test_circuitpadding.c | 13 +++++++------ src/test/test_hs_client.c | 5 ++--- src/test/test_hs_service.c | 4 ++-- src/test/test_relaycell.c | 4 ++-- src/test/test_relaycrypt.c | 2 +- 11 files changed, 35 insertions(+), 26 deletions(-) (limited to 'src/feature/rend') diff --git a/src/core/or/crypt_path.c b/src/core/or/crypt_path.c index 54f5623d32..975af6c16d 100644 --- a/src/core/or/crypt_path.c +++ b/src/core/or/crypt_path.c @@ -26,6 +26,17 @@ #include "core/or/crypt_path_st.h" #include "core/or/cell_st.h" +/** Initialize and return a minimal crypt_path_t */ +crypt_path_t * +crypt_path_new(void) +{ + crypt_path_t *cpath = tor_malloc_zero(sizeof(crypt_path_t)); + cpath->magic = CRYPT_PATH_MAGIC; + cpath->private = tor_malloc_zero(sizeof(struct crypt_path_private_t)); + + return cpath; +} + /** Add new_hop to the end of the doubly-linked-list head_ptr. * This function is used to extend cpath by another hop. */ @@ -49,12 +60,11 @@ onion_append_to_cpath(crypt_path_t **head_ptr, crypt_path_t *new_hop) int onion_append_hop(crypt_path_t **head_ptr, extend_info_t *choice) { - crypt_path_t *hop = tor_malloc_zero(sizeof(crypt_path_t)); + crypt_path_t *hop = crypt_path_new(); /* link hop into the cpath, at the end. */ onion_append_to_cpath(head_ptr, hop); - hop->magic = CRYPT_PATH_MAGIC; hop->state = CPATH_STATE_CLOSED; hop->extend_info = extend_info_dup(choice); @@ -158,6 +168,7 @@ circuit_free_cpath_node(crypt_path_t *victim) onion_handshake_state_release(&victim->handshake_state); crypto_dh_free(victim->rend_dh_handshake_state); extend_info_free(victim->extend_info); + tor_free(victim->private); memwipe(victim, 0xBB, sizeof(crypt_path_t)); /* poison memory */ tor_free(victim); diff --git a/src/core/or/crypt_path.h b/src/core/or/crypt_path.h index e8455c6326..c6d1cd1400 100644 --- a/src/core/or/crypt_path.h +++ b/src/core/or/crypt_path.h @@ -3,6 +3,8 @@ * \brief Header file for crypt_path.c. **/ +crypt_path_t *crypt_path_new(void); + /* rename */ void assert_cpath_layer_ok(const crypt_path_t *cp); diff --git a/src/core/or/crypt_path_st.h b/src/core/or/crypt_path_st.h index 833cfefad1..7da3c57f49 100644 --- a/src/core/or/crypt_path_st.h +++ b/src/core/or/crypt_path_st.h @@ -8,9 +8,6 @@ #define CRYPT_PATH_ST_H #include "core/or/relay_crypto_st.h" -struct crypto_dh_t; - -#define CRYPT_PATH_MAGIC 0x70127012u struct fast_handshake_state_t; struct ntor_handshake_state_t; @@ -26,6 +23,8 @@ struct onion_handshake_state_t { #ifdef CRYPT_PATH_PRIVATE +#define CRYPT_PATH_MAGIC 0x70127012u + /* The private parts of crypt path that don't need to be exposed to all the * modules. */ struct crypt_path_private_t { diff --git a/src/feature/hs/hs_circuit.c b/src/feature/hs/hs_circuit.c index a42228d362..3356db9d90 100644 --- a/src/feature/hs/hs_circuit.c +++ b/src/feature/hs/hs_circuit.c @@ -87,8 +87,7 @@ create_rend_cpath(const uint8_t *ntor_key_seed, size_t seed_len, } /* Setup the cpath */ - cpath = tor_malloc_zero(sizeof(crypt_path_t)); - cpath->magic = CRYPT_PATH_MAGIC; + cpath = crypt_path_new(); if (circuit_init_cpath_crypto(cpath, (char*)keys, sizeof(keys), is_service_side, 1) < 0) { diff --git a/src/feature/rend/rendclient.c b/src/feature/rend/rendclient.c index f84d221b1a..c6e9dde878 100644 --- a/src/feature/rend/rendclient.c +++ b/src/feature/rend/rendclient.c @@ -16,6 +16,7 @@ #include "core/or/circuituse.h" #include "core/or/connection_edge.h" #include "core/or/relay.h" +#include "core/or/crypt_path.h" #include "feature/client/circpathbias.h" #include "feature/control/control_events.h" #include "feature/dirclient/dirclient.h" @@ -194,9 +195,7 @@ rend_client_send_introduction(origin_circuit_t *introcirc, /* Initialize the pending_final_cpath and start the DH handshake. */ cpath = rendcirc->build_state->pending_final_cpath; if (!cpath) { - cpath = rendcirc->build_state->pending_final_cpath = - tor_malloc_zero(sizeof(crypt_path_t)); - cpath->magic = CRYPT_PATH_MAGIC; + cpath = rendcirc->build_state->pending_final_cpath = crypt_path_new(); if (!(cpath->rend_dh_handshake_state = crypto_dh_new(DH_TYPE_REND))) { log_warn(LD_BUG, "Internal error: couldn't allocate DH."); status = -2; diff --git a/src/feature/rend/rendservice.c b/src/feature/rend/rendservice.c index 5c267f8e34..38da4cfe7a 100644 --- a/src/feature/rend/rendservice.c +++ b/src/feature/rend/rendservice.c @@ -2158,8 +2158,7 @@ rend_service_receive_introduction(origin_circuit_t *circuit, launched->build_state->service_pending_final_cpath_ref->refcount = 1; launched->build_state->service_pending_final_cpath_ref->cpath = cpath = - tor_malloc_zero(sizeof(crypt_path_t)); - cpath->magic = CRYPT_PATH_MAGIC; + crypt_path_new(); launched->build_state->expiry_time = now + MAX_REND_TIMEOUT; cpath->rend_dh_handshake_state = dh; diff --git a/src/test/test_circuitpadding.c b/src/test/test_circuitpadding.c index 8a2667e802..6fa790c40d 100644 --- a/src/test/test_circuitpadding.c +++ b/src/test/test_circuitpadding.c @@ -115,7 +115,7 @@ new_fake_orcirc(channel_t *nchan, channel_t *pchan) { or_circuit_t *orcirc = NULL; circuit_t *circ = NULL; - crypt_path_t tmp_cpath; + crypt_path_t *tmp_cpath; char whatevs_key[CPATH_KEY_MATERIAL_LEN]; orcirc = tor_malloc_zero(sizeof(*orcirc)); @@ -144,13 +144,15 @@ new_fake_orcirc(channel_t *nchan, channel_t *pchan) circuit_set_p_circid_chan(orcirc, orcirc->p_circ_id, pchan); circuit_set_n_circid_chan(circ, circ->n_circ_id, nchan); - memset(&tmp_cpath, 0, sizeof(tmp_cpath)); - if (circuit_init_cpath_crypto(&tmp_cpath, whatevs_key, + tmp_cpath = crypt_path_new(); + if (circuit_init_cpath_crypto(tmp_cpath, whatevs_key, sizeof(whatevs_key), 0, 0)<0) { log_warn(LD_BUG,"Circuit initialization failed"); return NULL; } - orcirc->crypto = tmp_cpath.private->crypto; + orcirc->crypto = tmp_cpath->private->crypto; + tor_free(tmp_cpath->private); + tor_free(tmp_cpath); return orcirc; } @@ -1618,10 +1620,9 @@ simulate_single_hop_extend(circuit_t *client, circuit_t *mid_relay, circpad_cell_event_nonpadding_received((circuit_t*)client); // Add a hop to cpath - crypt_path_t *hop = tor_malloc_zero(sizeof(crypt_path_t)); + crypt_path_t *hop = crypt_path_new(); onion_append_to_cpath(&TO_ORIGIN_CIRCUIT(client)->cpath, hop); - hop->magic = CRYPT_PATH_MAGIC; hop->state = CPATH_STATE_OPEN; // add an extend info to indicate if this node supports padding or not. diff --git a/src/test/test_hs_client.c b/src/test/test_hs_client.c index 607be339a9..9e1d73a855 100644 --- a/src/test/test_hs_client.c +++ b/src/test/test_hs_client.c @@ -39,6 +39,7 @@ #include "feature/hs/hs_cache.h" #include "core/or/circuitlist.h" #include "core/or/circuitbuild.h" +#include "core/or/crypt_path.h" #include "core/mainloop/connection.h" #include "core/or/connection_edge.h" #include "feature/nodelist/networkstatus.h" @@ -145,9 +146,7 @@ helper_get_circ_and_stream_for_test(origin_circuit_t **circ_out, if (is_legacy) { /* Legacy: Setup rend data and final cpath */ - or_circ->build_state->pending_final_cpath = - tor_malloc_zero(sizeof(crypt_path_t)); - or_circ->build_state->pending_final_cpath->magic = CRYPT_PATH_MAGIC; + or_circ->build_state->pending_final_cpath = crypt_path_new(); or_circ->build_state->pending_final_cpath->rend_dh_handshake_state = crypto_dh_new(DH_TYPE_REND); tt_assert( diff --git a/src/test/test_hs_service.c b/src/test/test_hs_service.c index bfa66f551a..357db89040 100644 --- a/src/test/test_hs_service.c +++ b/src/test/test_hs_service.c @@ -38,6 +38,7 @@ #include "core/or/circuitbuild.h" #include "core/or/circuitlist.h" #include "core/or/circuituse.h" +#include "core/or/crypt_path.h" #include "core/or/connection_edge.h" #include "core/or/edge_connection_st.h" #include "core/or/relay.h" @@ -218,8 +219,7 @@ helper_create_origin_circuit(int purpose, int flags) circ = origin_circuit_init(purpose, flags); tor_assert(circ); - circ->cpath = tor_malloc_zero(sizeof(crypt_path_t)); - circ->cpath->magic = CRYPT_PATH_MAGIC; + circ->cpath = crypt_path_new(); circ->cpath->state = CPATH_STATE_OPEN; circ->cpath->package_window = circuit_initial_package_window(); circ->cpath->deliver_window = CIRCWINDOW_START; diff --git a/src/test/test_relaycell.c b/src/test/test_relaycell.c index 0623583511..b48c7ca8ac 100644 --- a/src/test/test_relaycell.c +++ b/src/test/test_relaycell.c @@ -16,6 +16,7 @@ #include "lib/crypt_ops/crypto_rand.h" #include "core/or/circuitbuild.h" #include "core/or/circuitlist.h" +#include "core/or/crypt_path.h" #include "core/or/connection_edge.h" #include "core/or/relay.h" #include "test/test.h" @@ -90,8 +91,7 @@ helper_create_origin_circuit(int purpose, int flags) circ = origin_circuit_init(purpose, flags); tor_assert(circ); - circ->cpath = tor_malloc_zero(sizeof(crypt_path_t)); - circ->cpath->magic = CRYPT_PATH_MAGIC; + circ->cpath = crypt_path_new(); circ->cpath->state = CPATH_STATE_OPEN; circ->cpath->package_window = circuit_initial_package_window(); circ->cpath->deliver_window = CIRCWINDOW_START; diff --git a/src/test/test_relaycrypt.c b/src/test/test_relaycrypt.c index b94ee07abc..1fe5df96ed 100644 --- a/src/test/test_relaycrypt.c +++ b/src/test/test_relaycrypt.c @@ -50,7 +50,7 @@ testing_circuitset_setup(const struct testcase_t *testcase) cs->origin_circ = origin_circuit_new(); cs->origin_circ->base_.purpose = CIRCUIT_PURPOSE_C_GENERAL; for (i=0; i<3; ++i) { - crypt_path_t *hop = tor_malloc_zero(sizeof(*hop)); + crypt_path_t *hop = crypt_path_new(); relay_crypto_init(&hop->private->crypto, KEY_MATERIAL[i], sizeof(KEY_MATERIAL[i]), 0, 0); hop->state = CPATH_STATE_OPEN; -- cgit v1.2.3-54-g00ecf From 58fbbc1409f65bbb65c9da03a035a5767820146b Mon Sep 17 00:00:00 2001 From: George Kadianakis Date: Tue, 9 Apr 2019 12:38:19 +0300 Subject: Hiding crypt_path_t: Rename some functions to fit the crypt_path API. Some of these functions are now public and cpath-specific so their name should signify the fact they are part of the cpath module: assert_cpath_layer_ok -> cpath_assert_layer_ok assert_cpath_ok -> cpath_assert_ok onion_append_hop -> cpath_append_hop circuit_init_cpath_crypto -> cpath_init_circuit_crypto circuit_free_cpath_node -> cpath_free onion_append_to_cpath -> cpath_extend_linked_list --- src/core/mainloop/connection.c | 2 +- src/core/or/circuitbuild.c | 8 ++++---- src/core/or/circuitlist.c | 10 +++++----- src/core/or/crypt_path.c | 16 ++++++++-------- src/core/or/crypt_path.h | 16 ++++++---------- src/feature/hs/hs_circuit.c | 6 +++--- src/feature/rend/rendservice.c | 4 ++-- src/test/test_circuitpadding.c | 6 +++--- src/test/test_circuitstats.c | 16 ++++++++-------- src/test/test_relaycrypt.c | 2 +- 10 files changed, 41 insertions(+), 45 deletions(-) (limited to 'src/feature/rend') diff --git a/src/core/mainloop/connection.c b/src/core/mainloop/connection.c index f6adfa765a..de49a1b7ef 100644 --- a/src/core/mainloop/connection.c +++ b/src/core/mainloop/connection.c @@ -5331,7 +5331,7 @@ assert_connection_ok(connection_t *conn, time_t now) tor_assert(entry_conn->socks_request->has_finished); if (!conn->marked_for_close) { tor_assert(ENTRY_TO_EDGE_CONN(entry_conn)->cpath_layer); - assert_cpath_layer_ok(ENTRY_TO_EDGE_CONN(entry_conn)->cpath_layer); + cpath_assert_layer_ok(ENTRY_TO_EDGE_CONN(entry_conn)->cpath_layer); } } } diff --git a/src/core/or/circuitbuild.c b/src/core/or/circuitbuild.c index 1ceb77c4ad..b445b94637 100644 --- a/src/core/or/circuitbuild.c +++ b/src/core/or/circuitbuild.c @@ -1409,7 +1409,7 @@ circuit_finish_handshake(origin_circuit_t *circ, onion_handshake_state_release(&hop->handshake_state); - if (circuit_init_cpath_crypto(hop, keys, sizeof(keys), 0, 0)<0) { + if (cpath_init_circuit_crypto(hop, keys, sizeof(keys), 0, 0)<0) { return -END_CIRC_REASON_TORPROTOCOL; } @@ -1461,7 +1461,7 @@ circuit_truncated(origin_circuit_t *circ, int reason) } layer->next = victim->next; - circuit_free_cpath_node(victim); + cpath_free(victim); } log_info(LD_CIRC, "finished"); @@ -2280,7 +2280,7 @@ circuit_append_new_exit(origin_circuit_t *circ, extend_info_t *exit_ei) state->chosen_exit = extend_info_dup(exit_ei); ++circ->build_state->desired_path_len; - onion_append_hop(&circ->cpath, exit_ei); + cpath_append_hop(&circ->cpath, exit_ei); return 0; } @@ -2713,7 +2713,7 @@ onion_extend_cpath(origin_circuit_t *circ) extend_info_describe(info), cur_len+1, build_state_get_exit_nickname(state)); - onion_append_hop(&circ->cpath, info); + cpath_append_hop(&circ->cpath, info); extend_info_free(info); return 0; } diff --git a/src/core/or/circuitlist.c b/src/core/or/circuitlist.c index 83c651ff17..cd2259c98d 100644 --- a/src/core/or/circuitlist.c +++ b/src/core/or/circuitlist.c @@ -1148,7 +1148,7 @@ circuit_free_(circuit_t *circ) if (ocirc->build_state) { extend_info_free(ocirc->build_state->chosen_exit); - circuit_free_cpath_node(ocirc->build_state->pending_final_cpath); + cpath_free(ocirc->build_state->pending_final_cpath); cpath_ref_decref(ocirc->build_state->service_pending_final_cpath_ref); } tor_free(ocirc->build_state); @@ -1272,10 +1272,10 @@ circuit_clear_cpath(origin_circuit_t *circ) while (cpath->next && cpath->next != head) { victim = cpath; cpath = victim->next; - circuit_free_cpath_node(victim); + cpath_free(victim); } - circuit_free_cpath_node(cpath); + cpath_free(cpath); circ->cpath = NULL; } @@ -1338,7 +1338,7 @@ cpath_ref_decref(crypt_path_reference_t *cpath_ref) { if (cpath_ref != NULL) { if (--(cpath_ref->refcount) == 0) { - circuit_free_cpath_node(cpath_ref->cpath); + cpath_free(cpath_ref->cpath); tor_free(cpath_ref); } } @@ -2830,7 +2830,7 @@ assert_circuit_ok,(const circuit_t *c)) !smartlist_contains(circuits_pending_chans, c)); } if (origin_circ && origin_circ->cpath) { - assert_cpath_ok(origin_circ->cpath); + cpath_assert_ok(origin_circ->cpath); } if (c->purpose == CIRCUIT_PURPOSE_REND_ESTABLISHED) { tor_assert(or_circ); diff --git a/src/core/or/crypt_path.c b/src/core/or/crypt_path.c index ea07ec495f..13063e5da8 100644 --- a/src/core/or/crypt_path.c +++ b/src/core/or/crypt_path.c @@ -41,7 +41,7 @@ crypt_path_new(void) * This function is used to extend cpath by another hop. */ void -onion_append_to_cpath(crypt_path_t **head_ptr, crypt_path_t *new_hop) +cpath_extend_linked_list(crypt_path_t **head_ptr, crypt_path_t *new_hop) { if (*head_ptr) { new_hop->next = (*head_ptr); @@ -58,12 +58,12 @@ onion_append_to_cpath(crypt_path_t **head_ptr, crypt_path_t *new_hop) * corresponding router choice, and append it to the * end of the cpath head_ptr. */ int -onion_append_hop(crypt_path_t **head_ptr, extend_info_t *choice) +cpath_append_hop(crypt_path_t **head_ptr, extend_info_t *choice) { crypt_path_t *hop = crypt_path_new(); /* link hop into the cpath, at the end. */ - onion_append_to_cpath(head_ptr, hop); + cpath_extend_linked_list(head_ptr, hop); hop->state = CPATH_STATE_CLOSED; @@ -79,12 +79,12 @@ onion_append_hop(crypt_path_t **head_ptr, extend_info_t *choice) * correct. Trigger an assert if anything is invalid. */ void -assert_cpath_ok(const crypt_path_t *cp) +cpath_assert_ok(const crypt_path_t *cp) { const crypt_path_t *start = cp; do { - assert_cpath_layer_ok(cp); + cpath_assert_layer_ok(cp); /* layers must be in sequence of: "open* awaiting? closed*" */ if (cp != start) { if (cp->state == CPATH_STATE_AWAITING_KEYS) { @@ -102,7 +102,7 @@ assert_cpath_ok(const crypt_path_t *cp) * correct. Trigger an assert if anything is invalid. */ void -assert_cpath_layer_ok(const crypt_path_t *cp) +cpath_assert_layer_ok(const crypt_path_t *cp) { // tor_assert(cp->addr); /* these are zero for rendezvous extra-hops */ // tor_assert(cp->port); @@ -147,7 +147,7 @@ assert_cpath_layer_ok(const crypt_path_t *cp) * Return 0 if init was successful, else -1 if it failed. */ int -circuit_init_cpath_crypto(crypt_path_t *cpath, +cpath_init_circuit_crypto(crypt_path_t *cpath, const char *key_data, size_t key_data_len, int reverse, int is_hs_v3) { @@ -160,7 +160,7 @@ circuit_init_cpath_crypto(crypt_path_t *cpath, /** Deallocate space associated with the cpath node victim. */ void -circuit_free_cpath_node(crypt_path_t *victim) +cpath_free(crypt_path_t *victim) { if (!victim || BUG(!victim->private)) return; diff --git a/src/core/or/crypt_path.h b/src/core/or/crypt_path.h index 874ff2b2ad..4a0117360e 100644 --- a/src/core/or/crypt_path.h +++ b/src/core/or/crypt_path.h @@ -8,24 +8,20 @@ crypt_path_t *crypt_path_new(void); -/* rename */ -void assert_cpath_layer_ok(const crypt_path_t *cp); +void cpath_assert_layer_ok(const crypt_path_t *cp); -/* rename */ -void assert_cpath_ok(const crypt_path_t *cp); +void cpath_assert_ok(const crypt_path_t *cp); -/* rename */ -int onion_append_hop(crypt_path_t **head_ptr, extend_info_t *choice); +int cpath_append_hop(crypt_path_t **head_ptr, extend_info_t *choice); -int circuit_init_cpath_crypto(crypt_path_t *cpath, +int cpath_init_circuit_crypto(crypt_path_t *cpath, const char *key_data, size_t key_data_len, int reverse, int is_hs_v3); void -circuit_free_cpath_node(crypt_path_t *victim); +cpath_free(crypt_path_t *victim); -/* rename */ -void onion_append_to_cpath(crypt_path_t **head_ptr, crypt_path_t *new_hop); +void cpath_extend_linked_list(crypt_path_t **head_ptr, crypt_path_t *new_hop); void cpath_crypt_cell(const crypt_path_t *cpath, uint8_t *payload, bool is_decrypt); diff --git a/src/feature/hs/hs_circuit.c b/src/feature/hs/hs_circuit.c index 3356db9d90..7d17aff72f 100644 --- a/src/feature/hs/hs_circuit.c +++ b/src/feature/hs/hs_circuit.c @@ -89,7 +89,7 @@ create_rend_cpath(const uint8_t *ntor_key_seed, size_t seed_len, /* Setup the cpath */ cpath = crypt_path_new(); - if (circuit_init_cpath_crypto(cpath, (char*)keys, sizeof(keys), + if (cpath_init_circuit_crypto(cpath, (char*)keys, sizeof(keys), is_service_side, 1) < 0) { tor_free(cpath); goto err; @@ -126,7 +126,7 @@ create_rend_cpath_legacy(origin_circuit_t *circ, const uint8_t *rend_cell_body) goto err; } /* ... and set up cpath. */ - if (circuit_init_cpath_crypto(hop, + if (cpath_init_circuit_crypto(hop, keys+DIGEST_LEN, sizeof(keys)-DIGEST_LEN, 0, 0) < 0) goto err; @@ -177,7 +177,7 @@ finalize_rend_circuit(origin_circuit_t *circ, crypt_path_t *hop, circ->hs_circ_has_timed_out = 0; /* Append the hop to the cpath of this circuit */ - onion_append_to_cpath(&circ->cpath, hop); + cpath_extend_linked_list(&circ->cpath, hop); /* In legacy code, 'pending_final_cpath' points to the final hop we just * appended to the cpath. We set the original pointer to NULL so that we diff --git a/src/feature/rend/rendservice.c b/src/feature/rend/rendservice.c index 38da4cfe7a..0ecd0e6ff6 100644 --- a/src/feature/rend/rendservice.c +++ b/src/feature/rend/rendservice.c @@ -2163,7 +2163,7 @@ rend_service_receive_introduction(origin_circuit_t *circuit, cpath->rend_dh_handshake_state = dh; dh = NULL; - if (circuit_init_cpath_crypto(cpath, + if (cpath_init_circuit_crypto(cpath, keys+DIGEST_LEN, sizeof(keys)-DIGEST_LEN, 1, 0)<0) goto err; @@ -3547,7 +3547,7 @@ rend_service_rendezvous_has_opened(origin_circuit_t *circuit) hop->package_window = circuit_initial_package_window(); hop->deliver_window = CIRCWINDOW_START; - onion_append_to_cpath(&circuit->cpath, hop); + cpath_extend_linked_list(&circuit->cpath, hop); circuit->build_state->pending_final_cpath = NULL; /* prevent double-free */ /* Change the circuit purpose. */ diff --git a/src/test/test_circuitpadding.c b/src/test/test_circuitpadding.c index 6fa790c40d..e33e56af3f 100644 --- a/src/test/test_circuitpadding.c +++ b/src/test/test_circuitpadding.c @@ -145,7 +145,7 @@ new_fake_orcirc(channel_t *nchan, channel_t *pchan) circuit_set_n_circid_chan(circ, circ->n_circ_id, nchan); tmp_cpath = crypt_path_new(); - if (circuit_init_cpath_crypto(tmp_cpath, whatevs_key, + if (cpath_init_circuit_crypto(tmp_cpath, whatevs_key, sizeof(whatevs_key), 0, 0)<0) { log_warn(LD_BUG,"Circuit initialization failed"); return NULL; @@ -1621,7 +1621,7 @@ simulate_single_hop_extend(circuit_t *client, circuit_t *mid_relay, // Add a hop to cpath crypt_path_t *hop = crypt_path_new(); - onion_append_to_cpath(&TO_ORIGIN_CIRCUIT(client)->cpath, hop); + cpath_extend_linked_list(&TO_ORIGIN_CIRCUIT(client)->cpath, hop); hop->state = CPATH_STATE_OPEN; @@ -1634,7 +1634,7 @@ simulate_single_hop_extend(circuit_t *client, circuit_t *mid_relay, digest, NULL, NULL, NULL, &addr, padding); - circuit_init_cpath_crypto(hop, whatevs_key, sizeof(whatevs_key), 0, 0); + cpath_init_circuit_crypto(hop, whatevs_key, sizeof(whatevs_key), 0, 0); hop->package_window = circuit_initial_package_window(); hop->deliver_window = CIRCWINDOW_START; diff --git a/src/test/test_circuitstats.c b/src/test/test_circuitstats.c index 1cbcb14f2b..2a09622f09 100644 --- a/src/test/test_circuitstats.c +++ b/src/test/test_circuitstats.c @@ -28,7 +28,7 @@ origin_circuit_t *subtest_fourhop_circuit(struct timeval, int); origin_circuit_t *add_opened_threehop(void); origin_circuit_t *build_unopened_fourhop(struct timeval); -int onion_append_hop(crypt_path_t **head_ptr, extend_info_t *choice); +int cpath_append_hop(crypt_path_t **head_ptr, extend_info_t *choice); static int marked_for_close; /* Mock function because we are not trying to test the close circuit that does @@ -57,9 +57,9 @@ add_opened_threehop(void) or_circ->build_state = tor_malloc_zero(sizeof(cpath_build_state_t)); or_circ->build_state->desired_path_len = DEFAULT_ROUTE_LEN; - onion_append_hop(&or_circ->cpath, &fakehop); - onion_append_hop(&or_circ->cpath, &fakehop); - onion_append_hop(&or_circ->cpath, &fakehop); + cpath_append_hop(&or_circ->cpath, &fakehop); + cpath_append_hop(&or_circ->cpath, &fakehop); + cpath_append_hop(&or_circ->cpath, &fakehop); or_circ->has_opened = 1; TO_CIRCUIT(or_circ)->state = CIRCUIT_STATE_OPEN; @@ -82,10 +82,10 @@ build_unopened_fourhop(struct timeval circ_start_time) or_circ->build_state = tor_malloc_zero(sizeof(cpath_build_state_t)); or_circ->build_state->desired_path_len = 4; - onion_append_hop(&or_circ->cpath, fakehop); - onion_append_hop(&or_circ->cpath, fakehop); - onion_append_hop(&or_circ->cpath, fakehop); - onion_append_hop(&or_circ->cpath, fakehop); + cpath_append_hop(&or_circ->cpath, fakehop); + cpath_append_hop(&or_circ->cpath, fakehop); + cpath_append_hop(&or_circ->cpath, fakehop); + cpath_append_hop(&or_circ->cpath, fakehop); tor_free(fakehop); diff --git a/src/test/test_relaycrypt.c b/src/test/test_relaycrypt.c index a3a102e73b..1977958d1f 100644 --- a/src/test/test_relaycrypt.c +++ b/src/test/test_relaycrypt.c @@ -54,7 +54,7 @@ testing_circuitset_setup(const struct testcase_t *testcase) relay_crypto_init(&hop->private->crypto, KEY_MATERIAL[i], sizeof(KEY_MATERIAL[i]), 0, 0); hop->state = CPATH_STATE_OPEN; - onion_append_to_cpath(&cs->origin_circ->cpath, hop); + cpath_extend_linked_list(&cs->origin_circ->cpath, hop); tt_ptr_op(hop, OP_EQ, cs->origin_circ->cpath->prev); } -- cgit v1.2.3-54-g00ecf From 4060b7623d3845a4d4ecdbf8f9c219e0148e1380 Mon Sep 17 00:00:00 2001 From: George Kadianakis Date: Fri, 26 Apr 2019 14:26:22 +0300 Subject: Revert "Hiding crypt_path_t: Create a constructor for crypt_path_t." This reverts commit ab8b80944967ee5a6a0c45dbf61839cf257bfe44. --- src/core/or/crypt_path.c | 15 ++------------- src/core/or/crypt_path.h | 2 -- src/core/or/crypt_path_st.h | 5 +++-- src/feature/hs/hs_circuit.c | 3 ++- src/feature/rend/rendclient.c | 5 +++-- src/feature/rend/rendservice.c | 3 ++- src/test/test_circuitpadding.c | 13 ++++++------- src/test/test_hs_client.c | 6 ++++-- src/test/test_hs_service.c | 5 +++-- src/test/test_relaycell.c | 4 ++-- src/test/test_relaycrypt.c | 2 +- 11 files changed, 28 insertions(+), 35 deletions(-) (limited to 'src/feature/rend') diff --git a/src/core/or/crypt_path.c b/src/core/or/crypt_path.c index c7ff8690de..c44d65231d 100644 --- a/src/core/or/crypt_path.c +++ b/src/core/or/crypt_path.c @@ -37,17 +37,6 @@ #include "core/or/crypt_path_st.h" #include "core/or/cell_st.h" -/** Initialize and return a minimal crypt_path_t */ -crypt_path_t * -crypt_path_new(void) -{ - crypt_path_t *cpath = tor_malloc_zero(sizeof(crypt_path_t)); - cpath->magic = CRYPT_PATH_MAGIC; - cpath->private = tor_malloc_zero(sizeof(struct crypt_path_private_t)); - - return cpath; -} - /** Add new_hop to the end of the doubly-linked-list head_ptr. * This function is used to extend cpath by another hop. */ @@ -71,11 +60,12 @@ cpath_extend_linked_list(crypt_path_t **head_ptr, crypt_path_t *new_hop) int cpath_append_hop(crypt_path_t **head_ptr, extend_info_t *choice) { - crypt_path_t *hop = crypt_path_new(); + crypt_path_t *hop = tor_malloc_zero(sizeof(crypt_path_t)); /* link hop into the cpath, at the end. */ cpath_extend_linked_list(head_ptr, hop); + hop->magic = CRYPT_PATH_MAGIC; hop->state = CPATH_STATE_CLOSED; hop->extend_info = extend_info_dup(choice); @@ -180,7 +170,6 @@ cpath_free(crypt_path_t *victim) onion_handshake_state_release(&victim->handshake_state); crypto_dh_free(victim->rend_dh_handshake_state); extend_info_free(victim->extend_info); - tor_free(victim->private); memwipe(victim, 0xBB, sizeof(crypt_path_t)); /* poison memory */ tor_free(victim); diff --git a/src/core/or/crypt_path.h b/src/core/or/crypt_path.h index ed59037760..19c8571d06 100644 --- a/src/core/or/crypt_path.h +++ b/src/core/or/crypt_path.h @@ -6,8 +6,6 @@ #ifndef CRYPT_PATH_H #define CRYPT_PATH_H -crypt_path_t *crypt_path_new(void); - void cpath_assert_layer_ok(const crypt_path_t *cp); void cpath_assert_ok(const crypt_path_t *cp); diff --git a/src/core/or/crypt_path_st.h b/src/core/or/crypt_path_st.h index 7da3c57f49..833cfefad1 100644 --- a/src/core/or/crypt_path_st.h +++ b/src/core/or/crypt_path_st.h @@ -8,6 +8,9 @@ #define CRYPT_PATH_ST_H #include "core/or/relay_crypto_st.h" +struct crypto_dh_t; + +#define CRYPT_PATH_MAGIC 0x70127012u struct fast_handshake_state_t; struct ntor_handshake_state_t; @@ -23,8 +26,6 @@ struct onion_handshake_state_t { #ifdef CRYPT_PATH_PRIVATE -#define CRYPT_PATH_MAGIC 0x70127012u - /* The private parts of crypt path that don't need to be exposed to all the * modules. */ struct crypt_path_private_t { diff --git a/src/feature/hs/hs_circuit.c b/src/feature/hs/hs_circuit.c index 7d17aff72f..a6e86c5ab3 100644 --- a/src/feature/hs/hs_circuit.c +++ b/src/feature/hs/hs_circuit.c @@ -87,7 +87,8 @@ create_rend_cpath(const uint8_t *ntor_key_seed, size_t seed_len, } /* Setup the cpath */ - cpath = crypt_path_new(); + cpath = tor_malloc_zero(sizeof(crypt_path_t)); + cpath->magic = CRYPT_PATH_MAGIC; if (cpath_init_circuit_crypto(cpath, (char*)keys, sizeof(keys), is_service_side, 1) < 0) { diff --git a/src/feature/rend/rendclient.c b/src/feature/rend/rendclient.c index c6e9dde878..f84d221b1a 100644 --- a/src/feature/rend/rendclient.c +++ b/src/feature/rend/rendclient.c @@ -16,7 +16,6 @@ #include "core/or/circuituse.h" #include "core/or/connection_edge.h" #include "core/or/relay.h" -#include "core/or/crypt_path.h" #include "feature/client/circpathbias.h" #include "feature/control/control_events.h" #include "feature/dirclient/dirclient.h" @@ -195,7 +194,9 @@ rend_client_send_introduction(origin_circuit_t *introcirc, /* Initialize the pending_final_cpath and start the DH handshake. */ cpath = rendcirc->build_state->pending_final_cpath; if (!cpath) { - cpath = rendcirc->build_state->pending_final_cpath = crypt_path_new(); + cpath = rendcirc->build_state->pending_final_cpath = + tor_malloc_zero(sizeof(crypt_path_t)); + cpath->magic = CRYPT_PATH_MAGIC; if (!(cpath->rend_dh_handshake_state = crypto_dh_new(DH_TYPE_REND))) { log_warn(LD_BUG, "Internal error: couldn't allocate DH."); status = -2; diff --git a/src/feature/rend/rendservice.c b/src/feature/rend/rendservice.c index 0ecd0e6ff6..98c7253bcc 100644 --- a/src/feature/rend/rendservice.c +++ b/src/feature/rend/rendservice.c @@ -2158,7 +2158,8 @@ rend_service_receive_introduction(origin_circuit_t *circuit, launched->build_state->service_pending_final_cpath_ref->refcount = 1; launched->build_state->service_pending_final_cpath_ref->cpath = cpath = - crypt_path_new(); + tor_malloc_zero(sizeof(crypt_path_t)); + cpath->magic = CRYPT_PATH_MAGIC; launched->build_state->expiry_time = now + MAX_REND_TIMEOUT; cpath->rend_dh_handshake_state = dh; diff --git a/src/test/test_circuitpadding.c b/src/test/test_circuitpadding.c index e33e56af3f..5550488d0f 100644 --- a/src/test/test_circuitpadding.c +++ b/src/test/test_circuitpadding.c @@ -115,7 +115,7 @@ new_fake_orcirc(channel_t *nchan, channel_t *pchan) { or_circuit_t *orcirc = NULL; circuit_t *circ = NULL; - crypt_path_t *tmp_cpath; + crypt_path_t tmp_cpath; char whatevs_key[CPATH_KEY_MATERIAL_LEN]; orcirc = tor_malloc_zero(sizeof(*orcirc)); @@ -144,15 +144,13 @@ new_fake_orcirc(channel_t *nchan, channel_t *pchan) circuit_set_p_circid_chan(orcirc, orcirc->p_circ_id, pchan); circuit_set_n_circid_chan(circ, circ->n_circ_id, nchan); - tmp_cpath = crypt_path_new(); - if (cpath_init_circuit_crypto(tmp_cpath, whatevs_key, + memset(&tmp_cpath, 0, sizeof(tmp_cpath)); + if (cpath_init_circuit_crypto(&tmp_cpath, whatevs_key, sizeof(whatevs_key), 0, 0)<0) { log_warn(LD_BUG,"Circuit initialization failed"); return NULL; } - orcirc->crypto = tmp_cpath->private->crypto; - tor_free(tmp_cpath->private); - tor_free(tmp_cpath); + orcirc->crypto = tmp_cpath.private->crypto; return orcirc; } @@ -1620,9 +1618,10 @@ simulate_single_hop_extend(circuit_t *client, circuit_t *mid_relay, circpad_cell_event_nonpadding_received((circuit_t*)client); // Add a hop to cpath - crypt_path_t *hop = crypt_path_new(); + crypt_path_t *hop = tor_malloc_zero(sizeof(crypt_path_t)); cpath_extend_linked_list(&TO_ORIGIN_CIRCUIT(client)->cpath, hop); + hop->magic = CRYPT_PATH_MAGIC; hop->state = CPATH_STATE_OPEN; // add an extend info to indicate if this node supports padding or not. diff --git a/src/test/test_hs_client.c b/src/test/test_hs_client.c index cd049b7c47..7f5f255076 100644 --- a/src/test/test_hs_client.c +++ b/src/test/test_hs_client.c @@ -39,13 +39,13 @@ #include "feature/hs/hs_cache.h" #include "core/or/circuitlist.h" #include "core/or/circuitbuild.h" -#include "core/or/crypt_path.h" #include "core/mainloop/connection.h" #include "core/or/connection_edge.h" #include "feature/nodelist/networkstatus.h" #include "core/or/cpath_build_state_st.h" #include "core/or/crypt_path_st.h" +#include "core/or/crypt_path.h" #include "feature/dircommon/dir_connection_st.h" #include "core/or/entry_connection_st.h" #include "core/or/extend_info_st.h" @@ -146,7 +146,9 @@ helper_get_circ_and_stream_for_test(origin_circuit_t **circ_out, if (is_legacy) { /* Legacy: Setup rend data and final cpath */ - or_circ->build_state->pending_final_cpath = crypt_path_new(); + or_circ->build_state->pending_final_cpath = + tor_malloc_zero(sizeof(crypt_path_t)); + or_circ->build_state->pending_final_cpath->magic = CRYPT_PATH_MAGIC; or_circ->build_state->pending_final_cpath->rend_dh_handshake_state = crypto_dh_new(DH_TYPE_REND); tt_assert( diff --git a/src/test/test_hs_service.c b/src/test/test_hs_service.c index 08dac04d21..8a22e4d590 100644 --- a/src/test/test_hs_service.c +++ b/src/test/test_hs_service.c @@ -38,7 +38,6 @@ #include "core/or/circuitbuild.h" #include "core/or/circuitlist.h" #include "core/or/circuituse.h" -#include "core/or/crypt_path.h" #include "core/or/connection_edge.h" #include "core/or/edge_connection_st.h" #include "core/or/relay.h" @@ -62,6 +61,7 @@ #include "core/or/cpath_build_state_st.h" #include "core/or/crypt_path_st.h" +#include "core/or/crypt_path.h" #include "feature/nodelist/networkstatus_st.h" #include "feature/nodelist/node_st.h" #include "core/or/origin_circuit_st.h" @@ -221,7 +221,8 @@ helper_create_origin_circuit(int purpose, int flags) circ = origin_circuit_init(purpose, flags); tor_assert(circ); - circ->cpath = crypt_path_new(); + circ->cpath = tor_malloc_zero(sizeof(crypt_path_t)); + circ->cpath->magic = CRYPT_PATH_MAGIC; circ->cpath->state = CPATH_STATE_OPEN; circ->cpath->package_window = circuit_initial_package_window(); circ->cpath->deliver_window = CIRCWINDOW_START; diff --git a/src/test/test_relaycell.c b/src/test/test_relaycell.c index b48c7ca8ac..0623583511 100644 --- a/src/test/test_relaycell.c +++ b/src/test/test_relaycell.c @@ -16,7 +16,6 @@ #include "lib/crypt_ops/crypto_rand.h" #include "core/or/circuitbuild.h" #include "core/or/circuitlist.h" -#include "core/or/crypt_path.h" #include "core/or/connection_edge.h" #include "core/or/relay.h" #include "test/test.h" @@ -91,7 +90,8 @@ helper_create_origin_circuit(int purpose, int flags) circ = origin_circuit_init(purpose, flags); tor_assert(circ); - circ->cpath = crypt_path_new(); + circ->cpath = tor_malloc_zero(sizeof(crypt_path_t)); + circ->cpath->magic = CRYPT_PATH_MAGIC; circ->cpath->state = CPATH_STATE_OPEN; circ->cpath->package_window = circuit_initial_package_window(); circ->cpath->deliver_window = CIRCWINDOW_START; diff --git a/src/test/test_relaycrypt.c b/src/test/test_relaycrypt.c index 1977958d1f..5dc6b47d74 100644 --- a/src/test/test_relaycrypt.c +++ b/src/test/test_relaycrypt.c @@ -50,7 +50,7 @@ testing_circuitset_setup(const struct testcase_t *testcase) cs->origin_circ = origin_circuit_new(); cs->origin_circ->base_.purpose = CIRCUIT_PURPOSE_C_GENERAL; for (i=0; i<3; ++i) { - crypt_path_t *hop = crypt_path_new(); + crypt_path_t *hop = tor_malloc_zero(sizeof(*hop)); relay_crypto_init(&hop->private->crypto, KEY_MATERIAL[i], sizeof(KEY_MATERIAL[i]), 0, 0); hop->state = CPATH_STATE_OPEN; -- cgit v1.2.3-54-g00ecf