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

Fix wrong assert if padding is disabled #21

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a00ecd0
Fix padding
simc Mar 19, 2021
80c04df
Update symm.rs
simc Mar 19, 2021
1ef88b4
Make rustfmt happy
simc Mar 23, 2021
dd04ec0
Provide access to inner I/O error during handshake
nox Apr 6, 2021
e13112e
Allow uppercase acronyms
nox Apr 6, 2021
3838b11
Merge pull request #25 from nox/expose-io-error
inikulin Apr 6, 2021
f4b8870
Bump boring-sys to 1.1.1, tokio-boring to 2.1.2
nox Apr 6, 2021
c4e1966
Merge pull request #26 from nox/bump
inikulin Apr 6, 2021
6baba64
Allow returning the server name from the early callback
nox Apr 13, 2021
d147f15
Allow retrieving the version string from early callback
nox Apr 13, 2021
10e472f
Merge pull request #28 from nox/early-servername
inikulin Apr 13, 2021
c85bf09
Bump boring to 1.1.5
nox Apr 13, 2021
90a195c
Merge pull request #29 from nox/bump
inikulin Apr 13, 2021
fbdcfc3
Introduce ClientHello::client_version
nox Apr 16, 2021
4473d08
Introduce HandshakeError::code
nox Apr 16, 2021
61e69eb
Merge pull request #31 from nox/unexpected-eof
inikulin Apr 16, 2021
dbc4e70
Merge pull request #30 from nox/client-version
inikulin Apr 16, 2021
77ef82c
Bump boring to 1.1.6
nox Apr 16, 2021
c8f13f2
Merge pull request #32 from nox/bump
inikulin Apr 16, 2021
72e347d
Bump tokio-boring to 2.1.3
nox Apr 16, 2021
9cb2e41
Merge pull request #33 from nox/bump
inikulin Apr 16, 2021
aee53a2
Fix padding
simc Mar 19, 2021
da3cc53
Update symm.rs
simc Mar 19, 2021
0024f43
Make rustfmt happy
simc Mar 23, 2021
e64317c
Merge branch 'master' of https://github.com/isar/boring
simc Apr 22, 2021
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: 1 addition & 1 deletion boring-sys/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "boring-sys"
version = "1.1.0"
version = "1.1.1"
authors = ["Alex Crichton <[email protected]>",
"Steven Fackler <[email protected]>",
"Ivan Nikulin <[email protected]>"]
Expand Down
1 change: 1 addition & 0 deletions boring-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
clippy::redundant_static_lifetimes,
clippy::too_many_arguments,
clippy::unreadable_literal,
clippy::upper_case_acronyms,
improper_ctypes,
non_camel_case_types,
non_snake_case,
Expand Down
2 changes: 1 addition & 1 deletion boring/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "boring"
version = "1.1.4"
version = "1.1.6"
authors = ["Steven Fackler <[email protected]>", "Ivan Nikulin <[email protected]>"]
license = "Apache-2.0"
description = "BoringSSL bindings"
Expand Down
2 changes: 1 addition & 1 deletion boring/src/ssl/bio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ use ffi::{BIO_get_data, BIO_set_data, BIO_set_flags, BIO_set_init};
#[allow(bad_style)]
unsafe fn BIO_set_num(_bio: *mut ffi::BIO, _num: c_int) {}

#[allow(bad_style)]
#[allow(bad_style, clippy::upper_case_acronyms)]
struct BIO_METHOD(*mut ffi::BIO_METHOD);

impl BIO_METHOD {
Expand Down
47 changes: 46 additions & 1 deletion boring/src/ssl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ impl From<u16> for ExtensionType {
}

/// An SSL/TLS protocol version.
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[derive(Copy, Clone, PartialEq, Eq)]
pub struct SslVersion(u16);

impl SslVersion {
Expand All @@ -540,6 +540,32 @@ impl SslVersion {
pub const TLS1_3: SslVersion = SslVersion(ffi::TLS1_3_VERSION as _);
}

impl fmt::Debug for SslVersion {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str(match *self {
Self::SSL3 => "SSL3",
Self::TLS1 => "TLS1",
Self::TLS1_1 => "TLS1_1",
Self::TLS1_2 => "TLS1_2",
Self::TLS1_3 => "TLS1_3",
_ => return write!(f, "{:#06x}", self.0),
})
}
}

impl fmt::Display for SslVersion {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str(match *self {
Self::SSL3 => "SSLv3",
Self::TLS1 => "TLSv1",
Self::TLS1_1 => "TLSv1.1",
Self::TLS1_2 => "TLSv1.2",
Self::TLS1_3 => "TLSv1.3",
_ => return write!(f, "unknown ({:#06x})", self.0),
})
}
}

/// A signature verification algorithm.
#[repr(transparent)]
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
Expand Down Expand Up @@ -1779,6 +1805,25 @@ impl ClientHello {
Some(slice::from_raw_parts(ptr, len))
}
}

fn ssl(&self) -> &SslRef {
unsafe { SslRef::from_ptr(self.0.ssl) }
}

/// Returns the servername sent by the client via Server Name Indication (SNI).
pub fn servername(&self, type_: NameType) -> Option<&str> {
self.ssl().servername(type_)
}

/// Returns the version sent by the client in its Client Hello record.
pub fn client_version(&self) -> SslVersion {
SslVersion(self.0.version)
}

/// Returns a string describing the protocol version of the connection.
pub fn version_str(&self) -> &'static str {
self.ssl().version_str()
}
}

/// Information about a cipher.
Expand Down
9 changes: 8 additions & 1 deletion boring/src/symm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ unsafe impl Send for Cipher {}
pub struct Crypter {
ctx: *mut ffi::EVP_CIPHER_CTX,
block_size: usize,
padding: bool,
}

unsafe impl Sync for Crypter {}
Expand All @@ -307,6 +308,7 @@ impl Crypter {
let crypter = Crypter {
ctx,
block_size: t.block_size(),
padding: true,
};

let mode = match mode {
Expand Down Expand Up @@ -364,6 +366,7 @@ impl Crypter {
/// If padding is disabled, total amount of data encrypted/decrypted must
/// be a multiple of the cipher's block size.
pub fn pad(&mut self, padding: bool) {
self.padding = padding;
unsafe {
ffi::EVP_CIPHER_CTX_set_padding(self.ctx, padding as c_int);
}
Expand Down Expand Up @@ -464,7 +467,11 @@ impl Crypter {
} else {
0
};
assert!(output.len() >= input.len() + block_size);
if self.padding {
assert!(output.len() >= input.len() + block_size);
} else {
assert!(output.len() >= input.len());
}
assert!(output.len() <= c_int::max_value() as usize);
let mut outl = output.len() as c_int;
let inl = input.len() as c_int;
Expand Down
2 changes: 1 addition & 1 deletion tokio-boring/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tokio-boring"
version = "2.1.1"
version = "2.1.3"
authors = ["Alex Crichton <[email protected]>", "Ivan Nikulin <[email protected]>"]
license = "MIT/Apache-2.0"
edition = "2018"
Expand Down
16 changes: 16 additions & 0 deletions tokio-boring/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,22 @@ impl<S> HandshakeError<S> {
_ => None,
}
}

/// Returns the error code, if any.
pub fn code(&self) -> Option<ErrorCode> {
match &self.0 {
ssl::HandshakeError::Failure(s) => Some(s.error().code()),
_ => None,
}
}

/// Returns a reference to the inner I/O error, if any.
pub fn as_io_error(&self) -> Option<&io::Error> {
match &self.0 {
ssl::HandshakeError::Failure(s) => s.error().io_error(),
_ => None,
}
}
}

impl<S> fmt::Debug for HandshakeError<S>
Expand Down