diff options
author | Barry Lind <barry@xythos.com> | 2003-02-27 05:45:44 +0000 |
---|---|---|
committer | Barry Lind <barry@xythos.com> | 2003-02-27 05:45:44 +0000 |
commit | 1cc55168d7867c4c4771c7d80361256abe22b8ea (patch) | |
tree | c8d558081423a7b149a58a59fda6ad191aefe2f3 /src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Connection.java | |
parent | 9ff872a27233d5e02e55e9572a4b8161e0186cba (diff) | |
download | postgresql-1cc55168d7867c4c4771c7d80361256abe22b8ea.tar.gz |
Added support for SSL in the jdbc driver
Modified Files:
jdbc/build.xml jdbc/org/postgresql/Driver.java.in
jdbc/org/postgresql/PG_Stream.java
jdbc/org/postgresql/errors.properties
jdbc/org/postgresql/jdbc1/AbstractJdbc1Connection.java
jdbc/org/postgresql/util/PSQLException.java
Diffstat (limited to 'src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Connection.java')
-rw-r--r-- | src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Connection.java | 69 |
1 files changed, 67 insertions, 2 deletions
diff --git a/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Connection.java b/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Connection.java index 7191f26a0e..328a5371eb 100644 --- a/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Connection.java +++ b/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Connection.java @@ -14,7 +14,7 @@ import org.postgresql.largeobject.LargeObjectManager; import org.postgresql.util.*; -/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Connection.java,v 1.15 2003/02/05 11:12:39 davec Exp $ +/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Connection.java,v 1.16 2003/02/27 05:45:44 barry Exp $ * This class defines methods of the jdbc1 specification. This class is * extended by org.postgresql.jdbc2.AbstractJdbc2Connection which adds the jdbc2 * methods. The real Connection class (for jdbc1) is org.postgresql.jdbc1.Jdbc1Connection @@ -34,6 +34,7 @@ public abstract class AbstractJdbc1Connection implements org.postgresql.PGConnec protected String PG_DATABASE; protected boolean PG_STATUS; protected String compatible; + protected boolean useSSL; // The PID an cancellation key we get from the backend process protected int pid; @@ -100,7 +101,7 @@ public abstract class AbstractJdbc1Connection implements org.postgresql.PGConnec * @exception SQLException if a database access error occurs */ public void openConnection(String host, int port, Properties info, String database, String url, org.postgresql.Driver d) throws SQLException - { + { firstWarning = null; // Throw an exception if the user or password properties are missing @@ -121,6 +122,15 @@ public abstract class AbstractJdbc1Connection implements org.postgresql.PGConnec PG_HOST = host; PG_STATUS = CONNECTION_BAD; + if (info.getProperty("ssl") != null && this_driver.sslEnabled()) + { + useSSL = true; + } + else + { + useSSL = false; + } + if (info.getProperty("compatible") == null) { compatible = d.getMajorVersion() + "." + d.getMinorVersion(); @@ -156,6 +166,11 @@ public abstract class AbstractJdbc1Connection implements org.postgresql.PGConnec //Print out the driver version number if (org.postgresql.Driver.logInfo) org.postgresql.Driver.info(org.postgresql.Driver.getVersion()); + if (org.postgresql.Driver.logDebug) { + org.postgresql.Driver.debug(" ssl = " + useSSL); + org.postgresql.Driver.debug(" compatible = " + compatible); + org.postgresql.Driver.debug(" loglevel = " + l_logLevel); + } // Now make the initial connection try @@ -174,6 +189,56 @@ public abstract class AbstractJdbc1Connection implements org.postgresql.PGConnec throw new PSQLException ("postgresql.con.failed", e); } + // Now we need to construct and send an ssl startup packet + try + { + if (useSSL) { + if (org.postgresql.Driver.logDebug) + org.postgresql.Driver.debug("Asking server if it supports ssl"); + pg_stream.SendInteger(8,4); + pg_stream.SendInteger(80877103,4); + + // now flush the ssl packets to the backend + pg_stream.flush(); + + // Now get the response from the backend, either an error message + // or an authentication request + int beresp = pg_stream.ReceiveChar(); + if (org.postgresql.Driver.logDebug) + org.postgresql.Driver.debug("Server response was (S=Yes,N=No): "+(char)beresp); + switch (beresp) + { + case 'E': + // An error occured, so pass the error message to the + // user. + // + // The most common one to be thrown here is: + // "User authentication failed" + // + throw new PSQLException("postgresql.con.misc", pg_stream.ReceiveString(encoding)); + + case 'N': + // Server does not support ssl + throw new PSQLException("postgresql.con.sslnotsupported"); + + case 'S': + // Server supports ssl + if (org.postgresql.Driver.logDebug) + org.postgresql.Driver.debug("server does support ssl"); + org.postgresql.Driver.makeSSL(pg_stream); + break; + + default: + throw new PSQLException("postgresql.con.sslfail"); + } + } + } + catch (IOException e) + { + throw new PSQLException("postgresql.con.failed", e); + } + + // Now we need to construct and send a startup packet try { |