Skip to content

Commit 2112d1f

Browse files
authored
Merge pull request #282 from RUB-NDS/gcmccm
GCM and CCM functionality added.
2 parents 7f7c1ae + 3b167db commit 2112d1f

File tree

67 files changed

+2080
-723
lines changed

Some content is hidden

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

67 files changed

+2080
-723
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ public Config createConfig() {
9797
cipherSuites.add(CipherSuite.TLS_RSA_WITH_RC4_128_SHA);
9898
config.setDefaultClientSupportedCiphersuites(cipherSuites);
9999
}
100+
config.setQuickReceive(true);
101+
config.setEarlyStop(true);
100102
return config;
101103
}
102104

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ public Config createConfig() {
8282
throw new ConfigurationException("This attack only works with CBC Ciphersuites");
8383
}
8484
}
85-
85+
config.setQuickReceive(true);
86+
config.setEarlyStop(true);
8687
return config;
8788
}
8889
}

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,10 @@ public static Config mergeWithDefaultValues(Config c) {
800800

801801
private byte[] defaultServerHandshakeTrafficSecret = new byte[0];
802802

803+
private byte[] defaultClientApplicationTrafficSecret = new byte[0];
804+
805+
private byte[] defaultServerApplicationTrafficSecret = new byte[0];
806+
803807
private TokenBindingType defaultTokenBindingType = TokenBindingType.PROVIDED_TOKEN_BINDING;
804808

805809
private CustomECPoint defaultTokenBindingECPublicKey = null;
@@ -2382,4 +2386,19 @@ public void setStopActionsAfterFatal(boolean stopActionsAfterFatal) {
23822386
this.stopActionsAfterFatal = stopActionsAfterFatal;
23832387
}
23842388

2389+
public byte[] getDefaultClientApplicationTrafficSecret() {
2390+
return defaultClientApplicationTrafficSecret;
2391+
}
2392+
2393+
public void setDefaultClientApplicationTrafficSecret(byte[] defaultClientApplicationTrafficSecret) {
2394+
this.defaultClientApplicationTrafficSecret = defaultClientApplicationTrafficSecret;
2395+
}
2396+
2397+
public byte[] getDefaultServerApplicationTrafficSecret() {
2398+
return defaultServerApplicationTrafficSecret;
2399+
}
2400+
2401+
public void setDefaultServerApplicationTrafficSecret(byte[] defaultServerApplicationTrafficSecret) {
2402+
this.defaultServerApplicationTrafficSecret = defaultServerApplicationTrafficSecret;
2403+
}
23852404
}

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

Lines changed: 54 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@
88
*/
99
package de.rub.nds.tlsattacker.core.constants;
1010

11+
import static de.rub.nds.tlsattacker.core.constants.BulkCipherAlgorithm.AES;
12+
import static de.rub.nds.tlsattacker.core.constants.BulkCipherAlgorithm.CAMELLIA;
13+
import static de.rub.nds.tlsattacker.core.constants.BulkCipherAlgorithm.DES;
14+
import static de.rub.nds.tlsattacker.core.constants.BulkCipherAlgorithm.DES40;
15+
import static de.rub.nds.tlsattacker.core.constants.BulkCipherAlgorithm.DESede;
16+
import static de.rub.nds.tlsattacker.core.constants.BulkCipherAlgorithm.FORTEZZA;
17+
import static de.rub.nds.tlsattacker.core.constants.BulkCipherAlgorithm.IDEA;
18+
import static de.rub.nds.tlsattacker.core.constants.BulkCipherAlgorithm.NULL;
19+
import static de.rub.nds.tlsattacker.core.constants.BulkCipherAlgorithm.RC2;
20+
import static de.rub.nds.tlsattacker.core.constants.BulkCipherAlgorithm.RC4;
21+
import static de.rub.nds.tlsattacker.core.constants.BulkCipherAlgorithm.SEED;
1122
import java.util.HashSet;
1223
import java.util.Set;
1324
import org.apache.logging.log4j.LogManager;
@@ -42,7 +53,7 @@ public static PRFAlgorithm getPRFAlgorithm(ProtocolVersion protocolVersion, Ciph
4253
if (protocolVersion == ProtocolVersion.TLS10 || protocolVersion == ProtocolVersion.TLS11
4354
|| protocolVersion == ProtocolVersion.DTLS10) {
4455
result = PRFAlgorithm.TLS_PRF_LEGACY;
45-
} else if (cipherSuite.name().endsWith("SHA384")) {
56+
} else if (cipherSuite.usesSHA384()) {
4657
result = PRFAlgorithm.TLS_PRF_SHA384;
4758
} else {
4859
result = PRFAlgorithm.TLS_PRF_SHA256;
@@ -72,7 +83,7 @@ public static DigestAlgorithm getDigestAlgorithm(ProtocolVersion protocolVersion
7283
if (protocolVersion == ProtocolVersion.TLS10 || protocolVersion == ProtocolVersion.TLS11
7384
|| protocolVersion == ProtocolVersion.DTLS10) {
7485
result = DigestAlgorithm.LEGACY;
75-
} else if (cipherSuite.name().endsWith("SHA384")) {
86+
} else if (cipherSuite.usesSHA384()) {
7687
result = DigestAlgorithm.SHA384;
7788
} else {
7889
result = DigestAlgorithm.SHA256;
@@ -241,20 +252,54 @@ public static CipherAlgorithm getCipher(CipherSuite cipherSuite) {
241252
throw new UnsupportedOperationException("The cipher algorithm in " + cipherSuite + " is not supported yet.");
242253
}
243254

255+
/**
256+
* @param cipherSuite
257+
* @return
258+
*/
259+
public static BulkCipherAlgorithm getBulkCipherAlgorithm(CipherSuite cipherSuite) {
260+
String cipher = cipherSuite.toString().toUpperCase();
261+
if (cipher.contains("3DES_EDE")) {
262+
return DESede;
263+
} else if (cipher.contains("AES")) {
264+
return AES;
265+
} else if (cipher.contains("RC4")) {
266+
return RC4;
267+
} else if (cipher.contains("RC2")) {
268+
return RC2; // Tode add export rc2
269+
} else if (cipher.contains("WITH_NULL")) {
270+
return NULL;
271+
} else if (cipher.contains("IDEA")) {
272+
return IDEA;
273+
} else if (cipher.contains("DES40")) {
274+
return DES40;
275+
} else if (cipher.contains("DES")) {
276+
return DES;
277+
} else if (cipher.contains("WITH_FORTEZZA")) {
278+
return FORTEZZA;
279+
} else if (cipher.contains("CAMELLIA")) {
280+
return CAMELLIA;
281+
} else if (cipher.contains("SEED")) {
282+
return SEED;
283+
} else if (cipher.contains("ARIA")) {
284+
return SEED;
285+
}
286+
throw new UnsupportedOperationException("The cipher algorithm from " + cipherSuite + " is not supported yet.");
287+
}
288+
244289
/**
245290
*
246291
* @param cipherSuite
247292
* @return
248293
*/
249294
public static CipherType getCipherType(CipherSuite cipherSuite) {
250-
String cipher = cipherSuite.toString().toUpperCase();
251-
if (cipherSuite.isAEAD()) {
295+
String cs = cipherSuite.toString().toUpperCase();
296+
if (cipherSuite.isGCM() || cipherSuite.isCCM() || cipherSuite.isOCB()) {
252297
return CipherType.AEAD;
253-
} else if (cipher.contains("AES") || cipher.contains("DES") || cipher.contains("IDEA")
254-
|| cipher.contains("WITH_FORTEZZA") || cipher.contains("CAMELLIA") || cipher.contains("GOST")
255-
|| cipher.contains("WITH_SEED") || cipher.contains("WITH_ARIA") || cipher.contains("RC2")) {
298+
} else if (cs.contains("AES") || cs.contains("DES") || cs.contains("IDEA") || cs.contains("WITH_FORTEZZA")
299+
|| cs.contains("CAMELLIA") || cs.contains("GOST") || cs.contains("WITH_SEED")
300+
|| cs.contains("WITH_ARIA") || cs.contains("RC2")) {
256301
return CipherType.BLOCK;
257-
} else if (cipher.contains("RC4") || cipher.contains("WITH_NULL") || cipher.contains("CHACHA")) {
302+
} else if (cs.contains("RC4") || cs.contains("WITH_NULL") || cs.contains("CHACHA")) {
258303
return CipherType.STREAM;
259304
}
260305
if (cipherSuite == CipherSuite.TLS_FALLBACK_SCSV
@@ -268,7 +313,7 @@ public static CipherType getCipherType(CipherSuite cipherSuite) {
268313

269314
public static MacAlgorithm getMacAlgorithm(ProtocolVersion protocolVersion, CipherSuite cipherSuite) {
270315
MacAlgorithm result = null;
271-
if (cipherSuite.isAEAD()) {
316+
if (getCipherType(cipherSuite) == CipherType.AEAD) {
272317
result = MacAlgorithm.AEAD;
273318
} else {
274319
String cipher = cipherSuite.toString();

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

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -29,40 +29,6 @@ public enum BulkCipherAlgorithm {
2929
ARIA,
3030
AES;
3131

32-
/**
33-
* @param cipherSuite
34-
* @return
35-
*/
36-
public static BulkCipherAlgorithm getBulkCipherAlgorithm(CipherSuite cipherSuite) {
37-
String cipher = cipherSuite.toString().toUpperCase();
38-
if (cipher.contains("3DES_EDE")) {
39-
return DESede;
40-
} else if (cipher.contains("AES")) {
41-
return AES;
42-
} else if (cipher.contains("RC4")) {
43-
return RC4;
44-
} else if (cipher.contains("RC2")) {
45-
return RC2; // Tode add export rc2
46-
} else if (cipher.contains("WITH_NULL")) {
47-
return NULL;
48-
} else if (cipher.contains("IDEA")) {
49-
return IDEA;
50-
} else if (cipher.contains("DES40")) {
51-
return DES40;
52-
} else if (cipher.contains("DES")) {
53-
return DES;
54-
} else if (cipher.contains("WITH_FORTEZZA")) {
55-
return FORTEZZA;
56-
} else if (cipher.contains("CAMELLIA")) {
57-
return CAMELLIA;
58-
} else if (cipher.contains("SEED")) {
59-
return SEED;
60-
} else if (cipher.contains("ARIA")) {
61-
return SEED;
62-
}
63-
throw new UnsupportedOperationException("The cipher algorithm from " + cipherSuite + " is not supported yet.");
64-
}
65-
6632
public String getJavaName() {
6733
if (this == DES40) {
6834
return "DES";

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

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -513,15 +513,6 @@ public boolean isExport() {
513513
return this.name().contains("EXPORT");
514514
}
515515

516-
/**
517-
* Returns true in case the cipher suite is an AEAD cipher suite.
518-
*
519-
* @return
520-
*/
521-
public boolean isAEAD() {
522-
return (this.name().contains("_GCM") || this.name().contains("_CCM") || this.name().contains("_OCB"));
523-
}
524-
525516
/**
526517
* Returns true in case the cipher suite is a CBC cipher suite.
527518
*
@@ -531,10 +522,35 @@ public boolean isCBC() {
531522
return (this.name().contains("_CBC"));
532523
}
533524

525+
public boolean isUsingPadding() {
526+
// todo this should be extended
527+
return (this.name().contains("_CBC"));
528+
}
529+
530+
public boolean isUsingMac() {
531+
return (this.name().contains("_CBC") || this.name().contains("RC4"));
532+
}
533+
534534
public boolean isSCSV() {
535535
return (this.name().contains("SCSV"));
536536
}
537537

538+
public boolean isGCM() {
539+
return (this.name().contains("_GCM"));
540+
}
541+
542+
public boolean isCCM() {
543+
return (this.name().contains("_CCM"));
544+
}
545+
546+
public boolean isOCB() {
547+
return (this.name().contains("_OCB"));
548+
}
549+
550+
public boolean usesSHA384() {
551+
return this.name().endsWith("SHA384");
552+
}
553+
538554
/**
539555
* Returns true if the cipher suite is supported by the specified protocol
540556
* version.
@@ -617,6 +633,30 @@ public static List<CipherSuite> getImplemented() {
617633
list.add(TLS_RSA_WITH_RC4_128_SHA);
618634
list.add(TLS_ECDHE_RSA_WITH_RC4_128_SHA);
619635
list.add(TLS_DHE_DSS_WITH_RC4_128_SHA);
636+
list.add(TLS_RSA_WITH_AES_128_GCM_SHA256);
637+
list.add(TLS_RSA_WITH_AES_256_GCM_SHA384);
638+
list.add(TLS_DHE_RSA_WITH_AES_128_GCM_SHA256);
639+
list.add(TLS_DHE_RSA_WITH_AES_256_GCM_SHA384);
640+
list.add(TLS_DH_RSA_WITH_AES_128_GCM_SHA256);
641+
list.add(TLS_DH_RSA_WITH_AES_256_GCM_SHA384);
642+
list.add(TLS_DHE_DSS_WITH_AES_128_GCM_SHA256);
643+
list.add(TLS_DHE_DSS_WITH_AES_256_GCM_SHA384);
644+
list.add(TLS_DH_DSS_WITH_AES_256_GCM_SHA384);
645+
list.add(TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256);
646+
list.add(TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384);
647+
list.add(TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256);
648+
list.add(TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384);
649+
list.add(TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256);
650+
list.add(TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384);
651+
list.add(TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256);
652+
list.add(TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384);
653+
list.add(TLS_RSA_WITH_AES_128_CCM);
654+
list.add(TLS_RSA_WITH_AES_256_CCM);
655+
list.add(TLS_DHE_RSA_WITH_AES_128_CCM);
656+
list.add(TLS_DHE_RSA_WITH_AES_256_CCM);
657+
list.add(TLS_ECDHE_ECDSA_WITH_AES_128_CCM);
658+
list.add(TLS_ECDHE_ECDSA_WITH_AES_256_CCM);
659+
620660
return list;
621661
}
622662

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,9 @@ public boolean isTLS13() {
167167
public boolean isSSL() {
168168
return this == SSL2 || this == SSL3;
169169
}
170+
171+
public boolean usesExplicitIv() {
172+
return this == ProtocolVersion.TLS11 || this == ProtocolVersion.TLS12 || this == ProtocolVersion.DTLS10
173+
|| this == ProtocolVersion.DTLS12;
174+
}
170175
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public static byte[] expand(HKDFAlgorithm hkdfAlgortihm, byte[] prk, byte[] info
113113
i++;
114114
}
115115
return Arrays.copyOfRange(stream.toByteArray(), 0, outLen);
116-
} catch (IOException | NoSuchAlgorithmException | InvalidKeyException ex) {
116+
} catch (IOException | NoSuchAlgorithmException | InvalidKeyException | IllegalArgumentException ex) {
117117
throw new CryptoException(ex);
118118
}
119119
}
@@ -169,5 +169,4 @@ public static byte[] expandLabel(HKDFAlgorithm hkdfAlgortihm, byte[] prk, String
169169
byte[] info = labelEncoder(hashValue, labelIn, outLen);
170170
return expand(hkdfAlgortihm, prk, info, outLen);
171171
}
172-
173172
}

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,14 @@ private void adjustServerSupportedSignatureAndHashAlgorithms(CertificateRequestM
5959
}
6060

6161
private void adjustDistinguishedNames(CertificateRequestMessage message) {
62-
byte[] distinguishedNames = message.getDistinguishedNames().getValue();
63-
tlsContext.setDistinguishedNames(distinguishedNames);
64-
LOGGER.debug("Set DistinguishedNames in Context to "
65-
+ ArrayConverter.bytesToHexString(distinguishedNames, false));
62+
if (message.getDistinguishedNames() != null && message.getDistinguishedNames().getValue() != null) {
63+
byte[] distinguishedNames = message.getDistinguishedNames().getValue();
64+
tlsContext.setDistinguishedNames(distinguishedNames);
65+
LOGGER.debug("Set DistinguishedNames in Context to "
66+
+ ArrayConverter.bytesToHexString(distinguishedNames, false));
67+
} else {
68+
LOGGER.debug("Not adjusting DistinguishedNames");
69+
}
6670
}
6771

6872
private void adjustClientCertificateTypes(CertificateRequestMessage message) {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public void adjustTLSContext(ChangeCipherSpecMessage message) {
4444
if (tlsContext.getTalkingConnectionEndType() != tlsContext.getChooser().getConnectionEnd()
4545
.getConnectionEndType()) {
4646
tlsContext.getRecordLayer().updateDecryptionCipher();
47+
tlsContext.setReadSequenceNumber(0);
4748
}
4849
}
4950
}

0 commit comments

Comments
 (0)