private Object decryptBlock(Command command) throws EncryptionError { try { synchronized (remoteSessionKey) { Bytes ciphertext = command.getParam(0); if (ciphertext == null) { throw new IllegalStateException("missing block data"); } Binder plain = Boss.unpack(remoteSessionKey.etaDecrypt(ciphertext.toArray())); inputQueue.put(plain); } } catch (SymmetricKey.AuthenticationFailed authenticationFailed) { throw new EncryptionError("authentication failed on bitrusted block"); } catch (InterruptedException e) { Thread.interrupted(); } catch (Exception e) { log.wtf("failed to process block", e); e.printStackTrace(); } return null; }
/** * We have received {@link PacketTypes#ACK} packet. Need to stop retransmitting of ack-ed packet. * @param packet received {@link Packet} */ private void onReceiveAck(Packet packet) throws EncryptionError, SymmetricKey.AuthenticationFailed { report(logLabel, ()->"received ack from " + packet.senderNodeId, VerboseLevel.DETAILED); Session session = getOrCreateSession(packet.senderNodeId); if (session != null) { if (session.state.get() == Session.STATE_EXCHANGING) { Integer ackPacketId = Boss.load(new SymmetricKey(session.sessionKey.getKey()).etaDecrypt(packet.payload)); session.removePacketFromRetransmitMap(ackPacketId); } } }
if (sessionReader.sessionKey != null) { try { byte[] decrypted = new SymmetricKey(sessionReader.sessionKey.getKey()).etaDecrypt(encryptedPayload); if (decrypted.length > 2) { byte[] payload = new byte[decrypted.length - 2];
@Test public void etaEncrypt() throws Exception { SymmetricKey k = new SymmetricKey(); byte[] plainText = "Hello, world!".getBytes(); byte[] cipherText = k.etaEncrypt(plainText); // Bytes.dump(cipherText); assertEquals(16 + 32 + plainText.length, cipherText.length); byte[] decryptedText = k.etaDecrypt(cipherText); assertArrayEquals(plainText, decryptedText); exception.expect(SymmetricKey.AuthenticationFailed.class); cipherText[19] += 1; k.etaDecrypt(cipherText); }
try { SymmetricKey sk = new SymmetricKey(k.decrypt(encryptedKey)); privateData = Boss.unpack(sk.etaDecrypt(encryptedData)); break outer; } catch (Exception e) {