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)) { LogManager.logDetail(LogConstants.CTX_TRANSPORT, large?"2048":"1024", "key exchange being used."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } boolean useCbc = handshake.isCbc(); try { this.cryptor = keyGen.getSymmetricCryptor(returnedPublicKey, "08.03".compareTo(clientVersion) > 0, SocketClientInstance.class.getClassLoader(), large, useCbc); //$NON-NLS-1$ } catch (CryptoException e) { throw new CommunicationException(RuntimePlugin.Event.TEIID40053, e); } this.keyGen = null; } else { this.cryptor = new NullCryptor(); } }
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); }
@Test public void testVersionNormalization() throws Exception { Handshake hs = new Handshake("11.2.3.a"); assertEquals("11.02.03.a", hs.getVersion()); }
serverVersion = handshake.getVersion(); handshake.setVersion(); byte[] serverPublicKey = handshake.getPublicKey(); byte[] serverPublicKeyLarge = handshake.getPublicKeyLarge(); try { byte[] publicKey = keyGen.createPublicKey(true); handshake.setPublicKey(null); handshake.setPublicKeyLarge(publicKey); serverPublicKey = serverPublicKeyLarge; large = true; handshake.setPublicKey(publicKey); handshake.setPublicKeyLarge(null); boolean useCbc = handshake.isCbc(); this.cryptor = keyGen.getSymmetricCryptor(serverPublicKey, "08.03".compareTo(serverVersion) > 0, this.getClass().getClassLoader(), large, useCbc); //$NON-NLS-1$ } else {
@Test public void testSuccessfulHandshake() throws Exception { final FakeObjectChannel channel = new FakeObjectChannel(Arrays.asList(new Handshake(), new SocketTimeoutException())); SocketServerInstanceImpl instance = createInstance(channel); //no remote server is hooked up, so this will timeout ILogon logon = instance.getService(ILogon.class); try { logon.logon(new Properties()); fail("Exception expected"); //$NON-NLS-1$ } catch (SingleInstanceCommunicationException e) { assertTrue(e.getCause() instanceof TimeoutException); } }
@Test public void testCompatibility() throws Exception { ObjectInputStream ois = new ObjectInputStream(new FileInputStream(UnitTestUtil.getTestDataFile("handshake.ser"))); Handshake hs = (Handshake)ois.readObject(); assertEquals(AuthenticationType.USERPASSWORD, hs.getAuthType()); }
serverVersion = handshake.getVersion(); handshake.setVersion(); byte[] serverPublicKey = handshake.getPublicKey(); byte[] serverPublicKeyLarge = handshake.getPublicKeyLarge(); try { byte[] publicKey = keyGen.createPublicKey(true); handshake.setPublicKey(null); handshake.setPublicKeyLarge(publicKey); serverPublicKey = serverPublicKeyLarge; large = true; handshake.setPublicKey(publicKey); handshake.setPublicKeyLarge(null); boolean useCbc = handshake.isCbc(); this.cryptor = keyGen.getSymmetricCryptor(serverPublicKey, "08.03".compareTo(serverVersion) > 0, this.getClass().getClassLoader(), large, useCbc); //$NON-NLS-1$ } else {