pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
JDBC with SSL
25+ messages / 10 participants
[nested] [flat]

* JDBC with SSL
@ 2003-03-27 21:40 John Laban <johnl@infotn.com>
  2003-03-27 22:58 ` Re: JDBC with SSL Barry Lind <blind@xythos.com>
  0 siblings, 1 reply; 25+ messages in thread

From: John Laban @ 2003-03-27 21:40 UTC (permalink / raw)
  To: pgsql-jdbc

Hello,

The newest developement JDBC drivers (7.4dev, build 204, 2003-03-23) say they include support for SSL.  I can set up the server to use SSL, but I can't seem to get the JDBC driver to actually connect using SSL.  Is there any documentation on this?  Or is there a specific parameter I am supposed to include in the connection URL?

Any help in this would be appreciated.

John Laban

^ permalink  raw  reply  [nested|flat] 25+ messages in thread

* Re: JDBC with SSL
  2003-03-27 21:40 JDBC with SSL John Laban <johnl@infotn.com>
@ 2003-03-27 22:58 ` Barry Lind <blind@xythos.com>
  2003-03-28 16:01   ` Re: JDBC with SSL John Laban <johnl@infotn.com>
  0 siblings, 1 reply; 25+ messages in thread

From: Barry Lind @ 2003-03-27 22:58 UTC (permalink / raw)
  To: John Laban <johnl@infotn.com>; +Cc: pgsql-jdbc

John,

This hasn't yet made it to the documentation.

but adding ?ssl to the url should be what you need.  (also consider 
using &loglevel=2 to turn on debugging info).

--Barry

John Laban wrote:
> Hello,
> 
> The newest developement JDBC drivers (7.4dev, build 204, 2003-03-23) say they include support for SSL.  I can set up the server to use SSL, but I can't seem to get the JDBC driver to actually connect using SSL.  Is there any documentation on this?  Or is there a specific parameter I am supposed to include in the connection URL?
> 
> Any help in this would be appreciated.
> 
> John Laban
> 




^ permalink  raw  reply  [nested|flat] 25+ messages in thread

* Re: JDBC with SSL
  2003-03-27 21:40 JDBC with SSL John Laban <johnl@infotn.com>
  2003-03-27 22:58 ` Re: JDBC with SSL Barry Lind <blind@xythos.com>
@ 2003-03-28 16:01   ` John Laban <johnl@infotn.com>
  2003-03-28 16:11     ` Re: JDBC with SSL Barry Lind <blind@xythos.com>
  0 siblings, 1 reply; 25+ messages in thread

From: John Laban @ 2003-03-28 16:01 UTC (permalink / raw)
  To: Barry Lind <blind@xythos.com>; +Cc: pgsql-jdbc

Thanks for the quick reply, but I'm still having some difficulty.

I have been trying to connect to postgresql (redhat version 7.2.3.1) using
JDBC and SSL - I am using the 7.4 development driver.

I know that the server side is set up correctly because when connecting
using psql the connection is established using SSL.


However when connecting via JDBC I receive




PostgreSQL 7.4devel JDBC3 with SSL (build 204)

    ssl = true

    compatible = 7.4

    loglevel = 2

Asking server if it supports ssl

Server response was (S=Yes,N=No): S

server does support ssl

converting regular socket connection to ssl



            at org.postgresql.core.PGStream.flush(PGStream.java:364)

            at
org.postgresql.jdbc1.AbstractJdbc1Connection.openConnection(AbstractJdbc1Con
nection.java:269)

            at org.postgresql.Driver.connect(Driver.java:137)

            at java.sql.DriverManager.getConnection(DriverManager.java:512)

            at java.sql.DriverManager.getConnection(DriverManager.java:140)

            at docextractor.test.main(test.java:35)


Exception: An I/O error has occured while flushing the output - Exception:
javax.net.ssl.SSLHandshakeException:
java.security.cert.CertificateException: Couldn't find trusted certificate

Stack Trace:



javax.net.ssl.SSLHandshakeException:
java.security.cert.CertificateException: Couldn't find trusted certificate

            at com.sun.net.ssl.internal.ssl.BaseSSLSocketImpl.a(DashoA6275)

            at com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA6275)

            at com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA6275)

            at com.sun.net.ssl.internal.ssl.SunJSSE_az.a(DashoA6275)

            at com.sun.net.ssl.internal.ssl.SunJSSE_az.a(DashoA6275)

            at com.sun.net.ssl.internal.ssl.SunJSSE_ax.a(DashoA6275)

            at com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA6275)

            at com.sun.net.ssl.internal.ssl.SSLSocketImpl.j(DashoA6275)

            at com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA6275)

            at
com.sun.net.ssl.internal.ssl.AppOutputStream.write(DashoA6275)

            at
java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:69)

            at
java.io.BufferedOutputStream.flush(BufferedOutputStream.java:127)

            at org.postgresql.core.PGStream.flush(PGStream.java:360)

            at
org.postgresql.jdbc1.AbstractJdbc1Connection.openConnection(AbstractJdbc1Con
nection.java:269)

            at org.postgresql.Driver.connect(Driver.java:137)

            at java.sql.DriverManager.getConnection(DriverManager.java:512)

            at java.sql.DriverManager.getConnection(DriverManager.java:140)

            at docextractor.test.main(test.java:35)


Caused by: java.security.cert.CertificateException: Couldn't find trusted
certificate


            at
com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.a(DashoA6275)

            at
com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(DashoA6
275)

            at
com.sun.net.ssl.internal.ssl.JsseX509TrustManager.checkServerTrusted(DashoA6
275)

            ... 15 more


End of Stack Trace





At the server side I get



Failed to inititalize SSL Connection: sslv3 alert certificate unknown
(Success)




I have not been able to find any clear resolutions to this problem. If
someone can shed some light on a solution to this problem it would be
greatly appreciated.



----- Original Message -----
From: "Barry Lind" <blind@xythos.com>
To: "John Laban" <johnl@infotn.com>
Cc: <pgsql-jdbc@postgresql.org>
Sent: Thursday, March 27, 2003 5:58 PM
Subject: Re: [JDBC] JDBC with SSL


> John,
>
> This hasn't yet made it to the documentation.
>
> but adding ?ssl to the url should be what you need.  (also consider
> using &loglevel=2 to turn on debugging info).
>
> --Barry
>
> John Laban wrote:
> > Hello,
> >
> > The newest developement JDBC drivers (7.4dev, build 204, 2003-03-23) say
they include support for SSL.  I can set up the server to use SSL, but I
can't seem to get the JDBC driver to actually connect using SSL.  Is there
any documentation on this?  Or is there a specific parameter I am supposed
to include in the connection URL?
> >
> > Any help in this would be appreciated.
> >
> > John Laban
> >
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/docs/faqs/FAQ.html




^ permalink  raw  reply  [nested|flat] 25+ messages in thread

* Re: JDBC with SSL
  2003-03-27 21:40 JDBC with SSL John Laban <johnl@infotn.com>
  2003-03-27 22:58 ` Re: JDBC with SSL Barry Lind <blind@xythos.com>
  2003-03-28 16:01   ` Re: JDBC with SSL John Laban <johnl@infotn.com>
@ 2003-03-28 16:11     ` Barry Lind <blind@xythos.com>
  2003-03-28 17:06       ` Re: JDBC with SSL John Laban <johnl@infotn.com>
  0 siblings, 1 reply; 25+ messages in thread

From: Barry Lind @ 2003-03-28 16:11 UTC (permalink / raw)
  To: John Laban <johnl@infotn.com>; +Cc: pgsql-jdbc

John,

The error message indicates that your client doesn't trust the servers 
certificate.  My guess is that you are using a self-signed certificate 
on the server.  If you want to be able to connect you are going to need 
to import that certificate into the client side java certificate store 
so that it recognizes the self-signed certificate as valid and trusted.

thanks,
--Barry


John Laban wrote:
> Thanks for the quick reply, but I'm still having some difficulty.
> 
> I have been trying to connect to postgresql (redhat version 7.2.3.1) using
> JDBC and SSL - I am using the 7.4 development driver.
> 
> I know that the server side is set up correctly because when connecting
> using psql the connection is established using SSL.
> 
> 
> However when connecting via JDBC I receive
> 
> 
> 
> 
> PostgreSQL 7.4devel JDBC3 with SSL (build 204)
> 
>     ssl = true
> 
>     compatible = 7.4
> 
>     loglevel = 2
> 
> Asking server if it supports ssl
> 
> Server response was (S=Yes,N=No): S
> 
> server does support ssl
> 
> converting regular socket connection to ssl
> 
> 
> 
>             at org.postgresql.core.PGStream.flush(PGStream.java:364)
> 
>             at
> org.postgresql.jdbc1.AbstractJdbc1Connection.openConnection(AbstractJdbc1Con
> nection.java:269)
> 
>             at org.postgresql.Driver.connect(Driver.java:137)
> 
>             at java.sql.DriverManager.getConnection(DriverManager.java:512)
> 
>             at java.sql.DriverManager.getConnection(DriverManager.java:140)
> 
>             at docextractor.test.main(test.java:35)
> 
> 
> Exception: An I/O error has occured while flushing the output - Exception:
> javax.net.ssl.SSLHandshakeException:
> java.security.cert.CertificateException: Couldn't find trusted certificate
> 
> Stack Trace:
> 
> 
> 
> javax.net.ssl.SSLHandshakeException:
> java.security.cert.CertificateException: Couldn't find trusted certificate
> 
>             at com.sun.net.ssl.internal.ssl.BaseSSLSocketImpl.a(DashoA6275)
> 
>             at com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA6275)
> 
>             at com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA6275)
> 
>             at com.sun.net.ssl.internal.ssl.SunJSSE_az.a(DashoA6275)
> 
>             at com.sun.net.ssl.internal.ssl.SunJSSE_az.a(DashoA6275)
> 
>             at com.sun.net.ssl.internal.ssl.SunJSSE_ax.a(DashoA6275)
> 
>             at com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA6275)
> 
>             at com.sun.net.ssl.internal.ssl.SSLSocketImpl.j(DashoA6275)
> 
>             at com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA6275)
> 
>             at
> com.sun.net.ssl.internal.ssl.AppOutputStream.write(DashoA6275)
> 
>             at
> java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:69)
> 
>             at
> java.io.BufferedOutputStream.flush(BufferedOutputStream.java:127)
> 
>             at org.postgresql.core.PGStream.flush(PGStream.java:360)
> 
>             at
> org.postgresql.jdbc1.AbstractJdbc1Connection.openConnection(AbstractJdbc1Con
> nection.java:269)
> 
>             at org.postgresql.Driver.connect(Driver.java:137)
> 
>             at java.sql.DriverManager.getConnection(DriverManager.java:512)
> 
>             at java.sql.DriverManager.getConnection(DriverManager.java:140)
> 
>             at docextractor.test.main(test.java:35)
> 
> 
> Caused by: java.security.cert.CertificateException: Couldn't find trusted
> certificate
> 
> 
>             at
> com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.a(DashoA6275)
> 
>             at
> com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(DashoA6
> 275)
> 
>             at
> com.sun.net.ssl.internal.ssl.JsseX509TrustManager.checkServerTrusted(DashoA6
> 275)
> 
>             ... 15 more
> 
> 
> End of Stack Trace
> 
> 
> 
> 
> 
> At the server side I get
> 
> 
> 
> Failed to inititalize SSL Connection: sslv3 alert certificate unknown
> (Success)
> 
> 
> 
> 
> I have not been able to find any clear resolutions to this problem. If
> someone can shed some light on a solution to this problem it would be
> greatly appreciated.
> 
> 
> 
> ----- Original Message -----
> From: "Barry Lind" <blind@xythos.com>
> To: "John Laban" <johnl@infotn.com>
> Cc: <pgsql-jdbc@postgresql.org>
> Sent: Thursday, March 27, 2003 5:58 PM
> Subject: Re: [JDBC] JDBC with SSL
> 
> 
> 
>>John,
>>
>>This hasn't yet made it to the documentation.
>>
>>but adding ?ssl to the url should be what you need.  (also consider
>>using &loglevel=2 to turn on debugging info).
>>
>>--Barry
>>
>>John Laban wrote:
>>
>>>Hello,
>>>
>>>The newest developement JDBC drivers (7.4dev, build 204, 2003-03-23) say
> 
> they include support for SSL.  I can set up the server to use SSL, but I
> can't seem to get the JDBC driver to actually connect using SSL.  Is there
> any documentation on this?  Or is there a specific parameter I am supposed
> to include in the connection URL?
> 
>>>Any help in this would be appreciated.
>>>
>>>John Laban
>>>
>>
>>
>>---------------------------(end of broadcast)---------------------------
>>TIP 5: Have you checked our extensive FAQ?
>>
>>http://www.postgresql.org/docs/faqs/FAQ.html
> 
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
> 
> http://archives.postgresql.org
> 




^ permalink  raw  reply  [nested|flat] 25+ messages in thread

* Re: JDBC with SSL
  2003-03-27 21:40 JDBC with SSL John Laban <johnl@infotn.com>
  2003-03-27 22:58 ` Re: JDBC with SSL Barry Lind <blind@xythos.com>
  2003-03-28 16:01   ` Re: JDBC with SSL John Laban <johnl@infotn.com>
  2003-03-28 16:11     ` Re: JDBC with SSL Barry Lind <blind@xythos.com>
@ 2003-03-28 17:06       ` John Laban <johnl@infotn.com>
  2003-03-28 17:48         ` Re: JDBC with SSL Csaba Nagy <nagy@ecircle-ag.com>
  2003-03-28 18:50         ` Re: JDBC with SSL Barry Lind <blind@xythos.com>
  2003-03-28 19:07         ` Re: JDBC with SSL Nagy Istvan <nistvan@ecity.agria.hu>
  0 siblings, 3 replies; 25+ messages in thread

From: John Laban @ 2003-03-28 17:06 UTC (permalink / raw)
  To: Barry Lind <blind@xythos.com>; +Cc: pgsql-jdbc

Hello again,

I have made numerous attempts to import the certificate from the server to
the client machine using java keytool with no success - the keytool
complains that the file is not a valid X.509 format.

Additionally, for my application, only the encryption of the channel is
important so if it is possible to create an ssl connection without the
authentication portion that would be the best solution.


However I would still appreciate any information on how to import the
certificate (as generated using the Postgresql documention) into the java
certificate store.



----- Original Message -----
From: "Barry Lind" <blind@xythos.com>
To: "John Laban" <johnl@infotn.com>
Cc: <pgsql-jdbc@postgresql.org>
Sent: Friday, March 28, 2003 11:11 AM
Subject: Re: [JDBC] JDBC with SSL


> John,
>
> The error message indicates that your client doesn't trust the servers
> certificate.  My guess is that you are using a self-signed certificate
> on the server.  If you want to be able to connect you are going to need
> to import that certificate into the client side java certificate store
> so that it recognizes the self-signed certificate as valid and trusted.
>
> thanks,
> --Barry
>
>
> John Laban wrote:
> > Thanks for the quick reply, but I'm still having some difficulty.
> >
> > I have been trying to connect to postgresql (redhat version 7.2.3.1)
using
> > JDBC and SSL - I am using the 7.4 development driver.
> >
> > I know that the server side is set up correctly because when connecting
> > using psql the connection is established using SSL.
> >
> >
> > However when connecting via JDBC I receive
> >
> >
> >
> >
> > PostgreSQL 7.4devel JDBC3 with SSL (build 204)
> >
> >     ssl = true
> >
> >     compatible = 7.4
> >
> >     loglevel = 2
> >
> > Asking server if it supports ssl
> >
> > Server response was (S=Yes,N=No): S
> >
> > server does support ssl
> >
> > converting regular socket connection to ssl
> >
> >
> >
> >             at org.postgresql.core.PGStream.flush(PGStream.java:364)
> >
> >             at
> >
org.postgresql.jdbc1.AbstractJdbc1Connection.openConnection(AbstractJdbc1Con
> > nection.java:269)
> >
> >             at org.postgresql.Driver.connect(Driver.java:137)
> >
> >             at
java.sql.DriverManager.getConnection(DriverManager.java:512)
> >
> >             at
java.sql.DriverManager.getConnection(DriverManager.java:140)
> >
> >             at docextractor.test.main(test.java:35)
> >
> >
> > Exception: An I/O error has occured while flushing the output -
Exception:
> > javax.net.ssl.SSLHandshakeException:
> > java.security.cert.CertificateException: Couldn't find trusted
certificate
> >
> > Stack Trace:
> >
> >
> >
> > javax.net.ssl.SSLHandshakeException:
> > java.security.cert.CertificateException: Couldn't find trusted
certificate
> >
> >             at
com.sun.net.ssl.internal.ssl.BaseSSLSocketImpl.a(DashoA6275)
> >
> >             at com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA6275)
> >
> >             at com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA6275)
> >
> >             at com.sun.net.ssl.internal.ssl.SunJSSE_az.a(DashoA6275)
> >
> >             at com.sun.net.ssl.internal.ssl.SunJSSE_az.a(DashoA6275)
> >
> >             at com.sun.net.ssl.internal.ssl.SunJSSE_ax.a(DashoA6275)
> >
> >             at com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA6275)
> >
> >             at com.sun.net.ssl.internal.ssl.SSLSocketImpl.j(DashoA6275)
> >
> >             at com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA6275)
> >
> >             at
> > com.sun.net.ssl.internal.ssl.AppOutputStream.write(DashoA6275)
> >
> >             at
> > java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:69)
> >
> >             at
> > java.io.BufferedOutputStream.flush(BufferedOutputStream.java:127)
> >
> >             at org.postgresql.core.PGStream.flush(PGStream.java:360)
> >
> >             at
> >
org.postgresql.jdbc1.AbstractJdbc1Connection.openConnection(AbstractJdbc1Con
> > nection.java:269)
> >
> >             at org.postgresql.Driver.connect(Driver.java:137)
> >
> >             at
java.sql.DriverManager.getConnection(DriverManager.java:512)
> >
> >             at
java.sql.DriverManager.getConnection(DriverManager.java:140)
> >
> >             at docextractor.test.main(test.java:35)
> >
> >
> > Caused by: java.security.cert.CertificateException: Couldn't find
trusted
> > certificate
> >
> >
> >             at
> > com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.a(DashoA6275)
> >
> >             at
> >
com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(DashoA6
> > 275)
> >
> >             at
> >
com.sun.net.ssl.internal.ssl.JsseX509TrustManager.checkServerTrusted(DashoA6
> > 275)
> >
> >             ... 15 more
> >
> >
> > End of Stack Trace
> >
> >
> >
> >
> >
> > At the server side I get
> >
> >
> >
> > Failed to inititalize SSL Connection: sslv3 alert certificate unknown
> > (Success)
> >
> >
> >
> >
> > I have not been able to find any clear resolutions to this problem. If
> > someone can shed some light on a solution to this problem it would be
> > greatly appreciated.
> >
> >
> >
> > ----- Original Message -----
> > From: "Barry Lind" <blind@xythos.com>
> > To: "John Laban" <johnl@infotn.com>
> > Cc: <pgsql-jdbc@postgresql.org>
> > Sent: Thursday, March 27, 2003 5:58 PM
> > Subject: Re: [JDBC] JDBC with SSL
> >
> >
> >
> >>John,
> >>
> >>This hasn't yet made it to the documentation.
> >>
> >>but adding ?ssl to the url should be what you need.  (also consider
> >>using &loglevel=2 to turn on debugging info).
> >>
> >>--Barry
> >>
> >>John Laban wrote:
> >>
> >>>Hello,
> >>>
> >>>The newest developement JDBC drivers (7.4dev, build 204, 2003-03-23)
say
> >
> > they include support for SSL.  I can set up the server to use SSL, but I
> > can't seem to get the JDBC driver to actually connect using SSL.  Is
there
> > any documentation on this?  Or is there a specific parameter I am
supposed
> > to include in the connection URL?
> >
> >>>Any help in this would be appreciated.
> >>>
> >>>John Laban
> >>>
> >>
> >>
> >>---------------------------(end of broadcast)---------------------------
> >>TIP 5: Have you checked our extensive FAQ?
> >>
> >>http://www.postgresql.org/docs/faqs/FAQ.html
> >
> >
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 6: Have you searched our list archives?
> >
> > http://archives.postgresql.org
> >
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://archives.postgresql.org




^ permalink  raw  reply  [nested|flat] 25+ messages in thread

* Re: JDBC with SSL
  2003-03-27 21:40 JDBC with SSL John Laban <johnl@infotn.com>
  2003-03-27 22:58 ` Re: JDBC with SSL Barry Lind <blind@xythos.com>
  2003-03-28 16:01   ` Re: JDBC with SSL John Laban <johnl@infotn.com>
  2003-03-28 16:11     ` Re: JDBC with SSL Barry Lind <blind@xythos.com>
  2003-03-28 17:06       ` Re: JDBC with SSL John Laban <johnl@infotn.com>
@ 2003-03-28 17:48         ` Csaba Nagy <nagy@ecircle-ag.com>
  2 siblings, 0 replies; 25+ messages in thread

From: Csaba Nagy @ 2003-03-28 17:48 UTC (permalink / raw)
  To: John Laban <johnl@infotn.com>; +Cc: Barry Lind <blind@xythos.com>; pgsql-jdbc

You can set the security provider (or something similar, read the
security docs) to your own implementation to permit any certificate.
You can do this on app initialization.
I did it once but forget how :D

HTH,
Csaba.

On Fri, 2003-03-28 at 18:06, John Laban wrote:
> Hello again,
> 
> I have made numerous attempts to import the certificate from the server to
> the client machine using java keytool with no success - the keytool
> complains that the file is not a valid X.509 format.
> 
> Additionally, for my application, only the encryption of the channel is
> important so if it is possible to create an ssl connection without the
> authentication portion that would be the best solution.
> 
> 
> However I would still appreciate any information on how to import the
> certificate (as generated using the Postgresql documention) into the java
> certificate store.
> 
> 
> 
> ----- Original Message -----
> From: "Barry Lind" <blind@xythos.com>
> To: "John Laban" <johnl@infotn.com>
> Cc: <pgsql-jdbc@postgresql.org>
> Sent: Friday, March 28, 2003 11:11 AM
> Subject: Re: [JDBC] JDBC with SSL
> 
> 
> > John,
> >
> > The error message indicates that your client doesn't trust the servers
> > certificate.  My guess is that you are using a self-signed certificate
> > on the server.  If you want to be able to connect you are going to need
> > to import that certificate into the client side java certificate store
> > so that it recognizes the self-signed certificate as valid and trusted.
> >
> > thanks,
> > --Barry
> >
> >
> > John Laban wrote:
> > > Thanks for the quick reply, but I'm still having some difficulty.
> > >
> > > I have been trying to connect to postgresql (redhat version 7.2.3.1)
> using
> > > JDBC and SSL - I am using the 7.4 development driver.
> > >
> > > I know that the server side is set up correctly because when connecting
> > > using psql the connection is established using SSL.
> > >
> > >
> > > However when connecting via JDBC I receive
> > >
> > >
> > >
> > >
> > > PostgreSQL 7.4devel JDBC3 with SSL (build 204)
> > >
> > >     ssl = true
> > >
> > >     compatible = 7.4
> > >
> > >     loglevel = 2
> > >
> > > Asking server if it supports ssl
> > >
> > > Server response was (S=Yes,N=No): S
> > >
> > > server does support ssl
> > >
> > > converting regular socket connection to ssl
> > >
> > >
> > >
> > >             at org.postgresql.core.PGStream.flush(PGStream.java:364)
> > >
> > >             at
> > >
> org.postgresql.jdbc1.AbstractJdbc1Connection.openConnection(AbstractJdbc1Con
> > > nection.java:269)
> > >
> > >             at org.postgresql.Driver.connect(Driver.java:137)
> > >
> > >             at
> java.sql.DriverManager.getConnection(DriverManager.java:512)
> > >
> > >             at
> java.sql.DriverManager.getConnection(DriverManager.java:140)
> > >
> > >             at docextractor.test.main(test.java:35)
> > >
> > >
> > > Exception: An I/O error has occured while flushing the output -
> Exception:
> > > javax.net.ssl.SSLHandshakeException:
> > > java.security.cert.CertificateException: Couldn't find trusted
> certificate
> > >
> > > Stack Trace:
> > >
> > >
> > >
> > > javax.net.ssl.SSLHandshakeException:
> > > java.security.cert.CertificateException: Couldn't find trusted
> certificate
> > >
> > >             at
> com.sun.net.ssl.internal.ssl.BaseSSLSocketImpl.a(DashoA6275)
> > >
> > >             at com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA6275)
> > >
> > >             at com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA6275)
> > >
> > >             at com.sun.net.ssl.internal.ssl.SunJSSE_az.a(DashoA6275)
> > >
> > >             at com.sun.net.ssl.internal.ssl.SunJSSE_az.a(DashoA6275)
> > >
> > >             at com.sun.net.ssl.internal.ssl.SunJSSE_ax.a(DashoA6275)
> > >
> > >             at com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA6275)
> > >
> > >             at com.sun.net.ssl.internal.ssl.SSLSocketImpl.j(DashoA6275)
> > >
> > >             at com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA6275)
> > >
> > >             at
> > > com.sun.net.ssl.internal.ssl.AppOutputStream.write(DashoA6275)
> > >
> > >             at
> > > java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:69)
> > >
> > >             at
> > > java.io.BufferedOutputStream.flush(BufferedOutputStream.java:127)
> > >
> > >             at org.postgresql.core.PGStream.flush(PGStream.java:360)
> > >
> > >             at
> > >
> org.postgresql.jdbc1.AbstractJdbc1Connection.openConnection(AbstractJdbc1Con
> > > nection.java:269)
> > >
> > >             at org.postgresql.Driver.connect(Driver.java:137)
> > >
> > >             at
> java.sql.DriverManager.getConnection(DriverManager.java:512)
> > >
> > >             at
> java.sql.DriverManager.getConnection(DriverManager.java:140)
> > >
> > >             at docextractor.test.main(test.java:35)
> > >
> > >
> > > Caused by: java.security.cert.CertificateException: Couldn't find
> trusted
> > > certificate
> > >
> > >
> > >             at
> > > com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.a(DashoA6275)
> > >
> > >             at
> > >
> com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(DashoA6
> > > 275)
> > >
> > >             at
> > >
> com.sun.net.ssl.internal.ssl.JsseX509TrustManager.checkServerTrusted(DashoA6
> > > 275)
> > >
> > >             ... 15 more
> > >
> > >
> > > End of Stack Trace
> > >
> > >
> > >
> > >
> > >
> > > At the server side I get
> > >
> > >
> > >
> > > Failed to inititalize SSL Connection: sslv3 alert certificate unknown
> > > (Success)
> > >
> > >
> > >
> > >
> > > I have not been able to find any clear resolutions to this problem. If
> > > someone can shed some light on a solution to this problem it would be
> > > greatly appreciated.
> > >
> > >
> > >
> > > ----- Original Message -----
> > > From: "Barry Lind" <blind@xythos.com>
> > > To: "John Laban" <johnl@infotn.com>
> > > Cc: <pgsql-jdbc@postgresql.org>
> > > Sent: Thursday, March 27, 2003 5:58 PM
> > > Subject: Re: [JDBC] JDBC with SSL
> > >
> > >
> > >
> > >>John,
> > >>
> > >>This hasn't yet made it to the documentation.
> > >>
> > >>but adding ?ssl to the url should be what you need.  (also consider
> > >>using &loglevel=2 to turn on debugging info).
> > >>
> > >>--Barry
> > >>
> > >>John Laban wrote:
> > >>
> > >>>Hello,
> > >>>
> > >>>The newest developement JDBC drivers (7.4dev, build 204, 2003-03-23)
> say
> > >
> > > they include support for SSL.  I can set up the server to use SSL, but I
> > > can't seem to get the JDBC driver to actually connect using SSL.  Is
> there
> > > any documentation on this?  Or is there a specific parameter I am
> supposed
> > > to include in the connection URL?
> > >
> > >>>Any help in this would be appreciated.
> > >>>
> > >>>John Laban
> > >>>
> > >>
> > >>
> > >>---------------------------(end of broadcast)---------------------------
> > >>TIP 5: Have you checked our extensive FAQ?
> > >>
> > >>http://www.postgresql.org/docs/faqs/FAQ.html
> > >
> > >
> > >
> > > ---------------------------(end of broadcast)---------------------------
> > > TIP 6: Have you searched our list archives?
> > >
> > > http://archives.postgresql.org
> > >
> >
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 6: Have you searched our list archives?
> >
> > http://archives.postgresql.org
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
> 




^ permalink  raw  reply  [nested|flat] 25+ messages in thread

* Re: JDBC with SSL
  2003-03-27 21:40 JDBC with SSL John Laban <johnl@infotn.com>
  2003-03-27 22:58 ` Re: JDBC with SSL Barry Lind <blind@xythos.com>
  2003-03-28 16:01   ` Re: JDBC with SSL John Laban <johnl@infotn.com>
  2003-03-28 16:11     ` Re: JDBC with SSL Barry Lind <blind@xythos.com>
  2003-03-28 17:06       ` Re: JDBC with SSL John Laban <johnl@infotn.com>
@ 2003-03-28 18:50         ` Barry Lind <blind@xythos.com>
  2 siblings, 0 replies; 25+ messages in thread

From: Barry Lind @ 2003-03-28 18:50 UTC (permalink / raw)
  To: John Laban <johnl@infotn.com>; +Cc: pgsql-jdbc

John,

I have done this before, but I don't remember the exact steps.  Java is 
very particular about the formats of certs it accepts.  I ended up doing 
a google search and found some good instructions on how to get java to 
import an openssl created cert.  Unfortunately I didn't keep those 
instructions.

--Barry


John Laban wrote:
> Hello again,
> 
> I have made numerous attempts to import the certificate from the server to
> the client machine using java keytool with no success - the keytool
> complains that the file is not a valid X.509 format.
> 
> Additionally, for my application, only the encryption of the channel is
> important so if it is possible to create an ssl connection without the
> authentication portion that would be the best solution.
> 
> 
> However I would still appreciate any information on how to import the
> certificate (as generated using the Postgresql documention) into the java
> certificate store.
> 
> 
> 
> ----- Original Message -----
> From: "Barry Lind" <blind@xythos.com>
> To: "John Laban" <johnl@infotn.com>
> Cc: <pgsql-jdbc@postgresql.org>
> Sent: Friday, March 28, 2003 11:11 AM
> Subject: Re: [JDBC] JDBC with SSL
> 
> 
> 
>>John,
>>
>>The error message indicates that your client doesn't trust the servers
>>certificate.  My guess is that you are using a self-signed certificate
>>on the server.  If you want to be able to connect you are going to need
>>to import that certificate into the client side java certificate store
>>so that it recognizes the self-signed certificate as valid and trusted.
>>
>>thanks,
>>--Barry
>>
>>
>>John Laban wrote:
>>
>>>Thanks for the quick reply, but I'm still having some difficulty.
>>>
>>>I have been trying to connect to postgresql (redhat version 7.2.3.1)
> 
> using
> 
>>>JDBC and SSL - I am using the 7.4 development driver.
>>>
>>>I know that the server side is set up correctly because when connecting
>>>using psql the connection is established using SSL.
>>>
>>>
>>>However when connecting via JDBC I receive
>>>
>>>
>>>
>>>
>>>PostgreSQL 7.4devel JDBC3 with SSL (build 204)
>>>
>>>    ssl = true
>>>
>>>    compatible = 7.4
>>>
>>>    loglevel = 2
>>>
>>>Asking server if it supports ssl
>>>
>>>Server response was (S=Yes,N=No): S
>>>
>>>server does support ssl
>>>
>>>converting regular socket connection to ssl
>>>
>>>
>>>
>>>            at org.postgresql.core.PGStream.flush(PGStream.java:364)
>>>
>>>            at
>>>
> 
> org.postgresql.jdbc1.AbstractJdbc1Connection.openConnection(AbstractJdbc1Con
> 
>>>nection.java:269)
>>>
>>>            at org.postgresql.Driver.connect(Driver.java:137)
>>>
>>>            at
> 
> java.sql.DriverManager.getConnection(DriverManager.java:512)
> 
>>>            at
> 
> java.sql.DriverManager.getConnection(DriverManager.java:140)
> 
>>>            at docextractor.test.main(test.java:35)
>>>
>>>
>>>Exception: An I/O error has occured while flushing the output -
> 
> Exception:
> 
>>>javax.net.ssl.SSLHandshakeException:
>>>java.security.cert.CertificateException: Couldn't find trusted
> 
> certificate
> 
>>>Stack Trace:
>>>
>>>
>>>
>>>javax.net.ssl.SSLHandshakeException:
>>>java.security.cert.CertificateException: Couldn't find trusted
> 
> certificate
> 
>>>            at
> 
> com.sun.net.ssl.internal.ssl.BaseSSLSocketImpl.a(DashoA6275)
> 
>>>            at com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA6275)
>>>
>>>            at com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA6275)
>>>
>>>            at com.sun.net.ssl.internal.ssl.SunJSSE_az.a(DashoA6275)
>>>
>>>            at com.sun.net.ssl.internal.ssl.SunJSSE_az.a(DashoA6275)
>>>
>>>            at com.sun.net.ssl.internal.ssl.SunJSSE_ax.a(DashoA6275)
>>>
>>>            at com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA6275)
>>>
>>>            at com.sun.net.ssl.internal.ssl.SSLSocketImpl.j(DashoA6275)
>>>
>>>            at com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA6275)
>>>
>>>            at
>>>com.sun.net.ssl.internal.ssl.AppOutputStream.write(DashoA6275)
>>>
>>>            at
>>>java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:69)
>>>
>>>            at
>>>java.io.BufferedOutputStream.flush(BufferedOutputStream.java:127)
>>>
>>>            at org.postgresql.core.PGStream.flush(PGStream.java:360)
>>>
>>>            at
>>>
> 
> org.postgresql.jdbc1.AbstractJdbc1Connection.openConnection(AbstractJdbc1Con
> 
>>>nection.java:269)
>>>
>>>            at org.postgresql.Driver.connect(Driver.java:137)
>>>
>>>            at
> 
> java.sql.DriverManager.getConnection(DriverManager.java:512)
> 
>>>            at
> 
> java.sql.DriverManager.getConnection(DriverManager.java:140)
> 
>>>            at docextractor.test.main(test.java:35)
>>>
>>>
>>>Caused by: java.security.cert.CertificateException: Couldn't find
> 
> trusted
> 
>>>certificate
>>>
>>>
>>>            at
>>>com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.a(DashoA6275)
>>>
>>>            at
>>>
> 
> com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(DashoA6
> 
>>>275)
>>>
>>>            at
>>>
> 
> com.sun.net.ssl.internal.ssl.JsseX509TrustManager.checkServerTrusted(DashoA6
> 
>>>275)
>>>
>>>            ... 15 more
>>>
>>>
>>>End of Stack Trace
>>>
>>>
>>>
>>>
>>>
>>>At the server side I get
>>>
>>>
>>>
>>>Failed to inititalize SSL Connection: sslv3 alert certificate unknown
>>>(Success)
>>>
>>>
>>>
>>>
>>>I have not been able to find any clear resolutions to this problem. If
>>>someone can shed some light on a solution to this problem it would be
>>>greatly appreciated.
>>>
>>>
>>>
>>>----- Original Message -----
>>>From: "Barry Lind" <blind@xythos.com>
>>>To: "John Laban" <johnl@infotn.com>
>>>Cc: <pgsql-jdbc@postgresql.org>
>>>Sent: Thursday, March 27, 2003 5:58 PM
>>>Subject: Re: [JDBC] JDBC with SSL
>>>
>>>
>>>
>>>
>>>>John,
>>>>
>>>>This hasn't yet made it to the documentation.
>>>>
>>>>but adding ?ssl to the url should be what you need.  (also consider
>>>>using &loglevel=2 to turn on debugging info).
>>>>
>>>>--Barry
>>>>
>>>>John Laban wrote:
>>>>
>>>>
>>>>>Hello,
>>>>>
>>>>>The newest developement JDBC drivers (7.4dev, build 204, 2003-03-23)
> 
> say
> 
>>>they include support for SSL.  I can set up the server to use SSL, but I
>>>can't seem to get the JDBC driver to actually connect using SSL.  Is
> 
> there
> 
>>>any documentation on this?  Or is there a specific parameter I am
> 
> supposed
> 
>>>to include in the connection URL?
>>>
>>>
>>>>>Any help in this would be appreciated.
>>>>>
>>>>>John Laban
>>>>>
>>>>
>>>>
>>>>---------------------------(end of broadcast)---------------------------
>>>>TIP 5: Have you checked our extensive FAQ?
>>>>
>>>>http://www.postgresql.org/docs/faqs/FAQ.html
>>>
>>>
>>>
>>>---------------------------(end of broadcast)---------------------------
>>>TIP 6: Have you searched our list archives?
>>>
>>>http://archives.postgresql.org
>>>
>>
>>
>>---------------------------(end of broadcast)---------------------------
>>TIP 6: Have you searched our list archives?
>>
>>http://archives.postgresql.org
> 
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
> 




^ permalink  raw  reply  [nested|flat] 25+ messages in thread

* Re: JDBC with SSL
  2003-03-27 21:40 JDBC with SSL John Laban <johnl@infotn.com>
  2003-03-27 22:58 ` Re: JDBC with SSL Barry Lind <blind@xythos.com>
  2003-03-28 16:01   ` Re: JDBC with SSL John Laban <johnl@infotn.com>
  2003-03-28 16:11     ` Re: JDBC with SSL Barry Lind <blind@xythos.com>
  2003-03-28 17:06       ` Re: JDBC with SSL John Laban <johnl@infotn.com>
@ 2003-03-28 19:07         ` Nagy Istvan <nistvan@ecity.agria.hu>
  2003-03-28 20:08           ` Re: JDBC with SSL John Laban <johnl@infotn.com>
  2 siblings, 1 reply; 25+ messages in thread

From: Nagy Istvan @ 2003-03-28 19:07 UTC (permalink / raw)
  To: John Laban <johnl@infotn.com>; +Cc: pgsql-jdbc

Hi John,

try this one (i hope it works)

1. open the certificate in a text editor
2. look for the line starting like this: ------ BEGIN CERTIFICATE ...
3. cut the closing section of the file ( incl. the ---- BEGIN CERTIFICATE
and ---- END CERTIFICATE lines) and copy it into the file cert2.crt
4. run: $ keytool -import -alias alias_name -file cert2.crt
5. answer all questions and say that you trust this cert

If you were successful can you tell me about your config? I use jdk1.3.0_02
and jsse (I know it is an old conf) and PG 7.3 and I recieve an answer as
follows:"FATAL: failed to initialize SSL connection: wrong version number".
I see the next in the server's log file: "FATAL: failed to initialize SSL
connection: sslv3 alert handshake failure" then "FATAL: SSL SYSCALL error:
Connection reset by peer"

If i change the next line in the back and code :
SSL_context=SSL_CTX_new(TLSv1_method()) to
SSL_context=SSL_CTX_new(SSLv23_method()) and
initialize the factory in the jdbc driver by using SSLv23 then
everything is ok.

why?

regards / Istvan Nagy

----- Original Message -----
From: John Laban <johnl@infotn.com>
To: Barry Lind <blind@xythos.com>
Cc: <pgsql-jdbc@postgresql.org>
Sent: Friday, March 28, 2003 6:06 PM
Subject: Re: [JDBC] JDBC with SSL


> Hello again,
>
> I have made numerous attempts to import the certificate from the server to
> the client machine using java keytool with no success - the keytool
> complains that the file is not a valid X.509 format.
>
> Additionally, for my application, only the encryption of the channel is
> important so if it is possible to create an ssl connection without the
> authentication portion that would be the best solution.
>
>
> However I would still appreciate any information on how to import the
> certificate (as generated using the Postgresql documention) into the java
> certificate store.
>
>
>
> ----- Original Message -----
> From: "Barry Lind" <blind@xythos.com>
> To: "John Laban" <johnl@infotn.com>
> Cc: <pgsql-jdbc@postgresql.org>
> Sent: Friday, March 28, 2003 11:11 AM
> Subject: Re: [JDBC] JDBC with SSL
>
>
> > John,
> >
> > The error message indicates that your client doesn't trust the servers
> > certificate.  My guess is that you are using a self-signed certificate
> > on the server.  If you want to be able to connect you are going to need
> > to import that certificate into the client side java certificate store
> > so that it recognizes the self-signed certificate as valid and trusted.
> >
> > thanks,
> > --Barry
> >
> >
> > John Laban wrote:
> > > Thanks for the quick reply, but I'm still having some difficulty.
> > >
> > > I have been trying to connect to postgresql (redhat version 7.2.3.1)
> using
> > > JDBC and SSL - I am using the 7.4 development driver.
> > >
> > > I know that the server side is set up correctly because when
connecting
> > > using psql the connection is established using SSL.
> > >
> > >
> > > However when connecting via JDBC I receive
> > >
> > >
> > >
> > >
> > > PostgreSQL 7.4devel JDBC3 with SSL (build 204)
> > >
> > >     ssl = true
> > >
> > >     compatible = 7.4
> > >
> > >     loglevel = 2
> > >
> > > Asking server if it supports ssl
> > >
> > > Server response was (S=Yes,N=No): S
> > >
> > > server does support ssl
> > >
> > > converting regular socket connection to ssl
> > >
> > >
> > >
> > >             at org.postgresql.core.PGStream.flush(PGStream.java:364)
> > >
> > >             at
> > >
>
org.postgresql.jdbc1.AbstractJdbc1Connection.openConnection(AbstractJdbc1Con
> > > nection.java:269)
> > >
> > >             at org.postgresql.Driver.connect(Driver.java:137)
> > >
> > >             at
> java.sql.DriverManager.getConnection(DriverManager.java:512)
> > >
> > >             at
> java.sql.DriverManager.getConnection(DriverManager.java:140)
> > >
> > >             at docextractor.test.main(test.java:35)
> > >
> > >
> > > Exception: An I/O error has occured while flushing the output -
> Exception:
> > > javax.net.ssl.SSLHandshakeException:
> > > java.security.cert.CertificateException: Couldn't find trusted
> certificate
> > >
> > > Stack Trace:
> > >
> > >
> > >
> > > javax.net.ssl.SSLHandshakeException:
> > > java.security.cert.CertificateException: Couldn't find trusted
> certificate
> > >
> > >             at
> com.sun.net.ssl.internal.ssl.BaseSSLSocketImpl.a(DashoA6275)
> > >
> > >             at
com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA6275)
> > >
> > >             at
com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA6275)
> > >
> > >             at com.sun.net.ssl.internal.ssl.SunJSSE_az.a(DashoA6275)
> > >
> > >             at com.sun.net.ssl.internal.ssl.SunJSSE_az.a(DashoA6275)
> > >
> > >             at com.sun.net.ssl.internal.ssl.SunJSSE_ax.a(DashoA6275)
> > >
> > >             at
com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA6275)
> > >
> > >             at
com.sun.net.ssl.internal.ssl.SSLSocketImpl.j(DashoA6275)
> > >
> > >             at
com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA6275)
> > >
> > >             at
> > > com.sun.net.ssl.internal.ssl.AppOutputStream.write(DashoA6275)
> > >
> > >             at
> > > java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:69)
> > >
> > >             at
> > > java.io.BufferedOutputStream.flush(BufferedOutputStream.java:127)
> > >
> > >             at org.postgresql.core.PGStream.flush(PGStream.java:360)
> > >
> > >             at
> > >
>
org.postgresql.jdbc1.AbstractJdbc1Connection.openConnection(AbstractJdbc1Con
> > > nection.java:269)
> > >
> > >             at org.postgresql.Driver.connect(Driver.java:137)
> > >
> > >             at
> java.sql.DriverManager.getConnection(DriverManager.java:512)
> > >
> > >             at
> java.sql.DriverManager.getConnection(DriverManager.java:140)
> > >
> > >             at docextractor.test.main(test.java:35)
> > >
> > >
> > > Caused by: java.security.cert.CertificateException: Couldn't find
> trusted
> > > certificate
> > >
> > >
> > >             at
> > > com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.a(DashoA6275)
> > >
> > >             at
> > >
>
com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(DashoA6
> > > 275)
> > >
> > >             at
> > >
>
com.sun.net.ssl.internal.ssl.JsseX509TrustManager.checkServerTrusted(DashoA6
> > > 275)
> > >
> > >             ... 15 more
> > >
> > >
> > > End of Stack Trace
> > >
> > >
> > >
> > >
> > >
> > > At the server side I get
> > >
> > >
> > >
> > > Failed to inititalize SSL Connection: sslv3 alert certificate unknown
> > > (Success)
> > >
> > >
> > >
> > >
> > > I have not been able to find any clear resolutions to this problem. If
> > > someone can shed some light on a solution to this problem it would be
> > > greatly appreciated.
> > >
> > >
> > >
> > > ----- Original Message -----
> > > From: "Barry Lind" <blind@xythos.com>
> > > To: "John Laban" <johnl@infotn.com>
> > > Cc: <pgsql-jdbc@postgresql.org>
> > > Sent: Thursday, March 27, 2003 5:58 PM
> > > Subject: Re: [JDBC] JDBC with SSL
> > >
> > >
> > >
> > >>John,
> > >>
> > >>This hasn't yet made it to the documentation.
> > >>
> > >>but adding ?ssl to the url should be what you need.  (also consider
> > >>using &loglevel=2 to turn on debugging info).
> > >>
> > >>--Barry
> > >>
> > >>John Laban wrote:
> > >>
> > >>>Hello,
> > >>>
> > >>>The newest developement JDBC drivers (7.4dev, build 204, 2003-03-23)
> say
> > >
> > > they include support for SSL.  I can set up the server to use SSL, but
I
> > > can't seem to get the JDBC driver to actually connect using SSL.  Is
> there
> > > any documentation on this?  Or is there a specific parameter I am
> supposed
> > > to include in the connection URL?
> > >
> > >>>Any help in this would be appreciated.
> > >>>
> > >>>John Laban
> > >>>
> > >>
> > >>
> > >>---------------------------(end of
broadcast)---------------------------
> > >>TIP 5: Have you checked our extensive FAQ?
> > >>
> > >>http://www.postgresql.org/docs/faqs/FAQ.html
> > >
> > >
> > >
> > > ---------------------------(end of
broadcast)---------------------------
> > > TIP 6: Have you searched our list archives?
> > >
> > > http://archives.postgresql.org
> > >
> >
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 6: Have you searched our list archives?
> >
> > http://archives.postgresql.org
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
>




^ permalink  raw  reply  [nested|flat] 25+ messages in thread

* Re: JDBC with SSL
  2003-03-27 21:40 JDBC with SSL John Laban <johnl@infotn.com>
  2003-03-27 22:58 ` Re: JDBC with SSL Barry Lind <blind@xythos.com>
  2003-03-28 16:01   ` Re: JDBC with SSL John Laban <johnl@infotn.com>
  2003-03-28 16:11     ` Re: JDBC with SSL Barry Lind <blind@xythos.com>
  2003-03-28 17:06       ` Re: JDBC with SSL John Laban <johnl@infotn.com>
  2003-03-28 19:07         ` Re: JDBC with SSL Nagy Istvan <nistvan@ecity.agria.hu>
@ 2003-03-28 20:08           ` John Laban <johnl@infotn.com>
  2003-03-31 08:29             ` Re: JDBC with SSL Csaba Nagy <nagy@ecircle-ag.com>
  0 siblings, 1 reply; 25+ messages in thread

From: John Laban @ 2003-03-28 20:08 UTC (permalink / raw)
  To: Nagy Istvan <nistvan@ecity.agria.hu>; +Cc: pgsql-jdbc

Thanks for the tip, but sorry, no luck.

As for us, we're going to try modifiying the driver to use a custom
SSLSocketFactory that won't care about the authentication procedure.

Thanks,
John Laban


----- Original Message -----
From: "Nagy Istvan" <nistvan@ecity.agria.hu>
To: "John Laban" <johnl@infotn.com>
Cc: <pgsql-jdbc@postgresql.org>
Sent: Friday, March 28, 2003 2:07 PM
Subject: Re: [JDBC] JDBC with SSL


> Hi John,
>
> try this one (i hope it works)
>
> 1. open the certificate in a text editor
> 2. look for the line starting like this: ------ BEGIN CERTIFICATE ...
> 3. cut the closing section of the file ( incl. the ---- BEGIN CERTIFICATE
> and ---- END CERTIFICATE lines) and copy it into the file cert2.crt
> 4. run: $ keytool -import -alias alias_name -file cert2.crt
> 5. answer all questions and say that you trust this cert
>
> If you were successful can you tell me about your config? I use
jdk1.3.0_02
> and jsse (I know it is an old conf) and PG 7.3 and I recieve an answer as
> follows:"FATAL: failed to initialize SSL connection: wrong version
number".
> I see the next in the server's log file: "FATAL: failed to initialize SSL
> connection: sslv3 alert handshake failure" then "FATAL: SSL SYSCALL error:
> Connection reset by peer"
>
> If i change the next line in the back and code :
> SSL_context=SSL_CTX_new(TLSv1_method()) to
> SSL_context=SSL_CTX_new(SSLv23_method()) and
> initialize the factory in the jdbc driver by using SSLv23 then
> everything is ok.
>
> why?
>
> regards / Istvan Nagy
>
> ----- Original Message -----
> From: John Laban <johnl@infotn.com>
> To: Barry Lind <blind@xythos.com>
> Cc: <pgsql-jdbc@postgresql.org>
> Sent: Friday, March 28, 2003 6:06 PM
> Subject: Re: [JDBC] JDBC with SSL
>
>
> > Hello again,
> >
> > I have made numerous attempts to import the certificate from the server
to
> > the client machine using java keytool with no success - the keytool
> > complains that the file is not a valid X.509 format.
> >
> > Additionally, for my application, only the encryption of the channel is
> > important so if it is possible to create an ssl connection without the
> > authentication portion that would be the best solution.
> >
> >
> > However I would still appreciate any information on how to import the
> > certificate (as generated using the Postgresql documention) into the
java
> > certificate store.
> >
> >
> >
> > ----- Original Message -----
> > From: "Barry Lind" <blind@xythos.com>
> > To: "John Laban" <johnl@infotn.com>
> > Cc: <pgsql-jdbc@postgresql.org>
> > Sent: Friday, March 28, 2003 11:11 AM
> > Subject: Re: [JDBC] JDBC with SSL
> >
> >
> > > John,
> > >
> > > The error message indicates that your client doesn't trust the servers
> > > certificate.  My guess is that you are using a self-signed certificate
> > > on the server.  If you want to be able to connect you are going to
need
> > > to import that certificate into the client side java certificate store
> > > so that it recognizes the self-signed certificate as valid and
trusted.
> > >
> > > thanks,
> > > --Barry
> > >
> > >
> > > John Laban wrote:
> > > > Thanks for the quick reply, but I'm still having some difficulty.
> > > >
> > > > I have been trying to connect to postgresql (redhat version 7.2.3.1)
> > using
> > > > JDBC and SSL - I am using the 7.4 development driver.
> > > >
> > > > I know that the server side is set up correctly because when
> connecting
> > > > using psql the connection is established using SSL.
> > > >
> > > >
> > > > However when connecting via JDBC I receive
> > > >
> > > >
> > > >
> > > >
> > > > PostgreSQL 7.4devel JDBC3 with SSL (build 204)
> > > >
> > > >     ssl = true
> > > >
> > > >     compatible = 7.4
> > > >
> > > >     loglevel = 2
> > > >
> > > > Asking server if it supports ssl
> > > >
> > > > Server response was (S=Yes,N=No): S
> > > >
> > > > server does support ssl
> > > >
> > > > converting regular socket connection to ssl
> > > >
> > > >
> > > >
> > > >             at org.postgresql.core.PGStream.flush(PGStream.java:364)
> > > >
> > > >             at
> > > >
> >
>
org.postgresql.jdbc1.AbstractJdbc1Connection.openConnection(AbstractJdbc1Con
> > > > nection.java:269)
> > > >
> > > >             at org.postgresql.Driver.connect(Driver.java:137)
> > > >
> > > >             at
> > java.sql.DriverManager.getConnection(DriverManager.java:512)
> > > >
> > > >             at
> > java.sql.DriverManager.getConnection(DriverManager.java:140)
> > > >
> > > >             at docextractor.test.main(test.java:35)
> > > >
> > > >
> > > > Exception: An I/O error has occured while flushing the output -
> > Exception:
> > > > javax.net.ssl.SSLHandshakeException:
> > > > java.security.cert.CertificateException: Couldn't find trusted
> > certificate
> > > >
> > > > Stack Trace:
> > > >
> > > >
> > > >
> > > > javax.net.ssl.SSLHandshakeException:
> > > > java.security.cert.CertificateException: Couldn't find trusted
> > certificate
> > > >
> > > >             at
> > com.sun.net.ssl.internal.ssl.BaseSSLSocketImpl.a(DashoA6275)
> > > >
> > > >             at
> com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA6275)
> > > >
> > > >             at
> com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA6275)
> > > >
> > > >             at com.sun.net.ssl.internal.ssl.SunJSSE_az.a(DashoA6275)
> > > >
> > > >             at com.sun.net.ssl.internal.ssl.SunJSSE_az.a(DashoA6275)
> > > >
> > > >             at com.sun.net.ssl.internal.ssl.SunJSSE_ax.a(DashoA6275)
> > > >
> > > >             at
> com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA6275)
> > > >
> > > >             at
> com.sun.net.ssl.internal.ssl.SSLSocketImpl.j(DashoA6275)
> > > >
> > > >             at
> com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA6275)
> > > >
> > > >             at
> > > > com.sun.net.ssl.internal.ssl.AppOutputStream.write(DashoA6275)
> > > >
> > > >             at
> > > >
java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:69)
> > > >
> > > >             at
> > > > java.io.BufferedOutputStream.flush(BufferedOutputStream.java:127)
> > > >
> > > >             at org.postgresql.core.PGStream.flush(PGStream.java:360)
> > > >
> > > >             at
> > > >
> >
>
org.postgresql.jdbc1.AbstractJdbc1Connection.openConnection(AbstractJdbc1Con
> > > > nection.java:269)
> > > >
> > > >             at org.postgresql.Driver.connect(Driver.java:137)
> > > >
> > > >             at
> > java.sql.DriverManager.getConnection(DriverManager.java:512)
> > > >
> > > >             at
> > java.sql.DriverManager.getConnection(DriverManager.java:140)
> > > >
> > > >             at docextractor.test.main(test.java:35)
> > > >
> > > >
> > > > Caused by: java.security.cert.CertificateException: Couldn't find
> > trusted
> > > > certificate
> > > >
> > > >
> > > >             at
> > > > com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.a(DashoA6275)
> > > >
> > > >             at
> > > >
> >
>
com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(DashoA6
> > > > 275)
> > > >
> > > >             at
> > > >
> >
>
com.sun.net.ssl.internal.ssl.JsseX509TrustManager.checkServerTrusted(DashoA6
> > > > 275)
> > > >
> > > >             ... 15 more
> > > >
> > > >
> > > > End of Stack Trace
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > At the server side I get
> > > >
> > > >
> > > >
> > > > Failed to inititalize SSL Connection: sslv3 alert certificate
unknown
> > > > (Success)
> > > >
> > > >
> > > >
> > > >
> > > > I have not been able to find any clear resolutions to this problem.
If
> > > > someone can shed some light on a solution to this problem it would
be
> > > > greatly appreciated.
> > > >
> > > >
> > > >
> > > > ----- Original Message -----
> > > > From: "Barry Lind" <blind@xythos.com>
> > > > To: "John Laban" <johnl@infotn.com>
> > > > Cc: <pgsql-jdbc@postgresql.org>
> > > > Sent: Thursday, March 27, 2003 5:58 PM
> > > > Subject: Re: [JDBC] JDBC with SSL
> > > >
> > > >
> > > >
> > > >>John,
> > > >>
> > > >>This hasn't yet made it to the documentation.
> > > >>
> > > >>but adding ?ssl to the url should be what you need.  (also consider
> > > >>using &loglevel=2 to turn on debugging info).
> > > >>
> > > >>--Barry
> > > >>
> > > >>John Laban wrote:
> > > >>
> > > >>>Hello,
> > > >>>
> > > >>>The newest developement JDBC drivers (7.4dev, build 204,
2003-03-23)
> > say
> > > >
> > > > they include support for SSL.  I can set up the server to use SSL,
but
> I
> > > > can't seem to get the JDBC driver to actually connect using SSL.  Is
> > there
> > > > any documentation on this?  Or is there a specific parameter I am
> > supposed
> > > > to include in the connection URL?
> > > >
> > > >>>Any help in this would be appreciated.
> > > >>>
> > > >>>John Laban
> > > >>>
> > > >>
> > > >>
> > > >>---------------------------(end of
> broadcast)---------------------------
> > > >>TIP 5: Have you checked our extensive FAQ?
> > > >>
> > > >>http://www.postgresql.org/docs/faqs/FAQ.html
> > > >
> > > >
> > > >
> > > > ---------------------------(end of
> broadcast)---------------------------
> > > > TIP 6: Have you searched our list archives?
> > > >
> > > > http://archives.postgresql.org
> > > >
> > >
> > >
> > > ---------------------------(end of
broadcast)---------------------------
> > > TIP 6: Have you searched our list archives?
> > >
> > > http://archives.postgresql.org
> >
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 4: Don't 'kill -9' the postmaster
> >
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://archives.postgresql.org




^ permalink  raw  reply  [nested|flat] 25+ messages in thread

* Re: JDBC with SSL
  2003-03-27 21:40 JDBC with SSL John Laban <johnl@infotn.com>
  2003-03-27 22:58 ` Re: JDBC with SSL Barry Lind <blind@xythos.com>
  2003-03-28 16:01   ` Re: JDBC with SSL John Laban <johnl@infotn.com>
  2003-03-28 16:11     ` Re: JDBC with SSL Barry Lind <blind@xythos.com>
  2003-03-28 17:06       ` Re: JDBC with SSL John Laban <johnl@infotn.com>
  2003-03-28 19:07         ` Re: JDBC with SSL Nagy Istvan <nistvan@ecity.agria.hu>
  2003-03-28 20:08           ` Re: JDBC with SSL John Laban <johnl@infotn.com>
@ 2003-03-31 08:29             ` Csaba Nagy <nagy@ecircle-ag.com>
  2003-03-31 13:13               ` Re: JDBC with SSL John Laban <johnl@infotn.com>
  0 siblings, 1 reply; 25+ messages in thread

From: Csaba Nagy @ 2003-03-31 08:29 UTC (permalink / raw)
  To: John Laban <johnl@infotn.com>; +Cc: Nagy Istvan <nistvan@ecity.agria.hu>; pgsql-jdbc

The following piece of code did it for us (I've found it):

static {
        // add support for https and the like
        System.setProperty("java.protocol.handler.pkgs",
                "com.sun.net.ssl.internal.www.protocol");
        Security.addProvider(new
com.sun.net.ssl.internal.ssl.Provider());

        try {
            SSLContext ctx = SSLContext.getInstance("TLS");
            ctx.init(
              null,
              new TrustManager[] {
                  new X509TrustManager() {
                      public X509Certificate[] getAcceptedIssuers() {
                          return new X509Certificate[0];
                      }

                      public boolean isClientTrusted(X509Certificate[]
x509Certificates) {
                          return true;
                      }

                      public boolean isServerTrusted(X509Certificate[]
x509Certificates) {
                          return true;
                      }
                  }
              },
              null
            );

           
HTTPConnection.setDefaultSSLSocketFactory(ctx.getSocketFactory());
        } catch (Exception e) {
            System.out.println("Failed to set SSL socket factory for
HTTPClient. There might be problems with https.");
        }

}

HTH,
CSaba.


On Fri, 2003-03-28 at 21:08, John Laban wrote:
> Thanks for the tip, but sorry, no luck.
> 
> As for us, we're going to try modifiying the driver to use a custom
> SSLSocketFactory that won't care about the authentication procedure.
> 
> Thanks,
> John Laban
> 
> 
> ----- Original Message -----
> From: "Nagy Istvan" <nistvan@ecity.agria.hu>
> To: "John Laban" <johnl@infotn.com>
> Cc: <pgsql-jdbc@postgresql.org>
> Sent: Friday, March 28, 2003 2:07 PM
> Subject: Re: [JDBC] JDBC with SSL
> 
> 
> > Hi John,
> >
> > try this one (i hope it works)
> >
> > 1. open the certificate in a text editor
> > 2. look for the line starting like this: ------ BEGIN CERTIFICATE ...
> > 3. cut the closing section of the file ( incl. the ---- BEGIN CERTIFICATE
> > and ---- END CERTIFICATE lines) and copy it into the file cert2.crt
> > 4. run: $ keytool -import -alias alias_name -file cert2.crt
> > 5. answer all questions and say that you trust this cert
> >
> > If you were successful can you tell me about your config? I use
> jdk1.3.0_02
> > and jsse (I know it is an old conf) and PG 7.3 and I recieve an answer as
> > follows:"FATAL: failed to initialize SSL connection: wrong version
> number".
> > I see the next in the server's log file: "FATAL: failed to initialize SSL
> > connection: sslv3 alert handshake failure" then "FATAL: SSL SYSCALL error:
> > Connection reset by peer"
> >
> > If i change the next line in the back and code :
> > SSL_context=SSL_CTX_new(TLSv1_method()) to
> > SSL_context=SSL_CTX_new(SSLv23_method()) and
> > initialize the factory in the jdbc driver by using SSLv23 then
> > everything is ok.
> >
> > why?
> >
> > regards / Istvan Nagy
> >
> > ----- Original Message -----
> > From: John Laban <johnl@infotn.com>
> > To: Barry Lind <blind@xythos.com>
> > Cc: <pgsql-jdbc@postgresql.org>
> > Sent: Friday, March 28, 2003 6:06 PM
> > Subject: Re: [JDBC] JDBC with SSL
> >
> >
> > > Hello again,
> > >
> > > I have made numerous attempts to import the certificate from the server
> to
> > > the client machine using java keytool with no success - the keytool
> > > complains that the file is not a valid X.509 format.
> > >
> > > Additionally, for my application, only the encryption of the channel is
> > > important so if it is possible to create an ssl connection without the
> > > authentication portion that would be the best solution.
> > >
> > >
> > > However I would still appreciate any information on how to import the
> > > certificate (as generated using the Postgresql documention) into the
> java
> > > certificate store.
> > >
> > >
> > >
> > > ----- Original Message -----
> > > From: "Barry Lind" <blind@xythos.com>
> > > To: "John Laban" <johnl@infotn.com>
> > > Cc: <pgsql-jdbc@postgresql.org>
> > > Sent: Friday, March 28, 2003 11:11 AM
> > > Subject: Re: [JDBC] JDBC with SSL
> > >
> > >
> > > > John,
> > > >
> > > > The error message indicates that your client doesn't trust the servers
> > > > certificate.  My guess is that you are using a self-signed certificate
> > > > on the server.  If you want to be able to connect you are going to
> need
> > > > to import that certificate into the client side java certificate store
> > > > so that it recognizes the self-signed certificate as valid and
> trusted.
> > > >
> > > > thanks,
> > > > --Barry
> > > >
> > > >
> > > > John Laban wrote:
> > > > > Thanks for the quick reply, but I'm still having some difficulty.
> > > > >
> > > > > I have been trying to connect to postgresql (redhat version 7.2.3.1)
> > > using
> > > > > JDBC and SSL - I am using the 7.4 development driver.
> > > > >
> > > > > I know that the server side is set up correctly because when
> > connecting
> > > > > using psql the connection is established using SSL.
> > > > >
> > > > >
> > > > > However when connecting via JDBC I receive
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > PostgreSQL 7.4devel JDBC3 with SSL (build 204)
> > > > >
> > > > >     ssl = true
> > > > >
> > > > >     compatible = 7.4
> > > > >
> > > > >     loglevel = 2
> > > > >
> > > > > Asking server if it supports ssl
> > > > >
> > > > > Server response was (S=Yes,N=No): S
> > > > >
> > > > > server does support ssl
> > > > >
> > > > > converting regular socket connection to ssl
> > > > >
> > > > >
> > > > >
> > > > >             at org.postgresql.core.PGStream.flush(PGStream.java:364)
> > > > >
> > > > >             at
> > > > >
> > >
> >
> org.postgresql.jdbc1.AbstractJdbc1Connection.openConnection(AbstractJdbc1Con
> > > > > nection.java:269)
> > > > >
> > > > >             at org.postgresql.Driver.connect(Driver.java:137)
> > > > >
> > > > >             at
> > > java.sql.DriverManager.getConnection(DriverManager.java:512)
> > > > >
> > > > >             at
> > > java.sql.DriverManager.getConnection(DriverManager.java:140)
> > > > >
> > > > >             at docextractor.test.main(test.java:35)
> > > > >
> > > > >
> > > > > Exception: An I/O error has occured while flushing the output -
> > > Exception:
> > > > > javax.net.ssl.SSLHandshakeException:
> > > > > java.security.cert.CertificateException: Couldn't find trusted
> > > certificate
> > > > >
> > > > > Stack Trace:
> > > > >
> > > > >
> > > > >
> > > > > javax.net.ssl.SSLHandshakeException:
> > > > > java.security.cert.CertificateException: Couldn't find trusted
> > > certificate
> > > > >
> > > > >             at
> > > com.sun.net.ssl.internal.ssl.BaseSSLSocketImpl.a(DashoA6275)
> > > > >
> > > > >             at
> > com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA6275)
> > > > >
> > > > >             at
> > com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA6275)
> > > > >
> > > > >             at com.sun.net.ssl.internal.ssl.SunJSSE_az.a(DashoA6275)
> > > > >
> > > > >             at com.sun.net.ssl.internal.ssl.SunJSSE_az.a(DashoA6275)
> > > > >
> > > > >             at com.sun.net.ssl.internal.ssl.SunJSSE_ax.a(DashoA6275)
> > > > >
> > > > >             at
> > com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA6275)
> > > > >
> > > > >             at
> > com.sun.net.ssl.internal.ssl.SSLSocketImpl.j(DashoA6275)
> > > > >
> > > > >             at
> > com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA6275)
> > > > >
> > > > >             at
> > > > > com.sun.net.ssl.internal.ssl.AppOutputStream.write(DashoA6275)
> > > > >
> > > > >             at
> > > > >
> java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:69)
> > > > >
> > > > >             at
> > > > > java.io.BufferedOutputStream.flush(BufferedOutputStream.java:127)
> > > > >
> > > > >             at org.postgresql.core.PGStream.flush(PGStream.java:360)
> > > > >
> > > > >             at
> > > > >
> > >
> >
> org.postgresql.jdbc1.AbstractJdbc1Connection.openConnection(AbstractJdbc1Con
> > > > > nection.java:269)
> > > > >
> > > > >             at org.postgresql.Driver.connect(Driver.java:137)
> > > > >
> > > > >             at
> > > java.sql.DriverManager.getConnection(DriverManager.java:512)
> > > > >
> > > > >             at
> > > java.sql.DriverManager.getConnection(DriverManager.java:140)
> > > > >
> > > > >             at docextractor.test.main(test.java:35)
> > > > >
> > > > >
> > > > > Caused by: java.security.cert.CertificateException: Couldn't find
> > > trusted
> > > > > certificate
> > > > >
> > > > >
> > > > >             at
> > > > > com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.a(DashoA6275)
> > > > >
> > > > >             at
> > > > >
> > >
> >
> com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(DashoA6
> > > > > 275)
> > > > >
> > > > >             at
> > > > >
> > >
> >
> com.sun.net.ssl.internal.ssl.JsseX509TrustManager.checkServerTrusted(DashoA6
> > > > > 275)
> > > > >
> > > > >             ... 15 more
> > > > >
> > > > >
> > > > > End of Stack Trace
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > At the server side I get
> > > > >
> > > > >
> > > > >
> > > > > Failed to inititalize SSL Connection: sslv3 alert certificate
> unknown
> > > > > (Success)
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > I have not been able to find any clear resolutions to this problem.
> If
> > > > > someone can shed some light on a solution to this problem it would
> be
> > > > > greatly appreciated.
> > > > >
> > > > >
> > > > >
> > > > > ----- Original Message -----
> > > > > From: "Barry Lind" <blind@xythos.com>
> > > > > To: "John Laban" <johnl@infotn.com>
> > > > > Cc: <pgsql-jdbc@postgresql.org>
> > > > > Sent: Thursday, March 27, 2003 5:58 PM
> > > > > Subject: Re: [JDBC] JDBC with SSL
> > > > >
> > > > >
> > > > >
> > > > >>John,
> > > > >>
> > > > >>This hasn't yet made it to the documentation.
> > > > >>
> > > > >>but adding ?ssl to the url should be what you need.  (also consider
> > > > >>using &loglevel=2 to turn on debugging info).
> > > > >>
> > > > >>--Barry
> > > > >>
> > > > >>John Laban wrote:
> > > > >>
> > > > >>>Hello,
> > > > >>>
> > > > >>>The newest developement JDBC drivers (7.4dev, build 204,
> 2003-03-23)
> > > say
> > > > >
> > > > > they include support for SSL.  I can set up the server to use SSL,
> but
> > I
> > > > > can't seem to get the JDBC driver to actually connect using SSL.  Is
> > > there
> > > > > any documentation on this?  Or is there a specific parameter I am
> > > supposed
> > > > > to include in the connection URL?
> > > > >
> > > > >>>Any help in this would be appreciated.
> > > > >>>
> > > > >>>John Laban
> > > > >>>
> > > > >>
> > > > >>
> > > > >>---------------------------(end of
> > broadcast)---------------------------
> > > > >>TIP 5: Have you checked our extensive FAQ?
> > > > >>
> > > > >>http://www.postgresql.org/docs/faqs/FAQ.html
> > > > >
> > > > >
> > > > >
> > > > > ---------------------------(end of
> > broadcast)---------------------------
> > > > > TIP 6: Have you searched our list archives?
> > > > >
> > > > > http://archives.postgresql.org
> > > > >
> > > >
> > > >
> > > > ---------------------------(end of
> broadcast)---------------------------
> > > > TIP 6: Have you searched our list archives?
> > > >
> > > > http://archives.postgresql.org
> > >
> > >
> > > ---------------------------(end of broadcast)---------------------------
> > > TIP 4: Don't 'kill -9' the postmaster
> > >
> >
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 6: Have you searched our list archives?
> >
> > http://archives.postgresql.org
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo@postgresql.org so that your
> message can get through to the mailing list cleanly
> 




^ permalink  raw  reply  [nested|flat] 25+ messages in thread

* Re: JDBC with SSL
  2003-03-27 21:40 JDBC with SSL John Laban <johnl@infotn.com>
  2003-03-27 22:58 ` Re: JDBC with SSL Barry Lind <blind@xythos.com>
  2003-03-28 16:01   ` Re: JDBC with SSL John Laban <johnl@infotn.com>
  2003-03-28 16:11     ` Re: JDBC with SSL Barry Lind <blind@xythos.com>
  2003-03-28 17:06       ` Re: JDBC with SSL John Laban <johnl@infotn.com>
  2003-03-28 19:07         ` Re: JDBC with SSL Nagy Istvan <nistvan@ecity.agria.hu>
  2003-03-28 20:08           ` Re: JDBC with SSL John Laban <johnl@infotn.com>
  2003-03-31 08:29             ` Re: JDBC with SSL Csaba Nagy <nagy@ecircle-ag.com>
@ 2003-03-31 13:13               ` John Laban <johnl@infotn.com>
  0 siblings, 0 replies; 25+ messages in thread

From: John Laban @ 2003-03-31 13:13 UTC (permalink / raw)
  To: Csaba Nagy <nagy@ecircle-ag.com>; +Cc: pgsql-jdbc

That is exactly what we did Friday afternoon, and it works great.

Thanks,
John


----- Original Message -----
From: "Csaba Nagy" <nagy@ecircle-ag.com>
To: "John Laban" <johnl@infotn.com>
Cc: "Nagy Istvan" <nistvan@ecity.agria.hu>; "Postgres JDBC"
<pgsql-jdbc@postgresql.org>
Sent: Monday, March 31, 2003 3:29 AM
Subject: Re: [JDBC] JDBC with SSL


> The following piece of code did it for us (I've found it):
>
> static {
>         // add support for https and the like
>         System.setProperty("java.protocol.handler.pkgs",
>                 "com.sun.net.ssl.internal.www.protocol");
>         Security.addProvider(new
> com.sun.net.ssl.internal.ssl.Provider());
>
>         try {
>             SSLContext ctx = SSLContext.getInstance("TLS");
>             ctx.init(
>               null,
>               new TrustManager[] {
>                   new X509TrustManager() {
>                       public X509Certificate[] getAcceptedIssuers() {
>                           return new X509Certificate[0];
>                       }
>
>                       public boolean isClientTrusted(X509Certificate[]
> x509Certificates) {
>                           return true;
>                       }
>
>                       public boolean isServerTrusted(X509Certificate[]
> x509Certificates) {
>                           return true;
>                       }
>                   }
>               },
>               null
>             );
>
>
> HTTPConnection.setDefaultSSLSocketFactory(ctx.getSocketFactory());
>         } catch (Exception e) {
>             System.out.println("Failed to set SSL socket factory for
> HTTPClient. There might be problems with https.");
>         }
>
> }
>
> HTH,
> CSaba.
>
>
> On Fri, 2003-03-28 at 21:08, John Laban wrote:
> > Thanks for the tip, but sorry, no luck.
> >
> > As for us, we're going to try modifiying the driver to use a custom
> > SSLSocketFactory that won't care about the authentication procedure.
> >
> > Thanks,
> > John Laban
> >
> >
> > ----- Original Message -----
> > From: "Nagy Istvan" <nistvan@ecity.agria.hu>
> > To: "John Laban" <johnl@infotn.com>
> > Cc: <pgsql-jdbc@postgresql.org>
> > Sent: Friday, March 28, 2003 2:07 PM
> > Subject: Re: [JDBC] JDBC with SSL
> >
> >
> > > Hi John,
> > >
> > > try this one (i hope it works)
> > >
> > > 1. open the certificate in a text editor
> > > 2. look for the line starting like this: ------ BEGIN CERTIFICATE ...
> > > 3. cut the closing section of the file ( incl. the ---- BEGIN
CERTIFICATE
> > > and ---- END CERTIFICATE lines) and copy it into the file cert2.crt
> > > 4. run: $ keytool -import -alias alias_name -file cert2.crt
> > > 5. answer all questions and say that you trust this cert
> > >
> > > If you were successful can you tell me about your config? I use
> > jdk1.3.0_02
> > > and jsse (I know it is an old conf) and PG 7.3 and I recieve an answer
as
> > > follows:"FATAL: failed to initialize SSL connection: wrong version
> > number".
> > > I see the next in the server's log file: "FATAL: failed to initialize
SSL
> > > connection: sslv3 alert handshake failure" then "FATAL: SSL SYSCALL
error:
> > > Connection reset by peer"
> > >
> > > If i change the next line in the back and code :
> > > SSL_context=SSL_CTX_new(TLSv1_method()) to
> > > SSL_context=SSL_CTX_new(SSLv23_method()) and
> > > initialize the factory in the jdbc driver by using SSLv23 then
> > > everything is ok.
> > >
> > > why?
> > >
> > > regards / Istvan Nagy
> > >
> > > ----- Original Message -----
> > > From: John Laban <johnl@infotn.com>
> > > To: Barry Lind <blind@xythos.com>
> > > Cc: <pgsql-jdbc@postgresql.org>
> > > Sent: Friday, March 28, 2003 6:06 PM
> > > Subject: Re: [JDBC] JDBC with SSL
> > >
> > >
> > > > Hello again,
> > > >
> > > > I have made numerous attempts to import the certificate from the
server
> > to
> > > > the client machine using java keytool with no success - the keytool
> > > > complains that the file is not a valid X.509 format.
> > > >
> > > > Additionally, for my application, only the encryption of the channel
is
> > > > important so if it is possible to create an ssl connection without
the
> > > > authentication portion that would be the best solution.
> > > >
> > > >
> > > > However I would still appreciate any information on how to import
the
> > > > certificate (as generated using the Postgresql documention) into the
> > java
> > > > certificate store.
> > > >
> > > >
> > > >
> > > > ----- Original Message -----
> > > > From: "Barry Lind" <blind@xythos.com>
> > > > To: "John Laban" <johnl@infotn.com>
> > > > Cc: <pgsql-jdbc@postgresql.org>
> > > > Sent: Friday, March 28, 2003 11:11 AM
> > > > Subject: Re: [JDBC] JDBC with SSL
> > > >
> > > >
> > > > > John,
> > > > >
> > > > > The error message indicates that your client doesn't trust the
servers
> > > > > certificate.  My guess is that you are using a self-signed
certificate
> > > > > on the server.  If you want to be able to connect you are going to
> > need
> > > > > to import that certificate into the client side java certificate
store
> > > > > so that it recognizes the self-signed certificate as valid and
> > trusted.
> > > > >
> > > > > thanks,
> > > > > --Barry
> > > > >
> > > > >
> > > > > John Laban wrote:
> > > > > > Thanks for the quick reply, but I'm still having some
difficulty.
> > > > > >
> > > > > > I have been trying to connect to postgresql (redhat version
7.2.3.1)
> > > > using
> > > > > > JDBC and SSL - I am using the 7.4 development driver.
> > > > > >
> > > > > > I know that the server side is set up correctly because when
> > > connecting
> > > > > > using psql the connection is established using SSL.
> > > > > >
> > > > > >
> > > > > > However when connecting via JDBC I receive
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > PostgreSQL 7.4devel JDBC3 with SSL (build 204)
> > > > > >
> > > > > >     ssl = true
> > > > > >
> > > > > >     compatible = 7.4
> > > > > >
> > > > > >     loglevel = 2
> > > > > >
> > > > > > Asking server if it supports ssl
> > > > > >
> > > > > > Server response was (S=Yes,N=No): S
> > > > > >
> > > > > > server does support ssl
> > > > > >
> > > > > > converting regular socket connection to ssl
> > > > > >
> > > > > >
> > > > > >
> > > > > >             at
org.postgresql.core.PGStream.flush(PGStream.java:364)
> > > > > >
> > > > > >             at
> > > > > >
> > > >
> > >
> >
org.postgresql.jdbc1.AbstractJdbc1Connection.openConnection(AbstractJdbc1Con
> > > > > > nection.java:269)
> > > > > >
> > > > > >             at org.postgresql.Driver.connect(Driver.java:137)
> > > > > >
> > > > > >             at
> > > > java.sql.DriverManager.getConnection(DriverManager.java:512)
> > > > > >
> > > > > >             at
> > > > java.sql.DriverManager.getConnection(DriverManager.java:140)
> > > > > >
> > > > > >             at docextractor.test.main(test.java:35)
> > > > > >
> > > > > >
> > > > > > Exception: An I/O error has occured while flushing the output -
> > > > Exception:
> > > > > > javax.net.ssl.SSLHandshakeException:
> > > > > > java.security.cert.CertificateException: Couldn't find trusted
> > > > certificate
> > > > > >
> > > > > > Stack Trace:
> > > > > >
> > > > > >
> > > > > >
> > > > > > javax.net.ssl.SSLHandshakeException:
> > > > > > java.security.cert.CertificateException: Couldn't find trusted
> > > > certificate
> > > > > >
> > > > > >             at
> > > > com.sun.net.ssl.internal.ssl.BaseSSLSocketImpl.a(DashoA6275)
> > > > > >
> > > > > >             at
> > > com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA6275)
> > > > > >
> > > > > >             at
> > > com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA6275)
> > > > > >
> > > > > >             at
com.sun.net.ssl.internal.ssl.SunJSSE_az.a(DashoA6275)
> > > > > >
> > > > > >             at
com.sun.net.ssl.internal.ssl.SunJSSE_az.a(DashoA6275)
> > > > > >
> > > > > >             at
com.sun.net.ssl.internal.ssl.SunJSSE_ax.a(DashoA6275)
> > > > > >
> > > > > >             at
> > > com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA6275)
> > > > > >
> > > > > >             at
> > > com.sun.net.ssl.internal.ssl.SSLSocketImpl.j(DashoA6275)
> > > > > >
> > > > > >             at
> > > com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA6275)
> > > > > >
> > > > > >             at
> > > > > > com.sun.net.ssl.internal.ssl.AppOutputStream.write(DashoA6275)
> > > > > >
> > > > > >             at
> > > > > >
> > java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:69)
> > > > > >
> > > > > >             at
> > > > > >
java.io.BufferedOutputStream.flush(BufferedOutputStream.java:127)
> > > > > >
> > > > > >             at
org.postgresql.core.PGStream.flush(PGStream.java:360)
> > > > > >
> > > > > >             at
> > > > > >
> > > >
> > >
> >
org.postgresql.jdbc1.AbstractJdbc1Connection.openConnection(AbstractJdbc1Con
> > > > > > nection.java:269)
> > > > > >
> > > > > >             at org.postgresql.Driver.connect(Driver.java:137)
> > > > > >
> > > > > >             at
> > > > java.sql.DriverManager.getConnection(DriverManager.java:512)
> > > > > >
> > > > > >             at
> > > > java.sql.DriverManager.getConnection(DriverManager.java:140)
> > > > > >
> > > > > >             at docextractor.test.main(test.java:35)
> > > > > >
> > > > > >
> > > > > > Caused by: java.security.cert.CertificateException: Couldn't
find
> > > > trusted
> > > > > > certificate
> > > > > >
> > > > > >
> > > > > >             at
> > > > > > com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.a(DashoA6275)
> > > > > >
> > > > > >             at
> > > > > >
> > > >
> > >
> >
com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(DashoA6
> > > > > > 275)
> > > > > >
> > > > > >             at
> > > > > >
> > > >
> > >
> >
com.sun.net.ssl.internal.ssl.JsseX509TrustManager.checkServerTrusted(DashoA6
> > > > > > 275)
> > > > > >
> > > > > >             ... 15 more
> > > > > >
> > > > > >
> > > > > > End of Stack Trace
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > At the server side I get
> > > > > >
> > > > > >
> > > > > >
> > > > > > Failed to inititalize SSL Connection: sslv3 alert certificate
> > unknown
> > > > > > (Success)
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > I have not been able to find any clear resolutions to this
problem.
> > If
> > > > > > someone can shed some light on a solution to this problem it
would
> > be
> > > > > > greatly appreciated.
> > > > > >
> > > > > >
> > > > > >
> > > > > > ----- Original Message -----
> > > > > > From: "Barry Lind" <blind@xythos.com>
> > > > > > To: "John Laban" <johnl@infotn.com>
> > > > > > Cc: <pgsql-jdbc@postgresql.org>
> > > > > > Sent: Thursday, March 27, 2003 5:58 PM
> > > > > > Subject: Re: [JDBC] JDBC with SSL
> > > > > >
> > > > > >
> > > > > >
> > > > > >>John,
> > > > > >>
> > > > > >>This hasn't yet made it to the documentation.
> > > > > >>
> > > > > >>but adding ?ssl to the url should be what you need.  (also
consider
> > > > > >>using &loglevel=2 to turn on debugging info).
> > > > > >>
> > > > > >>--Barry
> > > > > >>
> > > > > >>John Laban wrote:
> > > > > >>
> > > > > >>>Hello,
> > > > > >>>
> > > > > >>>The newest developement JDBC drivers (7.4dev, build 204,
> > 2003-03-23)
> > > > say
> > > > > >
> > > > > > they include support for SSL.  I can set up the server to use
SSL,
> > but
> > > I
> > > > > > can't seem to get the JDBC driver to actually connect using SSL.
Is
> > > > there
> > > > > > any documentation on this?  Or is there a specific parameter I
am
> > > > supposed
> > > > > > to include in the connection URL?
> > > > > >
> > > > > >>>Any help in this would be appreciated.
> > > > > >>>
> > > > > >>>John Laban
> > > > > >>>
> > > > > >>
> > > > > >>
> > > > > >>---------------------------(end of
> > > broadcast)---------------------------
> > > > > >>TIP 5: Have you checked our extensive FAQ?
> > > > > >>
> > > > > >>http://www.postgresql.org/docs/faqs/FAQ.html
> > > > > >
> > > > > >
> > > > > >
> > > > > > ---------------------------(end of
> > > broadcast)---------------------------
> > > > > > TIP 6: Have you searched our list archives?
> > > > > >
> > > > > > http://archives.postgresql.org
> > > > > >
> > > > >
> > > > >
> > > > > ---------------------------(end of
> > broadcast)---------------------------
> > > > > TIP 6: Have you searched our list archives?
> > > > >
> > > > > http://archives.postgresql.org
> > > >
> > > >
> > > > ---------------------------(end of
broadcast)---------------------------
> > > > TIP 4: Don't 'kill -9' the postmaster
> > > >
> > >
> > >
> > > ---------------------------(end of
broadcast)---------------------------
> > > TIP 6: Have you searched our list archives?
> > >
> > > http://archives.postgresql.org
> >
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 3: if posting/reading through Usenet, please send an appropriate
> > subscribe-nomail command to majordomo@postgresql.org so that your
> > message can get through to the mailing list cleanly
> >
>




^ permalink  raw  reply  [nested|flat] 25+ messages in thread

* JDBC with SSL
@ 2003-09-21 15:43 Angel Todorov <atodorov@acm.org>
  2003-09-22 04:06 ` Re: JDBC with SSL Barry Lind <blind@xythos.com>
  0 siblings, 1 reply; 25+ messages in thread

From: Angel Todorov @ 2003-09-21 15:43 UTC (permalink / raw)
  To: pgsql-jdbc

Hello,
I have a question regarding the SSL support of  the development JDBC3 
driver. I want to connect securely to a postgresql database . My 
environment is the following:

PostgreSQL server version: PostgreSQL 7.3.2
OS on which the server is running: OpenBSD 3.3

--- from postgresql.conf ---

ssl = true

----------------------------

I have also generated the needed certificates for the SSL support as 
described in the PostgreSQL manual under" 3.7. Secure TCP/IP Connections 
with SSL".

The client enviroment is the following:
OS: Windows XP
JDK : j2sdk1.4.2_01
jdbc driver: JDBC3, development version
IDE: Eclipse

Normally, without SSL, the connectivity is O.K

When enabled, the following exception is thrown:

org.postgresql.util.PSQLException: An I/O error has occured while 
flushing the output - Exception: javax.net.ssl.SSLHandshakeException: 
sun.security.validator.ValidatorException: No trusted certificate found

Here is also a small part of the stack trace:
--------------------------------------------------
Caused by: sun.security.validator.ValidatorException: No trusted 
certificate found
   at sun.security.validator.SimpleValidator.buildTrustedChain(Unknown 
Source)
   at sun.security.validator.SimpleValidator.engineValidate(Unknown Source)
   at sun.security.validator.Validator.validate(Unknown Source)
   at 
com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(Unknown 
Source)
   at 
com.sun.net.ssl.internal.ssl.JsseX509TrustManager.checkServerTrusted(Unknown 
Source)
   ... 16 more
End of Stack Trace

   at org.postgresql.core.PGStream.flush(PGStream.java:416)
   at 
org.postgresql.jdbc1.AbstractJdbc1Connection.openConnectionV3(AbstractJdbc1Connection.java:284) 

   at 
org.postgresql.jdbc1.AbstractJdbc1Connection.openConnection(AbstractJdbc1Connection.java:213) 

   at org.postgresql.Driver.connect(Driver.java:138)
   at java.sql.DriverManager.getConnection(Unknown Source)
   at java.sql.DriverManager.getConnection(Unknown Source)
   at PostgreSQLSSL.main(PostgreSQLSSL.java:33)
java.lang.NullPointerException
   at PostgreSQLSSL.main(PostgreSQLSSL.java:39)
Exception in thread "main"
-----------------------------------------------------

The code that generates the above Exception is :

--- START ------

   public static void main(String[] args) throws SQLException {

       Properties opt = new Properties();
             opt.setProperty("ssl", "true");
       opt.setProperty("user", username);
       opt.setProperty("password", password);

       Connection db=null;
             try {
                 Class driver=Class.forName("org.postgresql.Driver");
       db = DriverManager.getConnection(url, opt);
       } catch (Exception e) {
           e.printStackTrace();
       }
------- END ------------

I have imported the server's certificate using the keytool successfully 
, though the exception states that no *trusted* certificate is found. My 
certificate is self-signed. Could it be the problem that the certificate 
is not accepted (i.e i have to create it differently either on the 
server side, or import it differently on the client side) ? Or maybe  
there is a conflict between the PostgreSQL and JDBC3 versions?

Thanks a lot in advance for your help.

Regards,

Angel




^ permalink  raw  reply  [nested|flat] 25+ messages in thread

* Re: JDBC with SSL
  2003-09-21 15:43 JDBC with SSL Angel Todorov <atodorov@acm.org>
@ 2003-09-22 04:06 ` Barry Lind <blind@xythos.com>
  0 siblings, 0 replies; 25+ messages in thread

From: Barry Lind @ 2003-09-22 04:06 UTC (permalink / raw)
  To: Angel Todorov <atodorov@acm.org>; +Cc: pgsql-jdbc

Can you provide the steps you used to create and import your cert?

thanks,
--Barry


Angel Todorov wrote:
> Hello,
> I have a question regarding the SSL support of  the development JDBC3 
> driver. I want to connect securely to a postgresql database . My 
> environment is the following:
> 
> PostgreSQL server version: PostgreSQL 7.3.2
> OS on which the server is running: OpenBSD 3.3
> 
> --- from postgresql.conf ---
> 
> ssl = true
> 
> ----------------------------
> 
> I have also generated the needed certificates for the SSL support as 
> described in the PostgreSQL manual under" 3.7. Secure TCP/IP Connections 
> with SSL".
> 
> The client enviroment is the following:
> OS: Windows XP
> JDK : j2sdk1.4.2_01
> jdbc driver: JDBC3, development version
> IDE: Eclipse
> 
> Normally, without SSL, the connectivity is O.K
> 
> When enabled, the following exception is thrown:
> 
> org.postgresql.util.PSQLException: An I/O error has occured while 
> flushing the output - Exception: javax.net.ssl.SSLHandshakeException: 
> sun.security.validator.ValidatorException: No trusted certificate found
> 
> Here is also a small part of the stack trace:
> --------------------------------------------------
> Caused by: sun.security.validator.ValidatorException: No trusted 
> certificate found
>   at sun.security.validator.SimpleValidator.buildTrustedChain(Unknown 
> Source)
>   at sun.security.validator.SimpleValidator.engineValidate(Unknown Source)
>   at sun.security.validator.Validator.validate(Unknown Source)
>   at 
> com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(Unknown 
> Source)
>   at 
> com.sun.net.ssl.internal.ssl.JsseX509TrustManager.checkServerTrusted(Unknown 
> Source)
>   ... 16 more
> End of Stack Trace
> 
>   at org.postgresql.core.PGStream.flush(PGStream.java:416)
>   at 
> org.postgresql.jdbc1.AbstractJdbc1Connection.openConnectionV3(AbstractJdbc1Connection.java:284) 
> 
>   at 
> org.postgresql.jdbc1.AbstractJdbc1Connection.openConnection(AbstractJdbc1Connection.java:213) 
> 
>   at org.postgresql.Driver.connect(Driver.java:138)
>   at java.sql.DriverManager.getConnection(Unknown Source)
>   at java.sql.DriverManager.getConnection(Unknown Source)
>   at PostgreSQLSSL.main(PostgreSQLSSL.java:33)
> java.lang.NullPointerException
>   at PostgreSQLSSL.main(PostgreSQLSSL.java:39)
> Exception in thread "main"
> -----------------------------------------------------
> 
> The code that generates the above Exception is :
> 
> --- START ------
> 
>   public static void main(String[] args) throws SQLException {
> 
>       Properties opt = new Properties();
>             opt.setProperty("ssl", "true");
>       opt.setProperty("user", username);
>       opt.setProperty("password", password);
> 
>       Connection db=null;
>             try {
>                 Class driver=Class.forName("org.postgresql.Driver");
>       db = DriverManager.getConnection(url, opt);
>       } catch (Exception e) {
>           e.printStackTrace();
>       }
> ------- END ------------
> 
> I have imported the server's certificate using the keytool successfully 
> , though the exception states that no *trusted* certificate is found. My 
> certificate is self-signed. Could it be the problem that the certificate 
> is not accepted (i.e i have to create it differently either on the 
> server side, or import it differently on the client side) ? Or maybe  
> there is a conflict between the PostgreSQL and JDBC3 versions?
> 
> Thanks a lot in advance for your help.
> 
> Regards,
> 
> Angel
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
> 
>               http://www.postgresql.org/docs/faqs/FAQ.html
> 





^ permalink  raw  reply  [nested|flat] 25+ messages in thread

* JDBC with SSL
@ 2011-12-04 16:40 Walter Hurry <walterhurry@lavabit.com>
  2011-12-04 19:09 ` Re: JDBC with SSL Florent Guillaume <fg@nuxeo.com>
  0 siblings, 1 reply; 25+ messages in thread

From: Walter Hurry @ 2011-12-04 16:40 UTC (permalink / raw)
  To: pgsql-jdbc

First of all, I am sorry if this is the wrong place to ask. If it is, 
perhaps someone could direct me to the right arena.

This is PostgreSQL 9.0.1 with PostgreSQL JDBC 9.1.901.

I have successfully set up one of my databases to require SSL connections 
with a certificate, and installed a certificate into $HOME/.postgresql. 
That directory contains postgresql.crt,  postgresql.key and root.crt.

I can connect successfully using psql and libpq applications. The 
connection is also rejected properly if I move the certificate out of the 
way.

Now I am trying to connect using JDBC and SSL from a Java application 
(JDBC is fine without SSL on another database). However, I am getting the 
following error:

FATAL: connection requires a valid client certificate

So it appears that somehow I need to "tell" Java where to find the client 
certificate. Any pointers as to how I do this please?

By the way, since this is a self-signed certificate I have followed the 
instructions at <http://jdbc.postgresql.org/documentation/81/ssl-
client.html>. These succeeded, but I am still getting the error.

Thanks,
Walter

 





^ permalink  raw  reply  [nested|flat] 25+ messages in thread

* Re: JDBC with SSL
  2011-12-04 16:40 JDBC with SSL Walter Hurry <walterhurry@lavabit.com>
@ 2011-12-04 19:09 ` Florent Guillaume <fg@nuxeo.com>
  2011-12-04 20:48   ` Re: JDBC with SSL Walter Hurry <walterhurry@lavabit.com>
  0 siblings, 1 reply; 25+ messages in thread

From: Florent Guillaume @ 2011-12-04 19:09 UTC (permalink / raw)
  To: Walter Hurry <walterhurry@lavabit.com>; +Cc: pgsql-jdbc

Hi,

You have to install the certificate in the Java keystore using "keytool".
See http://docs.oracle.com/javase/tutorial/security/toolsign/rstep2.html
for a quick overview.
A more detailed doc is at
http://docs.oracle.com/javaee/1.4/tutorial/doc/Security6.html

Florent

On Sun, Dec 4, 2011 at 5:40 PM, Walter Hurry <walterhurry@lavabit.com> wrote:
> First of all, I am sorry if this is the wrong place to ask. If it is,
> perhaps someone could direct me to the right arena.
>
> This is PostgreSQL 9.0.1 with PostgreSQL JDBC 9.1.901.
>
> I have successfully set up one of my databases to require SSL connections
> with a certificate, and installed a certificate into $HOME/.postgresql.
> That directory contains postgresql.crt,  postgresql.key and root.crt.
>
> I can connect successfully using psql and libpq applications. The
> connection is also rejected properly if I move the certificate out of the
> way.
>
> Now I am trying to connect using JDBC and SSL from a Java application
> (JDBC is fine without SSL on another database). However, I am getting the
> following error:
>
> FATAL: connection requires a valid client certificate
>
> So it appears that somehow I need to "tell" Java where to find the client
> certificate. Any pointers as to how I do this please?
>
> By the way, since this is a self-signed certificate I have followed the
> instructions at <http://jdbc.postgresql.org/documentation/81/ssl-
> client.html>. These succeeded, but I am still getting the error.
>
> Thanks,
> Walter
>
>
>
>
>
> --
> Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-jdbc
>



-- 
Florent Guillaume, Director of R&D, Nuxeo
Open Source, Java EE based, Enterprise Content Management (ECM)
http://www.nuxeo.com   http://www.nuxeo.org   +33 1 40 33 79 87



^ permalink  raw  reply  [nested|flat] 25+ messages in thread

* Re: JDBC with SSL
  2011-12-04 16:40 JDBC with SSL Walter Hurry <walterhurry@lavabit.com>
  2011-12-04 19:09 ` Re: JDBC with SSL Florent Guillaume <fg@nuxeo.com>
@ 2011-12-04 20:48   ` Walter Hurry <walterhurry@lavabit.com>
  2011-12-05 00:28     ` Re: JDBC with SSL Craig Ringer <ringerc@ringerc.id.au>
  0 siblings, 1 reply; 25+ messages in thread

From: Walter Hurry @ 2011-12-04 20:48 UTC (permalink / raw)
  To: pgsql-jdbc

On Sun, 04 Dec 2011 20:09:09 +0100, Florent Guillaume wrote:

> Hi,
> 
> You have to install the certificate in the Java keystore using
> "keytool". See
> http://docs.oracle.com/javase/tutorial/security/toolsign/rstep2.html for
> a quick overview.
> A more detailed doc is at
> http://docs.oracle.com/javaee/1.4/tutorial/doc/Security6.html
> 
> Florent
> 
> On Sun, Dec 4, 2011 at 5:40 PM, Walter Hurry <walterhurry@lavabit.com>
> wrote:
>> First of all, I am sorry if this is the wrong place to ask. If it is,
>> perhaps someone could direct me to the right arena.
>>
>> This is PostgreSQL 9.0.1 with PostgreSQL JDBC 9.1.901.
>>
>> I have successfully set up one of my databases to require SSL
>> connections with a certificate, and installed a certificate into
>> $HOME/.postgresql. That directory contains postgresql.crt,
>>  postgresql.key and root.crt.
>>
>> I can connect successfully using psql and libpq applications. The
>> connection is also rejected properly if I move the certificate out of
>> the way.
>>
>> Now I am trying to connect using JDBC and SSL from a Java application
>> (JDBC is fine without SSL on another database). However, I am getting
>> the following error:
>>
>> FATAL: connection requires a valid client certificate
>>
>> So it appears that somehow I need to "tell" Java where to find the
>> client certificate. Any pointers as to how I do this please?
>>
>> By the way, since this is a self-signed certificate I have followed the
>> instructions at <http://jdbc.postgresql.org/documentation/81/ssl-
>> client.html>. These succeeded, but I am still getting the error.
>>
>> Thanks,
>> Walter

Thanks for the reply, Florent. I have followed the instructions yu 
mentioned carefully, and am now invoking the class with:

java -Djava.security.manager -Djava.security.policy=clientpolicy 
<classname>

but I am getting:

Your security policy has prevented the connection from being attempted.  
You probably need to grant the connect java.net.SocketPermission to the 
database server host and port that you wish to connect to.

Where do I go from here?

Thanks again,
Walter




^ permalink  raw  reply  [nested|flat] 25+ messages in thread

* Re: JDBC with SSL
  2011-12-04 16:40 JDBC with SSL Walter Hurry <walterhurry@lavabit.com>
  2011-12-04 19:09 ` Re: JDBC with SSL Florent Guillaume <fg@nuxeo.com>
  2011-12-04 20:48   ` Re: JDBC with SSL Walter Hurry <walterhurry@lavabit.com>
@ 2011-12-05 00:28     ` Craig Ringer <ringerc@ringerc.id.au>
  2011-12-05 18:46       ` Re: JDBC with SSL Walter Hurry <walterhurry@lavabit.com>
  0 siblings, 1 reply; 25+ messages in thread

From: Craig Ringer @ 2011-12-05 00:28 UTC (permalink / raw)
  To: Walter Hurry <walterhurry@lavabit.com>; +Cc: pgsql-jdbc

On 12/05/2011 04:48 AM, Walter Hurry wrote:
> On Sun, 04 Dec 2011 20:09:09 +0100, Florent Guillaume wrote:
>
>> Hi,
>>
>> You have to install the certificate in the Java keystore using
>> "keytool". See
>> http://docs.oracle.com/javase/tutorial/security/toolsign/rstep2.html for
>> a quick overview.
>> A more detailed doc is at
>> http://docs.oracle.com/javaee/1.4/tutorial/doc/Security6.html
>>
>> Florent
>>
>> On Sun, Dec 4, 2011 at 5:40 PM, Walter Hurry<walterhurry@lavabit.com>
>> wrote:
>>> First of all, I am sorry if this is the wrong place to ask. If it is,
>>> perhaps someone could direct me to the right arena.
>>>
>>> This is PostgreSQL 9.0.1 with PostgreSQL JDBC 9.1.901.
>>>
>>> I have successfully set up one of my databases to require SSL
>>> connections with a certificate, and installed a certificate into
>>> $HOME/.postgresql. That directory contains postgresql.crt,
>>>   postgresql.key and root.crt.
>>>
>>> I can connect successfully using psql and libpq applications. The
>>> connection is also rejected properly if I move the certificate out of
>>> the way.
>>>
>>> Now I am trying to connect using JDBC and SSL from a Java application
>>> (JDBC is fine without SSL on another database). However, I am getting
>>> the following error:
>>>
>>> FATAL: connection requires a valid client certificate
>>>
>>> So it appears that somehow I need to "tell" Java where to find the
>>> client certificate. Any pointers as to how I do this please?
>>>
>>> By the way, since this is a self-signed certificate I have followed the
>>> instructions at<http://jdbc.postgresql.org/documentation/81/ssl-
>>> client.html>. These succeeded, but I am still getting the error.
>>>
>>> Thanks,
>>> Walter
> Thanks for the reply, Florent. I have followed the instructions yu
> mentioned carefully, and am now invoking the class with:
>
> java -Djava.security.manager -Djava.security.policy=clientpolicy
> <classname>
>
You don't need the SecurityManager enabled. You need the java.net.ssl 
properties for keyStore, keyStorePassword and keyStoreType set to point 
to your JECKS keystore, and need trustStore, trustStorePassword and 
trustStoreType set to point to the keystore you imported the database's 
certificate into, which is probably the same store in your case.

Alternately, you can use the custom certificate manager class posted on 
this mailing list a while ago to manage key and trust store lookup from 
your own stores at runtime.

--
Craig Ringer



^ permalink  raw  reply  [nested|flat] 25+ messages in thread

* Re: JDBC with SSL
  2011-12-04 16:40 JDBC with SSL Walter Hurry <walterhurry@lavabit.com>
  2011-12-04 19:09 ` Re: JDBC with SSL Florent Guillaume <fg@nuxeo.com>
  2011-12-04 20:48   ` Re: JDBC with SSL Walter Hurry <walterhurry@lavabit.com>
  2011-12-05 00:28     ` Re: JDBC with SSL Craig Ringer <ringerc@ringerc.id.au>
@ 2011-12-05 18:46       ` Walter Hurry <walterhurry@lavabit.com>
  2011-12-05 19:21         ` Re: JDBC with SSL Magosányi Árpád <mag@magwas.rulez.org>
  2011-12-06 00:45         ` Re: JDBC with SSL Craig Ringer <ringerc@ringerc.id.au>
  0 siblings, 2 replies; 25+ messages in thread

From: Walter Hurry @ 2011-12-05 18:46 UTC (permalink / raw)
  To: pgsql-jdbc

On Mon, 05 Dec 2011 08:28:33 +0800, Craig Ringer wrote:

> You don't need the SecurityManager enabled. You need the java.net.ssl
> properties for keyStore, keyStorePassword and keyStoreType set to point
> to your JECKS keystore, and need trustStore, trustStorePassword and
> trustStoreType set to point to the keystore you imported the database's
> certificate into, which is probably the same store in your case.
 
<snip option 2>

Thanks for the guidance, Craig. I'm trying to use javax.net.ssl but I'm 
still stuck. Sample below:
-------------------------------------------------------------
$ java -Djavax.net.ssl.keyStore=$HOME/.postgresql/clientstore \
       -Djavax.net.ssl.keyStorePassword=changeit \
       -Djavax.net.ssl.keyStoreType="jks" \
       -Djavax.net.ssl.trustStore=$JAVA_HOME/lib/security/cacerts \
       -Djavax.net.ssl.trustStorePassword=changeit \
       -Djavax.net.ssl.trustStoreType="jks" \
       JDBCExample neptune misc
-------- PostgreSQL JDBC Connection Testing ------------
PostgreSQL JDBC driver registered
Getting connection to jdbc:postgresql://neptune/misc
Connect failed: FATAL: connection requires a valid client certificate
-------------------------------------------------------------

Any idea what I am doing wrong?

Thanks.





^ permalink  raw  reply  [nested|flat] 25+ messages in thread

* Re: JDBC with SSL
  2011-12-04 16:40 JDBC with SSL Walter Hurry <walterhurry@lavabit.com>
  2011-12-04 19:09 ` Re: JDBC with SSL Florent Guillaume <fg@nuxeo.com>
  2011-12-04 20:48   ` Re: JDBC with SSL Walter Hurry <walterhurry@lavabit.com>
  2011-12-05 00:28     ` Re: JDBC with SSL Craig Ringer <ringerc@ringerc.id.au>
  2011-12-05 18:46       ` Re: JDBC with SSL Walter Hurry <walterhurry@lavabit.com>
@ 2011-12-05 19:21         ` Magosányi Árpád <mag@magwas.rulez.org>
  1 sibling, 0 replies; 25+ messages in thread

From: Magosányi Árpád @ 2011-12-05 19:21 UTC (permalink / raw)
  To: pgsql-jdbc

Maybe a take in the wrong direction, but have you checked that all certs 
are existing and valid throughout the certificate chain?
I am talking about both the server and the client side.
(Yes, you have already said that it does work with psql, so the question 
is whether all certs and the key are imported correctly into the keystore.)

BTW I have found more convenient to use the same keystore for both the 
client cert/key and the trust anchors.

On 12/05/2011 07:46 PM, Walter Hurry wrote:
> On Mon, 05 Dec 2011 08:28:33 +0800, Craig Ringer wrote:
>
>> You don't need the SecurityManager enabled. You need the java.net.ssl
>> properties for keyStore, keyStorePassword and keyStoreType set to point
>> to your JECKS keystore, and need trustStore, trustStorePassword and
>> trustStoreType set to point to the keystore you imported the database's
>> certificate into, which is probably the same store in your case.
>
> <snip option 2>
>
> Thanks for the guidance, Craig. I'm trying to use javax.net.ssl but I'm
> still stuck. Sample below:
> -------------------------------------------------------------
> $ java -Djavax.net.ssl.keyStore=$HOME/.postgresql/clientstore \
>         -Djavax.net.ssl.keyStorePassword=changeit \
>         -Djavax.net.ssl.keyStoreType="jks" \
>         -Djavax.net.ssl.trustStore=$JAVA_HOME/lib/security/cacerts \
>         -Djavax.net.ssl.trustStorePassword=changeit \
>         -Djavax.net.ssl.trustStoreType="jks" \
>         JDBCExample neptune misc
> -------- PostgreSQL JDBC Connection Testing ------------
> PostgreSQL JDBC driver registered
> Getting connection to jdbc:postgresql://neptune/misc
> Connect failed: FATAL: connection requires a valid client certificate
> -------------------------------------------------------------
>
> Any idea what I am doing wrong?
>
> Thanks.
>
>
>




^ permalink  raw  reply  [nested|flat] 25+ messages in thread

* Re: JDBC with SSL
  2011-12-04 16:40 JDBC with SSL Walter Hurry <walterhurry@lavabit.com>
  2011-12-04 19:09 ` Re: JDBC with SSL Florent Guillaume <fg@nuxeo.com>
  2011-12-04 20:48   ` Re: JDBC with SSL Walter Hurry <walterhurry@lavabit.com>
  2011-12-05 00:28     ` Re: JDBC with SSL Craig Ringer <ringerc@ringerc.id.au>
  2011-12-05 18:46       ` Re: JDBC with SSL Walter Hurry <walterhurry@lavabit.com>
@ 2011-12-06 00:45         ` Craig Ringer <ringerc@ringerc.id.au>
  2011-12-06 19:43           ` Re: JDBC with SSL Walter Hurry <walterhurry@lavabit.com>
  1 sibling, 1 reply; 25+ messages in thread

From: Craig Ringer @ 2011-12-06 00:45 UTC (permalink / raw)
  To: Walter Hurry <walterhurry@lavabit.com>; +Cc: pgsql-jdbc

On 12/06/2011 02:46 AM, Walter Hurry wrote:
> -------------------------------------------------------------
> $ java -Djavax.net.ssl.keyStore=$HOME/.postgresql/clientstore \
>         -Djavax.net.ssl.keyStorePassword=changeit \
>         -Djavax.net.ssl.keyStoreType="jks" \
>
I thought you could only use a JECKS store when including private keys?

--
Craig Ringer



^ permalink  raw  reply  [nested|flat] 25+ messages in thread

* Re: JDBC with SSL
  2011-12-04 16:40 JDBC with SSL Walter Hurry <walterhurry@lavabit.com>
  2011-12-04 19:09 ` Re: JDBC with SSL Florent Guillaume <fg@nuxeo.com>
  2011-12-04 20:48   ` Re: JDBC with SSL Walter Hurry <walterhurry@lavabit.com>
  2011-12-05 00:28     ` Re: JDBC with SSL Craig Ringer <ringerc@ringerc.id.au>
  2011-12-05 18:46       ` Re: JDBC with SSL Walter Hurry <walterhurry@lavabit.com>
  2011-12-06 00:45         ` Re: JDBC with SSL Craig Ringer <ringerc@ringerc.id.au>
@ 2011-12-06 19:43           ` Walter Hurry <walterhurry@lavabit.com>
  2011-12-07 05:06             ` Re: JDBC with SSL Craig Ringer <ringerc@ringerc.id.au>
  0 siblings, 1 reply; 25+ messages in thread

From: Walter Hurry @ 2011-12-06 19:43 UTC (permalink / raw)
  To: pgsql-jdbc

On Tue, 06 Dec 2011 08:45:48 +0800, Craig Ringer wrote:

> On 12/06/2011 02:46 AM, Walter Hurry wrote:
>> ------------------------------------------------------------- $ java
>> -Djavax.net.ssl.keyStore=$HOME/.postgresql/clientstore \
>>         -Djavax.net.ssl.keyStorePassword=changeit \
>>         -Djavax.net.ssl.keyStoreType="jks" \
>>
> I thought you could only use a JECKS store when including private keys?

Sorry, I'm pretty new to all this. What is a JECKS store? Does it mean I 
have the keyStoreType wrong?





^ permalink  raw  reply  [nested|flat] 25+ messages in thread

* Re: JDBC with SSL
  2011-12-04 16:40 JDBC with SSL Walter Hurry <walterhurry@lavabit.com>
  2011-12-04 19:09 ` Re: JDBC with SSL Florent Guillaume <fg@nuxeo.com>
  2011-12-04 20:48   ` Re: JDBC with SSL Walter Hurry <walterhurry@lavabit.com>
  2011-12-05 00:28     ` Re: JDBC with SSL Craig Ringer <ringerc@ringerc.id.au>
  2011-12-05 18:46       ` Re: JDBC with SSL Walter Hurry <walterhurry@lavabit.com>
  2011-12-06 00:45         ` Re: JDBC with SSL Craig Ringer <ringerc@ringerc.id.au>
  2011-12-06 19:43           ` Re: JDBC with SSL Walter Hurry <walterhurry@lavabit.com>
@ 2011-12-07 05:06             ` Craig Ringer <ringerc@ringerc.id.au>
  2011-12-07 16:27               ` Re: JDBC with SSL Bruno Harbulot <bruno@distributedmatter.net>
  0 siblings, 1 reply; 25+ messages in thread

From: Craig Ringer @ 2011-12-07 05:06 UTC (permalink / raw)
  To: Walter Hurry <walterhurry@lavabit.com>; +Cc: pgsql-jdbc

On 07/12/11 03:43, Walter Hurry wrote:
> On Tue, 06 Dec 2011 08:45:48 +0800, Craig Ringer wrote:
>
>> On 12/06/2011 02:46 AM, Walter Hurry wrote:
>>> ------------------------------------------------------------- $ java
>>> -Djavax.net.ssl.keyStore=$HOME/.postgresql/clientstore \
>>>         -Djavax.net.ssl.keyStorePassword=changeit \
>>>         -Djavax.net.ssl.keyStoreType="jks" \
>>>
>> I thought you could only use a JECKS store when including private keys?
> Sorry, I'm pretty new to all this. What is a JECKS store? Does it mean I 
> have the keyStoreType wrong?

JKS and JECKS are two different key store formats. Keytool understands
both. If my memory serves, JECKS is the encrypted keystore format,
intended for storing private key data. I think you can use JECKS for
both certificate and key data, but you can use JKS only for certificate
data, NOT  for key data.

If you want your trusted certs and your client certs+keys in the same
store, use a JECKS store by passing the "-storetype JECKS" argument to
keytool when creating the store and importing a cert into it. I have the
niggling memory that if you use the JKS store (default) then keytool
imports the certificate from your input pkcs#2 (or whatever) file and
ignores the key.

--
Craig Ringer



^ permalink  raw  reply  [nested|flat] 25+ messages in thread

* Re: JDBC with SSL
  2011-12-04 16:40 JDBC with SSL Walter Hurry <walterhurry@lavabit.com>
  2011-12-04 19:09 ` Re: JDBC with SSL Florent Guillaume <fg@nuxeo.com>
  2011-12-04 20:48   ` Re: JDBC with SSL Walter Hurry <walterhurry@lavabit.com>
  2011-12-05 00:28     ` Re: JDBC with SSL Craig Ringer <ringerc@ringerc.id.au>
  2011-12-05 18:46       ` Re: JDBC with SSL Walter Hurry <walterhurry@lavabit.com>
  2011-12-06 00:45         ` Re: JDBC with SSL Craig Ringer <ringerc@ringerc.id.au>
  2011-12-06 19:43           ` Re: JDBC with SSL Walter Hurry <walterhurry@lavabit.com>
  2011-12-07 05:06             ` Re: JDBC with SSL Craig Ringer <ringerc@ringerc.id.au>
@ 2011-12-07 16:27               ` Bruno Harbulot <bruno@distributedmatter.net>
  2011-12-07 16:34                 ` Re: JDBC with SSL Bruno Harbulot <bruno@distributedmatter.net>
  2011-12-07 18:00                 ` Re: JDBC with SSL Walter Hurry <walterhurry@lavabit.com>
  0 siblings, 2 replies; 25+ messages in thread

From: Bruno Harbulot @ 2011-12-07 16:27 UTC (permalink / raw)
  To: pgsql-jdbc; +Cc: Craig Ringer <ringerc@ringerc.id.au>

On 07/12/2011 05:06, Craig Ringer wrote:
> On 07/12/11 03:43, Walter Hurry wrote:
>> On Tue, 06 Dec 2011 08:45:48 +0800, Craig Ringer wrote:
>>
>>> On 12/06/2011 02:46 AM, Walter Hurry wrote:
>>>> ------------------------------------------------------------- $ java
>>>> -Djavax.net.ssl.keyStore=$HOME/.postgresql/clientstore \
>>>>          -Djavax.net.ssl.keyStorePassword=changeit \
>>>>          -Djavax.net.ssl.keyStoreType="jks" \
>>>>
>>> I thought you could only use a JECKS store when including private keys?
>> Sorry, I'm pretty new to all this. What is a JECKS store? Does it mean I
>> have the keyStoreType wrong?
>
> JKS and JECKS are two different key store formats. Keytool understands
> both. If my memory serves, JECKS is the encrypted keystore format,
> intended for storing private key data. I think you can use JECKS for
> both certificate and key data, but you can use JKS only for certificate
> data, NOT  for key data.

You can store certificates and/or private keys in both JKS and JECKS.

PKCS12 is somewhat different in that, to store a certificate (or a 
certificate chain), it requires there to be a private key associated 
with this certificate. Java isn't the only implementation with this 
limitation, but I must admit I can't remember what the PKCS#12 
specification itself says about it.


More details on JKS/JECKS, from:
http://docs.oracle.com/javase/6/docs/technotes/guides/security/crypto/CryptoSpec.html#KeystoreImplem...

> jceks" is an alternate proprietary keystore format to "jks" that uses much stronger encryption in the form of Password-Based Encryption with Triple-DES.



The default keystore type with the Oracle security provider is JKS; you 
can check this using KeyStore.getDefaultType().


If your initial key and certs where in PEM format (as used by psql), it 
might be easier to build a PKCS#12 store with OpenSSL:

    openssl pkcs12 -export -in usercert.pem -inkey userkey.pem -out 
usercreds.p12


You can then use it with KeyStore type "PKCS12" (no #) from Java directly.
You could also convert this PKCS#12 file into a JKS/JECKS keystore using 
keytool and its -importstore options (only in Java 6+).


Best wishes,

Bruno.




^ permalink  raw  reply  [nested|flat] 25+ messages in thread

* Re: JDBC with SSL
  2011-12-04 16:40 JDBC with SSL Walter Hurry <walterhurry@lavabit.com>
  2011-12-04 19:09 ` Re: JDBC with SSL Florent Guillaume <fg@nuxeo.com>
  2011-12-04 20:48   ` Re: JDBC with SSL Walter Hurry <walterhurry@lavabit.com>
  2011-12-05 00:28     ` Re: JDBC with SSL Craig Ringer <ringerc@ringerc.id.au>
  2011-12-05 18:46       ` Re: JDBC with SSL Walter Hurry <walterhurry@lavabit.com>
  2011-12-06 00:45         ` Re: JDBC with SSL Craig Ringer <ringerc@ringerc.id.au>
  2011-12-06 19:43           ` Re: JDBC with SSL Walter Hurry <walterhurry@lavabit.com>
  2011-12-07 05:06             ` Re: JDBC with SSL Craig Ringer <ringerc@ringerc.id.au>
  2011-12-07 16:27               ` Re: JDBC with SSL Bruno Harbulot <bruno@distributedmatter.net>
@ 2011-12-07 16:34                 ` Bruno Harbulot <bruno@distributedmatter.net>
  1 sibling, 0 replies; 25+ messages in thread

From: Bruno Harbulot @ 2011-12-07 16:34 UTC (permalink / raw)
  To: pgsql-jdbc; +Cc: Walter Hurry <walterhurry@lavabit.com>; Craig Ringer <ringerc@ringerc.id.au>

On 07/12/2011 16:27, Bruno Harbulot wrote:
>
> You can then use it with KeyStore type "PKCS12" (no #) from Java directly.
> You could also convert this PKCS#12 file into a JKS/JECKS keystore using
> keytool and its -importstore options (only in Java 6+).
>

Sorry, I meant -importkeystore:

   keytool -importkeystore -srckeystore usercreds.p12 \
                           -srsstoretype PKCS12 \
                           -destkeystore usercreds.jceks \
                           -deststoretype JCEKS


Best wishes,

Bruno.




^ permalink  raw  reply  [nested|flat] 25+ messages in thread

* Re: JDBC with SSL
  2011-12-04 16:40 JDBC with SSL Walter Hurry <walterhurry@lavabit.com>
  2011-12-04 19:09 ` Re: JDBC with SSL Florent Guillaume <fg@nuxeo.com>
  2011-12-04 20:48   ` Re: JDBC with SSL Walter Hurry <walterhurry@lavabit.com>
  2011-12-05 00:28     ` Re: JDBC with SSL Craig Ringer <ringerc@ringerc.id.au>
  2011-12-05 18:46       ` Re: JDBC with SSL Walter Hurry <walterhurry@lavabit.com>
  2011-12-06 00:45         ` Re: JDBC with SSL Craig Ringer <ringerc@ringerc.id.au>
  2011-12-06 19:43           ` Re: JDBC with SSL Walter Hurry <walterhurry@lavabit.com>
  2011-12-07 05:06             ` Re: JDBC with SSL Craig Ringer <ringerc@ringerc.id.au>
  2011-12-07 16:27               ` Re: JDBC with SSL Bruno Harbulot <bruno@distributedmatter.net>
@ 2011-12-07 18:00                 ` Walter Hurry <walterhurry@lavabit.com>
  1 sibling, 0 replies; 25+ messages in thread

From: Walter Hurry @ 2011-12-07 18:00 UTC (permalink / raw)
  To: pgsql-jdbc

On Wed, 07 Dec 2011 16:27:47 +0000, Bruno Harbulot wrote:

> On 07/12/2011 05:06, Craig Ringer wrote:
>> On 07/12/11 03:43, Walter Hurry wrote:
>>> On Tue, 06 Dec 2011 08:45:48 +0800, Craig Ringer wrote:
>>>
>>>> On 12/06/2011 02:46 AM, Walter Hurry wrote:
>>>>> ------------------------------------------------------------- $ java
>>>>> -Djavax.net.ssl.keyStore=$HOME/.postgresql/clientstore \
>>>>>          -Djavax.net.ssl.keyStorePassword=changeit \
>>>>>          -Djavax.net.ssl.keyStoreType="jks" \
>>>>>
>>>> I thought you could only use a JECKS store when including private
>>>> keys?
>>> Sorry, I'm pretty new to all this. What is a JECKS store? Does it mean
>>> I have the keyStoreType wrong?
>>
>> JKS and JECKS are two different key store formats. Keytool understands
>> both. If my memory serves, JECKS is the encrypted keystore format,
>> intended for storing private key data. I think you can use JECKS for
>> both certificate and key data, but you can use JKS only for certificate
>> data, NOT  for key data.
> 
> You can store certificates and/or private keys in both JKS and JECKS.
> 
> PKCS12 is somewhat different in that, to store a certificate (or a
> certificate chain), it requires there to be a private key associated
> with this certificate. Java isn't the only implementation with this
> limitation, but I must admit I can't remember what the PKCS#12
> specification itself says about it.
> 
> 
> More details on JKS/JECKS, from:
> http://docs.oracle.com/javase/6/docs/technotes/guides/security/crypto/
CryptoSpec.html#KeystoreImplementation
> 
>> jceks" is an alternate proprietary keystore format to "jks" that uses
>> much stronger encryption in the form of Password-Based Encryption with
>> Triple-DES.
> 
> 
> 
> The default keystore type with the Oracle security provider is JKS; you
> can check this using KeyStore.getDefaultType().
> 
> 
> If your initial key and certs where in PEM format (as used by psql), it
> might be easier to build a PKCS#12 store with OpenSSL:
> 
>     openssl pkcs12 -export -in usercert.pem -inkey userkey.pem -out
> usercreds.p12
> 
> 
> You can then use it with KeyStore type "PKCS12" (no #) from Java
> directly.
> You could also convert this PKCS#12 file into a JKS/JECKS keystore using
> keytool and its -importstore options (only in Java 6+).

Eureka! That nailed it (I used the pkcs12 file as it was, and didn't 
bother to convert it). Very many thanks Bruno, and to everyone who 
offered help. It is deeply appreciated.

$ java -Djavax.net.ssl.keyStore=$HOME/.postgresql/postgresql.p12 \
>        -Djavax.net.ssl.keyStorePassword=changeit \
>        -Djavax.net.ssl.keyStoreType=PKCS12 \
>        -Djavax.net.ssl.trustStore=$HOME/.postgresql/server.jceks \
>        -Djavax.net.ssl.trustStorePassword=changeit \
>        -Djavax.net.ssl.trustStoreType=jceks \
>        JDBCExample neptune misc
-------- PostgreSQL JDBC Connection Testing ------------
PostgreSQL JDBC driver registered
Getting connection to jdbc:postgresql://neptune/misc
Connection successful
$ 

Thanks again,
Walter





^ permalink  raw  reply  [nested|flat] 25+ messages in thread


end of thread, other threads:[~2011-12-07 18:00 UTC | newest]

Thread overview: 25+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-03-27 21:40 JDBC with SSL John Laban <johnl@infotn.com>
2003-03-27 22:58 ` Barry Lind <blind@xythos.com>
2003-03-28 16:01   ` John Laban <johnl@infotn.com>
2003-03-28 16:11     ` Barry Lind <blind@xythos.com>
2003-03-28 17:06       ` John Laban <johnl@infotn.com>
2003-03-28 17:48         ` Csaba Nagy <nagy@ecircle-ag.com>
2003-03-28 18:50         ` Barry Lind <blind@xythos.com>
2003-03-28 19:07         ` Nagy Istvan <nistvan@ecity.agria.hu>
2003-03-28 20:08           ` John Laban <johnl@infotn.com>
2003-03-31 08:29             ` Csaba Nagy <nagy@ecircle-ag.com>
2003-03-31 13:13               ` John Laban <johnl@infotn.com>
2003-09-21 15:43 JDBC with SSL Angel Todorov <atodorov@acm.org>
2003-09-22 04:06 ` Barry Lind <blind@xythos.com>
2011-12-04 16:40 JDBC with SSL Walter Hurry <walterhurry@lavabit.com>
2011-12-04 19:09 ` Florent Guillaume <fg@nuxeo.com>
2011-12-04 20:48   ` Walter Hurry <walterhurry@lavabit.com>
2011-12-05 00:28     ` Craig Ringer <ringerc@ringerc.id.au>
2011-12-05 18:46       ` Walter Hurry <walterhurry@lavabit.com>
2011-12-05 19:21         ` Magosányi Árpád <mag@magwas.rulez.org>
2011-12-06 00:45         ` Craig Ringer <ringerc@ringerc.id.au>
2011-12-06 19:43           ` Walter Hurry <walterhurry@lavabit.com>
2011-12-07 05:06             ` Craig Ringer <ringerc@ringerc.id.au>
2011-12-07 16:27               ` Bruno Harbulot <bruno@distributedmatter.net>
2011-12-07 16:34                 ` Bruno Harbulot <bruno@distributedmatter.net>
2011-12-07 18:00                 ` Walter Hurry <walterhurry@lavabit.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox