sslopt-vars.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License, version 2.0,
  4. as published by the Free Software Foundation.
  5. This program is also distributed with certain software (including
  6. but not limited to OpenSSL) that is licensed under separate terms,
  7. as designated in a particular file or component or in included license
  8. documentation. The authors of MySQL hereby grant you an additional
  9. permission to link the program and your derivative works with the
  10. separately licensed software that they have included with MySQL.
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU General Public License, version 2.0, for more details.
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
  18. #ifndef SSLOPT_VARS_INCLUDED
  19. #define SSLOPT_VARS_INCLUDED
  20. #if defined(HAVE_OPENSSL) && !defined(EMBEDDED_LIBRARY)
  21. #ifndef MYSQL_CLIENT
  22. #error This header is supposed to be used only in the client
  23. #endif
  24. const char *ssl_mode_names_lib[] =
  25. {"DISABLED", "PREFERRED", "REQUIRED", "VERIFY_CA", "VERIFY_IDENTITY",
  26. NullS };
  27. TYPELIB ssl_mode_typelib = {array_elements(ssl_mode_names_lib) - 1, "",
  28. ssl_mode_names_lib, NULL};
  29. static uint opt_ssl_mode = SSL_MODE_PREFERRED;
  30. static char *opt_ssl_ca = 0;
  31. static char *opt_ssl_capath = 0;
  32. static char *opt_ssl_cert = 0;
  33. static char *opt_ssl_cipher = 0;
  34. static char *opt_ssl_key = 0;
  35. static char *opt_ssl_crl = 0;
  36. static char *opt_ssl_crlpath = 0;
  37. static char *opt_tls_version = 0;
  38. static my_bool ssl_mode_set_explicitly= FALSE;
  39. static my_bool opt_use_ssl_arg= TRUE;
  40. static my_bool opt_ssl_verify_server_cert_arg= FALSE;
  41. static void set_client_ssl_options(MYSQL *mysql)
  42. {
  43. /*
  44. Print a warning if explicitly defined combination of --ssl-mode other than
  45. VERIFY_CA or VERIFY_IDENTITY with explicit --ssl-ca or --ssl-capath values.
  46. */
  47. if (ssl_mode_set_explicitly &&
  48. opt_ssl_mode < SSL_MODE_VERIFY_CA &&
  49. (opt_ssl_ca || opt_ssl_capath))
  50. {
  51. fprintf(stderr, "WARNING: no verification of server certificate will be done. "
  52. "Use --ssl-mode=VERIFY_CA or VERIFY_IDENTITY.\n");
  53. }
  54. /* Set SSL parameters: key, cert, ca, capath, cipher, clr, clrpath. */
  55. if (opt_ssl_mode >= SSL_MODE_VERIFY_CA)
  56. mysql_ssl_set(mysql, opt_ssl_key, opt_ssl_cert, opt_ssl_ca,
  57. opt_ssl_capath, opt_ssl_cipher);
  58. else
  59. mysql_ssl_set(mysql, opt_ssl_key, opt_ssl_cert, NULL,
  60. NULL, opt_ssl_cipher);
  61. mysql_options(mysql, MYSQL_OPT_SSL_CRL, opt_ssl_crl);
  62. mysql_options(mysql, MYSQL_OPT_SSL_CRLPATH, opt_ssl_crlpath);
  63. mysql_options(mysql, MYSQL_OPT_TLS_VERSION, opt_tls_version);
  64. mysql_options(mysql, MYSQL_OPT_SSL_MODE, &opt_ssl_mode);
  65. }
  66. #define SSL_SET_OPTIONS(mysql) set_client_ssl_options(mysql);
  67. #else
  68. #define SSL_SET_OPTIONS(mysql) do { } while(0)
  69. #endif
  70. #endif /* SSLOPT_VARS_INCLUDED */