[CONJ-882] TLS connection parameters are ignored in properties and must be set in URL Created: 2021-05-11  Updated: 2021-05-11  Resolved: 2021-05-11

Status: Closed
Project: MariaDB Connector/J
Component/s: configuration, SSL, TLS
Affects Version/s: 2.7.2
Fix Version/s: N/A

Type: Bug Priority: Major
Reporter: Geoff Montee (Inactive) Assignee: Diego Dupin
Resolution: Duplicate Votes: 0
Labels: None

Issue Links:
Duplicate
duplicates CONJ-858 Properties parameter different than s... Closed

 Description   

Currently, TLS parameters must be set in the connection URL. If you try to set them in a Properties object, the connection attempt will fail.

For example, this test program successfully connects:

import java.sql.*;
import java.util.Properties;
 
public class MariaDB_Connection_Test {
 
   // Main Process
   public static void main(String[] args) {
      Connection conn = null;
 
      try {
 
         Properties connProperties = new Properties();
 
         connProperties.put("user", "my_user");
         connProperties.put("password", "my_passwd");
 
         // Establish the Connection
         conn = DriverManager.getConnection(
            "jdbc:mariadb://geoff-test-repl.my-proj.instance.skysql.net:5001/?useSSL=true&serverSslCert=/home/geoff/Downloads/tls_chain.pem",
            connProperties);
 
         // Use the connection
         // ...
      }
      catch (Exception e) {
 
         // Report Exception
         e.printStackTrace();
      }
   }
}

But this test program fails to connect:

import java.sql.*;
import java.util.Properties;
 
public class MariaDB_Connection_Test {
 
   // Main Process
   public static void main(String[] args) {
      Connection conn = null;
 
      try {
 
         Properties connProperties = new Properties();
 
         connProperties.put("user", "my_user");
         connProperties.put("password", "my_passwd");
         connProperties.put("useSSL", true);
         connProperties.put("serverSslCert", "/home/geoff/Downloads/stage_chain.pem");
 
         // Establish the Connection
         conn = DriverManager.getConnection(
            "jdbc:mariadb://geoff-test-repl.my-proj.instance.skysql.net:5001/",
            connProperties);
 
         // Use the connection
         // ...
      }
      catch (Exception e) {
 
         // Report Exception
         e.printStackTrace();
      }
   }
}

The stack trace is:

java.sql.SQLInvalidAuthorizationSpecException: Could not connect to address=(geoff-test-repl.my-proj.instance.skysql.net)(port=5001)(type=master) : (conn=89) Access denied for user 'my_user'@'10.87.0.97' (using password: YES)
Current charset is UTF-8. If password has been set using other charset, consider using option 'passwordCharacterEncoding'
	at org.mariadb.jdbc.internal.util.exceptions.ExceptionFactory.createException(ExceptionFactory.java:66)
	at org.mariadb.jdbc.internal.util.exceptions.ExceptionFactory.create(ExceptionFactory.java:192)
	at org.mariadb.jdbc.internal.protocol.AbstractConnectProtocol.connectWithoutProxy(AbstractConnectProtocol.java:1392)
	at org.mariadb.jdbc.internal.util.Utils.retrieveProxy(Utils.java:635)
	at org.mariadb.jdbc.MariaDbConnection.newConnection(MariaDbConnection.java:150)
	at org.mariadb.jdbc.Driver.connect(Driver.java:89)
	at java.sql.DriverManager.getConnection(DriverManager.java:664)
	at java.sql.DriverManager.getConnection(DriverManager.java:208)
	at MariaDB_Connection_Test.main(MariaDB_Connection_Test.java:24)
Caused by: java.sql.SQLInvalidAuthorizationSpecException: (conn=89) Access denied for user 'my_user'@'10.87.0.97' (using password: YES)
Current charset is UTF-8. If password has been set using other charset, consider using option 'passwordCharacterEncoding'
	at org.mariadb.jdbc.internal.util.exceptions.ExceptionFactory.createException(ExceptionFactory.java:66)
	at org.mariadb.jdbc.internal.util.exceptions.ExceptionFactory.create(ExceptionFactory.java:187)
	at org.mariadb.jdbc.internal.protocol.AbstractConnectProtocol.authenticationHandler(AbstractConnectProtocol.java:767)
	at org.mariadb.jdbc.internal.protocol.AbstractConnectProtocol.createConnection(AbstractConnectProtocol.java:553)
	at org.mariadb.jdbc.internal.protocol.AbstractConnectProtocol.connectWithoutProxy(AbstractConnectProtocol.java:1387)
	... 6 more

This seems to apply to the following TLS parameters at least, but I have not tested every TLS parameter:

  • useSSL
  • serverSslCert
  • trustServerCertificate


 Comments   
Comment by Diego Dupin [ 2021-05-11 ]

closing since that dupplicate CONJ-858.
same example with

connProperties.put("useSSL", "true");

would work.

Generated at Thu Feb 08 03:19:00 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.