Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 9CE86B5DE82 for ; Wed, 2 Nov 2011 14:12:42 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 68381-05-3 for ; Wed, 2 Nov 2011 17:12:34 +0000 (UTC) X-Greylist: from auto-whitelisted 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 15D01B5DE87 for ; Wed, 2 Nov 2011 14:12:32 -0300 (ADT) Received: from mxln133738.res.hu.corp (mag.webhome.hu [127.0.0.1]) by mag.webhome.hu (Postfix) with ESMTPS id B6D98192A for ; Wed, 2 Nov 2011 17:12:30 +0000 (UTC) Message-ID: <4EB179FD.90909@magwas.rulez.org> Date: Wed, 02 Nov 2011 18:12:29 +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: Re: Trouble setting up ssl cert authentication from java/hibernate References: <4EB1498A.4080400@magwas.rulez.org> In-Reply-To: <4EB1498A.4080400@magwas.rulez.org> 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=-0.778 tagged_above=-10 required=5 tests=BAYES_00=-1.9, URI_HEX=1.122 X-Spam-Level: X-Archive-Number: 201111/2 X-Sequence-Number: 22337 Hi! Well, I was able to connect using a CertAuthfactory method copied from=20 http://postgresql.1045698.n5.nabble.com/attachment/4405851/0/CertAuthFact= ory.java Should I consider it a workaround or the canonical solution? It WORKSFORME, but I have seen mentioned that the driver supports=20 certificate authentication out of the box by just configuring the=20 underlying ssl. Solution is in commit 21a2edb4e43be142a70493bd4041eb64678faa32. On 2011-11-02 14:45, Magos=C3=A1nyi =C3=81rp=C3=A1d wrote: > 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 = > my private key and cert along with the CA cert to my keystore. > I set the javax.net.ssl.trustStore and=20 > javax.net.ssl.trustStorePassword properties. But it seems that the=20 > underlying ssl does not use my certificate/key. > Both the server and client reports "FATAL: connection requires a=20 > valid client certificate" > What am I doing wrong? > > The juice of my hibernate config is: > name=3D"hibernate.connection.url">jdbc:postgresql://localhost:5433/arch= i?sslmode=3Drequired&ssl=3Dtrue& > mag > name=3D"hibernate.dialect">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.getAbsoluteP= ath()); > 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/= RepoFactoryTest.java=20 > > > And the stack trace: > > org.hibernate.exception.GenericJDBCException: Cannot open connection > at=20 > org.hibernate.exception.SQLStateConverter.handledNonSpecificException(S= QLStateConverter.java:140) > at=20 > org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.jav= a:128) > at=20 > org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper= =2Ejava:66) > at=20 > org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper= =2Ejava:52) > at=20 > org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.j= ava:449) > at=20 > org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.ja= va: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.ja= va:57) > at=20 > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccesso= rImpl.java:43) > at java.lang.reflect.Method.invoke(Method.java:616) > at=20 > org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWr= apper.invoke(ThreadLocalSessionContext.java:344) > at $Proxy5.beginTransaction(Unknown Source) > at=20 > org.rulez.magwas.enterprise.repository.RepoFactoryTest.test(RepoFactory= Test.java:28) > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > at=20 > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.ja= va:57) > at=20 > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccesso= rImpl.java:43) > at java.lang.reflect.Method.invoke(Method.java:616) > at=20 > org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMe= thod.java:44) > at=20 > org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCalla= ble.java:15) > at=20 > org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMeth= od.java:41) > at=20 > org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMetho= d.java:20) > at=20 > org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4Class= Runner.java:79) > at > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunne= r.java:71)=20 > > at=20 > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunne= r.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(JUnit4Te= stReference.java:50) > at=20 > org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.j= ava:38) > at=20 > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteT= estRunner.java:467) > at=20 > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteT= estRunner.java:683) > at=20 > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRu= nner.java:390) > at=20 > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestR= unner.java:197) > Caused by: org.postgresql.util.PSQLException: FATAL: connection=20 > requires a valid client certificate > at=20 > org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(Connectio= nFactoryImpl.java:291) > at=20 > org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(Connect= ionFactoryImpl.java:108) > at=20 > org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.= java:66) > at=20 > org.postgresql.jdbc2.AbstractJdbc2Connection.(AbstractJdbc2Connec= tion.java:125) > at=20 > org.postgresql.jdbc3.AbstractJdbc3Connection.(AbstractJdbc3Connec= tion.java:30) > at=20 > 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(= DriverManagerConnectionProvider.java:133) > at=20 > org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.j= ava:446) > ... 34 more > > > >