Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1U1HIc-0005iV-7K for pgsql-jdbc@arkaria.postgresql.org; Fri, 01 Feb 2013 14:09:02 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1U1HIa-0006yy-Qh for pgsql-jdbc@arkaria.postgresql.org; Fri, 01 Feb 2013 14:09:00 +0000 Received: from magus.postgresql.org ([87.238.57.229]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1U1HIM-0006n0-2i; Fri, 01 Feb 2013 14:08:46 +0000 Received: from szxga01-in.huawei.com ([119.145.14.64]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1U1HIG-0000u4-Rn; Fri, 01 Feb 2013 14:08:45 +0000 Received: from 172.24.2.119 (EHLO szxeml206-edg.china.huawei.com) ([172.24.2.119]) by szxrg01-dlp.huawei.com (MOS 4.3.4-GA FastPath queued) with ESMTP id AXC38650; Fri, 01 Feb 2013 22:08:37 +0800 (CST) Received: from SZXEML451-HUB.china.huawei.com (10.82.67.194) by szxeml206-edg.china.huawei.com (172.24.2.59) with Microsoft SMTP Server (TLS) id 14.1.323.7; Fri, 1 Feb 2013 22:06:26 +0800 Received: from blrprnc07ns (10.18.96.96) by szxeml451-hub.china.huawei.com (10.82.67.194) with Microsoft SMTP Server id 14.1.323.7; Fri, 1 Feb 2013 22:06:27 +0800 From: Hari Babu To: "'dmp'" CC: , References: <51068542.845c2b0a.7fd0.68b2SMTPIN_ADDED_BROKEN@mx.google.com> <00a401cdfdde$db9737e0$92c5a7a0$@kommi@huawei.com> <5107FBCA.3040107@ttc-cmc.net> <007601cdffb5$cc4834a0$64d89de0$@kommi@huawei.com> <510ABEC8.6030201@ttc-cmc.net> In-Reply-To: <510ABEC8.6030201@ttc-cmc.net> Subject: Re: JDBC connection test with SSL on PG 9.2.1 server Date: Fri, 1 Feb 2013 19:36:26 +0530 Message-ID: <003301ce0085$53a389c0$faea9d40$@kommi@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Office Outlook 12.0 Thread-Index: Ac3/5R1uUK4UA7svSSSlOAh3w4mmDgAn31Xw Content-Language: en-us X-Originating-IP: [10.18.96.96] X-CFilter-Loop: Reflected X-Pg-Spam-Score: -3.5 (---) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-jdbc Precedence: bulk Sender: pgsql-jdbc-owner@postgresql.org > On Tuesday, January 29, 2013 10:12 PM danap wrote: >> Hari Babu wrote: >>> On Monday, January 28, 2013 10:20 PM, Dave Cramer wrote: >>> >>> >>On Mon, Jan 28, 2013 at 9:03 AM, Hari Babu>> > wrote: >>> >>> >>While testing PostgreSQL JDBC java client to connect to the PG 9.2.1 >>> >>database server using SSL. >>> >>we got the following behavior. >>> >> >>> >>The test steps as below=EF=BC=9A >>> >> >>> >>url =3D "jdbc:postgresql://" + "10.145.98.227" + ':' >>> >> + "8707" + '/' >>> >> + "POSTGRES"; >>> >> Properties props =3D new Properties(); >>> >> props.setProperty("user", "CLIENT"); >>> >> props.setProperty("password", "1234@QWER"); >>> >> props.setProperty("ssl", "true"); >>> >> >>> >> System.setProperty("javax.net.ssl.trustStore", "193store"); >>> >> System.setProperty("javax.net.ssl.keyStore", "193client.jks"); >>> >> System.setProperty("javax.net.ssl.trustStorePassword", "qwerty"); >>> >> System.setProperty("javax.net.ssl.keyStorePassword", "qwerty"); >>> >> >>> >> /*Begin the first ssl connection*/ >>> >> conn1 =3D DriverManager.getConnection(url, props); >>> >> System.out.println("Connection1 successful!"); >>> >> >>> >> >>> >> System.setProperty("javax.net.ssl.trustStore", "193store"); >>> >> System.setProperty("javax.net.ssl.keyStore", "193client.jks"); >>> >> System.setProperty("javax.net.ssl.trustStorePassword", "qwerty"); >>> >> System.setProperty("javax.net.ssl.keyStorePassword", "wrongpasswo= rd"); >>> >> >>> >> /*Begin the second ssl connection*/ >>> >> conn2 =3D DriverManager.getConnection(url, props); >>> >> System.out.println("Connection2 successful!"); >>> >> >>> >>Before first connection we set >>> >>"System.setProperty("javax.net.ssl.keyStorePassword", "qwerty");" >>> qwerty is >>> >>the right password >>> >>and before second SSL connection we set >>> >>"System.setProperty("javax.net.ssl.keyStorePassword", "wrongpasswor= d");" >>> >>wrongpassword is the wrong password. >>> >> >>> >>we expect the first SSL connection will be successful and second fa= iled >>> >>because of wrong password, but actually we get two successful SSL >>> >>connections. >>> >>We found that if the first SSL connections password set right, all = the >>> >>following SSL connections are fine ,even set wrong keystroke passwo= rd. >>> >> >>> >>1. Is this a defect about JDBC? >>> >>2. Is it SSL behavior to authenticate only once? >>> >>3. Is it system property behavior can be set only once. >>> >>4. Is it because of any other problems? >>> >> >>> >>please give your suggestions? >>> >>> >JDBC uses java's SSL infrastructure, as such I don't think it's a >>> defect in JDBC. It could be because your truststore>does not require a >>> password. >>> >>> I removed the trustStorePassword setting from the test, still the second >>> connection is getting success with the wrong >>> >>> keyStorePassword. > >> Can you please set the property logLevel=3D1, INFO >> and then reply back with the output. You may also >> try logLevel=3D2, DEBUG for additional information. > > How to set logLevel=3D1 INFO and logLevel =3D2 DEBUG. Is it is JDBC loggi= ng or something else? > > We tried to get the SSL specific log by setting the system property for j= avax.net.debug as > "ssl" (system.setProperty("javax.net.debug", "ssl"). With this we got con= nection logs for each of the connection which are attached in the mail. > > For the first connection, it is opening the keys file and then does init = for keyStore and trustStore. But incase of second connection it just uses t= he previous cached session and does not open any of the file set in the pro= perty. So may be that is the reason even if wrong file or password is given= before second connection, connection is successful. > > From the logs we feel that SSL caching may be causing the problem. > Is there any exposed JSSE interface function to disable SSL session cachi= ng? > If you can derive something from the attached logs, please let us know. > > How to set the SSL property "sslfactory" from application with some valid= class? > Our idea is that JDBC convert function execution goes to the else part of > "if (classname =3D=3D null)". > > The code snippet is attached: > > String classname =3D info.getProperty("sslfactory"); > if (classname =3D=3D null) > { > //If sslmode is set, use the libp compatible factory > if (sslmode!=3Dnull) > { > factory =3D new LibPQFactory(info); > } > else > { > factory =3D (SSLSocketFactory)SSLSocketFactory.getDefault(); > } > } > else > { > try > { > factory =3D (SSLSocketFactory)instantiate(classname, inf= o, true, info.getProperty("sslfactoryarg")); > } > catch (Exception e) > { > throw new PSQLException(GT.tr("The SSLSocketFactory clas= s provided {0} could not be instantiated.", classname), PSQLState.CONNECTIO= N_FAILURE, e); > } > } > > Regards, > Hari babu. >Hello Hari, >I thought at first setting props.setProperty("loglevel", "1") may derive >additional information. It will not in this case. I already suspected and >believe that the System property is not changing, cached as you indicated. >Please try this first to see if System Properties can be uncached, changed >between the two connections. >danap. >url =3D "jdbc:postgresql://" + host + "/" + database; >Properties props =3D new Properties(); >props.setProperty("user", username); >props.setProperty("password", password); >props.setProperty("loglevel", "1"); >Properties systemProperties =3D System.getProperties(); >systemProperties.setProperty("javax.net.ssl.trustStore", "193store"); >systemProperties.setProperty("javax.net.ssl.keyStore", "193client.jks"); >systemProperties.setProperty("javax.net.ssl.trustStorePassword", "qwerty"); >systemProperties.setProperty("javax.net.ssl.keyStorePassword", "qwerty"); >System.setProperties(systemProperties); >System.out.println(System.getProperty("javax.net.ssl.keyStorePassword")); /*Begin the first ssl connection*/ >conn1 =3D DriverManager.getConnection(url, props); >System.out.println("Connection1 successful!"); >System.setProperties(null); >System.out.println(System.getProperty("javax.net.ssl.keyStorePassword")); >systemProperties.setProperty("javax.net.ssl.keyStorePassword", "wrongqwert= y"); >System.setProperties(systemProperties); >System.out.println(System.getProperty("javax.net.ssl.keyStorePassword")); >/*Begin the second ssl connection*/ >conn2 =3D DriverManager.getConnection(url, props); >System.out.println("Connection2 successful!"); We tried the approach as suggested by you but still it is not working as sh= own in the below log (I had enabled logLevel as 1) keystore passowrd is qwerty=20 19:26:22.666 (1) PostgreSQL 9.2 JDBC4 (build 1002)=20 19:26:23.451 (1) Receive Buffer Size is 43808=20 19:26:23.452 (1) Send Buffer Size is 25386=20 getConnection returning driver[className=3Dorg.postgresql.Driver,org.postgr= esql.Driver@3f7fa65e]=20 Connection1 successful! Conn1:org.postgresql.jdbc4.Jdbc4Connection@6baa9f99= =20 null=20 wrongqwerty=20 DriverManager.getConnection("jdbc:postgresql://127.0.0.1:15432/postgres")= =20 trying driver[className=3Dsun.jdbc.odbc.JdbcOdbcDriver,sun.jdbc.odbc.Jd= bcOdbcDriver@3597a37c]=20 *Driver.connect (jdbc:postgresql://127.0.0.1:15432/postgres)=20 trying driver[className=3Dorg.postgresql.Driver,org.postgresql.Driver@3= f7fa65e]=20 19:26:23.835 (2) PostgreSQL 9.2 JDBC4 (build 1002)=20 19:26:23.847 (2) Receive Buffer Size is 43808=20 19:26:23.848 (2) Send Buffer Size is 25386=20 getConnection returning driver[className=3Dorg.postgresql.Driver,org.postgr= esql.Driver@3f7fa65e]=20 Connection2 successful! Conn2:org.postgresql.jdbc4.Jdbc4Connection@2e958bb8= =20 Connect OK There is function as SSL_CTX_SETSESSIONCACHEMODE(ctxt, mode) in C library o= f SSL. Can you please let us know if there is some similar function in JSSE also. Regards, Hari Babu. --=20 Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-jdbc