Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting ssl-mode option for connections #202

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/MySQL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ function setoptions!(mysql;
passphrase::Union{AbstractString, Nothing}=nothing,
ssl_verify_server_cert::Union{Bool, Nothing}=nothing,
ssl_enforce::Union{Bool, Nothing}=nothing,
ssl_mode::Union{API.mysql_ssl_mode, Nothing}=nothing,
default_auth::Union{AbstractString, Nothing}=nothing,
connection_handler::Union{AbstractString, Nothing}=nothing,
plugin_dir::Union{AbstractString, Nothing}=nothing,
Expand Down Expand Up @@ -199,6 +200,9 @@ function setoptions!(mysql;
if ssl_crlpath !== nothing
API.setoption(mysql, API.MYSQL_OPT_SSL_CRLPATH, ssl_crlpath)
end
if ssl_mode !== nothing
API.setoption(mysql, API.MYSQL_OPT_SSL_MODE, ssl_mode)
end
if passphrase !== nothing
API.setoption(mysql, API.MARIADB_OPT_TLS_PASSPHRASE, passphrase)
end
Expand Down
11 changes: 10 additions & 1 deletion src/api/consts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,14 @@ end
MYSQL_PROTOCOL_MEMORY
end

@enum mysql_ssl_mode begin
SSL_MODE_DISABLED
SSL_MODE_PREFERRED
SSL_MODE_REQUIRED
SSL_MODE_VERIFY_CA
SSL_MODE_VERIFY_IDENTITY
end

# Options to be passed to mysql_options API.
@enum mysql_option begin
MYSQL_OPT_CONNECT_TIMEOUT
Expand Down Expand Up @@ -212,9 +220,10 @@ end
MARIADB_OPT_INTERACTIVE
MARIADB_OPT_PROXY_HEADER
MARIADB_OPT_IO_WAIT
MYSQL_OPT_SSL_MODE
end

const CUINTOPTS = Set([MYSQL_OPT_CONNECT_TIMEOUT, MYSQL_OPT_PROTOCOL, MYSQL_OPT_READ_TIMEOUT, MYSQL_OPT_WRITE_TIMEOUT])
const CUINTOPTS = Set([MYSQL_OPT_CONNECT_TIMEOUT, MYSQL_OPT_PROTOCOL, MYSQL_OPT_READ_TIMEOUT, MYSQL_OPT_WRITE_TIMEOUT, MYSQL_OPT_SSL_MODE])
const CULONGOPTS = Set([MYSQL_OPT_MAX_ALLOWED_PACKET, MYSQL_OPT_NET_BUFFER_LENGTH])
const BOOLOPTS = Set([MYSQL_ENABLE_CLEARTEXT_PLUGIN, MYSQL_OPT_CAN_HANDLE_EXPIRED_PASSWORDS, MYSQL_OPT_LOCAL_INFILE, MYSQL_OPT_RECONNECT, MYSQL_REPORT_DATA_TRUNCATION, MYSQL_OPT_SSL_ENFORCE, MYSQL_OPT_SSL_VERIFY_SERVER_CERT])
const STRINGOPTS = Set([MYSQL_DEFAULT_AUTH, MYSQL_OPT_BIND, MYSQL_OPT_SSL_CA, MYSQL_OPT_SSL_CAPATH, MYSQL_OPT_SSL_CERT, MYSQL_OPT_SSL_CIPHER, MYSQL_OPT_SSL_CRL, MYSQL_OPT_SSL_CRLPATH, MYSQL_OPT_SSL_KEY, MYSQL_OPT_TLS_VERSION, MYSQL_PLUGIN_DIR, MYSQL_READ_DEFAULT_FILE, MYSQL_READ_DEFAULT_GROUP, MYSQL_SERVER_PUBLIC_KEY, MYSQL_SET_CHARSET_DIR, MYSQL_SET_CHARSET_NAME, MYSQL_SHARED_MEMORY_BASE_NAME])
Expand Down