-
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
0ecf209
commit d3b471b
Showing
2 changed files
with
99 additions
and
69 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,99 @@ | ||
package tlschannel; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
import io.netty.buffer.ByteBufAllocator; | ||
import io.netty.handler.ssl.SslContextBuilder; | ||
import io.netty.handler.ssl.SslProvider; | ||
import io.netty.handler.ssl.util.SimpleTrustManagerFactory; | ||
import java.net.Socket; | ||
import java.nio.ByteBuffer; | ||
import java.nio.channels.ByteChannel; | ||
import java.security.KeyStore; | ||
import java.security.cert.X509Certificate; | ||
import javax.net.ssl.*; | ||
import javax.net.ssl.ManagerFactoryParameters; | ||
import javax.net.ssl.SSLEngine; | ||
import javax.net.ssl.TrustManager; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.TestInstance; | ||
import org.junit.jupiter.api.TestInstance.Lifecycle; | ||
|
||
@TestInstance(Lifecycle.PER_CLASS) | ||
public class NettySslEngineTest { | ||
|
||
// dummy handshake as minimal sanity test | ||
@Test | ||
void testDummyHandshake() throws SSLException { | ||
io.netty.handler.ssl.SslContext ctx = SslContextBuilder.forClient() | ||
.sslProvider(SslProvider.OPENSSL) | ||
.trustManager(dummyTrustManagerFactory) | ||
.protocols("TLSv1.3") | ||
.build(); | ||
SSLEngine sslEngine = ctx.newEngine(ByteBufAllocator.DEFAULT, "test", 0); | ||
|
||
ClientTlsChannel channel = ClientTlsChannel.newBuilder(new DummyByteChannel(), sslEngine) | ||
.withEncryptedBufferAllocator(new HeapBufferAllocator()) | ||
.build(); | ||
|
||
assertThrows(NeedsWriteException.class, () -> channel.handshake()); | ||
} | ||
|
||
private final TrustManagerFactory dummyTrustManagerFactory = new SimpleTrustManagerFactory() { | ||
@Override | ||
public void engineInit(KeyStore keyStore) {} | ||
|
||
@Override | ||
public void engineInit(ManagerFactoryParameters params) {} | ||
|
||
@Override | ||
public TrustManager[] engineGetTrustManagers() { | ||
return new TrustManager[] {new DummyTrustManager()}; | ||
} | ||
}; | ||
|
||
private static class DummyByteChannel implements ByteChannel { | ||
@Override | ||
public boolean isOpen() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public void close() {} | ||
|
||
@Override | ||
public int write(ByteBuffer src) { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public int read(ByteBuffer dst) { | ||
return 0; | ||
} | ||
} | ||
|
||
private static class DummyTrustManager extends X509ExtendedTrustManager { | ||
@Override | ||
public void checkClientTrusted(X509Certificate[] certs, String s) {} | ||
|
||
@Override | ||
public void checkServerTrusted(X509Certificate[] certs, String s) {} | ||
|
||
@Override | ||
public X509Certificate[] getAcceptedIssuers() { | ||
return new X509Certificate[0]; | ||
} | ||
|
||
@Override | ||
public void checkClientTrusted(X509Certificate[] certs, String s, Socket socket) {} | ||
|
||
@Override | ||
public void checkServerTrusted(X509Certificate[] certs, String s, Socket socket) {} | ||
|
||
@Override | ||
public void checkClientTrusted(X509Certificate[] certs, String s, SSLEngine sslEngine) {} | ||
|
||
@Override | ||
public void checkServerTrusted(X509Certificate[] certs, String s, SSLEngine sslEngine) {} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.