use of io.servicetalk.transport.api.ClientSslConfigBuilder in project servicetalk by apple.
the class SniTest method noSniClientDefaultServerFallbackSuccess.
@ParameterizedTest(name = "protocols={0}, alpn={1}")
@MethodSource("protocolsAndAlpn")
void noSniClientDefaultServerFallbackSuccess(List<HttpProtocol> protocols, boolean useALPN) throws Exception {
try (ServerContext serverContext = HttpServers.forAddress(localAddress(0)).protocols(protocolConfigs(protocols)).sslConfig(trustedServerConfig(alpnIds(protocols, useALPN)), singletonMap("no_match" + SNI_HOSTNAME, untrustedServerConfig())).listenBlockingAndAwait(newSslVerifyService());
BlockingHttpClient client = HttpClients.forSingleAddress(getLoopbackAddress().getHostName(), serverHostAndPort(serverContext).port()).protocols(protocolConfigs(protocols)).sslConfig(configureAlpn(new ClientSslConfigBuilder(DefaultTestCerts::loadServerCAPem).peerHost(serverPemHostname()), protocols, useALPN).build()).inferSniHostname(false).buildBlocking()) {
HttpRequest request = client.get("/");
ReservedBlockingHttpConnection reserved = client.reserveConnection(request);
assertNotNull(reserved.connectionContext().sslSession());
assertEquals(HttpResponseStatus.OK, reserved.request(request).status());
reserved.release();
}
}
use of io.servicetalk.transport.api.ClientSslConfigBuilder in project servicetalk by apple.
the class SslProvidersTest method setUp.
private void setUp(SslProvider serverSslProvider, SslProvider clientSslProvider, int payloadLength) throws Exception {
payloadBody = randomString(payloadLength);
serverContext = HttpServers.forAddress(localAddress(0)).sslConfig(new ServerSslConfigBuilder(DefaultTestCerts::loadServerPem, DefaultTestCerts::loadServerKey).provider(serverSslProvider).build()).listenBlockingAndAwait((ctx, request, responseFactory) -> {
assertThat(ctx.sslSession(), is(notNullValue()));
assertThat(request.path(), is("/path"));
assertThat(request.headers().get(CONTENT_TYPE), is(TEXT_PLAIN_UTF_8));
assertThat(request.payloadBody(textSerializerUtf8()), is("request-payload-body-" + payloadBody));
return responseFactory.ok().payloadBody("response-payload-body-" + payloadBody, textSerializerUtf8());
});
client = HttpClients.forSingleAddress(serverHostAndPort(serverContext)).ioExecutor(NettyIoExecutors.createIoExecutor("client-io")).sslConfig(new ClientSslConfigBuilder(DefaultTestCerts::loadServerCAPem).peerHost(serverPemHostname()).provider(clientSslProvider).build()).buildBlocking();
}
use of io.servicetalk.transport.api.ClientSslConfigBuilder in project servicetalk by apple.
the class TcpFastOpenTest method newClient.
private static BlockingHttpClient newClient(final ServerContext serverContext, final Collection<HttpProtocol> protocols, final boolean secure, @SuppressWarnings("rawtypes") final Map<SocketOption, Object> clientOptions) {
SingleAddressHttpClientBuilder<HostAndPort, InetSocketAddress> builder = HttpClients.forSingleAddress(serverHostAndPort(serverContext)).protocols(toConfigs(protocols));
if (secure) {
builder.sslConfig(new ClientSslConfigBuilder(DefaultTestCerts::loadServerCAPem).sniHostname(serverPemHostname()).build());
}
for (@SuppressWarnings("rawtypes") Entry<SocketOption, Object> entry : clientOptions.entrySet()) {
@SuppressWarnings("unchecked") SocketOption<Object> option = entry.getKey();
builder.socketOption(option, entry.getValue());
}
return builder.buildBlocking();
}
use of io.servicetalk.transport.api.ClientSslConfigBuilder in project servicetalk by apple.
the class Tls13Test method requiredCipher.
@ParameterizedTest
@MethodSource("sslProviders")
void requiredCipher(SslProvider serverSslProvider, SslProvider clientSslProvider, @Nullable String cipher) throws Exception {
ServerSslConfigBuilder serverSslBuilder = new ServerSslConfigBuilder(DefaultTestCerts::loadServerPem, DefaultTestCerts::loadServerKey).sslProtocols(TLS1_3).provider(serverSslProvider);
if (cipher != null) {
serverSslBuilder.ciphers(singletonList(cipher));
}
try (ServerContext serverContext = forAddress(localAddress(0)).ioExecutor(SERVER_CTX.ioExecutor()).executor(SERVER_CTX.executor()).executionStrategy(defaultStrategy()).enableWireLogging("servicetalk-tests-wire-logger", TRACE, () -> false).sslConfig(serverSslBuilder.build()).listenBlockingAndAwait((ctx, request, responseFactory) -> {
assertThat(request.payloadBody(textSerializerUtf8()), equalTo("request-payload-body"));
SslConfig sslConfig = ctx.sslConfig();
assertThat(sslConfig, is(notNullValue()));
assertThat(sslConfig.sslProtocols(), contains(TLS1_3));
SSLSession sslSession = ctx.sslSession();
assertThat(sslSession, is(notNullValue()));
return responseFactory.ok().payloadBody(sslSession.getProtocol(), textSerializerUtf8());
})) {
ClientSslConfigBuilder clientSslBuilder = new ClientSslConfigBuilder(DefaultTestCerts::loadServerCAPem).sslProtocols(TLS1_3).peerHost(serverPemHostname()).provider(clientSslProvider);
if (cipher != null) {
clientSslBuilder.ciphers(singletonList(cipher));
}
try (BlockingHttpClient client = HttpClients.forSingleAddress(serverHostAndPort(serverContext)).ioExecutor(CLIENT_CTX.ioExecutor()).executor(CLIENT_CTX.executor()).executionStrategy(defaultStrategy()).enableWireLogging("servicetalk-tests-wire-logger", TRACE, Boolean.FALSE::booleanValue).sslConfig(clientSslBuilder.build()).buildBlocking();
BlockingHttpConnection connection = client.reserveConnection(client.get("/"))) {
SslConfig sslConfig = connection.connectionContext().sslConfig();
assertThat(sslConfig, is(notNullValue()));
assertThat(sslConfig.sslProtocols(), contains(TLS1_3));
SSLSession sslSession = connection.connectionContext().sslSession();
assertThat(sslSession, is(notNullValue()));
assertThat(sslSession.getProtocol(), equalTo(TLS1_3));
if (cipher != null) {
assertThat(sslSession.getCipherSuite(), equalTo(cipher));
}
HttpResponse response = client.request(client.post("/").payloadBody("request-payload-body", textSerializerUtf8()));
assertThat(response.status(), is(OK));
assertThat(response.headers().get(CONTENT_TYPE), is(TEXT_PLAIN_UTF_8));
assertThat(response.payloadBody(textSerializerUtf8()), equalTo(TLS1_3));
}
}
}
Aggregations