Skip to content

Native iCloud apps for Windows and Linux, built in Rust. Notes, Reminders, Calendar, Contacts, Drive and Photos, offline and in sync with your iPhone.

Hidden: Windows Hello on Windows, its prompt owned by Skykeep's window; the password everywhere

Yashwanth Kamireddiffb56756dd21
diff --git a/.uiverify/photos-hidden-lock.mjs b/.uiverify/photos-hidden-lock.mjs
index 02d6593..dd004ce 100644
--- a/.uiverify/photos-hidden-lock.mjs
+++ b/.uiverify/photos-hidden-lock.mjs
@@ -104,6 +104,28 @@ await comeBack();
await page.waitForTimeout(200);
ok(await isLocked(), "…and the album is locked behind it");
+// Windows Hello, where it is set up: offered beside the password; declined, still locked with
+// the password still there; verified, unlocked. Not set up (Linux, or no Hello): not offered.
+await openScreen(page, "Photos");
+await page.waitForTimeout(200);
+await openHidden();
+await view.click();
+ok((await sheet.getByRole("button", { name: "Use Windows Hello" }).count()) === 0, "without Windows Hello, only the password is asked");
+await page.keyboard.press("Escape");
+await page.evaluate(() => { window.__hello = "declined"; });
+await view.click();
+await sheet.getByRole("button", { name: "Use Windows Hello" }).click();
+await page.waitForTimeout(250);
+ok(await sheet.count() === 1 && await isLocked() && (await sheet.getByLabel("Password").count()) === 1, "Windows Hello declined: still locked, the password still there");
+await page.evaluate(() => { window.__hello = "verified"; });
+await sheet.getByRole("button", { name: "Use Windows Hello" }).click();
+await page.locator('.px-tile[data-id="p2"]').waitFor({ timeout: 3000 });
+ok(await sheet.count() === 0 && (await tiles()).includes("p2"), "Windows Hello verified: Hidden opens");
+await page.evaluate(() => { window.__hello = undefined; });
+await page.locator(".px-source", { hasText: "Library" }).first().click();
+await page.waitForTimeout(250);
+await openHidden();
+
// A new start: locked.
await unlock();
await page.reload({ waitUntil: "networkidle" });
diff --git a/.uiverify/stub.mjs b/.uiverify/stub.mjs
index ba912d6..470645e 100644
--- a/.uiverify/stub.mjs
+++ b/.uiverify/stub.mjs
@@ -673,6 +673,12 @@ export function installStub({ screen, services, twoFactor, calendarFixture, note
window.__hiddenOpen = true;
return null;
case "photos_lock_hidden": (window.__hiddenCalls ??= []).push("lock"); window.__hiddenOpen = false; return null;
+ // Windows Hello: offered only where a test says it is set up (`__hello`: its answer).
+ case "photos_hello_available": return Boolean(window.__hello);
+ case "photos_unlock_hidden_hello":
+ (window.__hiddenCalls ??= []).push("hello");
+ if (window.__hello === "verified") window.__hiddenOpen = true;
+ return window.__hello ?? "unavailable";
case "photos_index": case "photos_page": {
const self = window.__TAURI_INTERNALS__.invoke;
const src = args.source;
diff --git a/Cargo.lock b/Cargo.lock
index 797a7cd..3fbf7c5 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -4065,6 +4065,7 @@ dependencies = [
"uuid",
"webkit2gtk",
"windows 0.62.2",
+ "windows-future 0.3.2",
"wiremock",
"zbus 5.19.0",
]
diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml
index 4bb4439..785d99e 100644
--- a/src-tauri/Cargo.toml
+++ b/src-tauri/Cargo.toml
@@ -58,6 +58,9 @@ tauri = { version = "2", features = ["tray-icon"] }
# Toasts with buttons on Windows (notify-rust sends none there): the same crate notify-rust uses.
[target.'cfg(windows)'.dependencies]
tauri-winrt-notification = "0.8"
+# The asynchronous operations the windows crate's WinRT calls answer with (hello.rs waits on
+# Windows Hello's): the same 0.3 the windows crate itself is built on.
+windows-future = "0.3"
# Each app its own taskbar button and the jump list's tasks (taskbar.rs), and whether this copy
# is an MSIX package's (package.rs) and its startup task (login.rs): the shell's own calls,
# from the same build of the crate Tauri and the toasts already compile.
@@ -76,6 +79,10 @@ windows = { version = "0.62", features = [
"Win32_UI_Shell",
"Win32_UI_Shell_Common",
"Win32_UI_Shell_PropertiesSystem",
+ # Windows Hello for the Hidden album (hello.rs): the consent verifier, owned by our window.
+ "Foundation",
+ "Security_Credentials_UI",
+ "Win32_System_WinRT",
] }
[target.'cfg(target_os = "linux")'.dependencies]
diff --git a/src-tauri/src/hello.rs b/src-tauri/src/hello.rs
new file mode 100644
index 0000000..a2da156
--- /dev/null
+++ b/src-tauri/src/hello.rs
@@ -0,0 +1,86 @@
+//! Windows Hello — face, fingerprint or PIN — to unlock the Hidden album on Windows, as Face ID
+//! unlocks it on an iPhone. The prompt is owned by Skykeep's own window
+//! (`IUserConsentVerifierInterop::RequestVerificationForWindowAsync`, reached through the
+//! activation factory): asked for the plain WinRT way, a desktop app's prompt has no owner and
+//! can open behind the window or at the corner of the screen (bitwarden/desktop#641). Where
+//! Hello isn't set up, or isn't Windows, it isn't offered; the Apple Account password always is.
+
+/// What asking Windows Hello came to.
+#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize)]
+#[serde(rename_all = "camelCase")]
+pub enum Hello {
+ Verified,
+ /// The person cancelled, or Windows Hello said no.
+ #[cfg_attr(not(windows), allow(dead_code))]
+ Declined,
+ /// Not set up on this computer (or not Windows): the password is asked instead.
+ Unavailable,
+}
+
+/// Whether Windows Hello can be asked on this computer.
+pub async fn available() -> bool {
+ #[cfg(windows)]
+ {
+ tokio::task::spawn_blocking(|| {
+ use windows::Security::Credentials::UI::{
+ UserConsentVerifier, UserConsentVerifierAvailability,
+ };
+ UserConsentVerifier::CheckAvailabilityAsync()
+ .and_then(|op| op.join())
+ .is_ok_and(|a| a == UserConsentVerifierAvailability::Available)
+ })
+ .await
+ .unwrap_or(false)
+ }
+ #[cfg(not(windows))]
+ {
+ false
+ }
+}
+
+/// Windows Hello asked, its prompt owned by the window `hwnd`, saying `message`.
+pub async fn verify(hwnd: isize, message: String) -> Hello {
+ #[cfg(windows)]
+ {
+ if !available().await {
+ return Hello::Unavailable;
+ }
+ tokio::task::spawn_blocking(move || {
+ use windows::core::{factory, HSTRING};
+ use windows::Security::Credentials::UI::{
+ UserConsentVerificationResult, UserConsentVerifier,
+ };
+ use windows::Win32::Foundation::HWND;
+ use windows::Win32::System::WinRT::IUserConsentVerifierInterop;
+ use windows_future::IAsyncOperation;
+ let asked = || -> windows::core::Result<UserConsentVerificationResult> {
+ let interop = factory::<UserConsentVerifier, IUserConsentVerifierInterop>()?;
+ // SAFETY: `hwnd` is this app's own window, alive while the prompt is up (the
+ // window waits on the answer); the call only reads it as the prompt's owner.
+ let op: IAsyncOperation<UserConsentVerificationResult> = unsafe {
+ interop.RequestVerificationForWindowAsync(
+ HWND(hwnd as *mut core::ffi::c_void),
+ &HSTRING::from(message.as_str()),
+ )
+ }?;
+ op.join()
+ };
+ match asked() {
+ Ok(UserConsentVerificationResult::Verified) => Hello::Verified,
+ Ok(
+ UserConsentVerificationResult::DeviceNotPresent
+ | UserConsentVerificationResult::NotConfiguredForUser
+ | UserConsentVerificationResult::DisabledByPolicy,
+ ) => Hello::Unavailable,
+ Ok(_) | Err(_) => Hello::Declined,
+ }
+ })
+ .await
+ .unwrap_or(Hello::Declined)
+ }
+ #[cfg(not(windows))]
+ {
+ let _ = (hwnd, message);
+ Hello::Unavailable
+ }
+}
diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs
index 6238550..e676573 100644
--- a/src-tauri/src/main.rs
+++ b/src-tauri/src/main.rs
@@ -25,6 +25,7 @@ mod drive_watch;
mod export;
mod folder_download;
mod grants;
+mod hello;
mod intake;
mod library_lock;
mod links;
@@ -7308,6 +7309,8 @@ fn main() {
photos::photos_shared_albums,
photos::photos_unlock_hidden,
photos::photos_lock_hidden,
+ photos::photos_hello_available,
+ photos::photos_unlock_hidden_hello,
photos::photos_prepare,
photos::photos_index,
photos::photos_months,
diff --git a/src-tauri/src/photos.rs b/src-tauri/src/photos.rs
index 25763e7..6c39055 100644
--- a/src-tauri/src/photos.rs
+++ b/src-tauri/src/photos.rs
@@ -101,6 +101,35 @@ pub async fn photos_unlock_hidden(password: String, auth: State<'_, Auth>) -> Ui
Err("That password isn't right.".into())
}
+/// Whether Hidden can be unlocked with Windows Hello on this computer (never elsewhere).
+#[tauri::command]
+pub async fn photos_hello_available() -> bool {
+ crate::hello::available().await
+}
+
+/// The Hidden album unlocked with Windows Hello — face, fingerprint or PIN — its prompt owned
+/// by the window that asked. Answers what came of it; Verified unlocks.
+#[tauri::command]
+pub async fn photos_unlock_hidden_hello(
+ window: tauri::WebviewWindow,
+) -> UiResult<crate::hello::Hello> {
+ #[cfg(windows)]
+ let hwnd = window.hwnd().map_err(|e| e.to_string())?.0 as isize;
+ #[cfg(not(windows))]
+ let hwnd = {
+ let _ = &window;
+ 0
+ };
+ let outcome = crate::hello::verify(hwnd, "Unlock the Hidden album in Skykeep".into()).await;
+ if outcome == crate::hello::Hello::Verified {
+ *HIDDEN_TRIES
+ .lock()
+ .unwrap_or_else(std::sync::PoisonError::into_inner) = (0, None);
+ HIDDEN_OPEN.store(true, std::sync::atomic::Ordering::SeqCst);
+ }
+ Ok(outcome)
+}
+
/// The Hidden album locked again: the window left it, or went out of sight.
#[tauri::command]
pub fn photos_lock_hidden() {
diff --git a/src/lib/ipc.ts b/src/lib/ipc.ts
index 71e09d3..ddba761 100644
--- a/src/lib/ipc.ts
+++ b/src/lib/ipc.ts
@@ -297,6 +297,9 @@ export const api = {
/** The Hidden album unlocked with the Apple ID password; refused with why (wrong, or a wait). */
photosUnlockHidden: (password: string) => invoke<void>("photos_unlock_hidden", { password }),
photosLockHidden: () => invoke<void>("photos_lock_hidden"),
+ /** Whether Windows Hello can unlock Hidden here (Windows, with Hello set up). */
+ photosHelloAvailable: () => invoke<boolean>("photos_hello_available"),
+ photosUnlockHiddenHello: () => invoke<"verified" | "declined" | "unavailable">("photos_unlock_hidden_hello"),
/** Every photo of one burst, in the order they were shot. */
photosBurst: (burst: string) => invoke<Photo[]>("photos_burst", { burst }),
/** Favorite, Delete (to Recently Deleted) or Recover; answers the photo as Apple now has it. */
diff --git a/src/screens/PhotosView.tsx b/src/screens/PhotosView.tsx
index a71e8fa..213563f 100644
--- a/src/screens/PhotosView.tsx
+++ b/src/screens/PhotosView.tsx
@@ -4244,7 +4244,25 @@ function UnlockSheet({ onCancel, onUnlocked }: { onCancel: () => void; onUnlocke
const [password, setPassword] = useState("");
const [busy, setBusy] = useState(false);
const [problem, setProblem] = useState<string | null>(null);
+ /** Windows Hello set up on this computer: offered first, as Face ID is on a phone. */
+ const [hello, setHello] = useState(false);
useEffect(() => field.current?.focus(), []);
+ useEffect(() => {
+ api.photosHelloAvailable().then(setHello, () => setHello(false));
+ }, []);
+ const withHello = async () => {
+ setBusy(true);
+ setProblem(null);
+ try {
+ const outcome = await api.photosUnlockHiddenHello();
+ if (outcome === "verified") return onUnlocked();
+ if (outcome === "unavailable") setHello(false);
+ } catch (e) {
+ setProblem(messageOf(e));
+ }
+ setBusy(false);
+ field.current?.focus();
+ };
const go = async () => {
if (!password || busy) return;
setBusy(true);
@@ -4300,6 +4318,11 @@ function UnlockSheet({ onCancel, onUnlocked }: { onCancel: () => void; onUnlocke
{problem}
</p>
)}
+ {hello && (
+ <button type="button" className="quiet px-unlock-hello" disabled={busy} onClick={() => void withHello()}>
+ Use Windows Hello
+ </button>
+ )}
<div className="confirm-actions">
<button type="button" className="quiet" onClick={onCancel}>
Cancel
diff --git a/src/styles/photos.css b/src/styles/photos.css
index 715cefa..84b7963 100644
--- a/src/styles/photos.css
+++ b/src/styles/photos.css
@@ -694,6 +694,7 @@
.px-shared-name { width: 100%; min-height: 34px; font-size: var(--t-15); }
/* Hidden's password sheet: the field the sheet's width, and a wrong password said under it. */
.px-unlock .field { width: 100%; min-height: 34px; font-size: var(--t-15); }
+.px-unlock .px-unlock-hello { width: 100%; margin-top: 8px; }
.px-unlock .px-unlock-problem { color: var(--danger); font-size: var(--t-13); margin: 6px 0 0; }
.px-dl-pics { display: flex; justify-content: center; gap: 4px; }
.px-dl-pics img { width: 58px; height: 58px; border-radius: 8px; object-fit: cover; background: color-mix(in srgb, var(--text) 8%, transparent); }