@Test public void testEncryptTLS12AEAD() throws NoSuchAlgorithmException, CryptoException { context.setSelectedProtocolVersion(ProtocolVersion.TLS12); context.setSelectedCipherSuite(CipherSuite.TLS_RSA_WITH_AES_128_GCM_SHA256); context.setMasterSecret(ArrayConverter .hexStringToByteArray("A12C1685B91E4EF31955842FACD5CC9D62F1663DBDC6EE9659A7D724FDDA76FCB5B6033302AAC0AD0D9C3B27C7DCC0D5")); context.setClientRandom(ArrayConverter .hexStringToByteArray("167D244D60B420BB3851D9D47ACB933DBE70399BF6C92DA33AF01D4FB770E98C")); context.setServerRandom(ArrayConverter .hexStringToByteArray("41C2F030D70B2944BE2B1905BB8488C873E056B030413788D5D1ECADC17C3C39")); record.setCleanProtocolMessageBytes(ArrayConverter.hexStringToByteArray("1400000C0C821172BB87E255D5C6E078")); record.setContentMessageType(ProtocolMessageType.HANDSHAKE); record.setProtocolVersion(ProtocolVersion.TLS12.getValue()); recordCipher = new RecordAEADCipher(context, KeySetGenerator.generateKeySet(context)); encryptor = new RecordEncryptor(recordCipher, context); encryptor.encrypt(record); assertArrayEquals(ArrayConverter.hexStringToByteArray("00000000000000001603030010"), record.getComputations() .getAuthenticatedMetaData().getValue()); assertNull(record.getComputations().getMac()); assertArrayEquals(ArrayConverter.hexStringToByteArray("FA78825C25329563CD9FEDFBE49AF948"), record .getComputations().getAuthenticatedNonMetaData().getValue()); assertNull(record.getComputations().getPadding()); assertArrayEquals(ArrayConverter.hexStringToByteArray("1400000C0C821172BB87E255D5C6E078"), record .getComputations().getPlainRecordBytes().getValue()); assertNull(record.getComputations().getCbcInitialisationVector()); assertNull(record.getComputations().getAdditionalPaddingLength()); assertArrayEquals( record.getProtocolMessageBytes().getValue(), ArrayConverter .hexStringToByteArray("0000000000000000FA78825C25329563CD9FEDFBE49AF948797D1023DA64D914704CDFBE26DD2A47")); }
@Override public void encrypt(BlobRecord record) { LOGGER.debug("Encrypting BlobRecord"); RecordCipher recordCipher = getRecordMostRecentCipher(); try { recordCipher.encrypt(record); } catch (CryptoException ex) { LOGGER.warn("Could not encrypt BlobRecord. Using NullCipher", ex); try { nullCipher.encrypt(record); } catch (CryptoException ex1) { LOGGER.error("Could not encrypt with NullCipher", ex1); } } context.increaseWriteSequenceNumber(); }
RecordEncryptor extends Encryptor { @Override public void encrypt(BlobRecord record) { LOGGER.debug("Encrypting BlobRecord"); RecordCipher recordCipher = getRecordMostRecentCipher(); try { recordCipher.encrypt(record); } catch (CryptoException ex) { LOGGER.warn("Could not encrypt BlobRecord. Using NullCipher", ex); try { nullCipher.encrypt(record); } catch (CryptoException ex1) { LOGGER.error("Could not encrypt with NullCipher", ex1); } } context.increaseWriteSequenceNumber(); } }
RecordEncryptor extends Encryptor { @Override public void encrypt(BlobRecord record) { LOGGER.debug("Encrypting BlobRecord"); RecordCipher recordCipher = getRecordMostRecentCipher(); try { recordCipher.encrypt(record); } catch (CryptoException ex) { LOGGER.warn("Could not encrypt BlobRecord. Using NullCipher", ex); try { nullCipher.encrypt(record); } catch (CryptoException ex1) { LOGGER.error("Could not encrypt with NullCipher", ex1); } } context.increaseWriteSequenceNumber(); } RecordEncryptor(RecordCipher recordCipher, TlsContext context); }
RecordEncryptor extends Encryptor { @Override public void encrypt(BlobRecord record) { LOGGER.debug("Encrypting BlobRecord"); RecordCipher recordCipher = getRecordMostRecentCipher(); try { recordCipher.encrypt(record); } catch (CryptoException ex) { LOGGER.warn("Could not encrypt BlobRecord. Using NullCipher", ex); try { nullCipher.encrypt(record); } catch (CryptoException ex1) { LOGGER.error("Could not encrypt with NullCipher", ex1); } } context.increaseWriteSequenceNumber(); } RecordEncryptor(RecordCipher recordCipher, TlsContext context); @Override void encrypt(BlobRecord record); @Override void encrypt(Record record); }
RecordEncryptor extends Encryptor { @Override public void encrypt(BlobRecord record) { LOGGER.debug("Encrypting BlobRecord"); RecordCipher recordCipher = getRecordMostRecentCipher(); try { recordCipher.encrypt(record); } catch (CryptoException ex) { LOGGER.warn("Could not encrypt BlobRecord. Using NullCipher", ex); try { nullCipher.encrypt(record); } catch (CryptoException ex1) { LOGGER.error("Could not encrypt with NullCipher", ex1); } } context.increaseWriteSequenceNumber(); } RecordEncryptor(RecordCipher recordCipher, TlsContext context); @Override void encrypt(BlobRecord record); @Override void encrypt(Record record);  }