1 /*
2  * Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License, version 2.0,
6  * as published by the Free Software Foundation.
7  *
8  * This program is also distributed with certain software (including
9  * but not limited to OpenSSL) that is licensed under separate terms,
10  * as designated in a particular file or component or in included license
11  * documentation.  The authors of MySQL hereby grant you an additional
12  * permission to link the program and your derivative works with the
13  * separately licensed software that they have included with MySQL.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License, version 2.0, for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
23  */
24 
25 #ifndef PLUGIN_X_SRC_SERVER_BUILDER_SSL_CONTEXT_BUILDER_H_
26 #define PLUGIN_X_SRC_SERVER_BUILDER_SSL_CONTEXT_BUILDER_H_
27 
28 #include <memory>
29 #include <string>
30 
31 #include "plugin/x/src/interface/ssl_context.h"
32 #include "plugin/x/src/variables/ssl_config.h"
33 
34 namespace xpl {
35 
36 class Ssl_context_builder {
37  public:
Ssl_context_builder()38   Ssl_context_builder() {}
39 
40   std::unique_ptr<iface::Ssl_context> get_result_context() const;
41 
42  private:
43   struct Ssl_config_local {
44     std::string m_ssl_key;
45     std::string m_ssl_ca;
46     std::string m_ssl_capath;
47     std::string m_ssl_cert;
48     std::string m_ssl_cipher;
49     std::string m_ssl_crl;
50     std::string m_ssl_crlpath;
51     std::string m_ssl_tls_version;
52     bool m_have_ssl = false;
53   };
54 
55   xpl::Ssl_config choose_ssl_config(const bool mysqld_have_ssl,
56                                     const xpl::Ssl_config &mysqld_ssl,
57                                     const xpl::Ssl_config &mysqlx_ssl) const;
58   Ssl_config_local get_mysqld_ssl_config() const;
59   void setup_ssl_context(iface::Ssl_context *ssl_context) const;
60 };
61 
62 }  // namespace xpl
63 
64 #endif  // PLUGIN_X_SRC_SERVER_BUILDER_SSL_CONTEXT_BUILDER_H_
65