Skip to content
This repository has been archived by the owner on Oct 19, 2022. It is now read-only.

Commit

Permalink
Encryption error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Levminer committed Sep 7, 2022
1 parent 02a4fec commit b974291
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion core/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/src/encryption.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub fn set_entry(name: String, data: String) {
let service = "authme_dev";
let entry = keyring::Entry::new(&service, &name);

entry.set_password(data.as_str()).unwrap();
entry.set_password(data.as_str()).unwrap_or_else(|error| error.into());
}

#[tauri::command]
Expand Down
24 changes: 20 additions & 4 deletions interface/libraries/encryption.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { invoke } from "@tauri-apps/api"
import { invoke, dialog } from "@tauri-apps/api"

/**
* Generates random key
Expand All @@ -11,14 +11,24 @@ export const generateRandomKey = async (): Promise<Buffer> => {
* Sets an entry on the system keychain
*/
export const setEntry = async (name: string, data: string) => {
await invoke("set_entry", { name, data })
const res = await invoke("set_entry", { name, data })

if (res === "error") {
dialog.message("Failed to set an entry on your systems keychain!\n\n Please try again or choose the password method!", { type: "error" })
}
}

/**
* Encrypts a string with the encryption key
*/
export const encryptData = async (data: string): Promise<string> => {
return await invoke("encrypt_data", { data })
const res: string = await invoke("encrypt_data", { data })

if (res === "error") {
dialog.message("Failed to decrypt your codes!\n\n Please restart the app and try again!", { type: "error" })
}

return res
}

/**
Expand All @@ -32,7 +42,13 @@ export const decryptData = async (data: string): Promise<string> => {
* Set the encryption key on the backend
*/
export const setEncryptionKey = async () => {
return await invoke("set_encryption_key")
const res: string = await invoke("set_encryption_key")

if (res === "error") {
dialog.message("Failed to set the encryption key on your systems keychain!\n\n Please restart the app and try again!", { type: "error" })
}

return res
}

/**
Expand Down
2 changes: 1 addition & 1 deletion interface/windows/codes/codes.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<div class="content mx-auto flex flex-col flex-wrap items-center justify-center gap-10 rounded-2xl p-10 sm:w-full">
<div class="importCodes transparent-800 hidden w-full max-w-2xl rounded-2xl p-5">
<h2>Import your codes</h2>
<h3>Import your 2FA codes, or if you have an import file choose it.</h3>
<h3>Import your existing 2FA codes, or choose your import file if you already have one.</h3>
<div class="mx-auto mt-6 flex flex-row items-center justify-center gap-3 sm:flex-wrap">
<button class="button" on:click={() => navigate("import")}>
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
Expand Down

0 comments on commit b974291

Please sign in to comment.