OpenSSLConnection.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #pragma once
  2. #include "../common/config.h"
  3. #ifdef HTTPS_BACKEND_OPENSSL
  4. #include <openssl/ssl.h>
  5. #include "../common/Connection.h"
  6. #include "../common/PlaintextConnection.h"
  7. class OpenSSLConnection : public Connection
  8. {
  9. public:
  10. OpenSSLConnection();
  11. virtual bool connect(const std::string &hostname, uint16_t port) override;
  12. virtual size_t read(char *buffer, size_t size) override;
  13. virtual size_t write(const char *buffer, size_t size) override;
  14. virtual void close() override;
  15. virtual ~OpenSSLConnection();
  16. static bool valid();
  17. private:
  18. PlaintextConnection socket;
  19. SSL_CTX *context;
  20. SSL *conn;
  21. struct SSLFuncs
  22. {
  23. SSLFuncs();
  24. bool valid;
  25. int (*library_init)();
  26. int (*init_ssl)(uint64_t opts, const void *settings);
  27. SSL_CTX *(*CTX_new)(const SSL_METHOD *method);
  28. long (*CTX_ctrl)(SSL_CTX *ctx, int cmd, long larg, void *parg);
  29. void (*CTX_set_verify)(SSL_CTX *ctx, int mode, void *verify_callback);
  30. int (*CTX_set_default_verify_paths)(SSL_CTX *ctx);
  31. void (*CTX_free)(SSL_CTX *ctx);
  32. SSL *(*SSL_new)(SSL_CTX *ctx);
  33. void (*SSL_free)(SSL *ctx);
  34. int (*set_fd)(SSL *ssl, int fd);
  35. int (*connect)(SSL *ssl);
  36. int (*read)(SSL *ssl, void *buf, int num);
  37. int (*write)(SSL *ssl, const void *buf, int num);
  38. int (*shutdown)(SSL *ssl);
  39. long (*get_verify_result)(const SSL *ssl);
  40. X509 *(*get_peer_certificate)(const SSL *ssl);
  41. const SSL_METHOD *(*SSLv23_method)();
  42. int (*check_host)(X509 *cert, const char *name, size_t namelen, unsigned int flags, char **peername);
  43. };
  44. static SSLFuncs ssl;
  45. };
  46. #endif // HTTPS_BACKEND_OPENSSL