From 74981d52b65dfaac21019a092ab65db4fb4f03ab Mon Sep 17 00:00:00 2001 From: Caio Date: Mon, 16 Dec 2024 08:14:23 -0300 Subject: [PATCH] Add `ca_certificate` option --- examples/rust/src/bin/client.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/examples/rust/src/bin/client.rs b/examples/rust/src/bin/client.rs index fbca240b..a045015a 100644 --- a/examples/rust/src/bin/client.rs +++ b/examples/rust/src/bin/client.rs @@ -16,7 +16,7 @@ use { time::{Duration, Instant, SystemTime, UNIX_EPOCH}, }, tokio::{fs, sync::Mutex}, - tonic::transport::channel::ClientTlsConfig, + tonic::transport::{channel::ClientTlsConfig, Certificate}, yellowstone_grpc_client::{GeyserGrpcClient, GeyserGrpcClientError, Interceptor}, yellowstone_grpc_proto::{ convert_from, @@ -48,6 +48,9 @@ type BlocksMetaFilterMap = HashMap; #[derive(Debug, Clone, Parser)] #[clap(author, version, about)] struct Args { + #[clap(long)] + ca_certificate: Option, + #[clap(short, long, default_value_t = String::from("http://127.0.0.1:10000"))] /// Service endpoint endpoint: String, @@ -117,9 +120,14 @@ impl Args { } async fn connect(&self) -> anyhow::Result> { + let mut tls_config = ClientTlsConfig::new().with_native_roots(); + if let Some(file_name) = &self.ca_certificate { + let contents = fs::read_to_string(file_name).await?; + tls_config = tls_config.ca_certificate(Certificate::from_pem(contents.as_bytes())); + } let mut builder = GeyserGrpcClient::build_from_shared(self.endpoint.clone())? .x_token(self.x_token.clone())? - .tls_config(ClientTlsConfig::new().with_native_roots())? + .tls_config(tls_config)? .max_decoding_message_size(self.max_decoding_message_size); if let Some(duration) = self.connect_timeout_ms {