aboutsummaryrefslogtreecommitdiff
path: root/src/feature/relay/ext_orport.h
blob: 416c358397128c1e0ecb2791323e766a43f6d47c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/* Copyright (c) 2001 Matej Pfajfar.
 * Copyright (c) 2001-2004, Roger Dingledine.
 * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
 * Copyright (c) 2007-2020, The Tor Project, Inc. */
/* See LICENSE for licensing information */

/**
 * @file ext_orport.h
 * @brief Header for ext_orport.c
 **/

#ifndef EXT_ORPORT_H
#define EXT_ORPORT_H

/** States of the Extended ORPort protocol. Be careful before changing
 *  the numbers: they matter. */
#define EXT_OR_CONN_STATE_MIN_ 1
/** Extended ORPort authentication is waiting for the authentication
 *  type selected by the client. */
#define EXT_OR_CONN_STATE_AUTH_WAIT_AUTH_TYPE 1
/** Extended ORPort authentication is waiting for the client nonce. */
#define EXT_OR_CONN_STATE_AUTH_WAIT_CLIENT_NONCE 2
/** Extended ORPort authentication is waiting for the client hash. */
#define EXT_OR_CONN_STATE_AUTH_WAIT_CLIENT_HASH 3
#define EXT_OR_CONN_STATE_AUTH_MAX 3
/** Authentication finished and the Extended ORPort is now accepting
 *  traffic. */
#define EXT_OR_CONN_STATE_OPEN 4
/** Extended ORPort is flushing its last messages and preparing to
 *  start accepting OR connections. */
#define EXT_OR_CONN_STATE_FLUSHING 5
#define EXT_OR_CONN_STATE_MAX_ 5

#ifdef HAVE_MODULE_RELAY

int connection_ext_or_start_auth(or_connection_t *or_conn);

void connection_or_set_ext_or_identifier(or_connection_t *conn);
void connection_or_remove_from_ext_or_id_map(or_connection_t *conn);
void connection_or_clear_ext_or_id_map(void);
int connection_ext_or_finished_flushing(or_connection_t *conn);
int connection_ext_or_process_inbuf(or_connection_t *or_conn);
char *get_ext_or_auth_cookie_file_name(void);

/* (No stub needed for these: they are only called within feature/relay.) */
int init_ext_or_cookie_authentication(int is_enabled);
void ext_orport_free_all(void);

#else /* !defined(HAVE_MODULE_RELAY) */

static inline int
connection_ext_or_start_auth(or_connection_t *conn)
{
  (void)conn;
  tor_assert_nonfatal_unreached();
  return -1;
}
static inline int
connection_ext_or_finished_flushing(or_connection_t *conn)
{
  (void)conn;
  tor_assert_nonfatal_unreached();
  return -1;
}
static inline int
connection_ext_or_process_inbuf(or_connection_t *conn)
{
  (void)conn;
  tor_assert_nonfatal_unreached();
  return -1;
}
#define connection_or_set_ext_or_identifier(conn) \
  ((void)(conn))
#define connection_or_remove_from_ext_or_id_map(conn) \
  ((void)(conn))
#define connection_or_clear_ext_or_id_map() \
  STMT_NIL

#define get_ext_or_auth_cookie_file_name() \
  (NULL)

#endif /* defined(HAVE_MODULE_RELAY) */

#ifdef EXT_ORPORT_PRIVATE
STATIC int connection_write_ext_or_command(connection_t *conn,
                                           uint16_t command,
                                           const char *body,
                                           size_t bodylen);
STATIC int handle_client_auth_nonce(const char *client_nonce,
                         size_t client_nonce_len,
                         char **client_hash_out,
                         char **reply_out, size_t *reply_len_out);

#ifdef TOR_UNIT_TESTS
extern uint8_t *ext_or_auth_cookie;
extern int ext_or_auth_cookie_is_set;
or_connection_t *connection_or_get_by_ext_or_id(const char *id);
#endif
#endif /* defined(EXT_ORPORT_PRIVATE) */

#endif /* !defined(EXT_ORPORT_H) */