vertx-sql-client icon indicating copy to clipboard operation
vertx-sql-client copied to clipboard

Oracle client - SSL connection support

Open NekiyXX opened this issue 3 years ago • 7 comments

Add support for SSL connection to Oracle DB with sslMode, certPaths and certValues options like it was done in PostgreSQL, MySQL and other clients.

NekiyXX avatar Jun 30 '22 14:06 NekiyXX

@NekiyXX for the record, I was able to connect to Oracle Cloud using the "wallet" downloaded from their site https://gist.github.com/tsegismont/3f6f00ca3052ef11f941c93728a01f80

Can you provide more details about your environment? In particular, how would you connect to it using plain JDBC?

The usual encryption parameters from Vert.x Reactive Clients may not be useful here, given the Oracle client is a different kind (a wrapper around JDBC driver reactive extensions).

tsegismont avatar Jul 04 '22 20:07 tsegismont

@tsegismont Thanks for your example. I see that ssl connection works. But it seems I understood main issue for my case: Your parser in OracleConnectOptions.fromUri does not support TNS URL Format in jdbc URL. And I do not know other way to setup protocol = tcps for oracle jdbc driver. In your current realization I should use additional file tnsnames.ora with information about protocol.

But I want opportunity to do it only in code like this:

final String connectionString = String.format(
        "jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCPS)(HOST=%s)(PORT=%d))(CONNECT_DATA=(SID=%s)))",
        DB_SERVER_NAME, SSL_PORT, DB_SID);
properties.put("user", DB_USER);
properties.put("password", DB_PASSWORD);
properties.put("javax.net.ssl.trustStore", KEY_STORE_FILE_PATH);
properties.put("javax.net.ssl.trustStoreType", "JKS");
properties.put("javax.net.ssl.trustStorePassword", KEY_STORE_PASS);
final Connection connection = DriverManager.getConnection(connectionString, properties);

Or maybe some setter for PROTOCOL if it possible.

NekiyXX avatar Jul 06 '22 21:07 NekiyXX

The EZConnect format allows to set the protocol to tcps. You could do this:

String connectionUri = String.format(
  "oracle:thin:@tcps://%s:%s/%s",
  DB_SERVER_NAME, SSL_PORT, DB_SID);

// Connect options
OracleConnectOptions connectOptions = OracleConnectOptions.fromUri(connectionUri)
  .setUser(DB_USER)
  .setPassword(DB_PASSWORD)
  .addProperty("javax.net.ssl.trustStore", KEY_STORE_FILE_PATH)
  .addProperty("javax.net.ssl.trustStoreType", "JKS")
  .addProperty("javax.net.ssl.trustStorePassword", KEY_STORE_PASS);

// Pool Options
PoolOptions poolOptions = new PoolOptions().setMaxSize(5);

// Create the pool from the connection URI
OraclePool pool = OraclePool.pool(vertx, connectOptions, poolOptions);

tsegismont avatar Jul 07 '22 09:07 tsegismont

@tsegismont I didn't know about supporting protocol in EZConnect. Thanks you very much. It is works. Also as I see in code it is enough to initialize OracleConnectOptions by jsonObject with {"ssl":true,host:"hostName", port:2484, (database or serviceName):"databaseName"} and after that add needed properties. So you could close ticket. Sorry for taking your time. But I think it should be added in documentation for vertx Oracle Reactive Client.

NekiyXX avatar Jul 07 '22 14:07 NekiyXX

We have this https://vertx.io/docs/vertx-oracle-client/java/#_connection_uri

What's your suggestion for improvement?

tsegismont avatar Jul 07 '22 21:07 tsegismont

In our application we can configure three databases MySQL, PostgreSQL and Oracle For MySQL client there is section: https://vertx.io/docs/vertx-mysql-client/java/#_using_ssltls For PostgreSQL section: https://vertx.io/docs/vertx-pg-client/java/#_using_ssltls

After implementing these two I start to search how it should be in Oracle client. Since the method of working with SSL in Oracle is different, I could not quickly find how to do it and asked a question here: https://groups.google.com/g/vertx/c/Rxgh-BDpyAo After this answer I created ticket. So I thing for Oracle also should be section "Using SSL/TLS" in documentation like MySQL and PostgreSQL clients. Thank you very much for help.

NekiyXX avatar Jul 08 '22 07:07 NekiyXX

Makes sense @NekiyXX , I will take care of it

tsegismont avatar Jul 08 '22 13:07 tsegismont