Build a gRPC client with mTLS (CA + client cert).
(
addr: SocketAddr,
ca_pem: Vec<u8>,
client_cert_pem: Vec<u8>,
client_key_pem: Vec<u8>,
)
| 648 | |
| 649 | /// Build a gRPC client with mTLS (CA + client cert). |
| 650 | pub async fn grpc_client_mtls( |
| 651 | addr: SocketAddr, |
| 652 | ca_pem: Vec<u8>, |
| 653 | client_cert_pem: Vec<u8>, |
| 654 | client_key_pem: Vec<u8>, |
| 655 | ) -> OpenShellClient<Channel> { |
| 656 | let ca_cert = tonic::transport::Certificate::from_pem(ca_pem); |
| 657 | let identity = tonic::transport::Identity::from_pem(client_cert_pem, client_key_pem); |
| 658 | let tls = ClientTlsConfig::new() |
| 659 | .ca_certificate(ca_cert) |
| 660 | .identity(identity) |
| 661 | .domain_name("localhost"); |
| 662 | let endpoint = Endpoint::from_shared(format!("https://localhost:{}", addr.port())) |
| 663 | .expect("invalid endpoint") |
| 664 | .tls_config(tls) |
| 665 | .expect("failed to set tls"); |
| 666 | let channel = endpoint.connect().await.expect("failed to connect"); |
| 667 | OpenShellClient::new(channel) |
| 668 | } |
no test coverage detected