ma_tls.h 4.0 KB

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