Skip to content

Commit

Permalink
ssl build for jdbc3
Browse files Browse the repository at this point in the history
  • Loading branch information
Dave Cramer authored and Dave Cramer committed Dec 27, 2011
1 parent c01fbcc commit b125321
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 14 deletions.
18 changes: 15 additions & 3 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
This file now requires Ant 1.4.1. 2002-04-18
$PostgreSQL: pgjdbc/build.xml,v 1.90 2011/09/22 12:53:20 davecramer Exp $
$PostgreSQL: pgjdbc/build.xml,v 1.92 2011/12/14 18:49:19 davecramer Exp $
-->

Expand Down Expand Up @@ -170,7 +170,8 @@
<exclude name="${package}/jdcb4/Jdbc4*.java" unless="jdbc4any" />

<!-- ssl -->
<include name="${package}/ssl/*.java" />
<include name="${package}/ssl/jdbc4/*.java" if="jdbc4any"/>
<include name="${package}/ssl/jdbc3/*.java" if="jdbc3any"/>

<!-- gss -->
<include name="${package}/gss/*.java" />
Expand Down Expand Up @@ -280,7 +281,13 @@
<condition property="xadsclass" value="org.postgresql.xa.jdbc4.AbstractJdbc4XADataSource">
<equals arg1="${jdbc4any}" arg2="true" />
</condition>

<condition property="makesslclass" value="org.postgresql.ssl.jdbc3.AbstractJdbc3MakeSSL">
<equals arg1="${jdbc3any}" arg2="true" />
</condition>
<condition property="makesslclass" value="org.postgresql.ssl.jdbc4.AbstractJdbc4MakeSSL">
<equals arg1="${jdbc4any}" arg2="true" />
</condition>

<!-- Some defaults -->
<filter token="MAJORVERSION" value="${major}" />
<filter token="MINORVERSION" value="${minor}" />
Expand All @@ -293,6 +300,7 @@
<filter token="POOLED_CONN_CLASS" value="${pooledconnclass}" />
<filter token="CONN_POOL_DS_CLASS" value="${connpooldsclass}" />
<filter token="DEF_PGPORT" value="${def_pgport}" />
<filter token="MAKE_SSL_CLASS" value="${makesslclass}"/>

<fail unless="major" message="'major' undefined. Please follow the directions in README."/>
<fail unless="minor" message="'minor' undefined. Please follow the directions in README."/>
Expand Down Expand Up @@ -327,6 +335,10 @@
overwrite="true"
tofile="${package}/xa/PGXADataSource.java"
filtering="yes" />
<copy file="${package}/ssl/MakeSSL.java.in"
overwrite="true"
tofile="${package}/ssl/MakeSSL.java"
filtering="yes" />

<echo message="Configured build for the ${edition} edition driver." />
</target>
Expand Down
20 changes: 20 additions & 0 deletions org/postgresql/ssl/MakeSSL.java.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*-------------------------------------------------------------------------
*
* Copyright (c) 2004-2011, PostgreSQL Global Development Group
*
* IDENTIFICATION
* $PostgreSQL: pgjdbc/org/postgresql/ssl/MakeSSL.java,v 1.8 2011/08/02 13:50:28 davecramer Exp $
*
*-------------------------------------------------------------------------
*/
package org.postgresql.ssl;



public class MakeSSL extends @MAKE_SSL_CLASS@
{

}



4 changes: 2 additions & 2 deletions org/postgresql/ssl/NonValidatingFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Copyright (c) 2004-2011, PostgreSQL Global Development Group
*
* IDENTIFICATION
* $PostgreSQL: pgjdbc/org/postgresql/ssl/NonValidatingFactory.java,v 1.8 2008/01/08 06:56:30 jurka Exp $
* $PostgreSQL: pgjdbc/org/postgresql/ssl/NonValidatingFactory.java,v 1.9 2011/08/02 13:50:28 davecramer Exp $
*
*-------------------------------------------------------------------------
*/
Expand Down Expand Up @@ -39,7 +39,7 @@ public NonValidatingFactory(String arg) throws GeneralSecurityException {
_factory = ctx.getSocketFactory();
}

static class NonValidatingTM implements X509TrustManager {
public static class NonValidatingTM implements X509TrustManager {

public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
Expand Down
69 changes: 69 additions & 0 deletions org/postgresql/ssl/jdbc3/AbstractJdbc3MakeSSL.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*-------------------------------------------------------------------------
*
* Copyright (c) 2004-2011, PostgreSQL Global Development Group
*
* IDENTIFICATION
* $PostgreSQL: pgjdbc/org/postgresql/ssl/MakeSSL.java,v 1.8 2011/08/02 13:50:28 davecramer Exp $
*
*-------------------------------------------------------------------------
*/
package org.postgresql.ssl.jdbc3;

import java.util.Properties;
import java.io.IOException;
import java.net.Socket;
import java.lang.reflect.Constructor;
import javax.net.ssl.SSLSocketFactory;

import org.postgresql.core.PGStream;
import org.postgresql.core.Logger;
import org.postgresql.util.GT;
import org.postgresql.util.PSQLState;
import org.postgresql.util.PSQLException;

public class AbstractJdbc3MakeSSL {
public static void convert(PGStream stream, Properties info, Logger logger) throws IOException, PSQLException {
logger.debug("converting regular socket connection to ssl");

SSLSocketFactory factory;

// Use the default factory if no specific factory is requested
//
String classname = info.getProperty("sslfactory");
if (classname == null)
{
factory = (SSLSocketFactory)SSLSocketFactory.getDefault();
}
else
{
Object[] args = {info.getProperty("sslfactoryarg")};
Constructor ctor;
Class factoryClass;

try
{
factoryClass = Class.forName(classname);
try
{
ctor = factoryClass.getConstructor(new Class[]{String.class});
}
catch (NoSuchMethodException nsme)
{
ctor = factoryClass.getConstructor((Class[])null);
args = null;
}
factory = (SSLSocketFactory)ctor.newInstance(args);
}
catch (Exception e)
{
throw new PSQLException(GT.tr("The SSLSocketFactory class provided {0} could not be instantiated.", classname), PSQLState.CONNECTION_FAILURE, e);
}
}

Socket newConnection = factory.createSocket(stream.getSocket(), stream.getHost(), stream.getPort(), true);
stream.changeSocket(newConnection);
}

}


Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
* Copyright (c) 2004-2011, PostgreSQL Global Development Group
*
* IDENTIFICATION
* $PostgreSQL: pgjdbc/org/postgresql/ssl/MakeSSL.java,v 1.8 2011/08/02 13:50:28 davecramer Exp $
* $PostgreSQL: pgjdbc/org/postgresql/ssl/MakeSSL.java,v 1.9 2011/11/17 11:27:51 davecramer Exp $
*
*-------------------------------------------------------------------------
*/
package org.postgresql.ssl;
package org.postgresql.ssl.jdbc4;

import java.io.IOException;
import java.lang.reflect.Constructor;
Expand All @@ -25,7 +25,7 @@
import org.postgresql.util.PSQLException;
import org.postgresql.util.PSQLState;

public class MakeSSL {
public class AbstractJdbc4MakeSSL {

/**
* Instantiates a class using the appropriate constructor.
Expand Down Expand Up @@ -92,7 +92,7 @@ public static void convert(PGStream stream, Properties info, Logger logger) thro
String classname = info.getProperty("sslfactory");
if (classname == null)
{
//If sslmode is set, use the libpg compatible factory
//If sslmode is set, use the libp compatible factory
if (sslmode!=null)
{
factory = new LibPQFactory(info);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.postgresql.ssl;
package org.postgresql.ssl.jdbc4;

import java.io.File;
import java.io.FileInputStream;
Expand Down Expand Up @@ -50,8 +50,8 @@ public class LazyKeyManager implements X509KeyManager {
private PSQLException error = null;

/**
* Costructor. certfile and keyfile can be null, in that case no
* certificat is presented to the server.
* Constructor. certfile and keyfile can be null, in that case no
* certificate is presented to the server.
* @param certfile
* @param keyfile
* @param cbh
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.postgresql.ssl;
package org.postgresql.ssl.jdbc4;

import java.io.Console;
import java.io.FileInputStream;
Expand Down Expand Up @@ -32,6 +32,7 @@
import javax.security.auth.x500.X500Principal;

import org.postgresql.ssl.NonValidatingFactory.NonValidatingTM;
import org.postgresql.ssl.WrappedFactory;
import org.postgresql.util.GT;
import org.postgresql.util.PSQLException;
import org.postgresql.util.PSQLState;
Expand Down Expand Up @@ -91,7 +92,7 @@ public LibPQFactory(Properties info) throws PSQLException {
{
try
{
cbh = (CallbackHandler)MakeSSL.instantiate(sslpasswordcallback, info, false, null);
cbh = (CallbackHandler)AbstractJdbc4MakeSSL.instantiate(sslpasswordcallback, info, false, null);
}
catch (Exception e)
{
Expand Down

0 comments on commit b125321

Please sign in to comment.