|
51 | 51 | import io.grpc.Status; |
52 | 52 | import io.grpc.StatusOr; |
53 | 53 | import io.grpc.StatusRuntimeException; |
| 54 | +import io.grpc.TlsServerCredentials; |
54 | 55 | import io.grpc.stub.StreamObserver; |
55 | 56 | import io.grpc.testing.GrpcCleanupRule; |
| 57 | +import io.grpc.testing.TlsTesting; |
56 | 58 | import io.grpc.testing.protobuf.SimpleRequest; |
57 | 59 | import io.grpc.testing.protobuf.SimpleResponse; |
58 | 60 | import io.grpc.testing.protobuf.SimpleServiceGrpc; |
@@ -513,6 +515,36 @@ public void mtlsClientServer_changeServerContext_expectException() |
513 | 515 | } |
514 | 516 | } |
515 | 517 |
|
| 518 | + @Test |
| 519 | + public void mtlsClientServer_withClientAuthentication_withTlsChannelCredsFromBootstrap() |
| 520 | + throws Exception { |
| 521 | + final String mtlsCertProviderInstanceName = "mtls_channel_creds_identity_certs"; |
| 522 | + |
| 523 | + UpstreamTlsContext upstreamTlsContext = |
| 524 | + setBootstrapInfoWithMTlsChannelCredsAndBuildUpstreamTlsContext( |
| 525 | + mtlsCertProviderInstanceName, CLIENT_KEY_FILE, CLIENT_PEM_FILE, CA_PEM_FILE); |
| 526 | + |
| 527 | + DownstreamTlsContext downstreamTlsContext = |
| 528 | + setBootstrapInfoWithMTlsChannelCredsAndBuildDownstreamTlsContext( |
| 529 | + mtlsCertProviderInstanceName, SERVER_1_KEY_FILE, SERVER_1_PEM_FILE, CA_PEM_FILE); |
| 530 | + |
| 531 | + ServerCredentials serverCreds = TlsServerCredentials.newBuilder() |
| 532 | + .keyManager(TlsTesting.loadCert(SERVER_1_PEM_FILE), TlsTesting.loadCert(SERVER_1_KEY_FILE)) |
| 533 | + .trustManager(TlsTesting.loadCert(CA_PEM_FILE)) |
| 534 | + .clientAuth(TlsServerCredentials.ClientAuth.REQUIRE) |
| 535 | + .build(); |
| 536 | + |
| 537 | + buildServer( |
| 538 | + XdsServerBuilder.forPort(0, serverCreds) |
| 539 | + .xdsClientPoolFactory(fakePoolFactory) |
| 540 | + .addService(new SimpleServiceImpl()), |
| 541 | + downstreamTlsContext); |
| 542 | + |
| 543 | + SimpleServiceGrpc.SimpleServiceBlockingStub blockingStub = |
| 544 | + getBlockingStub(upstreamTlsContext, OVERRIDE_AUTHORITY); |
| 545 | + assertThat(unaryRpc("buddy", blockingStub)).isEqualTo("Hello buddy"); |
| 546 | + } |
| 547 | + |
516 | 548 | private void performMtlsTestAndGetListenerWatcher( |
517 | 549 | UpstreamTlsContext upstreamTlsContext, String certInstanceName2, |
518 | 550 | String privateKey2, String cert2, String trustCa2) |
@@ -573,6 +605,22 @@ private UpstreamTlsContext setBootstrapInfoAndBuildUpstreamTlsContextForUsingSys |
573 | 605 | .build()); |
574 | 606 | } |
575 | 607 |
|
| 608 | + private UpstreamTlsContext setBootstrapInfoWithMTlsChannelCredsAndBuildUpstreamTlsContext( |
| 609 | + String instanceName, String clientKeyFile, String clientPemFile, String caCertFile) { |
| 610 | + bootstrapInfoForClient = CommonBootstrapperTestUtils |
| 611 | + .buildBootstrapInfoForMTlsChannelCredentialServerInfo( |
| 612 | + instanceName, clientKeyFile, clientPemFile, caCertFile); |
| 613 | + return CommonTlsContextTestsUtil.buildUpstreamTlsContext(instanceName, true); |
| 614 | + } |
| 615 | + |
| 616 | + private DownstreamTlsContext setBootstrapInfoWithMTlsChannelCredsAndBuildDownstreamTlsContext( |
| 617 | + String instanceName, String serverKeyFile, String serverPemFile, String caCertFile) { |
| 618 | + bootstrapInfoForServer = CommonBootstrapperTestUtils |
| 619 | + .buildBootstrapInfoForMTlsChannelCredentialServerInfo( |
| 620 | + instanceName, serverKeyFile, serverPemFile, caCertFile); |
| 621 | + return CommonTlsContextTestsUtil.buildDownstreamTlsContext(instanceName, true, true); |
| 622 | + } |
| 623 | + |
576 | 624 | private void buildServerWithTlsContext(DownstreamTlsContext downstreamTlsContext) |
577 | 625 | throws Exception { |
578 | 626 | buildServerWithTlsContext(downstreamTlsContext, InsecureServerCredentials.create()); |
|
0 commit comments