@Override public int getBlocksize() { return algorithm.getBlocksize(); }
/** * * @param suite * @param version * @return */ @Override public List<Record> getRecords(CipherSuite suite, ProtocolVersion version) { int blockSize = AlgorithmResolver.getCipher(suite).getBlocksize(); int macSize = AlgorithmResolver.getMacAlgorithm(version, suite).getSize(); List<Record> recordList = new LinkedList<>(); recordList.addAll(createRecordsWithModifiedMac()); recordList.addAll(createRecordsWithModifiedPadding()); recordList.addAll(createRecordsWithPlainData(blockSize, macSize)); return recordList; }
private List<Record> getPlainRecords(CipherSuite suite, ProtocolVersion version) { List<Record> recordList = new LinkedList<>(); int blockSize = AlgorithmResolver.getCipher(suite).getBlocksize(); for (int paddingLength = 0; paddingLength < 256; paddingLength++) { int messageSize = blockSize - (paddingLength % blockSize); byte[] message = new byte[messageSize]; byte[][] paddings = getModifiedPaddings(paddingLength); for (byte[] padding : paddings) { Record r = new Record(); r.prepareComputations(); byte[] plain = ArrayConverter.concatenate(message, padding); ModifiableByteArray modPlain = new ModifiableByteArray(); modPlain.setModification(new ByteArrayExplicitValueModification(plain)); r.getComputations().setPlainRecordBytes(modPlain); recordList.add(r); } } return recordList; }
private List<Record> getPlainRecords(CipherSuite suite, ProtocolVersion version) { List<Record> recordList = new LinkedList<>(); int blockSize = AlgorithmResolver.getCipher(suite).getBlocksize(); for (int paddingLength = 0; paddingLength < 256; paddingLength++) { int messageSize = blockSize - (paddingLength % blockSize); byte[] message = new byte[messageSize]; byte[][] paddings = getModifiedPaddings(paddingLength); for (byte[] padding : paddings) { Record r = new Record(); r.prepareComputations(); byte[] plain = ArrayConverter.concatenate(message, padding); ModifiableByteArray modPlain = new ModifiableByteArray(); modPlain.setModification(new ByteArrayExplicitValueModification(plain)); r.getComputations().setPlainRecordBytes(modPlain); recordList.add(r); } } return recordList; }
private List<Record> getPaddingFlippedRecords(CipherSuite suite, ProtocolVersion version) { List<Record> recordList = new LinkedList<>(); int blockSize = AlgorithmResolver.getCipher(suite).getBlocksize(); int macSize = AlgorithmResolver.getMacAlgorithm(version, suite).getSize(); for (int paddingLength = 0; paddingLength < 256; paddingLength++) { int messageSize = blockSize - ((paddingLength + macSize) % blockSize); byte[] message = new byte[messageSize]; byte[][] paddings = getModifiedPaddings(paddingLength); for (byte[] padding : paddings) { Record r = new Record(); r.prepareComputations(); ModifiableByteArray modPadding = new ModifiableByteArray(); modPadding.setModification(new ByteArrayExplicitValueModification(padding)); r.getComputations().setPadding(modPadding); ModifiableByteArray modMessage = new ModifiableByteArray(); modMessage.setModification(new ByteArrayExplicitValueModification(message)); r.setCleanProtocolMessageBytes(message); recordList.add(r); } } return recordList; }
private List<Record> getPaddingFlippedRecords(CipherSuite suite, ProtocolVersion version) { List<Record> recordList = new LinkedList<>(); int blockSize = AlgorithmResolver.getCipher(suite).getBlocksize(); int macSize = AlgorithmResolver.getMacAlgorithm(version, suite).getSize(); for (int paddingLength = 0; paddingLength < 256; paddingLength++) { int messageSize = blockSize - ((paddingLength + macSize) % blockSize); byte[] message = new byte[messageSize]; byte[][] paddings = getModifiedPaddings(paddingLength); for (byte[] padding : paddings) { Record r = new Record(); r.prepareComputations(); ModifiableByteArray modPadding = new ModifiableByteArray(); modPadding.setModification(new ByteArrayExplicitValueModification(padding)); r.getComputations().setPadding(modPadding); ModifiableByteArray modMessage = new ModifiableByteArray(); modMessage.setModification(new ByteArrayExplicitValueModification(message)); r.setCleanProtocolMessageBytes(message); recordList.add(r); } } return recordList; }
private static void deriveSSL3ExportKeys(CipherSuite cipherSuite, KeySet keySet, byte[] clientRandom, byte[] serverRandom) { int keySize = AlgorithmResolver.getCipher(cipherSuite).getKeySize(); keySet.setClientWriteKey(MD5firstNBytes(keySize, keySet.getClientWriteKey(), clientRandom, serverRandom)); keySet.setServerWriteKey(MD5firstNBytes(keySize, keySet.getServerWriteKey(), serverRandom, clientRandom)); int blockSize = AlgorithmResolver.getCipher(cipherSuite).getBlocksize(); keySet.setClientWriteIv(MD5firstNBytes(blockSize, clientRandom, serverRandom)); keySet.setServerWriteIv(MD5firstNBytes(blockSize, serverRandom, clientRandom)); }
private static void deriveExportKeys(KeySet keySet, TlsContext context) throws CryptoException { ProtocolVersion protocolVersion = context.getChooser().getSelectedProtocolVersion(); CipherSuite cipherSuite = context.getChooser().getSelectedCipherSuite(); byte[] clientRandom = context.getChooser().getClientRandom(); byte[] serverRandom = context.getChooser().getServerRandom(); if (protocolVersion == ProtocolVersion.SSL3) { deriveSSL3ExportKeys(cipherSuite, keySet, clientRandom, serverRandom); return; } byte[] clientAndServerRandom = ArrayConverter.concatenate(clientRandom, serverRandom); PRFAlgorithm prfAlgorithm = AlgorithmResolver.getPRFAlgorithm(protocolVersion, cipherSuite); int keySize = AlgorithmResolver.getCipher(cipherSuite).getKeySize(); keySet.setClientWriteKey(PseudoRandomFunction.compute(prfAlgorithm, keySet.getClientWriteKey(), PseudoRandomFunction.CLIENT_WRITE_KEY_LABEL, clientAndServerRandom, keySize)); keySet.setServerWriteKey(PseudoRandomFunction.compute(prfAlgorithm, keySet.getServerWriteKey(), PseudoRandomFunction.SERVER_WRITE_KEY_LABEL, clientAndServerRandom, keySize)); int blockSize = AlgorithmResolver.getCipher(cipherSuite).getBlocksize(); byte[] emptySecret = {}; byte[] ivBlock = PseudoRandomFunction.compute(prfAlgorithm, emptySecret, PseudoRandomFunction.IV_BLOCK_LABEL, clientAndServerRandom, 2 * blockSize); keySet.setClientWriteIv(Arrays.copyOfRange(ivBlock, 0, blockSize)); keySet.setServerWriteIv(Arrays.copyOfRange(ivBlock, blockSize, 2 * blockSize)); }
if (context.getChooser().getSelectedProtocolVersion().isTLS13()) { int length = AlgorithmResolver.getCipher(cipherSuite).getBlocksize() - (record.getCleanProtocolMessageBytes().getValue().length % AlgorithmResolver.getCipher( cipherSuite).getBlocksize()) + recordCipher.getTagSize(); record.setLength(length);