diff --git a/packages/secrets/src/keyring/Cargo.lock b/packages/secrets/src/keyring/Cargo.lock index 33b3050595..ca9f2a105d 100644 --- a/packages/secrets/src/keyring/Cargo.lock +++ b/packages/secrets/src/keyring/Cargo.lock @@ -11,24 +11,12 @@ dependencies = [ "memchr", ] -[[package]] -name = "anyhow" -version = "1.0.72" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b13c32d80ecc7ab747b80c3784bce54ee8a7a0cc4fbda9bf4cda2cf6fe90854" - [[package]] name = "autocfg" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" -[[package]] -name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - [[package]] name = "bitflags" version = "2.3.3" @@ -157,11 +145,10 @@ dependencies = [ [[package]] name = "gio" -version = "0.17.10" +version = "0.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6973e92937cf98689b6a054a9e56c657ed4ff76de925e36fc331a15f0c5d30a" +checksum = "57052f84e8e5999b258e8adf8f5f2af0ac69033864936b8b6838321db2f759b1" dependencies = [ - "bitflags 1.3.2", "futures-channel", "futures-core", "futures-io", @@ -177,9 +164,9 @@ dependencies = [ [[package]] name = "gio-sys" -version = "0.17.10" +version = "0.18.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ccf87c30a12c469b6d958950f6a9c09f2be20b7773f7e70d20b867fdf2628c3" +checksum = "37566df850baf5e4cb0dfb78af2e4b9898d817ed9263d1090a2df958c64737d2" dependencies = [ "glib-sys", "gobject-sys", @@ -190,11 +177,11 @@ dependencies = [ [[package]] name = "glib" -version = "0.17.10" +version = "0.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3fad45ba8d4d2cea612b432717e834f48031cd8853c8aaf43b2c79fec8d144b" +checksum = "1c316afb01ce8067c5eaab1fc4f2cd47dc21ce7b6296358605e2ffab23ccbd19" dependencies = [ - "bitflags 1.3.2", + "bitflags", "futures-channel", "futures-core", "futures-executor", @@ -213,24 +200,23 @@ dependencies = [ [[package]] name = "glib-macros" -version = "0.17.10" +version = "0.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eca5c79337338391f1ab8058d6698125034ce8ef31b72a442437fa6c8580de26" +checksum = "f8da903822b136d42360518653fcf154455defc437d3e7a81475bf9a95ff1e47" dependencies = [ - "anyhow", "heck", "proc-macro-crate", "proc-macro-error", "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.28", ] [[package]] name = "glib-sys" -version = "0.17.10" +version = "0.18.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d80aa6ea7bba0baac79222204aa786a6293078c210abe69ef1336911d4bdc4f0" +checksum = "063ce2eb6a8d0ea93d2bf8ba1957e78dbab6be1c2220dd3daca57d5a9d869898" dependencies = [ "libc", "system-deps", @@ -238,9 +224,9 @@ dependencies = [ [[package]] name = "gobject-sys" -version = "0.17.10" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd34c3317740a6358ec04572c1bcfd3ac0b5b6529275fae255b237b314bb8062" +checksum = "0850127b514d1c4a4654ead6dedadb18198999985908e6ffe4436f53c785ce44" dependencies = [ "glib-sys", "libc", @@ -306,23 +292,21 @@ dependencies = [ [[package]] name = "libsecret" -version = "0.3.0" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accb700635d0b1b296d83c93fa5d112400168d04481db0ccca946293af9f0206" +checksum = "ac6fae6ebe590e06ef9d01b125e46b7d4c05ccbd5961f12b4aefe2ecd010220f" dependencies = [ - "bitflags 1.3.2", "gio", "glib", "libc", "libsecret-sys", - "once_cell", ] [[package]] name = "libsecret-sys" -version = "0.3.0" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b06012ca123d27ccceffa112d0f930c23eb549a2447dc710e99f5dc2d1040b2" +checksum = "9b716fc5e1c82eb0d28665882628382ab0e0a156a6d73580e33f0ac6ac8d2540" dependencies = [ "gio-sys", "glib-sys", @@ -344,7 +328,7 @@ version = "2.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ede2d12cd6fce44da537a4be1f5510c73be2506c2e32dfaaafd1f36968f3a0e" dependencies = [ - "bitflags 2.3.3", + "bitflags", "ctor", "napi-derive", "napi-sys", diff --git a/packages/secrets/src/keyring/Cargo.toml b/packages/secrets/src/keyring/Cargo.toml index a6bf582f48..24829da005 100644 --- a/packages/secrets/src/keyring/Cargo.toml +++ b/packages/secrets/src/keyring/Cargo.toml @@ -31,11 +31,11 @@ core-foundation = "0.9.3" core-foundation-sys = "0.8.4" [target.'cfg(any(target_os = "freebsd", target_os = "linux"))'.dependencies] -glib = "0.17.10" -glib-sys = "0.17.10" -gio = "0.17.10" -libsecret = "0.3.0" -libsecret-sys = "0.3.0" +glib = "0.18.2" +glib-sys = "0.18.1" +gio = "0.18.2" +libsecret = "0.4.0" +libsecret-sys = "0.4.0" [build-dependencies] napi-build = "2" @@ -43,4 +43,4 @@ napi-build = "2" [profile.release] lto = true opt-level = "z" # Optimize for size. -strip = "symbols" \ No newline at end of file +strip = "symbols" diff --git a/packages/secrets/src/keyring/__test__/index.spec.mjs b/packages/secrets/src/keyring/__test__/index.spec.mjs index e8d3fce976..6ca2cd4c60 100644 --- a/packages/secrets/src/keyring/__test__/index.spec.mjs +++ b/packages/secrets/src/keyring/__test__/index.spec.mjs @@ -163,6 +163,17 @@ test.serial( } ); +test.serial("findCredentials works when only one credential is found", async (t) => { + await setPassword("TestKeyring2", "TestOneCred", "pass"); + + const creds = await findCredentials("TestKeyring2"); + t.deepEqual(creds, [{ + account: "TestOneCred", + password: "pass" + }]); + await deletePassword("TestKeyring2", "TestOneCred"); +}); + test.serial("findPassword for ASCII string", async (t) => { const pw = await findPassword("TestKeyring/TestASCII"); t.is(pw, "ASCII string"); @@ -183,17 +194,6 @@ test.serial("findPassword for CJK symbols", async (t) => { t.is(pw, "「こんにちは世界」"); }); -test.serial("findCredentials works when only one credential is found", async (t) => { - await setPassword("TestKeyring2", "TestOneCred", "pass"); - - const creds = await findCredentials("TestKeyring2"); - t.deepEqual(creds, [{ - account: "TestOneCred", - password: "pass" - }]); - await deletePassword("TestKeyring2", "TestOneCred"); -}); - test("deletePassword deletes all test credentials", async (t) => { console.log( "\nThe deletePassword test is running. There is an intended delay of 5 seconds to wait for the keyring to update." diff --git a/packages/secrets/src/keyring/src/os/unix.rs b/packages/secrets/src/keyring/src/os/unix.rs index c84473531e..db121368c0 100644 --- a/packages/secrets/src/keyring/src/os/unix.rs +++ b/packages/secrets/src/keyring/src/os/unix.rs @@ -4,6 +4,7 @@ use glib::translate::{FromGlibPtrContainer, ToGlibPtr}; use glib_sys::{g_hash_table_unref}; use libsecret::{ prelude::CollectionExtManual, traits::ItemExt, SearchFlags, Service, ServiceFlags, + password_free }; use std::collections::HashMap; @@ -181,32 +182,29 @@ pub fn find_credentials( match collection.search_sync( Some(&get_schema()), HashMap::from([("service", service.as_str())]), - SearchFlags::ALL | SearchFlags::LOAD_SECRETS, + SearchFlags::ALL | SearchFlags::UNLOCK | SearchFlags::LOAD_SECRETS, gio::Cancellable::NONE, ) { Ok(vec) => { let valid_creds: Vec<(String, String)> = vec .iter() .filter_map(|item| { - let attrs: HashMap = unsafe { - let attrs = - libsecret_sys::secret_item_get_attributes(item.to_glib_none().0); - FromGlibPtrContainer::from_glib_full(attrs) - }; match item.secret() { Some(secret) => { + let attrs: HashMap = unsafe { + let attrs = libsecret_sys::secret_item_get_attributes(item.to_glib_none().0); + FromGlibPtrContainer::from_glib_full(attrs) + }; let bytes = secret.get(); - let acc = attrs.get("account").unwrap().clone(); let pw = String::from_utf8(bytes).unwrap_or("".to_string()); + + let acc = attrs.get("account").unwrap().clone(); unsafe { - secret.unref(); g_hash_table_unref(attrs.to_glib_full()); } - Some((acc, pw)) } None => { - g_hash_table_unref(attrs.to_glib_full()); None }, }