-
Notifications
You must be signed in to change notification settings - Fork 552
adds tls sni support to mysql2 #1405
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
base: master
Are you sure you want to change the base?
adds tls sni support to mysql2 #1405
Conversation
|
||
#ifdef CLIENT_CONNECT_ATTRS | ||
mysql_options(wrapper->client, MYSQL_OPT_CONNECT_ATTR_RESET, 0); | ||
rb_hash_foreach(conn_attrs, opt_connect_attr_add_i, (VALUE)wrapper); | ||
#endif | ||
|
||
if(sni_hostname != NULL) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit:
if(sni_hostname != NULL) { | |
if (sni_hostname != NULL) { |
args.mysql = wrapper->client; | ||
args.client_flag = NUM2ULONG(flags); | ||
|
||
sni_hostname = NIL_P(tls_sni_name) ? NULL : StringValueCStr(tls_sni_name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to refresh myself on this code to remember if this ought to go into the args
structure. It is used to stash arguments that are passed by pointer-to-structure to nogvl_connect
-- but I don't remember if the args structure is also used for subsequent reconnects or looking up connection parameters later on.
args.passwd = NIL_P(pass) ? NULL : StringValueCStr(pass); | ||
args.db = NIL_P(database) ? NULL : StringValueCStr(database); | ||
args.mysql = wrapper->client; | ||
args.client_flag = NUM2ULONG(flags); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this spacing off by one or is that a GitHub display bug? (I'm reviewing on web)
|
||
#ifdef CLIENT_CONNECT_ATTRS | ||
mysql_options(wrapper->client, MYSQL_OPT_CONNECT_ATTR_RESET, 0); | ||
rb_hash_foreach(conn_attrs, opt_connect_attr_add_i, (VALUE)wrapper); | ||
#endif | ||
|
||
if(sni_hostname != NULL) { | ||
/* Set the TLS SNI name if provided */ | ||
mysql_options(wrapper->client, MYSQL_OPT_TLS_SNI_SERVERNAME, sni_hostname); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found that this wasn't added until MySQL 8.1:
https://dev.mysql.com/doc/relnotes/mysql/8.1/en/news-8-1-0.html
However MySQL 8.0 is still in support window, so #ifdef protection is required.
This pull request introduces support for specifying a TLS SNI (Server Name Indication) name during MySQL client connections. This enhancement allows users to set a custom SNI hostname for TLS connections, improving flexibility and compatibility with certain server configurations.
Enhancements to TLS Configuration:
rb_mysql_connect
function inext/mysql2/client.c
to accept an additional parameter,tls_sni_name
, and use it to set the TLS SNI server name via theMYSQL_OPT_TLS_SNI_SERVERNAME
option in the MySQL client library. [1] [2]init_mysql2_client
function inext/mysql2/client.c
to reflect the updatedrb_mysql_connect
method signature, increasing the number of expected arguments from 8 to 9.Updates to Ruby Client Initialization:
:tls_sni_name
option in theinitialize
method oflib/mysql2/client.rb
, allowing users to specify the SNI name when creating a MySQL client instance.tls_sni_name
value is converted to a string if provided, and passed it as an argument to the updatedconnect
method.