node-oracledb icon indicating copy to clipboard operation
node-oracledb copied to clipboard

2 way ssl connects without client certificate.

Open Kankan-0 opened this issue 6 years ago • 14 comments

Hi all,

I am using node oracledb to connect to an oracle db(12c) over an ssl connection. I configured client and server wallet according to the oracle documentation. Everything is working fine. However, ther's a scenario that I want to understand

  1. Initially, I have client certificate in client wallet and I try to connect using 2-way ssl setup. It connects properly.
  2. Without stopping the node process, I removed the client certificate from the client wallet. I am expecting the connection to fail, but it still succeeds.
  3. If I restart the node process(without the client certificate in wallet) it fails. (this is working as expected)

My question is does the package somehow caches the wallet content and until we restart the process, any changes made in the wallet will not get reflected??

Please help me understanding this if anyone has any idea. Will be happy to clarify the question if needed. Thanks

Kankan-0 avatar Feb 23 '20 11:02 Kankan-0

What kind of node-oracledb connection are you using? A pool?

cjbj avatar Feb 23 '20 11:02 cjbj

I think it's not a pooled connection although I am not sure. I'll upload the connection code shortly.

Kankan-0 avatar Feb 23 '20 17:02 Kankan-0

But does that make a difference? i.e. is it expected behaviour in case of pooled connections?

Kankan-0 avatar Feb 23 '20 17:02 Kankan-0

Are you sure you're using SSL and not native encryption? Could you please provide a link to the doc you used for setup?

As to the behavior you're experiencing, I would guess that the files (or at least the relevant values from them) are being cached.

dmcghan avatar Feb 23 '20 19:02 dmcghan

Yes, I am pretty sure that I am using SSL and not native encryption. I've used (https://docs.oracle.com/database/121/DBSEG/asossl.htm#DBSEG09361) for setup.

Kankan-0 avatar Feb 23 '20 20:02 Kankan-0

Regarding pooling, I could imagine that once connections in homogenous pool (the default), and any open stand-alone connections are created, then no further authentication is done. However, the details are not something I know about. If you can provide useful information about what you have configured and how you are connection, I'll see if I can get someone to comment.

cjbj avatar Feb 23 '20 23:02 cjbj

Here's my code that I'm using to connect to the db.

   const oracledb = require('oracledb');
    async function run() {
        let connection;
        try {
            connection = await oracledb.getConnection({
                user: "dummy",
                password: "dummy",
                connectString: "test"

             });
            console.log('success, retrying')
            await connection.close()
            setTimeout(run, 5000)
         } catch (err) {
            console.error(err, 'retrying');
            setTimeout(run, 5000)
        } finally {
            if (connection) {
                try { await connection.close()}
                catch (err) {}
             }
          }
       }

     run();
  1. I have valid certificates in my wallet. (expected behavior : it should connect. actual behavior : it properly connects)
  2. Now I manually delete all the files from my wallet location. (expected behavior : it should fail saying that failure to open file. actual behavior : it fails with correct answer)
  3. Here comes the unexpected thing. I now use invalid wallet contents(i.e. wallet with no client certificates). (expected behavior : it should fail with SSL error, actual behavior : it succeeds)
  4. If I restart the node process without changing the wallet contents, it fails as expected.

The reverse case works fine(i.e. if I first try with invalid details, and then without restarting the process I change the wallet content to have valid details, it connects properly)

As @cjbj mentioned, in homogenous pool (default) once connections are created, no further authentication is done. May be it's because of that (?). If yes, is there a way to turn off this setting? Also, once connected I am closing the connection before retrying. Shouldn't it try to create a new connection everytime or did I use setTimeout in a wrong manner ?

Kankan-0 avatar Feb 24 '20 06:02 Kankan-0

What's your business goal?

cjbj avatar Feb 24 '20 21:02 cjbj

I am using node-oracledb to connect to oracle databases(on both SSL and non SSL connections) and then performing different operations. While testing different scenarios, we came across this. Although, this will be hardly a use case in real world, I am just trying to understand how the connection setup works.

Kankan-0 avatar Feb 25 '20 18:02 Kankan-0

Established connections will continue to function even with the removal of the wallet; new connections will fail to connect without the wallet. The wallet is only needed during connection establishments.

onmp avatar Feb 26 '20 02:02 onmp

@onmp I understand that removal of wallet will have no impact in an already established connection. However if you check my test code, I am closing the connection and retrying it. Retry should get treated as a new connection request. However it's ignoring the presence/absence of wallet and creating the connection(if it was successful first time before closing and retrying)

Kankan-0 avatar Feb 26 '20 07:02 Kankan-0

With connection pooling closing a connection doesn't mean the connection is terminated, the connection is returned to the pool and the getConnection() will fetch a connection out of the pool. In your example the same connection is being returned with the close() and fetched with the getConnection(). There are oracledb properties oracledb.pool???? that you can use to get the behavior you want.

onmp avatar Feb 26 '20 23:02 onmp

@onmp there is no pooling in this example. I can give you a trace of OCI calls if you like.

cjbj avatar Feb 26 '20 23:02 cjbj

Closing - no activity

cjbj avatar Apr 01 '20 05:04 cjbj