From 1b8e28c938d03846b647c2393f69914491da9359 Mon Sep 17 00:00:00 2001 From: Nikita Galaiko Date: Tue, 5 Sep 2023 10:04:43 +0200 Subject: [PATCH] resolve key path --- butler/Cargo.lock | 134 ++++++++++++++++--------------- src-tauri/Cargo.lock | 30 +++++++ src-tauri/Cargo.toml | 1 + src-tauri/src/git/credentials.rs | 10 +-- 4 files changed, 107 insertions(+), 68 deletions(-) diff --git a/butler/Cargo.lock b/butler/Cargo.lock index cf21cc5a2..ce71d9f09 100644 --- a/butler/Cargo.lock +++ b/butler/Cargo.lock @@ -394,7 +394,7 @@ dependencies = [ "clap", "colored", "dialoguer", - "dirs", + "dirs 5.0.1", "git-butler-tauri", "git2", ] @@ -1053,13 +1053,22 @@ dependencies = [ "subtle", ] +[[package]] +name = "dirs" +version = "4.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059" +dependencies = [ + "dirs-sys 0.3.7", +] + [[package]] name = "dirs" version = "5.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "44c45a9d03d6676652bcb5e724c7e988de1acad23a711b5217ab9cbecbec2225" dependencies = [ - "dirs-sys", + "dirs-sys 0.4.1", ] [[package]] @@ -1072,6 +1081,17 @@ dependencies = [ "dirs-sys-next", ] +[[package]] +name = "dirs-sys" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6" +dependencies = [ + "libc", + "redox_users", + "winapi", +] + [[package]] name = "dirs-sys" version = "0.4.1" @@ -1171,17 +1191,17 @@ checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" [[package]] name = "elliptic-curve" -version = "0.12.3" +version = "0.13.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7bb888ab5300a19b8e5bceef25ac745ad065f3c9f7efc6de1b91958110891d3" +checksum = "968405c8fdc9b3bf4df0a6638858cc0b52462836ab6b1c87377785dd09cf1c0b" dependencies = [ "base16ct", "crypto-bigint", - "der", - "digest 0.10.7", + "digest", "ff", "generic-array", "group", + "pkcs8", "rand_core 0.6.4", "sec1", "subtle", @@ -1633,6 +1653,7 @@ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", + "zeroize", ] [[package]] @@ -1713,6 +1734,7 @@ dependencies = [ "rand 0.8.5", "refinery", "reqwest", + "resolve-path", "rusqlite", "rustix", "sentry", @@ -1723,7 +1745,7 @@ dependencies = [ "serde-jsonlines", "serde_json", "sha1", - "sha2 0.10.7", + "sha2", "similar", "ssh-key", "tantivy", @@ -1849,9 +1871,9 @@ dependencies = [ [[package]] name = "group" -version = "0.12.1" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5dfbfb3a6cfbd390d5c9564ab283a0349b9b9fcd46a706c1eb10e0db70bfbac7" +checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" dependencies = [ "ff", "rand_core 0.6.4", @@ -2012,7 +2034,7 @@ version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" dependencies = [ - "digest 0.10.7", + "digest", ] [[package]] @@ -3123,12 +3145,6 @@ dependencies = [ "loom", ] -[[package]] -name = "opaque-debug" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" - [[package]] name = "open" version = "3.2.0" @@ -3318,17 +3334,17 @@ version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "83a0692ec44e4cf1ef28ca317f14f8f07da2d95ec3fa01f86e4467b725e60917" dependencies = [ - "digest 0.10.7", + "digest", "hmac", "password-hash", - "sha2 0.10.7", + "sha2", ] [[package]] name = "pem-rfc7468" -version = "0.6.0" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24d159833a9105500e0398934e205e0773f0b27529557134ecfc51c27646adac" +checksum = "88b39c9bfcfc231068454382784bb460aae594343fb030d46e9f50a645418412" dependencies = [ "base64ct", ] @@ -3503,6 +3519,12 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" +[[package]] +name = "platforms" +version = "3.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4503fa043bf02cee09a9582e9554b4c6403b2ef55e4612e96561d294419429f8" + [[package]] name = "plist" version = "1.5.0" @@ -3581,6 +3603,15 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" +[[package]] +name = "primeorder" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c2fcef82c0ec6eefcc179b978446c399b3cdf73c392c35604e399eee6df1ee3" +dependencies = [ + "elliptic-curve", +] + [[package]] name = "proc-macro-crate" version = "1.3.1" @@ -4000,12 +4031,13 @@ dependencies = [ [[package]] name = "rsa" -version = "0.7.2" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "094052d5470cbcef561cb848a7209968c9f12dfa6d668f4bca048ac5de51099c" +checksum = "6ab43bb47d23c1a631b4b680199a45255dce26fa9ab2fa902581f624ff13e6a8" dependencies = [ "byteorder", - "digest 0.10.7", + "const-oid", + "digest", "num-bigint-dig", "num-integer", "num-iter", @@ -4013,8 +4045,9 @@ dependencies = [ "pkcs1", "pkcs8", "rand_core 0.6.4", + "sha2", "signature", - "smallvec", + "spki", "subtle", "zeroize", ] @@ -4147,9 +4180,9 @@ dependencies = [ [[package]] name = "sec1" -version = "0.3.0" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3be24c1842290c45df0a7bf069e0c268a747ad05a192f2fd7dcfdbc1cba40928" +checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" dependencies = [ "base16ct", "der", @@ -4525,20 +4558,7 @@ checksum = "f04293dc80c3993519f2d7f6f511707ee7094fe0c6d3406feb330cdb3540eba3" dependencies = [ "cfg-if", "cpufeatures", - "digest 0.10.7", -] - -[[package]] -name = "sha2" -version = "0.9.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800" -dependencies = [ - "block-buffer 0.9.0", - "cfg-if", - "cpufeatures", - "digest 0.9.0", - "opaque-debug", + "digest", ] [[package]] @@ -4549,7 +4569,7 @@ checksum = "479fb9d862239e610720565ca91403019f2f00410f1864c5aa7479b950a76ed8" dependencies = [ "cfg-if", "cpufeatures", - "digest 0.10.7", + "digest", ] [[package]] @@ -4588,11 +4608,11 @@ dependencies = [ [[package]] name = "signature" -version = "1.6.4" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74233d3b3b2f6d4b006dc19dee745e73e2a6bfb6f93607cd3b02bd5b00797d7c" +checksum = "5e1788eed21689f9cf370582dfc467ef36ed9c707f073528ddafa8d83e3b8500" dependencies = [ - "digest 0.10.7", + "digest", "rand_core 0.6.4", ] @@ -4730,9 +4750,11 @@ dependencies = [ "rand_core 0.6.4", "rsa", "sec1", - "sha2 0.10.7", + "sha2", "signature", + "ssh-cipher", "ssh-encoding", + "subtle", "zeroize", ] @@ -5152,7 +5174,7 @@ dependencies = [ "semver", "serde", "serde_json", - "sha2 0.10.7", + "sha2", "tauri-utils", "thiserror", "time", @@ -5286,9 +5308,9 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.7.1" +version = "3.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc02fddf48964c42031a0b3fe0428320ecf3a73c401040fc0096f97794310651" +checksum = "cb94d2f3cc536af71caac6b6fcebf65860b347e7ce0cc9ebe8f70d3e521054ef" dependencies = [ "cfg-if", "fastrand", @@ -6446,7 +6468,7 @@ dependencies = [ "once_cell", "serde", "serde_json", - "sha2 0.10.7", + "sha2", "soup2", "tao", "thiserror", @@ -6493,20 +6515,6 @@ name = "zeroize" version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a0956f1ba7c7909bfb66c2e9e4124ab6f6482560f6628b5aaeba39207c9aad9" -dependencies = [ - "zeroize_derive", -] - -[[package]] -name = "zeroize_derive" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.26", -] [[package]] name = "zip" diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 76a906d92..7269ce9b4 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -913,6 +913,15 @@ dependencies = [ "subtle", ] +[[package]] +name = "dirs" +version = "4.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059" +dependencies = [ + "dirs-sys", +] + [[package]] name = "dirs-next" version = "2.0.0" @@ -923,6 +932,17 @@ dependencies = [ "dirs-sys-next", ] +[[package]] +name = "dirs-sys" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6" +dependencies = [ + "libc", + "redox_users", + "winapi", +] + [[package]] name = "dirs-sys-next" version = "0.1.2" @@ -1546,6 +1566,7 @@ dependencies = [ "rand 0.8.5", "refinery", "reqwest", + "resolve-path", "rusqlite", "rustix", "sentry", @@ -3776,6 +3797,15 @@ dependencies = [ "winreg 0.10.1", ] +[[package]] +name = "resolve-path" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "321e5e41b3b192dab6f1e75b9deacb6688b4b8c5e68906a78e8f43e7c2887bb5" +dependencies = [ + "dirs", +] + [[package]] name = "rfc6979" version = "0.4.0" diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index d15b990db..dfdf6d553 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -60,6 +60,7 @@ rustix = "0.38" backoff = "0.4.0" byteorder = "1.4.3" num_cpus = "1.16.0" +resolve-path = "0.1.0" [features] # by default Tauri runs in production mode diff --git a/src-tauri/src/git/credentials.rs b/src-tauri/src/git/credentials.rs index 73ad42403..69a40f04c 100644 --- a/src-tauri/src/git/credentials.rs +++ b/src-tauri/src/git/credentials.rs @@ -1,5 +1,7 @@ use std::env; +use resolve_path::PathResolveExt; + use crate::keys; pub type CredentialsCallback<'a> = Box< @@ -43,17 +45,15 @@ pub fn for_key(key: &keys::Key) -> Vec> { credentials } -fn from_keypath<'a>( - key_path: std::path::PathBuf, - passphrase: Option<&'a str>, -) -> CredentialsCallback<'a> { +fn from_keypath(key_path: std::path::PathBuf, passphrase: Option<&str>) -> CredentialsCallback { Box::new(move |url, _username_from_url, _allowed_types| { + let key_path = key_path.resolve(); tracing::info!("authenticating with {} using {}", url, key_path.display()); git2::Cred::ssh_key("git", None, &key_path, passphrase) }) } -fn from_key(key: &keys::PrivateKey) -> CredentialsCallback<'_> { +fn from_key(key: &keys::PrivateKey) -> CredentialsCallback { Box::new(|url, _username_from_url, _allowed_types| { tracing::info!("authenticating with {} using gitbutler's key", url); git2::Cred::ssh_key_from_memory("git", None, &key.to_string(), None)