feat: added validation for TOTP link
This commit is contained in:
parent
3c5dc5276d
commit
7d989fed8f
@ -72,8 +72,13 @@ function GetTOTPList(storage){
|
||||
placeholder: "otpauth://",
|
||||
label: "Change OTP link",
|
||||
onChange: (changes) => {
|
||||
try{
|
||||
storage[elementId] = getTOTPByLink(changes)
|
||||
updateStorage(storage)
|
||||
}
|
||||
catch(err){
|
||||
console.log(err)
|
||||
}
|
||||
},
|
||||
labelStyle: {
|
||||
backgroundColor: "#14213D",
|
||||
|
@ -3,6 +3,7 @@ import { TOTP } from "../../lib/totp-quickjs";
|
||||
const otpScheme = "otpauth:/";
|
||||
|
||||
export function getTOTPByLink(link){
|
||||
try{
|
||||
let args = link.split("/", otpScheme.length)
|
||||
let type = args[2] //Returns 'hotp' or 'totp'
|
||||
let issuer = args[3].split(':')[0]?.split('?')[0] //Returns issuer
|
||||
@ -11,12 +12,15 @@ export function getTOTPByLink(link){
|
||||
let period = args[3].split('period=')[1]?.split('&')[0] //Returns period
|
||||
let digits = args[3].split('digits=')[1]?.split('&')[0] //Returns digits
|
||||
let algorithm = args[3].split('algorithm=')[1]?.split('&')[0] //Returns algorithm
|
||||
|
||||
}
|
||||
catch(err){
|
||||
throw new Error("Link is not valid")
|
||||
}
|
||||
if(type.toLowerCase() != 'totp')
|
||||
return Error("Type is not valid, requires 'TOTP'")
|
||||
throw new Error("Type is not valid, requires 'TOTP'")
|
||||
|
||||
if(secret === undefined)
|
||||
return Error("Secret not defined")
|
||||
throw new Error("Secret not defined")
|
||||
|
||||
issuer = issuer.replace("%20", " ")
|
||||
client = client.replace("%20", " ")
|
||||
|
Loading…
x
Reference in New Issue
Block a user