java中如何使用CA证书连接数据库
目前,我正在连接不需要CA证书的数据库,如下所示:java中如何使用CA证书连接数据库,java,ssl,jdbc,ca,Java,Ssl,Jdbc,Ca,目前,我正在连接不需要CA证书的数据库,如下所示: input = new FileInputStream("path/to/properties/file"); prop.load(input); Class.forName(prop.getProperty("JDBC_DRIVER")); conn = DriverManager.getConnection(prop.getProperty("DB_URL"), prop.getProperty("USER"), prop.getProp
input = new FileInputStream("path/to/properties/file");
prop.load(input);
Class.forName(prop.getProperty("JDBC_DRIVER"));
conn = DriverManager.getConnection(prop.getProperty("DB_URL"), prop.getProperty("USER"), prop.getProperty("PASS"));
现在需求已经改变,我必须使用我拥有的CA证书连接到数据库。
现在我尝试以下方法:
String url = prop.getProperty("DB_URL")+"?verifyServerCertificate=false"+"&useSSL=true"+"&requireSSL=true";
Class.forName(prop.getProperty("JDBC_DRIVER"));
conn = DriverManager.getConnection(url, prop.getProperty("USER"), prop.getProperty("PASS"));
您能告诉我如何提供CA证书的路径并成功连接到数据库吗。我知道如何使用SSL(CA证书)连接到数据库:
这个对我有用 它应该是
/path\u to\u truststore
,并且``getProperties()`部分是多余的。另外verifyServerCertificate=false
使您容易受到中间人攻击将进行建议的更改。谢谢
input = new FileInputStream("path/to/properties/file");
prop.load(input);
Class.forName(prop.getProperty("JDBC_DRIVER"));
System.getProperties().setProperty("javax.net.ssl.trustStore",
"/path_to_certificate");
String url = prop.getProperty("DB_URL")
+ "?verifyServerCertificate=false" + "&useSSL=true"
+ "&requireSSL=true";
return DriverManager.getConnection(url, prop.getProperty("USER"),
prop.getProperty("PASS"));