2019-03-16 02:08:21 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Poco/Net/TCPServerConnectionFactory.h>
|
2019-05-26 06:52:29 +00:00
|
|
|
#include <atomic>
|
2020-05-27 17:52:52 +00:00
|
|
|
#include <memory>
|
|
|
|
#include <Server/IServer.h>
|
2020-04-16 12:31:57 +00:00
|
|
|
|
|
|
|
#if !defined(ARCADIA_BUILD)
|
|
|
|
# include <Common/config.h>
|
|
|
|
#endif
|
|
|
|
|
2019-11-02 10:20:46 +00:00
|
|
|
#if USE_SSL
|
2020-04-16 12:31:57 +00:00
|
|
|
# include <openssl/rsa.h>
|
2019-11-02 10:20:46 +00:00
|
|
|
#endif
|
2019-03-16 02:08:21 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2019-04-29 06:37:39 +00:00
|
|
|
class MySQLHandlerFactory : public Poco::Net::TCPServerConnectionFactory
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
IServer & server;
|
|
|
|
Poco::Logger * log;
|
|
|
|
|
2019-11-02 10:20:46 +00:00
|
|
|
#if USE_SSL
|
2019-05-26 19:30:23 +00:00
|
|
|
struct RSADeleter
|
|
|
|
{
|
2019-05-26 06:52:29 +00:00
|
|
|
void operator()(RSA * ptr) { RSA_free(ptr); }
|
|
|
|
};
|
|
|
|
using RSAPtr = std::unique_ptr<RSA, RSADeleter>;
|
2019-04-22 10:57:50 +00:00
|
|
|
|
2019-05-26 06:52:29 +00:00
|
|
|
RSAPtr public_key;
|
|
|
|
RSAPtr private_key;
|
2019-03-16 02:08:21 +00:00
|
|
|
|
2019-05-26 06:52:29 +00:00
|
|
|
bool ssl_enabled = true;
|
2019-11-02 10:20:46 +00:00
|
|
|
#else
|
|
|
|
bool ssl_enabled = false;
|
|
|
|
#endif
|
2019-04-22 10:57:50 +00:00
|
|
|
|
2019-05-26 06:52:29 +00:00
|
|
|
std::atomic<size_t> last_connection_id = 0;
|
|
|
|
public:
|
|
|
|
explicit MySQLHandlerFactory(IServer & server_);
|
2019-04-29 06:37:39 +00:00
|
|
|
|
2019-05-26 06:52:29 +00:00
|
|
|
void readRSAKeys();
|
2019-04-29 06:37:39 +00:00
|
|
|
|
2019-05-26 06:52:29 +00:00
|
|
|
void generateRSAKeys();
|
2019-04-29 06:37:39 +00:00
|
|
|
|
2019-05-26 06:52:29 +00:00
|
|
|
Poco::Net::TCPServerConnection * createConnection(const Poco::Net::StreamSocket & socket) override;
|
2019-04-29 06:37:39 +00:00
|
|
|
};
|
2019-03-16 02:08:21 +00:00
|
|
|
|
|
|
|
}
|