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

Commit

Permalink
Export authme file
Browse files Browse the repository at this point in the history
  • Loading branch information
Levminer committed Jul 19, 2022
1 parent 9a3fc2c commit 236f518
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<h3>Your saved codes can be exported here. Ideal if you want to use your codes elsewhere or for a security backup.</h3>
</div>
<div class="ml-20 flex gap-3">
<button class="button requirePassword">
<button class="button" on:click={exportCodes}>
<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">
<path stroke-linecap="round" stroke-linejoin="round" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>
Expand All @@ -18,7 +18,7 @@
</div>
</div>

<div class="transparent-900 m-auto my-20 w-4/5 rounded-2xl p-10 text-left">
<div class="transparent-900 saveExportedCodes m-auto my-20 hidden w-4/5 rounded-2xl p-10 text-left">
<h1 class="px-10">Save exported codes</h1>
<div class="mx-auto flex flex-col items-center justify-center rounded-2xl p-10">
<div class="transparent-800 mb-5 flex w-full flex-row items-center justify-between rounded-xl p-5 text-left">
Expand All @@ -27,13 +27,13 @@
<h3>Ideal to import for Authme or other Authme apps.</h3>
</div>
<div class="ml-20 flex gap-3">
<button class="button requirePassword">
<button class="button" on:click={exportAuthmeFile}>
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
<path d="M14 3v4a1 1 0 0 0 1 1h4" />
<path d="M11.5 21h-4.5a2 2 0 0 1 -2 -2v-14a2 2 0 0 1 2 -2h7l5 5v5m-5 6h7m-3 -3l3 3l-3 3" />
</svg>
Export
Export file
</button>
</div>
</div>
Expand All @@ -44,15 +44,19 @@
<h3>Ideal for scanning the QR codes or for security backup.</h3>
</div>
<div class="ml-20 flex gap-3">
<button class="button requirePassword">
<button class="button">
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
<path d="M14 3v4a1 1 0 0 0 1 1h4" />
<path d="M11.5 21h-4.5a2 2 0 0 1 -2 -2v-14a2 2 0 0 1 2 -2h7l5 5v5m-5 6h7m-3 -3l3 3l-3 3" />
</svg>
Export
Export file
</button>
</div>
</div>
</div>
</div>

<script lang="ts">
import { exportCodes, exportAuthmeFile } from "./index"
</script>
46 changes: 46 additions & 0 deletions interface/windows/export/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { fs, path, dialog } from "@tauri-apps/api"
import { generateMasterKey, decrypt } from "../../libraries/auth"
import { generateTimestamp } from "../../libraries/time"
import { textConverter } from "../../libraries/convert"
import { getSettings } from "../../stores/settings"

let codesArray: LibImportFile
let codesText: string

export const exportCodes = async () => {
const settings = getSettings()
const filePath = await path.join(await path.configDir(), "Levminer", "Authme 4", "codes", "codes.authme")

try {
const saveFile: LibAuthmeFile = JSON.parse(await fs.readTextFile(filePath))

document.querySelector(".saveExportedCodes").style.display = "block"

const password = Buffer.from(settings.security.password, "base64")
const key = Buffer.from(settings.security.key, "base64")

const masterKey = await generateMasterKey(password, key)
const decrypted = await decrypt(saveFile.codes, masterKey)

codesArray = textConverter(decrypted, 0)
codesText = decrypted
} catch (error) {
dialog.message("No save file found. \n\nGo back to the codes page and save your codes!", { type: "error" })
}
}

export const exportAuthmeFile = async () => {
const saveFile: LibAuthmeFile = {
role: "codes",
encrypted: false,
codes: Buffer.from(codesText).toString("base64"),
date: generateTimestamp(),
version: 3,
}

const filePath = await dialog.save({ filters: [{ name: "Authme file", extensions: ["authme"] }] })

if (filePath !== null) {
fs.writeFile(filePath, JSON.stringify(saveFile, null, "\t"))
}
}

0 comments on commit 236f518

Please sign in to comment.