Skip to content

Commit 458d67e

Browse files
Merge remote-tracking branch 'origin/jetty-9.4.x' into jetty-9.4.x-5320-WebSocketHttpClient
2 parents 59883af + 8b61d70 commit 458d67e

3 files changed

Lines changed: 96 additions & 64 deletions

File tree

jetty-util/src/main/java/org/eclipse/jetty/util/ssl/SslContextFactory.java

Lines changed: 61 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,12 @@
4747
import java.util.Collections;
4848
import java.util.Comparator;
4949
import java.util.HashMap;
50-
import java.util.Iterator;
5150
import java.util.LinkedHashSet;
5251
import java.util.List;
5352
import java.util.Map;
5453
import java.util.Objects;
5554
import java.util.Set;
5655
import java.util.function.Consumer;
57-
import java.util.regex.Matcher;
5856
import java.util.regex.Pattern;
5957
import javax.net.ssl.CertPathTrustManagerParameters;
6058
import javax.net.ssl.HostnameVerifier;
@@ -140,7 +138,7 @@ public class SslContextFactory extends AbstractLifeCycle implements Dumpable
140138
private final Set<String> _excludeProtocols = new LinkedHashSet<>();
141139
private final Set<String> _includeProtocols = new LinkedHashSet<>();
142140
private final Set<String> _excludeCipherSuites = new LinkedHashSet<>();
143-
private final List<String> _includeCipherSuites = new ArrayList<>();
141+
private final Set<String> _includeCipherSuites = new LinkedHashSet<>();
144142
private final Map<String, X509> _aliasX509 = new HashMap<>();
145143
private final Map<String, X509> _certHosts = new HashMap<>();
146144
private final Map<String, X509> _certWilds = new HashMap<>();
@@ -526,6 +524,8 @@ public String[] getExcludeProtocols()
526524
}
527525

528526
/**
527+
* You can either use the exact Protocol name or a a regular expression.
528+
*
529529
* @param protocols The array of protocol names to exclude from
530530
* {@link SSLEngine#setEnabledProtocols(String[])}
531531
*/
@@ -536,15 +536,17 @@ public void setExcludeProtocols(String... protocols)
536536
}
537537

538538
/**
539-
* @param protocol Protocol names to add to {@link SSLEngine#setEnabledProtocols(String[])}
539+
* You can either use the exact Protocol name or a a regular expression.
540+
*
541+
* @param protocol Protocol name patterns to add to {@link SSLEngine#setEnabledProtocols(String[])}
540542
*/
541543
public void addExcludeProtocols(String... protocol)
542544
{
543545
_excludeProtocols.addAll(Arrays.asList(protocol));
544546
}
545547

546548
/**
547-
* @return The array of protocol names to include in
549+
* @return The array of protocol name patterns to include in
548550
* {@link SSLEngine#setEnabledProtocols(String[])}
549551
*/
550552
@ManagedAttribute("The included TLS protocols")
@@ -554,7 +556,9 @@ public String[] getIncludeProtocols()
554556
}
555557

556558
/**
557-
* @param protocols The array of protocol names to include in
559+
* You can either use the exact Protocol name or a a regular expression.
560+
*
561+
* @param protocols The array of protocol name patterns to include in
558562
* {@link SSLEngine#setEnabledProtocols(String[])}
559563
*/
560564
public void setIncludeProtocols(String... protocols)
@@ -564,7 +568,7 @@ public void setIncludeProtocols(String... protocols)
564568
}
565569

566570
/**
567-
* @return The array of cipher suite names to exclude from
571+
* @return The array of cipher suite name patterns to exclude from
568572
* {@link SSLEngine#setEnabledCipherSuites(String[])}
569573
*/
570574
@ManagedAttribute("The excluded cipher suites")
@@ -574,7 +578,7 @@ public String[] getExcludeCipherSuites()
574578
}
575579

576580
/**
577-
* You can either use the exact cipher suite name or a a regular expression.
581+
* You can either use the exact Cipher suite name or a a regular expression.
578582
*
579583
* @param cipherSuites The array of cipher suite names to exclude from
580584
* {@link SSLEngine#setEnabledCipherSuites(String[])}
@@ -586,6 +590,8 @@ public void setExcludeCipherSuites(String... cipherSuites)
586590
}
587591

588592
/**
593+
* You can either use the exact Cipher suite name or a a regular expression.
594+
*
589595
* @param cipher Cipher names to add to {@link SSLEngine#setEnabledCipherSuites(String[])}
590596
*/
591597
public void addExcludeCipherSuites(String... cipher)
@@ -594,7 +600,7 @@ public void addExcludeCipherSuites(String... cipher)
594600
}
595601

596602
/**
597-
* @return The array of cipher suite names to include in
603+
* @return The array of Cipher suite names to include in
598604
* {@link SSLEngine#setEnabledCipherSuites(String[])}
599605
*/
600606
@ManagedAttribute("The included cipher suites")
@@ -604,7 +610,7 @@ public String[] getIncludeCipherSuites()
604610
}
605611

606612
/**
607-
* You can either use the exact cipher suite name or a a regular expression.
613+
* You can either use the exact Cipher suite name or a a regular expression.
608614
*
609615
* @param cipherSuites The array of cipher suite names to include in
610616
* {@link SSLEngine#setEnabledCipherSuites(String[])}
@@ -1357,28 +1363,10 @@ protected PKIXBuilderParameters newPKIXBuilderParameters(KeyStore trustStore, Co
13571363
*/
13581364
public void selectProtocols(String[] enabledProtocols, String[] supportedProtocols)
13591365
{
1360-
Set<String> selectedProtocols = new LinkedHashSet<>();
1361-
1362-
// Set the starting protocols - either from the included or enabled list
1363-
if (!_includeProtocols.isEmpty())
1364-
{
1365-
// Use only the supported included protocols
1366-
for (String protocol : _includeProtocols)
1367-
{
1368-
if (Arrays.asList(supportedProtocols).contains(protocol))
1369-
selectedProtocols.add(protocol);
1370-
else
1371-
LOG.info("Protocol {} not supported in {}", protocol, Arrays.asList(supportedProtocols));
1372-
}
1373-
}
1374-
else
1375-
selectedProtocols.addAll(Arrays.asList(enabledProtocols));
1376-
1377-
// Remove any excluded protocols
1378-
selectedProtocols.removeAll(_excludeProtocols);
1366+
List<String> selectedProtocols = processIncludeExcludePatterns("Protocols", enabledProtocols, supportedProtocols, _includeProtocols, _excludeProtocols);
13791367

13801368
if (selectedProtocols.isEmpty())
1381-
LOG.warn("No selected protocols from {}", Arrays.asList(supportedProtocols));
1369+
LOG.warn("No selected Protocols from {}", Arrays.asList(supportedProtocols));
13821370

13831371
_selectedProtocols = selectedProtocols.toArray(new String[0]);
13841372
}
@@ -1393,18 +1381,10 @@ public void selectProtocols(String[] enabledProtocols, String[] supportedProtoco
13931381
*/
13941382
protected void selectCipherSuites(String[] enabledCipherSuites, String[] supportedCipherSuites)
13951383
{
1396-
List<String> selectedCiphers = new ArrayList<>();
1397-
1398-
// Set the starting ciphers - either from the included or enabled list
1399-
if (_includeCipherSuites.isEmpty())
1400-
selectedCiphers.addAll(Arrays.asList(enabledCipherSuites));
1401-
else
1402-
processIncludeCipherSuites(supportedCipherSuites, selectedCiphers);
1403-
1404-
removeExcludedCipherSuites(selectedCiphers);
1384+
List<String> selectedCiphers = processIncludeExcludePatterns("Cipher Suite", enabledCipherSuites, supportedCipherSuites, _includeCipherSuites, _excludeCipherSuites);
14051385

14061386
if (selectedCiphers.isEmpty())
1407-
LOG.warn("No supported ciphers from {}", Arrays.asList(supportedCipherSuites));
1387+
LOG.warn("No supported Cipher Suite from {}", Arrays.asList(supportedCipherSuites));
14081388

14091389
Comparator<String> comparator = getCipherComparator();
14101390
if (comparator != null)
@@ -1417,39 +1397,58 @@ protected void selectCipherSuites(String[] enabledCipherSuites, String[] support
14171397
_selectedCipherSuites = selectedCiphers.toArray(new String[0]);
14181398
}
14191399

1420-
protected void processIncludeCipherSuites(String[] supportedCipherSuites, List<String> selectedCiphers)
1400+
private List<String> processIncludeExcludePatterns(String type, String[] enabled, String[] supported, Set<String> included, Set<String> excluded)
14211401
{
1422-
for (String cipherSuite : _includeCipherSuites)
1402+
List<String> selected = new ArrayList<>();
1403+
// Set the starting list - either from the included or enabled list
1404+
if (included.isEmpty())
14231405
{
1424-
Pattern p = Pattern.compile(cipherSuite);
1425-
boolean added = false;
1426-
for (String supportedCipherSuite : supportedCipherSuites)
1406+
selected.addAll(Arrays.asList(enabled));
1407+
}
1408+
else
1409+
{
1410+
// process include patterns
1411+
for (String includedItem : included)
14271412
{
1428-
Matcher m = p.matcher(supportedCipherSuite);
1429-
if (m.matches())
1413+
Pattern pattern = Pattern.compile(includedItem);
1414+
boolean added = false;
1415+
for (String supportedItem : supported)
14301416
{
1431-
added = true;
1432-
selectedCiphers.add(supportedCipherSuite);
1417+
if (pattern.matcher(supportedItem).matches())
1418+
{
1419+
added = true;
1420+
selected.add(supportedItem);
1421+
}
14331422
}
1423+
if (!added)
1424+
LOG.info("No {} matching '{}' is supported", type, includedItem);
14341425
}
1435-
if (!added)
1436-
LOG.info("No Cipher matching '{}' is supported", cipherSuite);
14371426
}
1427+
1428+
// process exclude patterns
1429+
for (String excludedItem : excluded)
1430+
{
1431+
Pattern pattern = Pattern.compile(excludedItem);
1432+
selected.removeIf(selectedItem -> pattern.matcher(selectedItem).matches());
1433+
}
1434+
1435+
return selected;
14381436
}
14391437

1438+
/**
1439+
* @deprecated no replacement
1440+
*/
1441+
@Deprecated
1442+
protected void processIncludeCipherSuites(String[] supportedCipherSuites, List<String> selectedCiphers)
1443+
{
1444+
}
1445+
1446+
/**
1447+
* @deprecated no replacement
1448+
*/
1449+
@Deprecated
14401450
protected void removeExcludedCipherSuites(List<String> selectedCiphers)
14411451
{
1442-
for (String excludeCipherSuite : _excludeCipherSuites)
1443-
{
1444-
Pattern excludeCipherPattern = Pattern.compile(excludeCipherSuite);
1445-
for (Iterator<String> i = selectedCiphers.iterator(); i.hasNext(); )
1446-
{
1447-
String selectedCipherSuite = i.next();
1448-
Matcher m = excludeCipherPattern.matcher(selectedCipherSuite);
1449-
if (m.matches())
1450-
i.remove();
1451-
}
1452-
}
14531452
}
14541453

14551454
/**

jetty-util/src/test/java/org/eclipse/jetty/util/ssl/SslContextFactoryTest.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import static org.hamcrest.Matchers.equalTo;
5656
import static org.hamcrest.Matchers.greaterThan;
5757
import static org.hamcrest.Matchers.hasItem;
58+
import static org.hamcrest.Matchers.hasItemInArray;
5859
import static org.hamcrest.Matchers.is;
5960
import static org.hamcrest.Matchers.matchesRegex;
6061
import static org.hamcrest.Matchers.not;
@@ -95,6 +96,38 @@ public void testSLOTH() throws Exception
9596
}
9697
}
9798

99+
@Test
100+
public void testDumpExcludedProtocols() throws Exception
101+
{
102+
SslContextFactory.Server cf = new SslContextFactory.Server();
103+
cf.setExcludeProtocols("TLSv1\\.?[01]?");
104+
cf.start();
105+
106+
// Confirm behavior in engine
107+
assertThat(cf.newSSLEngine().getEnabledProtocols(), not(hasItemInArray("TLSv1.1")));
108+
assertThat(cf.newSSLEngine().getEnabledProtocols(), not(hasItemInArray("TLSv1")));
109+
110+
// Confirm output in dump
111+
List<SslSelectionDump> dumps = cf.selectionDump();
112+
113+
Optional<SslSelectionDump> protocolDumpOpt = dumps.stream()
114+
.filter((dump) -> dump.type.contains("Protocol"))
115+
.findFirst();
116+
117+
assertTrue(protocolDumpOpt.isPresent(), "Protocol dump section should exist");
118+
119+
SslSelectionDump protocolDump = protocolDumpOpt.get();
120+
121+
long countTls11Enabled = protocolDump.enabled.stream().filter((t) -> t.contains("TLSv1.1")).count();
122+
long countTls11Disabled = protocolDump.disabled.stream().filter((t) -> t.contains("TLSv1.1")).count();
123+
124+
assertThat("Enabled Protocols TLSv1.1 count", countTls11Enabled, is(0L));
125+
assertThat("Disabled Protocols TLSv1.1 count", countTls11Disabled, is(1L));
126+
127+
// Uncomment to show dump in console.
128+
// cf.dump(System.out, "");
129+
}
130+
98131
@Test
99132
public void testDumpIncludeTlsRsa() throws Exception
100133
{

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@
726726
<plugin>
727727
<groupId>org.asciidoctor</groupId>
728728
<artifactId>asciidoctor-maven-plugin</artifactId>
729-
<version>1.5.6</version>
729+
<version>2.1.0</version>
730730
</plugin>
731731
<plugin>
732732
<groupId>org.codehaus.mojo</groupId>
@@ -1154,7 +1154,7 @@
11541154
<dependency>
11551155
<groupId>io.grpc</groupId>
11561156
<artifactId>grpc-core</artifactId>
1157-
<version>1.0.1</version>
1157+
<version>1.33.0</version>
11581158
</dependency>
11591159
<dependency>
11601160
<groupId>org.apache.ant</groupId>

0 commit comments

Comments
 (0)