Skip to content

Commit

Permalink
Fix stream has already been operated upon or closed
Browse files Browse the repository at this point in the history
  • Loading branch information
hamadodene committed Feb 14, 2024
1 parent e33acbf commit 8363f5a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,13 @@ public boolean isMoreSpecific(SSLCertificateConfiguration other) {
if (subjectAltNames == null || subjectAltNames.isEmpty()) {
return hostname.length() > other.getHostname().length();
}
final var otherNames = other.getNames().stream().map(CertificatesUtils::removeWildcard);
for (var n: getNames()) {

final var otherNamesList = other.getNames().stream().map(CertificatesUtils::removeWildcard)
.collect(Collectors.toList());

for (var n : getNames()) {
final var name = CertificatesUtils.removeWildcard(n);
if (otherNames.anyMatch(on -> name.length() > on.length())) {
if (otherNamesList.stream().anyMatch(on -> name.length() > on.length())) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,16 @@ public void testChooseCertificate() throws Exception {
server.addCertificate(new SSLCertificateConfiguration("other", null, "cert", "pwd", STATIC));
server.addCertificate(new SSLCertificateConfiguration("*.example.com", Set.of("example.com", "*.example2.com"), "cert", "pwd", STATIC));
server.addCertificate(new SSLCertificateConfiguration("www.example.com", null, "cert", "pwd", STATIC));
server.addCertificate(new SSLCertificateConfiguration("*.qapatchweb.peachtest.it", Set.of("qapatchweb.peachtest.it"), "cert", "pwd", STATIC));
server.addCertificate(new SSLCertificateConfiguration("*.qapatch2web.peachtest.it", Set.of("qapatch2web.peachtest.it"), "cert", "pwd", STATIC));
server.addCertificate(new SSLCertificateConfiguration("*.peachtest.it", Set.of("gemini.peachtest.it"), "cert", "pwd", STATIC));


// client requests bad SNI, bad default in listener
assertNull(server.getListeners().chooseCertificate("no", "no-default"));

assertEquals("*.qapatchweb.peachtest.it", server.getListeners().chooseCertificate("test.qapatchweb.peachtest.it", "no-default").getId());

// client requests SNI, bad default in listener
assertEquals("other", server.getListeners().chooseCertificate("other", "no-default").getId());

Expand Down Expand Up @@ -131,17 +137,6 @@ public void testChooseCertificate() throws Exception {
assertEquals("*.example.com", server.getListeners().chooseCertificate("test.example2.com", "no-default").getId());
}

try (HttpProxyServer server = new HttpProxyServer(mapper, tmpDir.getRoot());) {

// full wildcard
server.addCertificate(new SSLCertificateConfiguration("*", null, "cert", "pwd", STATIC));

assertEquals("*", server.getListeners().chooseCertificate(null, "www.example.com").getId());
assertEquals("*", server.getListeners().chooseCertificate("www.example.com", null).getId());
assertEquals("*", server.getListeners().chooseCertificate(null, null).getId());
assertEquals("*", server.getListeners().chooseCertificate("", null).getId());
assertEquals("*", server.getListeners().chooseCertificate(null, "").getId());
}
}

@Test
Expand Down

0 comments on commit 8363f5a

Please sign in to comment.