@Test public void testKeyGenerationDefault() throws CryptoException { DhKeyGenerator keyGenServer = new DhKeyGenerator(); DhKeyGenerator keyGenClient = new DhKeyGenerator(); byte[] serverKey = keyGenServer.createPublicKey(true); byte[] clientKey = keyGenClient.createPublicKey(true); SymmetricCryptor serverCryptor = keyGenServer.getSymmetricCryptor(clientKey, false, TestDhKeyGenerator.class.getClassLoader(), true, true); SymmetricCryptor clientCryptor = keyGenClient.getSymmetricCryptor(serverKey, false, TestDhKeyGenerator.class.getClassLoader(), true, true); String cleartext = "cleartext!"; //$NON-NLS-1$ byte[] ciphertext = serverCryptor.encrypt(cleartext.getBytes(Charset.forName("UTF-8"))); byte[] cleartext2 = clientCryptor.decrypt(ciphertext); assertArrayEquals(cleartext.getBytes(Charset.forName("UTF-8")), cleartext2); assertTrue(!ciphertext.equals(cleartext)); Object sealed = serverCryptor.sealObject(cleartext); Object unsealed = clientCryptor.unsealObject(sealed); assertEquals(cleartext, unsealed); assertTrue(!sealed.equals(unsealed)); }
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); }
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(); } }
DhKeyGenerator keyGen = new DhKeyGenerator(); boolean large = false; if (serverPublicKeyLarge != null) { try { byte[] publicKey = keyGen.createPublicKey(true); handshake.setPublicKey(null); handshake.setPublicKeyLarge(publicKey); byte[] publicKey = keyGen.createPublicKey(false); handshake.setPublicKey(publicKey); handshake.setPublicKeyLarge(null); this.cryptor = keyGen.getSymmetricCryptor(serverPublicKey, "08.03".compareTo(serverVersion) > 0, this.getClass().getClassLoader(), large, useCbc); //$NON-NLS-1$ } else { this.cryptor = new NullCryptor();
DhKeyGenerator keyGen = new DhKeyGenerator(); boolean large = false; if (serverPublicKeyLarge != null) { try { byte[] publicKey = keyGen.createPublicKey(true); handshake.setPublicKey(null); handshake.setPublicKeyLarge(publicKey); byte[] publicKey = keyGen.createPublicKey(false); handshake.setPublicKey(publicKey); handshake.setPublicKeyLarge(null); this.cryptor = keyGen.getSymmetricCryptor(serverPublicKey, "08.03".compareTo(serverVersion) > 0, this.getClass().getClassLoader(), large, useCbc); //$NON-NLS-1$ } else { this.cryptor = new NullCryptor();