1 /*
2  * Copyright (c) 2015, 2021, Oracle and/or its affiliates.
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
23  * 02110-1301  USA
24  */
25 
26 #ifndef _NGS_ASIO_OPTIONS_H_
27 #define _NGS_ASIO_OPTIONS_H_
28 
29 #include <string>
30 #include <vector>
31 #include "ngs_common/smart_ptr.h"
32 
33 
34 namespace ngs
35 {
36 
37   class IOptions_session
38   {
39   public:
~IOptions_session()40     virtual ~IOptions_session() {};
41 
42     virtual bool supports_tls() = 0;
43     virtual bool active_tls() = 0;
44 
45     virtual std::string ssl_cipher() = 0;
46     virtual std::vector<std::string> ssl_cipher_list() = 0;
47 
48     virtual std::string ssl_version() = 0;
49 
50     virtual long ssl_verify_depth() = 0;
51     virtual long ssl_verify_mode() = 0;
52     virtual long ssl_sessions_reused() = 0;
53 
54     virtual long ssl_get_verify_result_and_cert() = 0;
55     virtual std::string ssl_get_peer_certificate_issuer() = 0;
56     virtual std::string ssl_get_peer_certificate_subject() = 0;
57   };
58 
59   class Options_session_default : public IOptions_session
60   {
61   public:
supports_tls()62     bool supports_tls() { return false; };
active_tls()63     bool active_tls() { return false; };
ssl_cipher()64     std::string ssl_cipher() { return ""; };
ssl_cipher_list()65     std::vector<std::string> ssl_cipher_list() { return std::vector<std::string>(); };
ssl_version()66     std::string ssl_version() { return ""; };
67 
ssl_ctx_verify_depth()68     long ssl_ctx_verify_depth() { return 0; }
ssl_ctx_verify_mode()69     long ssl_ctx_verify_mode() { return 0; }
ssl_verify_depth()70     long ssl_verify_depth() { return 0; }
ssl_verify_mode()71     long ssl_verify_mode() { return 0; }
72 
ssl_server_not_after()73     std::string ssl_server_not_after() { return ""; }
ssl_server_not_before()74     std::string ssl_server_not_before() { return ""; }
ssl_sessions_reused()75     long ssl_sessions_reused() { return 0; }
ssl_get_verify_result_and_cert()76     long ssl_get_verify_result_and_cert() { return 0; }
ssl_get_peer_certificate_issuer()77     std::string ssl_get_peer_certificate_issuer()  { return ""; }
ssl_get_peer_certificate_subject()78     std::string ssl_get_peer_certificate_subject() { return ""; }
79   };
80 
81   class IOptions_context
82   {
83   public:
~IOptions_context()84     virtual ~IOptions_context() {};
85 
86     virtual long ssl_ctx_verify_depth() = 0;
87     virtual long ssl_ctx_verify_mode() = 0;
88 
89     virtual std::string ssl_server_not_after() = 0;
90     virtual std::string ssl_server_not_before() = 0;
91 
92     virtual long ssl_sess_accept_good() = 0;
93     virtual long ssl_sess_accept() = 0;
94     virtual long ssl_accept_renegotiates() = 0;
95 
96     virtual std::string ssl_session_cache_mode() = 0;
97 
98     virtual long ssl_session_cache_hits() = 0;
99     virtual long ssl_session_cache_misses() = 0;
100     virtual long ssl_session_cache_overflows() = 0;
101     virtual long ssl_session_cache_size() = 0;
102     virtual long ssl_session_cache_timeouts() = 0;
103     virtual long ssl_used_session_cache_entries() = 0;
104   };
105 
106   class Options_context_default : public IOptions_context
107   {
108   public:
ssl_ctx_verify_depth()109     virtual long ssl_ctx_verify_depth() { return 0; }
ssl_ctx_verify_mode()110     virtual long ssl_ctx_verify_mode() { return 0; }
111 
ssl_server_not_after()112     virtual std::string ssl_server_not_after() { return ""; }
ssl_server_not_before()113     virtual std::string ssl_server_not_before() { return ""; }
114 
ssl_sess_accept_good()115     virtual long ssl_sess_accept_good() { return 0; }
ssl_sess_accept()116     virtual long ssl_sess_accept() { return 0; }
ssl_accept_renegotiates()117     virtual long ssl_accept_renegotiates() { return 0; }
118 
ssl_session_cache_mode()119     virtual std::string ssl_session_cache_mode() { return ""; }
120 
ssl_session_cache_hits()121     virtual long ssl_session_cache_hits() { return 0; }
ssl_session_cache_misses()122     virtual long ssl_session_cache_misses() { return 0; }
ssl_session_cache_overflows()123     virtual long ssl_session_cache_overflows() { return 0; }
ssl_session_cache_size()124     virtual long ssl_session_cache_size() { return 0; }
ssl_session_cache_timeouts()125     virtual long ssl_session_cache_timeouts() { return 0; }
ssl_used_session_cache_entries()126     virtual long ssl_used_session_cache_entries() { return 0; }
127   };
128 
129   typedef ngs::shared_ptr<IOptions_session> IOptions_session_ptr;
130   typedef ngs::shared_ptr<IOptions_context> IOptions_context_ptr;
131 
132 } // namespace ngs
133 
134 #endif // _NGS_ASIO_OPTIONS_H_
135