fix: fixed digit parameter resolve
This commit is contained in:
parent
0aeeebfb3d
commit
acc3218df6
@ -6,9 +6,9 @@ const otpauthScheme = "otpauth:/";
|
||||
const googleMigrationScheme = "otpauth-migration:/";
|
||||
|
||||
export function getTOTPByLink(link) {
|
||||
if(link.includes(otpauthScheme))
|
||||
if (link.includes(otpauthScheme))
|
||||
return getByOtpauthScheme(link)
|
||||
if(link.includes(googleMigrationScheme))
|
||||
if (link.includes(googleMigrationScheme))
|
||||
return getByGoogleMigrationScheme(link)
|
||||
|
||||
return null;
|
||||
@ -21,7 +21,7 @@ function getHashType(algorithm) {
|
||||
else return "SHA-1";
|
||||
}
|
||||
|
||||
function getByOtpauthScheme(link){
|
||||
function getByOtpauthScheme(link) {
|
||||
try {
|
||||
let args = link.split("/", otpauthScheme.length);
|
||||
let type = args[2]; //Returns 'hotp' or 'totp'
|
||||
@ -31,7 +31,7 @@ function getByOtpauthScheme(link){
|
||||
args[3].split(":")[0]?.split("?")[0]; //Returns client
|
||||
let secret = args[3].split("secret=")[1]?.split("&")[0]; //Returns secret
|
||||
let period = args[3].split("period=")[1]?.split("&")[0]; //Returns period
|
||||
let digits = args[3].split("digits=")[1]?.split("&")[0]; //Returns digits
|
||||
let digits = args[3].split("digit=")[1]?.split("&")[0]; //Returns digits
|
||||
let algorithm = args[3].split("algorithm=")[1]?.split("&")[0]; //Returns algorithm
|
||||
let offset = args[3].split("offset=")[1]?.split("&")[0] ?? 0; //Returns offset
|
||||
|
||||
@ -40,7 +40,7 @@ function getByOtpauthScheme(link){
|
||||
|
||||
if (secret === undefined) throw new Error("Secret not defined");
|
||||
|
||||
if(issuer == client){
|
||||
if (issuer == client) {
|
||||
issuer = args[3].split("issuer=")[1]?.split("&")[0];
|
||||
}
|
||||
|
||||
@ -51,8 +51,8 @@ function getByOtpauthScheme(link){
|
||||
secret,
|
||||
issuer,
|
||||
client,
|
||||
digits,
|
||||
period,
|
||||
Number(digits),
|
||||
Number(period),
|
||||
Number(offset),
|
||||
getHashType(algorithm)
|
||||
);
|
||||
@ -62,7 +62,7 @@ function getByOtpauthScheme(link){
|
||||
}
|
||||
}
|
||||
|
||||
function getByGoogleMigrationScheme(link){
|
||||
function getByGoogleMigrationScheme(link) {
|
||||
|
||||
let data = link.split("data=")[1]; //Returns base64 encoded data
|
||||
data = decodeURIComponent(data);
|
||||
@ -72,7 +72,7 @@ function getByGoogleMigrationScheme(link){
|
||||
let protoTotps = [];
|
||||
|
||||
proto.parts.forEach(part => {
|
||||
if(part.type == TYPES.LENDELIM){
|
||||
if (part.type == TYPES.LENDELIM) {
|
||||
protoTotps.push(decodeProto(part.value));
|
||||
}
|
||||
});
|
||||
@ -80,7 +80,7 @@ function getByGoogleMigrationScheme(link){
|
||||
let totps = [];
|
||||
protoTotps.forEach(x => {
|
||||
let type = x.parts.filter(x => x.index == 6)[0]; //find type of OTP
|
||||
if(type.value !== '2'){
|
||||
if (type.value !== '2') {
|
||||
console.log("ERR: it's a not TOTP record")
|
||||
return;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user