Skip to content

Commit cc14cf6

Browse files
author
Patrick Weixler
committed
Added requested changes from reviewed pullrequest #734
1 parent a89b7bc commit cc14cf6

File tree

6 files changed

+65
-74
lines changed

6 files changed

+65
-74
lines changed

TLS-Core/src/main/java/de/rub/nds/tlsattacker/core/constants/KeyUpdateRequest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ public enum KeyUpdateRequest {
1717
UPDATE_REQUESTED((byte) 1);
1818

1919
@HoldsModifiableVariable
20-
private byte request_update;
20+
private byte requestUpdate;
2121

22-
private KeyUpdateRequest(byte request_update) {
23-
this.request_update = request_update;
22+
private KeyUpdateRequest(byte requestUpdate) {
23+
this.requestUpdate = requestUpdate;
2424
}
2525

2626
public byte getValue() {
27-
return request_update;
27+
return requestUpdate;
2828
}
2929

3030
}

TLS-Core/src/main/java/de/rub/nds/tlsattacker/core/protocol/handler/KeyUpdateHandler.java

Lines changed: 43 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import de.rub.nds.modifiablevariable.util.ArrayConverter;
1313
import de.rub.nds.tlsattacker.core.constants.AlgorithmResolver;
1414
import de.rub.nds.tlsattacker.core.constants.HKDFAlgorithm;
15-
import de.rub.nds.tlsattacker.core.constants.KeyUpdateRequest;
1615
import de.rub.nds.tlsattacker.core.constants.Tls13KeySetType;
1716
import de.rub.nds.tlsattacker.core.crypto.HKDFunction;
1817
import de.rub.nds.tlsattacker.core.exceptions.AdjustmentException;
@@ -47,35 +46,27 @@ public KeyUpdateHandler(TlsContext tlsContext) {
4746

4847
@Override
4948
public void adjustTLSContext(KeyUpdateMessage message) {
50-
49+
if (tlsContext.getChooser().getTalkingConnectionEnd() != tlsContext.getChooser().getConnectionEndType()) {
50+
adjustApplicationTrafficSecrets();
51+
setRecordCipher(Tls13KeySetType.APPLICATION_TRAFFIC_SECRETS);
52+
}
5153
}
5254

5355
@Override
5456
public void adjustTlsContextAfterSerialize(KeyUpdateMessage message) {
55-
56-
if (message.getRequestUpdate() == KeyUpdateRequest.UPDATE_REQUESTED) {
57-
adjustApplicationTrafficSecrets();
58-
}
57+
adjustApplicationTrafficSecrets();
5958
setRecordCipher(Tls13KeySetType.APPLICATION_TRAFFIC_SECRETS);
60-
6159
}
6260

6361
@Override
6462
public ProtocolMessageParser getParser(byte[] message, int pointer) {
65-
6663
return new KeyUpdateParser(pointer, message, tlsContext.getChooser().getSelectedProtocolVersion(),
6764
tlsContext.getConfig());
6865

6966
}
7067

7168
@Override
7269
public ProtocolMessagePreparator getPreparator(KeyUpdateMessage message) {
73-
if (tlsContext.getChooser().getTalkingConnectionEnd() != tlsContext.getChooser().getConnectionEndType()) {
74-
if (message.getRequestUpdate() == KeyUpdateRequest.UPDATE_REQUESTED) {
75-
adjustApplicationTrafficSecrets();
76-
}
77-
setRecordCipher(Tls13KeySetType.APPLICATION_TRAFFIC_SECRETS);
78-
}
7970
return new KeyUpdatePreparator(tlsContext.getChooser(), message);
8071
}
8172

@@ -89,23 +80,29 @@ private void adjustApplicationTrafficSecrets() {
8980
.getSelectedCipherSuite());
9081

9182
try {
92-
9383
Mac mac = Mac.getInstance(hkdfAlgortihm.getMacAlgorithm().getJavaName());
94-
byte[] clientApplicationTrafficSecret = HKDFunction.expandLabel(hkdfAlgortihm,
95-
tlsContext.getClientApplicationTrafficSecret(), HKDFunction.TRAFFICUPD, new byte[0],
96-
mac.getMacLength());
9784

98-
tlsContext.setClientApplicationTrafficSecret(clientApplicationTrafficSecret);
99-
LOGGER.debug("Set clientApplicationTrafficSecret in Context to "
100-
+ ArrayConverter.bytesToHexString(clientApplicationTrafficSecret));
85+
if (tlsContext.getChooser().getTalkingConnectionEnd() == ConnectionEndType.CLIENT) {
86+
87+
byte[] clientApplicationTrafficSecret = HKDFunction.expandLabel(hkdfAlgortihm,
88+
tlsContext.getClientApplicationTrafficSecret(), HKDFunction.TRAFFICUPD, new byte[0],
89+
mac.getMacLength());
90+
91+
tlsContext.setClientApplicationTrafficSecret(clientApplicationTrafficSecret);
92+
LOGGER.debug("Set clientApplicationTrafficSecret in Context to "
93+
+ ArrayConverter.bytesToHexString(clientApplicationTrafficSecret));
10194

102-
byte[] serverApplicationTrafficSecret = HKDFunction.expandLabel(hkdfAlgortihm,
103-
tlsContext.getServerApplicationTrafficSecret(), HKDFunction.TRAFFICUPD, new byte[0],
104-
mac.getMacLength());
95+
} else {
10596

106-
tlsContext.setServerApplicationTrafficSecret(serverApplicationTrafficSecret);
107-
LOGGER.debug("Set serverApplicationTrafficSecret in Context to "
108-
+ ArrayConverter.bytesToHexString(serverApplicationTrafficSecret));
97+
byte[] serverApplicationTrafficSecret = HKDFunction.expandLabel(hkdfAlgortihm,
98+
tlsContext.getServerApplicationTrafficSecret(), HKDFunction.TRAFFICUPD, new byte[0],
99+
mac.getMacLength());
100+
101+
tlsContext.setServerApplicationTrafficSecret(serverApplicationTrafficSecret);
102+
LOGGER.debug("Set serverApplicationTrafficSecret in Context to "
103+
+ ArrayConverter.bytesToHexString(serverApplicationTrafficSecret));
104+
105+
}
109106

110107
} catch (NoSuchAlgorithmException | CryptoException ex) {
111108
throw new AdjustmentException(ex);
@@ -127,19 +124,26 @@ private KeySet getKeySet(TlsContext context, Tls13KeySetType keySetType) {
127124
private void setRecordCipher(Tls13KeySetType keySetType) {
128125
try {
129126
int AEAD_IV_LENGTH = 12;
127+
KeySet keySet;
130128
HKDFAlgorithm hkdfAlgortihm = AlgorithmResolver.getHKDFAlgorithm(tlsContext.getChooser()
131129
.getSelectedCipherSuite());
132130

133-
tlsContext.setActiveClientKeySetType(keySetType);
134-
LOGGER.debug("Setting cipher for client to use " + keySetType);
135-
KeySet keySet = getKeySet(tlsContext, tlsContext.getActiveClientKeySetType());
131+
if (tlsContext.getChooser().getTalkingConnectionEnd() == ConnectionEndType.CLIENT) {
136132

137-
if (tlsContext.getChooser().getTalkingConnectionEnd() == ConnectionEndType.CLIENT
138-
&& tlsContext.getChooser().getConnectionEndType() == ConnectionEndType.CLIENT
139-
|| tlsContext.getChooser().getTalkingConnectionEnd() == ConnectionEndType.SERVER
140-
&& tlsContext.getChooser().getConnectionEndType() == ConnectionEndType.SERVER) {
133+
tlsContext.setActiveClientKeySetType(keySetType);
134+
LOGGER.debug("Setting cipher for client to use " + keySetType);
135+
keySet = getKeySet(tlsContext, tlsContext.getActiveClientKeySetType());
136+
137+
} else {
138+
tlsContext.setActiveServerKeySetType(keySetType);
139+
LOGGER.debug("Setting cipher for server to use " + keySetType);
140+
keySet = getKeySet(tlsContext, tlsContext.getActiveServerKeySetType());
141+
}
142+
143+
if (tlsContext.getChooser().getTalkingConnectionEnd() == tlsContext.getChooser().getConnectionEndType()) {
141144

142145
if (tlsContext.getChooser().getConnectionEndType() == ConnectionEndType.CLIENT) {
146+
143147
keySet.setClientWriteIv(HKDFunction.expandLabel(hkdfAlgortihm,
144148
tlsContext.getClientApplicationTrafficSecret(), HKDFunction.IV, new byte[0], AEAD_IV_LENGTH));
145149

@@ -156,10 +160,8 @@ private void setRecordCipher(Tls13KeySetType keySetType) {
156160
AlgorithmResolver.getCipher(tlsContext.getChooser().getSelectedCipherSuite()).getKeySize()));
157161
}
158162

159-
} else if (tlsContext.getChooser().getTalkingConnectionEnd() == ConnectionEndType.SERVER
160-
&& tlsContext.getChooser().getConnectionEndType() == ConnectionEndType.CLIENT
161-
|| tlsContext.getChooser().getTalkingConnectionEnd() == ConnectionEndType.CLIENT
162-
&& tlsContext.getChooser().getConnectionEndType() == ConnectionEndType.SERVER) {
163+
} else if (tlsContext.getChooser().getTalkingConnectionEnd() != tlsContext.getChooser()
164+
.getConnectionEndType()) {
163165

164166
if (tlsContext.getChooser().getConnectionEndType() == ConnectionEndType.SERVER) {
165167

@@ -186,18 +188,11 @@ private void setRecordCipher(Tls13KeySetType keySetType) {
186188
.getChooser().getSelectedCipherSuite());
187189
tlsContext.getRecordLayer().setRecordCipher(recordCipherClient);
188190

189-
if (tlsContext.getChooser().getTalkingConnectionEnd() == ConnectionEndType.CLIENT
190-
&& tlsContext.getChooser().getConnectionEndType() == ConnectionEndType.CLIENT
191-
|| tlsContext.getChooser().getTalkingConnectionEnd() == ConnectionEndType.SERVER
192-
&& tlsContext.getChooser().getConnectionEndType() == ConnectionEndType.SERVER) {
193-
191+
if (tlsContext.getChooser().getTalkingConnectionEnd() == tlsContext.getChooser().getConnectionEndType()) {
194192
tlsContext.setWriteSequenceNumber(0);
195193
tlsContext.getRecordLayer().updateEncryptionCipher();
196-
} else if (tlsContext.getChooser().getTalkingConnectionEnd() == ConnectionEndType.SERVER
197-
&& tlsContext.getChooser().getConnectionEndType() == ConnectionEndType.CLIENT
198-
|| tlsContext.getChooser().getTalkingConnectionEnd() == ConnectionEndType.CLIENT
199-
&& tlsContext.getChooser().getConnectionEndType() == ConnectionEndType.SERVER) {
200-
194+
} else if (tlsContext.getChooser().getTalkingConnectionEnd() != tlsContext.getChooser()
195+
.getConnectionEndType()) {
201196
tlsContext.setReadSequenceNumber(0);
202197
tlsContext.getRecordLayer().updateDecryptionCipher();
203198
}

TLS-Core/src/main/java/de/rub/nds/tlsattacker/core/protocol/message/KeyUpdateMessage.java

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
*/
1010
package de.rub.nds.tlsattacker.core.protocol.message;
1111

12-
import de.rub.nds.modifiablevariable.HoldsModifiableVariable;
1312
import de.rub.nds.tlsattacker.core.config.Config;
1413
import de.rub.nds.tlsattacker.core.constants.HandshakeMessageType;
1514
import de.rub.nds.tlsattacker.core.constants.KeyUpdateRequest;
@@ -24,8 +23,7 @@ public class KeyUpdateMessage extends HandshakeMessage {
2423

2524
private static final Logger LOGGER = LogManager.getLogger();
2625

27-
@HoldsModifiableVariable
28-
private KeyUpdateRequest request_update;
26+
private KeyUpdateRequest requestUpdate;
2927

3028
@Override
3129
public ProtocolMessageHandler getHandler(TlsContext context) {
@@ -34,32 +32,28 @@ public ProtocolMessageHandler getHandler(TlsContext context) {
3432

3533
public KeyUpdateMessage() {
3634
super(HandshakeMessageType.KEY_UPDATE);
37-
this.request_update = KeyUpdateRequest.UPDATE_REQUESTED;
35+
this.setIncludeInDigest(false);
36+
this.requestUpdate = KeyUpdateRequest.UPDATE_NOT_REQUESTED;
3837
}
3938

4039
public KeyUpdateMessage(Config tlsConfig) {
4140
super(tlsConfig, HandshakeMessageType.KEY_UPDATE);
42-
this.request_update = KeyUpdateRequest.UPDATE_REQUESTED;
41+
this.requestUpdate = KeyUpdateRequest.UPDATE_NOT_REQUESTED;
42+
this.setIncludeInDigest(false);
4343
}
4444

45-
public KeyUpdateMessage(HandshakeMessageType handshakeMessageType, KeyUpdateRequest request_update) {
45+
public KeyUpdateMessage(HandshakeMessageType handshakeMessageType, KeyUpdateRequest requestUpdate) {
4646
super(handshakeMessageType);
47-
this.request_update = request_update;
48-
}
49-
50-
public void setRequestUpdate(int keyupdaterequest) {
51-
if (keyupdaterequest == 1) {
52-
request_update = KeyUpdateRequest.UPDATE_REQUESTED;
53-
} else
54-
request_update = KeyUpdateRequest.UPDATE_NOT_REQUESTED;
47+
this.requestUpdate = requestUpdate;
48+
this.setIncludeInDigest(false);
5549
}
5650

5751
public void setRequestUpdate(KeyUpdateRequest keyupdaterequest) {
58-
request_update = KeyUpdateRequest.UPDATE_REQUESTED;
52+
requestUpdate = keyupdaterequest;
5953
}
6054

6155
public KeyUpdateRequest getRequestUpdate() {
62-
return this.request_update;
56+
return this.requestUpdate;
6357
}
6458

6559
}

TLS-Core/src/main/java/de/rub/nds/tlsattacker/core/protocol/parser/KeyUpdateParser.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import org.apache.logging.log4j.LogManager;
1313
import org.apache.logging.log4j.Logger;
1414

15-
import de.rub.nds.modifiablevariable.util.ArrayConverter;
1615
import de.rub.nds.tlsattacker.core.config.Config;
1716
import de.rub.nds.tlsattacker.core.constants.HandshakeByteLength;
1817
import de.rub.nds.tlsattacker.core.constants.HandshakeMessageType;
@@ -39,8 +38,12 @@ protected KeyUpdateMessage createHandshakeMessage() {
3938
}
4039

4140
private void parseUpdateRequest(KeyUpdateMessage msg) {
42-
msg.setRequestUpdate(parseIntField(HandshakeByteLength.KEY_UPDATE_LENGTH));
43-
LOGGER.debug("KeyUpdateValue: " + msg.getRequestUpdate().getValue());
41+
42+
if (parseByteField(HandshakeByteLength.KEY_UPDATE_LENGTH) == KeyUpdateRequest.UPDATE_REQUESTED.getValue()) {
43+
msg.setRequestUpdate(KeyUpdateRequest.UPDATE_REQUESTED);
44+
} else
45+
msg.setRequestUpdate(KeyUpdateRequest.UPDATE_NOT_REQUESTED);
46+
LOGGER.debug("KeyUpdateValue: " + msg.getRequestUpdate());
4447

4548
}
4649

TLS-Core/src/main/java/de/rub/nds/tlsattacker/core/protocol/preparator/KeyUpdatePreparator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public KeyUpdatePreparator(Chooser chooser, KeyUpdateMessage message) {
2727

2828
@Override
2929
protected void prepareHandshakeMessageContents() {
30-
msg.setRequestUpdate(KeyUpdateRequest.UPDATE_NOT_REQUESTED);
30+
msg.setRequestUpdate(msg.getRequestUpdate());
3131
LOGGER.debug("Preparing KeyUpdate - MessageContent is: " + msg.getRequestUpdate());
3232
}
3333

TLS-Core/src/main/java/de/rub/nds/tlsattacker/core/protocol/serializer/KeyUpdateSerializer.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ public byte[] serializeHandshakeMessageContent() {
4444

4545
private void writeKeyUpdateData(KeyUpdateMessage msg) {
4646
appendByte(msg.getRequestUpdate().getValue());
47-
LOGGER.debug("Serialized KeyUpdate Data: " + msg.getRequestUpdate().getValue() + " ENUM Value: "
48-
+ msg.getRequestUpdate());
47+
LOGGER.debug("Serialized KeyUpdate Value: " + msg.getRequestUpdate());
4948
}
5049

5150
}

0 commit comments

Comments
 (0)