Skip to content

Commit

Permalink
Validate secrets and fix copy
Browse files Browse the repository at this point in the history
  • Loading branch information
Levminer committed Oct 15, 2022
1 parent 76aa227 commit 9e71d76
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
20 changes: 20 additions & 0 deletions interface/utils/convert.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { dialog } from "@tauri-apps/api"
import { getState, setState } from "interface/stores/state"
import { TOTP } from "otpauth"
import protobuf from "protocol-buffers"
import { encode } from "./base32"
import logger from "./logger"

const state = getState()

const protoContent = `
syntax = "proto3";
Expand Down Expand Up @@ -108,6 +114,20 @@ export const textConverter = (text: string, sortNumber: number): LibImportFile =
if (data[i].startsWith("Secret")) {
const secret = data[i].slice(8).trim()

try {
new TOTP({
secret,
}).generate()
} catch (error) {
dialog.message("Failed to generate TOTP code from secret. \n\nMake sure you import file is correct!", { type: "error" })
logger.error("Failed to generate TOTP code from secret")

state.importData = null
setState(state)

return
}

secrets.push(secret)
}

Expand Down
4 changes: 2 additions & 2 deletions interface/windows/codes/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { textConverter } from "../../utils/convert"
import { TOTP } from "otpauth"
import { dialog, fs } from "@tauri-apps/api"
import { clipboard, dialog, fs } from "@tauri-apps/api"
import { getSettings, setSettings } from "../../stores/settings"
import { getState, setState } from "../../stores/state"
import { decryptData, encryptData } from "interface/utils/encryption"
Expand Down Expand Up @@ -129,7 +129,7 @@ export const generateCodeElements = (data: LibImportFile) => {
time.textContent = remainingTime.toString()

button.addEventListener("click", () => {
navigator.clipboard.writeText(code.textContent)
clipboard.writeText(code.textContent)

button.innerHTML = `
<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 9e71d76

Please sign in to comment.