LCOV - code coverage report
Current view: top level - feature/rend - rendcommon.c (source / functions) Hit Total Coverage
Test: lcov.info Lines: 18 52 34.6 %
Date: 2021-11-24 03:28:48 Functions: 1 2 50.0 %

          Line data    Source code
       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"
      22             : #include "feature/hs/hs_intropoint.h"
      23             : #include "feature/rend/rendcommon.h"
      24             : #include "feature/rend/rendmid.h"
      25             : 
      26             : #include "core/or/circuit_st.h"
      27             : #include "core/or/cpath_build_state_st.h"
      28             : #include "core/or/crypt_path_st.h"
      29             : #include "core/or/origin_circuit_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
      34           2 : rend_process_relay_cell(circuit_t *circ, const crypt_path_t *layer_hint,
      35             :                         int command, size_t length,
      36             :                         const uint8_t *payload)
      37             : {
      38           2 :   or_circuit_t *or_circ = NULL;
      39           2 :   origin_circuit_t *origin_circ = NULL;
      40           2 :   int r = -2;
      41           2 :   if (CIRCUIT_IS_ORIGIN(circ)) {
      42           2 :     origin_circ = TO_ORIGIN_CIRCUIT(circ);
      43           2 :     if (!layer_hint || layer_hint != origin_circ->cpath->prev) {
      44           0 :       log_fn(LOG_PROTOCOL_WARN, LD_APP,
      45             :              "Relay cell (rend purpose %d) from wrong hop on origin circ",
      46             :              command);
      47           0 :       origin_circ = NULL;
      48             :     }
      49             :   } else {
      50           0 :     or_circ = TO_OR_CIRCUIT(circ);
      51             :   }
      52             : 
      53           2 :   switch (command) {
      54           1 :     case RELAY_COMMAND_ESTABLISH_INTRO:
      55           1 :       if (or_circ)
      56           0 :         r = hs_intro_received_establish_intro(or_circ, payload, length);
      57             :       break;
      58           0 :     case RELAY_COMMAND_ESTABLISH_RENDEZVOUS:
      59           0 :       if (or_circ)
      60           0 :         r = rend_mid_establish_rendezvous(or_circ, payload, length);
      61             :       break;
      62           0 :     case RELAY_COMMAND_INTRODUCE1:
      63           0 :       if (or_circ)
      64           0 :         r = hs_intro_received_introduce1(or_circ, payload, length);
      65             :       break;
      66           0 :     case RELAY_COMMAND_INTRODUCE2:
      67           0 :       if (origin_circ)
      68           0 :         r = hs_service_receive_introduce2(origin_circ, payload, length);
      69             :       break;
      70           0 :     case RELAY_COMMAND_INTRODUCE_ACK:
      71           0 :       if (origin_circ)
      72           0 :         r = hs_client_receive_introduce_ack(origin_circ, payload, length);
      73             :       break;
      74           0 :     case RELAY_COMMAND_RENDEZVOUS1:
      75           0 :       if (or_circ)
      76           0 :         r = rend_mid_rendezvous(or_circ, payload, length);
      77             :       break;
      78           0 :     case RELAY_COMMAND_RENDEZVOUS2:
      79           0 :       if (origin_circ)
      80           0 :         r = hs_client_receive_rendezvous2(origin_circ, payload, length);
      81             :       break;
      82           0 :     case RELAY_COMMAND_INTRO_ESTABLISHED:
      83           0 :       if (origin_circ)
      84           0 :         r = hs_service_receive_intro_established(origin_circ, payload, length);
      85             :       break;
      86           1 :     case RELAY_COMMAND_RENDEZVOUS_ESTABLISHED:
      87           1 :       if (origin_circ)
      88           1 :         r = hs_client_receive_rendezvous_acked(origin_circ, payload, length);
      89             :       break;
      90           0 :     default:
      91           0 :       tor_fragile_assert();
      92             :   }
      93             : 
      94           2 :   if (r == 0 && origin_circ) {
      95             :     /* This was a valid cell. Count it as delivered + overhead. */
      96           1 :     circuit_read_valid_data(origin_circ, length);
      97             :   }
      98             : 
      99           2 :   if (r == -2)
     100           1 :     log_info(LD_PROTOCOL, "Dropping cell (type %d) for wrong circuit type.",
     101             :              command);
     102           2 : }
     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           0 : assert_circ_anonymity_ok(const origin_circuit_t *circ,
     115             :                          const or_options_t *options)
     116             : {
     117           0 :   tor_assert(options);
     118           0 :   tor_assert(circ);
     119           0 :   tor_assert(circ->build_state);
     120             : 
     121           0 :   if (circ->build_state->onehop_tunnel) {
     122           0 :     tor_assert(hs_service_allow_non_anonymous_connection(options));
     123             :   }
     124           0 : }

Generated by: LCOV version 1.14