use of org.teiid.core.crypto.CryptoException 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.CryptoException 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();
}
}
use of org.teiid.core.crypto.CryptoException in project teiid by teiid.
the class SocketClientInstance method onConnection.
public void onConnection() throws CommunicationException {
Handshake handshake = new Handshake();
handshake.setAuthType(csr.getAuthenticationType());
if (usingEncryption) {
keyGen = new DhKeyGenerator();
byte[] publicKey;
try {
handshake.setPublicKeyLarge(keyGen.createPublicKey(true));
} catch (CryptoException e) {
// not supported on this platform
}
try {
publicKey = keyGen.createPublicKey(false);
} catch (CryptoException e) {
throw new CommunicationException(RuntimePlugin.Event.TEIID40051, e);
}
handshake.setPublicKey(publicKey);
}
this.objectSocket.write(handshake);
}
Aggregations