Skip to content

Commit 3bcef0d

Browse files
committed
make s2a default to pqc key exchange group
1 parent fd971d1 commit 3bcef0d

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

s2a/src/main/java/io/grpc/s2a/internal/handshaker/SslContextFactory.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ static SslContext createForClient(
9292
S2ATrustManager.createForClient(stub, targetName, localIdentity));
9393
sslContextBuilder.option(
9494
OpenSslContextOption.PRIVATE_KEY_METHOD, S2APrivateKeyMethod.create(stub, localIdentity));
95+
sslContextBuilder.option(
96+
OpenSslContextOption.GROUPS,
97+
new String[] {"X25519MLKEM768", "x25519", "secp256r1", "secp384r1", "secp521r1"});
9598

9699
SslContext sslContext = sslContextBuilder.build();
97100
SSLSessionContext sslSessionContext = sslContext.sessionContext();

s2a/src/test/java/io/grpc/s2a/IntegrationTest.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import io.grpc.testing.protobuf.SimpleResponse;
4545
import io.grpc.testing.protobuf.SimpleServiceGrpc;
4646
import io.netty.handler.ssl.ClientAuth;
47+
import io.netty.handler.ssl.OpenSslContextOption;
4748
import io.netty.handler.ssl.OpenSslSessionContext;
4849
import io.netty.handler.ssl.SslContext;
4950
import io.netty.handler.ssl.SslContextBuilder;
@@ -253,4 +254,41 @@ public void unaryRpc(SimpleRequest request, StreamObserver<SimpleResponse> obser
253254
observer.onCompleted();
254255
}
255256
}
257+
258+
@Test
259+
public void clientCommunicateWithPqcRequiredServer_succeeds() throws Exception {
260+
ClassLoader classLoader = IntegrationTest.class.getClassLoader();
261+
SslContextBuilder serverSslContextBuilder =
262+
SslContextBuilder.forServer(
263+
classLoader.getResourceAsStream("cert_chain_ec.pem"),
264+
classLoader.getResourceAsStream("leaf_key_ec.pem"));
265+
SslContext serverSslContext =
266+
GrpcSslContexts.configure(serverSslContextBuilder, SslProvider.OPENSSL)
267+
.protocols("TLSv1.3")
268+
.trustManager(classLoader.getResourceAsStream("root_cert_ec.pem"))
269+
.clientAuth(ClientAuth.REQUIRE)
270+
.option(OpenSslContextOption.GROUPS, new String[] {"X25519MLKEM768"})
271+
.build();
272+
273+
Server pqcServer =
274+
NettyServerBuilder.forPort(0)
275+
.addService(new SimpleServiceImpl())
276+
.sslContext(serverSslContext)
277+
.build()
278+
.start();
279+
int pqcServerPort = pqcServer.getPort();
280+
String pqcServerAddress = "localhost:" + pqcServerPort;
281+
282+
try {
283+
ChannelCredentials credentials =
284+
S2AChannelCredentials.newBuilder(s2aAddress, InsecureChannelCredentials.create())
285+
.setLocalSpiffeId("test-spiffe-id").build();
286+
ManagedChannel channel = Grpc.newChannelBuilder(pqcServerAddress, credentials).build();
287+
288+
assertThat(doUnaryRpc(channel)).isTrue();
289+
} finally {
290+
pqcServer.shutdown();
291+
pqcServer.awaitTermination(10, SECONDS);
292+
}
293+
}
256294
}

0 commit comments

Comments
 (0)