From 440a98d81e0a84077612a9592bd6da048f6c9e3c Mon Sep 17 00:00:00 2001 From: Caio Date: Mon, 16 Dec 2024 09:32:35 -0300 Subject: [PATCH 1/3] Add 'ca_certificate' option --- examples/rust/src/bin/client.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/examples/rust/src/bin/client.rs b/examples/rust/src/bin/client.rs index fbca240b..516d0df2 100644 --- a/examples/rust/src/bin/client.rs +++ b/examples/rust/src/bin/client.rs @@ -12,11 +12,12 @@ use { collections::HashMap, env, fs::File, + path::PathBuf, sync::Arc, 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 +49,10 @@ type BlocksMetaFilterMap = HashMap; #[derive(Debug, Clone, Parser)] #[clap(author, version, about)] struct Args { + /// Path of a certificate authority file + #[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 +122,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 { From 8aaafc46984d8e52be6c5f1c9c232ef1cda87912 Mon Sep 17 00:00:00 2001 From: Caio Date: Mon, 16 Dec 2024 17:42:19 -0300 Subject: [PATCH 2/3] Add to changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 41a5429f..df680dfc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,8 @@ The minor version will be incremented upon a breaking change and the patch versi ### Features +- geyser: Add option to allow the injection of a root authority ([#497](https://github.com/rpcpool/yellowstone-grpc/pull/497)) + ### Breaking ## 2024-12-15 From c01153b056cf6173f150a8e9a1010eaad4660284 Mon Sep 17 00:00:00 2001 From: Kirill Fomichev Date: Mon, 16 Dec 2024 16:07:32 -0500 Subject: [PATCH 3/3] read to buf --- CHANGELOG.md | 2 +- examples/rust/src/bin/client.rs | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index df680dfc..c9adf8fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,7 @@ The minor version will be incremented upon a breaking change and the patch versi ### Features -- geyser: Add option to allow the injection of a root authority ([#497](https://github.com/rpcpool/yellowstone-grpc/pull/497)) +- client: add `ca_certificate` option ([#497](https://github.com/rpcpool/yellowstone-grpc/pull/497)) ### Breaking diff --git a/examples/rust/src/bin/client.rs b/examples/rust/src/bin/client.rs index 516d0df2..fe3afa6e 100644 --- a/examples/rust/src/bin/client.rs +++ b/examples/rust/src/bin/client.rs @@ -49,14 +49,14 @@ type BlocksMetaFilterMap = HashMap; #[derive(Debug, Clone, Parser)] #[clap(author, version, about)] struct Args { - /// Path of a certificate authority file - #[clap(long)] - ca_certificate: Option, - #[clap(short, long, default_value_t = String::from("http://127.0.0.1:10000"))] /// Service endpoint endpoint: String, + /// Path of a certificate authority file + #[clap(long)] + ca_certificate: Option, + #[clap(long)] x_token: Option, @@ -123,9 +123,9 @@ 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())); + if let Some(path) = &self.ca_certificate { + let bytes = fs::read(path).await?; + tls_config = tls_config.ca_certificate(Certificate::from_pem(bytes)); } let mut builder = GeyserGrpcClient::build_from_shared(self.endpoint.clone())? .x_token(self.x_token.clone())?