Skip to content

Commit

Permalink
Merge pull request #1697 from zcash/1686-zcb-tor-dir-perms
Browse files Browse the repository at this point in the history
zcash_client_backend: Allow disabling Tor directory permissions tightening
  • Loading branch information
str4d authored Feb 8, 2025
2 parents 59a6525 + ba1c6a1 commit ad503f7
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 5 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ incrementalmerkletree-testing = "0.3"
# failure due to incompatible `libsqlite3-sys` versions.
arti-client = { version = "0.23", default-features = false, features = ["compression", "rustls", "tokio"] }
dynosaur = "0.1.1"
fs-mistrust = "0.8"
tokio = "1"
tor-rtcompat = "0.23"
tower = "0.4"
Expand Down
3 changes: 3 additions & 0 deletions zcash_client_backend/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ and this library adheres to Rust's notion of
- MSRV is now 1.81.0.
- Migrated to `bip32 =0.6.0-pre.1`, `nonempty 0.11`, `incrementalmerkletree 0.8`,
`shardtree 0.6`.
- `zcash_client_backend::tor`:
- `tor::Client::create` now takes an optional `with_permissions` argument for
configuring `fs_mistrust::Mistrust`.
- `zcash_client_backend::wallet::Recipient` has changed:
- The `Recipient::External` variant is now a structured variant.
- The `Recipient::EphemeralTransparent` variant is now only available if
Expand Down
2 changes: 2 additions & 0 deletions zcash_client_backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ crossbeam-channel.workspace = true
rayon.workspace = true

# - Tor
fs-mistrust = { workspace = true, optional = true }
tokio = { workspace = true, optional = true, features = ["fs"] }
tor-rtcompat = { workspace = true, optional = true }
tower = { workspace = true, optional = true }
Expand Down Expand Up @@ -201,6 +202,7 @@ sync = [
tor = [
"dep:arti-client",
"dep:dynosaur",
"dep:fs-mistrust",
"dep:futures-util",
"dep:http-body-util",
"dep:hyper",
Expand Down
23 changes: 18 additions & 5 deletions zcash_client_backend/src/tor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,33 @@ impl Client {
/// Preserving the contents of this directory will speed up subsequent calls to
/// `Client::create`.
///
/// If `with_permissions` is `None`, the default from [`arti_client`] will be used
/// (enable permissions checks unless the `ARTI_FS_DISABLE_PERMISSION_CHECKS` env
/// variable is set).
///
/// Returns an error if `tor_dir` does not exist, or if bootstrapping fails.
pub async fn create(tor_dir: &Path) -> Result<Self, Error> {
pub async fn create(
tor_dir: &Path,
with_permissions: Option<impl FnOnce(&mut fs_mistrust::MistrustBuilder)>,
) -> Result<Self, Error> {
let runtime = PreferredRuntime::current()?;

if !tokio::fs::try_exists(tor_dir).await? {
return Err(Error::MissingTorDirectory);
}

let config = TorClientConfigBuilder::from_directories(
let mut config_builder = TorClientConfigBuilder::from_directories(
tor_dir.join("arti-data"),
tor_dir.join("arti-cache"),
)
.build()
.expect("all required fields initialized");
);

if let Some(f) = with_permissions {
f(config_builder.storage().permissions());
}

let config = config_builder
.build()
.expect("all required fields initialized");

let client_builder = TorClient::with_runtime(runtime).config(config);

Expand Down

0 comments on commit ad503f7

Please sign in to comment.