tls_server.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * $Id$
  3. *
  4. * TLS module - main server part
  5. *
  6. * Copyright (C) 2001-2003 FhG FOKUS
  7. * Copyright (C) 2005-2010 iptelorg GmbH
  8. *
  9. * This file is part of SIP-router, a free SIP server.
  10. *
  11. * Permission to use, copy, modify, and distribute this software for any
  12. * purpose with or without fee is hereby granted, provided that the above
  13. * copyright notice and this permission notice appear in all copies.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  16. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  17. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  18. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  19. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  20. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  21. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  22. */
  23. /** main tls part (implements the tls hooks that are called from the tcp code).
  24. * @file tls_server.h
  25. * @ingroup tls
  26. * Module: @ref tls
  27. */
  28. #ifndef _TLS_SERVER_H
  29. #define _TLS_SERVER_H
  30. #include <stdio.h>
  31. #include "../../tcp_conn.h"
  32. #include "tls_domain.h"
  33. #include "tls_ct_wrq.h"
  34. enum tls_conn_states {
  35. S_TLS_NONE = 0,
  36. S_TLS_ACCEPTING,
  37. S_TLS_CONNECTING,
  38. S_TLS_ESTABLISHED
  39. };
  40. struct tls_rd_buf {
  41. unsigned int pos; /* current position */
  42. unsigned int size; /* total size (buf) */
  43. unsigned char buf[1];
  44. };
  45. /* tls conn flags */
  46. #define F_TLS_CON_WR_WANTS_RD 1 /* write wants read */
  47. #define F_TLS_CON_HANDSHAKED 2 /* connection is handshaked */
  48. #define F_TLS_CON_RENEGOTIATION 4 /* renegotiation by clinet */
  49. struct tls_extra_data {
  50. tls_domains_cfg_t* cfg; /* Configuration used for this connection */
  51. SSL* ssl; /* SSL context used for the connection */
  52. BIO* rwbio; /* bio used for read/write
  53. (openssl code might add buffering BIOs so
  54. it's better to remember our original BIO) */
  55. tls_ct_q* ct_wq;
  56. struct tls_rd_buf* enc_rd_buf;
  57. unsigned int flags;
  58. enum tls_conn_states state;
  59. };
  60. /* return true if write wants read */
  61. #define tls_write_wants_read(tls_ed) (tls_ed->flags & F_TLS_CON_WR_WANTS_RD)
  62. /*
  63. * Called when new tcp connection is accepted
  64. */
  65. int tls_h_tcpconn_init(struct tcp_connection *c, int sock);
  66. /*
  67. * clean the extra data upon connection shut down
  68. */
  69. void tls_h_tcpconn_clean(struct tcp_connection *c);
  70. /*
  71. * shut down the TLS connection
  72. */
  73. void tls_h_close(struct tcp_connection *c, int fd);
  74. int tls_encode_f(struct tcp_connection *c,
  75. const char ** pbuf, unsigned int* plen,
  76. const char** rest_buf, unsigned int* rest_len,
  77. snd_flags_t* send_flags) ;
  78. int tls_read_f(struct tcp_connection *c, int* flags);
  79. int tls_h_fix_read_conn(struct tcp_connection *c);
  80. int tls_connect(struct tcp_connection *c, int* error);
  81. int tls_accept(struct tcp_connection *c, int* error);
  82. #endif /* _TLS_SERVER_H */