Skip to content
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 .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[alias]
fmt-unstable = ["fmt", "--all", "--", "--config-path", ".rustfmt.unstable.toml"]
3 changes: 3 additions & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# keep in sync with .rustfmt.unstable.toml
chain_width = 40
style_edition = "2021"
7 changes: 7 additions & 0 deletions .rustfmt.unstable.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# keep in sync with .rustfmt.toml
chain_width = 40
style_edition = "2021"

# format imports
group_imports = "StdExternalCrate"
imports_granularity = "Module"
3 changes: 2 additions & 1 deletion ktls/src/cork_stream.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::{io, pin::Pin, task};
use std::pin::Pin;
use std::{io, task};

use rustls::internal::msgs::codec::Codec;
use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};
Expand Down
7 changes: 3 additions & 4 deletions ktls/src/ffi.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use std::os::unix::prelude::RawFd;

use ktls_sys::bindings as ktls;
use rustls::{
internal::msgs::{enums::AlertLevel, message::Message},
AlertDescription, ConnectionTrafficSecrets, SupportedCipherSuite,
};
use rustls::internal::msgs::enums::AlertLevel;
use rustls::internal::msgs::message::Message;
use rustls::{AlertDescription, ConnectionTrafficSecrets, SupportedCipherSuite};

pub(crate) const TLS_1_2_VERSION_NUMBER: u16 = (((ktls::TLS_1_2_VERSION_MAJOR & 0xFF) as u16) << 8)
| ((ktls::TLS_1_2_VERSION_MINOR & 0xFF) as u16);
Expand Down
27 changes: 14 additions & 13 deletions ktls/src/ktls_stream.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
use nix::{
errno::Errno,
sys::socket::{recvmsg, ControlMessageOwned, MsgFlags, SockaddrIn, TlsGetRecordType},
};
use num_enum::FromPrimitive;
use std::{
io::{self, IoSliceMut},
os::unix::prelude::AsRawFd,
pin::Pin,
task,
};
use std::io::{self, IoSliceMut};
use std::os::unix::prelude::AsRawFd;
use std::pin::Pin;
use std::task;

use nix::errno::Errno;
use nix::sys::socket::{ControlMessageOwned, MsgFlags, SockaddrIn, TlsGetRecordType, recvmsg};
use num_enum::FromPrimitive;
use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};

use crate::AsyncReadReady;
Expand Down Expand Up @@ -163,7 +159,10 @@ where
}
TlsGetRecordType::Alert => {
// the alert level and description are in iovs
let iov = r.iovs().next().expect("expected data in iovs");
let iov = r
.iovs()
.next()
.expect("expected data in iovs");

let (level, description) = match iov {
[] => {
Expand Down Expand Up @@ -230,7 +229,9 @@ where
);
}
TlsGetRecordType::ApplicationData => {
unreachable!("received TLS application in recvmsg, this is supposed to happen in the poll_read codepath")
unreachable!(
"received TLS application in recvmsg, this is supposed to happen in the poll_read codepath"
)
}
TlsGetRecordType::Unknown(t) => {
// just ignore the record?
Expand Down
63 changes: 33 additions & 30 deletions ktls/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,40 +1,34 @@
use ffi::{setup_tls_info, setup_ulp, KtlsCompatibilityError};
use futures_util::future::try_join_all;
use ktls_sys::bindings as sys;
use rustls::{Connection, SupportedCipherSuite, SupportedProtocolVersion};

#[cfg(all(not(feature = "ring"), not(feature = "aws_lc_rs")))]
compile_error!("This crate needs wither the 'ring' or 'aws_lc_rs' feature enabled");
#[cfg(all(feature = "ring", feature = "aws_lc_rs"))]
compile_error!("The 'ring' and 'aws_lc_rs' features are mutually exclusive");

mod async_read_ready;
mod cork_stream;
mod ffi;
mod ktls_stream;

use std::future::Future;
use std::io;
use std::net::SocketAddr;
use std::os::unix::prelude::{AsRawFd, RawFd};

use futures_util::future::try_join_all;
use ktls_sys::bindings as sys;
#[cfg(feature = "aws_lc_rs")]
use rustls::crypto::aws_lc_rs::cipher_suite;
#[cfg(feature = "ring")]
use rustls::crypto::ring::cipher_suite;

use rustls::{Connection, SupportedCipherSuite, SupportedProtocolVersion};
use smallvec::SmallVec;
use std::{
future::Future,
io,
net::SocketAddr,
os::unix::prelude::{AsRawFd, RawFd},
};
use tokio::{
io::{AsyncRead, AsyncReadExt, AsyncWrite},
net::{TcpListener, TcpStream},
};
use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite};
use tokio::net::{TcpListener, TcpStream};

mod ffi;
pub use crate::async_read_ready::AsyncReadReady;
pub use crate::cork_stream::CorkStream;
pub use crate::ffi::CryptoInfo;

mod async_read_ready;
pub use async_read_ready::AsyncReadReady;

mod ktls_stream;
pub use ktls_stream::KtlsStream;

mod cork_stream;
pub use cork_stream::CorkStream;
use crate::ffi::{KtlsCompatibilityError, setup_tls_info, setup_ulp};
pub use crate::ktls_stream::KtlsStream;

#[derive(Debug, Default)]
pub struct CompatibleCiphers {
Expand Down Expand Up @@ -70,7 +64,9 @@ impl CompatibleCiphers {
}
};

ciphers.test_ciphers(local_addr, accept_conns_fut).await?;
ciphers
.test_ciphers(local_addr, accept_conns_fut)
.await?;

Ok(ciphers)
}
Expand Down Expand Up @@ -252,7 +248,9 @@ where
IO: AsRawFd + AsyncRead + AsyncReadReady + AsyncWrite + Unpin,
{
stream.get_mut().0.corked = true;
let drained = drain(&mut stream).await.map_err(Error::DrainError)?;
let drained = drain(&mut stream)
.await
.map_err(Error::DrainError)?;
let (io, conn) = stream.into_inner();
let io = io.io;

Expand All @@ -273,7 +271,9 @@ where
IO: AsRawFd + AsyncRead + AsyncWrite + Unpin,
{
stream.get_mut().0.corked = true;
let drained = drain(&mut stream).await.map_err(Error::DrainError)?;
let drained = drain(&mut stream)
.await
.map_err(Error::DrainError)?;
let (io, conn) = stream.into_inner();
let io = io.io;

Expand All @@ -290,7 +290,10 @@ async fn drain(stream: &mut (impl AsyncRead + Unpin)) -> std::io::Result<Option<

loop {
tracing::trace!("stream.read called");
let n = match stream.read(&mut drained[filled..]).await {
let n = match stream
.read(&mut drained[filled..])
.await
{
Ok(n) => n,
Err(ref e) if e.kind() == std::io::ErrorKind::UnexpectedEof => {
// actually this is expected for us!
Expand Down
Loading