-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fd8c4e1
commit 05ff380
Showing
2 changed files
with
97 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package tlschannel; | ||
|
||
import java.security.NoSuchAlgorithmException; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import javax.net.ssl.SSLContext; | ||
import org.junit.jupiter.api.DynamicTest; | ||
import org.junit.jupiter.api.TestFactory; | ||
import org.junit.jupiter.api.TestInstance; | ||
import org.junit.jupiter.api.TestInstance.Lifecycle; | ||
import scala.Option; | ||
import scala.Some; | ||
import scala.jdk.CollectionConverters; | ||
import tlschannel.helpers.Loops; | ||
import tlschannel.helpers.SocketPair; | ||
import tlschannel.helpers.SocketPairFactory; | ||
import tlschannel.helpers.SslContextFactory; | ||
|
||
@TestInstance(Lifecycle.PER_CLASS) | ||
public class CipherTest { | ||
|
||
private final List<String> protocols; | ||
private final int dataSize = 200 * 1000; | ||
|
||
public CipherTest() { | ||
try { | ||
String[] allProtocols = | ||
SSLContext.getDefault().getSupportedSSLParameters().getProtocols(); | ||
protocols = Arrays.stream(allProtocols) | ||
.filter(x -> !x.equals("SSLv2Hello")) | ||
.collect(Collectors.toList()); | ||
} catch (NoSuchAlgorithmException e) { | ||
throw new RuntimeException(); | ||
} | ||
} | ||
|
||
// Test a half-duplex interaction, with renegotiation before reversing the direction of the flow (as in HTTP) | ||
@TestFactory | ||
public Collection<DynamicTest> testHalfDuplexWithRenegotiation() { | ||
System.out.println("testHalfDuplexWithRenegotiation():"); | ||
List<DynamicTest> tests = new ArrayList<>(); | ||
for (String protocol : protocols) { | ||
SslContextFactory ctxFactory = new SslContextFactory(protocol); | ||
for (String cipher : | ||
CollectionConverters.SeqHasAsJava(ctxFactory.allCiphers()).asJava()) { | ||
tests.add(DynamicTest.dynamicTest( | ||
String.format("testHalfDuplexWithRenegotiation() - protocol: %s, cipher: %s", protocol, cipher), | ||
() -> { | ||
SocketPairFactory socketFactory = new SocketPairFactory(ctxFactory.defaultContext()); | ||
SocketPair socketPair = socketFactory.nioNio( | ||
Some.apply(cipher), Option.apply(null), true, false, Option.apply(null)); | ||
Loops.halfDuplex(socketPair, dataSize, protocol.compareTo("TLSv1.2") < 0, false); | ||
String actualProtocol = socketPair | ||
.client() | ||
.tls() | ||
.getSslEngine() | ||
.getSession() | ||
.getProtocol(); | ||
String p = String.format("%s (%s)", protocol, actualProtocol); | ||
System.out.printf("%-18s %-50s\n", p, cipher); | ||
})); | ||
} | ||
} | ||
return tests; | ||
} | ||
|
||
// Test a full-duplex interaction, without any renegotiation | ||
@TestFactory | ||
public Collection<DynamicTest> testFullDuplex() { | ||
List<DynamicTest> tests = new ArrayList<>(); | ||
for (String protocol : protocols) { | ||
SslContextFactory ctxFactory = new SslContextFactory(protocol); | ||
for (String cipher : | ||
CollectionConverters.SeqHasAsJava(ctxFactory.allCiphers()).asJava()) { | ||
tests.add(DynamicTest.dynamicTest( | ||
String.format("testFullDuplex() - protocol: %s, cipher: %s", protocol, cipher), () -> { | ||
SocketPairFactory socketFactory = new SocketPairFactory(ctxFactory.defaultContext()); | ||
SocketPair socketPair = socketFactory.nioNio( | ||
Some.apply(cipher), Option.apply(null), true, false, Option.apply(null)); | ||
Loops.fullDuplex(socketPair, dataSize); | ||
String actualProtocol = socketPair | ||
.client() | ||
.tls() | ||
.getSslEngine() | ||
.getSession() | ||
.getProtocol(); | ||
String p = String.format("%s (%s)", protocol, actualProtocol); | ||
System.out.printf("%-18s %-50s\n", p, cipher); | ||
})); | ||
} | ||
} | ||
return tests; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.