From 6995e0b8d9409391877746c7a08b252b25498afd Mon Sep 17 00:00:00 2001 From: Huakun Shen Date: Sat, 4 Jan 2025 13:00:16 -0500 Subject: [PATCH] feat: integrate keyring and stronghold plugin (#39) * feat: add keyring plugin to handle DB encryption * feat: integrate stronghold plugin * feat: use new get_or_set APIs added to keyring plugin * chore: update keyring submodule * feat: add stronghold integration Stronghold loading is too slow for now, waiting for a fix https://github.com/tauri-apps/plugins-workspace/issues/2048 --- .gitmodules | 5 +- Cargo.lock | 853 +++++++++++++++++- Cargo.toml | 1 + apps/desktop/package.json | 1 + apps/desktop/src-tauri/Cargo.toml | 2 + .../src-tauri/capabilities/default.json | 2 + .../desktop/src-tauri/src/commands/keyring.rs | 13 + apps/desktop/src-tauri/src/commands/mod.rs | 1 + apps/desktop/src-tauri/src/lib.rs | 35 +- apps/desktop/src-tauri/src/setup/keyring.rs | 14 + apps/desktop/src-tauri/src/setup/mod.rs | 2 + .../desktop/src-tauri/src/setup/stronghold.rs | 12 + apps/desktop/src/lib/utils/stronghold.ts | 56 ++ package.json | 1 + packages/extension/src/load.ts | 2 - packages/tauri-plugins/jarvis/src/lib.rs | 5 +- pnpm-lock.yaml | 53 +- pnpm-workspace.yaml | 1 + vendors/tauri-plugin-keyring | 1 + vendors/tauri-plugin-system-info | 2 +- 20 files changed, 1024 insertions(+), 38 deletions(-) create mode 100644 apps/desktop/src-tauri/src/commands/keyring.rs create mode 100644 apps/desktop/src-tauri/src/commands/mod.rs create mode 100644 apps/desktop/src-tauri/src/setup/keyring.rs create mode 100644 apps/desktop/src-tauri/src/setup/stronghold.rs create mode 100644 apps/desktop/src/lib/utils/stronghold.ts create mode 160000 vendors/tauri-plugin-keyring diff --git a/.gitmodules b/.gitmodules index 65ff878..77d46dc 100644 --- a/.gitmodules +++ b/.gitmodules @@ -6,4 +6,7 @@ url = https://github.com/HuakunShen/tauri-plugin-network.git [submodule "vendors/tauri-plugin-system-info"] path = vendors/tauri-plugin-system-info - url = https://github.com/HuakunShen/tauri-plugin-system-info.git \ No newline at end of file + url = https://github.com/HuakunShen/tauri-plugin-system-info.git +[submodule "vendors/tauri-plugin-keyring"] + path = vendors/tauri-plugin-keyring + url = https://github.com/HuakunShen/tauri-plugin-keyring.git diff --git a/Cargo.lock b/Cargo.lock index 2aef12e..dde59a7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,6 +17,22 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" +[[package]] +name = "adler32" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aae1277d39aeec15cb388266ecc24b11c80469deae6067e17a1a7aa9e5c1f234" + +[[package]] +name = "aead" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d122413f284cf2d62fb1b7db97e02edb8cda96d769b16e443a4f6195e35662b0" +dependencies = [ + "crypto-common", + "generic-array", +] + [[package]] name = "aes" version = "0.8.4" @@ -28,6 +44,20 @@ dependencies = [ "cpufeatures", ] +[[package]] +name = "aes-gcm" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "831010a0f742e1209b3bcea8fab6a8e149051ba6099432c8cb2cc117dec3ead1" +dependencies = [ + "aead", + "aes", + "cipher", + "ctr", + "ghash", + "subtle", +] + [[package]] name = "ahash" version = "0.7.8" @@ -81,6 +111,12 @@ dependencies = [ "alloc-no-stdlib", ] +[[package]] +name = "allocator-api2" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" + [[package]] name = "android-tzdata" version = "0.1.1" @@ -218,6 +254,12 @@ dependencies = [ "syn 2.0.87", ] +[[package]] +name = "arrayref" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76a2e8124351fda1ef8aaaa3bbd7ebbcb486bbcd4225aca0aa0d84bb2db8fecb" + [[package]] name = "arrayvec" version = "0.7.6" @@ -600,6 +642,18 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "base16ct" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" + +[[package]] +name = "base64" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" + [[package]] name = "base64" version = "0.21.7" @@ -612,6 +666,21 @@ version = "0.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" +[[package]] +name = "base64ct" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" + +[[package]] +name = "bincode" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" +dependencies = [ + "serde", +] + [[package]] name = "bindgen" version = "0.69.5" @@ -674,6 +743,26 @@ dependencies = [ "wyz", ] +[[package]] +name = "blake2" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46502ad458c9a52b69d4d4d32775c788b7a1b85e8bc9d482d92250fc0e3f8efe" +dependencies = [ + "digest", +] + +[[package]] +name = "blake2b_simd" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23285ad32269793932e830392f2fe2f83e26488fd3ec778883a93c8323735780" +dependencies = [ + "arrayref", + "arrayvec", + "constant_time_eq 0.3.1", +] + [[package]] name = "block" version = "0.1.6" @@ -1009,6 +1098,30 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" +[[package]] +name = "chacha20" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3613f74bd2eac03dad61bd53dbe620703d4371614fe0bc3b9f04dd36fe4e818" +dependencies = [ + "cfg-if", + "cipher", + "cpufeatures", +] + +[[package]] +name = "chacha20poly1305" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10cd79432192d1c0f4e1a0fef9527696cc039165d729fb41b3f4f4f354c2dc35" +dependencies = [ + "aead", + "chacha20", + "cipher", + "poly1305", + "zeroize", +] + [[package]] name = "chrono" version = "0.4.38" @@ -1032,6 +1145,7 @@ checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" dependencies = [ "crypto-common", "inout", + "zeroize", ] [[package]] @@ -1228,6 +1342,12 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fe1d7dcda7d1da79e444bdfba1465f2f849a58b07774e1df473ee77030cb47a7" +[[package]] +name = "const-oid" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" + [[package]] name = "const-random" version = "0.1.18" @@ -1248,6 +1368,12 @@ dependencies = [ "tiny-keccak", ] +[[package]] +name = "constant_time_eq" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" + [[package]] name = "constant_time_eq" version = "0.3.1" @@ -1375,6 +1501,15 @@ dependencies = [ "libc", ] +[[package]] +name = "core2" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b49ba7ef1ad6107f8824dbe97de947cbaac53c44e7f9756a1fba0d37c1eec505" +dependencies = [ + "memchr", +] + [[package]] name = "cpufeatures" version = "0.2.14" @@ -1466,6 +1601,18 @@ dependencies = [ "tokio", ] +[[package]] +name = "crypto-bigint" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" +dependencies = [ + "generic-array", + "rand_core 0.6.4", + "subtle", + "zeroize", +] + [[package]] name = "crypto-common" version = "0.1.6" @@ -1513,6 +1660,42 @@ dependencies = [ "syn 2.0.87", ] +[[package]] +name = "ctr" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0369ee1ad671834580515889b80f2ea915f23b8be8d0daa4bbaf2ac5c7590835" +dependencies = [ + "cipher", +] + +[[package]] +name = "curve25519-dalek" +version = "4.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97fb8b7c4503de7d6ae7b42ab72a5a59857b4c937ec27a3d4539dba95b5ab2be" +dependencies = [ + "cfg-if", + "cpufeatures", + "curve25519-dalek-derive", + "digest", + "fiat-crypto", + "rustc_version", + "subtle", + "zeroize", +] + +[[package]] +name = "curve25519-dalek-derive" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + [[package]] name = "darling" version = "0.20.10" @@ -1548,6 +1731,12 @@ dependencies = [ "syn 2.0.87", ] +[[package]] +name = "dary_heap" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04d2cd9c18b9f454ed67da600630b021a8a80bf33f8c95896ab33aaf1c26b728" + [[package]] name = "data-url" version = "0.3.1" @@ -1567,12 +1756,46 @@ dependencies = [ "tempfile", ] +[[package]] +name = "dbus" +version = "0.9.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bb21987b9fb1613058ba3843121dd18b163b254d8a6e797e144cbac14d96d1b" +dependencies = [ + "libc", + "libdbus-sys", + "winapi", +] + +[[package]] +name = "dbus-secret-service" +version = "4.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b42a16374481d92aed73ae45b1f120207d8e71d24fb89f357fadbd8f946fd84b" +dependencies = [ + "dbus", + "futures-util", + "num", + "once_cell", + "rand 0.8.5", +] + [[package]] name = "deflate64" version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da692b8d1080ea3045efaab14434d40468c3d8657e42abddfffca87b428f4c1b" +[[package]] +name = "der" +version = "0.7.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" +dependencies = [ + "const-oid", + "zeroize", +] + [[package]] name = "deranged" version = "0.3.11" @@ -1625,6 +1848,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", + "const-oid", "crypto-common", "subtle", ] @@ -1791,12 +2015,69 @@ version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0d6ef0072f8a535281e4876be788938b528e9a1d43900b82c2569af7da799125" +[[package]] +name = "ecdsa" +version = "0.16.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" +dependencies = [ + "der", + "digest", + "elliptic-curve", + "rfc6979", + "signature", + "spki", +] + +[[package]] +name = "ed25519" +version = "2.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "115531babc129696a58c64a4fef0a8bf9e9698629fb97e9e40767d235cfbcd53" +dependencies = [ + "signature", +] + +[[package]] +name = "ed25519-zebra" +version = "4.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d9ce6874da5d4415896cd45ffbc4d1cfc0c4f9c079427bd870742c30f2f65a9" +dependencies = [ + "curve25519-dalek", + "ed25519", + "hashbrown 0.14.5", + "hex", + "rand_core 0.6.4", + "sha2", + "zeroize", +] + [[package]] name = "either" version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" +[[package]] +name = "elliptic-curve" +version = "0.13.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" +dependencies = [ + "base16ct", + "crypto-bigint", + "digest", + "ff", + "generic-array", + "group", + "pkcs8", + "rand_core 0.6.4", + "sec1", + "subtle", + "zeroize", +] + [[package]] name = "embed-resource" version = "2.5.0" @@ -1968,13 +2249,29 @@ dependencies = [ "log", ] +[[package]] +name = "ff" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" +dependencies = [ + "rand_core 0.6.4", + "subtle", +] + +[[package]] +name = "fiat-crypto" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28dea519a9695b9977216879a3ebfddf92f1c08c05d984f8996aecd6ecdc811d" + [[package]] name = "field-offset" version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "38e2275cc4e4fc009b0669731a1e5ab7ebf11f469eaede2bab9309a5b4d6057f" dependencies = [ - "memoffset", + "memoffset 0.9.1", "rustc_version", ] @@ -2315,6 +2612,7 @@ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", + "zeroize", ] [[package]] @@ -2355,8 +2653,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ "cfg-if", + "js-sys", "libc", "wasi 0.11.0+wasi-snapshot-preview1", + "wasm-bindgen", +] + +[[package]] +name = "ghash" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0d8a4362ccb29cb0b265253fb0a2728f592895ee6854fd9bc13f2ffda266ff1" +dependencies = [ + "opaque-debug", + "polyval", ] [[package]] @@ -2501,6 +2811,17 @@ dependencies = [ "system-deps", ] +[[package]] +name = "group" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" +dependencies = [ + "ff", + "rand_core 0.6.4", + "subtle", +] + [[package]] name = "grpc" version = "0.1.0" @@ -2630,6 +2951,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" dependencies = [ "ahash 0.8.11", + "allocator-api2", ] [[package]] @@ -2677,6 +2999,15 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +[[package]] +name = "hkdf" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b5f8eb2ad728638ea2c7d47a21db23b7b58a72ed6a38256b8a1849f15fbbdf7" +dependencies = [ + "hmac", +] + [[package]] name = "hmac" version = "0.12.1" @@ -3109,6 +3440,58 @@ dependencies = [ "syn 2.0.87", ] +[[package]] +name = "iota-crypto" +version = "0.23.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98a38db844c910d78825e173c083f2ef416b69cb091bba8ac1055763c6db065b" +dependencies = [ + "aead", + "aes", + "aes-gcm", + "autocfg", + "base64 0.21.7", + "blake2", + "chacha20poly1305", + "cipher", + "curve25519-dalek", + "digest", + "ed25519-zebra", + "generic-array", + "getrandom 0.2.15", + "hkdf", + "hmac", + "iterator-sorted", + "k256", + "pbkdf2", + "rand 0.8.5", + "scrypt", + "serde", + "sha2", + "tiny-keccak", + "unicode-normalization", + "x25519-dalek", + "zeroize", +] + +[[package]] +name = "iota_stronghold" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c0d301c7edbc31494d183b7d24c1bb51d3fb10fce2f3793df1baf45b6988e10" +dependencies = [ + "bincode", + "hkdf", + "iota-crypto", + "rust-argon2 1.0.0", + "serde", + "stronghold-derive", + "stronghold-utils", + "stronghold_engine", + "thiserror 1.0.66", + "zeroize", +] + [[package]] name = "ipnet" version = "2.10.1" @@ -3149,6 +3532,12 @@ version = "1.70.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" +[[package]] +name = "iterator-sorted" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d101775d2bc8f99f4ac18bf29b9ed70c0dd138b9a1e88d7b80179470cbbe8bd2" + [[package]] name = "itertools" version = "0.12.1" @@ -3261,6 +3650,19 @@ dependencies = [ "serde_json", ] +[[package]] +name = "k256" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6e3919bbaa2945715f0bb6d3934a173d1e9a59ac23767fbaaef277265a7411b" +dependencies = [ + "cfg-if", + "ecdsa", + "elliptic-curve", + "once_cell", + "sha2", +] + [[package]] name = "keyboard-types" version = "0.7.0" @@ -3272,6 +3674,20 @@ dependencies = [ "unicode-segmentation", ] +[[package]] +name = "keyring" +version = "3.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f8fe839464d4e4b37d756d7e910063696af79a7e877282cb1825e4ec5f10833" +dependencies = [ + "byteorder", + "dbus-secret-service", + "log", + "security-framework 2.11.1", + "security-framework 3.1.0", + "windows-sys 0.59.0", +] + [[package]] name = "kuchikiki" version = "0.8.2" @@ -3311,6 +3727,7 @@ dependencies = [ "tauri-plugin-global-shortcut", "tauri-plugin-http", "tauri-plugin-jarvis", + "tauri-plugin-keyring", "tauri-plugin-log", "tauri-plugin-network", "tauri-plugin-notification", @@ -3320,6 +3737,7 @@ dependencies = [ "tauri-plugin-shellx", "tauri-plugin-single-instance", "tauri-plugin-store", + "tauri-plugin-stronghold", "tauri-plugin-system-info", "tauri-plugin-updater", "tauri-plugin-upload", @@ -3377,6 +3795,39 @@ version = "0.2.161" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e9489c2807c139ffd9c1794f4af0ebe86a828db53ecdc7fea2111d0fed085d1" +[[package]] +name = "libdbus-sys" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06085512b750d640299b79be4bad3d2fa90a9c00b1fd9e1b46364f66f0485c72" +dependencies = [ + "pkg-config", +] + +[[package]] +name = "libflate" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45d9dfdc14ea4ef0900c1cddbc8dcd553fbaacd8a4a282cf4018ae9dd04fb21e" +dependencies = [ + "adler32", + "core2", + "crc32fast", + "dary_heap", + "libflate_lz77", +] + +[[package]] +name = "libflate_lz77" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6e0d73b369f386f1c44abd9c570d5318f55ccde816ff4b562fa452e5182863d" +dependencies = [ + "core2", + "hashbrown 0.14.5", + "rle-decode-fast", +] + [[package]] name = "libfuzzer-sys" version = "0.4.7" @@ -3419,6 +3870,23 @@ dependencies = [ "redox_syscall", ] +[[package]] +name = "libsodium-sys-stable" +version = "1.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "798a1c6d8c3424c0686ca46f2929d81809b371ef61a68c5d1880570584d32b85" +dependencies = [ + "cc", + "libc", + "libflate", + "minisign-verify", + "pkg-config", + "tar", + "ureq", + "vcpkg", + "zip 2.2.2", +] + [[package]] name = "libsqlite3-sys" version = "0.28.0" @@ -3614,6 +4082,15 @@ version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" +[[package]] +name = "memoffset" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce" +dependencies = [ + "autocfg", +] + [[package]] name = "memoffset" version = "0.9.1" @@ -3717,7 +4194,7 @@ dependencies = [ "openssl-probe", "openssl-sys", "schannel", - "security-framework", + "security-framework 2.11.1", "security-framework-sys", "tempfile", ] @@ -3771,6 +4248,18 @@ version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" +[[package]] +name = "nix" +version = "0.24.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa52e972a9a719cecb6864fb88568781eb706bac2cd1d4f04a648542dbf78069" +dependencies = [ + "bitflags 1.3.2", + "cfg-if", + "libc", + "memoffset 0.6.5", +] + [[package]] name = "nix" version = "0.27.1" @@ -3780,7 +4269,7 @@ dependencies = [ "bitflags 2.6.0", "cfg-if", "libc", - "memoffset", + "memoffset 0.9.1", ] [[package]] @@ -3839,6 +4328,20 @@ dependencies = [ "winapi", ] +[[package]] +name = "num" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35bd024e8b2ff75562e5f34e7f4905839deb4b22955ef5e73d2fea1b9813cb23" +dependencies = [ + "num-bigint", + "num-complex", + "num-integer", + "num-iter", + "num-rational", + "num-traits", +] + [[package]] name = "num-bigint" version = "0.4.6" @@ -3849,6 +4352,15 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-complex" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73f88a1307638156682bada9d7604135552957b7818057dcef22705b4d509495" +dependencies = [ + "num-traits", +] + [[package]] name = "num-conv" version = "0.1.0" @@ -3886,6 +4398,17 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-iter" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1429034a0490724d0075ebb2bc9e875d6503c3cf69e235a8941aa757d83ef5bf" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + [[package]] name = "num-rational" version = "0.4.2" @@ -4215,6 +4738,12 @@ version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" +[[package]] +name = "opaque-debug" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" + [[package]] name = "open" version = "5.3.0" @@ -4599,6 +5128,16 @@ dependencies = [ "futures-io", ] +[[package]] +name = "pkcs8" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" +dependencies = [ + "der", + "spki", +] + [[package]] name = "pkg-config" version = "0.3.31" @@ -4662,6 +5201,29 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "poly1305" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8159bd90725d2df49889a078b54f4f79e87f1f8a8444194cdca81d38f5393abf" +dependencies = [ + "cpufeatures", + "opaque-debug", + "universal-hash", +] + +[[package]] +name = "polyval" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d1fe60d06143b2430aa532c94cfe9e29783047f06c0d7fd359a9a51b729fa25" +dependencies = [ + "cfg-if", + "cpufeatures", + "opaque-debug", + "universal-hash", +] + [[package]] name = "powerfmt" version = "0.2.0" @@ -5283,6 +5845,16 @@ dependencies = [ "windows-registry 0.2.0", ] +[[package]] +name = "rfc6979" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" +dependencies = [ + "hmac", + "subtle", +] + [[package]] name = "rfd" version = "0.15.0" @@ -5356,6 +5928,12 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "rle-decode-fast" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3582f63211428f83597b51b2ddb88e2a91a9d52d12831f9d08f5e624e8977422" + [[package]] name = "rusqlite" version = "0.31.0" @@ -5370,6 +5948,29 @@ dependencies = [ "smallvec", ] +[[package]] +name = "rust-argon2" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b50162d19404029c1ceca6f6980fe40d45c8b369f6f44446fa14bb39573b5bb9" +dependencies = [ + "base64 0.13.1", + "blake2b_simd", + "constant_time_eq 0.1.5", + "crossbeam-utils", +] + +[[package]] +name = "rust-argon2" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d9848531d60c9cbbcf9d166c885316c24bc0e2a9d3eba0956bb6cbbd79bc6e8" +dependencies = [ + "base64 0.21.7", + "blake2b_simd", + "constant_time_eq 0.3.1", +] + [[package]] name = "rust-ini" version = "0.21.1" @@ -5550,6 +6151,15 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" +[[package]] +name = "salsa20" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97a22f5af31f73a954c10289c93e8a50cc23d971e80ee446f1f6f7137a088213" +dependencies = [ + "cipher", +] + [[package]] name = "same-file" version = "1.0.6" @@ -5607,6 +6217,17 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +[[package]] +name = "scrypt" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0516a385866c09368f0b5bcd1caff3366aace790fcd46e2bb032697bb172fd1f" +dependencies = [ + "pbkdf2", + "salsa20", + "sha2", +] + [[package]] name = "sct" version = "0.7.1" @@ -5623,6 +6244,20 @@ version = "4.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c107b6f4780854c8b126e228ea8869f4d7b71260f962fefb57b996b8959ba6b" +[[package]] +name = "sec1" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" +dependencies = [ + "base16ct", + "der", + "generic-array", + "pkcs8", + "subtle", + "zeroize", +] + [[package]] name = "security-framework" version = "2.11.1" @@ -5637,10 +6272,23 @@ dependencies = [ ] [[package]] -name = "security-framework-sys" -version = "2.12.0" +name = "security-framework" +version = "3.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" +checksum = "81d3f8c9bfcc3cbb6b0179eb57042d75b1582bdc65c3cb95f3fa999509c03cbc" +dependencies = [ + "bitflags 2.6.0", + "core-foundation 0.10.0", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1863fd3768cd83c56a7f60faa4dc0d403f1b6df0a38c3c25f44b7894e45370d5" dependencies = [ "core-foundation-sys", "libc", @@ -5880,6 +6528,16 @@ dependencies = [ "libc", ] +[[package]] +name = "signature" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" +dependencies = [ + "digest", + "rand_core 0.6.4", +] + [[package]] name = "simd-adler32" version = "0.3.7" @@ -5989,6 +6647,16 @@ dependencies = [ "lock_api", ] +[[package]] +name = "spki" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" +dependencies = [ + "base64ct", + "der", +] + [[package]] name = "stable_deref_trait" version = "1.2.0" @@ -6053,6 +6721,64 @@ dependencies = [ "vte", ] +[[package]] +name = "stronghold-derive" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2835db23c4724c05a2f85b81c4681f4aa8ea158edc8a7f4ad791c916fb766c2e" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "stronghold-runtime" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18db7cc51450cefdab5f4990e128dd02c98da6d2992b93ffef8992ac0d2f3ddf" +dependencies = [ + "dirs 4.0.0", + "iota-crypto", + "libc", + "libsodium-sys-stable", + "log", + "nix 0.24.3", + "rand 0.8.5", + "serde", + "thiserror 1.0.66", + "windows 0.36.1", + "zeroize", +] + +[[package]] +name = "stronghold-utils" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8300214898af5e153e7f66e49dbd1c6a21585f2d592d9f24f58b969792475ed6" +dependencies = [ + "rand 0.8.5", + "stronghold-derive", +] + +[[package]] +name = "stronghold_engine" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fd7371c42e557dd71a7f860bb2ec6b6fdb32f97a97987ccc2435fdd1f3a8615" +dependencies = [ + "anyhow", + "dirs-next", + "hex", + "iota-crypto", + "once_cell", + "paste", + "serde", + "stronghold-runtime", + "thiserror 1.0.66", + "zeroize", +] + [[package]] name = "strsim" version = "0.10.0" @@ -6642,6 +7368,17 @@ dependencies = [ "zip 1.1.4", ] +[[package]] +name = "tauri-plugin-keyring" +version = "0.1.0" +dependencies = [ + "keyring", + "serde", + "tauri", + "tauri-plugin", + "thiserror 2.0.3", +] + [[package]] name = "tauri-plugin-log" version = "2.2.0" @@ -6803,6 +7540,27 @@ dependencies = [ "tracing", ] +[[package]] +name = "tauri-plugin-stronghold" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6670fe0540223d2f6ecc3d71b8e2c513675aac3f0bb5a8a8efc8be5eb81e7b8c" +dependencies = [ + "hex", + "iota-crypto", + "iota_stronghold", + "log", + "rand_chacha 0.3.1", + "rand_core 0.6.4", + "rust-argon2 2.1.0", + "serde", + "serde_json", + "tauri", + "tauri-plugin", + "thiserror 2.0.3", + "zeroize", +] + [[package]] name = "tauri-plugin-system-info" version = "2.0.8" @@ -7465,7 +8223,7 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "89daebc3e6fd160ac4aa9fc8b3bf71e1f74fbf92367ae71fb83a037e8bf164b9" dependencies = [ - "memoffset", + "memoffset 0.9.1", "tempfile", "winapi", ] @@ -7544,6 +8302,16 @@ version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493" +[[package]] +name = "universal-hash" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc1de2c688dc15305988b563c3854064043356019f97a4b46276fe734c4f07ea" +dependencies = [ + "crypto-common", + "subtle", +] + [[package]] name = "untrusted" version = "0.9.0" @@ -7571,6 +8339,18 @@ dependencies = [ "typenum", ] +[[package]] +name = "ureq" +version = "2.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02d1a66277ed75f640d608235660df48c8e3c19f3b4edb6a263315626cc3c01d" +dependencies = [ + "base64 0.22.1", + "log", + "once_cell", + "url", +] + [[package]] name = "url" version = "2.5.2" @@ -8043,6 +8823,19 @@ dependencies = [ "windows-version", ] +[[package]] +name = "windows" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e53b97a83176b369b0eb2fd8158d4ae215357d02df9d40c1e1bf1879c5482c80" +dependencies = [ + "windows_aarch64_msvc 0.36.1", + "windows_i686_gnu 0.36.1", + "windows_i686_msvc 0.36.1", + "windows_x86_64_gnu 0.36.1", + "windows_x86_64_msvc 0.36.1", +] + [[package]] name = "windows" version = "0.52.0" @@ -8328,6 +9121,12 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" +[[package]] +name = "windows_aarch64_msvc" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" + [[package]] name = "windows_aarch64_msvc" version = "0.42.2" @@ -8346,6 +9145,12 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" +[[package]] +name = "windows_i686_gnu" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" + [[package]] name = "windows_i686_gnu" version = "0.42.2" @@ -8370,6 +9175,12 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" +[[package]] +name = "windows_i686_msvc" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" + [[package]] name = "windows_i686_msvc" version = "0.42.2" @@ -8388,6 +9199,12 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" +[[package]] +name = "windows_x86_64_gnu" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" + [[package]] name = "windows_x86_64_gnu" version = "0.42.2" @@ -8424,6 +9241,12 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" +[[package]] +name = "windows_x86_64_msvc" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" + [[package]] name = "windows_x86_64_msvc" version = "0.42.2" @@ -8561,6 +9384,17 @@ version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec107c4503ea0b4a98ef47356329af139c0a4f7750e621cf2973cd3385ebcb3d" +[[package]] +name = "x25519-dalek" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7e468321c81fb07fa7f4c636c3972b9100f0346e5b6a9f2bd0603a52f7ed277" +dependencies = [ + "curve25519-dalek", + "rand_core 0.6.4", + "zeroize", +] + [[package]] name = "xattr" version = "1.3.1" @@ -8674,6 +9508,7 @@ version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" dependencies = [ + "serde", "zeroize_derive", ] @@ -8697,7 +9532,7 @@ dependencies = [ "aes", "arbitrary", "bzip2", - "constant_time_eq", + "constant_time_eq 0.3.1", "crc32fast", "crossbeam-utils", "deflate64", @@ -8724,7 +9559,7 @@ dependencies = [ "aes", "arbitrary", "bzip2", - "constant_time_eq", + "constant_time_eq 0.3.1", "crc32fast", "crossbeam-utils", "deflate64", diff --git a/Cargo.toml b/Cargo.toml index 45caf75..d56e701 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,6 +19,7 @@ tokio = { version = "1.0", features = ["macros", "rt-multi-thread", "signal"] } tokio-util = "0.7.12" mdns-sd = "0.11.1" tauri-plugin-network = { path = "./vendors/tauri-plugin-network" } +tauri-plugin-keyring = { path = "./vendors/tauri-plugin-keyring" } tauri-plugin-clipboard = "2.1.8" mac-security-rs = { path = "./packages/mac-security-rs" } log = "0.4.22" diff --git a/apps/desktop/package.json b/apps/desktop/package.json index 53b8f77..b318311 100644 --- a/apps/desktop/package.json +++ b/apps/desktop/package.json @@ -23,6 +23,7 @@ "@tanstack/table-core": "^8.20.5", "@tauri-apps/api": "^2.1.1", "@tauri-apps/plugin-shell": "^2.2.0", + "@tauri-apps/plugin-stronghold": "^2.2.0", "dompurify": "^3.2.3", "gsap": "^3.12.5", "kkrpc": "^0.0.13", diff --git a/apps/desktop/src-tauri/Cargo.toml b/apps/desktop/src-tauri/Cargo.toml index a31578a..ff1dfac 100644 --- a/apps/desktop/src-tauri/Cargo.toml +++ b/apps/desktop/src-tauri/Cargo.toml @@ -43,6 +43,7 @@ tauri-plugin-http = "2.2.0" tauri-plugin-upload = { workspace = true } # tauri-plugin-upload = "2.2.1" tauri-plugin-jarvis = { workspace = true } +tauri-plugin-keyring = { workspace = true } tauri-plugin-network = { workspace = true } tauri-plugin-system-info = { workspace = true } tauri-plugin-clipboard = { workspace = true } @@ -55,6 +56,7 @@ uuid = "1.11.0" # tauri-plugin-devtools = "2.0.0" obfstr = { workspace = true } base64 = { workspace = true } +tauri-plugin-stronghold = "2.2.0" [target."cfg(target_os = \"macos\")".dependencies] cocoa = "0.24.1" diff --git a/apps/desktop/src-tauri/capabilities/default.json b/apps/desktop/src-tauri/capabilities/default.json index 1b20c60..a01015f 100644 --- a/apps/desktop/src-tauri/capabilities/default.json +++ b/apps/desktop/src-tauri/capabilities/default.json @@ -147,6 +147,8 @@ "process:default", "system-info:allow-all", "shell:default", + "keyring:default", + "stronghold:default", { "identifier": "shell:allow-spawn", "allow": [ diff --git a/apps/desktop/src-tauri/src/commands/keyring.rs b/apps/desktop/src-tauri/src/commands/keyring.rs new file mode 100644 index 0000000..aa891fb --- /dev/null +++ b/apps/desktop/src-tauri/src/commands/keyring.rs @@ -0,0 +1,13 @@ +use tauri::Runtime; +use tauri_plugin_keyring::KeyringExt; + +#[tauri::command] +pub async fn get_stronghold_key(app: tauri::AppHandle) -> Result { + app.keyring() + .get_or_set_password( + "kunkun", + "stronghold_key", + uuid::Uuid::new_v4().to_string().as_str(), + ) + .map_err(|err| err.to_string()) +} diff --git a/apps/desktop/src-tauri/src/commands/mod.rs b/apps/desktop/src-tauri/src/commands/mod.rs new file mode 100644 index 0000000..32aeacc --- /dev/null +++ b/apps/desktop/src-tauri/src/commands/mod.rs @@ -0,0 +1 @@ +pub mod keyring; diff --git a/apps/desktop/src-tauri/src/lib.rs b/apps/desktop/src-tauri/src/lib.rs index 060608b..bb1a857 100644 --- a/apps/desktop/src-tauri/src/lib.rs +++ b/apps/desktop/src-tauri/src/lib.rs @@ -1,4 +1,5 @@ use std::{path::PathBuf, sync::Mutex}; +pub mod commands; mod setup; pub mod utils; use base64::prelude::*; @@ -15,6 +16,7 @@ use tauri_plugin_jarvis::{ settings::AppSettings, }, }; +use tauri_plugin_keyring::KeyringExt; pub use tauri_plugin_log::fern::colors::ColoredLevelConfig; use tauri_plugin_store::{StoreBuilder, StoreExt}; use utils::server::tauri_file_server; @@ -24,15 +26,15 @@ pub fn run() { let context = tauri::generate_context!(); let mut builder = tauri::Builder::default(); - let db_key = if cfg!(debug_assertions) { - None - } else { - let db_enc_key_env = obfstr::obfstr!(env!("DB_ENCRYPTION_KEY")).to_string(); - match db_enc_key_env == "none" { - true => None, - false => Some(db_enc_key_env), - } - }; + // let db_key = if cfg!(debug_assertions) { + // None + // } else { + // let db_enc_key_env = obfstr::obfstr!(env!("DB_ENCRYPTION_KEY")).to_string(); + // match db_enc_key_env == "none" { + // true => None, + // false => Some(db_enc_key_env), + // } + // }; #[cfg(debug_assertions)] { @@ -102,10 +104,12 @@ pub fn run() { .plugin(tauri_plugin_notification::init()) .plugin(tauri_plugin_fs::init()) .plugin(tauri_plugin_shellx::init(shell_unlocked)) - .plugin(tauri_plugin_jarvis::init(db_key.clone())) + .plugin(tauri_plugin_jarvis::init()) .plugin(tauri_plugin_clipboard::init()) + .plugin(tauri_plugin_keyring::init()) .plugin(tauri_plugin_network::init()) - .plugin(tauri_plugin_system_info::init()); + .plugin(tauri_plugin_system_info::init()) + .invoke_handler(tauri::generate_handler![commands::keyring::get_stronghold_key]); let app = builder .register_uri_scheme_protocol("appicon", |_app, request| { @@ -196,6 +200,7 @@ pub fn run() { .setup(move |app| { setup::window::setup_window(app.handle()); setup::tray::create_tray(app.handle())?; + setup::stronghold::setup_stronghold(app.handle())?; #[cfg(all(not(target_os = "macos"), debug_assertions))] { app.deep_link().register("kunkun")?; @@ -241,8 +246,14 @@ pub fn run() { /* ----------------------------- Database Setup ----------------------------- */ // setup::db::setup_db(app)?; - /* ------------------------- Clipboard History Setup ------------------------ */ + let db_key = setup::keyring::setup_keyring(app.handle())?; let db_path = get_kunkun_db_path(app.app_handle())?; + app.manage(tauri_plugin_jarvis::commands::db::DBState::new( + db_path.clone(), + db_key.clone(), + )?); + tauri_plugin_jarvis::setup::db::setup_db(app.app_handle())?; + /* ------------------------- Clipboard History Setup ------------------------ */ // println!("DB_ENCRYPTION_KEY: {:?}", db_key); // let jarvis_db = JarvisDB::new(db_path.clone(), db_key.clone())?; diff --git a/apps/desktop/src-tauri/src/setup/keyring.rs b/apps/desktop/src-tauri/src/setup/keyring.rs new file mode 100644 index 0000000..dbc6ac5 --- /dev/null +++ b/apps/desktop/src-tauri/src/setup/keyring.rs @@ -0,0 +1,14 @@ +use tauri::AppHandle; +use tauri_plugin_keyring::KeyringExt; + +pub fn setup_keyring(app: &AppHandle) -> anyhow::Result> { + Ok(if cfg!(debug_assertions) { + None + } else { + Some(app.keyring().get_or_set_password( + "kunkun", + "db_key", + uuid::Uuid::new_v4().to_string().as_str(), + )?) + }) +} diff --git a/apps/desktop/src-tauri/src/setup/mod.rs b/apps/desktop/src-tauri/src/setup/mod.rs index 309dc48..9d8aeda 100644 --- a/apps/desktop/src-tauri/src/setup/mod.rs +++ b/apps/desktop/src-tauri/src/setup/mod.rs @@ -1,4 +1,6 @@ pub mod clipboard; pub mod deeplink; +pub mod keyring; +pub mod stronghold; pub mod tray; pub mod window; diff --git a/apps/desktop/src-tauri/src/setup/stronghold.rs b/apps/desktop/src-tauri/src/setup/stronghold.rs new file mode 100644 index 0000000..6639a06 --- /dev/null +++ b/apps/desktop/src-tauri/src/setup/stronghold.rs @@ -0,0 +1,12 @@ +use tauri::{AppHandle, Manager}; + +pub fn setup_stronghold(app: &AppHandle) -> tauri::Result<()> { + let salt_path = app + .path() + .app_local_data_dir() + .expect("could not resolve app local data path") + .join("salt.txt"); + app.plugin(tauri_plugin_stronghold::Builder::with_argon2(&salt_path).build())?; + + Ok(()) +} diff --git a/apps/desktop/src/lib/utils/stronghold.ts b/apps/desktop/src/lib/utils/stronghold.ts new file mode 100644 index 0000000..f9ebc4d --- /dev/null +++ b/apps/desktop/src/lib/utils/stronghold.ts @@ -0,0 +1,56 @@ +import { invoke } from "@tauri-apps/api/core" +import { Client, Store, Stronghold } from "@tauri-apps/plugin-stronghold" + +/** + * @returns Stronghold Encryption Key Stored in Keyring + */ +export function getStrongholdKey() { + return invoke("get_stronghold_key") +} + +export class KunkunStronghold { + private stronghold: Stronghold | undefined + private client: Client | undefined + private store: Store | undefined + private vaultPath: string + private clientName: string + + constructor(vaultPath: string, clientName: string) { + this.vaultPath = vaultPath + this.clientName = clientName + } + + async init() { + console.log("init debug 1") + const key = await getStrongholdKey() + console.log("init debug 2", this.vaultPath, "vault password") + this.stronghold = await Stronghold.load(this.vaultPath, "vault password") + console.log("init debug 3") + try { + this.client = await this.stronghold.loadClient(this.clientName) + } catch (error) { + this.client = await this.stronghold.createClient(this.clientName) + } + console.log("init debug 4") + this.store = this.client?.getStore() + } + + insertRecord(key: string, value: string) { + const data = Array.from(new TextEncoder().encode(value)) + return this.store?.insert(key, data) + } + + async getRecord(key: string) { + const data = await this.store?.get(key) + if (!data) return null + return new TextDecoder().decode(new Uint8Array(data)) + } + + removeRecord(key: string) { + return this.store?.remove(key) + } + + save() { + return this.stronghold?.save() + } +} diff --git a/package.json b/package.json index 9a618f3..9e32cab 100644 --- a/package.json +++ b/package.json @@ -46,6 +46,7 @@ "@tauri-apps/plugin-upload": "https://gitpkg.vercel.app/HuakunShen/tauri-plugins-workspace/plugins/upload?69b198b0ccba269fe7622a95ec6a33ae392bff03", "supabase": "^2.1.1", "tauri-plugin-network-api": "workspace:*", + "tauri-plugin-keyring-api": "workspace:*", "tauri-plugin-shellx-api": "^2.0.14", "tauri-plugin-system-info-api": "workspace:*", "valibot": "^1.0.0-beta.9", diff --git a/packages/extension/src/load.ts b/packages/extension/src/load.ts index 55080cc..087a69b 100644 --- a/packages/extension/src/load.ts +++ b/packages/extension/src/load.ts @@ -14,9 +14,7 @@ import { upsertExtension } from "./db" export function loadExtensionManifestFromDisk(manifestPath: string): Promise { debug(`loadExtensionManifestFromDisk: ${manifestPath}`) return readTextFile(manifestPath).then(async (content) => { - console.log("content", content) const json = JSON.parse(content) - console.log("manifest json", json) const parse = v.safeParse(ExtPackageJson, json) if (parse.issues) { error(`Fail to load extension from ${manifestPath}. See console for parse error.`) diff --git a/packages/tauri-plugins/jarvis/src/lib.rs b/packages/tauri-plugins/jarvis/src/lib.rs index 61c18b9..c869b26 100644 --- a/packages/tauri-plugins/jarvis/src/lib.rs +++ b/packages/tauri-plugins/jarvis/src/lib.rs @@ -53,7 +53,7 @@ impl JarvisState { } /// Initializes the plugin. -pub fn init(db_key: Option) -> TauriPlugin { +pub fn init() -> TauriPlugin { Builder::new("jarvis") .invoke_handler(tauri::generate_handler![ /* ------------------------------ dev commands ------------------------------ */ @@ -185,9 +185,6 @@ pub fn init(db_key: Option) -> TauriPlugin { app.manage(JarvisState::new()); app.manage(FileTransferState::default()); app.manage(commands::apps::ApplicationsState::default()); - let db_path = get_kunkun_db_path(app)?; - app.manage(commands::db::DBState::new(db_path.clone(), db_key.clone())?); - setup::db::setup_db(app)?; println!("Jarvis Plugin Initialized"); app.manage(Peers::default()); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5b652fe..0357697 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -65,6 +65,9 @@ importers: supabase: specifier: ^2.1.1 version: 2.1.1 + tauri-plugin-keyring-api: + specifier: workspace:* + version: link:vendors/tauri-plugin-keyring tauri-plugin-network-api: specifier: workspace:* version: link:vendors/tauri-plugin-network @@ -230,6 +233,9 @@ importers: '@tauri-apps/plugin-shell': specifier: ^2.2.0 version: 2.2.0 + '@tauri-apps/plugin-stronghold': + specifier: ^2.2.0 + version: 2.2.0 dompurify: specifier: ^3.2.3 version: 3.2.3 @@ -1160,6 +1166,28 @@ importers: specifier: latest version: 1.1.14 + vendors/tauri-plugin-keyring: + dependencies: + '@tauri-apps/api': + specifier: ^2.1.1 + version: 2.1.1 + devDependencies: + '@rollup/plugin-typescript': + specifier: ^11.1.6 + version: 11.1.6(rollup@4.28.1)(tslib@2.8.1)(typescript@5.6.3) + rollup: + specifier: ^4.9.6 + version: 4.28.1 + tslib: + specifier: ^2.6.2 + version: 2.8.1 + typedoc: + specifier: ^0.27.5 + version: 0.27.5(typescript@5.6.3) + typescript: + specifier: ^5.3.3 + version: 5.6.3 + vendors/tauri-plugin-network: dependencies: '@tauri-apps/api': @@ -4111,6 +4139,9 @@ packages: '@tauri-apps/plugin-store@2.2.0': resolution: {integrity: sha512-hJTRtuJis4w5fW1dkcgftsYxKXK0+DbAqurZ3CURHG5WkAyyZgbxpeYctw12bbzF9ZbZREXZklPq8mocCC3Sgg==} + '@tauri-apps/plugin-stronghold@2.2.0': + resolution: {integrity: sha512-N0SxfcNifvlXQ3ZHGxx9ecWNZGXtYJ6PBL0Ac8bGs90I2e2a0+JJcsAnMxQA5XQcIQfpYIXPgf0hNCliz828fw==} + '@tauri-apps/plugin-updater@2.3.0': resolution: {integrity: sha512-qdzyZEUN69FZQ/nRx51fBub10tT6wffJl3DLVo9q922Gvw8Wk++rZhoD9eethPlZYbog/7RGgT8JkrfLh5BKAg==} @@ -14208,6 +14239,10 @@ snapshots: dependencies: '@tauri-apps/api': 2.1.1 + '@tauri-apps/plugin-stronghold@2.2.0': + dependencies: + '@tauri-apps/api': 2.1.1 + '@tauri-apps/plugin-updater@2.3.0': dependencies: '@tauri-apps/api': 2.1.1 @@ -16768,8 +16803,8 @@ snapshots: '@typescript-eslint/parser': 8.15.0(eslint@8.57.1)(typescript@5.6.3) eslint: 8.57.1 eslint-import-resolver-node: 0.3.9 - eslint-import-resolver-typescript: 3.6.3(@typescript-eslint/parser@8.15.0(eslint@8.57.1)(typescript@5.6.3))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.31.0(@typescript-eslint/parser@8.15.0(eslint@8.57.1)(typescript@5.6.3))(eslint@8.57.1))(eslint@8.57.1) - eslint-plugin-import: 2.31.0(@typescript-eslint/parser@8.15.0(eslint@8.57.1)(typescript@5.6.3))(eslint-import-resolver-typescript@3.6.3(@typescript-eslint/parser@8.15.0(eslint@8.57.1)(typescript@5.6.3))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.31.0(@typescript-eslint/parser@8.15.0(eslint@8.57.1)(typescript@5.6.3))(eslint@8.57.1))(eslint@8.57.1))(eslint@8.57.1) + eslint-import-resolver-typescript: 3.6.3(@typescript-eslint/parser@8.15.0(eslint@8.57.1)(typescript@5.6.3))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.31.0)(eslint@8.57.1) + eslint-plugin-import: 2.31.0(@typescript-eslint/parser@8.15.0(eslint@8.57.1)(typescript@5.6.3))(eslint-import-resolver-typescript@3.6.3)(eslint@8.57.1) eslint-plugin-jsx-a11y: 6.10.2(eslint@8.57.1) eslint-plugin-react: 7.37.2(eslint@8.57.1) eslint-plugin-react-hooks: 5.0.0(eslint@8.57.1) @@ -16797,37 +16832,37 @@ snapshots: transitivePeerDependencies: - supports-color - eslint-import-resolver-typescript@3.6.3(@typescript-eslint/parser@8.15.0(eslint@8.57.1)(typescript@5.6.3))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.31.0(@typescript-eslint/parser@8.15.0(eslint@8.57.1)(typescript@5.6.3))(eslint@8.57.1))(eslint@8.57.1): + eslint-import-resolver-typescript@3.6.3(@typescript-eslint/parser@8.15.0(eslint@8.57.1)(typescript@5.6.3))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.31.0)(eslint@8.57.1): dependencies: '@nolyfill/is-core-module': 1.0.39 debug: 4.3.7(supports-color@9.4.0) enhanced-resolve: 5.17.1 eslint: 8.57.1 - eslint-module-utils: 2.12.0(@typescript-eslint/parser@8.15.0(eslint@8.57.1)(typescript@5.6.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.3(@typescript-eslint/parser@8.15.0(eslint@8.57.1)(typescript@5.6.3))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.31.0(@typescript-eslint/parser@8.15.0(eslint@8.57.1)(typescript@5.6.3))(eslint@8.57.1))(eslint@8.57.1))(eslint@8.57.1) + eslint-module-utils: 2.12.0(@typescript-eslint/parser@8.15.0(eslint@8.57.1)(typescript@5.6.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.3)(eslint@8.57.1) fast-glob: 3.3.2 get-tsconfig: 4.8.1 is-bun-module: 1.2.1 is-glob: 4.0.3 optionalDependencies: - eslint-plugin-import: 2.31.0(@typescript-eslint/parser@8.15.0(eslint@8.57.1)(typescript@5.6.3))(eslint-import-resolver-typescript@3.6.3(@typescript-eslint/parser@8.15.0(eslint@8.57.1)(typescript@5.6.3))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.31.0(@typescript-eslint/parser@8.15.0(eslint@8.57.1)(typescript@5.6.3))(eslint@8.57.1))(eslint@8.57.1))(eslint@8.57.1) + eslint-plugin-import: 2.31.0(@typescript-eslint/parser@8.15.0(eslint@8.57.1)(typescript@5.6.3))(eslint-import-resolver-typescript@3.6.3)(eslint@8.57.1) transitivePeerDependencies: - '@typescript-eslint/parser' - eslint-import-resolver-node - eslint-import-resolver-webpack - supports-color - eslint-module-utils@2.12.0(@typescript-eslint/parser@8.15.0(eslint@8.57.1)(typescript@5.6.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.3(@typescript-eslint/parser@8.15.0(eslint@8.57.1)(typescript@5.6.3))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.31.0(@typescript-eslint/parser@8.15.0(eslint@8.57.1)(typescript@5.6.3))(eslint@8.57.1))(eslint@8.57.1))(eslint@8.57.1): + eslint-module-utils@2.12.0(@typescript-eslint/parser@8.15.0(eslint@8.57.1)(typescript@5.6.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.3)(eslint@8.57.1): dependencies: debug: 3.2.7 optionalDependencies: '@typescript-eslint/parser': 8.15.0(eslint@8.57.1)(typescript@5.6.3) eslint: 8.57.1 eslint-import-resolver-node: 0.3.9 - eslint-import-resolver-typescript: 3.6.3(@typescript-eslint/parser@8.15.0(eslint@8.57.1)(typescript@5.6.3))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.31.0(@typescript-eslint/parser@8.15.0(eslint@8.57.1)(typescript@5.6.3))(eslint@8.57.1))(eslint@8.57.1) + eslint-import-resolver-typescript: 3.6.3(@typescript-eslint/parser@8.15.0(eslint@8.57.1)(typescript@5.6.3))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.31.0)(eslint@8.57.1) transitivePeerDependencies: - supports-color - eslint-plugin-import@2.31.0(@typescript-eslint/parser@8.15.0(eslint@8.57.1)(typescript@5.6.3))(eslint-import-resolver-typescript@3.6.3(@typescript-eslint/parser@8.15.0(eslint@8.57.1)(typescript@5.6.3))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.31.0(@typescript-eslint/parser@8.15.0(eslint@8.57.1)(typescript@5.6.3))(eslint@8.57.1))(eslint@8.57.1))(eslint@8.57.1): + eslint-plugin-import@2.31.0(@typescript-eslint/parser@8.15.0(eslint@8.57.1)(typescript@5.6.3))(eslint-import-resolver-typescript@3.6.3)(eslint@8.57.1): dependencies: '@rtsao/scc': 1.1.0 array-includes: 3.1.8 @@ -16838,7 +16873,7 @@ snapshots: doctrine: 2.1.0 eslint: 8.57.1 eslint-import-resolver-node: 0.3.9 - eslint-module-utils: 2.12.0(@typescript-eslint/parser@8.15.0(eslint@8.57.1)(typescript@5.6.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.3(@typescript-eslint/parser@8.15.0(eslint@8.57.1)(typescript@5.6.3))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.31.0(@typescript-eslint/parser@8.15.0(eslint@8.57.1)(typescript@5.6.3))(eslint@8.57.1))(eslint@8.57.1))(eslint@8.57.1) + eslint-module-utils: 2.12.0(@typescript-eslint/parser@8.15.0(eslint@8.57.1)(typescript@5.6.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.3)(eslint@8.57.1) hasown: 2.0.2 is-core-module: 2.15.1 is-glob: 4.0.3 diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index 4d5870d..917e24c 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -5,6 +5,7 @@ packages: - "packages/templates/*" - "packages/tauri-plugins/*" - "vendors/tauri-plugin-network" + - "vendors/tauri-plugin-keyring" - "vendors/tauri-plugin-system-info" - "vendors/kkrpc/packages/kkrpc" diff --git a/vendors/tauri-plugin-keyring b/vendors/tauri-plugin-keyring new file mode 160000 index 0000000..9444a75 --- /dev/null +++ b/vendors/tauri-plugin-keyring @@ -0,0 +1 @@ +Subproject commit 9444a75884a4a7ce1f22ebf3e65ea36de49acd8c diff --git a/vendors/tauri-plugin-system-info b/vendors/tauri-plugin-system-info index b755ff4..990320d 160000 --- a/vendors/tauri-plugin-system-info +++ b/vendors/tauri-plugin-system-info @@ -1 +1 @@ -Subproject commit b755ff494e0b58e46459dc1484b8b9f65e9c1a9a +Subproject commit 990320d9068b832c6291bccb1e252cf7175bd4a6