Skip to content

Commit 69501e0

Browse files
pfg666kostis
andauthored
Remove unnecessary methods from TlsInput (#170)
* Remove methods from TlsInput that are now unnecessary given the transition to generics. --------- Co-authored-by: Kostis Sagonas <kostis@it.uu.se>
1 parent 20bb29b commit 69501e0

13 files changed

Lines changed: 60 additions & 93 deletions

src/main/java/se/uu/it/dtlsfuzzer/components/sul/core/TlsSul.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ private void initializeTransportHandler() {
198198
try {
199199
var firstClientHello = transportHandler.fetchData();
200200
receivedClientHello = true;
201-
FirstCachedUdpLayer udpLayer = (FirstCachedUdpLayer) context.getState().getTlsContext().getLayerStack().getLowestLayer();
201+
FirstCachedUdpLayer udpLayer = (FirstCachedUdpLayer) context.getTlsContext().getLayerStack().getLowestLayer();
202202
udpLayer.setFirstClientHelo(firstClientHello);
203203
udpLayer.isFuzzingClient = true;
204204
} catch (SocketTimeoutException e) {

src/main/java/se/uu/it/dtlsfuzzer/components/sul/mapper/DtlsOutputMapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public DtlsOutputMapper(MapperConfig mapperConfig, TlsOutputBuilder outputBuilde
3131

3232
@Override
3333
public TlsOutput receiveOutput(TlsExecutionContext context) {
34-
TlsContext tlsContext = context.getState().getTlsContext();
34+
TlsContext tlsContext = context.getTlsContext();
3535
try {
3636
if (tlsContext.getTransportHandler().isClosed()) {
3737
return socketClosed();

src/main/java/se/uu/it/dtlsfuzzer/components/sul/mapper/TlsExecutionContext.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,4 @@ public Long getWriteRecordNumberEpoch0() {
126126
protected TlsStepContext buildStepContext() {
127127
return new TlsStepContext(stepContexts.size());
128128
}
129-
130-
/*
131-
public Long incrementWriteRecordNumberEpoch0() {
132-
Long old = writeRecordNumberEpoch0;
133-
writeRecordNumberEpoch0++;
134-
return old;
135-
}
136-
*/
137129
}

src/main/java/se/uu/it/dtlsfuzzer/components/sul/mapper/symbols/inputs/ChangeCipherSpecInput.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ public ChangeCipherSpecInput() {
1818

1919
@Override
2020
public void preSendDtlsUpdate(TlsExecutionContext context) {
21-
Encryptor encryptor = getState(context).getTlsContext().getRecordLayer().getEncryptor();
22-
int writeEpoch = getState(context).getTlsContext().getWriteEpoch();
21+
Encryptor encryptor = context.getTlsContext().getRecordLayer().getEncryptor();
22+
int writeEpoch = context.getTlsContext().getWriteEpoch();
2323
Long writeSeqNumForCurrentEpoch = encryptor.getRecordCipher(writeEpoch).getState().getWriteSequenceNumber();
2424
context.setWriteRecordNumberEpoch0(writeSeqNumForCurrentEpoch + 1);
2525
}
@@ -35,9 +35,9 @@ public void postSendDtlsUpdate(TlsExecutionContext context) {
3535
// TLS-Attacker instantiates non-null ciphers even when the pre-master secret has not been yet negotiated.
3636
// Here, we replace the ciphers instantiated in such cases by null ciphers.
3737
// This ensures that encrypted messages are more likely to make sense to the SUT.
38-
if (getTlsContext(context).getPreMasterSecret() == null) {
39-
makeNullCipherAsMostRecent(getTlsContext(context).getRecordLayer().getEncryptor(), getTlsContext(context));
40-
makeNullCipherAsMostRecent(getTlsContext(context).getRecordLayer().getDecryptor(), getTlsContext(context));
38+
if (context.getTlsContext().getPreMasterSecret() == null) {
39+
makeNullCipherAsMostRecent(context.getTlsContext().getRecordLayer().getEncryptor(), context.getTlsContext());
40+
makeNullCipherAsMostRecent(context.getTlsContext().getRecordLayer().getDecryptor(), context.getTlsContext());
4141
}
4242
}
4343

src/main/java/se/uu/it/dtlsfuzzer/components/sul/mapper/symbols/inputs/ClientHelloInput.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,25 +48,25 @@ public ClientHelloInput(CipherSuite cipherSuite) {
4848

4949
@Override
5050
public TlsProtocolMessage generateProtocolMessage(TlsExecutionContext context) {
51-
getConfig(context).setDefaultClientSupportedCipherSuites(Arrays.asList(suite));
51+
context.getConfig().setDefaultClientSupportedCipherSuites(Arrays.asList(suite));
5252
if (suite.name().contains("EC")) {
53-
getConfig(context).setAddECPointFormatExtension(true);
54-
getConfig(context).setAddEllipticCurveExtension(true);
53+
context.getConfig().setAddECPointFormatExtension(true);
54+
context.getConfig().setAddEllipticCurveExtension(true);
5555
} else {
56-
getConfig(context).setAddECPointFormatExtension(false);
57-
getConfig(context).setAddEllipticCurveExtension(false);
56+
context.getConfig().setAddECPointFormatExtension(false);
57+
context.getConfig().setAddEllipticCurveExtension(false);
5858
}
5959

60-
if(getConfig(context).getHighestProtocolVersion().isDTLS13()) {
60+
if (context.getConfig().getHighestProtocolVersion().isDTLS13()) {
6161
// aka supported_groups
62-
getConfig(context).setAddEllipticCurveExtension(true);
62+
context.getConfig().setAddEllipticCurveExtension(true);
6363
}
6464

6565
if (resetDigest) {
66-
getTlsContext(context).getDigest().reset();
66+
context.getTlsContext().getDigest().reset();
6767
}
6868

69-
ClientHelloMessage message = new ClientHelloMessage(getConfig(context));
69+
ClientHelloMessage message = new ClientHelloMessage(context.getConfig());
7070

7171
// we exclude the sessionId
7272
if (!withSessionId) {

src/main/java/se/uu/it/dtlsfuzzer/components/sul/mapper/symbols/inputs/ClientHelloRenegotiationInput.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,30 +41,30 @@ public boolean isEnabled(TlsExecutionContext context) {
4141
return switch (enabled) {
4242
case OWN_EPOCH_CHANGE ->
4343
// send epoch is 1 or more
44-
getTlsContext(context).getWriteEpoch() > 0;
44+
context.getTlsContext().getWriteEpoch() > 0;
4545
case SERVER_EPOCH_CHANGE ->
4646
// receive epoch is 1 or more
47-
getTlsContext(context).getReadEpoch() > 0;
47+
context.getTlsContext().getReadEpoch() > 0;
4848
case ONCE ->
49-
getTlsExecutionContext(context)
49+
context
5050
.getTlsStepContextStream()
51-
.noneMatch(s -> this.equals(s.getInput()) && s.getIndex() != getTlsExecutionContext(context).getStepCount() - 1);
51+
.noneMatch(s -> this.equals(s.getInput()) && s.getIndex() != context.getStepCount() - 1);
5252
default ->
5353
true;
5454
};
5555
}
5656

5757
@Override
5858
public TlsProtocolMessage generateProtocolMessage(TlsExecutionContext context) {
59-
getTlsContext(context).getDigest().reset();
59+
context.getTlsContext().getDigest().reset();
6060
if (resetMSeq) {
61-
getTlsContext(context).setWriteSequenceNumber(getTlsContext(context).getWriteEpoch(), 0);
61+
context.getTlsContext().setWriteSequenceNumber(context.getTlsContext().getWriteEpoch(), 0);
6262
}
63-
getTlsContext(context).setReadSequenceNumber(getTlsContext(context).getReadEpoch(), 0);
63+
context.getTlsContext().setReadSequenceNumber(context.getTlsContext().getReadEpoch(), 0);
6464
if (suite != null) {
65-
getConfig(context).setDefaultClientSupportedCipherSuites(suite);
65+
context.getConfig().setDefaultClientSupportedCipherSuites(suite);
6666
}
67-
ClientHelloMessage message = new ClientHelloMessage(getConfig(context));
67+
ClientHelloMessage message = new ClientHelloMessage(context.getConfig());
6868
if (!isShort) {
6969
ModifiableByteArray sbyte = new ModifiableByteArray();
7070
sbyte.setModification(new ByteArrayExplicitValueModification(
@@ -73,7 +73,7 @@ public TlsProtocolMessage generateProtocolMessage(TlsExecutionContext context) {
7373
}
7474

7575
// mbedtls will only engage in renegotiation if the cookie is empty
76-
if (!withCookie && getTlsContext(context).getDtlsCookie() != null) {
76+
if (!withCookie && context.getTlsContext().getDtlsCookie() != null) {
7777
ModifiableByteArray sbyte = new ModifiableByteArray();
7878
sbyte.setModification(new ByteArrayExplicitValueModification(
7979
new byte[] {}));
@@ -89,7 +89,7 @@ public void postReceiveUpdate(TlsOutput output, OutputChecker<TlsOutput> abstrac
8989
switch (enabled) {
9090
case ON_SERVER_HELLO:
9191
if (!TlsOutputChecker.hasServerHello(output)) {
92-
getTlsExecutionContext(context).disableExecution();
92+
context.disableExecution();
9393
}
9494
break;
9595
default:

src/main/java/se/uu/it/dtlsfuzzer/components/sul/mapper/symbols/inputs/ClientHelloWithSessionIdInput.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ private void resetTransportHandler(State state) {
4242
@Override
4343
public TlsProtocolMessage generateProtocolMessage(TlsExecutionContext context) {
4444
// reset and resume the connection
45-
resetTransportHandler(getState(context));
45+
resetTransportHandler(context.getState().getState());
4646
if (suite != null) {
47-
getConfig(context).setDefaultClientSupportedCipherSuites(suite);
47+
context.getConfig().setDefaultClientSupportedCipherSuites(suite);
4848
}
49-
ClientHelloMessage message = new ClientHelloMessage(getConfig(context));
50-
message.setSessionId(getTlsContext(context).getChooser()
49+
ClientHelloMessage message = new ClientHelloMessage(context.getConfig());
50+
message.setSessionId(context.getTlsContext().getChooser()
5151
.getServerSessionId());
5252

5353
return new TlsProtocolMessage(message);

src/main/java/se/uu/it/dtlsfuzzer/components/sul/mapper/symbols/inputs/ClientKeyExchangeInput.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public ClientKeyExchangeInput(KeyExchangeAlgorithm algorithm) {
3232

3333
@Override
3434
public TlsProtocolMessage generateProtocolMessage(TlsExecutionContext context) {
35-
getTlsContext(context).setPreMasterSecret(null);
35+
context.getTlsContext().setPreMasterSecret(null);
3636
if (algorithm == null) {
3737
throw new RuntimeException("Algorithm not set");
3838
}

src/main/java/se/uu/it/dtlsfuzzer/components/sul/mapper/symbols/inputs/DtlsInput.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import jakarta.xml.bind.annotation.XmlAttribute;
44
import org.apache.commons.lang3.NotImplementedException;
55
import se.uu.it.dtlsfuzzer.components.sul.mapper.TlsExecutionContext;
6-
import se.uu.it.dtlsfuzzer.components.sul.mapper.TlsState;
76

87
public abstract class DtlsInput extends TlsInput {
98

@@ -32,20 +31,18 @@ protected DtlsInput(String name) {
3231

3332
@Override
3433
public final void preSendUpdate(TlsExecutionContext context) {
35-
TlsState state = getTlsExecutionContext(context).getState();
36-
3734
// if different epoch than current, set the epoch in TLS context
38-
if (epoch != null && epoch != state.getTlsContext().getWriteEpoch()) {
39-
state.getTlsContext().setWriteEpoch(epoch);
40-
contextEpoch = state.getTlsContext().getWriteEpoch();
35+
if (epoch != null && epoch != context.getTlsContext().getWriteEpoch()) {
36+
context.getTlsContext().setWriteEpoch(epoch);
37+
contextEpoch = context.getTlsContext().getWriteEpoch();
4138
}
4239

4340
// if epoch > 0, deactivate encryption
4441
if (!encryptionEnabled) {
4542
throw new NotImplementedException("Disabling encryption is not currently supported.");
4643
}
4744

48-
preSendDtlsUpdate(getTlsExecutionContext(context));
45+
preSendDtlsUpdate(context);
4946
}
5047

5148
public void preSendDtlsUpdate(TlsExecutionContext context) {
@@ -55,15 +52,15 @@ public void preSendDtlsUpdate(TlsExecutionContext context) {
5552
public final void postSendUpdate(TlsExecutionContext context) {
5653
// reset epoch number and, if original epoch > 0, reactivate encryption
5754
if (contextEpoch != null) {
58-
getTlsExecutionContext(context).getState().getTlsContext().setWriteEpoch(contextEpoch);
55+
context.getTlsContext().setWriteEpoch(contextEpoch);
5956
contextEpoch = null;
6057
}
6158

6259
if (!encryptionEnabled) {
6360
throw new NotImplementedException("Re-enabling encryption is not currently supported.");
6461
}
6562

66-
postSendDtlsUpdate(getTlsExecutionContext(context));
63+
postSendDtlsUpdate(context);
6764
}
6865

6966
public void postSendDtlsUpdate(TlsExecutionContext context) {

src/main/java/se/uu/it/dtlsfuzzer/components/sul/mapper/symbols/inputs/FinishedInput.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,29 +24,29 @@ public TlsProtocolMessage generateProtocolMessage(TlsExecutionContext context) {
2424
// Uncomment line to print digest, TODO remove this when polishing things up
2525
// System.out.println(ArrayConverter.bytesToHexString(state.getTlsContext().getDigest().getRawBytes()));
2626
FinishedMessage message = new FinishedMessage();
27-
lastSequenceNumber = getTlsContext(context).getWriteSequenceNumber(getTlsContext(context).getWriteEpoch());
28-
// getTlsContext(context).setWriteEpoch(getTlsContext(context).getWriteEpoch() + 1);
29-
// getTlsContext(context).setWriteSequenceNumber(getTlsContext(context).getWriteEpoch(), 0L);
27+
lastSequenceNumber = context.getTlsContext().getWriteSequenceNumber(context.getTlsContext().getWriteEpoch());
28+
// context.getTlsContext().setWriteEpoch(context.getTlsContext().getWriteEpoch() + 1);
29+
// context.getTlsContext().setWriteSequenceNumber(context.getTlsContext().getWriteEpoch(), 0L);
3030
return new TlsProtocolMessage(message);
3131
}
3232

3333
@Override
3434
public void postSendDtlsUpdate(TlsExecutionContext context) {
35-
if (getTlsContext(context).getConfig().getHighestProtocolVersion().isDTLS13() && !getTlsContext(context).isDtls13ShouldSendFinished()){
35+
if (context.getTlsContext().getConfig().getHighestProtocolVersion().isDTLS13() && !context.getTlsContext().isDtls13ShouldSendFinished()){
3636
// invalid Finished message, we shouldn't care
3737
return;
3838
}
39-
getTlsContext(context).getDigest().reset();
39+
context.getTlsContext().getDigest().reset();
4040
// we have to make this change for learning to scale
41-
getTlsContext(context).setWriteSequenceNumber(getTlsContext(context).getWriteEpoch(), lastSequenceNumber + 1);
41+
context.getTlsContext().setWriteSequenceNumber(context.getTlsContext().getWriteEpoch(), lastSequenceNumber + 1);
4242
}
4343

4444
@Override
4545
public void postReceiveUpdate(TlsOutput output, OutputChecker<TlsOutput> abstractOutputChecker,
4646
TlsExecutionContext context) {
4747
if (resetMSeq) {
4848
if (TlsOutputChecker.hasChangeCipherSpec(output)) {
49-
getTlsContext(context).setWriteSequenceNumber(getTlsContext(context).getWriteEpoch(), 0);
49+
context.getTlsContext().setWriteSequenceNumber(context.getTlsContext().getWriteEpoch(), 0);
5050
}
5151
}
5252
super.postReceiveUpdate(output, abstractOutputChecker, context);

0 commit comments

Comments
 (0)