@Test public void testEncryptTls10Client() throws NoSuchAlgorithmException, CryptoException { context.setConnection(new OutboundConnection()); context.setSelectedCipherSuite(CipherSuite.TLS_RSA_WITH_3DES_EDE_CBC_SHA); context.setSelectedProtocolVersion(ProtocolVersion.TLS10); byte[] data = ArrayConverter .hexStringToByteArray("1400000CCE92FBEC9131F48A63FED31F71573F726479AA9108FB86A4FA16BC1D5CB5753003030303"); KeySet keySet = new KeySet(); keySet.setClientWriteKey(ArrayConverter .hexStringToByteArray("65B7DA726864D4184D75A549BF5C06AB20867846AF4434CC")); keySet.setClientWriteMacSecret(ArrayConverter.hexStringToByteArray("183612323C5507EDAA5BF0DE71272A2EA87B1165")); keySet.setClientWriteIv(ArrayConverter.hexStringToByteArray("1ACF314DA7208EB8")); keySet.setServerWriteIv(new byte[8]); keySet.setServerWriteKey(new byte[24]); keySet.setServerWriteMacSecret(new byte[20]); cipher = new RecordBlockCipher(context, keySet); Record record = new Record(); record.setContentType(ProtocolMessageType.HANDSHAKE.getValue()); record.prepareComputations(); record.setSequenceNumber(new BigInteger("0")); record.setCleanProtocolMessageBytes(data); record.setProtocolVersion(ProtocolVersion.TLS10.getValue()); cipher.encrypt(record); assertNull(record.getComputations().getExplicitNonce()); assertNull(record.getComputations().getAeadSalt()); assertNull(record.getComputations().getGcmNonce()); assertNull(record.getComputations().getAuthenticationTag()); assertNull(record.getComputations().getAuthenticationTagValid()); assertArrayEquals(ArrayConverter.hexStringToByteArray("00000000000000001603010028"), record.getComputations() .getAuthenticatedMetaData().getValue()); assertArrayEquals(data, record.getComputations().getAuthenticatedNonMetaData().getValue()); assertArrayEquals(ArrayConverter.hexStringToByteArray("1ACF314DA7208EB8"), record.getComputations() .getCbcInitialisationVector().getValue()); assertArrayEquals(ArrayConverter.hexStringToByteArray("65B7DA726864D4184D75A549BF5C06AB20867846AF4434CC"), record.getComputations().getCipherKey().getValue()); assertArrayEquals(ArrayConverter.hexStringToByteArray("183612323C5507EDAA5BF0DE71272A2EA87B1165"), record .getComputations().getMacKey().getValue()); assertArrayEquals(ArrayConverter.hexStringToByteArray("7952A83507720317BEE172747A2A6C84759E6A33"), record .getComputations().getMac().getValue()); assertArrayEquals(ArrayConverter.hexStringToByteArray("03030303"), record.getComputations().getPadding() .getValue()); assertArrayEquals( ArrayConverter .hexStringToByteArray("1400000CCE92FBEC9131F48A63FED31F71573F726479AA9108FB86A4FA16BC1D5CB57530030303037952A83507720317BEE172747A2A6C84759E6A3303030303"), record.getComputations().getPlainRecordBytes().getValue()); assertArrayEquals( ArrayConverter .hexStringToByteArray("C34B06D54CDE2A5AF25EE0AE1896F6F149720FA9EC205C6629B2C7F52A7F3A72931E351D4AD26E231DE35AD06AC17B8A26638290BB5846283B4788D8C42119BD"), record.getComputations().getCiphertext().getValue()); assertArrayEquals( ArrayConverter .hexStringToByteArray("C34B06D54CDE2A5AF25EE0AE1896F6F149720FA9EC205C6629B2C7F52A7F3A72931E351D4AD26E231DE35AD06AC17B8A26638290BB5846283B4788D8C42119BD"), record.getProtocolMessageBytes().getValue()); assertTrue(record.getComputations().getMacValid()); assertTrue(record.getComputations().getPaddingValid()); }
private byte[] encrypt(byte[] plaintext, byte[] iv) throws CryptoException { byte[] expandedPlaintext = this.expandToBlocksize(plaintext); byte[] ciphertext = encryptCipher.encrypt(iv, expandedPlaintext); if (!useExplicitIv) { encryptCipher.setIv(extractNextEncryptIv(ciphertext)); } LOGGER.debug("EncryptIv: " + ArrayConverter.bytesToHexString(encryptCipher.getIv())); return ciphertext; }
RecordBlockCipher extends RecordCipher { private byte[] encrypt(byte[] plaintext, byte[] iv) throws CryptoException { byte[] expandedPlaintext = this.expandToBlocksize(plaintext); byte[] ciphertext = encryptCipher.encrypt(iv, expandedPlaintext); if (!useExplicitIv) { encryptCipher.setIv(extractNextEncryptIv(ciphertext)); } LOGGER.debug("EncryptIv: " + ArrayConverter.bytesToHexString(encryptCipher.getIv())); return ciphertext; } }
RecordBlockCipher extends RecordCipher { private byte[] encrypt(byte[] plaintext, byte[] iv) throws CryptoException { byte[] expandedPlaintext = this.expandToBlocksize(plaintext); byte[] ciphertext = encryptCipher.encrypt(iv, expandedPlaintext); if (!useExplicitIv) { encryptCipher.setIv(extractNextEncryptIv(ciphertext)); } LOGGER.debug("EncryptIv: " + ArrayConverter.bytesToHexString(encryptCipher.getIv())); return ciphertext; } RecordBlockCipher(TlsContext context, KeySet keySet); }
RecordBlockCipher extends RecordCipher { private byte[] encrypt(byte[] plaintext, byte[] iv) throws CryptoException { byte[] expandedPlaintext = this.expandToBlocksize(plaintext); byte[] ciphertext = encryptCipher.encrypt(iv, expandedPlaintext); if (!useExplicitIv) { encryptCipher.setIv(extractNextEncryptIv(ciphertext)); } LOGGER.debug("EncryptIv: " + ArrayConverter.bytesToHexString(encryptCipher.getIv())); return ciphertext; } RecordBlockCipher(TlsContext context, KeySet keySet); byte[] calculatePadding(int paddingLength); int calculatePaddingLength(Record record, int dataLength); byte[] getEncryptionIV(); @Override void encrypt(Record record); @Override void decrypt(Record record); @Override void encrypt(BlobRecord br); @Override void decrypt(BlobRecord br); }
RecordBlockCipher extends RecordCipher { private byte[] encrypt(byte[] plaintext, byte[] iv) throws CryptoException { byte[] expandedPlaintext = this.expandToBlocksize(plaintext); byte[] ciphertext = encryptCipher.encrypt(iv, expandedPlaintext); if (!useExplicitIv) { encryptCipher.setIv(extractNextEncryptIv(ciphertext)); } LOGGER.debug("EncryptIv: " + ArrayConverter.bytesToHexString(encryptCipher.getIv())); return ciphertext; } RecordBlockCipher(TlsContext context, KeySet keySet); byte[] calculatePadding(int paddingLength); int calculatePaddingLength(Record record, int dataLength); byte[] getEncryptionIV(); @Override void encrypt(Record record); @Override void decrypt(Record record); @Override void encrypt(BlobRecord br); @Override void decrypt(BlobRecord br);  }