tortls.h 3.2 KB

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