Teiid Client side SSL settings in System properties not working as expected

75 Views Asked by At

I have a teiid embedded server and I am trying to connect to a vds on that server through SSL from my remote client by passing the teiid SSL properties in SystemProperties as per the teiid documentation at: http://teiid.github.io/teiid-documents/12.3.x/content/client-dev/SSL_Client_Connections.html

For the first time when I get the connection, the client SSL properties which are passed in System properties work fine. However, in the same session when I change the system properties and create connection the second time, teiid driver seems to ignore it and creates connection using the system property values from the first connection.

Here is the code snippet to replicate this issue:

public static void main(String args[]) { try { String Teiid_SSL_URL = "jdbc:teiid:LocalMSSQLMS@mms://localhost:32750";

  Properties properties = new Properties();
  properties.put("user", "admin");
  properties.put("password", "admin");

  //CONNECTION-1 with valid SSL property values in System properties
  System.setProperty("org.teiid.ssl.trustStore", "C:/truststore.p12");
  System.setProperty("org.teiid.ssl.trustStorePassword", "testssl");

  DriverManager.registerDriver(new TeiidDriver());
  Connection connection1 = DriverManager.getConnection(Teiid_SSL_URL, properties);
  if (connection1.isValid(1000))
  {
    System.out.println("Connection-1 success");
    System.out.println("org.teiid.ssl.trustStore ->" + System.getProperty("org.teiid.ssl.trustStore"));
    System.out.println("org.teiid.ssl.trustStorePassword ->" + System.getProperty("org.teiid.ssl.trustStorePassword"));
  }

  //CONNECTION-2 with invalid SSL property values in System properties
  System.setProperty("org.teiid.ssl.trustStore", "abc");
  System.setProperty("org.teiid.ssl.trustStorePassword", "abc");

  Connection connection2 = DriverManager.getConnection(Teiid_SSL_URL, properties);
  if (connection2.isValid(1000))
  {
    System.out.println("\n\nConnection-2 success");
    System.out.println("org.teiid.ssl.trustStore ->" + System.getProperty("org.teiid.ssl.trustStore"));
    System.out.println("org.teiid.ssl.trustStorePassword ->" + System.getProperty("org.teiid.ssl.trustStorePassword"));
  }

}
catch (Exception e)
{
  e.printStackTrace();
}

}

========================================================================

Output of the above code:

Connection-1 success

org.teiid.ssl.trustStore ->C:/truststore.p12

org.teiid.ssl.trustStorePassword ->testssl

Connection-2 success

org.teiid.ssl.trustStore ->abc

org.teiid.ssl.trustStorePassword ->abc

==============================================================================

Here, in case of second connection since the truststore is not valid, it should have thrown the error. However, it is creating the connection-2 successfully. If the connection-2 with invalid values is created before connection-1 with valid values, the the driver throws error as expected. So, to conclude it is only considering the SSL settings passes as System proeprties for the first time. For any other connection calls after that, no matter what system properties are set, it uses the ones set before first call only.

If there is any additional client side configuration that is missing please let me know. Otherwise can you please look into this issue and let me know by when will be the fix available for this.

Thanks, Megha

1

There are 1 best solutions below

1
On

This is expected as the system properties are read only when the socket factory is initially created. It would be difficult to do this within the same vs - you'd have to use a different classloader that loaded the driver jar each time you wanted to change the settings. Otherwise you need to create separate vms. You can log an issue, but it would be very low priority.