Skip to content

Commit

Permalink
switching to nonvalidating rather than anon
Browse files Browse the repository at this point in the history
  • Loading branch information
shawkins committed Feb 27, 2016
1 parent 37a6b44 commit 45e4ed9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 79 deletions.
Expand Up @@ -33,7 +33,6 @@
import org.junit.Test;
import org.postgresql.Driver;
import org.teiid.jdbc.TestMMDatabaseMetaData;
import org.teiid.transport.TestODBCSocketTransport.AnonSSLSocketFactory;
import org.teiid.transport.TestODBCSocketTransport.FakeOdbcServer;
import org.teiid.transport.TestODBCSocketTransport.Mode;

Expand All @@ -53,7 +52,7 @@ public class TestODBCSSL {
p.setProperty("user", "testuser");
p.setProperty("password", "testpassword");
p.setProperty("ssl", "true");
p.setProperty("sslfactory", AnonSSLSocketFactory.class.getName());
p.setProperty("sslfactory", "org.postgresql.ssl.NonValidatingFactory");
Connection conn = d.connect("jdbc:postgresql://"+odbcServer.addr.getHostName()+":" +odbcServer.odbcTransport.getPort()+"/parts", p);
Statement s = conn.createStatement();
assertTrue(s.execute("select * from tables order by name"));
Expand Down Expand Up @@ -84,7 +83,7 @@ public class TestODBCSSL {
p.setProperty("user", "testuser");
p.setProperty("password", "testpassword");
p.setProperty("ssl", "true");
p.setProperty("sslfactory", AnonSSLSocketFactory.class.getName());
p.setProperty("sslfactory", "org.postgresql.ssl.NonValidatingFactory");
d.connect("jdbc:postgresql://"+odbcServer.addr.getHostName()+":" +odbcServer.odbcTransport.getPort()+"/parts", p);
}

Expand Down
Expand Up @@ -24,13 +24,8 @@

import static org.junit.Assert.*;

import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import java.nio.charset.Charset;
import java.security.NoSuchAlgorithmException;
import java.sql.Array;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
Expand All @@ -40,10 +35,6 @@
import java.sql.Statement;
import java.util.Properties;

import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
Expand All @@ -60,78 +51,13 @@
import org.teiid.core.util.UnitTestUtil;
import org.teiid.jdbc.FakeServer;
import org.teiid.jdbc.TestMMDatabaseMetaData;
import org.teiid.net.socket.SocketUtil;
import org.teiid.runtime.EmbeddedConfiguration;
import org.teiid.runtime.TestEmbeddedServer;
import org.teiid.runtime.TestEmbeddedServer.MockTransactionManager;

@SuppressWarnings("nls")
public class TestODBCSocketTransport {

public static class AnonSSLSocketFactory extends SSLSocketFactory {

private SSLSocketFactory sslSocketFactory;

public AnonSSLSocketFactory() {
try {
sslSocketFactory = SSLContext.getDefault().getSocketFactory();
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException();
}
}

@Override
public Socket createSocket() throws IOException {
return sslSocketFactory.createSocket();
}

@Override
public Socket createSocket(InetAddress address, int port,
InetAddress localAddress, int localPort) throws IOException {
return sslSocketFactory.createSocket(address, port, localAddress,
localPort);
}

@Override
public Socket createSocket(InetAddress host, int port)
throws IOException {
return sslSocketFactory.createSocket(host, port);
}

@Override
public Socket createSocket(Socket s, String host, int port,
boolean autoClose) throws IOException {
SSLSocket socket = (SSLSocket)sslSocketFactory.createSocket(s, host, port, autoClose);
SocketUtil.addCipherSuite(socket, SocketUtil.ANON_CIPHER_SUITE);
return socket;
}

@Override
public Socket createSocket(String host, int port,
InetAddress localHost, int localPort) throws IOException,
UnknownHostException {
return sslSocketFactory.createSocket(host, port, localHost,
localPort);
}

@Override
public Socket createSocket(String host, int port) throws IOException,
UnknownHostException {
return sslSocketFactory.createSocket(host, port);
}

@Override
public String[] getDefaultCipherSuites() {
return sslSocketFactory.getDefaultCipherSuites();
}

@Override
public String[] getSupportedCipherSuites() {
return sslSocketFactory.getSupportedCipherSuites();
}

}

private static final MockTransactionManager TRANSACTION_MANAGER = new TestEmbeddedServer.MockTransactionManager();

enum Mode {
Expand All @@ -153,7 +79,9 @@ public void start(Mode mode) throws Exception {
sslConfig.setMode(SSLConfiguration.LOGIN);
} else if (mode == Mode.ENABLED || mode == Mode.LEGACY) {
sslConfig.setMode(SSLConfiguration.ENABLED);
sslConfig.setAuthenticationMode(SSLConfiguration.ANONYMOUS);
sslConfig.setAuthenticationMode(SSLConfiguration.ONEWAY);
sslConfig.setKeystoreFilename(UnitTestUtil.getTestDataFile("keystore.jks").getAbsolutePath());
sslConfig.setKeystorePassword("password");
} else {
sslConfig.setMode(SSLConfiguration.DISABLED);
}
Expand Down Expand Up @@ -465,7 +393,7 @@ private void connect(String database) throws SQLException {
p.setProperty("user", "testuser");
p.setProperty("password", "testpassword");
p.setProperty("ssl", "true");
p.setProperty("sslfactory", AnonSSLSocketFactory.class.getName());
p.setProperty("sslfactory", "org.postgresql.ssl.NonValidatingFactory");
conn = d.connect("jdbc:postgresql://"+odbcServer.addr.getHostName()+":" +odbcServer.odbcTransport.getPort()+"/parts", p);
Statement s = conn.createStatement();
assertTrue(s.execute("select * from tables order by name"));
Expand Down

0 comments on commit 45e4ed9

Please sign in to comment.