tortls.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 _TORTLS_H
  7. #define _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. /** Use this macro in a switch statement to catch _any_ TLS error. That way,
  31. * if more errors are added, your switches will still work. */
  32. #define CASE_TOR_TLS_ERROR_ANY \
  33. case TOR_TLS_ERROR_MISC: \
  34. case TOR_TLS_ERROR_IO: \
  35. case TOR_TLS_ERROR_CONNREFUSED: \
  36. case TOR_TLS_ERROR_CONNRESET: \
  37. case TOR_TLS_ERROR_NO_ROUTE: \
  38. case TOR_TLS_ERROR_TIMEOUT
  39. #define TOR_TLS_IS_ERROR(rv) ((rv) < TOR_TLS_CLOSE)
  40. const char *tor_tls_err_to_string(int err);
  41. void tor_tls_free_all(void);
  42. int tor_tls_context_new(crypto_pk_env_t *rsa,
  43. const char *nickname, unsigned int key_lifetime);
  44. tor_tls_t *tor_tls_new(int sock, int is_server);
  45. void tor_tls_set_renegotiate_callback(tor_tls_t *tls,
  46. void (*cb)(tor_tls_t *, void *arg),
  47. void *arg);
  48. int tor_tls_is_server(tor_tls_t *tls);
  49. void tor_tls_free(tor_tls_t *tls);
  50. int tor_tls_peer_has_cert(tor_tls_t *tls);
  51. int tor_tls_verify_v1(int severity, tor_tls_t *tls,
  52. crypto_pk_env_t **identity);
  53. int tor_tls_check_lifetime(tor_tls_t *tls, int tolerance);
  54. int tor_tls_read(tor_tls_t *tls, char *cp, size_t len);
  55. int tor_tls_write(tor_tls_t *tls, const char *cp, size_t n);
  56. int tor_tls_handshake(tor_tls_t *tls);
  57. int tor_tls_renegotiate(tor_tls_t *tls);
  58. int tor_tls_shutdown(tor_tls_t *tls);
  59. int tor_tls_get_pending_bytes(tor_tls_t *tls);
  60. size_t tor_tls_get_forced_write_size(tor_tls_t *tls);
  61. void tor_tls_get_n_raw_bytes(tor_tls_t *tls,
  62. size_t *n_read, size_t *n_written);
  63. int tor_tls_used_v1_handshake(tor_tls_t *tls);
  64. /* Log and abort if there are unhandled TLS errors in OpenSSL's error stack.
  65. */
  66. #define check_no_tls_errors() _check_no_tls_errors(__FILE__,__LINE__)
  67. void _check_no_tls_errors(const char *fname, int line);
  68. #endif