Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g0Qf8-00043T-J6 for pgsql-jdbc@arkaria.postgresql.org; Thu, 13 Sep 2018 12:23:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1g0Qf5-0000ti-Ah for pgsql-jdbc@arkaria.postgresql.org; Thu, 13 Sep 2018 12:23:55 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g0Qf5-0000tb-2o for pgsql-jdbc@lists.postgresql.org; Thu, 13 Sep 2018 12:23:55 +0000 Received: from mail.sonicle.com ([62.173.161.2]) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1g0Qex-0000SV-GY for pgsql-jdbc@lists.postgresql.org; Thu, 13 Sep 2018 12:23:54 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.sonicle.com (Postfix) with ESMTP id ED0E762DA29 for ; Thu, 13 Sep 2018 14:23:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=sonicle.com; h= content-type:content-type:mime-version:subject:subject :references:in-reply-to:message-id:from:from:date:date:received :received; s=dkim; t=1536841425; x=1538655826; bh=Xpk8+QEe2CA/ek 55OH/sjxHNKKDOrxW4HwCROZ+ifVc=; b=XS+86pl5YVfHxXIycfVz/7VWqrzDR3 bwZxSJ38K+kRQwbrFonfQyOn8CaXQJCdHmI/muxLIZDj4bKOUNifzohMve6rXEtq +TlpCMdSfYnOwGEwljNtXE6Dgg30CSnQLUTgIM15bHem11Rf33OvD6AXEIC99ra3 beh1gynOrn9I8= Received: from www ([127.0.0.1]) by localhost (mail.sonicle.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id b4maPDumuJWj for ; Thu, 13 Sep 2018 14:23:45 +0200 (CEST) Received: from www (www [192.168.222.200]) by www with SMTP (SubEthaSMTP 3.1.7) id JM0JPDJZ for pgsql-jdbc@lists.postgresql.org; Thu, 13 Sep 2018 14:23:45 +0200 (CEST) Date: Thu, 13 Sep 2018 14:23:45 +0200 (CEST) From: Gabriele Bulfon To: pgsql-jdbc@lists.postgresql.org Message-ID: <652759681.5047.1536841425886@www> In-Reply-To: References: Subject: ssl connection issues MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_5045_331632430.1536841425885" Forwarded-From: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk ------=_Part_5045_331632430.1536841425885 Content-Type: multipart/alternative; boundary="----=_Part_5046_832012322.1536841425885" ------=_Part_5046_832012322.1536841425885 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hello, =C2=A0 I recently configured Postgresql 9.0.9 with SSL only "on" and all its neede= d server certificates. I then created the client certificates and started working with them from a= windows client. =C2=A0 At first I used them with tools like Navicat, just specified the 3 certs fi= les (key,crt and root.crt) in the ssl pane, worked fine. =C2=A0 Then I tried with ODBC,=C2=A0placed the files in %APPDATA%/postgresql with = correct names (postgresql.key, postgresql.crt, root.crt), created the conne= ction and tested it, worked fine. =C2=A0 Last I tried with jdbc, thinking it would have been so easy: I'm fighting f= or 2 days with lots of different issues. After some messing, I also finally discovered that, different from odbc, it= would look for a pk8 file (why this difference?). I created the pk8 file on the server from the original key used for odbc, w= ith the command: # openssl pkcs8 -topk8 -in client.key -out client.pk8 -outform DER -nocrypt placed the pk8 file in=C2=A0 %APPDATA%/postgresql and launched my test java connection: =C2=A0 Connection con=3DDriverManager.getConnection("jdbc:postgresql://myhost:5432= /mydb?ssl=3Dtrue&loggerLevel=3DDEBUG&sslfactory=3Dorg.postgresql.ssl.jdbc4.= LibPQFactory&sslmode=3Drequire","user","pass"); =C2=A0 And now I get this: =C2=A0 Exception in thread "main" org.postgresql.util.PSQLException: SSL error: Re= ceived fatal alert: decrypt_error at org.postgresql.ssl.MakeSSL.convert(MakeSSL.java:42) at org.postgresql.core.v3.ConnectionFactoryImpl.enableSSL(ConnectionFactory= Impl.java:435) at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactor= yImpl.java:94) at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(Connecti= onFactoryImpl.java:192) at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.j= ava:49) at org.postgresql.jdbc.PgConnection. (PgConnection.java:195) at org.postgresql.Driver.makeConnection(Driver.java:454) at org.postgresql.Driver.connect(Driver.java:256) at java.sql.DriverManager.getConnection(DriverManager.java:664) at java.sql.DriverManager.getConnection(DriverManager.java:247) at com.sonicle.aliseo.server.TestPostgresSSL.main(TestPostgresSSL.java:23) Caused by: javax.net.ssl.SSLHandshakeException: Received fatal alert: decry= pt_error at sun.security.ssl.Alerts.getSSLException(Alerts.java:192) at sun.security.ssl.Alerts.getSSLException(Alerts.java:154) at sun.security.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:2023) at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1125) at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.jav= a:1375) at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1403) at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1387) at org.postgresql.ssl.MakeSSL.convert(MakeSSL.java:40) ... 10 more =C2=A0 Tried both with jdk1.7 and jdk1.8 and openjdk1.8. =C2=A0 Any idea? Gabriele Sonicle S.r.l.=C2=A0 :=C2=A0 http://www.sonicle.com Music:=C2=A0 http://www.gabrielebulfon.com Quantum Mechanics :=C2=A0 http://www.cdbaby.com/cd/gabrielebulfon ------=_Part_5046_832012322.1536841425885 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hello,
 =
I rece= ntly configured Postgresql 9.0.9 with SSL only "on" and all its needed serv= er certificates.
I then= created the client certificates and started working with them from a windo= ws client.
 =
At fir= st I used them with tools like Navicat, just specified the 3 certs files (k= ey,crt and root.crt) in the ssl pane, worked fine.
 =
Then I= tried with ODBC, placed the files in %APPDATA%/postgresql with correc= t names (postgresql.key, postgresql.crt, root.crt), created the connection = and tested it, worked fine.
 =
Last I= tried with jdbc, thinking it would have been so easy: I'm fighting for 2 d= ays with lots of different issues.
After = some messing, I also finally discovered that, different from odbc, it would= look for a pk8 file (why this difference?).
I crea= ted the pk8 file on the server from the original key used for odbc, with th= e command:
# open= ssl pkcs8 -topk8 -in client.key -out client.pk8 -outform DER -nocrypt
placed= the pk8 file in %APPDATA%/postgresql and launched my test java = connection:
 =
Connec= tion con=3DDriverManager.getConnection("jdbc:postgresql://myhost:5432/mydb?= ssl=3Dtrue&loggerLevel=3DDEBUG&sslfactory=3Dorg.postgresql.ssl.jdbc= 4.LibPQFactory&sslmode=3Drequire","user","pass");
 =
And no= w I get this:
 =
Except= ion in thread "main" org.postgresql.util.PSQLException: SSL error: Received= fatal alert: decrypt_error
at org.postgresql.ssl.MakeSSL.convert(MakeS= SL.java:42)
at org.postgresql.core.v3.ConnectionFactoryImpl.enableSSL(C= onnectionFactoryImpl.java:435)
at org.postgresql.core.v3.ConnectionFact= oryImpl.tryConnect(ConnectionFactoryImpl.java:94)
at org.postgresql.cor= e.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:19= 2)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFa= ctory.java:49)
at org.postgresql.jdbc.PgConnection.<init>(PgConne= ction.java:195)
at org.postgresql.Driver.makeConnection(Driver.java:454= )
at org.postgresql.Driver.connect(Driver.java:256)
at java.sql.Dri= verManager.getConnection(DriverManager.java:664)
at java.sql.DriverMana= ger.getConnection(DriverManager.java:247)
at com.sonicle.aliseo.server.= TestPostgresSSL.main(TestPostgresSSL.java:23)
Caused by: javax.net.ssl.S= SLHandshakeException: Received fatal alert: decrypt_error
at sun.securi= ty.ssl.Alerts.getSSLException(Alerts.java:192)
at sun.security.ssl.Aler= ts.getSSLException(Alerts.java:154)
at sun.security.ssl.SSLSocketImpl.r= ecvAlert(SSLSocketImpl.java:2023)
at sun.security.ssl.SSLSocketImpl.rea= dRecord(SSLSocketImpl.java:1125)
at sun.security.ssl.SSLSocketImpl.perf= ormInitialHandshake(SSLSocketImpl.java:1375)
at sun.security.ssl.SSLSoc= ketImpl.startHandshake(SSLSocketImpl.java:1403)
at sun.security.ssl.SSL= SocketImpl.startHandshake(SSLSocketImpl.java:1387)
at org.postgresql.ss= l.MakeSSL.convert(MakeSSL.java:40)
... 10 more
 =
Tried = both with jdk1.7 and jdk1.8 and openjdk1.8.
 =
Any id= ea?
Gabriele

------=_Part_5046_832012322.1536841425885-- ------=_Part_5045_331632430.1536841425885--