diff --git a/interface/libraries/encryption.ts b/interface/libraries/encryption.ts index f11e24d..ba96dde 100644 --- a/interface/libraries/encryption.ts +++ b/interface/libraries/encryption.ts @@ -1,4 +1,7 @@ import { invoke, dialog } from "@tauri-apps/api" +import { getSettings, setSettings } from "interface/stores/settings" + +const settings = getSettings() /** * Generates random key @@ -66,3 +69,67 @@ export const sendEncryptionKey = async (key: string) => { export const deleteEncryptionKey = async (name: string) => { return await invoke("delete_entry", { name }) } + +/** + * Create a new WebAuthn credential + */ +export const createWebAuthnLogin = async () => { + try { + const res = await navigator.credentials.create({ + publicKey: { + rp: { + name: "Authme Windows Hello", + }, + + user: { + id: new Uint8Array(16), + name: "Authme", + displayName: "Authme", + }, + + pubKeyCredParams: [ + { + type: "public-key", + alg: -257, + }, + { + type: "public-key", + alg: -7, + }, + ], + + attestation: "none", + + timeout: 60000, + + challenge: window.crypto.getRandomValues(new Uint8Array(64)), + }, + }) + + settings.security.hardwareAuthentication = true + setSettings(settings) + + console.log(res) + } catch (error) { + console.log(error) + } +} + +/** + * Get an existing WebAuthn credential + */ +export const getWebAuthnLogin = async () => { + try { + const res = await navigator.credentials.get({ + publicKey: { + timeout: 60000, + challenge: window.crypto.getRandomValues(new Uint8Array(64)), + userVerification: "discouraged", + }, + }) + + console.log(res) + } catch (error) { + console.log(error) + } +} diff --git a/interface/libraries/types.d.ts b/interface/libraries/types.d.ts index 6770b7e..6266b3e 100644 --- a/interface/libraries/types.d.ts +++ b/interface/libraries/types.d.ts @@ -46,6 +46,7 @@ declare global { security: { requireAuthentication: null | boolean + hardwareAuthentication: boolean password: null | string } diff --git a/interface/stores/settings.ts b/interface/stores/settings.ts index 7d2b702..8de20ec 100644 --- a/interface/stores/settings.ts +++ b/interface/stores/settings.ts @@ -11,6 +11,7 @@ const defaultSettings: LibSettings = { security: { requireAuthentication: null, + hardwareAuthentication: false, password: null, }, @@ -45,12 +46,15 @@ const defaultSettings: LibSettings = { }, } +// Setup auto launch on first start if (build.dev === false && localStorage.settings === undefined) { invoke("auto_launch") } +// Create store export const settings = writable(localStorage.settings ? JSON.parse(localStorage.settings) : defaultSettings) +// Listen for store events settings.subscribe((data) => { console.log("Settings changed: ", data) @@ -64,7 +68,3 @@ export const getSettings = (): LibSettings => { export const setSettings = (newSettings: LibSettings) => { settings.set(newSettings) } - -export const resetSettings = () => { - settings.set(defaultSettings) -} diff --git a/interface/stores/state.ts b/interface/stores/state.ts index f954f95..8961bb5 100644 --- a/interface/stores/state.ts +++ b/interface/stores/state.ts @@ -21,7 +21,3 @@ export const getState = (): LibState => { export const setState = (newState: LibState) => { state.set(newState) } - -export const resetState = () => { - state.set(defaultState) -} diff --git a/interface/windows/landing/landing.svelte b/interface/windows/landing/landing.svelte index cb50935..c5e6d48 100644 --- a/interface/windows/landing/landing.svelte +++ b/interface/windows/landing/landing.svelte @@ -9,7 +9,7 @@
-

Require password

+

Password authentication

You have to type in a password every time you launch Authme.
-

No password

-
If you don't want to type in your password every time you launch Authme.
+

No authentication

+
If you don't want to type in a password every time you launch Authme.
-
-

Hardware key authentication

-
Login with Windows Hello, Touch ID or any WebAuthn compatible hardware key.
- - - - +
+
+

Hardware authentication

+
Confirm important actions with Windows Hello, Touch ID or any WebAuthn compatible hardware key.
+
+
+ +