Tor  0.4.7.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-2021, 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 }
Base circuit structure.
origin_circuit_t * TO_ORIGIN_CIRCUIT(circuit_t *x)
Definition: circuitlist.c:166
or_circuit_t * TO_OR_CIRCUIT(circuit_t *x)
Definition: circuitlist.c:154
Header file for circuitlist.c.
#define CIRCUIT_IS_ORIGIN(c)
Definition: circuitlist.h:147
void circuit_read_valid_data(origin_circuit_t *circ, uint16_t relay_body_len)
Definition: circuituse.c:3165
Header file for circuituse.c.
tor_cmdline_mode_t command
Definition: config.c:2440
Header file for config.c.
Circuit-build-stse structure.
Path structures for origin circuits.
int hs_client_receive_introduce_ack(origin_circuit_t *circ, const uint8_t *payload, size_t payload_len)
Definition: hs_client.c:2411
int hs_client_receive_rendezvous2(origin_circuit_t *circ, const uint8_t *payload, size_t payload_len)
Definition: hs_client.c:2438
int hs_client_receive_rendezvous_acked(origin_circuit_t *circ, const uint8_t *payload, size_t payload_len)
Definition: hs_client.c:2102
Header file containing client data for the HS subsystem.
Header file containing common data for the whole HS subsystem.
int hs_intro_received_introduce1(or_circuit_t *circ, const uint8_t *request, size_t request_len)
int hs_intro_received_establish_intro(or_circuit_t *circ, const uint8_t *request, size_t request_len)
Header file for hs_intropoint.c.
int hs_service_receive_introduce2(origin_circuit_t *circ, const uint8_t *payload, size_t payload_len)
Definition: hs_service.c:4066
int hs_service_receive_intro_established(origin_circuit_t *circ, const uint8_t *payload, size_t payload_len)
Definition: hs_service.c:4095
#define log_fn(severity, domain, args,...)
Definition: log.h:283
#define LD_APP
Definition: log.h:78
#define LD_PROTOCOL
Definition: log.h:72
Master header file for Tor-specific functionality.
Origin circuit structure.
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
Header file for rendcommon.c.
int rend_mid_establish_rendezvous(or_circuit_t *circ, const uint8_t *request, size_t request_len)
Definition: rendmid.c:29
int rend_mid_rendezvous(or_circuit_t *circ, const uint8_t *request, size_t request_len)
Definition: rendmid.c:102
Header file for rendmid.c.
struct crypt_path_t * prev
Definition: crypt_path_st.h:75
crypt_path_t * cpath
cpath_build_state_t * build_state
#define tor_assert(expr)
Definition: util_bug.h:102
#define tor_fragile_assert()
Definition: util_bug.h:270