? org/postgresql/util/PSQLException.java Index: README =================================================================== RCS file: /usr/local/cvsroot/pgjdbc/pgjdbc/README,v retrieving revision 1.14 diff -c -r1.14 README *** README 13 Jan 2004 02:49:34 -0000 1.14 --- README 18 Feb 2004 16:58:35 -0000 *************** *** 124,129 **** --- 124,175 ---- --------------------------------------------------------------------------- + SSL connections + + You can connect to a PostgreSQL backend using SSL for encryption of the + communication link. There are three requirements to do so: + + 1) The PostgreSQL backend must be built with SSL enabled. + + 2) The JDBC driver must have been built with SSL enabled. + + 3) You must specify the 'ssl=true' on the connection URL (or include + that in the java.util.Properties object used when opening the + connection. For example, your connection URL may be: + + jdbc:postgresql:database?user=me&ssl=true + + NOTE: If the driver is not built with SSL support, it will silently + ignore a request to communicate via SSL. If encryption is important in + your environment, please be sure that your JDBC driver was built with + SSL enabled. + + ------------------ + + For most users, the configuration above will be sufficient. However, SSL + offers a number of trust-related options that may need to modified in rare + circumstances. These options are used, for example, to modify the + verification requirements for clients or servers. You can modify these + options for a PostgreSQL JDBC connection by specifying a custom instance + of SSLSocketFactory to be used for establishing an SSL connection to the + PostgreSQL backend. To do so, use the following code: + + SSLSocketFactory factory; // Create/customize your SSLSocketFactory + org.postgresql.Driver.setSSLSocketFactory(factory); + + Connections established after that line of code will use your custom factory + to establish SSL connections. To revert to the default behavior for + additional connections, use the following code: + + org.postgresql.Driver.setSSLSocketFactory(null); + + The details of obtaining and customizing SSLSocketFactory instances are + beyond the scope of this JDBC driver. You are referred to the Java API + documentation for the package javax.net.ssl. Please be aware, since some + modifications made to SSL can negate many of its security benefits. + + --------------------------------------------------------------------------- + That's the basics related to this driver. You'll need to read the JDBC Docs on how to use it. However, there are some examples included in the example directory. To build, type: make examples Index: org/postgresql/Driver.java.in =================================================================== RCS file: /usr/local/cvsroot/pgjdbc/pgjdbc/org/postgresql/Driver.java.in,v retrieving revision 1.40 diff -c -r1.40 Driver.java.in *** org/postgresql/Driver.java.in 11 Dec 2003 18:10:40 -0000 1.40 --- org/postgresql/Driver.java.in 18 Feb 2004 16:58:35 -0000 *************** *** 480,490 **** } } 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@ p_stream.connection = (javax.net.ssl.SSLSocket) factory.createSocket(p_stream.connection,p_stream.host,p_stream.port,true); @SSL@ p_stream.pg_input = new BufferedInputStream(p_stream.connection.getInputStream(), 8192); @SSL@ p_stream.pg_output = new BufferedOutputStream(p_stream.connection.getOutputStream(), 8192); --- 480,498 ---- } } + @SSL@ private static javax.net.ssl.SSLSocketFactory sslFactory; + @SSL@ + @SSL@ public static void setSSLSocketFactory(javax.net.ssl.SSLSocketFactory f) + @SSL@ { + @SSL@ sslFactory = f; + @SSL@ } 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; ! @SSL@ if (sslFactory != null) factory = sslFactory; ! @SSL@ else factory = (javax.net.ssl.SSLSocketFactory) javax.net.ssl.SSLSocketFactory.getDefault(); @SSL@ p_stream.connection = (javax.net.ssl.SSLSocket) factory.createSocket(p_stream.connection,p_stream.host,p_stream.port,true); @SSL@ p_stream.pg_input = new BufferedInputStream(p_stream.connection.getInputStream(), 8192); @SSL@ p_stream.pg_output = new BufferedOutputStream(p_stream.connection.getOutputStream(), 8192);