Skip to content

Commit

Permalink
Separate encryption for prod and dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Levminer committed Oct 15, 2022
1 parent 9e71d76 commit beea216
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
13 changes: 5 additions & 8 deletions core/src/encryption.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ pub fn decrypt_data(data: String) -> String {
}

#[tauri::command]
pub fn set_entry(name: String, data: String) -> String {
let service = "authme";
pub fn set_entry(name: String, data: String, service: String) -> String {
let entry = keyring::Entry::new(&service, &name);

let res = entry.set_password(data.as_str());
Expand All @@ -72,8 +71,7 @@ pub fn set_entry(name: String, data: String) -> String {
}

#[tauri::command]
pub fn get_entry(name: String) -> String {
let service = "authme";
pub fn get_entry(name: String, service: String) -> String {
let entry = keyring::Entry::new(&service, &name);

let item = entry.get_password().unwrap_or_else(|error| "error".into());
Expand All @@ -82,8 +80,7 @@ pub fn get_entry(name: String) -> String {
}

#[tauri::command]
pub fn delete_entry(name: String) {
let service = "authme";
pub fn delete_entry(name: String, service: String) {
let entry = keyring::Entry::new(&service, &name);

let item = entry.delete_password();
Expand All @@ -95,6 +92,6 @@ pub fn receive_encryption_key(key: String) {
}

#[tauri::command]
pub fn set_encryption_key() {
*ENCRYPTION_KEY.lock().unwrap() = get_entry("encryptionKey".to_string())
pub fn set_encryption_key(service: String) {
*ENCRYPTION_KEY.lock().unwrap() = get_entry("encryptionKey".to_string(), service)
}
8 changes: 5 additions & 3 deletions interface/utils/encryption.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { invoke, dialog } from "@tauri-apps/api"
import { getSettings, setSettings } from "interface/stores/settings"
import logger from "./logger"
import { dev } from "../../build.json"

const settings = getSettings()
const service = dev ? "authme_dev" : "authme"

/**
* Generates random key
Expand Down Expand Up @@ -35,7 +37,7 @@ export const decryptData = async (data: string): Promise<string> => {
* Sets an entry on the system keychain
*/
export const setEntry = async (name: string, data: string) => {
const res = await invoke("set_entry", { name, data })
const res = await invoke("set_entry", { name, data, service })

if (res === "error") {
dialog.message("Failed to set the encryption key on your systems keychain!\n\n You can use the password method.", { type: "error" })
Expand All @@ -48,7 +50,7 @@ export const setEntry = async (name: string, data: string) => {
* Set the encryption key on the backend
*/
export const setEncryptionKey = async () => {
const res: string = await invoke("set_encryption_key")
const res: string = await invoke("set_encryption_key", { service })

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" })
Expand All @@ -68,7 +70,7 @@ export const sendEncryptionKey = async (key: string) => {
* Delete encryption key
*/
export const deleteEncryptionKey = async (name: string) => {
return await invoke("delete_entry", { name })
return await invoke("delete_entry", { name, service })
}

/**
Expand Down

0 comments on commit beea216

Please sign in to comment.