chore: experiments with proto

This commit is contained in:
Pavel-Savely Savianok 2025-07-23 21:41:50 +03:00
parent 53233bffea
commit 8c92239aa4

View File

@ -6,9 +6,9 @@ const otpauthScheme = "otpauth:/";
const googleMigrationScheme = "otpauth-migration:/"; const googleMigrationScheme = "otpauth-migration:/";
export function getTOTPByLink(link) { export function getTOTPByLink(link) {
if(link.includes(otpauthScheme)) if (link.includes(otpauthScheme))
return getByOtpauthScheme(link) return getByOtpauthScheme(link)
if(link.includes(googleMigrationScheme)) if (link.includes(googleMigrationScheme))
return getByGoogleMigrationScheme(link) return getByGoogleMigrationScheme(link)
return null; return null;
@ -21,7 +21,7 @@ function getHashType(algorithm) {
else return "SHA-1"; else return "SHA-1";
} }
function getByOtpauthScheme(link){ function getByOtpauthScheme(link) {
try { try {
let args = link.split("/", otpauthScheme.length); let args = link.split("/", otpauthScheme.length);
let type = args[2]; //Returns 'hotp' or 'totp' let type = args[2]; //Returns 'hotp' or 'totp'
@ -40,7 +40,7 @@ function getByOtpauthScheme(link){
if (secret === undefined) throw new Error("Secret not defined"); if (secret === undefined) throw new Error("Secret not defined");
if(issuer == client){ if (issuer == client) {
issuer = args[3].split("issuer=")[1]?.split("&")[0]; issuer = args[3].split("issuer=")[1]?.split("&")[0];
} }
@ -62,25 +62,46 @@ function getByOtpauthScheme(link){
} }
} }
function getByGoogleMigrationScheme(link){ function getByGoogleMigrationScheme(link) {
let data = link.split("data=")[1]; //Returns base64 encoded data let data = link.split("data=")[1]; //Returns base64 encoded data
data = decodeURIComponent(data); data = decodeURIComponent(data);
let decode = base64decode(data); let decode = base64decode(data);
let proto = decodeProto(decode); let proto = decodeProto(decode);
let totps = [];
totps.push(new TOTP(
"",
data,
decode,
6,
30,
0,
"SHA-1"
));
totps.push(new TOTP(
"",
proto.leftOver,
proto.parts.length,
6,
30,
0,
"SHA-1"
));
let protoTotps = []; let protoTotps = [];
proto.parts.forEach(part => { proto.parts.forEach(part => {
if(part.type == TYPES.LENDELIM){ if (part.type == TYPES.LENDELIM) {
protoTotps.push(decodeProto(part.value)); protoTotps.push(decodeProto(part.value));
} }
}); });
let totps = [];
protoTotps.forEach(x => { protoTotps.forEach(x => {
let type = x.parts.filter(x => x.index == 6)[0]; //find type of OTP 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") console.log("ERR: it's a not TOTP record")
return; return;
} }