Skip to content

Commit

Permalink
docs(tls): Add an example in rust
Browse files Browse the repository at this point in the history
  • Loading branch information
mxxntype committed May 23, 2024
1 parent ca50094 commit 878fc0e
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tls/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
> [!CAUTION]
> These TLS CA certificates and private keys are given as example ones to showcase SSL/TLS capabilities of the server and client. We are not generating them automatically using Certbot or something else for ease of deployment.
### An example of connecting to a TLS-enabled gRPC server in Go

```go
package main

Expand Down Expand Up @@ -50,3 +52,25 @@ func main() {
log.Printf("Greeting: %s", r.GetMessage())
}
```

### An example of doing the same in Rust

```rust
use tcp_chat::proto::registry_client::RegistryClient;
use tonic::transport::{Certificate, ClientTlsConfig, Channel};

const CERT: &str = include_str!("./ca.pem");

let channel = Channel::from_static("https://localhost:9001")
.tls_config(
ClientTlsConfig::new()
.ca_certificate(Certificate::from_pem(CERT))
.domain_name("example.com"),
)
.unwrap()
.connect()
.await
.unwrap();

let mut registry = RegistryClient::new(channel);
```

0 comments on commit 878fc0e

Please sign in to comment.