2019-03-16 02:08:21 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Poco/Net/TCPServerConnection.h>
|
2019-04-29 06:05:30 +00:00
|
|
|
#include <Poco/Net/SecureStreamSocket.h>
|
2019-03-16 02:08:21 +00:00
|
|
|
#include <Common/getFQDNOrHostName.h>
|
2019-03-26 18:30:41 +00:00
|
|
|
#include <Core/MySQLProtocol.h>
|
2019-04-22 10:57:50 +00:00
|
|
|
#include <openssl/evp.h>
|
2019-03-16 02:08:21 +00:00
|
|
|
#include "IServer.h"
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
/// Handler for MySQL wire protocol connections. Allows to connect to ClickHouse using MySQL client.
|
2019-04-01 09:59:49 +00:00
|
|
|
class MySQLHandler : public Poco::Net::TCPServerConnection
|
|
|
|
{
|
2019-03-16 02:08:21 +00:00
|
|
|
public:
|
2019-04-22 10:57:50 +00:00
|
|
|
MySQLHandler(
|
|
|
|
IServer & server_,
|
|
|
|
const Poco::Net::StreamSocket & socket_,
|
|
|
|
RSA * public_key,
|
|
|
|
RSA * private_key)
|
|
|
|
: Poco::Net::TCPServerConnection(socket_)
|
|
|
|
, server(server_)
|
|
|
|
, log(&Poco::Logger::get("MySQLHandler"))
|
|
|
|
, connection_context(server.context())
|
|
|
|
, connection_id(last_connection_id++)
|
|
|
|
, public_key(public_key)
|
|
|
|
, private_key(private_key)
|
2019-03-16 02:08:21 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void run() final;
|
|
|
|
|
2019-04-22 10:57:50 +00:00
|
|
|
private:
|
2019-04-29 06:05:30 +00:00
|
|
|
/// Enables SSL, if client requested.
|
|
|
|
MySQLProtocol::HandshakeResponse finishHandshake();
|
|
|
|
|
2019-03-26 18:30:41 +00:00
|
|
|
void comQuery(String payload);
|
2019-03-16 02:08:21 +00:00
|
|
|
|
2019-03-26 18:30:41 +00:00
|
|
|
void comFieldList(String payload);
|
2019-03-16 02:08:21 +00:00
|
|
|
|
|
|
|
void comPing();
|
|
|
|
|
2019-03-26 18:30:41 +00:00
|
|
|
void comInitDB(String payload);
|
2019-04-01 09:59:49 +00:00
|
|
|
|
2019-04-22 10:57:50 +00:00
|
|
|
static String generateScramble();
|
|
|
|
|
|
|
|
void authenticate(const MySQLProtocol::HandshakeResponse &, const String & scramble);
|
|
|
|
|
2019-03-16 02:08:21 +00:00
|
|
|
IServer & server;
|
|
|
|
Poco::Logger * log;
|
|
|
|
Context connection_context;
|
|
|
|
|
2019-03-26 18:30:41 +00:00
|
|
|
MySQLProtocol::PacketSender packet_sender;
|
2019-03-16 02:08:21 +00:00
|
|
|
|
|
|
|
uint32_t connection_id = 0;
|
|
|
|
|
|
|
|
uint32_t capabilities;
|
|
|
|
|
|
|
|
static uint32_t last_connection_id;
|
2019-04-22 10:57:50 +00:00
|
|
|
|
|
|
|
RSA * public_key, * private_key;
|
2019-04-29 06:05:30 +00:00
|
|
|
|
|
|
|
std::shared_ptr<ReadBuffer> in;
|
|
|
|
std::shared_ptr<WriteBuffer> out;
|
|
|
|
|
|
|
|
bool secure_connection = false;
|
|
|
|
std::shared_ptr<Poco::Net::SecureStreamSocket> ss;
|
2019-03-16 02:08:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|