or.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. /* Copyright 2001,2002 Roger Dingledine, Matej Pfajfar. */
  2. /* See LICENSE for licensing information */
  3. /* $Id$ */
  4. #ifndef __OR_H
  5. #define __OR_H
  6. #include "orconfig.h"
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <limits.h>
  10. #include <unistd.h>
  11. #include <string.h>
  12. #include <signal.h>
  13. #include <netdb.h>
  14. #include <ctype.h>
  15. #ifdef HAVE_STDINT_H
  16. #include <stdint.h>
  17. #endif
  18. #ifdef HAVE_SYS_POLL_H
  19. #include <sys/poll.h>
  20. #elif HAVE_POLL_H
  21. #include <poll.h>
  22. #else
  23. #include "../common/fakepoll.h"
  24. #endif
  25. #include <sys/types.h>
  26. #include <sys/fcntl.h>
  27. #include <sys/ioctl.h>
  28. #include <sys/socket.h>
  29. #include <sys/time.h>
  30. #include <netinet/in.h>
  31. #include <arpa/inet.h>
  32. #include <errno.h>
  33. #include <assert.h>
  34. #include <time.h>
  35. #include "../common/config.h"
  36. #include "../common/crypto.h"
  37. #include "../common/log.h"
  38. #include "../common/ss.h"
  39. #include "../common/version.h"
  40. #define MAXCONNECTIONS 200 /* upper bound on max connections.
  41. can be overridden by config file */
  42. #define MAX_BUF_SIZE (640*1024)
  43. #define DEFAULT_BANDWIDTH_OP 102400
  44. #define ACI_TYPE_LOWER 0
  45. #define ACI_TYPE_HIGHER 1
  46. #define ACI_TYPE_BOTH 2
  47. /* bitvector of the roles that we might want to play. You can or (|) them together */
  48. #define ROLE_OR_LISTEN 1
  49. #define ROLE_OR_CONNECT_ALL 2
  50. #define ROLE_OP_LISTEN 4
  51. #define ROLE_AP_LISTEN 8
  52. #define ROLE_IS_OR(role) ((role & ROLE_OR_LISTEN) || (role & ROLE_OR_CONNECT_ALL) || (role & ROLE_OP_LISTEN))
  53. #define CONN_TYPE_OP_LISTENER 1
  54. #define CONN_TYPE_OP 2
  55. #define CONN_TYPE_OR_LISTENER 3
  56. #define CONN_TYPE_OR 4
  57. #define CONN_TYPE_EXIT 5
  58. #define CONN_TYPE_AP_LISTENER 6
  59. #define CONN_TYPE_AP 7
  60. #define LISTENER_STATE_READY 0
  61. #define OP_CONN_STATE_AWAITING_KEYS 0
  62. #define OP_CONN_STATE_OPEN 1
  63. #if 0
  64. #define OP_CONN_STATE_CLOSE 2 /* flushing the buffer, then will close */
  65. #define OP_CONN_STATE_CLOSE_WAIT 3 /* have sent a destroy, awaiting a confirmation */
  66. #endif
  67. /* how to read these states:
  68. * foo_CONN_STATE_bar_baz:
  69. * "I am acting as a bar, currently in stage baz of talking with a foo."
  70. */
  71. #define OR_CONN_STATE_OP_CONNECTING 0 /* an application proxy wants me to connect to this OR */
  72. #define OR_CONN_STATE_OP_SENDING_KEYS 1
  73. #define OR_CONN_STATE_CLIENT_CONNECTING 2 /* I'm connecting to this OR as an OR */
  74. #define OR_CONN_STATE_CLIENT_SENDING_AUTH 3 /* sending address and info */
  75. #define OR_CONN_STATE_CLIENT_AUTH_WAIT 4 /* have sent address and info, waiting */
  76. #define OR_CONN_STATE_CLIENT_SENDING_NONCE 5 /* sending nonce, last piece of handshake */
  77. #define OR_CONN_STATE_SERVER_AUTH_WAIT 6 /* waiting for address and info */
  78. #define OR_CONN_STATE_SERVER_SENDING_AUTH 7 /* writing auth and nonce */
  79. #define OR_CONN_STATE_SERVER_NONCE_WAIT 8 /* waiting for confirmation of nonce */
  80. #define OR_CONN_STATE_OPEN 9 /* ready to send/receive cells. */
  81. #define EXIT_CONN_STATE_CONNECTING_WAIT 0 /* waiting for standard structure or dest info */
  82. #define EXIT_CONN_STATE_CONNECTING 1
  83. #define EXIT_CONN_STATE_OPEN 2
  84. #if 0
  85. #define EXIT_CONN_STATE_CLOSE 3 /* flushing the buffer, then will close */
  86. #define EXIT_CONN_STATE_CLOSE_WAIT 4 /* have sent a destroy, awaiting a confirmation */
  87. #endif
  88. #define AP_CONN_STATE_SOCKS_WAIT 0
  89. #define AP_CONN_STATE_OR_WAIT 1
  90. #define AP_CONN_STATE_OPEN 2
  91. #define CIRCUIT_STATE_OPEN_WAIT 0 /* receiving/processing the onion */
  92. #define CIRCUIT_STATE_OR_WAIT 1 /* I'm at the beginning of the path, my firsthop is still connecting */
  93. #define CIRCUIT_STATE_OPEN 2 /* onion processed, ready to send data along the connection */
  94. #define CIRCUIT_STATE_CLOSE_WAIT1 3 /* sent two "destroy" signals, waiting for acks */
  95. #define CIRCUIT_STATE_CLOSE_WAIT2 4 /* received one ack, waiting for one more
  96. (or if just one was sent, waiting for that one */
  97. //#define CIRCUIT_STATE_CLOSE 4 /* both acks received, connection is dead */ /* NOT USED */
  98. /* available cipher functions */
  99. #define ONION_CIPHER_IDENTITY 0
  100. #define ONION_CIPHER_DES 1
  101. #define ONION_CIPHER_RC4 2
  102. /* default cipher function */
  103. #define ONION_DEFAULT_CIPHER ONION_CIPHER_DES
  104. #define RECEIVE_WINDOW_START 100
  105. #define RECEIVE_WINDOW_INCREMENT 10
  106. /* cell commands */
  107. #define CELL_PADDING 0
  108. #define CELL_CREATE 1
  109. #define CELL_DATA 2
  110. #define CELL_DESTROY 3
  111. #define CELL_ACK 4
  112. #define CELL_NACK 5
  113. #define CELL_SENDME 6
  114. #define CELL_CONNECTED 7
  115. #define CELL_PAYLOAD_SIZE 120
  116. typedef uint16_t aci_t;
  117. /* cell definition */
  118. typedef struct
  119. {
  120. aci_t aci; /* Anonymous Connection Identifier */
  121. unsigned char command;
  122. unsigned char length; /* of payload if data cell, else value of sendme */
  123. uint32_t seq; /* sequence number */
  124. unsigned char payload[120];
  125. } cell_t;
  126. #define SOCKS4_REQUEST_GRANTED 90
  127. #define SOCKS4_REQUEST_REJECT 91
  128. #define SOCKS4_REQUEST_IDENT_FAILED 92
  129. #define SOCKS4_REQUEST_IDENT_CONFLICT 93
  130. /* structure of a socks client operation */
  131. typedef struct {
  132. unsigned char version; /* socks version number */
  133. unsigned char command; /* command code */
  134. unsigned char destport[2]; /* destination port, network order */
  135. unsigned char destip[4]; /* destination address */
  136. /* userid follows, terminated by a NULL */
  137. /* dest host follows, terminated by a NULL */
  138. } socks4_t;
  139. typedef struct
  140. {
  141. /* Used by all types: */
  142. unsigned char type;
  143. int state;
  144. int s; /* our socket */
  145. int poll_index;
  146. int marked_for_close;
  147. char *inbuf;
  148. int inbuflen;
  149. int inbuf_datalen;
  150. int inbuf_reached_eof;
  151. char *outbuf;
  152. int outbuflen; /* how many bytes are allocated for the outbuf? */
  153. int outbuf_flushlen; /* how much data should we try to flush from the outbuf? */
  154. int outbuf_datalen; /* how much data is there total on the outbuf? */
  155. // uint16_t aci; /* anonymous connection identifier */
  156. /* used by OR and OP: */
  157. uint32_t bandwidth; /* connection bandwidth */
  158. int receiver_bucket; /* when this hits 0, stop receiving. Every second we
  159. * add 'bandwidth' to this, capping it at 10*bandwidth.
  160. */
  161. struct timeval send_timeval; /* for determining when to send the next cell */
  162. /* link encryption */
  163. crypto_cipher_env_t *f_crypto;
  164. crypto_cipher_env_t *b_crypto;
  165. // struct timeval lastsend; /* time of last transmission to the client */
  166. // struct timeval interval; /* transmission interval */
  167. uint32_t addr; /* these two uniquely identify a router */
  168. uint16_t port;
  169. /* used by exit and ap: */
  170. // ss_t ss; /* standard structure */
  171. // int ss_received; /* size of ss, received so far */
  172. char socks_version;
  173. char read_username;
  174. char *dest_addr;
  175. uint16_t dest_port;
  176. /* used by OR, to keep state while connect()ing: Kludge. */
  177. crypto_pk_env_t *prkey;
  178. struct sockaddr_in local;
  179. #if 0 /* obsolete, we now use conn->bandwidth */
  180. /* link info */
  181. uint32_t min;
  182. uint32_t max;
  183. #endif
  184. char *address; /* strdup into this, because free_connection frees it */
  185. crypto_pk_env_t *pkey; /* public RSA key for the other side */
  186. char nonce[8];
  187. } connection_t;
  188. /* config stuff we know about the other ORs in the network */
  189. typedef struct
  190. {
  191. char *address;
  192. uint32_t addr;
  193. uint16_t or_port;
  194. uint16_t op_port;
  195. uint16_t ap_port;
  196. crypto_pk_env_t *pkey; /* public RSA key */
  197. /* link info */
  198. uint32_t min;
  199. uint32_t max;
  200. // struct timeval min_interval;
  201. /* time when last data was sent to that router */
  202. // struct timeval lastsend;
  203. /* socket */
  204. // int s;
  205. void *next;
  206. } routerinfo_t;
  207. typedef struct
  208. {
  209. unsigned int forwf;
  210. unsigned int backf;
  211. char digest2[20]; /* second SHA output for onion_layer_t.keyseed */
  212. char digest3[20]; /* third SHA output for onion_layer_t.keyseed */
  213. /* crypto environments */
  214. crypto_cipher_env_t *f_crypto;
  215. crypto_cipher_env_t *b_crypto;
  216. } crypt_path_t;
  217. /* per-anonymous-connection struct */
  218. typedef struct
  219. {
  220. #if 0
  221. uint32_t p_addr; /* all in network order */
  222. uint16_t p_port;
  223. #endif
  224. uint32_t n_addr;
  225. uint16_t n_port;
  226. connection_t *p_conn;
  227. connection_t *n_conn;
  228. int n_receive_window;
  229. int p_receive_window;
  230. aci_t p_aci; /* connection identifiers */
  231. aci_t n_aci;
  232. unsigned char p_f; /* crypto functions */
  233. unsigned char n_f;
  234. crypto_cipher_env_t *p_crypto; /* crypto environments */
  235. crypto_cipher_env_t *n_crypto;
  236. crypt_path_t **cpath;
  237. int cpathlen;
  238. uint32_t expire; /* expiration time for the corresponding onion */
  239. int state;
  240. unsigned char *onion; /* stores the onion when state is CONN_STATE_OPEN_WAIT */
  241. uint32_t onionlen; /* total onion length */
  242. uint32_t recvlen; /* length of the onion so far */
  243. void *next;
  244. } circuit_t;
  245. typedef struct
  246. {
  247. int zero:1;
  248. int version:7;
  249. int backf:4;
  250. int forwf:4;
  251. uint16_t port;
  252. uint32_t addr;
  253. time_t expire;
  254. unsigned char keyseed[16];
  255. } onion_layer_t;
  256. typedef struct
  257. {
  258. time_t expire;
  259. char digest[20]; /* SHA digest of the onion */
  260. void *prev;
  261. void *next;
  262. } tracked_onion_t;
  263. typedef struct
  264. {
  265. char *LogLevel;
  266. char *RouterFile;
  267. char *PrivateKeyFile;
  268. float CoinWeight;
  269. int ORPort;
  270. int OPPort;
  271. int APPort;
  272. int MaxConn;
  273. int TrafficShaping;
  274. int LinkPadding;
  275. int Role;
  276. int loglevel;
  277. } or_options_t;
  278. /* all the function prototypes go here */
  279. /********************************* buffers.c ***************************/
  280. int buf_new(char **buf, int *buflen, int *buf_datalen);
  281. void buf_free(char *buf);
  282. int read_to_buf(int s, int at_most, char **buf, int *buflen, int *buf_datalen, int *reached_eof);
  283. /* grab from s, put onto buf, return how many bytes read */
  284. int flush_buf(int s, char **buf, int *buflen, int *buf_flushlen, int *buf_datalen);
  285. /* push from buf onto s
  286. * then memmove to front of buf
  287. * return -1 or how many bytes remain on the buf */
  288. int write_to_buf(char *string, int string_len,
  289. char **buf, int *buflen, int *buf_datalen);
  290. /* append string to buf (growing as needed, return -1 if "too big")
  291. * return total number of bytes on the buf
  292. */
  293. int fetch_from_buf(char *string, int string_len,
  294. char **buf, int *buflen, int *buf_datalen);
  295. /* if there is string_len bytes in buf, write them onto string,
  296. * * then memmove buf back (that is, remove them from buf) */
  297. /********************************* cell.c ***************************/
  298. int pack_create(uint16_t aci, unsigned char *onion, uint32_t onionlen, unsigned char **cellbuf, unsigned int *cellbuflen);
  299. /********************************* circuit.c ***************************/
  300. void circuit_add(circuit_t *circ);
  301. void circuit_remove(circuit_t *circ);
  302. circuit_t *circuit_new(aci_t p_aci, connection_t *p_conn);
  303. /* internal */
  304. aci_t get_unique_aci_by_addr_port(uint32_t addr, uint16_t port, int aci_type);
  305. circuit_t *circuit_get_by_aci_conn(aci_t aci, connection_t *conn);
  306. circuit_t *circuit_get_by_conn(connection_t *conn);
  307. circuit_t *circuit_get_by_naddr_nport(uint32_t naddr, uint16_t nport);
  308. int circuit_deliver_data_cell(cell_t *cell, circuit_t *circ, connection_t *conn, int crypt_type);
  309. int circuit_crypt(circuit_t *circ, char *in, int inlen, char crypt_type);
  310. int circuit_init(circuit_t *circ, int aci_type);
  311. void circuit_free(circuit_t *circ);
  312. void circuit_free_cpath(crypt_path_t **cpath, int cpathlen);
  313. void circuit_close(circuit_t *circ);
  314. void circuit_about_to_close_connection(connection_t *conn);
  315. /* flush and send destroys for all circuits using conn */
  316. void circuit_dump_by_conn(connection_t *conn);
  317. /********************************* command.c ***************************/
  318. void command_process_cell(cell_t *cell, connection_t *conn);
  319. void command_process_create_cell(cell_t *cell, connection_t *conn);
  320. void command_process_sendme_cell(cell_t *cell, connection_t *conn);
  321. void command_process_data_cell(cell_t *cell, connection_t *conn);
  322. void command_process_destroy_cell(cell_t *cell, connection_t *conn);
  323. void command_process_connected_cell(cell_t *cell, connection_t *conn);
  324. /********************************* config.c ***************************/
  325. /* loads the configuration file */
  326. int getconfig(char *filename, config_opt_t *options);
  327. /* create or_options_t from command-line args and config files(s) */
  328. int getoptions(int argc, char **argv, or_options_t *options);
  329. /********************************* connection.c ***************************/
  330. int tv_cmp(struct timeval *a, struct timeval *b);
  331. connection_t *connection_new(int type);
  332. void connection_free(connection_t *conn);
  333. int connection_create_listener(crypto_pk_env_t *prkey, struct sockaddr_in *local, int type);
  334. int connection_handle_listener_read(connection_t *conn, int new_type, int new_state);
  335. /* start all connections that should be up but aren't */
  336. int retry_all_connections(int role, routerinfo_t **router_array, int rarray_len,
  337. crypto_pk_env_t *prkey, uint16_t or_port, uint16_t op_port, uint16_t ap_port);
  338. connection_t *connection_connect_to_router_as_op(routerinfo_t *router, uint16_t local_or_port);
  339. int connection_read_to_buf(connection_t *conn);
  340. int connection_fetch_from_buf(char *string, int len, connection_t *conn);
  341. int connection_outbuf_too_full(connection_t *conn);
  342. int connection_wants_to_flush(connection_t *conn);
  343. int connection_flush_buf(connection_t *conn);
  344. int connection_write_to_buf(char *string, int len, connection_t *conn);
  345. void connection_send_cell(connection_t *conn);
  346. int connection_receiver_bucket_should_increase(connection_t *conn);
  347. void connection_increment_receiver_bucket (connection_t *conn);
  348. void connection_increment_send_timeval(connection_t *conn);
  349. void connection_init_timeval(connection_t *conn);
  350. int connection_speaks_cells(connection_t *conn);
  351. int connection_is_listener(connection_t *conn);
  352. int connection_state_is_open(connection_t *conn);
  353. int connection_send_destroy(aci_t aci, connection_t *conn);
  354. int connection_send_connected(aci_t aci, connection_t *conn);
  355. int connection_encrypt_cell(cell_t *cellp, connection_t *conn);
  356. int connection_write_cell_to_buf(cell_t *cellp, connection_t *conn);
  357. int connection_process_inbuf(connection_t *conn);
  358. int connection_package_raw_inbuf(connection_t *conn);
  359. int connection_process_cell_from_inbuf(connection_t *conn);
  360. int connection_consider_sending_sendme(connection_t *conn);
  361. int connection_finished_flushing(connection_t *conn);
  362. /********************************* connection_ap.c ****************************/
  363. int connection_ap_process_inbuf(connection_t *conn);
  364. int ap_handshake_process_socks(connection_t *conn);
  365. int ap_handshake_create_onion(connection_t *conn);
  366. int ap_handshake_establish_circuit(connection_t *conn, unsigned int *route, int routelen, char *onion,
  367. int onionlen, crypt_path_t **cpath);
  368. /* find the circ that's waiting on me, if any, and get it to send its onion */
  369. int ap_handshake_n_conn_open(connection_t *or_conn);
  370. int ap_handshake_send_onion(connection_t *ap_conn, connection_t *or_conn, circuit_t *circ);
  371. int ap_handshake_socks_reply(connection_t *conn, char result);
  372. int connection_ap_send_connected(connection_t *conn);
  373. int connection_ap_process_data_cell(cell_t *cell, connection_t *conn);
  374. int connection_ap_finished_flushing(connection_t *conn);
  375. int connection_ap_create_listener(crypto_pk_env_t *prkey, struct sockaddr_in *local);
  376. int connection_ap_handle_listener_read(connection_t *conn);
  377. /********************************* connection_exit.c ***************************/
  378. int connection_exit_process_inbuf(connection_t *conn);
  379. int connection_exit_package_inbuf(connection_t *conn);
  380. int connection_exit_send_connected(connection_t *conn);
  381. int connection_exit_process_data_cell(cell_t *cell, connection_t *conn);
  382. int connection_exit_finished_flushing(connection_t *conn);
  383. /********************************* connection_op.c ***************************/
  384. int op_handshake_process_keys(connection_t *conn);
  385. int connection_op_process_inbuf(connection_t *conn);
  386. int connection_op_finished_flushing(connection_t *conn);
  387. int connection_op_create_listener(crypto_pk_env_t *prkey, struct sockaddr_in *local);
  388. int connection_op_handle_listener_read(connection_t *conn);
  389. /********************************* connection_or.c ***************************/
  390. int connection_or_process_inbuf(connection_t *conn);
  391. int connection_or_finished_flushing(connection_t *conn);
  392. void conn_or_init_crypto(connection_t *conn);
  393. int or_handshake_op_send_keys(connection_t *conn);
  394. int or_handshake_op_finished_sending_keys(connection_t *conn);
  395. int or_handshake_client_process_auth(connection_t *conn);
  396. int or_handshake_client_send_auth(connection_t *conn);
  397. int or_handshake_server_process_auth(connection_t *conn);
  398. int or_handshake_server_process_nonce(connection_t *conn);
  399. connection_t *connect_to_router_as_or(routerinfo_t *router, crypto_pk_env_t *prkey, struct sockaddr_in *local);
  400. connection_t *connection_or_connect_as_or(routerinfo_t *router, crypto_pk_env_t *prkey, struct sockaddr_in *local);
  401. connection_t *connection_or_connect_as_op(routerinfo_t *router, struct sockaddr_in *local);
  402. int connection_or_create_listener(crypto_pk_env_t *prkey, struct sockaddr_in *local);
  403. int connection_or_handle_listener_read(connection_t *conn);
  404. /********************************* main.c ***************************/
  405. int connection_add(connection_t *conn);
  406. int connection_remove(connection_t *conn);
  407. void connection_set_poll_socket(connection_t *conn);
  408. int pkey_cmp(crypto_pk_env_t *a, crypto_pk_env_t *b);
  409. connection_t *connection_twin_get_by_addr_port(uint32_t addr, uint16_t port);
  410. connection_t *connection_exact_get_by_addr_port(uint32_t addr, uint16_t port);
  411. connection_t *connection_get_by_type(int type);
  412. routerinfo_t *router_get_by_addr_port(uint32_t addr, uint16_t port);
  413. unsigned int *router_new_route(int *routelen);
  414. unsigned char *router_create_onion(unsigned int *route, int routelen, int *len, crypt_path_t **cpath);
  415. routerinfo_t *router_get_first_in_route(unsigned int *route, int routelen);
  416. connection_t *connect_to_router_as_op(routerinfo_t *router);
  417. void connection_watch_events(connection_t *conn, short events);
  418. void connection_stop_reading(connection_t *conn);
  419. void connection_start_reading(connection_t *conn);
  420. void connection_stop_writing(connection_t *conn);
  421. void connection_start_writing(connection_t *conn);
  422. void check_conn_read(int i);
  423. void check_conn_marked(int i);
  424. void check_conn_write(int i);
  425. int prepare_for_poll(int *timeout);
  426. int do_main_loop(void);
  427. void catchint();
  428. void catchusr1();
  429. void dumpstats(void);
  430. int main(int argc, char *argv[]);
  431. /********************************* onion.c ***************************/
  432. int decide_aci_type(uint32_t local_addr, uint16_t local_port,
  433. uint32_t remote_addr, uint16_t remote_port);
  434. int process_onion(circuit_t *circ, connection_t *conn);
  435. /* uses a weighted coin with weight cw to choose a route length */
  436. int chooselen(double cw);
  437. /* returns an array of pointers to routent that define a new route through the OR network
  438. * int cw is the coin weight to use when choosing the route
  439. * order of routers is from last to first
  440. */
  441. unsigned int *new_route(double cw, routerinfo_t **rarray, int rarray_len, int *routelen);
  442. /* creates a new onion from route, stores it and its length into bufp and lenp respectively */
  443. unsigned char *create_onion(routerinfo_t **rarray, int rarray_len, unsigned int *route, int routelen, int *len, crypt_path_t **cpath);
  444. /* encrypts 128 bytes of the onion with the specified public key, the rest with
  445. * DES OFB with the key as defined in the outter layer */
  446. unsigned char *encrypt_onion(onion_layer_t *onion, uint32_t onionlen, crypto_pk_env_t *pkey);
  447. /* decrypts the first 128 bytes using RSA and prkey, decrypts the rest with DES OFB with key1 */
  448. unsigned char *decrypt_onion(onion_layer_t *onion, uint32_t onionlen, crypto_pk_env_t *prkey);
  449. /* delete first n bytes of the onion and pads the end with n bytes of random data */
  450. void pad_onion(unsigned char *onion, uint32_t onionlen, int n);
  451. /* create a new tracked_onion entry */
  452. tracked_onion_t *new_tracked_onion(unsigned char *onion, uint32_t onionlen, tracked_onion_t **tracked_onions, tracked_onion_t **last_tracked_onion);
  453. /* delete a tracked onion entry */
  454. void remove_tracked_onion(tracked_onion_t *to, tracked_onion_t **tracked_onions, tracked_onion_t **last_tracked_onion);
  455. /* find a tracked onion in the linked list of tracked onions */
  456. tracked_onion_t *id_tracked_onion(unsigned char *onion, uint32_t onionlen, tracked_onion_t *tracked_onions);
  457. /********************************* routers.c ***************************/
  458. routerinfo_t **getrouters(char *routerfile, int *listlenp, uint16_t or_listenport);
  459. void delete_routerlist(routerinfo_t *list);
  460. /* create an NULL-terminated array of pointers pointing to elements of a router list */
  461. routerinfo_t **make_rarray(routerinfo_t* list, int *len);
  462. #endif