2007-12-12 21:09:01 +00:00
|
|
|
/* Copyright (c) 2003, Roger Dingledine
|
|
|
|
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
|
2011-01-03 11:50:39 -05:00
|
|
|
* Copyright (c) 2007-2011, The Tor Project, Inc. */
|
2003-09-04 16:05:08 +00:00
|
|
|
/* See LICENSE for licensing information */
|
|
|
|
|
2008-12-29 02:21:02 +00:00
|
|
|
#ifndef _TOR_TORTLS_H
|
|
|
|
#define _TOR_TORTLS_H
|
2003-09-04 16:05:08 +00:00
|
|
|
|
2004-05-10 07:54:13 +00:00
|
|
|
/**
|
|
|
|
* \file tortls.h
|
|
|
|
* \brief Headers for tortls.c
|
|
|
|
**/
|
|
|
|
|
2007-08-08 05:50:31 +00:00
|
|
|
#include "crypto.h"
|
|
|
|
#include "compat.h"
|
2011-11-13 14:47:11 +01:00
|
|
|
#include "compat_libevent.h"
|
2003-09-04 16:05:08 +00:00
|
|
|
|
2004-05-01 20:46:28 +00:00
|
|
|
/* Opaque structure to hold a TLS connection. */
|
2005-10-06 04:33:40 +00:00
|
|
|
typedef struct tor_tls_t tor_tls_t;
|
2003-09-04 16:05:08 +00:00
|
|
|
|
2011-09-13 11:37:15 -04:00
|
|
|
/* Opaque structure to hold an X509 certificate. */
|
|
|
|
typedef struct tor_cert_t tor_cert_t;
|
|
|
|
|
2004-05-01 20:46:28 +00:00
|
|
|
/* Possible return values for most tor_tls_* functions. */
|
2007-01-15 21:21:05 +00:00
|
|
|
#define _MIN_TOR_TLS_ERROR_VAL -9
|
2007-01-15 21:13:37 +00:00
|
|
|
#define TOR_TLS_ERROR_MISC -9
|
2008-12-18 16:11:24 +00:00
|
|
|
/* Rename to unexpected close or something. XXXX */
|
2007-01-15 21:13:37 +00:00
|
|
|
#define TOR_TLS_ERROR_IO -8
|
|
|
|
#define TOR_TLS_ERROR_CONNREFUSED -7
|
|
|
|
#define TOR_TLS_ERROR_CONNRESET -6
|
|
|
|
#define TOR_TLS_ERROR_NO_ROUTE -5
|
|
|
|
#define TOR_TLS_ERROR_TIMEOUT -4
|
|
|
|
#define TOR_TLS_CLOSE -3
|
|
|
|
#define TOR_TLS_WANTREAD -2
|
|
|
|
#define TOR_TLS_WANTWRITE -1
|
|
|
|
#define TOR_TLS_DONE 0
|
2003-09-04 16:05:08 +00:00
|
|
|
|
2008-12-17 22:58:20 +00:00
|
|
|
/** Collection of case statements for all TLS errors that are not due to
|
|
|
|
* underlying IO failure. */
|
2008-02-21 16:11:58 +00:00
|
|
|
#define CASE_TOR_TLS_ERROR_ANY_NONIO \
|
2007-01-15 21:21:05 +00:00
|
|
|
case TOR_TLS_ERROR_MISC: \
|
|
|
|
case TOR_TLS_ERROR_CONNREFUSED: \
|
|
|
|
case TOR_TLS_ERROR_CONNRESET: \
|
|
|
|
case TOR_TLS_ERROR_NO_ROUTE: \
|
|
|
|
case TOR_TLS_ERROR_TIMEOUT
|
|
|
|
|
2008-02-21 16:11:58 +00:00
|
|
|
/** Use this macro in a switch statement to catch _any_ TLS error. That way,
|
|
|
|
* if more errors are added, your switches will still work. */
|
|
|
|
#define CASE_TOR_TLS_ERROR_ANY \
|
|
|
|
CASE_TOR_TLS_ERROR_ANY_NONIO: \
|
|
|
|
case TOR_TLS_ERROR_IO
|
|
|
|
|
2007-01-15 21:21:05 +00:00
|
|
|
#define TOR_TLS_IS_ERROR(rv) ((rv) < TOR_TLS_CLOSE)
|
2007-11-07 16:37:08 +00:00
|
|
|
const char *tor_tls_err_to_string(int err);
|
2011-06-22 15:29:30 -04:00
|
|
|
void tor_tls_get_state_description(tor_tls_t *tls, char *buf, size_t sz);
|
2007-01-15 21:21:05 +00:00
|
|
|
|
2005-02-11 01:41:19 +00:00
|
|
|
void tor_tls_free_all(void);
|
2010-10-03 18:14:08 -07:00
|
|
|
int tor_tls_context_init(int is_public_server,
|
|
|
|
crypto_pk_env_t *client_identity,
|
|
|
|
crypto_pk_env_t *server_identity,
|
2010-10-01 14:06:57 -07:00
|
|
|
unsigned int key_lifetime);
|
2006-06-07 06:21:11 +00:00
|
|
|
tor_tls_t *tor_tls_new(int sock, int is_server);
|
2008-02-19 22:27:44 +00:00
|
|
|
void tor_tls_set_logged_address(tor_tls_t *tls, const char *address);
|
2011-11-13 14:47:11 +01:00
|
|
|
void tor_tls_set_renegotiate_callbacks(tor_tls_t *tls,
|
2007-12-01 08:09:48 +00:00
|
|
|
void (*cb)(tor_tls_t *, void *arg),
|
2011-11-13 14:47:11 +01:00
|
|
|
void (*cb2)(evutil_socket_t, short, void *),
|
2007-12-01 08:09:48 +00:00
|
|
|
void *arg);
|
2005-10-06 04:33:40 +00:00
|
|
|
int tor_tls_is_server(tor_tls_t *tls);
|
|
|
|
void tor_tls_free(tor_tls_t *tls);
|
|
|
|
int tor_tls_peer_has_cert(tor_tls_t *tls);
|
2011-09-22 11:01:14 -04:00
|
|
|
tor_cert_t *tor_tls_get_peer_cert(tor_tls_t *tls);
|
2008-02-12 20:20:52 +00:00
|
|
|
int tor_tls_verify(int severity, tor_tls_t *tls, crypto_pk_env_t **identity);
|
2011-11-15 11:56:21 -05:00
|
|
|
int tor_tls_check_lifetime(int severity,
|
|
|
|
tor_tls_t *tls, int past_tolerance,
|
2011-11-14 22:21:45 -05:00
|
|
|
int future_tolerance);
|
2005-10-06 04:33:40 +00:00
|
|
|
int tor_tls_read(tor_tls_t *tls, char *cp, size_t len);
|
2007-01-30 22:19:41 +00:00
|
|
|
int tor_tls_write(tor_tls_t *tls, const char *cp, size_t n);
|
2005-10-06 04:33:40 +00:00
|
|
|
int tor_tls_handshake(tor_tls_t *tls);
|
2009-08-14 14:34:16 -04:00
|
|
|
int tor_tls_finish_handshake(tor_tls_t *tls);
|
2007-12-01 08:09:46 +00:00
|
|
|
int tor_tls_renegotiate(tor_tls_t *tls);
|
2010-09-27 16:07:14 -04:00
|
|
|
void tor_tls_unblock_renegotiation(tor_tls_t *tls);
|
2010-10-12 14:45:15 -04:00
|
|
|
void tor_tls_assert_renegotiation_unblocked(tor_tls_t *tls);
|
2005-10-06 04:33:40 +00:00
|
|
|
int tor_tls_shutdown(tor_tls_t *tls);
|
|
|
|
int tor_tls_get_pending_bytes(tor_tls_t *tls);
|
2006-12-13 22:46:42 +00:00
|
|
|
size_t tor_tls_get_forced_write_size(tor_tls_t *tls);
|
2005-10-06 04:33:40 +00:00
|
|
|
|
2006-12-29 03:42:46 +00:00
|
|
|
void tor_tls_get_n_raw_bytes(tor_tls_t *tls,
|
|
|
|
size_t *n_read, size_t *n_written);
|
2004-01-13 01:19:02 +00:00
|
|
|
|
2008-04-10 15:12:24 +00:00
|
|
|
void tor_tls_get_buffer_sizes(tor_tls_t *tls,
|
2009-09-01 05:23:47 +02:00
|
|
|
size_t *rbuf_capacity, size_t *rbuf_bytes,
|
|
|
|
size_t *wbuf_capacity, size_t *wbuf_bytes);
|
2008-04-10 15:12:24 +00:00
|
|
|
|
2007-10-30 21:46:02 +00:00
|
|
|
int tor_tls_used_v1_handshake(tor_tls_t *tls);
|
2011-09-16 17:48:20 -04:00
|
|
|
int tor_tls_received_v3_certificate(tor_tls_t *tls);
|
2010-10-11 13:45:27 -04:00
|
|
|
int tor_tls_get_num_server_handshakes(tor_tls_t *tls);
|
|
|
|
int tor_tls_server_got_renegotiate(tor_tls_t *tls);
|
2011-09-13 13:46:21 -04:00
|
|
|
int tor_tls_get_tlssecrets(tor_tls_t *tls, uint8_t *secrets_out);
|
2007-10-30 21:46:02 +00:00
|
|
|
|
2004-05-01 20:46:28 +00:00
|
|
|
/* Log and abort if there are unhandled TLS errors in OpenSSL's error stack.
|
|
|
|
*/
|
2005-10-25 07:05:03 +00:00
|
|
|
#define check_no_tls_errors() _check_no_tls_errors(__FILE__,__LINE__)
|
2004-04-26 23:00:07 +00:00
|
|
|
|
2005-04-23 14:26:02 +00:00
|
|
|
void _check_no_tls_errors(const char *fname, int line);
|
2010-10-11 13:26:57 -04:00
|
|
|
void tor_tls_log_one_error(tor_tls_t *tls, unsigned long err,
|
|
|
|
int severity, int domain, const char *doing);
|
2004-04-26 23:00:07 +00:00
|
|
|
|
2009-08-14 14:34:16 -04:00
|
|
|
#ifdef USE_BUFFEREVENTS
|
|
|
|
int tor_tls_start_renegotiating(tor_tls_t *tls);
|
|
|
|
struct bufferevent *tor_tls_init_bufferevent(tor_tls_t *tls,
|
|
|
|
struct bufferevent *bufev_in,
|
2010-11-09 15:36:27 -05:00
|
|
|
evutil_socket_t socket, int receiving,
|
|
|
|
int filter);
|
2009-08-14 14:34:16 -04:00
|
|
|
#endif
|
|
|
|
|
2011-09-13 11:37:15 -04:00
|
|
|
void tor_cert_free(tor_cert_t *cert);
|
2011-10-11 11:30:01 -04:00
|
|
|
tor_cert_t *tor_cert_decode(const uint8_t *certificate,
|
|
|
|
size_t certificate_len);
|
2011-09-13 11:37:15 -04:00
|
|
|
void tor_cert_get_der(const tor_cert_t *cert,
|
|
|
|
const uint8_t **encoded_out, size_t *size_out);
|
2011-09-14 14:43:44 -04:00
|
|
|
const digests_t *tor_cert_get_id_digests(const tor_cert_t *cert);
|
|
|
|
const digests_t *tor_cert_get_cert_digests(const tor_cert_t *cert);
|
2011-09-13 11:37:15 -04:00
|
|
|
int tor_tls_get_my_certs(int server,
|
|
|
|
const tor_cert_t **link_cert_out,
|
|
|
|
const tor_cert_t **id_cert_out);
|
2011-09-22 10:18:17 -04:00
|
|
|
crypto_pk_env_t *tor_tls_get_my_client_auth_key(void);
|
|
|
|
crypto_pk_env_t *tor_tls_cert_get_key(tor_cert_t *cert);
|
2011-09-14 13:04:48 -04:00
|
|
|
int tor_tls_cert_matches_key(const tor_tls_t *tls, const tor_cert_t *cert);
|
2011-11-15 11:56:21 -05:00
|
|
|
int tor_tls_cert_is_valid(int severity,
|
|
|
|
const tor_cert_t *cert,
|
2011-09-22 10:01:41 -04:00
|
|
|
const tor_cert_t *signing_cert,
|
|
|
|
int check_rsa_1024);
|
2011-09-13 11:37:15 -04:00
|
|
|
|
2003-09-04 16:05:08 +00:00
|
|
|
#endif
|
2005-06-09 19:03:31 +00:00
|
|
|
|