Skip to content

Commit 7b8ec07

Browse files
committed
Fixed SSLv3 export key derivation to use correct key and block size.
1 parent 410673f commit 7b8ec07

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

TLS-Core/src/main/java/de/rub/nds/tlsattacker/core/record/cipher/cryptohelper/KeySetGenerator.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,16 +120,16 @@ private static KeySet getTlsKeySet(TlsContext context) throws NoSuchAlgorithmExc
120120

121121
private static void deriveExportKeys(KeySet keySet, TlsContext context) throws CryptoException {
122122
ProtocolVersion protocolVersion = context.getChooser().getSelectedProtocolVersion();
123+
CipherSuite cipherSuite = context.getChooser().getSelectedCipherSuite();
123124
byte[] clientRandom = context.getChooser().getClientRandom();
124125
byte[] serverRandom = context.getChooser().getServerRandom();
125126

126127
if (protocolVersion == ProtocolVersion.SSL3) {
127-
deriveSSL3ExportKeys(keySet, clientRandom, serverRandom);
128+
deriveSSL3ExportKeys(cipherSuite, keySet, clientRandom, serverRandom);
128129
return;
129130
}
130131

131132
byte[] clientAndServerRandom = ArrayConverter.concatenate(clientRandom, serverRandom);
132-
CipherSuite cipherSuite = context.getChooser().getSelectedCipherSuite();
133133
PRFAlgorithm prfAlgorithm = AlgorithmResolver.getPRFAlgorithm(protocolVersion, cipherSuite);
134134
int keySize = AlgorithmResolver.getCipher(cipherSuite).getKeySize();
135135

@@ -146,11 +146,20 @@ private static void deriveExportKeys(KeySet keySet, TlsContext context) throws C
146146
keySet.setServerWriteIv(Arrays.copyOfRange(ivBlock, blockSize, 2 * blockSize));
147147
}
148148

149-
private static void deriveSSL3ExportKeys(KeySet keySet, byte[] clientRandom, byte[] serverRandom) {
150-
keySet.setClientWriteKey(MD5Utils.MD5(keySet.getClientWriteKey(), clientRandom, serverRandom));
151-
keySet.setServerWriteKey(MD5Utils.MD5(keySet.getServerWriteKey(), serverRandom, clientRandom));
152-
keySet.setClientWriteIv(MD5Utils.MD5(clientRandom, serverRandom));
153-
keySet.setServerWriteIv(MD5Utils.MD5(serverRandom, clientRandom));
149+
private static byte[] MD5firstNBytes(int numOfBytes, byte[]... byteArrays) {
150+
byte[] md5 = MD5Utils.MD5(byteArrays);
151+
return Arrays.copyOfRange(md5, 0, numOfBytes);
152+
}
153+
154+
private static void deriveSSL3ExportKeys(CipherSuite cipherSuite, KeySet keySet, byte[] clientRandom,
155+
byte[] serverRandom) {
156+
int keySize = AlgorithmResolver.getCipher(cipherSuite).getKeySize();
157+
keySet.setClientWriteKey(MD5firstNBytes(keySize, keySet.getClientWriteKey(), clientRandom, serverRandom));
158+
keySet.setServerWriteKey(MD5firstNBytes(keySize, keySet.getServerWriteKey(), serverRandom, clientRandom));
159+
160+
int blockSize = AlgorithmResolver.getCipher(cipherSuite).getBlocksize();
161+
keySet.setClientWriteIv(MD5firstNBytes(blockSize, clientRandom, serverRandom));
162+
keySet.setServerWriteIv(MD5firstNBytes(blockSize, serverRandom, clientRandom));
154163
}
155164

156165
private static int getSecretSetSize(ProtocolVersion protocolVersion, CipherSuite cipherSuite)

0 commit comments

Comments
 (0)