1 /* Copyright (c) 2001 Matej Pfajfar.
2  * Copyright (c) 2001-2004, Roger Dingledine.
3  * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
4  * Copyright (c) 2007-2021, The Tor Project, Inc. */
5 /* See LICENSE for licensing information */
6 
7 /**
8  * @file ext_orport.h
9  * @brief Header for ext_orport.c
10  **/
11 
12 #ifndef EXT_ORPORT_H
13 #define EXT_ORPORT_H
14 
15 /** States of the Extended ORPort protocol. Be careful before changing
16  *  the numbers: they matter. */
17 #define EXT_OR_CONN_STATE_MIN_ 1
18 /** Extended ORPort authentication is waiting for the authentication
19  *  type selected by the client. */
20 #define EXT_OR_CONN_STATE_AUTH_WAIT_AUTH_TYPE 1
21 /** Extended ORPort authentication is waiting for the client nonce. */
22 #define EXT_OR_CONN_STATE_AUTH_WAIT_CLIENT_NONCE 2
23 /** Extended ORPort authentication is waiting for the client hash. */
24 #define EXT_OR_CONN_STATE_AUTH_WAIT_CLIENT_HASH 3
25 #define EXT_OR_CONN_STATE_AUTH_MAX 3
26 /** Authentication finished and the Extended ORPort is now accepting
27  *  traffic. */
28 #define EXT_OR_CONN_STATE_OPEN 4
29 /** Extended ORPort is flushing its last messages and preparing to
30  *  start accepting OR connections. */
31 #define EXT_OR_CONN_STATE_FLUSHING 5
32 #define EXT_OR_CONN_STATE_MAX_ 5
33 
34 #ifdef HAVE_MODULE_RELAY
35 
36 int connection_ext_or_start_auth(or_connection_t *or_conn);
37 
38 void connection_or_set_ext_or_identifier(or_connection_t *conn);
39 int connection_ext_or_finished_flushing(or_connection_t *conn);
40 int connection_ext_or_process_inbuf(or_connection_t *or_conn);
41 char *get_ext_or_auth_cookie_file_name(void);
42 
43 /* (No stub needed for these: they are only called within feature/relay.) */
44 int init_ext_or_cookie_authentication(int is_enabled);
45 void ext_orport_free_all(void);
46 
47 #else /* !defined(HAVE_MODULE_RELAY) */
48 
49 static inline int
connection_ext_or_start_auth(or_connection_t * conn)50 connection_ext_or_start_auth(or_connection_t *conn)
51 {
52   (void)conn;
53   tor_assert_nonfatal_unreached();
54   return -1;
55 }
56 static inline int
connection_ext_or_finished_flushing(or_connection_t * conn)57 connection_ext_or_finished_flushing(or_connection_t *conn)
58 {
59   (void)conn;
60   tor_assert_nonfatal_unreached();
61   return -1;
62 }
63 static inline int
connection_ext_or_process_inbuf(or_connection_t * conn)64 connection_ext_or_process_inbuf(or_connection_t *conn)
65 {
66   (void)conn;
67   tor_assert_nonfatal_unreached();
68   return -1;
69 }
70 #define connection_or_set_ext_or_identifier(conn) \
71   ((void)(conn))
72 
73 #define get_ext_or_auth_cookie_file_name() \
74   (NULL)
75 
76 #endif /* defined(HAVE_MODULE_RELAY) */
77 
78 #ifdef EXT_ORPORT_PRIVATE
79 STATIC int connection_write_ext_or_command(connection_t *conn,
80                                            uint16_t command,
81                                            const char *body,
82                                            size_t bodylen);
83 STATIC int handle_client_auth_nonce(const char *client_nonce,
84                          size_t client_nonce_len,
85                          char **client_hash_out,
86                          char **reply_out, size_t *reply_len_out);
87 
88 #ifdef TOR_UNIT_TESTS
89 extern uint8_t *ext_or_auth_cookie;
90 extern int ext_or_auth_cookie_is_set;
91 #endif
92 #endif /* defined(EXT_ORPORT_PRIVATE) */
93 
94 #endif /* !defined(EXT_ORPORT_H) */
95