Skip to content

Commit 54797a0

Browse files
committed
Merge #135: Add use-rustls-ring feature
8d71f95 feat: add use-rustls-ring feature (thunderbiscuit) Pull request description: This PR adds the ability to build the client using the `ring` dependency for `rustls` instead of the new default `aws-lc-rs`. As of the [`0.23.0` release](https://github.com/rustls/rustls/releases/tag/v%2F0.23.0), rustls changed its default cryptography provider to [aws-lc-rs](https://crates.io/crates/aws-lc-rs). This new library is actually a set of bindings to a C library maintained by AWS, and they provide prebuilt bindings for [some platforms](https://aws.github.io/aws-lc-rs/platform_support.html) but not all. On these other platforms, the compilation step will attempt to build the bindings, requiring extra dependencies (CMake, libclang and others depending on the platform). This compilation step is what is currently breaking our Android and Swift builds for bdk-ffi. It is certainly possible to build the bindings (and the AWS docs on it are very nice), but for some reason I have not been able to make it work everywhere yet (local, CI, Windows). This PR enables us to use the previous default `ring` library for rustls. I basically have to turn off the default features on `rustls` and re-enable all of them _except_ for the `aws_lc_rs`. We also have a few feature-gated constructs in the library, for which I needed to add the new proposed `use-rustls-ring` feature in order to make all of this work for us. Let me know if there are maybe better ways to achieve this! ACKs for top commit: oleonardolima: ACK 8d71f95 notmandatory: ACK 8d71f95 Tree-SHA512: 5ea8bfac7a18700e32035518e9e8253252c8ff9064b011e14a060ac8ed7b478876ee408ce06a89af9e53de837ffa9a13fbe5030d12b48a76558fd4e8187e5651
2 parents 64c77ee + 8d71f95 commit 54797a0

File tree

5 files changed

+48
-14
lines changed

5 files changed

+48
-14
lines changed

.github/workflows/cont_integration.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,4 @@ jobs:
4545
- run: cargo check --verbose --no-default-features --features=minimal,debug-calls
4646
- run: cargo check --verbose --no-default-features --features=proxy,use-openssl
4747
- run: cargo check --verbose --no-default-features --features=proxy,use-rustls
48+
- run: cargo check --verbose --no-default-features --features=proxy,use-rustls-ring

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ serde_json = { version = "^1.0" }
2525

2626
# Optional dependencies
2727
openssl = { version = "0.10", optional = true }
28-
rustls = { version = "0.23", optional = true }
28+
rustls = { version = "0.23", optional = true, default-features = false }
2929
webpki-roots = { version = "0.25", optional = true }
3030

3131
byteorder = { version = "1.0", optional = true }
@@ -41,5 +41,6 @@ default = ["proxy", "use-rustls"]
4141
minimal = []
4242
debug-calls = []
4343
proxy = ["byteorder", "winapi", "libc"]
44-
use-rustls = ["webpki-roots", "rustls"]
44+
use-rustls = ["webpki-roots", "rustls/default"]
45+
use-rustls-ring = ["webpki-roots", "rustls/ring", "rustls/logging", "rustls/std", "rustls/tls12"]
4546
use-openssl = ["openssl"]

src/lib.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,22 @@ extern crate log;
2525
#[cfg(feature = "use-openssl")]
2626
extern crate openssl;
2727
#[cfg(all(
28-
any(feature = "default", feature = "use-rustls"),
28+
any(
29+
feature = "default",
30+
feature = "use-rustls",
31+
feature = "use-rustls-ring"
32+
),
2933
not(feature = "use-openssl")
3034
))]
3135
extern crate rustls;
3236
extern crate serde;
3337
extern crate serde_json;
3438

35-
#[cfg(any(feature = "use-rustls", feature = "default"))]
39+
#[cfg(any(
40+
feature = "default",
41+
feature = "use-rustls",
42+
feature = "use-rustls-ring"
43+
))]
3644
extern crate webpki_roots;
3745

3846
#[cfg(any(feature = "default", feature = "proxy"))]
@@ -51,7 +59,8 @@ mod batch;
5159

5260
#[cfg(any(
5361
all(feature = "proxy", feature = "use-openssl"),
54-
all(feature = "proxy", feature = "use-rustls")
62+
all(feature = "proxy", feature = "use-rustls"),
63+
all(feature = "proxy", feature = "use-rustls-ring")
5564
))]
5665
pub mod client;
5766

@@ -66,7 +75,8 @@ pub use api::ElectrumApi;
6675
pub use batch::Batch;
6776
#[cfg(any(
6877
all(feature = "proxy", feature = "use-openssl"),
69-
all(feature = "proxy", feature = "use-rustls")
78+
all(feature = "proxy", feature = "use-rustls"),
79+
all(feature = "proxy", feature = "use-rustls-ring")
7080
))]
7181
pub use client::*;
7282
pub use config::{Config, ConfigBuilder, Socks5Config};

src/raw_client.rs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ use bitcoin::{Script, Txid};
2323
use openssl::ssl::{SslConnector, SslMethod, SslStream, SslVerifyMode};
2424

2525
#[cfg(all(
26-
any(feature = "default", feature = "use-rustls"),
26+
any(
27+
feature = "default",
28+
feature = "use-rustls",
29+
feature = "use-rustls-ring"
30+
),
2731
not(feature = "use-openssl")
2832
))]
2933
use rustls::{
@@ -286,7 +290,11 @@ impl RawClient<ElectrumSslStream> {
286290
}
287291

288292
#[cfg(all(
289-
any(feature = "default", feature = "use-rustls"),
293+
any(
294+
feature = "default",
295+
feature = "use-rustls",
296+
feature = "use-rustls-ring"
297+
),
290298
not(feature = "use-openssl")
291299
))]
292300
mod danger {
@@ -336,13 +344,21 @@ mod danger {
336344
}
337345

338346
#[cfg(all(
339-
any(feature = "default", feature = "use-rustls"),
347+
any(
348+
feature = "default",
349+
feature = "use-rustls",
350+
feature = "use-rustls-ring"
351+
),
340352
not(feature = "use-openssl")
341353
))]
342354
/// Transport type used to establish a Rustls TLS encrypted/authenticated connection with the server
343355
pub type ElectrumSslStream = StreamOwned<ClientConnection, TcpStream>;
344356
#[cfg(all(
345-
any(feature = "default", feature = "use-rustls"),
357+
any(
358+
feature = "default",
359+
feature = "use-rustls",
360+
feature = "use-rustls-ring"
361+
),
346362
not(feature = "use-openssl")
347363
))]
348364
impl RawClient<ElectrumSslStream> {
@@ -451,7 +467,11 @@ impl RawClient<ElectrumProxyStream> {
451467
Ok(stream.into())
452468
}
453469

454-
#[cfg(any(feature = "use-openssl", feature = "use-rustls"))]
470+
#[cfg(any(
471+
feature = "use-openssl",
472+
feature = "use-rustls",
473+
feature = "use-rustls-ring"
474+
))]
455475
/// Creates a new TLS client that connects to `target_addr` using `proxy_addr` as a socks proxy
456476
/// server. The DNS resolution of `target_addr`, if required, is done through the proxy. This
457477
/// allows to specify, for instance, `.onion` addresses.

src/types.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,7 @@ pub enum Error {
315315
CouldntLockReader,
316316
/// Broken IPC communication channel: the other thread probably has exited
317317
Mpsc,
318-
319-
#[cfg(feature = "use-rustls")]
318+
#[cfg(any(feature = "use-rustls", feature = "use-rustls-ring"))]
320319
/// Could not create a rustls client connection
321320
CouldNotCreateConnection(rustls::Error),
322321

@@ -340,7 +339,10 @@ impl Display for Error {
340339
Error::SslHandshakeError(e) => Display::fmt(e, f),
341340
#[cfg(feature = "use-openssl")]
342341
Error::InvalidSslMethod(e) => Display::fmt(e, f),
343-
#[cfg(feature = "use-rustls")]
342+
#[cfg(any(
343+
feature = "use-rustls",
344+
feature = "use-rustls-ring",
345+
))]
344346
Error::CouldNotCreateConnection(e) => Display::fmt(e, f),
345347

346348
Error::Message(e) => f.write_str(e),

0 commit comments

Comments
 (0)