Tor  0.4.6.0-alpha-dev
rendcommon.c
Go to the documentation of this file.
1 /* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
2  * Copyright (c) 2007-2020, The Tor Project, Inc. */
3 /* See LICENSE for licensing information */
4 
5 /**
6  * \file rendcommon.c
7  * \brief Rendezvous implementation: shared code between
8  * introducers, services, clients, and rendezvous points.
9  **/
10 
11 #define RENDCOMMON_PRIVATE
12 
13 #include "core/or/or.h"
14 
15 #include "app/config/config.h"
16 
17 #include "core/or/circuitlist.h"
18 #include "core/or/circuituse.h"
19 
20 #include "feature/hs/hs_client.h"
21 #include "feature/hs/hs_common.h"
24 #include "feature/rend/rendmid.h"
25 
26 #include "core/or/circuit_st.h"
28 #include "core/or/crypt_path_st.h"
30 
31 /** Called when we get a rendezvous-related relay cell on circuit
32  * <b>circ</b>. Dispatch on rendezvous relay command. */
33 void
35  int command, size_t length,
36  const uint8_t *payload)
37 {
38  or_circuit_t *or_circ = NULL;
39  origin_circuit_t *origin_circ = NULL;
40  int r = -2;
41  if (CIRCUIT_IS_ORIGIN(circ)) {
42  origin_circ = TO_ORIGIN_CIRCUIT(circ);
43  if (!layer_hint || layer_hint != origin_circ->cpath->prev) {
44  log_fn(LOG_PROTOCOL_WARN, LD_APP,
45  "Relay cell (rend purpose %d) from wrong hop on origin circ",
46  command);
47  origin_circ = NULL;
48  }
49  } else {
50  or_circ = TO_OR_CIRCUIT(circ);
51  }
52 
53  switch (command) {
54  case RELAY_COMMAND_ESTABLISH_INTRO:
55  if (or_circ)
56  r = hs_intro_received_establish_intro(or_circ, payload, length);
57  break;
58  case RELAY_COMMAND_ESTABLISH_RENDEZVOUS:
59  if (or_circ)
60  r = rend_mid_establish_rendezvous(or_circ, payload, length);
61  break;
62  case RELAY_COMMAND_INTRODUCE1:
63  if (or_circ)
64  r = hs_intro_received_introduce1(or_circ, payload, length);
65  break;
66  case RELAY_COMMAND_INTRODUCE2:
67  if (origin_circ)
68  r = hs_service_receive_introduce2(origin_circ, payload, length);
69  break;
70  case RELAY_COMMAND_INTRODUCE_ACK:
71  if (origin_circ)
72  r = hs_client_receive_introduce_ack(origin_circ, payload, length);
73  break;
74  case RELAY_COMMAND_RENDEZVOUS1:
75  if (or_circ)
76  r = rend_mid_rendezvous(or_circ, payload, length);
77  break;
78  case RELAY_COMMAND_RENDEZVOUS2:
79  if (origin_circ)
80  r = hs_client_receive_rendezvous2(origin_circ, payload, length);
81  break;
82  case RELAY_COMMAND_INTRO_ESTABLISHED:
83  if (origin_circ)
84  r = hs_service_receive_intro_established(origin_circ, payload, length);
85  break;
86  case RELAY_COMMAND_RENDEZVOUS_ESTABLISHED:
87  if (origin_circ)
88  r = hs_client_receive_rendezvous_acked(origin_circ, payload, length);
89  break;
90  default:
92  }
93 
94  if (r == 0 && origin_circ) {
95  /* This was a valid cell. Count it as delivered + overhead. */
96  circuit_read_valid_data(origin_circ, length);
97  }
98 
99  if (r == -2)
100  log_info(LD_PROTOCOL, "Dropping cell (type %d) for wrong circuit type.",
101  command);
102 }
103 
104 /* Make sure that tor only builds one-hop circuits when they would not
105  * compromise user anonymity.
106  *
107  * One-hop circuits are permitted in Single Onion modes.
108  *
109  * Single Onion modes are also allowed to make multi-hop circuits.
110  * For example, single onion HSDir circuits are 3-hop to prevent denial of
111  * service.
112  */
113 void
114 assert_circ_anonymity_ok(const origin_circuit_t *circ,
115  const or_options_t *options)
116 {
117  tor_assert(options);
118  tor_assert(circ);
119  tor_assert(circ->build_state);
120 
121  if (circ->build_state->onehop_tunnel) {
122  tor_assert(hs_service_allow_non_anonymous_connection(options));
123  }
124 }
log_fn
#define log_fn(severity, domain, args,...)
Definition: log.h:283
hs_service_receive_introduce2
int hs_service_receive_introduce2(origin_circuit_t *circ, const uint8_t *payload, size_t payload_len)
Definition: hs_service.c:4060
hs_client_receive_introduce_ack
int hs_client_receive_introduce_ack(origin_circuit_t *circ, const uint8_t *payload, size_t payload_len)
Definition: hs_client.c:2411
tor_assert
#define tor_assert(expr)
Definition: util_bug.h:102
cpath_build_state_st.h
Circuit-build-stse structure.
rend_process_relay_cell
void rend_process_relay_cell(circuit_t *circ, const crypt_path_t *layer_hint, int command, size_t length, const uint8_t *payload)
Definition: rendcommon.c:34
circuituse.h
Header file for circuituse.c.
tor_fragile_assert
#define tor_fragile_assert()
Definition: util_bug.h:270
hs_service_receive_intro_established
int hs_service_receive_intro_established(origin_circuit_t *circ, const uint8_t *payload, size_t payload_len)
Definition: hs_service.c:4089
rend_mid_establish_rendezvous
int rend_mid_establish_rendezvous(or_circuit_t *circ, const uint8_t *request, size_t request_len)
Definition: rendmid.c:29
CIRCUIT_IS_ORIGIN
#define CIRCUIT_IS_ORIGIN(c)
Definition: circuitlist.h:146
crypt_path_t
Definition: crypt_path_st.h:47
hs_client_receive_rendezvous2
int hs_client_receive_rendezvous2(origin_circuit_t *circ, const uint8_t *payload, size_t payload_len)
Definition: hs_client.c:2438
hs_client.h
Header file containing client data for the HS subsystem.
hs_client_receive_rendezvous_acked
int hs_client_receive_rendezvous_acked(origin_circuit_t *circ, const uint8_t *payload, size_t payload_len)
Definition: hs_client.c:2102
circuitlist.h
Header file for circuitlist.c.
crypt_path_st.h
Path structures for origin circuits.
origin_circuit_t
Definition: origin_circuit_st.h:79
cpath_build_state_t::onehop_tunnel
unsigned int onehop_tunnel
Definition: cpath_build_state_st.h:32
rendmid.h
Header file for rendmid.c.
circuit_t
Definition: circuit_st.h:61
hs_intro_received_introduce1
int hs_intro_received_introduce1(or_circuit_t *circ, const uint8_t *request, size_t request_len)
Definition: hs_intropoint.c:757
command
tor_cmdline_mode_t command
Definition: config.c:2436
origin_circuit_t::build_state
cpath_build_state_t * build_state
Definition: origin_circuit_st.h:123
hs_common.h
Header file containing common data for the whole HS subsystem.
origin_circuit_t::cpath
crypt_path_t * cpath
Definition: origin_circuit_st.h:129
hs_intro_received_establish_intro
int hs_intro_received_establish_intro(or_circuit_t *circ, const uint8_t *request, size_t request_len)
Definition: hs_intropoint.c:500
TO_ORIGIN_CIRCUIT
origin_circuit_t * TO_ORIGIN_CIRCUIT(circuit_t *x)
Definition: circuitlist.c:166
crypt_path_t::prev
struct crypt_path_t * prev
Definition: crypt_path_st.h:75
circuit_read_valid_data
void circuit_read_valid_data(origin_circuit_t *circ, uint16_t relay_body_len)
Definition: circuituse.c:3165
hs_intropoint.h
Header file for hs_intropoint.c.
circuit_st.h
Base circuit structure.
or_circuit_t
Definition: or_circuit_st.h:21
LD_APP
#define LD_APP
Definition: log.h:78
config.h
Header file for config.c.
rend_mid_rendezvous
int rend_mid_rendezvous(or_circuit_t *circ, const uint8_t *request, size_t request_len)
Definition: rendmid.c:102
or_options_t
Definition: or_options_st.h:64
TO_OR_CIRCUIT
or_circuit_t * TO_OR_CIRCUIT(circuit_t *x)
Definition: circuitlist.c:154
origin_circuit_st.h
Origin circuit structure.
rendcommon.h
Header file for rendcommon.c.
or.h
Master header file for Tor-specific functionality.
LD_PROTOCOL
#define LD_PROTOCOL
Definition: log.h:72