You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ssl_util.h 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*-
  2. * Copyright 2016 Vsevolod Stakhov
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef SRC_LIBUTIL_SSL_UTIL_H_
  17. #define SRC_LIBUTIL_SSL_UTIL_H_
  18. #include "config.h"
  19. #include "libutil/addr.h"
  20. #include "libutil/libev_helper.h"
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. struct rspamd_ssl_connection;
  25. typedef void (*rspamd_ssl_handler_t) (gint fd, short what, gpointer d);
  26. typedef void (*rspamd_ssl_error_handler_t) (gpointer d, GError *err);
  27. /**
  28. * Creates a new ssl connection data structure
  29. * @param ssl_ctx initialized SSL_CTX structure
  30. * @return opaque connection data
  31. */
  32. struct rspamd_ssl_connection *rspamd_ssl_connection_new (gpointer ssl_ctx,
  33. struct ev_loop *ev_base,
  34. gboolean verify_peer,
  35. const gchar *log_tag);
  36. /**
  37. * Connects SSL session using the specified (connected) FD
  38. * @param conn connection
  39. * @param fd fd to use
  40. * @param hostname hostname for SNI
  41. * @param ev event to use
  42. * @param tv timeout for connection
  43. * @param handler connected session handler
  44. * @param handler_data opaque data
  45. * @return TRUE if a session has been connected
  46. */
  47. gboolean rspamd_ssl_connect_fd (struct rspamd_ssl_connection *conn, gint fd,
  48. const gchar *hostname, struct rspamd_io_ev *ev, ev_tstamp timeout,
  49. rspamd_ssl_handler_t handler, rspamd_ssl_error_handler_t err_handler,
  50. gpointer handler_data);
  51. /**
  52. * Perform async read from SSL socket
  53. * @param conn
  54. * @param buf
  55. * @param buflen
  56. * @return
  57. */
  58. gssize rspamd_ssl_read (struct rspamd_ssl_connection *conn, gpointer buf,
  59. gsize buflen);
  60. /**
  61. * Perform async write to ssl buffer
  62. * @param conn
  63. * @param buf
  64. * @param buflen
  65. * @param ev
  66. * @param tv
  67. * @return
  68. */
  69. gssize rspamd_ssl_write (struct rspamd_ssl_connection *conn, gconstpointer buf,
  70. gsize buflen);
  71. /**
  72. * Emulate writev by copying iovec to a temporary buffer
  73. * @param conn
  74. * @param buf
  75. * @param buflen
  76. * @return
  77. */
  78. gssize rspamd_ssl_writev (struct rspamd_ssl_connection *conn, struct iovec *iov,
  79. gsize iovlen);
  80. /**
  81. * Removes connection data
  82. * @param conn
  83. */
  84. void rspamd_ssl_connection_free (struct rspamd_ssl_connection *conn);
  85. gpointer rspamd_init_ssl_ctx (void);
  86. gpointer rspamd_init_ssl_ctx_noverify (void);
  87. #ifdef __cplusplus
  88. }
  89. #endif
  90. #endif /* SRC_LIBUTIL_SSL_UTIL_H_ */