Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

geyser: Add option to allow the injection of a root authority #497

Merged
merged 3 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ The minor version will be incremented upon a breaking change and the patch versi

### Features

- client: add `ca_certificate` option ([#497](https://github.com/rpcpool/yellowstone-grpc/pull/497))

### Breaking

## 2024-12-15
Expand Down
14 changes: 12 additions & 2 deletions examples/rust/src/bin/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -52,6 +53,10 @@ struct Args {
/// Service endpoint
endpoint: String,

/// Path of a certificate authority file
#[clap(long)]
ca_certificate: Option<PathBuf>,

#[clap(long)]
x_token: Option<String>,

Expand Down Expand Up @@ -117,9 +122,14 @@ impl Args {
}

async fn connect(&self) -> anyhow::Result<GeyserGrpcClient<impl Interceptor>> {
let mut tls_config = ClientTlsConfig::new().with_native_roots();
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())?
.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 {
Expand Down