@@ -46,9 +46,14 @@ def initialize(opts = {})
46
46
# force the encoding to utf8
47
47
self . charset_name = opts [ :encoding ] || 'utf8'
48
48
49
+ mode = parse_ssl_mode ( opts [ :ssl_mode ] ) if opts [ :ssl_mode ]
50
+ if ( mode == SSL_MODE_VERIFY_CA || mode == SSL_MODE_VERIFY_IDENTITY ) && !opts [ :sslca ]
51
+ opts [ :sslca ] = find_default_ca_path
52
+ end
53
+
49
54
ssl_options = opts . values_at ( :sslkey , :sslcert , :sslca , :sslcapath , :sslcipher )
50
55
ssl_set ( *ssl_options ) if ssl_options . any? || opts . key? ( :sslverify )
51
- self . ssl_mode = parse_ssl_mode ( opts [ :ssl_mode ] ) if opts [ :ssl_mode ]
56
+ self . ssl_mode = mode if mode
52
57
53
58
flags = case opts [ :flags ]
54
59
when Array
@@ -115,6 +120,18 @@ def parse_flags_array(flags, initial = 0)
115
120
end
116
121
end
117
122
123
+ # Find any default system CA paths to handle system roots
124
+ # by default if stricter validation is requested and no
125
+ # path is provide.
126
+ def find_default_ca_path
127
+ [
128
+ "/etc/ssl/certs/ca-certificates.crt" ,
129
+ "/etc/pki/tls/certs/ca-bundle.crt" ,
130
+ "/etc/ssl/ca-bundle.pem" ,
131
+ "/etc/ssl/cert.pem" ,
132
+ ] . find { |f | File . exist? ( f ) }
133
+ end
134
+
118
135
# Set default program_name in performance_schema.session_connect_attrs
119
136
# and performance_schema.session_account_connect_attrs
120
137
def parse_connect_attrs ( conn_attrs )
0 commit comments