tortls.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /* Copyright (c) 2003, Roger Dingledine
  2. * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
  3. * Copyright (c) 2007-2010, The Tor Project, Inc. */
  4. /* See LICENSE for licensing information */
  5. #ifndef _TOR_TORTLS_H
  6. #define _TOR_TORTLS_H
  7. /**
  8. * \file tortls.h
  9. * \brief Headers for tortls.c
  10. **/
  11. #include "crypto.h"
  12. #include "compat.h"
  13. /* Opaque structure to hold a TLS connection. */
  14. typedef struct tor_tls_t tor_tls_t;
  15. /* Possible return values for most tor_tls_* functions. */
  16. #define _MIN_TOR_TLS_ERROR_VAL -9
  17. #define TOR_TLS_ERROR_MISC -9
  18. /* Rename to unexpected close or something. XXXX */
  19. #define TOR_TLS_ERROR_IO -8
  20. #define TOR_TLS_ERROR_CONNREFUSED -7
  21. #define TOR_TLS_ERROR_CONNRESET -6
  22. #define TOR_TLS_ERROR_NO_ROUTE -5
  23. #define TOR_TLS_ERROR_TIMEOUT -4
  24. #define TOR_TLS_CLOSE -3
  25. #define TOR_TLS_WANTREAD -2
  26. #define TOR_TLS_WANTWRITE -1
  27. #define TOR_TLS_DONE 0
  28. /** Collection of case statements for all TLS errors that are not due to
  29. * underlying IO failure. */
  30. #define CASE_TOR_TLS_ERROR_ANY_NONIO \
  31. case TOR_TLS_ERROR_MISC: \
  32. case TOR_TLS_ERROR_CONNREFUSED: \
  33. case TOR_TLS_ERROR_CONNRESET: \
  34. case TOR_TLS_ERROR_NO_ROUTE: \
  35. case TOR_TLS_ERROR_TIMEOUT
  36. /** Use this macro in a switch statement to catch _any_ TLS error. That way,
  37. * if more errors are added, your switches will still work. */
  38. #define CASE_TOR_TLS_ERROR_ANY \
  39. CASE_TOR_TLS_ERROR_ANY_NONIO: \
  40. case TOR_TLS_ERROR_IO
  41. #define TOR_TLS_IS_ERROR(rv) ((rv) < TOR_TLS_CLOSE)
  42. const char *tor_tls_err_to_string(int err);
  43. void tor_tls_free_all(void);
  44. int tor_tls_context_new(crypto_pk_env_t *rsa, unsigned int key_lifetime);
  45. tor_tls_t *tor_tls_new(int sock, int is_server);
  46. void tor_tls_set_logged_address(tor_tls_t *tls, const char *address);
  47. void tor_tls_set_renegotiate_callback(tor_tls_t *tls,
  48. void (*cb)(tor_tls_t *, void *arg),
  49. void *arg);
  50. int tor_tls_is_server(tor_tls_t *tls);
  51. void tor_tls_free(tor_tls_t *tls);
  52. int tor_tls_peer_has_cert(tor_tls_t *tls);
  53. int tor_tls_verify(int severity, tor_tls_t *tls, crypto_pk_env_t **identity);
  54. int tor_tls_check_lifetime(tor_tls_t *tls, int tolerance);
  55. int tor_tls_read(tor_tls_t *tls, char *cp, size_t len);
  56. int tor_tls_write(tor_tls_t *tls, const char *cp, size_t n);
  57. int tor_tls_handshake(tor_tls_t *tls);
  58. int tor_tls_renegotiate(tor_tls_t *tls);
  59. void tor_tls_block_renegotiation(tor_tls_t *tls);
  60. int tor_tls_shutdown(tor_tls_t *tls);
  61. int tor_tls_get_pending_bytes(tor_tls_t *tls);
  62. size_t tor_tls_get_forced_write_size(tor_tls_t *tls);
  63. void tor_tls_get_n_raw_bytes(tor_tls_t *tls,
  64. size_t *n_read, size_t *n_written);
  65. void tor_tls_get_buffer_sizes(tor_tls_t *tls,
  66. size_t *rbuf_capacity, size_t *rbuf_bytes,
  67. size_t *wbuf_capacity, size_t *wbuf_bytes);
  68. int tor_tls_used_v1_handshake(tor_tls_t *tls);
  69. /* Log and abort if there are unhandled TLS errors in OpenSSL's error stack.
  70. */
  71. #define check_no_tls_errors() _check_no_tls_errors(__FILE__,__LINE__)
  72. void _check_no_tls_errors(const char *fname, int line);
  73. #endif