1 /* Copyright (c) 2003, Roger Dingledine
2 * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
3 * Copyright (c) 2007-2011, The Tor Project, Inc. */
4 /* See LICENSE for licensing information */
11 * \brief Headers for tortls.c
17 /* Opaque structure to hold a TLS connection. */
18 typedef struct tor_tls_t tor_tls_t
;
20 /* Possible return values for most tor_tls_* functions. */
21 #define _MIN_TOR_TLS_ERROR_VAL -9
22 #define TOR_TLS_ERROR_MISC -9
23 /* Rename to unexpected close or something. XXXX */
24 #define TOR_TLS_ERROR_IO -8
25 #define TOR_TLS_ERROR_CONNREFUSED -7
26 #define TOR_TLS_ERROR_CONNRESET -6
27 #define TOR_TLS_ERROR_NO_ROUTE -5
28 #define TOR_TLS_ERROR_TIMEOUT -4
29 #define TOR_TLS_CLOSE -3
30 #define TOR_TLS_WANTREAD -2
31 #define TOR_TLS_WANTWRITE -1
32 #define TOR_TLS_DONE 0
34 /** Collection of case statements for all TLS errors that are not due to
35 * underlying IO failure. */
36 #define CASE_TOR_TLS_ERROR_ANY_NONIO \
37 case TOR_TLS_ERROR_MISC: \
38 case TOR_TLS_ERROR_CONNREFUSED: \
39 case TOR_TLS_ERROR_CONNRESET: \
40 case TOR_TLS_ERROR_NO_ROUTE: \
41 case TOR_TLS_ERROR_TIMEOUT
43 /** Use this macro in a switch statement to catch _any_ TLS error. That way,
44 * if more errors are added, your switches will still work. */
45 #define CASE_TOR_TLS_ERROR_ANY \
46 CASE_TOR_TLS_ERROR_ANY_NONIO: \
49 #define TOR_TLS_IS_ERROR(rv) ((rv) < TOR_TLS_CLOSE)
50 const char *tor_tls_err_to_string(int err
);
52 void tor_tls_free_all(void);
53 int tor_tls_context_new(crypto_pk_env_t
*rsa
, unsigned int key_lifetime
);
54 tor_tls_t
*tor_tls_new(int sock
, int is_server
);
55 void tor_tls_set_logged_address(tor_tls_t
*tls
, const char *address
);
56 void tor_tls_set_renegotiate_callback(tor_tls_t
*tls
,
57 void (*cb
)(tor_tls_t
*, void *arg
),
59 int tor_tls_is_server(tor_tls_t
*tls
);
60 void tor_tls_free(tor_tls_t
*tls
);
61 int tor_tls_peer_has_cert(tor_tls_t
*tls
);
62 int tor_tls_verify(int severity
, tor_tls_t
*tls
, crypto_pk_env_t
**identity
);
63 int tor_tls_check_lifetime(tor_tls_t
*tls
, int tolerance
);
64 int tor_tls_read(tor_tls_t
*tls
, char *cp
, size_t len
);
65 int tor_tls_write(tor_tls_t
*tls
, const char *cp
, size_t n
);
66 int tor_tls_handshake(tor_tls_t
*tls
);
67 int tor_tls_renegotiate(tor_tls_t
*tls
);
68 void tor_tls_block_renegotiation(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 size_t *rbuf_capacity
, size_t *rbuf_bytes
,
78 size_t *wbuf_capacity
, size_t *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
);