-
Notifications
You must be signed in to change notification settings - Fork 9k
Expand file tree
/
Copy pathMySQLHandlerFactory.cpp
More file actions
87 lines (74 loc) · 2.4 KB
/
Copy pathMySQLHandlerFactory.cpp
File metadata and controls
87 lines (74 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <Server/MySQLHandlerFactory.h>
#include <Common/logger_useful.h>
#include <Server/MySQLHandler.h>
#include <base/scope_guard.h>
#if USE_SSL
# include <Poco/Net/SSLManager.h>
# include <Common/OpenSSLHelpers.h>
#endif
#include <Poco/Net/TCPServerConnectionFactory.h>
#include <Poco/Util/Application.h>
namespace DB
{
MySQLHandlerFactory::MySQLHandlerFactory(
IServer & server_,
bool secure_required_,
const ProfileEvents::Event & read_event_,
const ProfileEvents::Event & write_event_,
std::optional<String> default_session_user_)
: server(server_)
, log(getLogger("MySQLHandlerFactory"))
#if USE_SSL
, keypair(KeyPair::generateRSA())
#endif
, secure_required(secure_required_)
, default_session_user(std::move(default_session_user_))
, read_event(read_event_)
, write_event(write_event_)
{
#if USE_SSL
try
{
Poco::Net::SSLManager::instance().defaultServerContext();
}
catch (...)
{
LOG_TRACE(log, "Failed to create SSL context. SSL will be disabled. Error: {}", getCurrentExceptionMessage(false));
ssl_enabled = false;
}
/// Reading RSA keys for SHA256 authentication plugin.
try
{
const Poco::Util::LayeredConfiguration & config = Poco::Util::Application::instance().config();
String private_key_file_property = "openSSL.server.privateKeyFile";
String private_key_file = config.getString(private_key_file_property);
keypair = KeyPair::fromFile(private_key_file);
}
catch (...)
{
LOG_TRACE(log, "Failed to read RSA key pair from server certificate. Error: {}", getCurrentExceptionMessage(false));
LOG_TRACE(log, "Generating new RSA key pair.");
keypair = KeyPair::generateRSA();
}
#endif
}
Poco::Net::TCPServerConnection * MySQLHandlerFactory::createConnectionImpl(const Poco::Net::StreamSocket & socket, TCPServer & tcp_server)
{
uint32_t connection_id = last_connection_id++;
LOG_TRACE(log, "MySQL connection. Id: {}. Address: {}", connection_id, socket.peerAddress().toString());
#if USE_SSL
return new MySQLHandlerSSL(
server,
tcp_server,
socket,
ssl_enabled,
secure_required,
connection_id,
default_session_user,
keypair
);
#else
return new MySQLHandler(server, tcp_server, socket, ssl_enabled, secure_required, connection_id, default_session_user);
#endif
}
}