jruby jdbcmysql adapter does not work with ssl?
I cannot seem to get jdbcmysql to run over ssl.
Downloaded gems:
jdbc-mysql (5.0.4)
jruby-openssl (0.7.1)
Using a normal rails console (not jruby), I got it to run with (sanitized below):
cp = ActiveRecord::Base.establish_connection(
:adapter => 'jdbcmysql',
:host => 'host',
:username => 'user',
:password => 'pw',
:database => 'db',
:sslca => "ca-cert.pem"
)
but the same command throws this right after I call cp.connection:
RuntimeError: The driver encountered an unknown error: java.sql.SQLException: Access denied for user 'user'@'host' (using passw开发者_高级运维ord: YES)
in jruby console. This is probably because ssl is not used because I set the user to require ssl.
Does jdbc-mysql just not support ssl? I'm pretty sure the jdbc adapter does.
What happened here was that the mysql client was version 5.0 while the server was 5.1
The syntax is exactly the same, accessing without ssl works, but with ssl silently fails :(
I've found that with jruby/odbc and ssl, you MUST use the odbc url param to configure your connection. Docs are scarce, but I believe the MRI gem will use ssl (if available) by default, but the odbc adapters, don't. There doesn't appear to be a key you can put in your yml/establish_connection to enable ssl on odbc.
This should work for this situation: ssl=true
cp = ActiveRecord::Base.establish_connection(
:url => 'jdbc:mysql://host/db?user=user&password=pw&ssl=true&sslca=ca-cert.pem'
)
I'm not sure if the sslca key translates directly like that, or how it would calculate paths.
heroku/postgresql recommends adding: sslfactory=org.postgresql.ssl.NonValidatingFactory
Tested only with postgresql, but I'm confident mysql and most all odbc adapters will also work like this.
精彩评论