pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ulrich Meis <kenobi@halifax.rwth-aachen.de>
To: Oliver Jowett <oliver@opencloud.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: A solution to the SSL customizing problem
Date: Sat, 16 Oct 2004 04:41:29 +0200
Message-ID: <200410160441.29561.kenobi@halifax.rwth-aachen.de> (raw)
In-Reply-To: <4170289B.6060108@opencloud.com>
References: <200410111752.33375.kenobi@halifax.rwth-aachen.de>
	<200410151621.49160.kenobi@halifax.rwth-aachen.de>
	<4170289B.6060108@opencloud.com>

On Friday 15 October 2004 21:44, Oliver Jowett wrote:
> Ulrich Meis wrote:
> > The attached changes provide as first parameter "hostname:port" to the
> > factory as given in the Properties object, so I removed the &urlServer&
> > thing.
>
> The host and port are already given to the SSLSocketFactory when the
>
> socket is created:
> >   @SSL@       java.net.Socket newConnection =
> > factory.createSocket(p_stream.getSocket(), p_stream.getHost(),
> > p_stream.getPort(), true);

Right! I forgot.

>
> Why do we need to also pass them separately to the factory's ctor?

We don't ;-)

I removed that.

See next try attached ;-)

Uli

Attachments:

pgjdbc-custom-ssl4.txt (text/plain, 6.7K) download Index: org/postgresql/Driver.java.in =================================================================== RCS file: /usr/local/cvsroot/pgjdbc/pgjdbc/org/postgresql/Driver.java.in,v retrieving revision 1.48 diff -c -r1.48 Driver.java.in *** org/postgresql/Driver.java.in 10 Oct 2004 15:39:30 -0000 1.48 --- org/postgresql/Driver.java.in 16 Oct 2004 02:34:04 -0000 *************** *** 189,194 **** --- 189,198 ---- "Force use of a particular protocol version when connecting; if set, disables protocol version fallback.", }, { "ssl", Boolean.FALSE, "Control use of SSL; any nonnull value causes SSL to be required." }, + { "sslfactory", Boolean.FALSE, + "Provide a SSLSocketFactory class when using SSL." }, + { "sslfactoryargs", Boolean.FALSE, + "Arguments forwarded to constructor of SSLSocketFactory class." }, { "logLevel", Boolean.FALSE, "Control the driver's log verbosity: 0 is off, 1 is INFO, 2 is DEBUG.", new String[] { "0", "1", "2" } }, *************** *** 524,533 **** } ! public static void makeSSL(org.postgresql.core.PGStream p_stream) throws IOException { @SSL@ if (logDebug) @SSL@ debug("converting regular socket connection to ssl"); ! @SSL@ javax.net.ssl.SSLSocketFactory factory = (javax.net.ssl.SSLSocketFactory) javax.net.ssl.SSLSocketFactory.getDefault(); @SSL@ java.net.Socket newConnection = factory.createSocket(p_stream.getSocket(), p_stream.getHost(), p_stream.getPort(), true); @SSL@ p_stream.changeSocket(newConnection); } --- 528,563 ---- } ! public static void makeSSL(org.postgresql.core.PGStream p_stream, Properties info) throws IOException,SQLException { @SSL@ if (logDebug) @SSL@ debug("converting regular socket connection to ssl"); ! @SSL@ javax.net.ssl.SSLSocketFactory factory; ! @SSL@ ! @SSL@ // If the url contains no class, use the default factory ! @SSL@ String classname = info.getProperty("sslfactory"); ! @SSL@ if (classname == null) ! @SSL@ factory = (javax.net.ssl.SSLSocketFactory) javax.net.ssl.SSLSocketFactory.getDefault(); ! @SSL@ else { ! @SSL@ ! @SSL@ // passed to the provided class if a fitting constructor is found ! @SSL@ Object[] args = {info.getProperty("sslfactoryargs")}; ! @SSL@ java.lang.reflect.Constructor ctor; ! @SSL@ Class factory_class; ! @SSL@ ! @SSL@ // get the (String,String) constructor and use () if that fails ! @SSL@ try { ! @SSL@ factory_class = Class.forName(classname); ! @SSL@ try { ! @SSL@ ctor = factory_class.getConstructor(new Class[]{String.class}); ! @SSL@ } catch (NoSuchMethodException e) { ! @SSL@ ctor = factory_class.getConstructor(null); ! @SSL@ args = null; ! @SSL@ } ! @SSL@ factory = (javax.net.ssl.SSLSocketFactory) ctor.newInstance(args); ! @SSL@ } catch (Exception e) { ! @SSL@ throw new PSQLException(GT.tr("The SSLSocketFactory class provided in the connection URL could not be instantiated"), PSQLState.CONNECTION_FAILURE, e); ! @SSL@ } ! @SSL@ } @SSL@ java.net.Socket newConnection = factory.createSocket(p_stream.getSocket(), p_stream.getHost(), p_stream.getPort(), true); @SSL@ p_stream.changeSocket(newConnection); } Index: org/postgresql/core/v2/ConnectionFactoryImpl.java =================================================================== RCS file: /usr/local/cvsroot/pgjdbc/pgjdbc/org/postgresql/core/v2/ConnectionFactoryImpl.java,v retrieving revision 1.3 diff -c -r1.3 ConnectionFactoryImpl.java *** org/postgresql/core/v2/ConnectionFactoryImpl.java 10 Oct 2004 15:39:35 -0000 1.3 --- org/postgresql/core/v2/ConnectionFactoryImpl.java 16 Oct 2004 02:34:04 -0000 *************** *** 68,74 **** // Construct and send an ssl startup packet if requested. if (trySSL) ! newStream = enableSSL(newStream, requireSSL); // Construct and send a startup packet. sendStartupPacket(newStream, user, database); --- 68,74 ---- // Construct and send an ssl startup packet if requested. if (trySSL) ! newStream = enableSSL(newStream, requireSSL, info); // Construct and send a startup packet. sendStartupPacket(newStream, user, database); *************** *** 107,113 **** } } ! private PGStream enableSSL(PGStream pgStream, boolean requireSSL) throws IOException, SQLException { if (Driver.logDebug) Driver.debug(" FE=> SSLRequest"); --- 107,113 ---- } } ! private PGStream enableSSL(PGStream pgStream, boolean requireSSL, Properties info) throws IOException, SQLException { if (Driver.logDebug) Driver.debug(" FE=> SSLRequest"); *************** *** 147,153 **** Driver.debug(" <=BE SSLOk"); // Server supports ssl ! Driver.makeSSL(pgStream); return pgStream; default: --- 147,153 ---- Driver.debug(" <=BE SSLOk"); // Server supports ssl ! Driver.makeSSL(pgStream,info); return pgStream; default: Index: org/postgresql/core/v3/ConnectionFactoryImpl.java =================================================================== RCS file: /usr/local/cvsroot/pgjdbc/pgjdbc/org/postgresql/core/v3/ConnectionFactoryImpl.java,v retrieving revision 1.3 diff -c -r1.3 ConnectionFactoryImpl.java *** org/postgresql/core/v3/ConnectionFactoryImpl.java 10 Oct 2004 15:39:37 -0000 1.3 --- org/postgresql/core/v3/ConnectionFactoryImpl.java 16 Oct 2004 02:34:04 -0000 *************** *** 78,84 **** // Construct and send an ssl startup packet if requested. if (trySSL) ! newStream = enableSSL(newStream, requireSSL); // Construct and send a startup packet. String[][] params = { --- 78,84 ---- // Construct and send an ssl startup packet if requested. if (trySSL) ! newStream = enableSSL(newStream, requireSSL, info); // Construct and send a startup packet. String[][] params = { *************** *** 126,132 **** } } ! private PGStream enableSSL(PGStream pgStream, boolean requireSSL) throws IOException, SQLException { if (Driver.logDebug) Driver.debug(" FE=> SSLRequest"); --- 126,132 ---- } } ! private PGStream enableSSL(PGStream pgStream, boolean requireSSL, Properties info) throws IOException, SQLException { if (Driver.logDebug) Driver.debug(" FE=> SSLRequest"); *************** *** 166,172 **** Driver.debug(" <=BE SSLOk"); // Server supports ssl ! Driver.makeSSL(pgStream); return pgStream; default: --- 166,172 ---- Driver.debug(" <=BE SSLOk"); // Server supports ssl ! Driver.makeSSL(pgStream,info); return pgStream; default:

view thread (31+ messages)  latest in thread

Message-ID: <200410160441.29561.kenobi@halifax.rwth-aachen.de>
Permalink:  ../200410160441.29561.kenobi@halifax.rwth-aachen.de/
Also on:    postgresql.org/message-id/200410160441.29561.kenobi@halifax.rwth-aachen.de

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: kenobi@halifax.rwth-aachen.de, oliver@opencloud.com
  Subject: Re: A solution to the SSL customizing problem
  In-Reply-To: <200410160441.29561.kenobi@halifax.rwth-aachen.de>
  References: <200410111752.33375.kenobi@halifax.rwth-aachen.de> <200410151621.49160.kenobi@halifax.rwth-aachen.de> <4170289B.6060108@opencloud.com> <200410160441.29561.kenobi@halifax.rwth-aachen.de>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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