fix(transport): Remove with_rustls for tls config (#188)
This commit is contained in:
@@ -27,7 +27,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
|
|
||||||
let certs = tokio::fs::read("tonic-examples/data/gcp/roots.pem").await?;
|
let certs = tokio::fs::read("tonic-examples/data/gcp/roots.pem").await?;
|
||||||
|
|
||||||
let tls_config = ClientTlsConfig::with_rustls()
|
let tls_config = ClientTlsConfig::new()
|
||||||
.ca_certificate(Certificate::from_pem(certs.as_slice()))
|
.ca_certificate(Certificate::from_pem(certs.as_slice()))
|
||||||
.domain_name("pubsub.googleapis.com");
|
.domain_name("pubsub.googleapis.com");
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let pem = tokio::fs::read("tonic-examples/data/tls/ca.pem").await?;
|
let pem = tokio::fs::read("tonic-examples/data/tls/ca.pem").await?;
|
||||||
let ca = Certificate::from_pem(pem);
|
let ca = Certificate::from_pem(pem);
|
||||||
|
|
||||||
let tls = ClientTlsConfig::with_rustls()
|
let tls = ClientTlsConfig::new()
|
||||||
.ca_certificate(ca)
|
.ca_certificate(ca)
|
||||||
.domain_name("example.com");
|
.domain_name("example.com");
|
||||||
|
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let server = EchoServer::default();
|
let server = EchoServer::default();
|
||||||
|
|
||||||
Server::builder()
|
Server::builder()
|
||||||
.tls_config(ServerTlsConfig::with_rustls().identity(identity))
|
.tls_config(ServerTlsConfig::new().identity(identity))
|
||||||
.add_service(pb::echo_server::EchoServer::new(server))
|
.add_service(pb::echo_server::EchoServer::new(server))
|
||||||
.serve(addr)
|
.serve(addr)
|
||||||
.await?;
|
.await?;
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let client_key = tokio::fs::read("tonic-examples/data/tls/client1.key").await?;
|
let client_key = tokio::fs::read("tonic-examples/data/tls/client1.key").await?;
|
||||||
let client_identity = Identity::from_pem(client_cert, client_key);
|
let client_identity = Identity::from_pem(client_cert, client_key);
|
||||||
|
|
||||||
let tls = ClientTlsConfig::with_rustls()
|
let tls = ClientTlsConfig::new()
|
||||||
.domain_name("localhost")
|
.domain_name("localhost")
|
||||||
.ca_certificate(server_root_ca_cert)
|
.ca_certificate(server_root_ca_cert)
|
||||||
.identity(client_identity);
|
.identity(client_identity);
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let addr = "[::1]:50051".parse().unwrap();
|
let addr = "[::1]:50051".parse().unwrap();
|
||||||
let server = EchoServer::default();
|
let server = EchoServer::default();
|
||||||
|
|
||||||
let tls = ServerTlsConfig::with_rustls()
|
let tls = ServerTlsConfig::new()
|
||||||
.identity(server_identity)
|
.identity(server_identity)
|
||||||
.client_ca_root(client_ca_cert);
|
.client_ca_root(client_ca_cert);
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let pem = tokio::fs::read("interop/data/ca.pem").await?;
|
let pem = tokio::fs::read("interop/data/ca.pem").await?;
|
||||||
let ca = Certificate::from_pem(pem);
|
let ca = Certificate::from_pem(pem);
|
||||||
endpoint = endpoint.tls_config(
|
endpoint = endpoint.tls_config(
|
||||||
ClientTlsConfig::with_rustls()
|
ClientTlsConfig::new()
|
||||||
.ca_certificate(ca)
|
.ca_certificate(ca)
|
||||||
.domain_name("foo.test.google.fr"),
|
.domain_name("foo.test.google.fr"),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ async fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
|
|||||||
let key = tokio::fs::read("interop/data/server1.key").await?;
|
let key = tokio::fs::read("interop/data/server1.key").await?;
|
||||||
let identity = Identity::from_pem(cert, key);
|
let identity = Identity::from_pem(cert, key);
|
||||||
|
|
||||||
builder = builder.tls_config(ServerTlsConfig::with_rustls().identity(identity));
|
builder = builder.tls_config(ServerTlsConfig::new().identity(identity));
|
||||||
}
|
}
|
||||||
|
|
||||||
let test_service = server::TestServiceServer::new(server::TestService::default());
|
let test_service = server::TestServiceServer::new(server::TestService::default());
|
||||||
|
|||||||
@@ -167,6 +167,7 @@ impl Endpoint {
|
|||||||
|
|
||||||
/// Configures TLS for the endpoint.
|
/// Configures TLS for the endpoint.
|
||||||
#[cfg(feature = "tls")]
|
#[cfg(feature = "tls")]
|
||||||
|
#[cfg_attr(docsrs, doc(cfg(feature = "tls")))]
|
||||||
pub fn tls_config(self, tls_config: ClientTlsConfig) -> Self {
|
pub fn tls_config(self, tls_config: ClientTlsConfig) -> Self {
|
||||||
Endpoint {
|
Endpoint {
|
||||||
tls: Some(tls_config.tls_connector(self.uri.clone()).unwrap()),
|
tls: Some(tls_config.tls_connector(self.uri.clone()).unwrap()),
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
mod endpoint;
|
mod endpoint;
|
||||||
#[cfg(feature = "tls")]
|
#[cfg(feature = "tls")]
|
||||||
|
#[cfg_attr(docsrs, doc(cfg(feature = "tls")))]
|
||||||
mod tls;
|
mod tls;
|
||||||
|
|
||||||
pub use endpoint::Endpoint;
|
pub use endpoint::Endpoint;
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ use std::fmt;
|
|||||||
|
|
||||||
/// Configures TLS settings for endpoints.
|
/// Configures TLS settings for endpoints.
|
||||||
#[cfg(feature = "tls")]
|
#[cfg(feature = "tls")]
|
||||||
|
#[cfg_attr(docsrs, doc(cfg(feature = "tls")))]
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct ClientTlsConfig {
|
pub struct ClientTlsConfig {
|
||||||
domain: Option<String>,
|
domain: Option<String>,
|
||||||
@@ -29,7 +30,7 @@ impl fmt::Debug for ClientTlsConfig {
|
|||||||
#[cfg(feature = "tls")]
|
#[cfg(feature = "tls")]
|
||||||
impl ClientTlsConfig {
|
impl ClientTlsConfig {
|
||||||
/// Creates a new `ClientTlsConfig` using Rustls.
|
/// Creates a new `ClientTlsConfig` using Rustls.
|
||||||
pub fn with_rustls() -> Self {
|
pub fn new() -> Self {
|
||||||
ClientTlsConfig {
|
ClientTlsConfig {
|
||||||
domain: None,
|
domain: None,
|
||||||
cert: None,
|
cert: None,
|
||||||
|
|||||||
@@ -107,8 +107,10 @@ pub use self::tls::{Certificate, Identity};
|
|||||||
pub use hyper::Body;
|
pub use hyper::Body;
|
||||||
|
|
||||||
#[cfg(feature = "tls")]
|
#[cfg(feature = "tls")]
|
||||||
|
#[cfg_attr(docsrs, doc(cfg(feature = "tls")))]
|
||||||
pub use self::channel::ClientTlsConfig;
|
pub use self::channel::ClientTlsConfig;
|
||||||
#[cfg(feature = "tls")]
|
#[cfg(feature = "tls")]
|
||||||
|
#[cfg_attr(docsrs, doc(cfg(feature = "tls")))]
|
||||||
pub use self::server::ServerTlsConfig;
|
pub use self::server::ServerTlsConfig;
|
||||||
|
|
||||||
pub(crate) use self::error::ErrorKind;
|
pub(crate) use self::error::ErrorKind;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
mod conn;
|
mod conn;
|
||||||
mod incoming;
|
mod incoming;
|
||||||
#[cfg(feature = "tls")]
|
#[cfg(feature = "tls")]
|
||||||
|
#[cfg_attr(docsrs, doc(cfg(feature = "tls")))]
|
||||||
mod tls;
|
mod tls;
|
||||||
|
|
||||||
pub use conn::Connected;
|
pub use conn::Connected;
|
||||||
@@ -98,6 +99,7 @@ impl Server {
|
|||||||
impl Server {
|
impl Server {
|
||||||
/// Configure TLS for this server.
|
/// Configure TLS for this server.
|
||||||
#[cfg(feature = "tls")]
|
#[cfg(feature = "tls")]
|
||||||
|
#[cfg_attr(docsrs, doc(cfg(feature = "tls")))]
|
||||||
pub fn tls_config(self, tls_config: ServerTlsConfig) -> Self {
|
pub fn tls_config(self, tls_config: ServerTlsConfig) -> Self {
|
||||||
Server {
|
Server {
|
||||||
tls: Some(tls_config.tls_acceptor().unwrap()),
|
tls: Some(tls_config.tls_acceptor().unwrap()),
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ use std::fmt;
|
|||||||
|
|
||||||
/// Configures TLS settings for servers.
|
/// Configures TLS settings for servers.
|
||||||
#[cfg(feature = "tls")]
|
#[cfg(feature = "tls")]
|
||||||
|
#[cfg_attr(docsrs, doc(cfg(feature = "tls")))]
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct ServerTlsConfig {
|
pub struct ServerTlsConfig {
|
||||||
identity: Option<Identity>,
|
identity: Option<Identity>,
|
||||||
@@ -23,7 +24,7 @@ impl fmt::Debug for ServerTlsConfig {
|
|||||||
#[cfg(feature = "tls")]
|
#[cfg(feature = "tls")]
|
||||||
impl ServerTlsConfig {
|
impl ServerTlsConfig {
|
||||||
/// Creates a new `ServerTlsConfig`.
|
/// Creates a new `ServerTlsConfig`.
|
||||||
pub fn with_rustls() -> Self {
|
pub fn new() -> Self {
|
||||||
ServerTlsConfig {
|
ServerTlsConfig {
|
||||||
identity: None,
|
identity: None,
|
||||||
client_ca_root: None,
|
client_ca_root: None,
|
||||||
|
|||||||
Reference in New Issue
Block a user