Commit Graph

300 Commits

Author SHA1 Message Date
Alessandro Ghedini 97e2a8bc30 Add a few WouldBlock cases 2023-10-10 09:22:36 +01:00
Anthony Ramine 3d7ff0a5c0 Introduce setup_accept and setup_connect
These two new kinds of methods immediately return a MidHandshakeSslStream
instead of actually initiating a handshake. This greatly simplifies
loops around MidHandshakeSslStream::WouldBlock.
2023-10-10 09:22:36 +01:00
Anthony Ramine 3b88f4ee5b Panic on error when setting default curves list
These lists are hardcoded and the calls have no business failing in the first place.
2023-10-10 09:22:36 +01:00
Alessandro Ghedini 7b0de9341c Introduce ssl::Error::would_block 2023-10-10 09:22:36 +01:00
Anthony Ramine 602bb6d63d Fix clippy lints 2023-10-09 11:49:07 +01:00
Yuchen Wu a3cdf8769a Add new(), connect(), accept() and handshake() to SslStream
These APIs allow more SslStream to be used more flexibly
2023-09-21 17:40:06 +02:00
Christopher Patton 6057ab79f9 Enable P-521 with "kx-safe-default"
While not commonly used, P-521 is a perfectly safe choice of key
exchange algorithm.
2023-09-20 11:09:38 +01:00
Yuchen Wu 52307b145b Provide into_ssl() for ConnectConfiguration
Port from openssl-rs.
2023-09-19 22:04:59 +02:00
Christopher Patton 2fa3d96966 Use features to set key exchange preferences
Overwrite boringSSL's default key exchange preferences with safe
defaults using feature flags:

* "kx-pq-supported" enables support for PQ key exchange algorithms.
  Classical key exchange is still preferred, but will be upgraded to PQ
  if requested.

* "kx-pq-preferred" enables preference for PQ key exchange,
  with fallback to classical key exchange if requested.

* "kx-nist-required" disables non-NIST key exchange.

Each feature implies "kx-safe-default". When this feature is enabled,
don't compile bindings for `SSL_CTX_set1_curves()` and `SslCurve`. This
is to prevent the feature flags from silently overriding curve
preferences chosen by the user.

Ideally we'd allow both: that is, use "kx-*" to set defaults, but still
allow the user to manually override them. However, this doesn't work
because by the time the `SSL_CTX` is constructed, we don't yet know
whether we're the client or server. (The "kx-*" features set different
preferences for each.) If "kx-sfe-default" is set, then the curve
preferences are set just before initiating a TLS handshake
(`SslStreamBuilder::connect()`) or waiting for a TLS handshake
(`SslStreamBuilder::accept()`).
2023-09-01 14:21:35 -07:00
Ivan Nikulin 5d6ca7e19c Introduce `no-patches` feature 2023-09-01 09:28:27 +01:00
Ivan Nikulin 011d500460 Separate `fips` and `fips-link-precompiled` features.
Make the later compatible with `rpk` feature.
2023-08-30 11:41:20 +01:00
Ivan Nikulin bb063aa9e6 Fix Diplay panics for HandshakeError with `rpk` (fixes #140) 2023-08-03 15:00:09 +01:00
Ivan Nikulin 7fd29555b6 Fix feature gates for fips-link-precompiled 2023-08-03 13:38:59 +01:00
Anthony Ramine abfe2f7980 Switch boring from lazy_static to once_cell 2023-08-02 12:14:02 +01:00
Anthony Ramine af5bb39a78 Clean up and remove some unsafe code from ffi callbacks 2023-08-02 12:14:02 +01:00
Ivan Nikulin 3478bc2668
Merge pull request #83 from signalapp/private_key_to_der_pkcs8
boring: Expose PKey::private_key_to_der_pkcs8(_passphrase)
2023-07-27 10:11:02 +01:00
Ivan Nikulin d4ddd16ee2 Add fips-link-precompiled feature 2023-07-26 14:35:40 +01:00
Alessandro Ghedini f772338238 Allow specifying a custom BoringSSL source directory 2023-07-14 10:47:37 +01:00
Ivan Nikulin 0b542999d4 Address review comments 2023-07-10 14:00:52 +01:00
Ivan Nikulin d59d170c4d Update docs 2023-07-10 12:29:30 +01:00
Ivan Nikulin d1ee9bfd86 Use workspace metadata for crates 2023-07-10 11:38:18 +01:00
Ivan Nikulin c4e8a94a69 Add RPK and PQ crypto features 2023-07-07 13:50:36 +01:00
Anthony Ramine 6e751e85cb Revert "Merge pull request #108 from nox/store-clone"
This reverts commit 1c1af4b38b, reversing
changes made to da32be1fa9.

SslContextBuilder::cert_store_mut returns a &mut X509StoreBuilder
backed by a X509Store that is already shared with an existing SslContext.
2023-05-15 15:36:17 +02:00
Anthony Ramine ad2517f797 Fix build 2023-05-15 15:36:17 +02:00
Ivan Nikulin 1c1af4b38b
Merge pull request #108 from nox/store-clone
Implement ToOwned for X509StoreRef and Clone for X509Store
2023-05-11 16:25:11 +01:00
Ivan Nikulin da32be1fa9
Merge pull request #114 from nox/nox/openssl-fixes
Port security fixes from the openssl crate (fixes #111)
2023-05-11 16:24:29 +01:00
Ivan Nikulin ec52371e6b
Merge pull request #79 from signalapp/deriver-leak
boring: Fix memory leak in `Deriver`
2023-05-11 16:23:56 +01:00
Ivan Nikulin 0dd85d187b
Merge pull request #117 from nox/bump-boringssl
Update boringssl to latest upstream commit (fixes #100)
2023-05-11 16:23:28 +01:00
Ivan Nikulin 561d786c10
Merge pull request #97 from PiotrSikora/boringcrypto_4407
Update BoringCrypto to FIPS 140-2 certificate 4407.
2023-05-11 16:22:25 +01:00
Ivan Nikulin e1dc466cd1
Merge pull request #104 from tbu-/pr_doc_typo
psuedo → pseudo
2023-05-11 16:20:47 +01:00
Piotr Sikora 902e7d0c92 Update BoringCrypto to FIPS 140-2 certificate 4407.
Signed-off-by: Piotr Sikora <piotr@aviatrix.com>
2023-05-09 10:37:32 +02:00
Anthony Ramine 6274f70726 Update boringssl to latest upstream commit
Notable commits that cause code changes here:

X509 fields notBefore and notAfter need to be specified
https://boringssl-review.googlesource.com/c/boringssl/+/49349

X509ReqBuilder only accepts X509v1 now
https://boringssl-review.googlesource.com/c/boringssl/+/52605

Some functions switched from int to size_t
https://boringssl-review.googlesource.com/c/boringssl/+/54985

CECPQ2 support was dropped
https://boringssl-review.googlesource.com/c/boringssl/+/58645

This is a breaking change.
2023-05-09 10:28:10 +02:00
Anthony Ramine 2ceb99216f Implement ToOwned for X509StoreRef and Clone for X509Store 2023-05-05 11:10:42 +02:00
Alex Gaynor b36b1705b3 Fix race condition with X509Name creation 2023-05-05 11:10:11 +02:00
Alex Gaynor 90dfe2f912 Document the horror show 2023-05-05 11:10:11 +02:00
Alex Gaynor c80e3a3ec5 Always provide an X509V3Context in X509Extension::new because OpenSSL requires it for some extensions (and segfaults without) 2023-05-05 11:10:11 +02:00
Alex Gaynor 0f28001027 Resolve an injection vulnerability in EKU creation 2023-05-05 11:10:10 +02:00
Alex Gaynor 1eea7c5271 Resolve an injection vulnerability in SAN creation 2023-05-05 11:10:10 +02:00
Rob Shearman ae0cd6b98e Add X509Name to/from DER methods
Since X509Name is more complex than a single value (it's a a sequence
of entries) it's useful to be able to serialise/deserialise to/from
flat data, and DER is a natural form for this.

So add a {i2d,d2i}_X509_NAME -sys functions, and to_der/from_der
wrappers in X509NameRef and X509Name respectively.

Originally added in https://github.com/sfackler/rust-openssl/pull/1534
2023-05-05 11:10:10 +02:00
Joshua Nitschke f8e225e6a4 Add additional function so that x509 name with specific type can be added
Originally added in https://github.com/sfackler/rust-openssl/pull/1371
2023-05-05 11:10:10 +02:00
Anthony Ramine 74b0cc0da7 Fix lints 2023-03-27 13:15:12 +02:00
Tobias Bucher 8c2c2bd2b6 Add link in docs 2023-02-28 14:33:07 +01:00
Tobias Bucher f102b3792b psuedo → pseudo 2023-02-28 13:27:35 +01:00
Joshua Nelson da2c13e761 Update changelogs and bump version numbers 2022-09-16 13:03:26 -05:00
Joshua Nelson bd4f8d58ef Fix clippy warnings 2022-09-16 12:13:55 -05:00
Joshua Nelson 774e721ad9 Remove uses of `mem::uninitialized`
According to [the docs](https://doc.rust-lang.org/stable/std/mem/fn.uninitialized.html),

> Calling this when the content is not yet fully initialized causes immediate undefined behavior.
> it [is] undefined behavior to have uninitialized data in a variable even if that variable has an integer type.

Using MaybeUninit instead, as recommended by the official documentation, avoids undefined behavior by not creating a `&mut` reference to uninitialized data.
2022-09-16 12:13:55 -05:00
Jordan Rose 172b623bcc boring: Expose PKey::private_key_to_der_pkcs8(_passphrase) 2022-07-28 16:30:41 -07:00
Ravi Khadiwala db03da82fd boring: Fix memory leak in `Deriver` 2022-07-01 12:44:04 -05:00
BiagioFesta 863b72b3a8 ssl/test: fix UT expectations accordingly with boringssl change
- boringssl fix:
https://boringssl.googlesource.com/boringssl/+/c02c19e0d842f54d903a9b62316476f4b9c4e3f0

- Now ALPN validation with SSL_TLSEXT_ERR_ALERT_FATAL makes the server
abort the handshake with an alarm. UT now correctly asserts
connection error on both client and server side.
2022-04-28 11:29:13 -05:00
BiagioFesta e141e834f1 Update boringssl deps for quiche 0.12.0 compatibility
- ExtensionType::TOKEN_BINDING removed from implementation
d89ec688f2

- ExtensionType::ECH_IS_INNER removed from implementation
18b6836b2f
2022-04-28 11:29:13 -05:00
ilammy e6ddc40333 boring: BigNumRef::to_vec_padded()
Wrap BN_bn2bin_padded() which comes useful for exporting fixed-length
BIGNUMs, more efficient than padding result of to_vec() afterwards.

Note that in OpenSSL the function is called BN_bn2binpad() and has
a different order of arguments. BoringSSL's BN_bn2bin_padded() also
takes the desired length as "size_t".
2022-02-12 12:20:36 -06:00
Braden Ehrat 1507689c5b
Add fips-3678 feature (#52)
* Add rerun-if-env-changed instructions for BORING_* variables

* Use X509_get0_notBefore() and X509_get0_notAfter() instead of X509_getm_notBefore() and X509_getm_notAfter().

According to
https://www.openssl.org/docs/man1.1.0/man3/X509_getm_notBefore.html,
"X509_getm_notBefore() and X509_getm_notAfter() are similar to
X509_get0_notBefore() and X509_get0_notAfter() except they return
non-constant mutable references to the associated date field of the
certificate".

* Only update boringssl submodule if BORING_BSSL_PATH not provided

* Allow BORING_BSSL_LIB_PATH to control link search

* Add fips feature

* Use X509_set_notAfter unconditionally for FIPS compatibility

This is equivalent according to
https://boringssl.googlesource.com/boringssl/+/c947efabcbc38dcf93e8ad0e6a76206cf0ec8072

The version of boringssl that's FIPS-certified doesn't have `X509_set1_notAfter`.
The only difference between that and `X509_set_notAfter` is whether they're const-correct,
which doesn't seem worth having two different code-paths.

* Check out fips commit automatically

* Verify the version of the compiler used for building boringssl

NIST specifies that it needs to be 7.0.1; I originally tried building with clang 10 and it failed.
Theoretically this should check the versions of Go and Ninja too, but they haven't given me trouble in practice.

Example error:
```
   Compiling boring-sys v1.1.1 (/home/jnelson/work/boring/boring-sys)
error: failed to run custom build command for `boring-sys v1.1.1 (/home/jnelson/work/boring/boring-sys)`

Caused by:
  process didn't exit successfully: `/home/jnelson/work/boring/target/debug/build/boring-sys-31b8ce53031cfd83/build-script-build` (exit status: 101)
  --- stdout
  cargo:rerun-if-env-changed=BORING_BSSL_PATH

  --- stderr
  warning: missing clang-7, trying other compilers: Permission denied (os error 13)
  warning: FIPS requires clang version 7.0.1, skipping incompatible version "clang version 10.0.0-4ubuntu1 "
  thread 'main' panicked at 'unsupported clang version "cc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0": FIPS requires clang 7.0.1', boring-sys/build.rs:216:13
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
```

* Add Github actions workflow testing FIPS

Co-authored-by: Joshua Nelson <jnelson@cloudflare.com>
2022-01-31 16:11:33 -06:00
ilammy 5f327aba86 boring: Suppress Clippy warnings about missing safety docs
I'm not quite sure why these are unsafe traits, probably to prevent
implementing them for random types accidentally. However, Clippy
demands a "# Safety" section in their docs. Tell it to get lost.
2022-01-04 18:27:39 -05:00
Joshua Nelson 18650f625e Bump versions for release
- Major version for boring-sys: `PasswordCallback` was removed
- Major version for boring: the public `*Ref` types were removed and `foreign-types` appears in our public api and had a major version bump
- Patch version for tokio-boring: the only API change was removing the `S: Debug` bound
- Patch version for hyper-boring: no API changes, only removed dependencies
2021-12-16 13:52:38 -06:00
Joshua Nelson 75d6ced4c9 Remove unused and deprecated `tempdir` dependency 2021-08-17 10:44:50 -05:00
Joshua Nelson 057a81b9a4 Remove unused `*Ref` parameters to macro
This doesn't actually do anything, it just makes it more clear that those parameters are ignored.
2021-08-17 10:44:50 -05:00
Joshua Nelson e46378d4de Update dependencies
In particular, this updates `foreign-types`, which had a lot of breaking changes.

- `ForeignType` is now an unsafe trait
- `*Ref` types no longer need a separate macro call, they're generated automatically
- Generated types now store `NonNull<T>` instead of `*mut T`
2021-08-17 10:44:50 -05:00
Joshua Nelson c037a438f8 Switch to 2018 edition in boring 2021-08-13 15:22:56 -05:00
Joshua Nelson 46787b7b69 Run `cargo fix --edition 2021-08-13 15:22:56 -05:00
Joshua Nelson 03dda42d1a Remove unused attribute 2021-07-30 16:24:16 -04:00
Joshua Nelson 6ddfee29b7 Fix clippy warnings for 1.54 2021-07-29 12:16:55 -04:00
Anthony Ramine 77ef82c88d Bump boring to 1.1.6 2021-04-16 13:00:09 +02:00
Anthony Ramine fbdcfc3dbc Introduce ClientHello::client_version 2021-04-16 12:31:04 +02:00
Anthony Ramine c85bf0940e Bump boring to 1.1.5 2021-04-13 16:05:40 +02:00
Anthony Ramine d147f155a4 Allow retrieving the version string from early callback 2021-04-13 12:03:55 +02:00
Anthony Ramine 6baba64eec Allow returning the server name from the early callback 2021-04-13 11:59:27 +02:00
Anthony Ramine e13112e3ca Allow uppercase acronyms 2021-04-06 11:44:47 +02:00
Ivan Nikulin 00f54790fb Bump boring to 1.1.4 2021-03-15 14:19:02 +00:00
Anthony Ramine 4353e4f8f3 Use Display for ssl::Error in Display for ssl::HandshakeError 2021-03-15 13:32:23 +01:00
Anthony Ramine 56564c7cb6 Tweak yet again the boring error reporting
We also omit file and line in ErrorStack itself now too.

ErrorStack is the wrapped error type returned by
hyper_boring::HttpsConnector::call.
2021-03-15 11:26:09 +01:00
Ivan Nikulin 7f6bd732e4 Bump boring to 1.1.3 2021-03-11 21:28:57 +00:00
Anthony Ramine 6f4ecb3d90 Remove file/line from Display for HandshakeError 2021-03-11 14:42:00 +01:00
Ivan Nikulin ebab82eb5b Bump boring to 1.1.2, tokio-boring 2.1.1 2021-03-09 17:47:01 +00:00
Ivan Nikulin 2667b0fdee
Merge pull request #17 from nox/handshake-error
Improve error printing
2021-03-09 17:43:44 +00:00
Anthony Ramine 66cabd882c Introduce MidHandshakeSslStream::into_parts 2021-03-09 16:26:30 +01:00
Anthony Ramine 51734088ef Print handshake errors in a better way
We completely ignore the ErrorStack value if it is
an X509 verification failure.
2021-03-09 16:26:30 +01:00
Anthony Ramine 8274492b95 Separate errors in an error stack better 2021-03-05 16:24:11 +01:00
Ivan Nikulin adb00bde17 Bump boring to 1.1.1 2021-03-01 12:54:56 +00:00
Anthony Ramine be0b2605ff Make Display for Error more readable 2021-03-01 12:09:04 +01:00
Ivan Nikulin ed3279c4f1 Bump feature version on all packages instead. 2021-02-24 11:52:24 +00:00
Ivan Nikulin 3772a53bc0 Bump boring-sys to 1.0.5. Bump boring to 1.0.4 2021-02-24 11:06:01 +00:00
Ivan Nikulin af25e9c9a0
Merge pull request #14 from except/bssl-specific-options
Enable various client features of bssl
2021-02-24 02:51:33 +00:00
Anthony Ramine 86691d8d72 Introduce ExtensionType for the arg of get_extension 2021-02-22 14:23:26 +01:00
Anthony Ramine f831b25bf1 Introduce ClientHello::get_extension 2021-02-22 14:20:50 +01:00
Hasan Gondal ee94b2a01d Add support for SSL_CTX_set1_curves 2021-02-20 23:58:25 +00:00
Hasan Gondal 6cfc713483 Enable various client features of bssl 2021-02-19 22:52:38 +00:00
Anthony Ramine 9c5c7e3db5 Introduce set_select_certificate_callback 2021-02-19 16:11:14 +01:00
Frank Denis 05c6a41270 Use bindgen to automatically generate boring-sys
This ensures that all the Rust functions, types and constants
always match the actual BoringSSL definitions.

It also removes quite a lot of manually maintained code, as well
as the need for systest.

The value for `SslOptions::ALL`, for example, was wrong. On current
BoringSSL versions, this is a no-op, and is set to `0`.

Clearing it does nothing. So, the `clear_ctx_options` test, that
passed by accident, was adjusted to use a different option.

The `libc` crate is not required, as we only use it for types that
are already defined in the standard library. It was removed from
`boring-sys`. The same can be done to other crates later.
2021-02-12 15:03:45 +01:00
Ivan Nikulin 0c9166dd74 Make new clippy happy 2021-02-11 19:35:11 +00:00
Gabriela Alexandra Moldovan 12d6a27104 Fix clippy warning. 2021-01-08 16:53:20 +00:00
Ivan Nikulin a6fbc0fed2 Bump version 2020-12-23 14:15:50 +00:00
Ivan Nikulin f40ac2d1ed Implement conversion of HandshakeError to the source stream 2020-12-23 12:25:30 +00:00
Gabriela Alexandra Moldovan 31ed6443b1 Fix boring repository links. 2020-11-14 00:03:43 +00:00
Ivan Nikulin 5afd10b577 Fix boring-sys linking. Bump version. 2020-11-12 13:03:41 +00:00
Ivan Nikulin 2b61e14211 Fix doc comment 2020-11-11 20:40:58 +00:00
Ivan Nikulin fda73f4947 Fix docs 2020-11-11 20:32:53 +00:00
Ivan Nikulin 548771adb1 Add tokio-boring 2020-11-11 19:26:22 +00:00
Ivan Nikulin ec45baa6d8 Revive CI 2020-11-11 19:01:29 +00:00
Ivan Nikulin fc07d7dfbb Fix doc comments 2020-11-11 18:08:14 +00:00
Ivan Nikulin 5cb8947d7e Rename stuff 2020-11-11 17:47:30 +00:00