Compare commits

...

5 Commits

8 changed files with 74 additions and 47 deletions

View File

@ -6,7 +6,7 @@
"appType": "app", "appType": "app",
"version": { "version": {
"code": 1, "code": 1,
"name": "1.1.3" "name": "1.2.2"
}, },
"icon": "icon.png", "icon": "icon.png",
"vender": "zepp", "vender": "zepp",

BIN
docs/screenshots/scr1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
docs/screenshots/scr2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

BIN
docs/screenshots/scr3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

BIN
icon_for_appstore.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

View File

@ -1,6 +1,6 @@
{ {
"name": "totpfit", "name": "totpfit",
"version": "1.1.3", "version": "1.2.2",
"description": "Another 2FAuthenticator based on TOTP for Zepp Amazfit GTS 4", "description": "Another 2FAuthenticator based on TOTP for Zepp Amazfit GTS 4",
"main": "app.js", "main": "app.js",
"author": "Lisoveliy", "author": "Lisoveliy",

View File

@ -23,10 +23,15 @@ Page(
}) })
.catch((x) => { .catch((x) => {
console.log(`Init failed: ${x}`); console.log(`Init failed: ${x}`);
let localStorage = new LocalStorage(); try{
app._options.globalData.TOTPS = JSON.parse( let localStorage = new LocalStorage();
localStorage.getItem("TOTPs", null) ?? [] app._options.globalData.TOTPS = JSON.parse(
); localStorage.getItem("TOTPs", [])
);
}
catch{
app._options.globalData.TOTPS = [];
}
this.initPage(); this.initPage();
}); });
}, },

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'
@ -33,15 +33,16 @@ function getByOtpauthScheme(link){
let period = args[3].split("period=")[1]?.split("&")[0]; //Returns period 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("digits=")[1]?.split("&")[0]; //Returns digits
let algorithm = args[3].split("algorithm=")[1]?.split("&")[0]; //Returns algorithm let algorithm = args[3].split("algorithm=")[1]?.split("&")[0]; //Returns algorithm
let offset = args[3].split("offset=")[1]?.split("&")[0] ?? 0; //Returns offset
if (type.toLowerCase() != "totp") if (type.toLowerCase() != "totp")
throw new Error("Type is not valid, requires 'TOTP'"); throw new Error("Type is not valid, requires 'TOTP'");
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];
} }
issuer = decodeURIComponent(issuer); issuer = decodeURIComponent(issuer);
client = decodeURIComponent(client); client = decodeURIComponent(client);
@ -52,62 +53,83 @@ function getByOtpauthScheme(link){
client, client,
digits, digits,
period, period,
0, Number(offset),
getHashType(algorithm) getHashType(algorithm)
); );
} catch (err) { } catch (err) {
console.log(err) console.log(err)
return null; return null;
} }
} }
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 protoTotps = []; let totps = [];
proto.parts.forEach(part => { totps.push(new TOTP(
if(part.type == TYPES.LENDELIM){ "",
protoTotps.push(decodeProto(part.value)); data,
} decode,
}); 6,
30,
0,
"SHA-1"
));
let totps = []; totps.push(new TOTP(
protoTotps.forEach(x => { "",
let type = x.parts.filter(x => x.index == 6)[0]; //find type of OTP proto.leftOver,
if(type.value !== '2'){ proto.parts.length,
console.log("ERR: it's a not TOTP record") 6,
return; 30,
} 0,
let secret = x.parts.filter(x => x.index == 1)[0].value; "SHA-1"
secret = encode(secret); ));
let name = bytesToString(x.parts.filter(x => x.index == 2)[0].value); let protoTotps = [];
let issuer = bytesToString(x.parts.filter(x => x.index == 3)[0].value);
proto.parts.forEach(part => {
totps.push(new TOTP( if (part.type == TYPES.LENDELIM) {
protoTotps.push(decodeProto(part.value));
}
});
protoTotps.forEach(x => {
let type = x.parts.filter(x => x.index == 6)[0]; //find type of OTP
if (type.value !== '2') {
console.log("ERR: it's a not TOTP record")
return;
}
let secret = x.parts.filter(x => x.index == 1)[0].value;
secret = encode(secret);
let name = bytesToString(x.parts.filter(x => x.index == 2)[0].value);
let issuer = bytesToString(x.parts.filter(x => x.index == 3)[0].value);
totps.push(new TOTP(
secret, secret,
issuer, issuer,
name, name,
6, 6,
30, 30,
0, 0,
"SHA-1" "SHA-1"
)); ));
}); });
return totps;
return totps;
} }
function bytesToString(bytes) { function bytesToString(bytes) {
let str = ''; let str = '';
for (let i = 0; i < bytes.length; i++) { for (let i = 0; i < bytes.length; i++) {
str += String.fromCharCode(bytes[i]); str += String.fromCharCode(bytes[i]);
} }
return str; return str;
} }