RecordBlockCipher extends RecordCipher { @Override public void decrypt(Record record) throws CryptoException { if (record.getComputations() == null) { LOGGER.warn("Record computations are not preapred."); record.prepareComputations(); } LOGGER.debug("Decrypting Record"); RecordCryptoComputations computations = record.getComputations(); computations.setMacKey(getKeySet().getReadMacSecret(context.getChooser().getConnectionEndType())); computations.setCipherKey(getKeySet().getReadKey(context.getChooser().getConnectionEndType())); byte[] plaintext = record.getProtocolMessageBytes().getValue(); DecryptionParser parser = new DecryptionParser(0, plaintext); CipherSuite cipherSuite = context.getChooser().getSelectedCipherSuite(); byte[] iv; if (useExplicitIv) { LOGGER.debug("Using explicit IV"); CipherAlgorithm cipherAlgorithm = AlgorithmResolver.getCipher(cipherSuite); iv = parser.parseByteArrayField(cipherAlgorithm.getNonceBytesFromHandshake()); } else { LOGGER.debug("Using implicit IV"); iv = decryptCipher.getIv(); } LOGGER.debug("Using IV:" + ArrayConverter.bytesToHexString(iv)); record.getComputations().setCbcInitialisationVector(iv); if (context.isExtensionNegotiated(ExtensionType.ENCRYPT_THEN_MAC)) { int macLength = readMac.getMacLength(); int toParseCiphertextLenght = parser.getBytesLeft() - macLength; if (toParseCiphertextLenght < 0) { throw new CryptoException("Record too small"); } byte[] ciphertext = parser.parseByteArrayField(toParseCiphertextLenght); computations.setCiphertext(ciphertext); byte[] hmac = parser.parseByteArrayField(macLength); computations.setMac(hmac); byte[] plainData = decryptCipher.decrypt(iv, ciphertext); computations.setPlainRecordBytes(plainData); plainData = computations.getPlainRecordBytes().getValue(); LOGGER.info(ArrayConverter.bytesToHexString(plainData)); parser = new DecryptionParser(0, plainData); byte[] cleanProtocolBytes = parser.parseByteArrayField(plainData.length - (plainData[plainData.length - 1] + 1)); record.setCleanProtocolMessageBytes(cleanProtocolBytes); if (useExplicitIv) { computations.setAuthenticatedNonMetaData(ArrayConverter.concatenate(record.getComputations() .getCbcInitialisationVector().getValue(), record.getComputations().getCiphertext().getValue())); } else { computations.setAuthenticatedNonMetaData(record.getComputations().getCiphertext().getValue()); } computations.setAuthenticatedMetaData(collectAdditionalAuthenticatedData(record, version)); byte[] padding = parser.parseByteArrayField(plainData[plainData.length - 1] + 1); computations.setPadding(padding); computations.setPaddingValid(isPaddingValid(padding)); byte[] calculatedHMAC = calculateMac(ArrayConverter.concatenate(computations.getAuthenticatedMetaData() .getValue(), computations.getAuthenticatedNonMetaData().getValue()), context.getConnection() .getLocalConnectionEndType().getPeer()); computations.setMacValid(Arrays.equals(calculatedHMAC, computations.getMac().getValue())); } else { byte[] ciphertext = parser.parseByteArrayField(parser.getBytesLeft()); computations.setCiphertext(ciphertext); ciphertext = computations.getCiphertext().getValue(); byte[] plainData = decryptCipher.decrypt(iv, ciphertext); computations.setPlainRecordBytes(plainData); plainData = computations.getPlainRecordBytes().getValue(); parser = new DecryptionParser(0, plainData); byte[] cleanProtocolBytes = parser.parseByteArrayField(plainData.length - readMac.getMacLength() - (plainData[plainData.length - 1] + 1)); record.setCleanProtocolMessageBytes(cleanProtocolBytes); byte[] hmac = parser.parseByteArrayField(readMac.getMacLength()); record.getComputations().setMac(hmac); byte[] padding = parser.parseByteArrayField(plainData[plainData.length - 1] + 1); computations.setPadding(padding); computations.setAuthenticatedNonMetaData(cleanProtocolBytes); computations.setAuthenticatedMetaData(collectAdditionalAuthenticatedData(record, version)); computations.setPaddingValid(isPaddingValid(padding)); byte[] calculatedHMAC = calculateMac(ArrayConverter.concatenate(computations.getAuthenticatedMetaData() .getValue(), computations.getAuthenticatedNonMetaData().getValue()), context.getConnection() .getLocalConnectionEndType().getPeer()); computations.setMacValid(Arrays.equals(calculatedHMAC, computations.getMac().getValue())); } } 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);  }
@Test public void testDecryptTls10Client() throws NoSuchAlgorithmException, CryptoException { context.setConnection(new InboundConnection()); context.setSelectedCipherSuite(CipherSuite.TLS_RSA_WITH_3DES_EDE_CBC_SHA); context.setSelectedProtocolVersion(ProtocolVersion.TLS10); byte[] data = ArrayConverter .hexStringToByteArray("C34B06D54CDE2A5AF25EE0AE1896F6F149720FA9EC205C6629B2C7F52A7F3A72931E351D4AD26E231DE35AD06AC17B8A26638290BB5846283B4788D8C42119BD"); 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.setProtocolMessageBytes(data); record.setProtocolVersion(ProtocolVersion.TLS10.getValue()); cipher.decrypt(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( ArrayConverter .hexStringToByteArray("1400000CCE92FBEC9131F48A63FED31F71573F726479AA9108FB86A4FA16BC1D5CB5753003030303"), 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()); assertArrayEquals( ArrayConverter .hexStringToByteArray("1400000CCE92FBEC9131F48A63FED31F71573F726479AA9108FB86A4FA16BC1D5CB5753003030303"), record.getCleanProtocolMessageBytes().getValue()); assertTrue(record.getComputations().getMacValid()); assertTrue(record.getComputations().getPaddingValid()); }
@Test public void testDecryptTls11Client() throws NoSuchAlgorithmException, CryptoException { context.setConnection(new InboundConnection()); context.setSelectedCipherSuite(CipherSuite.TLS_RSA_WITH_3DES_EDE_CBC_SHA); context.setSelectedProtocolVersion(ProtocolVersion.TLS11); KeySet keySet = new KeySet(); keySet.setClientWriteKey(ArrayConverter .hexStringToByteArray("65B7DA726864D4184D75A549BF5C06AB20867846AF4434CC")); keySet.setClientWriteMacSecret(ArrayConverter.hexStringToByteArray("183612323C5507EDAA5BF0DE71272A2EA87B1165")); keySet.setClientWriteIv(new byte[8]); keySet.setServerWriteIv(new byte[8]); keySet.setServerWriteKey(new byte[24]); keySet.setServerWriteMacSecret(new byte[20]); byte[] data = ArrayConverter .hexStringToByteArray("1ACF314DA7208EB8C34B06D54CDE2A5AF25EE0AE1896F6F149720FA9EC205C6629B2C7F52A7F3A72931E351D4AD26E235FDF3AEC315FD8629559C31FDF6F88E35EC40BF4B2A46473"); cipher = new RecordBlockCipher(context, keySet); Record record = new Record(); record.setContentType(ProtocolMessageType.HANDSHAKE.getValue()); record.prepareComputations(); record.setSequenceNumber(new BigInteger("0")); record.setProtocolMessageBytes(data); record.setProtocolVersion(ProtocolVersion.TLS11.getValue()); cipher.decrypt(record); assertNull(record.getComputations().getExplicitNonce()); assertNull(record.getComputations().getAeadSalt()); assertNull(record.getComputations().getGcmNonce()); assertNull(record.getComputations().getAuthenticationTag()); assertNull(record.getComputations().getAuthenticationTagValid()); assertArrayEquals(ArrayConverter.hexStringToByteArray("00000000000000001603020028"), record.getComputations() .getAuthenticatedMetaData().getValue()); assertArrayEquals( ArrayConverter .hexStringToByteArray("1400000CCE92FBEC9131F48A63FED31F71573F726479AA9108FB86A4FA16BC1D5CB5753003030303"), 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("223E43EF3310C5801FD0219E41EF6972738E96C6"), record .getComputations().getMac().getValue()); assertArrayEquals(ArrayConverter.hexStringToByteArray("03030303"), record.getComputations().getPadding() .getValue()); assertArrayEquals( ArrayConverter .hexStringToByteArray("1400000CCE92FBEC9131F48A63FED31F71573F726479AA9108FB86A4FA16BC1D5CB5753003030303223E43EF3310C5801FD0219E41EF6972738E96C603030303"), record.getComputations().getPlainRecordBytes().getValue()); assertArrayEquals( ArrayConverter .hexStringToByteArray("C34B06D54CDE2A5AF25EE0AE1896F6F149720FA9EC205C6629B2C7F52A7F3A72931E351D4AD26E235FDF3AEC315FD8629559C31FDF6F88E35EC40BF4B2A46473"), record.getComputations().getCiphertext().getValue()); assertArrayEquals( ArrayConverter .hexStringToByteArray("1ACF314DA7208EB8C34B06D54CDE2A5AF25EE0AE1896F6F149720FA9EC205C6629B2C7F52A7F3A72931E351D4AD26E235FDF3AEC315FD8629559C31FDF6F88E35EC40BF4B2A46473"), record.getProtocolMessageBytes().getValue()); assertArrayEquals( ArrayConverter .hexStringToByteArray("1400000CCE92FBEC9131F48A63FED31F71573F726479AA9108FB86A4FA16BC1D5CB5753003030303"), record.getCleanProtocolMessageBytes().getValue()); assertTrue(record.getComputations().getMacValid()); assertTrue(record.getComputations().getPaddingValid()); }
@Test public void testDecryptTls12Client() throws NoSuchAlgorithmException, CryptoException { context.setConnection(new InboundConnection()); context.setSelectedCipherSuite(CipherSuite.TLS_RSA_WITH_3DES_EDE_CBC_SHA); context.setSelectedProtocolVersion(ProtocolVersion.TLS12); KeySet keySet = new KeySet(); keySet.setClientWriteKey(ArrayConverter .hexStringToByteArray("65B7DA726864D4184D75A549BF5C06AB20867846AF4434CC")); keySet.setClientWriteMacSecret(ArrayConverter.hexStringToByteArray("183612323C5507EDAA5BF0DE71272A2EA87B1165")); keySet.setClientWriteIv(new byte[8]); keySet.setServerWriteIv(new byte[8]); keySet.setServerWriteKey(new byte[24]); keySet.setServerWriteMacSecret(new byte[20]); byte[] data = ArrayConverter .hexStringToByteArray("1ACF314DA7208EB8C34B06D54CDE2A5AF25EE0AE1896F6F149720FA9EC205C6629B2C7F52A7F3A72931E351D4AD26E23658D0028D806AD6DCFB4A1C95523EE32182FE110528D80AE"); cipher = new RecordBlockCipher(context, keySet); Record record = new Record(); record.setContentType(ProtocolMessageType.HANDSHAKE.getValue()); record.prepareComputations(); record.setSequenceNumber(new BigInteger("0")); record.setProtocolMessageBytes(data); record.setProtocolVersion(ProtocolVersion.TLS12.getValue()); cipher.decrypt(record); assertNull(record.getComputations().getExplicitNonce()); assertNull(record.getComputations().getAeadSalt()); assertNull(record.getComputations().getGcmNonce()); assertNull(record.getComputations().getAuthenticationTag()); assertNull(record.getComputations().getAuthenticationTagValid()); assertArrayEquals(ArrayConverter.hexStringToByteArray("00000000000000001603030028"), record.getComputations() .getAuthenticatedMetaData().getValue()); assertArrayEquals( ArrayConverter .hexStringToByteArray("1400000CCE92FBEC9131F48A63FED31F71573F726479AA9108FB86A4FA16BC1D5CB5753003030303"), 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("86878C26AA74D2576F5849AEF6CFED88BFD7FE7E"), record .getComputations().getMac().getValue()); assertArrayEquals(ArrayConverter.hexStringToByteArray("03030303"), record.getComputations().getPadding() .getValue()); assertArrayEquals( ArrayConverter .hexStringToByteArray("1400000CCE92FBEC9131F48A63FED31F71573F726479AA9108FB86A4FA16BC1D5CB575300303030386878C26AA74D2576F5849AEF6CFED88BFD7FE7E03030303"), record.getComputations().getPlainRecordBytes().getValue()); assertArrayEquals( ArrayConverter .hexStringToByteArray("C34B06D54CDE2A5AF25EE0AE1896F6F149720FA9EC205C6629B2C7F52A7F3A72931E351D4AD26E23658D0028D806AD6DCFB4A1C95523EE32182FE110528D80AE"), record.getComputations().getCiphertext().getValue()); assertArrayEquals( ArrayConverter .hexStringToByteArray("1ACF314DA7208EB8C34B06D54CDE2A5AF25EE0AE1896F6F149720FA9EC205C6629B2C7F52A7F3A72931E351D4AD26E23658D0028D806AD6DCFB4A1C95523EE32182FE110528D80AE"), record.getProtocolMessageBytes().getValue()); assertArrayEquals( ArrayConverter .hexStringToByteArray("1400000CCE92FBEC9131F48A63FED31F71573F726479AA9108FB86A4FA16BC1D5CB5753003030303"), record.getCleanProtocolMessageBytes().getValue()); assertTrue(record.getComputations().getMacValid()); assertTrue(record.getComputations().getPaddingValid()); }
@Test public void testDecryptTls10Server() throws NoSuchAlgorithmException, CryptoException { context.setConnection(new OutboundConnection()); context.setTalkingConnectionEndType(ConnectionEndType.SERVER); context.setSelectedCipherSuite(CipherSuite.TLS_RSA_WITH_3DES_EDE_CBC_SHA); context.setSelectedProtocolVersion(ProtocolVersion.TLS10); byte[] data = ArrayConverter .hexStringToByteArray("C34B06D54CDE2A5AF25EE0AE1896F6F149720FA9EC205C6629B2C7F52A7F3A72931E351D4AD26E231DE35AD06AC17B8A26638290BB5846283B4788D8C42119BD"); KeySet keySet = new KeySet(); keySet.setServerWriteKey(ArrayConverter .hexStringToByteArray("65B7DA726864D4184D75A549BF5C06AB20867846AF4434CC")); keySet.setServerWriteMacSecret(ArrayConverter.hexStringToByteArray("183612323C5507EDAA5BF0DE71272A2EA87B1165")); keySet.setServerWriteIv(ArrayConverter.hexStringToByteArray("1ACF314DA7208EB8")); keySet.setClientWriteIv(new byte[8]); keySet.setClientWriteKey(new byte[24]); keySet.setClientWriteMacSecret(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.setProtocolMessageBytes(data); record.setProtocolVersion(ProtocolVersion.TLS10.getValue()); cipher.decrypt(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( ArrayConverter .hexStringToByteArray("1400000CCE92FBEC9131F48A63FED31F71573F726479AA9108FB86A4FA16BC1D5CB5753003030303"), 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()); assertArrayEquals( ArrayConverter .hexStringToByteArray("1400000CCE92FBEC9131F48A63FED31F71573F726479AA9108FB86A4FA16BC1D5CB5753003030303"), record.getCleanProtocolMessageBytes().getValue()); assertTrue(record.getComputations().getMacValid()); assertTrue(record.getComputations().getPaddingValid()); }
@Test public void testDecryptTls11Server() throws NoSuchAlgorithmException, CryptoException { context.setConnection(new OutboundConnection()); context.setTalkingConnectionEndType(ConnectionEndType.SERVER); context.setSelectedCipherSuite(CipherSuite.TLS_RSA_WITH_3DES_EDE_CBC_SHA); context.setSelectedProtocolVersion(ProtocolVersion.TLS11); KeySet keySet = new KeySet(); keySet.setServerWriteKey(ArrayConverter .hexStringToByteArray("65B7DA726864D4184D75A549BF5C06AB20867846AF4434CC")); keySet.setServerWriteMacSecret(ArrayConverter.hexStringToByteArray("183612323C5507EDAA5BF0DE71272A2EA87B1165")); keySet.setServerWriteIv(new byte[8]); keySet.setClientWriteIv(new byte[8]); keySet.setClientWriteKey(new byte[24]); keySet.setClientWriteMacSecret(new byte[20]); byte[] data = ArrayConverter .hexStringToByteArray("1ACF314DA7208EB8C34B06D54CDE2A5AF25EE0AE1896F6F149720FA9EC205C6629B2C7F52A7F3A72931E351D4AD26E235FDF3AEC315FD8629559C31FDF6F88E35EC40BF4B2A46473"); cipher = new RecordBlockCipher(context, keySet); Record record = new Record(); record.setContentType(ProtocolMessageType.HANDSHAKE.getValue()); record.prepareComputations(); record.setSequenceNumber(new BigInteger("0")); record.setProtocolMessageBytes(data); record.setProtocolVersion(ProtocolVersion.TLS11.getValue()); cipher.decrypt(record); assertNull(record.getComputations().getExplicitNonce()); assertNull(record.getComputations().getAeadSalt()); assertNull(record.getComputations().getGcmNonce()); assertNull(record.getComputations().getAuthenticationTag()); assertNull(record.getComputations().getAuthenticationTagValid()); assertArrayEquals(ArrayConverter.hexStringToByteArray("00000000000000001603020028"), record.getComputations() .getAuthenticatedMetaData().getValue()); assertArrayEquals( ArrayConverter .hexStringToByteArray("1400000CCE92FBEC9131F48A63FED31F71573F726479AA9108FB86A4FA16BC1D5CB5753003030303"), 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("223E43EF3310C5801FD0219E41EF6972738E96C6"), record .getComputations().getMac().getValue()); assertArrayEquals(ArrayConverter.hexStringToByteArray("03030303"), record.getComputations().getPadding() .getValue()); assertArrayEquals( ArrayConverter .hexStringToByteArray("1400000CCE92FBEC9131F48A63FED31F71573F726479AA9108FB86A4FA16BC1D5CB5753003030303223E43EF3310C5801FD0219E41EF6972738E96C603030303"), record.getComputations().getPlainRecordBytes().getValue()); assertArrayEquals( ArrayConverter .hexStringToByteArray("C34B06D54CDE2A5AF25EE0AE1896F6F149720FA9EC205C6629B2C7F52A7F3A72931E351D4AD26E235FDF3AEC315FD8629559C31FDF6F88E35EC40BF4B2A46473"), record.getComputations().getCiphertext().getValue()); assertArrayEquals( ArrayConverter .hexStringToByteArray("1ACF314DA7208EB8C34B06D54CDE2A5AF25EE0AE1896F6F149720FA9EC205C6629B2C7F52A7F3A72931E351D4AD26E235FDF3AEC315FD8629559C31FDF6F88E35EC40BF4B2A46473"), record.getProtocolMessageBytes().getValue()); assertArrayEquals( ArrayConverter .hexStringToByteArray("1400000CCE92FBEC9131F48A63FED31F71573F726479AA9108FB86A4FA16BC1D5CB5753003030303"), record.getCleanProtocolMessageBytes().getValue()); assertTrue(record.getComputations().getMacValid()); assertTrue(record.getComputations().getPaddingValid()); }
@Test public void testDecryptTls12Server() throws NoSuchAlgorithmException, CryptoException { context.setConnection(new OutboundConnection()); context.setTalkingConnectionEndType(ConnectionEndType.SERVER); context.setSelectedCipherSuite(CipherSuite.TLS_RSA_WITH_3DES_EDE_CBC_SHA); context.setSelectedProtocolVersion(ProtocolVersion.TLS12); KeySet keySet = new KeySet(); keySet.setServerWriteKey(ArrayConverter .hexStringToByteArray("65B7DA726864D4184D75A549BF5C06AB20867846AF4434CC")); keySet.setServerWriteMacSecret(ArrayConverter.hexStringToByteArray("183612323C5507EDAA5BF0DE71272A2EA87B1165")); keySet.setServerWriteIv(new byte[8]); keySet.setClientWriteIv(new byte[8]); keySet.setClientWriteKey(new byte[24]); keySet.setClientWriteMacSecret(new byte[20]); byte[] data = ArrayConverter .hexStringToByteArray("1ACF314DA7208EB8C34B06D54CDE2A5AF25EE0AE1896F6F149720FA9EC205C6629B2C7F52A7F3A72931E351D4AD26E23658D0028D806AD6DCFB4A1C95523EE32182FE110528D80AE"); cipher = new RecordBlockCipher(context, keySet); Record record = new Record(); record.setContentType(ProtocolMessageType.HANDSHAKE.getValue()); record.prepareComputations(); record.setSequenceNumber(new BigInteger("0")); record.setProtocolMessageBytes(data); record.setProtocolVersion(ProtocolVersion.TLS12.getValue()); cipher.decrypt(record); assertNull(record.getComputations().getExplicitNonce()); assertNull(record.getComputations().getAeadSalt()); assertNull(record.getComputations().getGcmNonce()); assertNull(record.getComputations().getAuthenticationTag()); assertNull(record.getComputations().getAuthenticationTagValid()); assertArrayEquals(ArrayConverter.hexStringToByteArray("00000000000000001603030028"), record.getComputations() .getAuthenticatedMetaData().getValue()); assertArrayEquals( ArrayConverter .hexStringToByteArray("1400000CCE92FBEC9131F48A63FED31F71573F726479AA9108FB86A4FA16BC1D5CB5753003030303"), 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("86878C26AA74D2576F5849AEF6CFED88BFD7FE7E"), record .getComputations().getMac().getValue()); assertArrayEquals(ArrayConverter.hexStringToByteArray("03030303"), record.getComputations().getPadding() .getValue()); assertArrayEquals( ArrayConverter .hexStringToByteArray("1400000CCE92FBEC9131F48A63FED31F71573F726479AA9108FB86A4FA16BC1D5CB575300303030386878C26AA74D2576F5849AEF6CFED88BFD7FE7E03030303"), record.getComputations().getPlainRecordBytes().getValue()); assertArrayEquals( ArrayConverter .hexStringToByteArray("C34B06D54CDE2A5AF25EE0AE1896F6F149720FA9EC205C6629B2C7F52A7F3A72931E351D4AD26E23658D0028D806AD6DCFB4A1C95523EE32182FE110528D80AE"), record.getComputations().getCiphertext().getValue()); assertArrayEquals( ArrayConverter .hexStringToByteArray("1ACF314DA7208EB8C34B06D54CDE2A5AF25EE0AE1896F6F149720FA9EC205C6629B2C7F52A7F3A72931E351D4AD26E23658D0028D806AD6DCFB4A1C95523EE32182FE110528D80AE"), record.getProtocolMessageBytes().getValue()); assertArrayEquals( ArrayConverter .hexStringToByteArray("1400000CCE92FBEC9131F48A63FED31F71573F726479AA9108FB86A4FA16BC1D5CB5753003030303"), record.getCleanProtocolMessageBytes().getValue()); assertTrue(record.getComputations().getMacValid()); assertTrue(record.getComputations().getPaddingValid()); }
@Test public void testDecryptTls10WithEncryptThenMacClient() throws NoSuchAlgorithmException, CryptoException { context.setConnection(new InboundConnection()); context.setSelectedCipherSuite(CipherSuite.TLS_RSA_WITH_3DES_EDE_CBC_SHA); context.setSelectedProtocolVersion(ProtocolVersion.TLS10); context.addNegotiatedExtension(ExtensionType.ENCRYPT_THEN_MAC); byte[] data = ArrayConverter .hexStringToByteArray("C34B06D54CDE2A5AF25EE0AE1896F6F149720FA9EC205C6629B2C7F52A7F3A72931E351D4AD26E23A5B8C98C4E2DE3621A9BCCDD712329663F4065FA0E178F7A434676BE"); 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.setProtocolMessageBytes(data); record.setProtocolVersion(ProtocolVersion.TLS10.getValue()); cipher.decrypt(record); assertNull(record.getComputations().getExplicitNonce()); assertNull(record.getComputations().getAeadSalt()); assertNull(record.getComputations().getGcmNonce()); assertNull(record.getComputations().getAuthenticationTag()); assertNull(record.getComputations().getAuthenticationTagValid()); assertArrayEquals( ArrayConverter .hexStringToByteArray("C34B06D54CDE2A5AF25EE0AE1896F6F149720FA9EC205C6629B2C7F52A7F3A72931E351D4AD26E23A5B8C98C4E2DE362"), record.getComputations().getCiphertext().getValue()); assertArrayEquals(ArrayConverter.hexStringToByteArray("00000000000000001603010030"), record.getComputations() .getAuthenticatedMetaData().getValue()); assertArrayEquals( ArrayConverter .hexStringToByteArray("C34B06D54CDE2A5AF25EE0AE1896F6F149720FA9EC205C6629B2C7F52A7F3A72931E351D4AD26E23A5B8C98C4E2DE362"), 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("1A9BCCDD712329663F4065FA0E178F7A434676BE"), record .getComputations().getMac().getValue()); assertArrayEquals(ArrayConverter.hexStringToByteArray("0707070707070707"), record.getComputations() .getPadding().getValue()); assertArrayEquals( ArrayConverter .hexStringToByteArray("1400000CCE92FBEC9131F48A63FED31F71573F726479AA9108FB86A4FA16BC1D5CB57530030303030707070707070707"), record.getComputations().getPlainRecordBytes().getValue()); assertArrayEquals( ArrayConverter .hexStringToByteArray("1400000CCE92FBEC9131F48A63FED31F71573F726479AA9108FB86A4FA16BC1D5CB5753003030303"), record.getCleanProtocolMessageBytes().getValue()); assertTrue(record.getComputations().getMacValid()); assertTrue(record.getComputations().getPaddingValid()); }
@Test public void testDecryptTls11WithEncryptThenMacClient() throws NoSuchAlgorithmException, CryptoException { context.setConnection(new InboundConnection()); context.setSelectedCipherSuite(CipherSuite.TLS_RSA_WITH_3DES_EDE_CBC_SHA); context.setSelectedProtocolVersion(ProtocolVersion.TLS11); context.addNegotiatedExtension(ExtensionType.ENCRYPT_THEN_MAC); byte[] data = ArrayConverter .hexStringToByteArray("1ACF314DA7208EB8C34B06D54CDE2A5AF25EE0AE1896F6F149720FA9EC205C6629B2C7F52A7F3A72931E351D4AD26E23A5B8C98C4E2DE362BE44B61CE4B722E0A741C12A74D50019A38C91B1"); KeySet keySet = new KeySet(); keySet.setClientWriteKey(ArrayConverter .hexStringToByteArray("65B7DA726864D4184D75A549BF5C06AB20867846AF4434CC")); keySet.setClientWriteMacSecret(ArrayConverter.hexStringToByteArray("183612323C5507EDAA5BF0DE71272A2EA87B1165")); keySet.setClientWriteIv(new byte[0]); 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.setProtocolMessageBytes(data); record.setProtocolVersion(ProtocolVersion.TLS11.getValue()); cipher.decrypt(record); assertNull(record.getComputations().getExplicitNonce()); assertNull(record.getComputations().getAeadSalt()); assertNull(record.getComputations().getGcmNonce()); assertNull(record.getComputations().getAuthenticationTag()); assertNull(record.getComputations().getAuthenticationTagValid()); assertArrayEquals( ArrayConverter .hexStringToByteArray("C34B06D54CDE2A5AF25EE0AE1896F6F149720FA9EC205C6629B2C7F52A7F3A72931E351D4AD26E23A5B8C98C4E2DE362"), record.getComputations().getCiphertext().getValue()); assertArrayEquals(ArrayConverter.hexStringToByteArray("00000000000000001603020038"), record.getComputations() .getAuthenticatedMetaData().getValue()); assertArrayEquals( ArrayConverter .hexStringToByteArray("1ACF314DA7208EB8C34B06D54CDE2A5AF25EE0AE1896F6F149720FA9EC205C6629B2C7F52A7F3A72931E351D4AD26E23A5B8C98C4E2DE362"), 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("BE44B61CE4B722E0A741C12A74D50019A38C91B1"), record .getComputations().getMac().getValue()); assertArrayEquals(ArrayConverter.hexStringToByteArray("0707070707070707"), record.getComputations() .getPadding().getValue()); assertArrayEquals( ArrayConverter .hexStringToByteArray("1400000CCE92FBEC9131F48A63FED31F71573F726479AA9108FB86A4FA16BC1D5CB57530030303030707070707070707"), record.getComputations().getPlainRecordBytes().getValue()); assertArrayEquals( ArrayConverter .hexStringToByteArray("1400000CCE92FBEC9131F48A63FED31F71573F726479AA9108FB86A4FA16BC1D5CB5753003030303"), record.getCleanProtocolMessageBytes().getValue()); assertTrue(record.getComputations().getMacValid()); assertTrue(record.getComputations().getPaddingValid()); }
@Test public void testDecryptTls12WithEncryptThenMacClient() throws NoSuchAlgorithmException, CryptoException { context.setConnection(new InboundConnection()); context.setSelectedCipherSuite(CipherSuite.TLS_RSA_WITH_3DES_EDE_CBC_SHA); context.setSelectedProtocolVersion(ProtocolVersion.TLS12); context.addNegotiatedExtension(ExtensionType.ENCRYPT_THEN_MAC); byte[] data = ArrayConverter .hexStringToByteArray("1ACF314DA7208EB8C34B06D54CDE2A5AF25EE0AE1896F6F149720FA9EC205C6629B2C7F52A7F3A72931E351D4AD26E23A5B8C98C4E2DE3624920C96B8BD457549DA1B0908E13FA3EDD02211B"); KeySet keySet = new KeySet(); keySet.setClientWriteKey(ArrayConverter .hexStringToByteArray("65B7DA726864D4184D75A549BF5C06AB20867846AF4434CC")); keySet.setClientWriteMacSecret(ArrayConverter.hexStringToByteArray("183612323C5507EDAA5BF0DE71272A2EA87B1165")); keySet.setClientWriteIv(new byte[0]); 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.setProtocolMessageBytes(data); record.setProtocolVersion(ProtocolVersion.TLS12.getValue()); cipher.decrypt(record); assertNull(record.getComputations().getExplicitNonce()); assertNull(record.getComputations().getAeadSalt()); assertNull(record.getComputations().getGcmNonce()); assertNull(record.getComputations().getAuthenticationTag()); assertNull(record.getComputations().getAuthenticationTagValid()); assertArrayEquals( ArrayConverter .hexStringToByteArray("C34B06D54CDE2A5AF25EE0AE1896F6F149720FA9EC205C6629B2C7F52A7F3A72931E351D4AD26E23A5B8C98C4E2DE362"), record.getComputations().getCiphertext().getValue()); assertArrayEquals(ArrayConverter.hexStringToByteArray("00000000000000001603030038"), record.getComputations() .getAuthenticatedMetaData().getValue()); assertArrayEquals( ArrayConverter .hexStringToByteArray("1ACF314DA7208EB8C34B06D54CDE2A5AF25EE0AE1896F6F149720FA9EC205C6629B2C7F52A7F3A72931E351D4AD26E23A5B8C98C4E2DE362"), 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("4920C96B8BD457549DA1B0908E13FA3EDD02211B"), record .getComputations().getMac().getValue()); assertArrayEquals(ArrayConverter.hexStringToByteArray("0707070707070707"), record.getComputations() .getPadding().getValue()); assertArrayEquals( ArrayConverter .hexStringToByteArray("1400000CCE92FBEC9131F48A63FED31F71573F726479AA9108FB86A4FA16BC1D5CB57530030303030707070707070707"), record.getComputations().getPlainRecordBytes().getValue()); assertArrayEquals( ArrayConverter .hexStringToByteArray("1400000CCE92FBEC9131F48A63FED31F71573F726479AA9108FB86A4FA16BC1D5CB5753003030303"), record.getCleanProtocolMessageBytes().getValue()); assertTrue(record.getComputations().getMacValid()); assertTrue(record.getComputations().getPaddingValid()); }
@Test public void testDecryptTls10WithEncryptThenMacServer() throws NoSuchAlgorithmException, CryptoException { context.setConnection(new OutboundConnection()); context.setSelectedCipherSuite(CipherSuite.TLS_RSA_WITH_3DES_EDE_CBC_SHA); context.setSelectedProtocolVersion(ProtocolVersion.TLS10); context.addNegotiatedExtension(ExtensionType.ENCRYPT_THEN_MAC); byte[] data = ArrayConverter .hexStringToByteArray("C34B06D54CDE2A5AF25EE0AE1896F6F149720FA9EC205C6629B2C7F52A7F3A72931E351D4AD26E23A5B8C98C4E2DE3621A9BCCDD712329663F4065FA0E178F7A434676BE"); KeySet keySet = new KeySet(); keySet.setServerWriteKey(ArrayConverter .hexStringToByteArray("65B7DA726864D4184D75A549BF5C06AB20867846AF4434CC")); keySet.setServerWriteMacSecret(ArrayConverter.hexStringToByteArray("183612323C5507EDAA5BF0DE71272A2EA87B1165")); keySet.setServerWriteIv(ArrayConverter.hexStringToByteArray("1ACF314DA7208EB8")); keySet.setClientWriteIv(new byte[8]); keySet.setClientWriteKey(new byte[24]); keySet.setClientWriteMacSecret(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.setProtocolMessageBytes(data); record.setProtocolVersion(ProtocolVersion.TLS10.getValue()); cipher.decrypt(record); assertNull(record.getComputations().getExplicitNonce()); assertNull(record.getComputations().getAeadSalt()); assertNull(record.getComputations().getGcmNonce()); assertNull(record.getComputations().getAuthenticationTag()); assertNull(record.getComputations().getAuthenticationTagValid()); assertArrayEquals( ArrayConverter .hexStringToByteArray("C34B06D54CDE2A5AF25EE0AE1896F6F149720FA9EC205C6629B2C7F52A7F3A72931E351D4AD26E23A5B8C98C4E2DE362"), record.getComputations().getCiphertext().getValue()); assertArrayEquals(ArrayConverter.hexStringToByteArray("00000000000000001603010030"), record.getComputations() .getAuthenticatedMetaData().getValue()); assertArrayEquals( ArrayConverter .hexStringToByteArray("C34B06D54CDE2A5AF25EE0AE1896F6F149720FA9EC205C6629B2C7F52A7F3A72931E351D4AD26E23A5B8C98C4E2DE362"), 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("1A9BCCDD712329663F4065FA0E178F7A434676BE"), record .getComputations().getMac().getValue()); assertArrayEquals(ArrayConverter.hexStringToByteArray("0707070707070707"), record.getComputations() .getPadding().getValue()); assertArrayEquals( ArrayConverter .hexStringToByteArray("1400000CCE92FBEC9131F48A63FED31F71573F726479AA9108FB86A4FA16BC1D5CB57530030303030707070707070707"), record.getComputations().getPlainRecordBytes().getValue()); assertArrayEquals( ArrayConverter .hexStringToByteArray("1400000CCE92FBEC9131F48A63FED31F71573F726479AA9108FB86A4FA16BC1D5CB5753003030303"), record.getCleanProtocolMessageBytes().getValue()); assertTrue(record.getComputations().getMacValid()); assertTrue(record.getComputations().getPaddingValid()); }
@Test public void testDecryptTls11WithEncryptThenMacServer() throws NoSuchAlgorithmException, CryptoException { context.setConnection(new OutboundConnection()); context.setSelectedCipherSuite(CipherSuite.TLS_RSA_WITH_3DES_EDE_CBC_SHA); context.setSelectedProtocolVersion(ProtocolVersion.TLS11); context.addNegotiatedExtension(ExtensionType.ENCRYPT_THEN_MAC); byte[] data = ArrayConverter .hexStringToByteArray("1ACF314DA7208EB8C34B06D54CDE2A5AF25EE0AE1896F6F149720FA9EC205C6629B2C7F52A7F3A72931E351D4AD26E23A5B8C98C4E2DE362BE44B61CE4B722E0A741C12A74D50019A38C91B1"); KeySet keySet = new KeySet(); keySet.setServerWriteKey(ArrayConverter .hexStringToByteArray("65B7DA726864D4184D75A549BF5C06AB20867846AF4434CC")); keySet.setServerWriteMacSecret(ArrayConverter.hexStringToByteArray("183612323C5507EDAA5BF0DE71272A2EA87B1165")); keySet.setServerWriteIv(new byte[0]); keySet.setClientWriteIv(new byte[8]); keySet.setClientWriteKey(new byte[24]); keySet.setClientWriteMacSecret(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.setProtocolMessageBytes(data); record.setProtocolVersion(ProtocolVersion.TLS11.getValue()); cipher.decrypt(record); assertNull(record.getComputations().getExplicitNonce()); assertNull(record.getComputations().getAeadSalt()); assertNull(record.getComputations().getGcmNonce()); assertNull(record.getComputations().getAuthenticationTag()); assertNull(record.getComputations().getAuthenticationTagValid()); assertArrayEquals( ArrayConverter .hexStringToByteArray("C34B06D54CDE2A5AF25EE0AE1896F6F149720FA9EC205C6629B2C7F52A7F3A72931E351D4AD26E23A5B8C98C4E2DE362"), record.getComputations().getCiphertext().getValue()); assertArrayEquals(ArrayConverter.hexStringToByteArray("00000000000000001603020038"), record.getComputations() .getAuthenticatedMetaData().getValue()); assertArrayEquals( ArrayConverter .hexStringToByteArray("1ACF314DA7208EB8C34B06D54CDE2A5AF25EE0AE1896F6F149720FA9EC205C6629B2C7F52A7F3A72931E351D4AD26E23A5B8C98C4E2DE362"), 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("BE44B61CE4B722E0A741C12A74D50019A38C91B1"), record .getComputations().getMac().getValue()); assertArrayEquals(ArrayConverter.hexStringToByteArray("0707070707070707"), record.getComputations() .getPadding().getValue()); assertArrayEquals( ArrayConverter .hexStringToByteArray("1400000CCE92FBEC9131F48A63FED31F71573F726479AA9108FB86A4FA16BC1D5CB57530030303030707070707070707"), record.getComputations().getPlainRecordBytes().getValue()); assertArrayEquals( ArrayConverter .hexStringToByteArray("1400000CCE92FBEC9131F48A63FED31F71573F726479AA9108FB86A4FA16BC1D5CB5753003030303"), record.getCleanProtocolMessageBytes().getValue()); assertTrue(record.getComputations().getMacValid()); assertTrue(record.getComputations().getPaddingValid()); }
@Test public void testDecryptTls12WithEncryptThenMacServer() throws NoSuchAlgorithmException, CryptoException { context.setConnection(new OutboundConnection()); context.setSelectedCipherSuite(CipherSuite.TLS_RSA_WITH_3DES_EDE_CBC_SHA); context.setSelectedProtocolVersion(ProtocolVersion.TLS12); context.addNegotiatedExtension(ExtensionType.ENCRYPT_THEN_MAC); byte[] data = ArrayConverter .hexStringToByteArray("1ACF314DA7208EB8C34B06D54CDE2A5AF25EE0AE1896F6F149720FA9EC205C6629B2C7F52A7F3A72931E351D4AD26E23A5B8C98C4E2DE3624920C96B8BD457549DA1B0908E13FA3EDD02211B"); KeySet keySet = new KeySet(); keySet.setServerWriteKey(ArrayConverter .hexStringToByteArray("65B7DA726864D4184D75A549BF5C06AB20867846AF4434CC")); keySet.setServerWriteMacSecret(ArrayConverter.hexStringToByteArray("183612323C5507EDAA5BF0DE71272A2EA87B1165")); keySet.setServerWriteIv(new byte[0]); keySet.setClientWriteIv(new byte[8]); keySet.setClientWriteKey(new byte[24]); keySet.setClientWriteMacSecret(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.setProtocolMessageBytes(data); record.setProtocolVersion(ProtocolVersion.TLS12.getValue()); cipher.decrypt(record); assertNull(record.getComputations().getExplicitNonce()); assertNull(record.getComputations().getAeadSalt()); assertNull(record.getComputations().getGcmNonce()); assertNull(record.getComputations().getAuthenticationTag()); assertNull(record.getComputations().getAuthenticationTagValid()); assertArrayEquals( ArrayConverter .hexStringToByteArray("C34B06D54CDE2A5AF25EE0AE1896F6F149720FA9EC205C6629B2C7F52A7F3A72931E351D4AD26E23A5B8C98C4E2DE362"), record.getComputations().getCiphertext().getValue()); assertArrayEquals(ArrayConverter.hexStringToByteArray("00000000000000001603030038"), record.getComputations() .getAuthenticatedMetaData().getValue()); assertArrayEquals( ArrayConverter .hexStringToByteArray("1ACF314DA7208EB8C34B06D54CDE2A5AF25EE0AE1896F6F149720FA9EC205C6629B2C7F52A7F3A72931E351D4AD26E23A5B8C98C4E2DE362"), 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("4920C96B8BD457549DA1B0908E13FA3EDD02211B"), record .getComputations().getMac().getValue()); assertArrayEquals(ArrayConverter.hexStringToByteArray("0707070707070707"), record.getComputations() .getPadding().getValue()); assertArrayEquals( ArrayConverter .hexStringToByteArray("1400000CCE92FBEC9131F48A63FED31F71573F726479AA9108FB86A4FA16BC1D5CB57530030303030707070707070707"), record.getComputations().getPlainRecordBytes().getValue()); assertArrayEquals( ArrayConverter .hexStringToByteArray("1400000CCE92FBEC9131F48A63FED31F71573F726479AA9108FB86A4FA16BC1D5CB5753003030303"), record.getCleanProtocolMessageBytes().getValue()); assertTrue(record.getComputations().getMacValid()); assertTrue(record.getComputations().getPaddingValid()); }