use of org.teiid.core.crypto.NullCryptor in project teiid by teiid.
the class TestCommSockets method testConnectWithoutClientEncryption.
@Test
public void testConnectWithoutClientEncryption() throws Exception {
SSLConfiguration config = new SSLConfiguration();
config.setMode(SSLConfiguration.DISABLED);
SocketServerConnection conn = helpEstablishConnection(false, config, new Properties());
assertTrue(conn.selectServerInstance(false).getCryptor() instanceof NullCryptor);
conn.close();
}
use of org.teiid.core.crypto.NullCryptor in project teiid by teiid.
the class TestSocketServerConnection method createConnection.
private SocketServerConnection createConnection(final Throwable t, final HostInfo hostInfo, Properties p) throws CommunicationException, ConnectionException {
ServerDiscovery discovery = new UrlServerDiscovery(new TeiidURL(hostInfo.getHostName(), hostInfo.getPortNumber(), false));
SocketServerInstanceFactory instanceFactory = new SocketServerInstanceFactory() {
FakeILogon logon = new FakeILogon(t);
@Override
public SocketServerInstance getServerInstance(HostInfo info) throws CommunicationException, IOException {
SocketServerInstance instance = Mockito.mock(SocketServerInstance.class);
Mockito.stub(instance.getCryptor()).toReturn(new NullCryptor());
Mockito.stub(instance.getHostInfo()).toReturn(hostInfo);
Mockito.stub(instance.getService(ILogon.class)).toReturn(logon);
Mockito.stub(instance.getServerVersion()).toReturn("07.03");
if (t != null) {
try {
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
if (logon.t == null) {
return null;
}
throw logon.t;
}
}).when(instance).send((Message) Mockito.anyObject(), (ResultsReceiver<Object>) Mockito.anyObject(), (Serializable) Mockito.anyObject());
} catch (Exception e) {
}
}
Mockito.stub(instance.isOpen()).toReturn(true);
return instance;
}
@Override
public void connected(SocketServerInstance instance, SessionToken session) {
}
@Override
public void disconnected(SocketServerInstance instance, SessionToken session) {
}
};
SocketServerConnection connection = new SocketServerConnection(instanceFactory, false, discovery, p);
return connection;
}
use of org.teiid.core.crypto.NullCryptor in project teiid by teiid.
the class SocketServerInstanceImpl method doHandshake.
private void doHandshake() throws IOException, CommunicationException {
Handshake handshake = null;
boolean sentInit = false;
long handShakeRetries = 1;
if (this.soTimeout > 0) {
handShakeRetries = Math.max(1, synchTimeout / this.soTimeout);
}
for (int i = 0; i < handShakeRetries; i++) {
try {
Object obj = this.socketChannel.read();
if (!(obj instanceof Handshake)) {
throw new SingleInstanceCommunicationException(JDBCPlugin.Event.TEIID20009, null, JDBCPlugin.Util.gs(JDBCPlugin.Event.TEIID20009));
}
handshake = (Handshake) obj;
break;
} catch (ClassNotFoundException e1) {
throw new SingleInstanceCommunicationException(JDBCPlugin.Event.TEIID20010, e1, e1.getMessage());
} catch (SocketTimeoutException e) {
if (!sentInit && !this.info.isSsl()) {
// write a dummy initialization value - if the server is actually ssl, this can cause the server side handshake to fail, otherwise it's ignored
// TODO: could always do this initialization in the non-ssl case and not wait for a timeout
this.socketChannel.write(null);
sentInit = true;
}
if (i == handShakeRetries - 1) {
throw e;
}
} catch (IOException e) {
if (sentInit && !this.info.isSsl()) {
throw new SingleInstanceCommunicationException(JDBCPlugin.Event.TEIID20032, e, JDBCPlugin.Util.gs(JDBCPlugin.Event.TEIID20032));
}
throw e;
}
}
try {
/*if (!getVersionInfo().equals(handshake.getVersion())) {
throw new CommunicationException(JDBCPlugin.Event.TEIID20011, NetPlugin.Util.getString(JDBCPlugin.Event.TEIID20011, getVersionInfo(), handshake.getVersion()));
}*/
serverVersion = handshake.getVersion();
handshake.setVersion();
byte[] serverPublicKey = handshake.getPublicKey();
byte[] serverPublicKeyLarge = handshake.getPublicKeyLarge();
if (serverPublicKey != null) {
DhKeyGenerator keyGen = new DhKeyGenerator();
boolean large = false;
if (serverPublicKeyLarge != null) {
try {
byte[] publicKey = keyGen.createPublicKey(true);
handshake.setPublicKey(null);
handshake.setPublicKeyLarge(publicKey);
serverPublicKey = serverPublicKeyLarge;
large = true;
} catch (CryptoException e) {
// not supported on this platform
}
}
if (!large) {
byte[] publicKey = keyGen.createPublicKey(false);
handshake.setPublicKey(publicKey);
handshake.setPublicKeyLarge(null);
}
boolean useCbc = handshake.isCbc();
// $NON-NLS-1$
this.cryptor = keyGen.getSymmetricCryptor(serverPublicKey, "08.03".compareTo(serverVersion) > 0, this.getClass().getClassLoader(), large, useCbc);
} else {
this.cryptor = new NullCryptor();
}
this.socketChannel.write(handshake);
} catch (CryptoException e) {
throw new CommunicationException(JDBCPlugin.Event.TEIID20012, e, e.getMessage());
}
}
use of org.teiid.core.crypto.NullCryptor in project teiid by teiid.
the class SocketClientInstance method receivedHahdshake.
private void receivedHahdshake(Handshake handshake) throws CommunicationException {
String clientVersion = handshake.getVersion();
this.workContext.setClientVersion(Version.getVersion(clientVersion));
if (usingEncryption) {
byte[] returnedPublicKey = handshake.getPublicKey();
byte[] returnedPublicKeyLarge = handshake.getPublicKeyLarge();
boolean large = false;
// ensure the key information
if (returnedPublicKey == null) {
if (returnedPublicKeyLarge == null) {
throw new CommunicationException(RuntimePlugin.Event.TEIID40052, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40052));
}
large = true;
returnedPublicKey = returnedPublicKeyLarge;
}
if (LogManager.isMessageToBeRecorded(LogConstants.CTX_TRANSPORT, MessageLevel.DETAIL)) {
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
LogManager.logDetail(LogConstants.CTX_TRANSPORT, large ? "2048" : "1024", "key exchange being used.");
}
boolean useCbc = handshake.isCbc();
try {
// $NON-NLS-1$
this.cryptor = keyGen.getSymmetricCryptor(returnedPublicKey, "08.03".compareTo(clientVersion) > 0, SocketClientInstance.class.getClassLoader(), large, useCbc);
} catch (CryptoException e) {
throw new CommunicationException(RuntimePlugin.Event.TEIID40053, e);
}
this.keyGen = null;
} else {
this.cryptor = new NullCryptor();
}
}
Aggregations