Skip to content

Commit

Permalink
Remove backup key restore #172
Browse files Browse the repository at this point in the history
  • Loading branch information
Levminer committed Dec 27, 2021
1 parent 889b0c7 commit aff7731
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 278 deletions.
11 changes: 0 additions & 11 deletions app/confirm/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,6 @@ <h4 id="text">Please enter your password to continue!</h4>
</div>
<div id="more_options" class="mx-auto rounded-2xl bg-gray-800 w-2/3 mt-20 mb-20 pb-10 pt-1 animation invisible hidden">
<div>
<h3>Forgot password?</h3>
<h4>If you have a backup key you can recover your password. If you don't have one there is no way to decrypt your codes, try to remember your password.</h4>
<button onclick="forgotPassword()" class="buttoni">
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 21h7a2 2 0 002-2V9.414a1 1 0 00-.293-.707l-5.414-5.414A1 1 0 0012.586 3H7a2 2 0 00-2 2v11m0 5l4.879-4.879m0 0a3 3 0 104.243-4.242 3 3 0 00-4.243 4.242z" />
</svg>
Choose backup file
</button>

<hr />

<h3>Window capture</h3>
<h4>Allows screenshots and screen capture. You can record or screenshot the app until you restart Authme.</h4>
<div class="flex justify-center items-center w-72 h-[68px] bg-white mx-auto rounded-full">
Expand Down
148 changes: 47 additions & 101 deletions app/confirm/src/js/index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
const { app, dialog, clipboard } = require("@electron/remote")
const logger = require("@levminer/lib/logger/renderer")
const { app, dialog } = require("@electron/remote")
const { ipcRenderer: ipc } = require("electron")
const bcrypt = require("bcryptjs")
const fs = require("fs")
const electron = require("electron")
const ipc = electron.ipcRenderer
const { sha, rsa } = require("@levminer/lib")
const path = require("path")
const fs = require("fs")

// ? error in window
/**
* Send error to main process
*/
window.onerror = (error) => {
ipc.send("rendererError", { renderer: "confirm", error: error })
}

// ? logger
/**
* Start logger
*/
logger.getWindow("confirm")

// ? if development
/**
* Check if running in development
*/
let dev = false
let integrity = false

Expand Down Expand Up @@ -53,9 +57,14 @@ if (res.build_number.startsWith("alpha")) {
document.querySelector(".build").style.display = "block"
}

// ? init
/**
* Get info text
*/
const text = document.querySelector("#text")

/**
* Confirm password on enter press
*/
document.querySelector("#password_input").addEventListener("keypress", (e) => {
if (e.key === "Enter") {
if (integrity === false) {
Expand All @@ -68,7 +77,9 @@ document.querySelector("#password_input").addEventListener("keypress", (e) => {
}
})

// ? check integrity
/**
* Check files integrity
*/
const check_integrity = () => {
// read settings
settings = JSON.parse(fs.readFileSync(path.join(folder_path, "settings", "settings.json"), "utf-8"))
Expand Down Expand Up @@ -109,7 +120,9 @@ const check_integrity = () => {
}
}

// ? compare
/**
* Compare passwords
*/
const unhashPassword = async () => {
if (integrity === false) {
check_integrity()
Expand Down Expand Up @@ -144,100 +157,16 @@ const unhashPassword = async () => {
}
}

// ? forgot password
const forgotPassword = () => {
dialog
.showOpenDialog({
title: "Choose backup file",
properties: ["openFile"],
filters: [{ name: "Key file", extensions: ["key"] }],
})
.then((result) => {
canceled = result.canceled
filepath = result.filePaths

const loaded_key = Buffer.from(fs.readFileSync(filepath[0]))

if (loaded_key.toString().startsWith("-----BEGIN RSA PRIVATE KEY-----")) {
/**
* Load storage
* @type {LibStorage}
*/
let storage

if (dev === true) {
storage = JSON.parse(localStorage.getItem("dev_storage"))
} else {
storage = JSON.parse(localStorage.getItem("storage"))
}

const hash = Buffer.from(sha.generateHash(loaded_key.toString("base64")))

if (hash.toString() === storage.hash) {
const encrypted = Buffer.from(rsa.decrypt(loaded_key.toString(), Buffer.from(storage.backup_string, "base64")), "base64")

dialog
.showMessageBox({
title: "Authme",
buttons: ["Copy"],
defaultId: 0,
noLink: true,
type: "info",
message: "Backup key successfully decrypted! \n\nThe password is copied to your clipboard!",
})
.then((result) => {
clipboard.writeText(encrypted.toString())

if (result.response === 0) {
clipboard.writeText(encrypted.toString())
}

loaded_key.fill(0)
hash.fill()
encrypted.fill(0)
})
} else {
dialog.showMessageBox({
title: "Authme",
buttons: ["Close"],
type: "error",
message: "This is not a matching backup key! \n\nThis backup key is not matching with the your backup key!",
})

loaded_key.fill(0)
hash.fill(0)
}
} else {
dialog.showMessageBox({
title: "Authme",
buttons: ["Close"],
type: "error",
message: "This is not a backup key! \n\nPlease choose another file!",
})
}
})
}

// ? show password
document.querySelector("#show_pass_0").addEventListener("click", () => {
document.querySelector("#password_input").setAttribute("type", "text")

document.querySelector("#show_pass_0").style.display = "none"
document.querySelector("#show_pass_01").style.display = "flex"
})

document.querySelector("#show_pass_01").addEventListener("click", () => {
document.querySelector("#password_input").setAttribute("type", "password")

document.querySelector("#show_pass_0").style.display = "flex"
document.querySelector("#show_pass_01").style.display = "none"
})

let more_options_shown = false
/**
* Forget password
*/
const forgotPassword = () => {}

/**
* Show more options div
*/
let more_options_shown = false

const showMoreOptions = () => {
const more_options = document.querySelector("#more_options")

Expand Down Expand Up @@ -271,3 +200,20 @@ const toggleWindowCapture = () => {
ipc.send("enableWindowCapture")
}
}

/**
* Show passwords
*/
document.querySelector("#show_pass_0").addEventListener("click", () => {
document.querySelector("#password_input").setAttribute("type", "text")

document.querySelector("#show_pass_0").style.display = "none"
document.querySelector("#show_pass_01").style.display = "flex"
})

document.querySelector("#show_pass_01").addEventListener("click", () => {
document.querySelector("#password_input").setAttribute("type", "password")

document.querySelector("#show_pass_0").style.display = "flex"
document.querySelector("#show_pass_01").style.display = "none"
})
13 changes: 0 additions & 13 deletions app/landing/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,7 @@ <h4>If you don't want to type in your password every time you launch Authme.</h4
</svg>
Confirm
</button>

<hr />

<h3>Backup key</h3>
<h4>In case you forget your password you can use this backup key to get back your codes.</h4>
<button onclick="generateBackupKey()" class="buttoni mb-7">
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 7a2 2 0 012 2m4 0a6 6 0 01-7.743 5.743L11 17H9v2H7v2H4a1 1 0 01-1-1v-2.586a1 1 0 01.293-.707l5.964-5.964A6 6 0 1121 9z" />
</svg>
Generate key
</button>

<hr />

<h3>Window capture</h3>
<h4>Allows screenshots and screen capture. You can record or screenshot the app until you restart Authme.</h4>
<div class="flex justify-center items-center w-72 h-[68px] bg-white mx-auto rounded-full">
Expand Down
Loading

0 comments on commit aff7731

Please sign in to comment.