ma_tls.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. #ifndef _ma_tls_h_
  2. #define _ma_tls_h_
  3. enum enum_pvio_tls_type {
  4. SSL_TYPE_DEFAULT=0,
  5. #ifdef _WIN32
  6. SSL_TYPE_SCHANNEL,
  7. #endif
  8. SSL_TYPE_OPENSSL,
  9. SSL_TYPE_GNUTLS
  10. };
  11. #define PROTOCOL_SSLV3 0
  12. #define PROTOCOL_TLS_1_0 1
  13. #define PROTOCOL_TLS_1_1 2
  14. #define PROTOCOL_TLS_1_2 3
  15. #define PROTOCOL_TLS_1_3 4
  16. #define PROTOCOL_UNKNOWN 5
  17. #define PROTOCOL_MAX PROTOCOL_TLS_1_3
  18. #define TLS_VERSION_LENGTH 64
  19. extern char tls_library_version[TLS_VERSION_LENGTH];
  20. typedef struct st_ma_pvio_tls {
  21. void *data;
  22. MARIADB_PVIO *pvio;
  23. void *ssl;
  24. } MARIADB_TLS;
  25. /* Function prototypes */
  26. /* ma_tls_start
  27. initializes the ssl library
  28. Parameter:
  29. errmsg pointer to error message buffer
  30. errmsg_len length of error message buffer
  31. Returns:
  32. 0 success
  33. 1 if an error occurred
  34. Notes:
  35. On success the global variable ma_tls_initialized will be set to 1
  36. */
  37. int ma_tls_start(char *errmsg, size_t errmsg_len);
  38. /* ma_tls_end
  39. unloads/deinitializes ssl library and unsets global variable
  40. ma_tls_initialized
  41. */
  42. void ma_tls_end(void);
  43. /* ma_tls_init
  44. creates a new SSL structure for a SSL connection and loads
  45. client certificates
  46. Parameters:
  47. MYSQL a mysql structure
  48. Returns:
  49. void * a pointer to internal SSL structure
  50. */
  51. void * ma_tls_init(MYSQL *mysql);
  52. /* ma_tls_connect
  53. performs SSL handshake
  54. Parameters:
  55. MARIADB_TLS MariaDB SSL container
  56. Returns:
  57. 0 success
  58. 1 error
  59. */
  60. my_bool ma_tls_connect(MARIADB_TLS *ctls);
  61. /* ma_tls_read
  62. reads up to length bytes from socket
  63. Parameters:
  64. ctls MariaDB SSL container
  65. buffer read buffer
  66. length buffer length
  67. Returns:
  68. 0-n bytes read
  69. -1 if an error occurred
  70. */
  71. ssize_t ma_tls_read(MARIADB_TLS *ctls, const uchar* buffer, size_t length);
  72. /* ma_tls_write
  73. write buffer to socket
  74. Parameters:
  75. ctls MariaDB SSL container
  76. buffer write buffer
  77. length buffer length
  78. Returns:
  79. 0-n bytes written
  80. -1 if an error occurred
  81. */
  82. ssize_t ma_tls_write(MARIADB_TLS *ctls, const uchar* buffer, size_t length);
  83. /* ma_tls_close
  84. closes SSL connection and frees SSL structure which was previously
  85. created by ma_tls_init call
  86. Parameters:
  87. MARIADB_TLS MariaDB SSL container
  88. Returns:
  89. 0 success
  90. 1 error
  91. */
  92. my_bool ma_tls_close(MARIADB_TLS *ctls);
  93. /* ma_tls_verify_server_cert
  94. validation check of server certificate
  95. Parameter:
  96. MARIADB_TLS MariaDB SSL container
  97. Returns:
  98. ß success
  99. 1 error
  100. */
  101. int ma_tls_verify_server_cert(MARIADB_TLS *ctls);
  102. /* ma_tls_get_cipher
  103. returns cipher for current ssl connection
  104. Parameter:
  105. MARIADB_TLS MariaDB SSL container
  106. Returns:
  107. cipher in use or
  108. NULL on error
  109. */
  110. const char *ma_tls_get_cipher(MARIADB_TLS *ssl);
  111. /* ma_tls_get_finger_print
  112. returns SHA1 finger print of server certificate
  113. Parameter:
  114. MARIADB_TLS MariaDB SSL container
  115. fp buffer for fingerprint
  116. fp_len buffer length
  117. Returns:
  118. actual size of finger print
  119. */
  120. unsigned int ma_tls_get_finger_print(MARIADB_TLS *ctls, char *fp, unsigned int fp_len);
  121. /* ma_tls_get_protocol_version
  122. returns protocol version number in use
  123. Parameter:
  124. MARIADB_TLS MariaDB SSL container
  125. Returns:
  126. protocol number
  127. */
  128. int ma_tls_get_protocol_version(MARIADB_TLS *ctls);
  129. const char *ma_pvio_tls_get_protocol_version(MARIADB_TLS *ctls);
  130. int ma_pvio_tls_get_protocol_version_id(MARIADB_TLS *ctls);
  131. /* Function prototypes */
  132. MARIADB_TLS *ma_pvio_tls_init(MYSQL *mysql);
  133. my_bool ma_pvio_tls_connect(MARIADB_TLS *ctls);
  134. ssize_t ma_pvio_tls_read(MARIADB_TLS *ctls, const uchar *buffer, size_t length);
  135. ssize_t ma_pvio_tls_write(MARIADB_TLS *ctls, const uchar *buffer, size_t length);
  136. my_bool ma_pvio_tls_close(MARIADB_TLS *ctls);
  137. int ma_pvio_tls_verify_server_cert(MARIADB_TLS *ctls);
  138. const char *ma_pvio_tls_cipher(MARIADB_TLS *ctls);
  139. my_bool ma_pvio_tls_check_fp(MARIADB_TLS *ctls, const char *fp, const char *fp_list);
  140. my_bool ma_pvio_start_ssl(MARIADB_PVIO *pvio);
  141. void ma_pvio_tls_end();
  142. #endif /* _ma_tls_h_ */