public void visit(GetSessionKeyMessage message) { LOGGER.debug("Process GetSessionKeyMessage: " + message); peerAddress_ = message.getPeerAddress(); localSourceJobId_ = message.getSourceJobId(); sessionId_ = message.getSessionId(); InitSessionObject initSessionObject = null; initSessionContext_.acquireReadLock(); try { initSessionObject = initSessionContext_.tryGetInitSessionObject(sessionId_); if (initSessionObject.getSessionKey() == null) { throw new SessionRuntimeException("SessionKey null"); } } catch (SessionRuntimeException e) { endWithError(e, ErrorNotificationMethod.LOCAL); return; } finally { initSessionContext_.releaseReadLock(); } outQueue_.add( new GetSessionKeyResponseMessage( localSourceJobId_, message.getPeerAddress(), initSessionObject.getSessionKey(), sessionId_)); endWithSuccessAndClear(); }
public void visit(InitSessionResponseMessage message) { LOGGER.debug("Process InitSessionResponseMessage: " + message); remoteSourceJobId_ = message.getSourceJobId(); InitSessionObject initSessionObject = null; initSessionContext_.acquireReadLock(); try { initSessionObject = initSessionContext_.tryGetInitSessionObject(sessionId_); } catch (SessionRuntimeException e) { endWithErrorAndClear(e, ErrorNotificationMethod.ALL); return; } finally { initSessionContext_.releaseReadLock(); } try { DiffieHellmanResponsePackage diffieHellmanResponsePackage = (DiffieHellmanResponsePackage) encryptionAPI_.decrypt(message.getEncryptedData(), privateKeyPeerId_); KeyAgreement keyAgreement = DiffieHellmanProtocol.thirdStepDHKeyAgreement( initSessionObject.getKeyAgreement(), diffieHellmanResponsePackage); initSessionObject.setSessionKey( DiffieHellmanProtocol.fourthStepDHKeyAgreement(keyAgreement)); InitSessionEndMessage initSessionEndMessage = new InitSessionEndMessage(initSessionObject, getJobId()); outQueue_.add(initSessionEndMessage); if (peerAddress_.equals(myAddress_)) { endWithSuccess(); } else { endWithSuccessAndClear(); } } catch (CryptoException e) { endWithErrorAndClear(e, ErrorNotificationMethod.ALL); } }