security.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #ifndef NETDATA_SECURITY_H
  2. # define NETDATA_SECURITY_H
  3. # define NETDATA_SSL_HANDSHAKE_COMPLETE 0 //All the steps were successful
  4. # define NETDATA_SSL_START 1 //Starting handshake, conn variable is NULL
  5. # define NETDATA_SSL_WANT_READ 2 //The connection wanna read from socket
  6. # define NETDATA_SSL_WANT_WRITE 4 //The connection wanna write on socket
  7. # define NETDATA_SSL_NO_HANDSHAKE 8 //Continue without encrypt connection.
  8. # define NETDATA_SSL_OPTIONAL 16 //Flag to define the HTTP request
  9. # define NETDATA_SSL_FORCE 32 //We only accepts HTTPS request
  10. # define NETDATA_SSL_INVALID_CERTIFICATE 64 //Accepts invalid certificate
  11. # define NETDATA_SSL_VALID_CERTIFICATE 128 //Accepts invalid certificate
  12. # define NETDATA_SSL_PROXY_HTTPS 256 //Proxy is using HTTPS
  13. #define NETDATA_SSL_CONTEXT_SERVER 0
  14. #define NETDATA_SSL_CONTEXT_STREAMING 1
  15. #define NETDATA_SSL_CONTEXT_EXPORTING 2
  16. # ifdef ENABLE_HTTPS
  17. #define OPENSSL_VERSION_095 0x00905100L
  18. #define OPENSSL_VERSION_097 0x0907000L
  19. #define OPENSSL_VERSION_110 0x10100000L
  20. #define OPENSSL_VERSION_111 0x10101000L
  21. #define OPENSSL_VERSION_300 0x30000000L
  22. # include <openssl/ssl.h>
  23. # include <openssl/err.h>
  24. # include <openssl/evp.h>
  25. # include <openssl/pem.h>
  26. # if (SSLEAY_VERSION_NUMBER >= OPENSSL_VERSION_097) && (OPENSSL_VERSION_NUMBER < OPENSSL_VERSION_110)
  27. # include <openssl/conf.h>
  28. # endif
  29. #if OPENSSL_VERSION_NUMBER >= OPENSSL_VERSION_300
  30. #include <openssl/core_names.h>
  31. #include <openssl/decoder.h>
  32. #endif
  33. struct netdata_ssl{
  34. SSL *conn; //SSL connection
  35. uint32_t flags; //The flags for SSL connection
  36. };
  37. extern SSL_CTX *netdata_exporting_ctx;
  38. extern SSL_CTX *netdata_client_ctx;
  39. extern SSL_CTX *netdata_srv_ctx;
  40. extern const char *security_key;
  41. extern const char *security_cert;
  42. extern const char *tls_version;
  43. extern const char *tls_ciphers;
  44. extern int netdata_validate_server;
  45. extern int security_location_for_context(SSL_CTX *ctx,char *file,char *path);
  46. void security_openssl_library();
  47. void security_clean_openssl();
  48. void security_start_ssl(int selector);
  49. int security_process_accept(SSL *ssl,int msg);
  50. int security_test_certificate(SSL *ssl);
  51. SSL_CTX * security_initialize_openssl_client();
  52. # endif //ENABLE_HTTPS
  53. #endif //NETDATA_SECURITY_H