Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id E247AB5DC61 for ; Wed, 2 Nov 2011 10:53:11 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 26916-02 for ; Wed, 2 Nov 2011 13:53:05 +0000 (UTC) X-Greylist: delayed 00:07:14.883478 by SQLgrey-1.8.0-rc2 Received: from mag.webhome.hu (mag.webhome.hu [212.52.168.15]) by mail.postgresql.org (Postfix) with ESMTP id 537C2B5DBEE for ; Wed, 2 Nov 2011 10:53:05 -0300 (ADT) Received: from mxln133738.res.hu.corp (mag.webhome.hu [127.0.0.1]) by mag.webhome.hu (Postfix) with ESMTPS id 1CE6517E9 for ; Wed, 2 Nov 2011 13:45:46 +0000 (UTC) Message-ID: <4EB1498A.4080400@magwas.rulez.org> Date: Wed, 02 Nov 2011 14:45:46 +0100 From: =?UTF-8?B?TWFnb3PDoW55aSDDgXJww6Fk?= User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.20) Gecko/20110805 Lightning/1.0b2 Thunderbird/3.1.12 MIME-Version: 1.0 To: pgsql-jdbc@postgresql.org Subject: Trouble setting up ssl cert authentication from java/hibernate Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201111/1 X-Sequence-Number: 22336 Hi! I have a server which authenticates with ssl certificates. I have no=20 trouble using it with psql. However I cannot figure out how to do the same with java. I have added=20 my private key and cert along with the CA cert to my keystore. I set the javax.net.ssl.trustStore and javax.net.ssl.trustStorePassword=20 properties. But it seems that the underlying ssl does not use my=20 certificate/key. Both the server and client reports "FATAL: connection requires a valid=20 client certificate" What am I doing wrong? The juice of my hibernate config is: jdbc:postgresql://localhost:5433/archi?= sslmode=3Drequired&ssl=3Dtrue& mag org.hibernate.dialect.PostgreSQLDialect The juice of my test case: String password =3D new PasswordDialog(new Shell()).ask(); System.out.println("keystore=20 path=3D"+System.getProperty("javax.net.ssl.trustStore")); File keystorepath =3D new=20 File(System.getProperty("user.home"),".keystore"); =20 System.setProperty("javax.net.ssl.trustStore",keystorepath.getAbsolutePat= h()); System.setProperty("javax.net.ssl.trustStorePassword", password)= ; System.out.println("keystore=20 path=3D"+System.getProperty("javax.net.ssl.trustStore")); System.out.println("keystore=20 pwd=3D"+System.getProperty("javax.net.ssl.trustStorePassword")); Session session =3D getSessionFactory().getCurrentSession(); System.out.println("session=3D"+session); session.beginTransaction(); // dies here You can find the full code at commit=20 8c35c887d973fed1ba6eccdcc7726a11ebfe0612 of=20 git@github.com:magwas/org.rulez.magwas.styledhtml.git org.rulez.magwas.enterprise/src/org/rulez/magwas/enterprise/repository/Re= poFactoryTest.java And the stack trace: org.hibernate.exception.GenericJDBCException: Cannot open connection at=20 org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQL= StateConverter.java:140) at=20 org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:= 128) at=20 org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.j= ava:66) at=20 org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.j= ava:52) at=20 org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.jav= a:449) at=20 org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java= :167) at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:142) at=20 org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:85) at=20 org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1463) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at=20 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java= :57) at=20 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorI= mpl.java:43) at java.lang.reflect.Method.invoke(Method.java:616) at=20 org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrap= per.invoke(ThreadLocalSessionContext.java:344) at $Proxy5.beginTransaction(Unknown Source) at=20 org.rulez.magwas.enterprise.repository.RepoFactoryTest.test(RepoFactoryTe= st.java:28) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at=20 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java= :57) at=20 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorI= mpl.java:43) at java.lang.reflect.Method.invoke(Method.java:616) at=20 org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMeth= od.java:44) at=20 org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallabl= e.java:15) at=20 org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod= =2Ejava:41) at=20 org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.= java:20) at=20 org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRu= nner.java:79) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.= java:71) at=20 org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.= java:49) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)= at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184) at org.junit.runners.ParentRunner.run(ParentRunner.java:236) at=20 org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4Test= Reference.java:50) at=20 org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.jav= a:38) at=20 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTes= tRunner.java:467) at=20 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTes= tRunner.java:683) at=20 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunn= er.java:390) at=20 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRun= ner.java:197) Caused by: org.postgresql.util.PSQLException: FATAL: connection requires = a valid client certificate at=20 org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionF= actoryImpl.java:291) at=20 org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(Connectio= nFactoryImpl.java:108) at=20 org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.ja= va:66) at=20 org.postgresql.jdbc2.AbstractJdbc2Connection.(AbstractJdbc2Connecti= on.java:125) at=20 org.postgresql.jdbc3.AbstractJdbc3Connection.(AbstractJdbc3Connecti= on.java:30) at org.postgresql.jdbc3.Jdbc3Connection.(Jdbc3Connection.java:= 24) at org.postgresql.Driver.makeConnection(Driver.java:393) at org.postgresql.Driver.connect(Driver.java:267) at java.sql.DriverManager.getConnection(DriverManager.java:620) at java.sql.DriverManager.getConnection(DriverManager.java:169) at=20 org.hibernate.connection.DriverManagerConnectionProvider.getConnection(Dr= iverManagerConnectionProvider.java:133) at=20 org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.jav= a:446) ... 34 more