Skip to content

Commit 6ab9a5e

Browse files
authored
Merge pull request #666 from RUB-NDS/fuzzerfixes
Fuzzer fixes. Fixed also TLS 1.3 code
2 parents 07564fe + e6c518f commit 6ab9a5e

File tree

47 files changed

+396
-225
lines changed

Some content is hidden

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

47 files changed

+396
-225
lines changed

TLS-Core/src/main/java/de/rub/nds/tlsattacker/core/certificate/CertificateByteChooser.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,10 @@ public CertificateKeyPair chooseCertificateKeyPair(Chooser chooser) {
167167
} else {
168168
KeyExchangeAlgorithm keyExchangeAlgorithm = AlgorithmResolver.getKeyExchangeAlgorithm(chooser
169169
.getSelectedCipherSuite());
170+
if (keyExchangeAlgorithm == null) {
171+
LOGGER.warn("CipherSuite does not specify a certificate kex. Using RSA.");
172+
keyExchangeAlgorithm = KeyExchangeAlgorithm.RSA;
173+
}
170174
switch (keyExchangeAlgorithm) {
171175
case DH_RSA:
172176
case DHE_RSA:

TLS-Core/src/main/java/de/rub/nds/tlsattacker/core/config/Config.java

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import de.rub.nds.tlsattacker.core.certificate.CertificateKeyPair;
1616
import de.rub.nds.tlsattacker.core.connection.InboundConnection;
1717
import de.rub.nds.tlsattacker.core.connection.OutboundConnection;
18+
import de.rub.nds.tlsattacker.core.constants.AlertDescription;
19+
import de.rub.nds.tlsattacker.core.constants.AlertLevel;
1820
import de.rub.nds.tlsattacker.core.constants.AuthzDataFormat;
1921
import de.rub.nds.tlsattacker.core.constants.CertificateKeyType;
2022
import de.rub.nds.tlsattacker.core.constants.CertificateStatusRequestType;
@@ -27,6 +29,7 @@
2729
import de.rub.nds.tlsattacker.core.constants.ECPointFormat;
2830
import de.rub.nds.tlsattacker.core.constants.EsniDnsKeyRecordVersion;
2931
import de.rub.nds.tlsattacker.core.constants.EsniVersion;
32+
import de.rub.nds.tlsattacker.core.constants.ExtensionType;
3033
import de.rub.nds.tlsattacker.core.constants.GOSTCurve;
3134
import de.rub.nds.tlsattacker.core.constants.HashAlgorithm;
3235
import de.rub.nds.tlsattacker.core.constants.HeartbeatMode;
@@ -514,7 +517,7 @@ public static Config createEmptyConfig() {
514517
*/
515518
private Boolean addSessionTicketTLSExtension = false;
516519

517-
/***
520+
/**
518521
* If we generate ClientHello with extended Random Extension
519522
*/
520523
private Boolean addExtendedRandomExtension = false;
@@ -921,9 +924,9 @@ public static Config createEmptyConfig() {
921924

922925
private PRFAlgorithm defaultPRFAlgorithm = PRFAlgorithm.TLS_PRF_LEGACY;
923926

924-
private Byte defaultAlertDescription = 0;
927+
private AlertDescription defaultAlertDescription = AlertDescription.CLOSE_NOTIFY;
925928

926-
private Byte defaultAlertLevel = 0;
929+
private AlertLevel defaultAlertLevel = AlertLevel.WARNING;
927930

928931
private NamedGroup defaultEcCertificateCurve = NamedGroup.SECP256R1;
929932

@@ -1107,7 +1110,7 @@ public static Config createEmptyConfig() {
11071110
/**
11081111
* Min iterations for finding the PWD password element
11091112
*/
1110-
private int defaultPWDIterations = 40;
1113+
private Integer defaultPWDIterations = 40;
11111114

11121115
@XmlJavaTypeAdapter(UnformattedByteArrayAdapter.class)
11131116
private byte[] defaultServerPWDPrivate = ArrayConverter
@@ -1184,16 +1187,17 @@ public static Config createEmptyConfig() {
11841187

11851188
private List<CipherSuite> defaultEsniServerCiphersuites = new LinkedList();
11861189

1187-
private int defaultEsniPaddedLength = 260;
1190+
private Integer defaultEsniPaddedLength = 260;
11881191

11891192
private Long defaultEsniNotBefore = 1582655135231L;
11901193

11911194
private Long defaultEsniNotAfter = 1582655135231L + 2592000000L;
11921195

1193-
private List<ExtensionMessage> defaultEsniExtensions = new LinkedList();
1194-
private boolean acceptOnlyFittingDtlsFragments = false;
1196+
private List<ExtensionType> defaultEsniExtensions = new LinkedList();
1197+
1198+
private Boolean acceptOnlyFittingDtlsFragments = false;
11951199

1196-
private boolean acceptContentRewritingDtlsFragments = true;
1200+
private Boolean acceptContentRewritingDtlsFragments = true;
11971201

11981202
private boolean writeKeylogFile = false;
11991203

@@ -1303,19 +1307,19 @@ public static Config createEmptyConfig() {
13031307
}
13041308
}
13051309

1306-
public boolean isAcceptOnlyFittingDtlsFragments() {
1310+
public Boolean isAcceptOnlyFittingDtlsFragments() {
13071311
return acceptOnlyFittingDtlsFragments;
13081312
}
13091313

1310-
public void setAcceptOnlyFittingDtlsFragments(boolean acceptOnlyFittingDtlsFragments) {
1314+
public void setAcceptOnlyFittingDtlsFragments(Boolean acceptOnlyFittingDtlsFragments) {
13111315
this.acceptOnlyFittingDtlsFragments = acceptOnlyFittingDtlsFragments;
13121316
}
13131317

1314-
public boolean isAcceptContentRewritingDtlsFragments() {
1318+
public Boolean isAcceptContentRewritingDtlsFragments() {
13151319
return acceptContentRewritingDtlsFragments;
13161320
}
13171321

1318-
public void setAcceptContentRewritingDtlsFragments(boolean acceptContentRewritingDtlsFragments) {
1322+
public void setAcceptContentRewritingDtlsFragments(Boolean acceptContentRewritingDtlsFragments) {
13191323
this.acceptContentRewritingDtlsFragments = acceptContentRewritingDtlsFragments;
13201324
}
13211325

@@ -1770,19 +1774,19 @@ public void setDefaultServerEcPublicKey(Point defaultServerEcPublicKey) {
17701774
this.defaultServerEcPublicKey = defaultServerEcPublicKey;
17711775
}
17721776

1773-
public byte getDefaultAlertDescription() {
1777+
public AlertDescription getDefaultAlertDescription() {
17741778
return defaultAlertDescription;
17751779
}
17761780

1777-
public void setDefaultAlertDescription(byte defaultAlertDescription) {
1781+
public void setDefaultAlertDescription(AlertDescription defaultAlertDescription) {
17781782
this.defaultAlertDescription = defaultAlertDescription;
17791783
}
17801784

1781-
public byte getDefaultAlertLevel() {
1785+
public AlertLevel getDefaultAlertLevel() {
17821786
return defaultAlertLevel;
17831787
}
17841788

1785-
public void setDefaultAlertLevel(byte defaultAlertLevel) {
1789+
public void setDefaultAlertLevel(AlertLevel defaultAlertLevel) {
17861790
this.defaultAlertLevel = defaultAlertLevel;
17871791
}
17881792

@@ -3420,11 +3424,11 @@ public void setDefaultPWDPassword(String password) {
34203424
this.defaultPWDPassword = password;
34213425
}
34223426

3423-
public int getDefaultPWDIterations() {
3427+
public Integer getDefaultPWDIterations() {
34243428
return defaultPWDIterations;
34253429
}
34263430

3427-
public void setDefaultPWDIterations(int defaultPWDIterations) {
3431+
public void setDefaultPWDIterations(Integer defaultPWDIterations) {
34283432
this.defaultPWDIterations = defaultPWDIterations;
34293433
}
34303434

@@ -3600,11 +3604,11 @@ public void setDefaultEsniServerCiphersuites(List<CipherSuite> defaultEsniServer
36003604
this.defaultEsniServerCiphersuites = defaultEsniServerCiphersuites;
36013605
}
36023606

3603-
public int getDefaultEsniPaddedLength() {
3607+
public Integer getDefaultEsniPaddedLength() {
36043608
return defaultEsniPaddedLength;
36053609
}
36063610

3607-
public void setDefaultEsniPaddedLength(int defaultEsniPaddedLength) {
3611+
public void setDefaultEsniPaddedLength(Integer defaultEsniPaddedLength) {
36083612
this.defaultEsniPaddedLength = defaultEsniPaddedLength;
36093613
}
36103614

@@ -3624,11 +3628,11 @@ public void setDefaultEsniNotAfter(Long defaultEsniNotAfter) {
36243628
this.defaultEsniNotAfter = defaultEsniNotAfter;
36253629
}
36263630

3627-
public List<ExtensionMessage> getDefaultEsniExtensions() {
3631+
public List<ExtensionType> getDefaultEsniExtensions() {
36283632
return defaultEsniExtensions;
36293633
}
36303634

3631-
public void setDefaultEsniExtensions(List<ExtensionMessage> defaultEsniExtensions) {
3635+
public void setDefaultEsniExtensions(List<ExtensionType> defaultEsniExtensions) {
36323636
this.defaultEsniExtensions = defaultEsniExtensions;
36333637
}
36343638

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,26 @@ public static List<CipherSuite> getEsniImplemented() {
10031003
return list;
10041004
}
10051005

1006+
public static List<CipherSuite> getTls13CipherSuites() {
1007+
List<CipherSuite> list = new LinkedList();
1008+
list.add(CipherSuite.TLS_AES_128_GCM_SHA256);
1009+
list.add(CipherSuite.TLS_AES_256_GCM_SHA384);
1010+
list.add(CipherSuite.TLS_CHACHA20_POLY1305_SHA256);
1011+
list.add(CipherSuite.TLS_AES_128_CCM_SHA256);
1012+
list.add(CipherSuite.TLS_AES_128_CCM_8_SHA256);
1013+
return list;
1014+
}
1015+
1016+
public static List<CipherSuite> getImplementedTls13CipherSuites() {
1017+
List<CipherSuite> list = new LinkedList();
1018+
list.add(CipherSuite.TLS_AES_128_GCM_SHA256);
1019+
list.add(CipherSuite.TLS_AES_256_GCM_SHA384);
1020+
list.add(CipherSuite.TLS_CHACHA20_POLY1305_SHA256);
1021+
list.add(CipherSuite.TLS_AES_128_CCM_SHA256);
1022+
list.add(CipherSuite.TLS_AES_128_CCM_8_SHA256);
1023+
return list;
1024+
}
1025+
10061026
public static List<CipherSuite> getNotImplemented() {
10071027
List<CipherSuite> notImplemented = new LinkedList<>();
10081028
for (CipherSuite suite : values()) {

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,23 @@ public static List<? extends SignatureAndHashAlgorithm> getImplemented() {
102102
return algoList;
103103
}
104104

105+
public static List<SignatureAndHashAlgorithm> getTls13SignatureAndHashAlgorithms() {
106+
List<SignatureAndHashAlgorithm> algos = new LinkedList<>();
107+
algos.add(SignatureAndHashAlgorithm.RSA_SHA256);
108+
algos.add(SignatureAndHashAlgorithm.RSA_SHA384);
109+
algos.add(SignatureAndHashAlgorithm.RSA_SHA512);
110+
algos.add(SignatureAndHashAlgorithm.ECDSA_SHA256);
111+
algos.add(SignatureAndHashAlgorithm.ECDSA_SHA384);
112+
algos.add(SignatureAndHashAlgorithm.ECDSA_SHA512);
113+
algos.add(SignatureAndHashAlgorithm.RSA_PSS_PSS_SHA256);
114+
algos.add(SignatureAndHashAlgorithm.RSA_PSS_PSS_SHA384);
115+
algos.add(SignatureAndHashAlgorithm.RSA_PSS_PSS_SHA512);
116+
algos.add(SignatureAndHashAlgorithm.RSA_PSS_RSAE_SHA256);
117+
algos.add(SignatureAndHashAlgorithm.RSA_PSS_RSAE_SHA384);
118+
algos.add(SignatureAndHashAlgorithm.RSA_PSS_RSAE_SHA512);
119+
return algos;
120+
}
121+
105122
private int value;
106123

107124
private static final Map<Integer, SignatureAndHashAlgorithm> MAP;
@@ -306,8 +323,9 @@ public static SignatureAndHashAlgorithm forCertificateKeyPair(CertificateKeyPair
306323
break;
307324
}
308325

309-
if (found)
326+
if (found) {
310327
break;
328+
}
311329
}
312330

313331
if (sigHashAlgo == null) {

TLS-Core/src/main/java/de/rub/nds/tlsattacker/core/crypto/PseudoRandomFunction.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@ public class PseudoRandomFunction {
8080
*/
8181
public static byte[] compute(PRFAlgorithm prfAlgorithm, byte[] secret, String label, byte[] seed, int size)
8282
throws CryptoException {
83-
83+
if (prfAlgorithm == null) {
84+
LOGGER.warn("Trying to compute PRF without specified PRF algorithm. Using TLS 1.0/TLS 1.1 as default.");
85+
prfAlgorithm = PRFAlgorithm.TLS_PRF_LEGACY;
86+
}
8487
switch (prfAlgorithm) {
8588
case TLS_PRF_SHA256:
8689
case TLS_PRF_SHA384:

TLS-Core/src/main/java/de/rub/nds/tlsattacker/core/crypto/cipher/ChaCha20Poly1305Cipher.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,19 @@ public class ChaCha20Poly1305Cipher implements EncryptionCipher, DecryptionCiphe
3939
private final Poly1305 mac = new Poly1305();
4040

4141
public ChaCha20Poly1305Cipher(byte[] key) {
42+
if (key.length != 32) {
43+
LOGGER.warn("Key for ChaCha20Poly1305 has wrong size. Expected 32 byte but found: " + key.length
44+
+ ". Padding/Trimming to 32 Byte.");
45+
if (key.length > 32) {
46+
key = Arrays.copyOfRange(key, 0, 32);
47+
} else {
48+
byte[] tempKey = new byte[32];
49+
for (int i = 0; i < key.length; i++) {
50+
tempKey[i] = key[i];
51+
}
52+
key = tempKey;
53+
}
54+
}
4255
this.key = key;
4356
}
4457

TLS-Core/src/main/java/de/rub/nds/tlsattacker/core/crypto/cipher/JavaCipher.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public byte[] encrypt(byte[] iv, byte[] someBytes) throws CryptoException {
5252
byte[] result = cipher.doFinal(someBytes);
5353
this.iv = cipher.getIV();
5454
return result;
55-
} catch (IllegalBlockSizeException | BadPaddingException | NoSuchAlgorithmException
55+
} catch (IllegalStateException | IllegalBlockSizeException | BadPaddingException | NoSuchAlgorithmException
5656
| InvalidAlgorithmParameterException | InvalidKeyException | NoSuchPaddingException ex) {
5757
throw new CryptoException("Could not initialize JavaCipher. "
5858
+ "Did you forget to use UnlimitedStrengthEnabler/add BouncyCastleProvider?", ex);
@@ -68,8 +68,8 @@ public byte[] encrypt(byte[] someBytes) throws CryptoException {
6868
cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(key, keySpecAlgorithm));
6969
}
7070
return cipher.doFinal(someBytes);
71-
} catch (IllegalBlockSizeException | BadPaddingException | NoSuchAlgorithmException | InvalidKeyException
72-
| NoSuchPaddingException ex) {
71+
} catch (IllegalStateException | IllegalBlockSizeException | BadPaddingException | NoSuchAlgorithmException
72+
| InvalidKeyException | NoSuchPaddingException ex) {
7373
throw new CryptoException("Could not encrypt data", ex);
7474
}
7575
}
@@ -84,7 +84,7 @@ public byte[] encrypt(byte[] iv, int tagLength, byte[] someBytes) throws CryptoE
8484
byte[] result = cipher.doFinal(someBytes);
8585
this.iv = cipher.getIV();
8686
return result;
87-
} catch (IllegalBlockSizeException | BadPaddingException | NoSuchAlgorithmException
87+
} catch (IllegalStateException | IllegalBlockSizeException | BadPaddingException | NoSuchAlgorithmException
8888
| InvalidAlgorithmParameterException | InvalidKeyException | NoSuchPaddingException ex) {
8989
throw new CryptoException("Could not encrypt data", ex);
9090
}
@@ -103,7 +103,7 @@ public byte[] encrypt(byte[] iv, int tagLength, byte[] additionAuthenticatedData
103103
byte[] result = cipher.doFinal(someBytes);
104104
this.iv = cipher.getIV();
105105
return result;
106-
} catch (IllegalBlockSizeException | BadPaddingException | NoSuchAlgorithmException
106+
} catch (IllegalStateException | IllegalBlockSizeException | BadPaddingException | NoSuchAlgorithmException
107107
| InvalidAlgorithmParameterException | InvalidKeyException | NoSuchPaddingException ex) {
108108
throw new CryptoException("Could not enrypt data", ex);
109109
}
@@ -132,7 +132,7 @@ public byte[] decrypt(byte[] iv, byte[] someBytes) throws CryptoException {
132132
System.arraycopy(someBytes, someBytes.length - getBlocksize(), this.iv, 0, getBlocksize());
133133
}
134134
return result;
135-
} catch (IllegalBlockSizeException | BadPaddingException | NoSuchAlgorithmException
135+
} catch (IllegalStateException | IllegalBlockSizeException | BadPaddingException | NoSuchAlgorithmException
136136
| InvalidAlgorithmParameterException | InvalidKeyException | NoSuchPaddingException ex) {
137137
throw new CryptoException("Could not decrypt data", ex);
138138
}
@@ -148,8 +148,8 @@ public byte[] decrypt(byte[] someBytes) throws CryptoException {
148148
}
149149
byte[] result = cipher.doFinal(someBytes);
150150
return result;
151-
} catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | IllegalBlockSizeException
152-
| BadPaddingException ex) {
151+
} catch (IllegalStateException | NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException
152+
| IllegalBlockSizeException | BadPaddingException ex) {
153153
throw new CryptoException("Could not decrypt data", ex);
154154
}
155155
}
@@ -167,7 +167,7 @@ public byte[] decrypt(byte[] iv, int tagLength, byte[] someBytes) throws CryptoE
167167
System.arraycopy(someBytes, someBytes.length - getBlocksize(), this.iv, 0, getBlocksize());
168168
}
169169
return result;
170-
} catch (IllegalBlockSizeException | BadPaddingException | NoSuchAlgorithmException
170+
} catch (IllegalStateException | IllegalBlockSizeException | BadPaddingException | NoSuchAlgorithmException
171171
| InvalidAlgorithmParameterException | InvalidKeyException | NoSuchPaddingException ex) {
172172
throw new CryptoException("Could not decrypt data", ex);
173173
}
@@ -188,7 +188,7 @@ public byte[] decrypt(byte[] iv, int tagLength, byte[] additionalAuthenticatedDa
188188
System.arraycopy(cipherText, cipherText.length - getBlocksize(), this.iv, 0, getBlocksize());
189189
}
190190
return result;
191-
} catch (IllegalBlockSizeException | BadPaddingException | NoSuchAlgorithmException
191+
} catch (IllegalStateException | IllegalBlockSizeException | BadPaddingException | NoSuchAlgorithmException
192192
| InvalidAlgorithmParameterException | InvalidKeyException | NoSuchPaddingException ex) {
193193
throw new CryptoException("Could not decrypt data", ex);
194194
}

TLS-Core/src/main/java/de/rub/nds/tlsattacker/core/crypto/ec/EllipticCurve.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ public Point add(Point p, Point q) {
9191
}
9292

9393
/**
94-
* Returns k*p on this curve. If k or p is null, the result will be null. If
95-
* the point is not on the curve and the calculations would require dividing
96-
* by 0, the result will be the point at infinity.
94+
* Returns k*p on this curve. If the point is not on the curve and the
95+
* calculations would require dividing by 0, the result will be the point at
96+
* infinity.
9797
*
9898
* @param p
9999
* A point which's coordinates are elements of the field over
@@ -106,7 +106,7 @@ public Point mult(BigInteger k, Point p) {
106106
}
107107

108108
// Double-and-add
109-
Point q = new Point(); // q == O
109+
Point q = getPoint(BigInteger.ZERO, BigInteger.ZERO); // q == O
110110

111111
for (int i = k.bitLength(); i > 0; i--) {
112112

@@ -129,7 +129,6 @@ public Point mult(BigInteger k, Point p) {
129129
* which the curve is defined or the point at infinity.
130130
*/
131131
public Point inverse(Point p) {
132-
133132
if (p.isAtInfinity()) {
134133
// -O == O
135134
return p;

TLS-Core/src/main/java/de/rub/nds/tlsattacker/core/crypto/ec/EllipticCurveOverF2m.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ public boolean isOnCurve(Point p) {
112112

113113
@Override
114114
protected Point inverseAffine(Point p) {
115+
if (!(p.getX() instanceof FieldElementF2m && p.getY() instanceof FieldElementF2m)) {
116+
LOGGER.warn("Trying to invert non F2m point with F2m curve. Returning point at (0,0)");
117+
return this.getPoint(BigInteger.ZERO, BigInteger.ZERO);
118+
}
115119
// -p == (x, x+y)
116120

117121
FieldElementF2m x = (FieldElementF2m) p.getX();
@@ -122,6 +126,11 @@ protected Point inverseAffine(Point p) {
122126

123127
@Override
124128
protected Point additionFormular(Point p, Point q) {
129+
if (!(p.getX() instanceof FieldElementF2m && p.getY() instanceof FieldElementF2m
130+
&& q.getX() instanceof FieldElementF2m && q.getY() instanceof FieldElementF2m)) {
131+
LOGGER.warn("Trying to add non F2m points with F2m curve. Returning point at (0,0)");
132+
return this.getPoint(BigInteger.ZERO, BigInteger.ZERO);
133+
}
125134
try {
126135
FieldElementF2m x1 = (FieldElementF2m) p.getX();
127136
FieldElementF2m y1 = (FieldElementF2m) p.getY();

0 commit comments

Comments
 (0)