MXS-2483: Rename SSL_LISTENER to mxs::SSLContext

This commit is contained in:
Markus Mäkelä
2019-05-17 15:47:34 +03:00
parent 650230455a
commit cab336ed89
13 changed files with 52 additions and 52 deletions

View File

@ -144,9 +144,9 @@ public:
const char* state() const; const char* state() const;
/** /**
* The SSL_LISTENER object * The mxs::SSLContext object
*/ */
SSL_LISTENER* ssl() const; mxs::SSLContext* ssl() const;
/** /**
* Convert to JSON * Convert to JSON
@ -209,7 +209,7 @@ private:
std::string m_authenticator; /**< Name of authenticator */ std::string m_authenticator; /**< Name of authenticator */
std::string m_auth_options; /**< Authenticator options */ std::string m_auth_options; /**< Authenticator options */
void* m_auth_instance; /**< Authenticator instance */ void* m_auth_instance; /**< Authenticator instance */
SSL_LISTENER* m_ssl; /**< Structure of SSL data or NULL */ mxs::SSLContext* m_ssl; /**< Structure of SSL data or NULL */
struct users* m_users; /**< The user data for this listener */ struct users* m_users; /**< The user data for this listener */
SERVICE* m_service; /**< The service which used by this listener */ SERVICE* m_service; /**< The service which used by this listener */
std::atomic<bool> m_active; /**< True if the port has not been deleted */ std::atomic<bool> m_active; /**< True if the port has not been deleted */
@ -249,7 +249,7 @@ private:
*/ */
Listener(SERVICE* service, const std::string& name, const std::string& address, uint16_t port, Listener(SERVICE* service, const std::string& name, const std::string& address, uint16_t port,
const std::string& protocol, const std::string& authenticator, const std::string& protocol, const std::string& authenticator,
const std::string& auth_opts, void* auth_instance, SSL_LISTENER* ssl, const std::string& auth_opts, void* auth_instance, mxs::SSLContext* ssl,
const MXS_CONFIG_PARAMETER& params); const MXS_CONFIG_PARAMETER& params);
/** /**

View File

@ -182,7 +182,7 @@ public:
// Base variables // Base variables
bool is_active = false; /**< Server is active and has not been "destroyed" */ bool is_active = false; /**< Server is active and has not been "destroyed" */
SSL_LISTENER* server_ssl = nullptr; /**< SSL data */ mxs::SSLContext* server_ssl = nullptr; /**< SSL data */
uint8_t charset = DEFAULT_CHARSET; /**< Character set. Read from backend and sent to client. */ uint8_t charset = DEFAULT_CHARSET; /**< Character set. Read from backend and sent to client. */
// Statistics and events // Statistics and events

View File

@ -49,11 +49,14 @@ enum ssl_method_type_t
#define SSL_ERROR_CLIENT_NOT_SSL 1 #define SSL_ERROR_CLIENT_NOT_SSL 1
#define SSL_ERROR_ACCEPT_FAILED 2 #define SSL_ERROR_ACCEPT_FAILED 2
namespace maxscale
{
/** /**
* The ssl_listener structure is used to aggregate the SSL configuration items * The ssl_listener structure is used to aggregate the SSL configuration items
* and data for a particular listener * and data for a particular listener
*/ */
struct SSL_LISTENER struct SSLContext
{ {
SSL_CTX* ctx; SSL_CTX* ctx;
SSL_METHOD* method; /**< SSLv3 or TLS1.0/1.1/1.2 methods SSL_METHOD* method; /**< SSLv3 or TLS1.0/1.1/1.2 methods
@ -67,9 +70,8 @@ struct SSL_LISTENER
char* ssl_ca_cert; /**< SSL CA certificate */ char* ssl_ca_cert; /**< SSL CA certificate */
bool ssl_init_done; /**< If SSL has already been initialized for this service */ bool ssl_init_done; /**< If SSL has already been initialized for this service */
bool ssl_verify_peer_certificate; /**< Enable peer certificate verification */ bool ssl_verify_peer_certificate; /**< Enable peer certificate verification */
SSL_LISTENER* next; /**< Next SSL configuration, currently used to store obsolete configurations */
}; };
}
int ssl_authenticate_client(DCB* dcb, bool is_capable); int ssl_authenticate_client(DCB* dcb, bool is_capable);
bool ssl_is_connection_healthy(DCB* dcb); bool ssl_is_connection_healthy(DCB* dcb);
@ -92,7 +94,7 @@ ssl_method_type_t string_to_ssl_method_type(const char* str);
int ssl_authenticate_check_status(DCB* dcb); int ssl_authenticate_check_status(DCB* dcb);
// TODO: Move this to an internal ssl.h header // TODO: Move this to an internal ssl.h header
void write_ssl_config(int fd, SSL_LISTENER* ssl); void write_ssl_config(int fd, mxs::SSLContext* ssl);
/** /**
* Set the maximum SSL/TLS version the listener will support * Set the maximum SSL/TLS version the listener will support
@ -102,7 +104,7 @@ void write_ssl_config(int fd, SSL_LISTENER* ssl);
* *
* @return 0 on success, -1 on invalid version string * @return 0 on success, -1 on invalid version string
*/ */
int listener_set_ssl_version(SSL_LISTENER* ssl_listener, const char* version); int listener_set_ssl_version(mxs::SSLContext* ssl_listener, const char* version);
/** /**
* Set the locations of the listener's SSL certificate, listener's private key * Set the locations of the listener's SSL certificate, listener's private key
@ -113,7 +115,7 @@ int listener_set_ssl_version(SSL_LISTENER* ssl_listener, const char* version);
* @param key SSL private key * @param key SSL private key
* @param ca_cert SSL CA certificate * @param ca_cert SSL CA certificate
*/ */
void listener_set_certificates(SSL_LISTENER* ssl_listener, const std::string& cert, void listener_set_certificates(mxs::SSLContext* ssl_listener, const std::string& cert,
const std::string& key, const std::string& ca_cert); const std::string& key, const std::string& ca_cert);
/** /**
@ -131,11 +133,11 @@ void listener_set_certificates(SSL_LISTENER* ssl_listener, const std::string& ce
* *
* @return True on success, false on error * @return True on success, false on error
*/ */
bool SSL_LISTENER_init(SSL_LISTENER* ssl); bool SSL_LISTENER_init(mxs::SSLContext* ssl);
/** /**
* Free an SSL_LISTENER * Free an SSL_LISTENER
* *
* @param ssl SSL_LISTENER to free * @param ssl mxs::SSLContext to free
*/ */
void SSL_LISTENER_free(SSL_LISTENER* ssl); void SSL_LISTENER_free(mxs::SSLContext* ssl);

View File

@ -2874,7 +2874,7 @@ bool config_can_modify_at_runtime(const char* name)
* *
* @param ssl SSL structure to free * @param ssl SSL structure to free
*/ */
static void free_ssl_structure(SSL_LISTENER* ssl) static void free_ssl_structure(mxs::SSLContext* ssl)
{ {
if (ssl) if (ssl)
{ {
@ -2889,9 +2889,9 @@ static void free_ssl_structure(SSL_LISTENER* ssl)
bool config_create_ssl(const char* name, bool config_create_ssl(const char* name,
const MXS_CONFIG_PARAMETER& params, const MXS_CONFIG_PARAMETER& params,
bool require_cert, bool require_cert,
SSL_LISTENER** dest) mxs::SSLContext** dest)
{ {
SSL_LISTENER* ssl = NULL; mxs::SSLContext* ssl = NULL;
// The enum values convert to bool // The enum values convert to bool
int value = params.get_enum(CN_SSL, ssl_values); int value = params.get_enum(CN_SSL, ssl_values);
@ -2939,7 +2939,7 @@ bool config_create_ssl(const char* name,
return false; return false;
} }
ssl = (SSL_LISTENER*)MXS_CALLOC(1, sizeof(SSL_LISTENER)); ssl = (mxs::SSLContext*)MXS_CALLOC(1, sizeof(mxs::SSLContext));
MXS_ABORT_IF_NULL(ssl); MXS_ABORT_IF_NULL(ssl);
int ssl_version = params.get_enum(CN_SSL_VERSION, ssl_version_values); int ssl_version = params.get_enum(CN_SSL_VERSION, ssl_version_values);

View File

@ -394,7 +394,7 @@ bool runtime_destroy_server(Server* server)
return rval; return rval;
} }
static SSL_LISTENER* create_ssl(const char* name, static mxs::SSLContext* create_ssl(const char* name,
const char* key, const char* key,
const char* cert, const char* cert,
const char* ca, const char* ca,
@ -402,7 +402,7 @@ static SSL_LISTENER* create_ssl(const char* name,
const char* depth, const char* depth,
const char* verify) const char* verify)
{ {
SSL_LISTENER* rval = NULL; mxs::SSLContext* rval = NULL;
CONFIG_CONTEXT* obj = config_context_create(name); CONFIG_CONTEXT* obj = config_context_create(name);
if (obj) if (obj)
@ -437,13 +437,11 @@ bool runtime_enable_server_ssl(Server* server,
if (key && cert && ca) if (key && cert && ca)
{ {
std::lock_guard<std::mutex> guard(crt_lock); std::lock_guard<std::mutex> guard(crt_lock);
SSL_LISTENER* ssl = create_ssl(server->name(), key, cert, ca, version, depth, verify); mxs::SSLContext* ssl = create_ssl(server->name(), key, cert, ca, version, depth, verify);
if (ssl) if (ssl)
{ {
/** TODO: Properly discard old SSL configurations.This could cause the // TODO: Properly discard old SSL configurations
* loss of a pointer if two update operations are done at the same time.*/
ssl->next = server->server_ssl;
/** Sync to prevent reads on partially initialized server_ssl */ /** Sync to prevent reads on partially initialized server_ssl */
atomic_synchronize(); atomic_synchronize();

View File

@ -101,7 +101,7 @@ static void dcb_stop_polling_and_shutdown(DCB* dcb);
static bool dcb_maybe_add_persistent(DCB*); static bool dcb_maybe_add_persistent(DCB*);
static inline bool dcb_write_parameter_check(DCB* dcb, GWBUF* queue); static inline bool dcb_write_parameter_check(DCB* dcb, GWBUF* queue);
static int dcb_read_no_bytes_available(DCB* dcb, int nreadtotal); static int dcb_read_no_bytes_available(DCB* dcb, int nreadtotal);
static int dcb_create_SSL(DCB* dcb, SSL_LISTENER* ssl); static int dcb_create_SSL(DCB* dcb, mxs::SSLContext* ssl);
static int dcb_read_SSL(DCB* dcb, GWBUF** head); static int dcb_read_SSL(DCB* dcb, GWBUF** head);
static GWBUF* dcb_basic_read(DCB* dcb, static GWBUF* dcb_basic_read(DCB* dcb,
int bytesavailable, int bytesavailable,
@ -2118,7 +2118,7 @@ int dcb_count_by_usage(DCB_USAGE usage)
* @param dcb * @param dcb
* @return -1 on error, 0 otherwise. * @return -1 on error, 0 otherwise.
*/ */
static int dcb_create_SSL(DCB* dcb, SSL_LISTENER* ssl) static int dcb_create_SSL(DCB* dcb, mxs::SSLContext* ssl)
{ {
if ((dcb->ssl = SSL_new(ssl->ctx)) == NULL) if ((dcb->ssl = SSL_new(ssl->ctx)) == NULL)
{ {

View File

@ -142,7 +142,7 @@ void config_remove_param(CONFIG_CONTEXT* obj, const char* name);
bool config_create_ssl(const char* name, bool config_create_ssl(const char* name,
const MXS_CONFIG_PARAMETER& params, const MXS_CONFIG_PARAMETER& params,
bool require_cert, bool require_cert,
SSL_LISTENER** dest); mxs::SSLContext** dest);
/** /**
* @brief Check if all SSL parameters are defined * @brief Check if all SSL parameters are defined

View File

@ -105,7 +105,7 @@ Listener::Listener(SERVICE* service,
const std::string& authenticator, const std::string& authenticator,
const std::string& auth_opts, const std::string& auth_opts,
void* auth_instance, void* auth_instance,
SSL_LISTENER* ssl, mxs::SSLContext* ssl,
const MXS_CONFIG_PARAMETER& params) const MXS_CONFIG_PARAMETER& params)
: MXB_POLL_DATA{Listener::poll_handler} : MXB_POLL_DATA{Listener::poll_handler}
, m_name(name) , m_name(name)
@ -209,7 +209,7 @@ SListener Listener::create(const std::string& name,
return nullptr; return nullptr;
} }
SSL_LISTENER* ssl_info = NULL; mxs::SSLContext* ssl_info = NULL;
if (!config_create_ssl(name.c_str(), params, true, &ssl_info)) if (!config_create_ssl(name.c_str(), params, true, &ssl_info))
{ {
@ -618,7 +618,7 @@ void* Listener::auth_instance() const
return m_auth_instance; return m_auth_instance;
} }
SSL_LISTENER* Listener::ssl() const mxs::SSLContext* Listener::ssl() const
{ {
return m_ssl; return m_ssl;
} }

View File

@ -155,7 +155,7 @@ char* mxs_lestr_consume(uint8_t** c, size_t* size)
MYSQL* mxs_mysql_real_connect(MYSQL* con, SERVER* server, const char* user, const char* passwd) MYSQL* mxs_mysql_real_connect(MYSQL* con, SERVER* server, const char* user, const char* passwd)
{ {
SSL_LISTENER* listener = server->server_ssl; mxs::SSLContext* listener = server->server_ssl;
if (listener) if (listener)
{ {

View File

@ -195,7 +195,7 @@ Server* Server::server_alloc(const char* name, const MXS_CONFIG_PARAMETER& param
return NULL; return NULL;
} }
SSL_LISTENER* ssl = NULL; mxs::SSLContext* ssl = NULL;
if (!config_create_ssl(name, params, false, &ssl)) if (!config_create_ssl(name, params, false, &ssl))
{ {
@ -528,7 +528,7 @@ void Server::print_to_dcb(DCB* dcb) const
} }
if (server->server_ssl) if (server->server_ssl)
{ {
SSL_LISTENER* l = server->server_ssl; mxs::SSLContext* l = server->server_ssl;
dcb_printf(dcb, dcb_printf(dcb,
"\tSSL initialized: %s\n", "\tSSL initialized: %s\n",
l->ssl_init_done ? "yes" : "no"); l->ssl_init_done ? "yes" : "no");

View File

@ -254,7 +254,7 @@ ssl_method_type_t string_to_ssl_method_type(const char* str)
return SERVICE_SSL_UNKNOWN; return SERVICE_SSL_UNKNOWN;
} }
void write_ssl_config(int fd, SSL_LISTENER* ssl) void write_ssl_config(int fd, mxs::SSLContext* ssl)
{ {
if (ssl) if (ssl)
{ {
@ -320,7 +320,7 @@ int ssl_authenticate_check_status(DCB* dcb)
return rval; return rval;
} }
int listener_set_ssl_version(SSL_LISTENER* ssl_listener, const char* version) int listener_set_ssl_version(mxs::SSLContext* ssl_listener, const char* version)
{ {
if (strcasecmp(version, "MAX") == 0) if (strcasecmp(version, "MAX") == 0)
{ {
@ -350,7 +350,7 @@ int listener_set_ssl_version(SSL_LISTENER* ssl_listener, const char* version)
return 0; return 0;
} }
void listener_set_certificates(SSL_LISTENER* ssl_listener, const std::string& cert, void listener_set_certificates(mxs::SSLContext* ssl_listener, const std::string& cert,
const std::string& key, const std::string& ca_cert) const std::string& key, const std::string& ca_cert)
{ {
MXS_FREE(ssl_listener->ssl_cert); MXS_FREE(ssl_listener->ssl_cert);
@ -449,7 +449,7 @@ static RSA* tmp_rsa_callback(SSL* s, int is_export, int keylength)
return rsa_tmp; return rsa_tmp;
} }
bool SSL_LISTENER_init(SSL_LISTENER* ssl) bool SSL_LISTENER_init(mxs::SSLContext* ssl)
{ {
mxb_assert(!ssl->ssl_init_done); mxb_assert(!ssl->ssl_init_done);
bool rval = true; bool rval = true;
@ -584,7 +584,7 @@ bool SSL_LISTENER_init(SSL_LISTENER* ssl)
return rval; return rval;
} }
void SSL_LISTENER_free(SSL_LISTENER* ssl) void SSL_LISTENER_free(mxs::SSLContext* ssl)
{ {
if (ssl) if (ssl)
{ {

View File

@ -825,10 +825,10 @@ static MXS_ROUTER* createInstance(SERVICE* service, MXS_CONFIG_PARAMETER* params
return NULL; return NULL;
} }
SSL_LISTENER* ssl_cfg; mxs::SSLContext* ssl_cfg;
/* Allocate SSL struct for backend connection */ /* Allocate SSL struct for backend connection */
if ((ssl_cfg = if ((ssl_cfg =
static_cast<SSL_LISTENER*>(MXS_CALLOC(1, sizeof(SSL_LISTENER)))) == NULL) static_cast<mxs::SSLContext*>(MXS_CALLOC(1, sizeof(mxs::SSLContext)))) == NULL)
{ {
MXS_ERROR("%s: Error allocating memory for SSL struct in createInstance", MXS_ERROR("%s: Error allocating memory for SSL struct in createInstance",
inst->service->name()); inst->service->name());
@ -2941,7 +2941,7 @@ const char* blr_get_event_description(ROUTER_INSTANCE* router, uint8_t event)
*/ */
void blr_free_ssl_data(ROUTER_INSTANCE* inst) void blr_free_ssl_data(ROUTER_INSTANCE* inst)
{ {
SSL_LISTENER* server_ssl; mxs::SSLContext* server_ssl;
if (inst->service->dbref->server->server_ssl) if (inst->service->dbref->server->server_ssl)
{ {

View File

@ -4841,7 +4841,7 @@ static char* blr_set_master_logfile(ROUTER_INSTANCE* router,
*/ */
static void blr_master_get_config(ROUTER_INSTANCE* router, MasterServerConfig* curr_master) static void blr_master_get_config(ROUTER_INSTANCE* router, MasterServerConfig* curr_master)
{ {
SSL_LISTENER* server_ssl; mxs::SSLContext* server_ssl;
curr_master->port = router->service->dbref->server->port; curr_master->port = router->service->dbref->server->port;
curr_master->host = router->service->dbref->server->address; curr_master->host = router->service->dbref->server->address;
@ -6330,7 +6330,7 @@ static int blr_set_master_ssl(ROUTER_INSTANCE* router,
const ChangeMasterConfig& config, const ChangeMasterConfig& config,
char* error_message) char* error_message)
{ {
SSL_LISTENER* server_ssl = NULL; mxs::SSLContext* server_ssl = NULL;
int updated = 0; int updated = 0;
if (config.ssl_enabled) if (config.ssl_enabled)
@ -6355,7 +6355,7 @@ static int blr_set_master_ssl(ROUTER_INSTANCE* router,
else else
{ {
/* Allocate SSL struct for backend connection */ /* Allocate SSL struct for backend connection */
server_ssl = static_cast<SSL_LISTENER*>(MXS_CALLOC(1, sizeof(SSL_LISTENER))); server_ssl = static_cast<mxs::SSLContext*>(MXS_CALLOC(1, sizeof(mxs::SSLContext)));
if (server_ssl == NULL) if (server_ssl == NULL)
{ {
router->ssl_enabled = false; router->ssl_enabled = false;