feat: added google migration support (BETA) v.1.2.0
This commit is contained in:
@@ -13,12 +13,16 @@ AppSettingsPage({
|
||||
placeholder: "otpauth://",
|
||||
label: "Add new OTP Link",
|
||||
onChange: (changes) => {
|
||||
var link = getTOTPByLink(changes);
|
||||
let link = getTOTPByLink(changes);
|
||||
if (link == null) {
|
||||
console.log("link is invalid");
|
||||
return;
|
||||
}
|
||||
storage.push(link);
|
||||
|
||||
if(Array.isArray(link))
|
||||
storage.push(...link);
|
||||
else storage.push(link);
|
||||
|
||||
updateStorage(storage);
|
||||
},
|
||||
labelStyle: {
|
||||
@@ -80,7 +84,11 @@ function GetTOTPList(storage) {
|
||||
label: "Change OTP link",
|
||||
onChange: (changes) => {
|
||||
try {
|
||||
storage[elementId] = getTOTPByLink(changes);
|
||||
let link = getTOTPByLink(changes);
|
||||
if(Array.isArray(link))
|
||||
return;
|
||||
|
||||
storage[elementId] = link;
|
||||
updateStorage(storage);
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { decodeProto } from "../../lib/protobuf-decoder/protobufDecoder";
|
||||
import { decodeProto, TYPES } from "../../lib/protobuf-decoder/protobufDecoder";
|
||||
import { TOTP } from "../../lib/totp-quickjs";
|
||||
import { base64decode } from "../../lib/totp-quickjs/base32decoder";
|
||||
import { base64decode, encode } from "../../lib/totp-quickjs/base32decoder";
|
||||
|
||||
const otpauthScheme = "otpauth:/";
|
||||
const googleMigrationScheme = "otpauth-migration:/";
|
||||
@@ -40,7 +40,7 @@ function getByOtpauthScheme(link){
|
||||
if (secret === undefined) throw new Error("Secret not defined");
|
||||
|
||||
if(issuer == client){
|
||||
issuer = args[3].split("issuer=")[1]?.split("&")[0]
|
||||
issuer = args[3].split("issuer=")[1]?.split("&")[0];
|
||||
}
|
||||
|
||||
issuer = decodeURIComponent(issuer);
|
||||
@@ -65,9 +65,49 @@ function getByGoogleMigrationScheme(link){
|
||||
|
||||
let data = link.split("data=")[1]; //Returns base64 encoded data
|
||||
data = decodeURIComponent(data);
|
||||
console.log(data)
|
||||
let decode = base64decode(data);
|
||||
console.log(decode)
|
||||
let proto = decodeProto(decode);
|
||||
console.log(proto);
|
||||
|
||||
let protoTotps = [];
|
||||
|
||||
proto.parts.forEach(part => {
|
||||
if(part.type == TYPES.LENDELIM){
|
||||
protoTotps.push(decodeProto(part.value));
|
||||
}
|
||||
});
|
||||
|
||||
let totps = [];
|
||||
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,
|
||||
issuer,
|
||||
name,
|
||||
6,
|
||||
30,
|
||||
0,
|
||||
"SHA-1"
|
||||
));
|
||||
});
|
||||
|
||||
return totps;
|
||||
|
||||
}
|
||||
|
||||
function bytesToString(bytes) {
|
||||
let str = '';
|
||||
for (let i = 0; i < bytes.length; i++) {
|
||||
str += String.fromCharCode(bytes[i]);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
Reference in New Issue
Block a user