tortls.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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, unsigned int key_lifetime);
  43. tor_tls_t *tor_tls_new(int sock, int is_server);
  44. void tor_tls_set_renegotiate_callback(tor_tls_t *tls,
  45. void (*cb)(tor_tls_t *, void *arg),
  46. void *arg);
  47. int tor_tls_is_server(tor_tls_t *tls);
  48. void tor_tls_free(tor_tls_t *tls);
  49. int tor_tls_peer_has_cert(tor_tls_t *tls);
  50. int tor_tls_verify(int severity, tor_tls_t *tls, crypto_pk_env_t **identity);
  51. int tor_tls_check_lifetime(tor_tls_t *tls, int tolerance);
  52. int tor_tls_read(tor_tls_t *tls, char *cp, size_t len);
  53. int tor_tls_write(tor_tls_t *tls, const char *cp, size_t n);
  54. int tor_tls_handshake(tor_tls_t *tls);
  55. int tor_tls_renegotiate(tor_tls_t *tls);
  56. int tor_tls_shutdown(tor_tls_t *tls);
  57. int tor_tls_get_pending_bytes(tor_tls_t *tls);
  58. size_t tor_tls_get_forced_write_size(tor_tls_t *tls);
  59. void tor_tls_get_n_raw_bytes(tor_tls_t *tls,
  60. size_t *n_read, size_t *n_written);
  61. int tor_tls_used_v1_handshake(tor_tls_t *tls);
  62. /* Log and abort if there are unhandled TLS errors in OpenSSL's error stack.
  63. */
  64. #define check_no_tls_errors() _check_no_tls_errors(__FILE__,__LINE__)
  65. void _check_no_tls_errors(const char *fname, int line);
  66. #endif