1 /* Copyright (c) 2003, Roger Dingledine
2 * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
3 * Copyright (c) 2007-2008, The Tor Project, Inc. */
4 /* See LICENSE for licensing information */
9 #define TORTLS_H_ID "$Id$"
13 * \brief Headers for tortls.c
19 /* Opaque structure to hold a TLS connection. */
20 typedef struct tor_tls_t tor_tls_t
;
22 /* Possible return values for most tor_tls_* functions. */
23 #define _MIN_TOR_TLS_ERROR_VAL -9
24 #define TOR_TLS_ERROR_MISC -9
25 /* Rename to unexpected close or something. XXXX021 */
26 #define TOR_TLS_ERROR_IO -8
27 #define TOR_TLS_ERROR_CONNREFUSED -7
28 #define TOR_TLS_ERROR_CONNRESET -6
29 #define TOR_TLS_ERROR_NO_ROUTE -5
30 #define TOR_TLS_ERROR_TIMEOUT -4
31 #define TOR_TLS_CLOSE -3
32 #define TOR_TLS_WANTREAD -2
33 #define TOR_TLS_WANTWRITE -1
34 #define TOR_TLS_DONE 0
36 /** DOCDOC XXXX021 also rename me. */
37 #define CASE_TOR_TLS_ERROR_ANY_NONIO \
38 case TOR_TLS_ERROR_MISC: \
39 case TOR_TLS_ERROR_CONNREFUSED: \
40 case TOR_TLS_ERROR_CONNRESET: \
41 case TOR_TLS_ERROR_NO_ROUTE: \
42 case TOR_TLS_ERROR_TIMEOUT
44 /** Use this macro in a switch statement to catch _any_ TLS error. That way,
45 * if more errors are added, your switches will still work. */
46 #define CASE_TOR_TLS_ERROR_ANY \
47 CASE_TOR_TLS_ERROR_ANY_NONIO: \
50 #define TOR_TLS_IS_ERROR(rv) ((rv) < TOR_TLS_CLOSE)
51 const char *tor_tls_err_to_string(int err
);
53 void tor_tls_free_all(void);
54 int tor_tls_context_new(crypto_pk_env_t
*rsa
, unsigned int key_lifetime
);
55 tor_tls_t
*tor_tls_new(int sock
, int is_server
);
56 void tor_tls_set_logged_address(tor_tls_t
*tls
, const char *address
);
57 void tor_tls_set_renegotiate_callback(tor_tls_t
*tls
,
58 void (*cb
)(tor_tls_t
*, void *arg
),
60 int tor_tls_is_server(tor_tls_t
*tls
);
61 void tor_tls_free(tor_tls_t
*tls
);
62 int tor_tls_peer_has_cert(tor_tls_t
*tls
);
63 int tor_tls_verify(int severity
, tor_tls_t
*tls
, crypto_pk_env_t
**identity
);
64 int tor_tls_check_lifetime(tor_tls_t
*tls
, int tolerance
);
65 int tor_tls_read(tor_tls_t
*tls
, char *cp
, size_t len
);
66 int tor_tls_write(tor_tls_t
*tls
, const char *cp
, size_t n
);
67 int tor_tls_handshake(tor_tls_t
*tls
);
68 int tor_tls_renegotiate(tor_tls_t
*tls
);
69 int tor_tls_shutdown(tor_tls_t
*tls
);
70 int tor_tls_get_pending_bytes(tor_tls_t
*tls
);
71 size_t tor_tls_get_forced_write_size(tor_tls_t
*tls
);
73 void tor_tls_get_n_raw_bytes(tor_tls_t
*tls
,
74 size_t *n_read
, size_t *n_written
);
76 void tor_tls_get_buffer_sizes(tor_tls_t
*tls
,
77 int *rbuf_capacity
, int *rbuf_bytes
,
78 int *wbuf_capacity
, int *wbuf_bytes
);
80 int tor_tls_used_v1_handshake(tor_tls_t
*tls
);
82 /* Log and abort if there are unhandled TLS errors in OpenSSL's error stack.
84 #define check_no_tls_errors() _check_no_tls_errors(__FILE__,__LINE__)
86 void _check_no_tls_errors(const char *fname
, int line
);