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

Keep TLS transport items together in a single module #1778

Closed
wants to merge 6 commits into from
Closed
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
8 changes: 3 additions & 5 deletions tonic/src/transport/channel/service/tls.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::fmt;
use std::io::Cursor;
use std::sync::Arc;

use hyper_util::rt::TokioIo;
Expand All @@ -10,8 +9,7 @@ use tokio_rustls::{
};

use super::io::BoxedIo;
use crate::transport::service::tls::{add_certs_from_pem, load_identity, TlsError, ALPN_H2};
use crate::transport::tls::{Certificate, Identity};
use crate::transport::tls::{Certificate, Identity, TlsError, ALPN_H2};

#[derive(Clone)]
pub(crate) struct TlsConnector {
Expand Down Expand Up @@ -43,13 +41,13 @@ impl TlsConnector {
}

for cert in ca_certs {
add_certs_from_pem(&mut Cursor::new(cert), &mut roots)?;
roots.add_parsable_certificates(cert.to_der_certificates()?);
}

let builder = builder.with_root_certificates(roots);
let mut config = match identity {
Some(identity) => {
let (client_cert, client_key) = load_identity(identity)?;
let (client_cert, client_key) = identity.to_der_parts()?;
builder.with_client_auth_cert(client_cert, client_key)?
}
None => builder.with_no_client_auth(),
Expand Down
11 changes: 4 additions & 7 deletions tonic/src/transport/server/service/tls.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{fmt, io::Cursor, sync::Arc};
use std::{fmt, sync::Arc};

use tokio::io::{AsyncRead, AsyncWrite};
use tokio_rustls::{
Expand All @@ -7,10 +7,7 @@ use tokio_rustls::{
TlsAcceptor as RustlsAcceptor,
};

use crate::transport::{
service::tls::{add_certs_from_pem, load_identity, ALPN_H2},
Certificate, Identity,
};
use crate::transport::tls::{Certificate, Identity, ALPN_H2};

#[derive(Clone)]
pub(crate) struct TlsAcceptor {
Expand All @@ -29,7 +26,7 @@ impl TlsAcceptor {
None => builder.with_no_client_auth(),
Some(cert) => {
let mut roots = RootCertStore::empty();
add_certs_from_pem(&mut Cursor::new(cert), &mut roots)?;
roots.add_parsable_certificates(cert.to_der_certificates()?);
let verifier = if client_auth_optional {
WebPkiClientVerifier::builder(roots.into()).allow_unauthenticated()
} else {
Expand All @@ -40,7 +37,7 @@ impl TlsAcceptor {
}
};

let (cert, key) = load_identity(identity)?;
let (cert, key) = identity.to_der_parts()?;
let mut config = builder.with_single_cert(cert, key)?;

config.alpn_protocols.push(ALPN_H2.into());
Expand Down
263 changes: 0 additions & 263 deletions tonic/src/transport/service/grpc_timeout.rs

This file was deleted.

Loading