Skip to content

Commit 158954c

Browse files
author
Timur Alperovich
committed
Remove the check for SSL CA or Key being set.
Currently, the C bindings for the mysql2 gem enforce specifying either the ssl-ca or ssl-key option, in order to set any of the SSL flags. This makes the usage of mysql client worse for a few reasons. For one, it's impossible to specify the ssl-capath flag by itself. This is troubling if the server certificate is signed by a trusted authority, whose certificate is present in /etc/ssl/certs, for example. The other issue is that --ssl-cipher may not be specified on itsown. The reason it may be desired is that it forces the client to use SSL to connect to the server, without requiring the client to validate the server certificate. In certain situations that may actually be desirable (e.g. self-signed certificates which do not have a CA certificate generated). This patch also guards against calling mysql_ssl_set() uncondtionally by ensuring that at least one of the SSL options is set. Fixes: #355
1 parent d79e804 commit 158954c

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

ext/mysql2/client.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,14 +1051,12 @@ static VALUE set_charset_name(VALUE self, VALUE value) {
10511051
static VALUE set_ssl_options(VALUE self, VALUE key, VALUE cert, VALUE ca, VALUE capath, VALUE cipher) {
10521052
GET_CLIENT(self);
10531053

1054-
if(!NIL_P(ca) || !NIL_P(key)) {
1055-
mysql_ssl_set(wrapper->client,
1056-
NIL_P(key) ? NULL : StringValuePtr(key),
1057-
NIL_P(cert) ? NULL : StringValuePtr(cert),
1058-
NIL_P(ca) ? NULL : StringValuePtr(ca),
1059-
NIL_P(capath) ? NULL : StringValuePtr(capath),
1060-
NIL_P(cipher) ? NULL : StringValuePtr(cipher));
1061-
}
1054+
mysql_ssl_set(wrapper->client,
1055+
NIL_P(key) ? NULL : StringValuePtr(key),
1056+
NIL_P(cert) ? NULL : StringValuePtr(cert),
1057+
NIL_P(ca) ? NULL : StringValuePtr(ca),
1058+
NIL_P(capath) ? NULL : StringValuePtr(capath),
1059+
NIL_P(cipher) ? NULL : StringValuePtr(cipher));
10621060

10631061
return self;
10641062
}

lib/mysql2/client.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ def initialize(opts = {})
3636
# force the encoding to utf8
3737
self.charset_name = opts[:encoding] || 'utf8'
3838

39-
ssl_set(*opts.values_at(:sslkey, :sslcert, :sslca, :sslcapath, :sslcipher))
39+
ssl_options = opts.values_at(:sslkey, :sslcert, :sslca, :sslcapath, :sslcipher)
40+
ssl_set(*ssl_options) if ssl_options.any?
4041

4142
if [:user,:pass,:hostname,:dbname,:db,:sock].any?{|k| @query_options.has_key?(k) }
4243
warn "============= WARNING FROM mysql2 ============="

0 commit comments

Comments
 (0)