Compare commits
32 Commits
b4df58765d
...
v1.3.0
| Author | SHA1 | Date | |
|---|---|---|---|
| 6a2ab542b9 | |||
| 3aaedec7f6 | |||
| 70841349b7 | |||
| 7eafac6916 | |||
| 08b11a3d09 | |||
| acc3218df6 | |||
| 0aeeebfb3d | |||
| 684aff7131 | |||
| 6d15fe9b72 | |||
| 53233bffea | |||
| 640ebb0600 | |||
|
|
90be9c4606 | ||
|
|
dd32a6eac7 | ||
|
|
21c7646c71 | ||
|
|
fb6ece773c | ||
|
|
ba4b8cc29e | ||
|
|
bd490d4642 | ||
|
|
ccfd422061 | ||
|
|
ca342bf6e4 | ||
|
|
8ab87fe8e9 | ||
|
|
096051b49d | ||
|
|
ca1936d20d | ||
|
|
b12eacb5e1 | ||
|
|
430e45fb6f | ||
|
|
43af7e2055 | ||
|
|
5fa5455e00 | ||
|
|
73ea81af54 | ||
|
|
24e097a253 | ||
|
|
cebe95acf5 | ||
|
|
3c8c804fc3 | ||
|
|
999c47789b | ||
|
|
90c3432e94 |
1
.prettierrc.yaml
Normal file
@@ -0,0 +1 @@
|
|||||||
|
tabWidth: 4
|
||||||
17
README.md
@@ -1,4 +1,15 @@
|
|||||||
# TOTPFIT - Another 2FAuthenticator based on TOTP for Zepp Amazfit GTS 4
|
# TOTPFIT
|
||||||
|
### Another 2FAuthenticator based on TOTP for Zepp Amazfit GTS 4 with Google Authenticator migration Support
|
||||||
|
|
||||||
Features:
|

|
||||||
- Supports otpauth links with parameters "issuer", "algorithm", "digits", "period"
|
|
||||||
|
### Features:
|
||||||
|
- Supports of ```otpauth://``` links with parameters "client", "issuer", "algorithm", "digits", "period", "offset"
|
||||||
|
- Addition/Edition/Deletion of TOTPs from mobile app
|
||||||
|
- Support of Google Authenticator migration links formated: ```otpauth-migration://offline?data=...``` (At this stage with only 6 digits and only 30 seconds period)
|
||||||
|
|
||||||
|
### Guides:
|
||||||
|
|
||||||
|
[How to add 2FA TOTP records (keys) on app](/docs/guides/how-to-add-totps/README.md)
|
||||||
|
|
||||||
|
#### This repo has mirror for issues on [GitHub](https://github.com/Lisoveliy/totpfit)
|
||||||
@@ -6,11 +6,12 @@ AppSideService(
|
|||||||
onInit(){
|
onInit(){
|
||||||
|
|
||||||
},
|
},
|
||||||
onRequest(req, res){
|
onRequest(request, response){
|
||||||
if(req.method === 'totps'){
|
if(request.method === 'totps'){
|
||||||
res(null, settings.settingsStorage.getItem('TOTPs'))
|
response(null, settings.settingsStorage.getItem('TOTPs'))
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
onSettingsChange(){ }
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
19
app.js
@@ -1,14 +1,11 @@
|
|||||||
import { BaseApp } from "@zeppos/zml/base-app"
|
import { BaseApp } from "@zeppos/zml/base-app";
|
||||||
|
|
||||||
App(
|
App(
|
||||||
BaseApp(
|
BaseApp({
|
||||||
{
|
globalData: {
|
||||||
globalData: {
|
TOTPS: [],
|
||||||
TOTPS: []
|
},
|
||||||
},
|
onCreate() {},
|
||||||
onCreate() {
|
onDestroy() {},
|
||||||
},
|
|
||||||
onDestroy() {
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
)
|
);
|
||||||
|
|||||||
6
app.json
@@ -6,11 +6,11 @@
|
|||||||
"appType": "app",
|
"appType": "app",
|
||||||
"version": {
|
"version": {
|
||||||
"code": 1,
|
"code": 1,
|
||||||
"name": "1.0.0"
|
"name": "1.3.0"
|
||||||
},
|
},
|
||||||
"icon": "icon.png",
|
"icon": "icon.png",
|
||||||
"vender": "zepp",
|
"vender": "zepp",
|
||||||
"description": "TOTP Authenticator for Amazfit devices"
|
"description": "Another 2FAuthenticator based on TOTP for Zepp Amazfit GTS 4"
|
||||||
},
|
},
|
||||||
"permissions": [
|
"permissions": [
|
||||||
"data:os.device.info",
|
"data:os.device.info",
|
||||||
@@ -53,4 +53,4 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"defaultLanguage": "en-US"
|
"defaultLanguage": "en-US"
|
||||||
}
|
}
|
||||||
|
Before Width: | Height: | Size: 5.5 KiB After Width: | Height: | Size: 76 KiB |
|
Before Width: | Height: | Size: 5.5 KiB After Width: | Height: | Size: 76 KiB |
|
Before Width: | Height: | Size: 5.5 KiB After Width: | Height: | Size: 76 KiB |
BIN
docs/assets/image.png
Normal file
|
After Width: | Height: | Size: 27 KiB |
BIN
docs/assets/image2.png
Normal file
|
After Width: | Height: | Size: 18 KiB |
37
docs/guides/how-to-add-totps/README.md
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
# How to add 2FA TOTP records (keys) on app
|
||||||
|
|
||||||
|
### If you use default 2FA otpauth:// links
|
||||||
|
|
||||||
|
To add 2FA TOTP records using 2FA TOTP QR-Codes, you must scan QR-Code of service providing 2FA and scan (decode) it to a URI. If you have screenshot of QR-Code -- scan it on any app providing scan from image, ex: Search screen on Google Assistant. For example, this QR-Code will represent next URI string:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
Copy this URI string and paste it to app using button *"Add new TOTP record"*:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
Then press OK, record will appear on page
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
You can edit your otpauth:// records using button "Change TOTP link". Your previous record will be replaced with a new otpauth:// link entered on text field, and previous link will not be shown on field.
|
||||||
|
|
||||||
|
### If you use google migrations (otpauth-migration:// links)
|
||||||
|
|
||||||
|
To add 2FA TOTP recods using migration from Google Authenticator app, you must go to menu, select "Transfer accounts" -> "Export accounts"
|
||||||
|
|
||||||
|
Select codes then screenshot QR code and and scan (decode) it to a URI. Use any app providing scan from image, ex: "Search screen" function (Google Lens) on Google Assistant.
|
||||||
|
|
||||||
|
For example, this QR-Code will represent next URI string:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
After scaning copy this URI string and paste it to app using button *"Add new TOTP record"*:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
Then press OK, all selected records on Google Authenticator will appear on page
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
You can edit your records using button "Change TOTP link". Your previous record will be replaced with a new otpauth:// link entered on text field, and previous link will not be shown on field.
|
||||||
BIN
docs/guides/how-to-add-totps/image-2.png
Normal file
|
After Width: | Height: | Size: 22 KiB |
BIN
docs/guides/how-to-add-totps/image-4.png
Normal file
|
After Width: | Height: | Size: 17 KiB |
BIN
docs/guides/how-to-add-totps/image-5.png
Normal file
|
After Width: | Height: | Size: 448 KiB |
BIN
docs/guides/how-to-add-totps/image-6.png
Normal file
|
After Width: | Height: | Size: 27 KiB |
BIN
docs/guides/how-to-add-totps/image-7.png
Normal file
|
After Width: | Height: | Size: 27 KiB |
BIN
docs/guides/how-to-add-totps/image.png
Normal file
|
After Width: | Height: | Size: 44 KiB |
BIN
docs/screenshots/scr1.png
Normal file
|
After Width: | Height: | Size: 12 KiB |
BIN
docs/screenshots/scr2.png
Normal file
|
After Width: | Height: | Size: 22 KiB |
BIN
docs/screenshots/scr3.png
Normal file
|
After Width: | Height: | Size: 43 KiB |
BIN
icon_for_appstore.png
Normal file
|
After Width: | Height: | Size: 74 KiB |
36
lib/protobuf-decoder/hexUtils.js
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
import { Buffer } from 'buffer'
|
||||||
|
|
||||||
|
export function parseInput(input) {
|
||||||
|
const normalizedInput = input.replace(/\s/g, "");
|
||||||
|
const normalizedHexInput = normalizedInput.replace(/0x/g, "").toLowerCase();
|
||||||
|
if (isHex(normalizedHexInput)) {
|
||||||
|
return Buffer.from(normalizedHexInput, "hex");
|
||||||
|
} else {
|
||||||
|
return Buffer.from(normalizedInput, "base64");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isHex(string) {
|
||||||
|
let result = true;
|
||||||
|
for (const char of string) {
|
||||||
|
if (!((char >= "a" && char <= "f") || (char >= "0" && char <= "9"))) {
|
||||||
|
result = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function bufferLeToBeHex(buffer) {
|
||||||
|
let output = "";
|
||||||
|
for (const v of buffer) {
|
||||||
|
const hex = v.toString(16);
|
||||||
|
if (hex.length === 1) {
|
||||||
|
output = "0" + hex + output;
|
||||||
|
} else {
|
||||||
|
output = hex + output;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const bufferToPrettyHex = b => [...b].map(c => c.toString(16).padStart(2, '0')).join(' ');
|
||||||
132
lib/protobuf-decoder/protobufDecoder.js
Normal file
@@ -0,0 +1,132 @@
|
|||||||
|
import { decodeVarint } from "./varintUtils";
|
||||||
|
|
||||||
|
export class BufferReader {
|
||||||
|
constructor(buffer) {
|
||||||
|
this.buffer = buffer;
|
||||||
|
this.offset = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
readVarInt() {
|
||||||
|
const result = decodeVarint(this.buffer, this.offset);
|
||||||
|
this.offset += result.length;
|
||||||
|
|
||||||
|
return result.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
readBuffer(length) {
|
||||||
|
this.checkByte(length);
|
||||||
|
const result = this.buffer.slice(this.offset, this.offset + length);
|
||||||
|
this.offset += length;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// gRPC has some additional header - remove it
|
||||||
|
trySkipGrpcHeader() {
|
||||||
|
const backupOffset = this.offset;
|
||||||
|
|
||||||
|
if (this.buffer[this.offset] === 0 && this.leftBytes() >= 5) {
|
||||||
|
this.offset++;
|
||||||
|
const length = this.buffer.readInt32BE(this.offset);
|
||||||
|
this.offset += 4;
|
||||||
|
|
||||||
|
if (length > this.leftBytes()) {
|
||||||
|
// Something is wrong, revert
|
||||||
|
this.offset = backupOffset;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
leftBytes() {
|
||||||
|
return this.buffer.length - this.offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
checkByte(length) {
|
||||||
|
const bytesAvailable = this.leftBytes();
|
||||||
|
if (length > bytesAvailable) {
|
||||||
|
throw new Error(
|
||||||
|
"Not enough bytes left. Requested: " +
|
||||||
|
length +
|
||||||
|
" left: " +
|
||||||
|
bytesAvailable
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
checkpoint() {
|
||||||
|
this.savedOffset = this.offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
resetToCheckpoint() {
|
||||||
|
this.offset = this.savedOffset;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const TYPES = {
|
||||||
|
VARINT: 0,
|
||||||
|
FIXED64: 1,
|
||||||
|
LENDELIM: 2,
|
||||||
|
FIXED32: 5
|
||||||
|
};
|
||||||
|
|
||||||
|
export function decodeProto(buffer) {
|
||||||
|
const reader = new BufferReader(buffer);
|
||||||
|
const parts = [];
|
||||||
|
reader.trySkipGrpcHeader();
|
||||||
|
|
||||||
|
try {
|
||||||
|
while (reader.leftBytes() > 0) {
|
||||||
|
reader.checkpoint();
|
||||||
|
|
||||||
|
const byteRange = [reader.offset];
|
||||||
|
const indexType = parseInt(reader.readVarInt().toString());
|
||||||
|
const type = indexType & 0b111;
|
||||||
|
const index = indexType >> 3;
|
||||||
|
|
||||||
|
let value;
|
||||||
|
if (type === TYPES.VARINT) {
|
||||||
|
value = reader.readVarInt().toString();
|
||||||
|
} else if (type === TYPES.LENDELIM) {
|
||||||
|
const length = parseInt(reader.readVarInt().toString());
|
||||||
|
value = reader.readBuffer(length);
|
||||||
|
} else if (type === TYPES.FIXED32) {
|
||||||
|
value = reader.readBuffer(4);
|
||||||
|
} else if (type === TYPES.FIXED64) {
|
||||||
|
value = reader.readBuffer(8);
|
||||||
|
} else {
|
||||||
|
throw new Error("Unknown type: " + type);
|
||||||
|
}
|
||||||
|
byteRange.push(reader.offset);
|
||||||
|
|
||||||
|
parts.push({
|
||||||
|
byteRange,
|
||||||
|
index,
|
||||||
|
type,
|
||||||
|
value
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
reader.resetToCheckpoint();
|
||||||
|
console.log(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
parts,
|
||||||
|
leftOver: reader.readBuffer(reader.leftBytes())
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function typeToString(type, subType) {
|
||||||
|
switch (type) {
|
||||||
|
case TYPES.VARINT:
|
||||||
|
return "varint";
|
||||||
|
case TYPES.LENDELIM:
|
||||||
|
return subType || "len_delim";
|
||||||
|
case TYPES.FIXED32:
|
||||||
|
return "fixed32";
|
||||||
|
case TYPES.FIXED64:
|
||||||
|
return "fixed64";
|
||||||
|
default:
|
||||||
|
return "unknown";
|
||||||
|
}
|
||||||
|
}
|
||||||
23
lib/protobuf-decoder/varintUtils.js
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
export function decodeVarint(buffer, offset) {
|
||||||
|
let res = 0;
|
||||||
|
let shift = 0;
|
||||||
|
let byte = 0;
|
||||||
|
|
||||||
|
do {
|
||||||
|
if (offset >= buffer.length) {
|
||||||
|
throw new RangeError("Index out of bound decoding varint");
|
||||||
|
}
|
||||||
|
|
||||||
|
byte = buffer[offset++];
|
||||||
|
|
||||||
|
const multiplier = 2 ** shift;
|
||||||
|
const thisByteValue = (byte & 0x7f) * multiplier;
|
||||||
|
shift += 7;
|
||||||
|
res = res + thisByteValue;
|
||||||
|
} while (byte >= 0x80);
|
||||||
|
|
||||||
|
return {
|
||||||
|
value: res,
|
||||||
|
length: shift / 7
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -16,7 +16,6 @@ export function getHOTP(counter, secret, digits = 6, hashType = 'SHA-1'){
|
|||||||
rawDataCounter.setUint32(4, counter)
|
rawDataCounter.setUint32(4, counter)
|
||||||
|
|
||||||
const bCounter = new Uint8Array(rawDataCounter.buffer)
|
const bCounter = new Uint8Array(rawDataCounter.buffer)
|
||||||
console.log(bCounter)
|
|
||||||
const bSecret = new Uint8Array(decode(secret).match(/.{1,2}/g).map(chunk => parseInt(chunk, 16))); //confirmed
|
const bSecret = new Uint8Array(decode(secret).match(/.{1,2}/g).map(chunk => parseInt(chunk, 16))); //confirmed
|
||||||
|
|
||||||
//Stage 2: Hash data
|
//Stage 2: Hash data
|
||||||
|
|||||||
@@ -23,4 +23,58 @@ function leftpad(str, len, pad) {
|
|||||||
(str = new Array(len + 1 - str.length).join(pad) + str),
|
(str = new Array(len + 1 - str.length).join(pad) + str),
|
||||||
str
|
str
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function encode(bytes) {
|
||||||
|
const alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';
|
||||||
|
let bits = 0;
|
||||||
|
let value = 0;
|
||||||
|
let output = '';
|
||||||
|
|
||||||
|
for (let i = 0; i < bytes.length; i++) {
|
||||||
|
value = (value << 8) | bytes[i];
|
||||||
|
bits += 8;
|
||||||
|
|
||||||
|
while (bits >= 5) {
|
||||||
|
output += alphabet[(value >>> (bits - 5)) & 0x1F];
|
||||||
|
bits -= 5;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bits > 0) {
|
||||||
|
output += alphabet[(value << (5 - bits)) & 0x1F];
|
||||||
|
}
|
||||||
|
|
||||||
|
const paddingLength = (8 - (output.length % 8)) % 8;
|
||||||
|
output += '='.repeat(paddingLength);
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function base64decode(base64) {
|
||||||
|
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||||
|
let result = [];
|
||||||
|
let i = 0, j = 0;
|
||||||
|
let b1, b2, b3, b4;
|
||||||
|
|
||||||
|
while (i < base64.length) {
|
||||||
|
b1 = chars.indexOf(base64.charAt(i++));
|
||||||
|
b2 = chars.indexOf(base64.charAt(i++));
|
||||||
|
b3 = chars.indexOf(base64.charAt(i++));
|
||||||
|
b4 = chars.indexOf(base64.charAt(i++));
|
||||||
|
|
||||||
|
if (b1 === -1 || b2 === -1) break;
|
||||||
|
|
||||||
|
result[j++] = (b1 << 2) | (b2 >> 4);
|
||||||
|
|
||||||
|
if (b3 !== -1) {
|
||||||
|
result[j++] = ((b2 & 15) << 4) | (b3 >> 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (b4 !== -1) {
|
||||||
|
result[j++] = ((b3 & 3) << 6) | b4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result.slice(0, j);
|
||||||
}
|
}
|
||||||
@@ -1,12 +1,9 @@
|
|||||||
{
|
{
|
||||||
"name": "totpfit",
|
"name": "totpfit",
|
||||||
"version": "1.0.0",
|
"version": "1.3.0",
|
||||||
"description": "TOTP Authenticator for Amazfit devices",
|
"description": "Another 2FAuthenticator based on TOTP for Zepp Amazfit GTS 4",
|
||||||
"main": "app.js",
|
"main": "app.js",
|
||||||
"scripts": {
|
"author": "Lisoveliy",
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
|
||||||
},
|
|
||||||
"author": "",
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@zeppos/device-types": "^3.0.0"
|
"@zeppos/device-types": "^3.0.0"
|
||||||
|
|||||||
101
page/index.js
@@ -1,47 +1,60 @@
|
|||||||
import { RenderAddButton } from './render/totpRenderer'
|
import { RenderAddButton } from "./render/totpRenderer";
|
||||||
import { initLoop } from './render/index/renderer'
|
import { initLoop } from "./render/index/renderer";
|
||||||
import { BasePage } from '@zeppos/zml/base-page'
|
import { BasePage } from "@zeppos/zml/base-page";
|
||||||
import { LocalStorage } from "@zos/storage"
|
import { LocalStorage } from "@zos/storage";
|
||||||
|
|
||||||
|
const app = getApp();
|
||||||
|
|
||||||
const localStorage = new LocalStorage()
|
|
||||||
const app = getApp()
|
|
||||||
let waitForFetch = true;
|
let waitForFetch = true;
|
||||||
Page(
|
|
||||||
BasePage({
|
|
||||||
onInit() {
|
|
||||||
this.getTOTPData().then((x) => {
|
|
||||||
console.log(x)
|
|
||||||
localStorage.setItem('TOTPs', x ?? [])
|
|
||||||
app._options.globalData.TOTPS = x ?? []
|
|
||||||
this.initPage();
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
app._options.globalData.TOTPS = localStorage.getItem('TOTPs') ?? []
|
|
||||||
this.initPage()
|
|
||||||
})
|
|
||||||
},
|
|
||||||
build() {
|
|
||||||
let fetch = setInterval(() => {
|
|
||||||
if(waitForFetch)
|
|
||||||
return;
|
|
||||||
|
|
||||||
clearInterval(fetch);
|
Page(
|
||||||
const buffer = app._options.globalData.TOTPS
|
BasePage({
|
||||||
if (buffer.length < 1){
|
onInit() {
|
||||||
RenderAddButton('page/tip')
|
this.getTOTPData()
|
||||||
}
|
.then((x) => {
|
||||||
else {
|
app._options.globalData.TOTPS = JSON.parse(x) ?? [];
|
||||||
initLoop(buffer)
|
|
||||||
}
|
let localStorage = new LocalStorage();
|
||||||
}, 100);
|
localStorage.setItem(
|
||||||
},
|
"TOTPs",
|
||||||
initPage() {
|
JSON.stringify(app._options.globalData.TOTPS)
|
||||||
waitForFetch = false;
|
);
|
||||||
},
|
this.initPage();
|
||||||
getTOTPData() {
|
})
|
||||||
return this.request({
|
.catch((x) => {
|
||||||
method: 'totps'
|
console.log(`Init failed: ${x}`);
|
||||||
})
|
try{
|
||||||
}
|
let localStorage = new LocalStorage();
|
||||||
})
|
app._options.globalData.TOTPS = JSON.parse(
|
||||||
)
|
localStorage.getItem("TOTPs", [])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch{
|
||||||
|
app._options.globalData.TOTPS = [];
|
||||||
|
}
|
||||||
|
this.initPage();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
build() {
|
||||||
|
let fetch = setInterval(() => {
|
||||||
|
if (waitForFetch) return;
|
||||||
|
|
||||||
|
clearInterval(fetch);
|
||||||
|
const buffer = app._options.globalData.TOTPS;
|
||||||
|
if (buffer.length < 1) {
|
||||||
|
RenderAddButton("page/tip");
|
||||||
|
} else {
|
||||||
|
initLoop(buffer);
|
||||||
|
}
|
||||||
|
}, 100);
|
||||||
|
},
|
||||||
|
initPage() {
|
||||||
|
waitForFetch = false;
|
||||||
|
},
|
||||||
|
getTOTPData() {
|
||||||
|
return this.request({
|
||||||
|
method: "totps",
|
||||||
|
});
|
||||||
|
},
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { px } from "@zos/utils";
|
import { px } from "@zos/utils";
|
||||||
|
|
||||||
export const TEXT_STYLE = {
|
export const TEXT_STYLE = {
|
||||||
x: px(0),
|
x: px(0),
|
||||||
y: px(0),
|
y: px(0),
|
||||||
}
|
};
|
||||||
|
|||||||
@@ -1,46 +1,57 @@
|
|||||||
import { prop } from "@zos/ui";
|
import { prop } from "@zos/ui";
|
||||||
import { TOTP } from "../../../lib/totp-quickjs";
|
import { TOTP } from "../../../lib/totp-quickjs";
|
||||||
import { RenderExpireBar, RenderOTPValue, RenderTOTPContainer } from '../totpRenderer'
|
import {
|
||||||
|
RenderExpireBar,
|
||||||
|
RenderOTPValue,
|
||||||
|
RenderTOTPContainer,
|
||||||
|
} from "../totpRenderer";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param {Array<TOTP>} buffer
|
* @param {Array<TOTP>} buffer
|
||||||
*/
|
*/
|
||||||
export function initLoop(buffer) {
|
export function initLoop(buffer) {
|
||||||
renderContainers(buffer)
|
renderContainers(buffer);
|
||||||
renderTOTPs(buffer)
|
renderTOTPs(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderContainers(buffer) {
|
function renderContainers(buffer) {
|
||||||
for (let i = 0; i < buffer.length; i++) {
|
for (let i = 0; i < buffer.length; i++) {
|
||||||
RenderTOTPContainer(i, buffer[i].issuer, buffer[i].client)
|
RenderTOTPContainer(i, buffer[i].issuer, buffer[i].client);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const renderData = []
|
|
||||||
|
|
||||||
|
const renderData = [];
|
||||||
function renderTOTPs(buffer) {
|
function renderTOTPs(buffer) {
|
||||||
for (let i = 0; i < buffer.length; i++) {
|
for (let i = 0; i < buffer.length; i++) {
|
||||||
let otpData = TOTP.copy(buffer[i]).getOTP()
|
let otpData = TOTP.copy(buffer[i]).getOTP();
|
||||||
console.log(otpData.otp)
|
|
||||||
renderData[i] = {
|
renderData[i] = {
|
||||||
OTP: RenderOTPValue(i, otpData.otp),
|
OTP: RenderOTPValue(i, otpData.otp),
|
||||||
expireBar: RenderExpireBar(i, otpData.createdTime, buffer[i].fetchTime)
|
expireBar: RenderExpireBar(
|
||||||
}
|
i,
|
||||||
|
otpData.createdTime,
|
||||||
|
buffer[i].fetchTime
|
||||||
|
),
|
||||||
|
};
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
const expireDif = Math.abs((((Date.now() - otpData.createdTime) / 1000)
|
const expireDif = Math.abs(
|
||||||
/ buffer[i].fetchTime) - 1)
|
(Date.now() - otpData.createdTime) /
|
||||||
|
1000 /
|
||||||
|
buffer[i].fetchTime -
|
||||||
|
1
|
||||||
|
);
|
||||||
|
|
||||||
renderData[i].expireBar.setProperty(prop.MORE, {
|
renderData[i].expireBar.setProperty(prop.MORE, {
|
||||||
end_angle: (expireDif * 360) - 90,
|
end_angle: expireDif * 360 - 90,
|
||||||
color: expireDif > 0.25 ? 0x1ca9c9 : 0xfa0404,
|
color: expireDif > 0.25 ? 0x1ca9c9 : 0xfa0404,
|
||||||
})
|
});
|
||||||
|
|
||||||
if (otpData.expireTime < Date.now()) {
|
if (otpData.expireTime < Date.now()) {
|
||||||
otpData = TOTP.copy(buffer[i]).getOTP()
|
otpData = TOTP.copy(buffer[i]).getOTP();
|
||||||
renderData[i].OTP.setProperty(prop.MORE, {
|
renderData[i].OTP.setProperty(prop.MORE, {
|
||||||
text: otpData.otp
|
text: otpData.otp,
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
}, 50)
|
}, 50);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,35 +1,36 @@
|
|||||||
import { getDeviceInfo } from '@zos/device'
|
import { getDeviceInfo } from "@zos/device";
|
||||||
import { push } from '@zos/router'
|
import { push } from "@zos/router";
|
||||||
import { createWidget, widget, align, text_style } from '@zos/ui'
|
import { createWidget, widget, align, text_style } from "@zos/ui";
|
||||||
|
|
||||||
//Renderer module for TOTPs page
|
//Renderer module for TOTPs page
|
||||||
|
|
||||||
const { width, height } = getDeviceInfo()
|
const { width, height } = getDeviceInfo();
|
||||||
const buttonWidth = width - width / 20 //Width of container
|
const buttonWidth = width - width / 20; //Width of container
|
||||||
const buttonHeight = height / 4 //Height of container
|
const buttonHeight = height / 4; //Height of container
|
||||||
const containerColor = 0x303030 //Color of container
|
|
||||||
const containerRadius = 20 //Corner radius of container
|
|
||||||
|
|
||||||
const textColor = 0xa0a0a0 //Color of TOTP description text
|
const containerColor = 0x303030; //Color of container
|
||||||
const textSize = 24 //Size of TOTP description text
|
const containerRadius = 20; //Corner radius of container
|
||||||
const statusBarPading = 65
|
|
||||||
|
const textColor = 0xa0a0a0; //Color of TOTP description text
|
||||||
|
const textSize = 24; //Size of TOTP description text
|
||||||
|
const statusBarPading = 65;
|
||||||
|
|
||||||
/** Function for render box container for TOTP values
|
/** Function for render box container for TOTP values
|
||||||
*
|
*
|
||||||
* @param {number} position position offset of container
|
* @param {number} position position offset of container
|
||||||
* @param {string} issuer issuer of TOTP
|
* @param {string} issuer issuer of TOTP
|
||||||
* @param {string} client client of TOTP
|
* @param {string} client client of TOTP
|
||||||
*/
|
*/
|
||||||
export function RenderTOTPContainer(position, issuer, client) {
|
export function RenderTOTPContainer(position, issuer, client) {
|
||||||
const yPos = getYPos(position)
|
const yPos = getYPos(position);
|
||||||
createWidget(widget.FILL_RECT, {
|
createWidget(widget.FILL_RECT, {
|
||||||
x: width / 2 - buttonWidth / 2,
|
x: width / 2 - buttonWidth / 2,
|
||||||
y: yPos,
|
y: yPos,
|
||||||
w: buttonWidth,
|
w: buttonWidth,
|
||||||
h: buttonHeight,
|
h: buttonHeight,
|
||||||
color: containerColor,
|
color: containerColor,
|
||||||
radius: containerRadius
|
radius: containerRadius,
|
||||||
})
|
});
|
||||||
createWidget(widget.TEXT, {
|
createWidget(widget.TEXT, {
|
||||||
x: 0 + (width - buttonWidth) / 2,
|
x: 0 + (width - buttonWidth) / 2,
|
||||||
y: yPos + 10,
|
y: yPos + 10,
|
||||||
@@ -40,18 +41,18 @@ export function RenderTOTPContainer(position, issuer, client) {
|
|||||||
align_h: align.CENTER_H,
|
align_h: align.CENTER_H,
|
||||||
align_v: align.CENTER_V,
|
align_v: align.CENTER_V,
|
||||||
text_style: text_style.NONE,
|
text_style: text_style.NONE,
|
||||||
text: issuer + ': ' + client
|
text: issuer + ": " + client,
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Render OTP Value on container
|
/** Render OTP Value on container
|
||||||
*
|
*
|
||||||
* @param {number} position position offset of container
|
* @param {number} position position offset of container
|
||||||
* @param {string} otpValue value to display
|
* @param {string} otpValue value to display
|
||||||
* @returns widget with OTP
|
* @returns widget with OTP
|
||||||
*/
|
*/
|
||||||
export function RenderOTPValue(position, otpValue) {
|
export function RenderOTPValue(position, otpValue) {
|
||||||
const yPos = getYPos(position)
|
const yPos = getYPos(position);
|
||||||
return createWidget(widget.TEXT, {
|
return createWidget(widget.TEXT, {
|
||||||
x: 0,
|
x: 0,
|
||||||
y: yPos + 50,
|
y: yPos + 50,
|
||||||
@@ -62,21 +63,22 @@ export function RenderOTPValue(position, otpValue) {
|
|||||||
align_h: align.CENTER_H,
|
align_h: align.CENTER_H,
|
||||||
align_v: align.CENTER_V,
|
align_v: align.CENTER_V,
|
||||||
text_style: text_style.NONE,
|
text_style: text_style.NONE,
|
||||||
text: otpValue
|
text: otpValue,
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Render expire bar
|
/** Render expire bar
|
||||||
*
|
*
|
||||||
* @param {} position position offset of container
|
* @param {} position position offset of container
|
||||||
* @param {*} createdTime UNIX epoch time of creation
|
* @param {*} createdTime UNIX epoch time of creation
|
||||||
* @param {*} fetchTime time in seconds to fetch value
|
* @param {*} fetchTime time in seconds to fetch value
|
||||||
* @returns widget with bar
|
* @returns widget with bar
|
||||||
*/
|
*/
|
||||||
export function RenderExpireBar(position, createdTime, fetchTime) {
|
export function RenderExpireBar(position, createdTime, fetchTime) {
|
||||||
const yPos = getYPos(position)
|
const yPos = getYPos(position);
|
||||||
const expireDif = Math.abs((((Date.now() - createdTime) / 1000)
|
const expireDif = Math.abs(
|
||||||
/ fetchTime) - 1)
|
(Date.now() - createdTime) / 1000 / fetchTime - 1
|
||||||
|
);
|
||||||
return createWidget(widget.ARC, {
|
return createWidget(widget.ARC, {
|
||||||
x: buttonWidth - 50,
|
x: buttonWidth - 50,
|
||||||
y: yPos + 52,
|
y: yPos + 52,
|
||||||
@@ -85,13 +87,13 @@ export function RenderExpireBar(position, createdTime, fetchTime) {
|
|||||||
line_width: 5,
|
line_width: 5,
|
||||||
color: expireDif > 0.25 ? 0x1ca9c9 : 0xfa0404,
|
color: expireDif > 0.25 ? 0x1ca9c9 : 0xfa0404,
|
||||||
start_angle: -90,
|
start_angle: -90,
|
||||||
end_angle: (expireDif * 360) - 90,
|
end_angle: expireDif * 360 - 90,
|
||||||
text: expireDif
|
text: expireDif,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Function for render 'Add' button on center of screen
|
/** Function for render 'Add' button on center of screen
|
||||||
*
|
*
|
||||||
* @param {string} pagePath destination to page onClick ex: 'page/index'
|
* @param {string} pagePath destination to page onClick ex: 'page/index'
|
||||||
*/
|
*/
|
||||||
export function RenderAddButton(pagePath) {
|
export function RenderAddButton(pagePath) {
|
||||||
@@ -100,17 +102,19 @@ export function RenderAddButton(pagePath) {
|
|||||||
y: height / 2 - 20,
|
y: height / 2 - 20,
|
||||||
w: 80,
|
w: 80,
|
||||||
h: 80,
|
h: 80,
|
||||||
text: '+',
|
text: "+",
|
||||||
radius: 50,
|
radius: 50,
|
||||||
text_size: 40,
|
text_size: 40,
|
||||||
normal_color: 0x303030,
|
normal_color: 0x303030,
|
||||||
press_color: 0x181c18,
|
press_color: 0x181c18,
|
||||||
click_func: () => {
|
click_func: () => {
|
||||||
push({
|
push({
|
||||||
url: pagePath
|
url: pagePath,
|
||||||
})
|
});
|
||||||
}
|
},
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function getYPos(position) { return position * (buttonHeight + 10) + statusBarPading }
|
function getYPos(position) {
|
||||||
|
return position * (buttonHeight + 10) + statusBarPading;
|
||||||
|
}
|
||||||
|
|||||||
18
page/tip.js
@@ -1,6 +1,6 @@
|
|||||||
import { createWidget, widget, align } from "@zos/ui";
|
import { createWidget, widget, align } from "@zos/ui";
|
||||||
import { getDeviceInfo } from "@zos/device";
|
import { getDeviceInfo } from "@zos/device";
|
||||||
import { onGesture, GESTURE_LEFT } from '@zos/interaction'
|
import { onGesture, GESTURE_LEFT } from "@zos/interaction";
|
||||||
import { back } from "@zos/router";
|
import { back } from "@zos/router";
|
||||||
import { BasePage } from "@zeppos/zml/base-page";
|
import { BasePage } from "@zeppos/zml/base-page";
|
||||||
Page(
|
Page(
|
||||||
@@ -9,13 +9,13 @@ Page(
|
|||||||
onGesture({
|
onGesture({
|
||||||
callback(event) {
|
callback(event) {
|
||||||
if (event === GESTURE_LEFT) {
|
if (event === GESTURE_LEFT) {
|
||||||
back()
|
back();
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
})
|
});
|
||||||
},
|
},
|
||||||
build() {
|
build() {
|
||||||
const { width, height } = getDeviceInfo()
|
const { width, height } = getDeviceInfo();
|
||||||
createWidget(widget.TEXT, {
|
createWidget(widget.TEXT, {
|
||||||
x: 0,
|
x: 0,
|
||||||
w: width,
|
w: width,
|
||||||
@@ -24,8 +24,8 @@ Page(
|
|||||||
text_size: 30,
|
text_size: 30,
|
||||||
align_h: align.CENTER_H,
|
align_h: align.CENTER_H,
|
||||||
align_v: align.CENTER_V,
|
align_v: align.CENTER_V,
|
||||||
text: 'To add TOTP record open\n settings on Zepp app'
|
text: "To add TOTP record open\n settings on Zepp app",
|
||||||
})
|
});
|
||||||
}
|
},
|
||||||
})
|
})
|
||||||
)
|
);
|
||||||
|
|||||||
358
setting/index.js
@@ -1,162 +1,220 @@
|
|||||||
import { getTOTPByLink } from './utils/queryParser.js'
|
import { getTOTPByLink } from "./utils/queryParser.js";
|
||||||
|
|
||||||
let _props = null;
|
let _props = null;
|
||||||
|
|
||||||
|
const colors = {
|
||||||
|
bg: "#101010",
|
||||||
|
linkBg: "#ffffffc0",
|
||||||
|
secondaryBg: "#282828",
|
||||||
|
text: "#fafafa",
|
||||||
|
alert: "#ad3c23",
|
||||||
|
notify: "#555555",
|
||||||
|
bigText: "#fafafa"
|
||||||
|
};
|
||||||
|
|
||||||
AppSettingsPage({
|
AppSettingsPage({
|
||||||
build(props) {
|
build(props) {
|
||||||
_props = props;
|
_props = props;
|
||||||
|
const storage = JSON.parse(
|
||||||
const storage = props.settingsStorage.getItem("TOTPs") ?? []
|
props.settingsStorage.getItem("TOTPs") ?? "[]"
|
||||||
const totpEntrys = GetTOTPList(storage)
|
);
|
||||||
const createButton = TextInput({
|
const totpEntrys = GetTOTPList(storage);
|
||||||
placeholder: "otpauth://",
|
const addTOTPsHint = storage.length < 1 ?
|
||||||
label: "Add new OTP Link",
|
Text({
|
||||||
onChange: (changes) => {
|
paragraph: true,
|
||||||
var link = getTOTPByLink(changes)
|
align: "center",
|
||||||
if(link == null){
|
style: {
|
||||||
console.log("link is invalid")
|
paddingTop: "10px",
|
||||||
return;
|
marginBottom: "10px",
|
||||||
}
|
color: colors.text,
|
||||||
storage.push(link)
|
fontSize: 16,
|
||||||
updateStorage(storage)
|
verticalAlign: "middle",
|
||||||
},
|
},
|
||||||
labelStyle: {
|
|
||||||
backgroundColor: "#14213D",
|
|
||||||
display: "flex",
|
|
||||||
alignItems: "center",
|
|
||||||
justifyContent: "center",
|
|
||||||
margin: "10px",
|
|
||||||
flexGrow: 1,
|
|
||||||
fontSize: "20px",
|
|
||||||
color: "#FFFFFF",
|
|
||||||
borderRadius: "5px"
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
var body = Section(
|
|
||||||
{
|
|
||||||
style: {
|
|
||||||
backgroundColor: "black",
|
|
||||||
minHeight: "100vh",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
[
|
|
||||||
View(
|
|
||||||
{
|
|
||||||
style: {
|
|
||||||
textAlign: "center",
|
|
||||||
},
|
},
|
||||||
},
|
"For add a 2FA TOTP record you must have otpauth:// link or otpauth-migration:// link from Google Authenticator Migration QR-Code"
|
||||||
Text(
|
) : null;
|
||||||
|
const createButton = TextInput({
|
||||||
|
placeholder: "otpauth(-migration)://",
|
||||||
|
label: "Add new TOTP record",
|
||||||
|
onChange: (changes) => {
|
||||||
|
let link = getTOTPByLink(changes);
|
||||||
|
if (link == null) {
|
||||||
|
console.log("link is invalid");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Array.isArray(link))
|
||||||
|
storage.push(...link);
|
||||||
|
else storage.push(link);
|
||||||
|
|
||||||
|
updateStorage(storage);
|
||||||
|
},
|
||||||
|
labelStyle: {
|
||||||
|
backgroundColor: colors.notify,
|
||||||
|
display: "flex",
|
||||||
|
alignItems: "center",
|
||||||
|
justifyContent: "center",
|
||||||
|
margin: "10px",
|
||||||
|
fontSize: "20px",
|
||||||
|
color: colors.text,
|
||||||
|
borderRadius: "5px",
|
||||||
|
position: storage.length < 1 ? "absolute" : null, //TODO: Сделать что-то с этим кошмаром
|
||||||
|
bottom: storage.length < 1 ? "0px" : null,
|
||||||
|
left: storage.length < 1 ? "0px" : null,
|
||||||
|
right: storage.length < 1 ? "0px" : null
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
var body = Section(
|
||||||
{
|
{
|
||||||
align: "center",
|
style: {
|
||||||
paragraph: true,
|
backgroundColor: colors.bg,
|
||||||
style: {
|
minHeight: "100vh",
|
||||||
marginBottom: "10px",
|
},
|
||||||
color: "#fff",
|
|
||||||
fontSize: 23,
|
|
||||||
verticalAlign: "middle",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
"TOTPS:"
|
[
|
||||||
)
|
View(
|
||||||
),
|
{
|
||||||
...totpEntrys,
|
style: {
|
||||||
createButton
|
textAlign: "center",
|
||||||
]
|
},
|
||||||
);
|
},
|
||||||
return body;
|
storage.length < 1 ? addTOTPsHint : Text(
|
||||||
},
|
{
|
||||||
|
align: "center",
|
||||||
|
paragraph: true,
|
||||||
|
style: {
|
||||||
|
marginBottom: "10px",
|
||||||
|
color: colors.bigText,
|
||||||
|
fontSize: 23,
|
||||||
|
fontWeight: "500",
|
||||||
|
verticalAlign: "middle",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"TOTP records:"
|
||||||
|
)
|
||||||
|
),
|
||||||
|
...totpEntrys,
|
||||||
|
createButton,
|
||||||
|
View({
|
||||||
|
style: {
|
||||||
|
display: "flex",
|
||||||
|
justifyContent: "center"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Link({
|
||||||
|
source: "https://github.com/Lisoveliy/totpfit/blob/main/docs/guides/how-to-add-totps/README.md"
|
||||||
|
},
|
||||||
|
"Instruction | Report issue (GitHub)")
|
||||||
|
),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
return body;
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
function GetTOTPList(storage){
|
function GetTOTPList(storage) {
|
||||||
let totpEntrys = [];
|
let totpEntrys = [];
|
||||||
let counter = 0;
|
let counter = 0;
|
||||||
storage.forEach((element) => {
|
storage.forEach((element) => {
|
||||||
const elementId = counter;
|
const elementId = counter;
|
||||||
const textInput = TextInput({
|
const textInput = TextInput({
|
||||||
placeholder: "otpauth://",
|
placeholder: "otpauth(-migration)://",
|
||||||
label: "Change OTP link",
|
label: "Change TOTP link",
|
||||||
onChange: (changes) => {
|
onChange: (changes) => {
|
||||||
try{
|
try {
|
||||||
storage[elementId] = getTOTPByLink(changes)
|
let link = getTOTPByLink(changes);
|
||||||
updateStorage(storage)
|
if (Array.isArray(link))
|
||||||
}
|
return;
|
||||||
catch(err){
|
|
||||||
console.log(err)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
labelStyle: {
|
|
||||||
backgroundColor: "#14213D",
|
|
||||||
textAlign: "center",
|
|
||||||
display: "flex",
|
|
||||||
alignItems: "center",
|
|
||||||
justifyContent: "center",
|
|
||||||
margin: "10px",
|
|
||||||
flexGrow: 1,
|
|
||||||
fontSize: "20px",
|
|
||||||
color: "#E5E5E5",
|
|
||||||
borderRadius: "5px"
|
|
||||||
},
|
|
||||||
});
|
|
||||||
const textBig = Text(
|
|
||||||
{
|
|
||||||
align: "center",
|
|
||||||
style: {
|
|
||||||
color: "#ffffff",
|
|
||||||
fontSize: "16px"
|
|
||||||
},
|
|
||||||
paragraph: true,
|
|
||||||
},
|
|
||||||
`${element.issuer}: ${element.client}`
|
|
||||||
);
|
|
||||||
const delButton = Button(
|
|
||||||
{
|
|
||||||
onClick: () => {
|
|
||||||
storage = storage.filter(x => storage.indexOf(x) != elementId)
|
|
||||||
updateStorage(storage)
|
|
||||||
},
|
|
||||||
style: {
|
|
||||||
backgroundColor: "#ba181b",
|
|
||||||
fontSize: "18px",
|
|
||||||
color: "#ffffff",
|
|
||||||
height: "fit-content",
|
|
||||||
margin: "10px"
|
|
||||||
},
|
|
||||||
label: "DEL"
|
|
||||||
}
|
|
||||||
);
|
|
||||||
const text = Text(
|
|
||||||
{
|
|
||||||
style: {
|
|
||||||
color: "#ffffff",
|
|
||||||
fontSize: "14px"
|
|
||||||
},
|
|
||||||
align: "center"
|
|
||||||
},
|
|
||||||
`${element.hashType} | ${element.digits} digits | ${element.fetchTime} seconds | offset ${element.timeOffset} seconds`
|
|
||||||
);
|
|
||||||
const view = View(
|
|
||||||
{
|
|
||||||
style: {
|
|
||||||
textAlign: "center",
|
|
||||||
border: "2px solid white",
|
|
||||||
borderRadius: "5px",
|
|
||||||
margin: "10px"
|
|
||||||
},
|
|
||||||
},
|
|
||||||
[textBig, text, View({style: {
|
|
||||||
display: "grid",
|
|
||||||
gridTemplateColumns: "1fr 100px"
|
|
||||||
}}, [textInput, delButton])]
|
|
||||||
);
|
|
||||||
totpEntrys.push({ text: text, view: view });
|
|
||||||
counter++;
|
|
||||||
});
|
|
||||||
|
|
||||||
return totpEntrys.map(x => x.view);
|
storage[elementId] = link;
|
||||||
|
updateStorage(storage);
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
labelStyle: {
|
||||||
|
backgroundColor: colors.notify,
|
||||||
|
textAlign: "center",
|
||||||
|
display: "flex",
|
||||||
|
alignItems: "center",
|
||||||
|
justifyContent: "center",
|
||||||
|
margin: "10px",
|
||||||
|
flexGrow: 1,
|
||||||
|
fontSize: "20px",
|
||||||
|
color: colors.text,
|
||||||
|
borderRadius: "5px",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const textBig = Text(
|
||||||
|
{
|
||||||
|
align: "center",
|
||||||
|
style: {
|
||||||
|
color: colors.text,
|
||||||
|
fontSize: "18px",
|
||||||
|
fontWeight: "500"
|
||||||
|
},
|
||||||
|
paragraph: true,
|
||||||
|
},
|
||||||
|
`${element.issuer}: ${element.client}`
|
||||||
|
);
|
||||||
|
const delButton = Button({
|
||||||
|
onClick: () => {
|
||||||
|
storage = storage.filter(
|
||||||
|
(x) => storage.indexOf(x) != elementId
|
||||||
|
);
|
||||||
|
updateStorage(storage);
|
||||||
|
},
|
||||||
|
style: {
|
||||||
|
backgroundColor: colors.alert,
|
||||||
|
fontSize: "18px",
|
||||||
|
color: colors.text,
|
||||||
|
height: "fit-content",
|
||||||
|
margin: "10px",
|
||||||
|
},
|
||||||
|
label: "Delete",
|
||||||
|
});
|
||||||
|
const text = Text(
|
||||||
|
{
|
||||||
|
style: {
|
||||||
|
color: colors.text,
|
||||||
|
fontSize: "14px",
|
||||||
|
},
|
||||||
|
align: "center",
|
||||||
|
},
|
||||||
|
`${element.hashType} | ${element.digits} digits | ${element.fetchTime} seconds | ${element.timeOffset} sec offset`
|
||||||
|
);
|
||||||
|
const view = View(
|
||||||
|
{
|
||||||
|
style: {
|
||||||
|
textAlign: "center",
|
||||||
|
backgroundColor: colors.secondaryBg,
|
||||||
|
//border: "2px solid white",
|
||||||
|
borderRadius: "5px",
|
||||||
|
margin: "10px",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
[
|
||||||
|
textBig,
|
||||||
|
text,
|
||||||
|
View(
|
||||||
|
{
|
||||||
|
style: {
|
||||||
|
display: "grid",
|
||||||
|
gridTemplateColumns: "1fr 100px",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
[textInput, delButton]
|
||||||
|
),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
totpEntrys.push({ text: text, view: view });
|
||||||
|
counter++;
|
||||||
|
});
|
||||||
|
|
||||||
|
return totpEntrys.map((x) => x.view);
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateStorage(storage){
|
function updateStorage(storage) {
|
||||||
_props.settingsStorage.setItem('TOTPs', storage)
|
_props.settingsStorage.setItem("TOTPs", JSON.stringify(storage));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,45 +1,114 @@
|
|||||||
|
import { decodeProto, TYPES } from "../../lib/protobuf-decoder/protobufDecoder";
|
||||||
import { TOTP } from "../../lib/totp-quickjs";
|
import { TOTP } from "../../lib/totp-quickjs";
|
||||||
|
import { base64decode, encode } from "../../lib/totp-quickjs/base32decoder";
|
||||||
|
|
||||||
const otpScheme = "otpauth:/";
|
const otpauthScheme = "otpauth:/";
|
||||||
|
const googleMigrationScheme = "otpauth-migration:/";
|
||||||
|
|
||||||
export function getTOTPByLink(link) {
|
export function getTOTPByLink(link) {
|
||||||
try {
|
if (link.includes(otpauthScheme))
|
||||||
let args = link.split("/", otpScheme.length);
|
return getByOtpauthScheme(link)
|
||||||
let type = args[2]; //Returns 'hotp' or 'totp'
|
if (link.includes(googleMigrationScheme))
|
||||||
let issuer = args[3].split(":")[0]?.split("?")[0]; //Returns issuer
|
return getByGoogleMigrationScheme(link)
|
||||||
let client =
|
|
||||||
args[3].split(":")[1]?.split("?")[0] ??
|
|
||||||
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 algorithm = args[3].split("algorithm=")[1]?.split("&")[0]; //Returns algorithm
|
|
||||||
|
|
||||||
if (type.toLowerCase() != "totp")
|
return null;
|
||||||
throw new Error("Type is not valid, requires 'TOTP'");
|
|
||||||
|
|
||||||
if (secret === undefined) throw new Error("Secret not defined");
|
|
||||||
|
|
||||||
issuer = issuer.replace("%20", " ");
|
|
||||||
client = client.replace("%20", " ");
|
|
||||||
|
|
||||||
return new TOTP(
|
|
||||||
secret,
|
|
||||||
issuer,
|
|
||||||
client,
|
|
||||||
digits,
|
|
||||||
period,
|
|
||||||
0,
|
|
||||||
getHashType(algorithm)
|
|
||||||
);
|
|
||||||
} catch (err) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getHashType(algorithm) {
|
function getHashType(algorithm) {
|
||||||
if (algorithm == "SHA1") return "SHA-1";
|
if (algorithm == "SHA1") return "SHA-1";
|
||||||
if (algorithm == "SHA256") return "SHA-256";
|
if (algorithm == "SHA256") return "SHA-256";
|
||||||
if (algorithm == "SHA512") return "SHA-512";
|
if (algorithm == "SHA512") return "SHA-512";
|
||||||
else return "SHA-1";
|
else return "SHA-1";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getByOtpauthScheme(link) {
|
||||||
|
try {
|
||||||
|
let args = link.split("/", otpauthScheme.length);
|
||||||
|
let type = args[2]; //Returns 'hotp' or 'totp'
|
||||||
|
let issuer = args[3].split(":")[0]?.split("?")[0]; //Returns issuer
|
||||||
|
let client =
|
||||||
|
args[3].split(":")[1]?.split("?")[0] ??
|
||||||
|
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("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
|
||||||
|
|
||||||
|
if (type.toLowerCase() != "totp")
|
||||||
|
throw new Error("Type is not valid, requires 'TOTP'");
|
||||||
|
|
||||||
|
if (secret === undefined) throw new Error("Secret not defined");
|
||||||
|
|
||||||
|
if (issuer == client) {
|
||||||
|
issuer = args[3].split("issuer=")[1]?.split("&")[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
issuer = decodeURIComponent(issuer);
|
||||||
|
client = decodeURIComponent(client);
|
||||||
|
|
||||||
|
return new TOTP(
|
||||||
|
secret,
|
||||||
|
issuer,
|
||||||
|
client,
|
||||||
|
Number(digits),
|
||||||
|
Number(period),
|
||||||
|
Number(offset),
|
||||||
|
getHashType(algorithm)
|
||||||
|
);
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err)
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getByGoogleMigrationScheme(link) {
|
||||||
|
|
||||||
|
let data = link.split("data=")[1]; //Returns base64 encoded data
|
||||||
|
data = decodeURIComponent(data);
|
||||||
|
let decode = base64decode(data);
|
||||||
|
let proto = decodeProto(decode);
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||