Skip to content

Commit f8fdf00

Browse files
authored
Merge branch 'master' into java-11-compatibility
2 parents 7d2feca + 0ca4581 commit f8fdf00

File tree

45 files changed

+1555
-382
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1555
-382
lines changed

Attacks/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>de.rub.nds.tlsattacker</groupId>
66
<artifactId>TLS-Attacker</artifactId>
7-
<version>3.5.0</version>
7+
<version>3.6.0</version>
88
</parent>
99
<artifactId>Attacks</artifactId>
1010
<packaging>jar</packaging>

Attacks/src/main/java/de/rub/nds/tlsattacker/attacks/config/InvalidCurveAttackConfig.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ public class InvalidCurveAttackConfig extends AttackConfig {
6060
@Parameter(names = "-protocol_flows", description = "Number of Protocol flows")
6161
private int protocolFlows = 15;
6262

63+
@Parameter(names = "-key_offset", description = "Offset of the first attempted secretkey")
64+
private int keyOffset = 0;
65+
6366
// These are for scanning only
6467
@Parameter(names = "-premaster_secret", description = "Premaster Secret String (use 0x at the beginning for a hex value)", hidden = true, converter = BigIntegerConverter.class)
6568
private BigInteger premasterSecret;
@@ -347,6 +350,7 @@ public Config createConfig() {
347350
config.setStopReceivingAfterFatal(true);
348351
config.setEarlyStop(true);
349352
config.setStopActionsAfterIOException(true);
353+
config.setStopTraceAfterUnexpected(true);
350354
config.setAddECPointFormatExtension(true);
351355
config.setAddEllipticCurveExtension(true);
352356
config.setAddServerNameIndicationExtension(true);
@@ -403,4 +407,12 @@ public boolean isAttackInRenegotiation() {
403407
public void setAttackInRenegotiation(boolean attackInRenegotiation) {
404408
this.attackInRenegotiation = attackInRenegotiation;
405409
}
410+
411+
public int getKeyOffset() {
412+
return keyOffset;
413+
}
414+
415+
public void setKeyOffset(int keyOffset) {
416+
this.keyOffset = keyOffset;
417+
}
406418
}

Attacks/src/main/java/de/rub/nds/tlsattacker/attacks/ec/InvalidCurvePoint.java

Lines changed: 265 additions & 68 deletions
Large diffs are not rendered by default.

Attacks/src/main/java/de/rub/nds/tlsattacker/attacks/ec/TwistedCurvePoint.java

Lines changed: 331 additions & 114 deletions
Large diffs are not rendered by default.

Attacks/src/main/java/de/rub/nds/tlsattacker/attacks/impl/InvalidCurveAttacker.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,9 @@ public Boolean isVulnerable() {
167167

168168
List<TlsTask> taskList = new LinkedList<>();
169169
for (int i = 1; i <= protocolFlows; i++) {
170-
setPremasterSecret(curve, i, point);
171-
InvalidCurveTask taskToAdd = new InvalidCurveTask(buildState(), executor.getReexecutions(), i);
170+
setPremasterSecret(curve, i + config.getKeyOffset(), point);
171+
InvalidCurveTask taskToAdd = new InvalidCurveTask(buildState(), executor.getReexecutions(), i
172+
+ config.getKeyOffset());
172173
taskList.add(taskToAdd);
173174
}
174175
executor.bulkExecuteTasks(taskList);

Attacks/src/main/java/de/rub/nds/tlsattacker/attacks/util/response/ResponseFingerprint.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ public boolean equals(Object obj) {
235235

236236
} else {
237237
// Comparing BlobRecords
238-
if (Arrays.equals(this.getRecordList().get(i).getCompleteRecordBytes().getValue(), other
238+
if (!Arrays.equals(this.getRecordList().get(i).getCompleteRecordBytes().getValue(), other
239239
.getRecordList().get(i).getCompleteRecordBytes().getValue())) {
240240
return false;
241241
}
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/**
2+
* TLS-Attacker - A Modular Penetration Testing Framework for TLS
3+
*
4+
* Copyright 2014-2020 Ruhr University Bochum, Paderborn University,
5+
* and Hackmanit GmbH
6+
*
7+
* Licensed under Apache License 2.0
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*/
10+
package de.rub.nds.tlsattacker.attacks.ec;
11+
12+
import de.rub.nds.tlsattacker.core.constants.NamedGroup;
13+
import de.rub.nds.tlsattacker.core.crypto.ec.CurveFactory;
14+
import de.rub.nds.tlsattacker.core.crypto.ec.EllipticCurve;
15+
import de.rub.nds.tlsattacker.core.crypto.ec.FieldElementFp;
16+
import de.rub.nds.tlsattacker.core.crypto.ec.Point;
17+
import java.math.BigInteger;
18+
import java.util.ArrayList;
19+
import java.util.Arrays;
20+
import java.util.List;
21+
import org.junit.After;
22+
import org.junit.AfterClass;
23+
import org.junit.Before;
24+
import org.junit.BeforeClass;
25+
import org.junit.Test;
26+
import static org.junit.Assert.*;
27+
28+
public class InvalidCurvePointTest {
29+
30+
public InvalidCurvePointTest() {
31+
}
32+
33+
/**
34+
* Test points of small order.
35+
*/
36+
@Test
37+
public void testSmallOrder() {
38+
List<NamedGroup> knownGroups = new ArrayList<>(Arrays.asList(NamedGroup.values()));
39+
for (NamedGroup group : knownGroups) {
40+
assertTrue(pointsForGroupAreOrdered(group));
41+
InvalidCurvePoint invP = InvalidCurvePoint.smallOrder(group);
42+
if (invP != null) {
43+
assertEquals(group, invP.getNamedGroup());
44+
assertTrue(isOrderCorrect(invP));
45+
}
46+
}
47+
}
48+
49+
/**
50+
* Test points of alternative order.
51+
*/
52+
@Test
53+
public void testAlternativeOrder() {
54+
List<NamedGroup> knownGroups = new ArrayList<>(Arrays.asList(NamedGroup.values()));
55+
for (NamedGroup group : knownGroups) {
56+
assertTrue(pointsForGroupAreOrdered(group));
57+
InvalidCurvePoint invP = InvalidCurvePoint.alternativeOrder(group);
58+
if (invP != null) {
59+
assertEquals(group, invP.getNamedGroup());
60+
assertTrue(isOrderCorrect(invP));
61+
}
62+
}
63+
}
64+
65+
/**
66+
* Test points of large order.
67+
*/
68+
@Test
69+
public void testLargeOrder() {
70+
List<NamedGroup> knownGroups = new ArrayList<>(Arrays.asList(NamedGroup.values()));
71+
for (NamedGroup group : knownGroups) {
72+
assertTrue(pointsForGroupAreOrdered(group));
73+
InvalidCurvePoint invP = InvalidCurvePoint.largeOrder(group);
74+
if (invP != null) {
75+
assertEquals(group, invP.getNamedGroup());
76+
assertTrue(isOrderCorrect(invP));
77+
}
78+
}
79+
}
80+
81+
private boolean isOrderCorrect(InvalidCurvePoint invP) {
82+
EllipticCurve curve = CurveFactory.getCurve(invP.getNamedGroup());
83+
FieldElementFp bX = new FieldElementFp(invP.getPublicPointBaseX(), curve.getModulus());
84+
FieldElementFp bY = new FieldElementFp(invP.getPublicPointBaseY(), curve.getModulus());
85+
Point point = new Point(bX, bY);
86+
87+
if (invP.getOrder().isProbablePrime(100)) {
88+
Point res = curve.mult(invP.getOrder(), point);
89+
return res.isAtInfinity();
90+
} else {
91+
for (int i = 1; i <= invP.getOrder().intValue(); i++) {
92+
Point res = curve.mult(BigInteger.valueOf(i), point);
93+
if (res.isAtInfinity()) {
94+
return i == invP.getOrder().intValue();
95+
}
96+
}
97+
}
98+
return false;
99+
}
100+
101+
private boolean pointsForGroupAreOrdered(NamedGroup group) {
102+
InvalidCurvePoint invP1 = InvalidCurvePoint.smallOrder(group);
103+
InvalidCurvePoint invP2 = InvalidCurvePoint.alternativeOrder(group);
104+
InvalidCurvePoint invP3 = InvalidCurvePoint.largeOrder(group);
105+
106+
if (invP1 == null && (invP2 != null || invP3 != null)) {
107+
return false;
108+
} else if (invP2 == null && invP3 != null) {
109+
return false;
110+
} else if (invP2 != null && invP1.getOrder().compareTo(invP2.getOrder()) >= 0) {
111+
return false;
112+
} else if (invP3 != null && invP2 != null && invP2.getOrder().compareTo(invP3.getOrder()) >= 0) {
113+
return false;
114+
}
115+
return true;
116+
}
117+
118+
}
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
/**
2+
* TLS-Attacker - A Modular Penetration Testing Framework for TLS
3+
*
4+
* Copyright 2014-2020 Ruhr University Bochum, Paderborn University,
5+
* and Hackmanit GmbH
6+
*
7+
* Licensed under Apache License 2.0
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*/
10+
package de.rub.nds.tlsattacker.attacks.ec;
11+
12+
import de.rub.nds.tlsattacker.core.constants.NamedGroup;
13+
import de.rub.nds.tlsattacker.core.crypto.ec.CurveFactory;
14+
import de.rub.nds.tlsattacker.core.crypto.ec.EllipticCurve;
15+
import de.rub.nds.tlsattacker.core.crypto.ec.EllipticCurveOverFp;
16+
import de.rub.nds.tlsattacker.core.crypto.ec.FieldElementFp;
17+
import de.rub.nds.tlsattacker.core.crypto.ec.Point;
18+
import de.rub.nds.tlsattacker.core.crypto.ec.RFC7748Curve;
19+
import java.math.BigInteger;
20+
import java.util.ArrayList;
21+
import java.util.Arrays;
22+
import java.util.List;
23+
import org.junit.Test;
24+
import static org.junit.Assert.*;
25+
26+
public class TwistedCurvePointTest {
27+
28+
public TwistedCurvePointTest() {
29+
}
30+
31+
@Test
32+
public void testSmallOrder() {
33+
List<NamedGroup> knownGroups = new ArrayList<>(Arrays.asList(NamedGroup.values()));
34+
for (NamedGroup group : knownGroups) {
35+
assertTrue(pointsForGroupAreOrdered(group));
36+
TwistedCurvePoint invP = TwistedCurvePoint.smallOrder(group);
37+
if (invP != null) {
38+
assertEquals(group, invP.getIntendedNamedGroup());
39+
assertTrue(isOrderCorrect(invP));
40+
}
41+
}
42+
}
43+
44+
@Test
45+
public void testAlternativeOrder() {
46+
List<NamedGroup> knownGroups = new ArrayList<>(Arrays.asList(NamedGroup.values()));
47+
for (NamedGroup group : knownGroups) {
48+
assertTrue(pointsForGroupAreOrdered(group));
49+
TwistedCurvePoint invP = TwistedCurvePoint.alternativeOrder(group);
50+
if (invP != null) {
51+
assertEquals(group, invP.getIntendedNamedGroup());
52+
assertTrue(isOrderCorrect(invP));
53+
}
54+
}
55+
}
56+
57+
@Test
58+
public void testLargeOrder() {
59+
List<NamedGroup> knownGroups = new ArrayList<>(Arrays.asList(NamedGroup.values()));
60+
for (NamedGroup group : knownGroups) {
61+
assertTrue(pointsForGroupAreOrdered(group));
62+
TwistedCurvePoint invP = TwistedCurvePoint.largeOrder(group);
63+
if (invP != null) {
64+
assertEquals(group, invP.getIntendedNamedGroup());
65+
assertTrue(isOrderCorrect(invP));
66+
}
67+
}
68+
}
69+
70+
private boolean isOrderCorrect(TwistedCurvePoint invP) {
71+
if (invP.getIntendedNamedGroup() == NamedGroup.ECDH_X25519
72+
|| invP.getIntendedNamedGroup() == NamedGroup.ECDH_X448) {
73+
RFC7748Curve rfcCurve = (RFC7748Curve) CurveFactory.getCurve(invP.getIntendedNamedGroup());
74+
Point montgPoint = rfcCurve.getPoint(invP.getPublicPointBaseX(), invP.getPublicPointBaseY());
75+
Point weierPoint = rfcCurve.toWeierstrass(montgPoint);
76+
BigInteger transformedX = weierPoint.getX().getData().multiply(invP.getD()).mod(rfcCurve.getModulus());
77+
78+
EllipticCurveOverFp intendedCurve = ((RFC7748Curve) CurveFactory.getCurve(invP.getIntendedNamedGroup()))
79+
.getWeierstrassEquivalent();
80+
BigInteger modA = intendedCurve.getA().getData().multiply(invP.getD().pow(2))
81+
.mod(intendedCurve.getModulus());
82+
BigInteger modB = intendedCurve.getB().getData().multiply(invP.getD().pow(3))
83+
.mod(intendedCurve.getModulus());
84+
EllipticCurveOverFp twistedCurve = new EllipticCurveOverFp(modA, modB, intendedCurve.getModulus());
85+
Point point = Point.createPoint(transformedX, invP.getPublicPointBaseY(), invP.getIntendedNamedGroup());
86+
87+
for (long i = 1; i <= invP.getOrder().longValue(); i++) {
88+
Point res = twistedCurve.mult(BigInteger.valueOf(i), point);
89+
if (res.isAtInfinity()) {
90+
return i == invP.getOrder().intValue();
91+
}
92+
}
93+
} else {
94+
EllipticCurveOverFp intendedCurve = (EllipticCurveOverFp) CurveFactory.getCurve(invP
95+
.getIntendedNamedGroup());
96+
BigInteger modA = intendedCurve.getA().getData().multiply(invP.getD().pow(2))
97+
.mod(intendedCurve.getModulus());
98+
BigInteger modB = intendedCurve.getB().getData().multiply(invP.getD().pow(3))
99+
.mod(intendedCurve.getModulus());
100+
EllipticCurveOverFp twistedCurve = new EllipticCurveOverFp(modA, modB, intendedCurve.getModulus());
101+
102+
BigInteger modX = invP.getPublicPointBaseX().multiply(invP.getD()).mod(twistedCurve.getModulus());
103+
FieldElementFp bX = new FieldElementFp(modX, twistedCurve.getModulus());
104+
FieldElementFp bY = new FieldElementFp(invP.getPublicPointBaseY(), twistedCurve.getModulus());
105+
Point point = new Point(bX, bY);
106+
107+
if (invP.getOrder().isProbablePrime(100)) {
108+
Point res = twistedCurve.mult(invP.getOrder(), point);
109+
return res.isAtInfinity();
110+
} else {
111+
for (long i = 1; i <= invP.getOrder().longValue(); i++) {
112+
Point res = twistedCurve.mult(BigInteger.valueOf(i), point);
113+
if (res.isAtInfinity()) {
114+
return i == invP.getOrder().intValue();
115+
}
116+
}
117+
}
118+
}
119+
return false;
120+
}
121+
122+
private boolean pointsForGroupAreOrdered(NamedGroup group) {
123+
TwistedCurvePoint invP1 = TwistedCurvePoint.smallOrder(group);
124+
TwistedCurvePoint invP2 = TwistedCurvePoint.alternativeOrder(group);
125+
TwistedCurvePoint invP3 = TwistedCurvePoint.largeOrder(group);
126+
127+
if (invP1 == null && (invP2 != null || invP3 != null)) {
128+
return false;
129+
} else if (invP2 == null && invP3 != null) {
130+
return false;
131+
} else if (invP2 != null && invP1.getOrder().compareTo(invP2.getOrder()) >= 0) {
132+
return false;
133+
} else if (invP3 != null && invP2 != null && invP2.getOrder().compareTo(invP3.getOrder()) >= 0) {
134+
return false;
135+
}
136+
return true;
137+
}
138+
139+
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# TLS-Attacker
22

3-
[![release](https://img.shields.io/badge/Release-v3.4.0-blue.svg)](https://github.com/RUB-NDS/TLS-Attacker/releases)
3+
[![release](https://img.shields.io/badge/Release-v3.6.0-blue.svg)](https://github.com/RUB-NDS/TLS-Attacker/releases)
44
![licence](https://img.shields.io/badge/License-Apachev2-brightgreen.svg)
55
[![travis](https://travis-ci.org/RUB-NDS/TLS-Attacker.svg?branch=master)](https://travis-ci.org/RUB-NDS/TLS-Attacker)
66

TLS-Client/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>de.rub.nds.tlsattacker</groupId>
66
<artifactId>TLS-Attacker</artifactId>
7-
<version>3.5.0</version>
7+
<version>3.6.0</version>
88
</parent>
99
<name>TLS-Client</name>
1010
<artifactId>TLS-Client</artifactId>

0 commit comments

Comments
 (0)