Compare commits
26 Commits
73ea81af54
...
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 |
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)
|
||||||
7
app.json
@@ -6,14 +6,15 @@
|
|||||||
"appType": "app",
|
"appType": "app",
|
||||||
"version": {
|
"version": {
|
||||||
"code": 1,
|
"code": 1,
|
||||||
"name": "1.0.1"
|
"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",
|
||||||
|
"device:os.local_storage"
|
||||||
],
|
],
|
||||||
"runtime": {
|
"runtime": {
|
||||||
"apiVersion": {
|
"apiVersion": {
|
||||||
|
|||||||
|
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
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -24,3 +24,57 @@ function leftpad(str, len, pad) {
|
|||||||
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"
|
||||||
|
|||||||
@@ -1,19 +1,37 @@
|
|||||||
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";
|
||||||
|
|
||||||
const app = getApp();
|
const app = getApp();
|
||||||
|
|
||||||
let waitForFetch = true;
|
let waitForFetch = true;
|
||||||
|
|
||||||
Page(
|
Page(
|
||||||
BasePage({
|
BasePage({
|
||||||
onInit() {
|
onInit() {
|
||||||
this.getTOTPData()
|
this.getTOTPData()
|
||||||
.then((x) => {
|
.then((x) => {
|
||||||
app._options.globalData.TOTPS = JSON.parse(x) ?? [];
|
app._options.globalData.TOTPS = JSON.parse(x) ?? [];
|
||||||
|
|
||||||
|
let localStorage = new LocalStorage();
|
||||||
|
localStorage.setItem(
|
||||||
|
"TOTPs",
|
||||||
|
JSON.stringify(app._options.globalData.TOTPS)
|
||||||
|
);
|
||||||
this.initPage();
|
this.initPage();
|
||||||
})
|
})
|
||||||
.catch((x) => {
|
.catch((x) => {
|
||||||
|
console.log(`Init failed: ${x}`);
|
||||||
|
try{
|
||||||
|
let localStorage = new LocalStorage();
|
||||||
|
app._options.globalData.TOTPS = JSON.parse(
|
||||||
|
localStorage.getItem("TOTPs", [])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch{
|
||||||
app._options.globalData.TOTPS = [];
|
app._options.globalData.TOTPS = [];
|
||||||
|
}
|
||||||
this.initPage();
|
this.initPage();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ function renderContainers(buffer) {
|
|||||||
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();
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import { createWidget, widget, align, text_style } from "@zos/ui";
|
|||||||
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 containerColor = 0x303030; //Color of container
|
||||||
const containerRadius = 20; //Corner radius of container
|
const containerRadius = 20; //Corner radius of container
|
||||||
|
|
||||||
|
|||||||
@@ -2,43 +2,73 @@ 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 = JSON.parse(
|
||||||
props.settingsStorage.getItem("TOTPs") ?? "[]"
|
props.settingsStorage.getItem("TOTPs") ?? "[]"
|
||||||
);
|
);
|
||||||
const totpEntrys = GetTOTPList(storage);
|
const totpEntrys = GetTOTPList(storage);
|
||||||
|
const addTOTPsHint = storage.length < 1 ?
|
||||||
|
Text({
|
||||||
|
paragraph: true,
|
||||||
|
align: "center",
|
||||||
|
style: {
|
||||||
|
paddingTop: "10px",
|
||||||
|
marginBottom: "10px",
|
||||||
|
color: colors.text,
|
||||||
|
fontSize: 16,
|
||||||
|
verticalAlign: "middle",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"For add a 2FA TOTP record you must have otpauth:// link or otpauth-migration:// link from Google Authenticator Migration QR-Code"
|
||||||
|
) : null;
|
||||||
const createButton = TextInput({
|
const createButton = TextInput({
|
||||||
placeholder: "otpauth://",
|
placeholder: "otpauth(-migration)://",
|
||||||
label: "Add new OTP Link",
|
label: "Add new TOTP record",
|
||||||
onChange: (changes) => {
|
onChange: (changes) => {
|
||||||
var link = getTOTPByLink(changes);
|
let link = getTOTPByLink(changes);
|
||||||
if (link == null) {
|
if (link == null) {
|
||||||
console.log("link is invalid");
|
console.log("link is invalid");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
storage.push(link);
|
|
||||||
|
if (Array.isArray(link))
|
||||||
|
storage.push(...link);
|
||||||
|
else storage.push(link);
|
||||||
|
|
||||||
updateStorage(storage);
|
updateStorage(storage);
|
||||||
},
|
},
|
||||||
labelStyle: {
|
labelStyle: {
|
||||||
backgroundColor: "#14213D",
|
backgroundColor: colors.notify,
|
||||||
display: "flex",
|
display: "flex",
|
||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
justifyContent: "center",
|
justifyContent: "center",
|
||||||
margin: "10px",
|
margin: "10px",
|
||||||
flexGrow: 1,
|
|
||||||
fontSize: "20px",
|
fontSize: "20px",
|
||||||
color: "#FFFFFF",
|
color: colors.text,
|
||||||
borderRadius: "5px",
|
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(
|
var body = Section(
|
||||||
{
|
{
|
||||||
style: {
|
style: {
|
||||||
backgroundColor: "black",
|
backgroundColor: colors.bg,
|
||||||
minHeight: "100vh",
|
minHeight: "100vh",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -49,22 +79,34 @@ AppSettingsPage({
|
|||||||
textAlign: "center",
|
textAlign: "center",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Text(
|
storage.length < 1 ? addTOTPsHint : Text(
|
||||||
{
|
{
|
||||||
align: "center",
|
align: "center",
|
||||||
paragraph: true,
|
paragraph: true,
|
||||||
style: {
|
style: {
|
||||||
marginBottom: "10px",
|
marginBottom: "10px",
|
||||||
color: "#fff",
|
color: colors.bigText,
|
||||||
fontSize: 23,
|
fontSize: 23,
|
||||||
|
fontWeight: "500",
|
||||||
verticalAlign: "middle",
|
verticalAlign: "middle",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"TOTPS:"
|
"TOTP records:"
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
...totpEntrys,
|
...totpEntrys,
|
||||||
createButton,
|
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;
|
return body;
|
||||||
@@ -77,18 +119,22 @@ function GetTOTPList(storage) {
|
|||||||
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);
|
||||||
|
if (Array.isArray(link))
|
||||||
|
return;
|
||||||
|
|
||||||
|
storage[elementId] = link;
|
||||||
updateStorage(storage);
|
updateStorage(storage);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
labelStyle: {
|
labelStyle: {
|
||||||
backgroundColor: "#14213D",
|
backgroundColor: colors.notify,
|
||||||
textAlign: "center",
|
textAlign: "center",
|
||||||
display: "flex",
|
display: "flex",
|
||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
@@ -96,7 +142,7 @@ function GetTOTPList(storage) {
|
|||||||
margin: "10px",
|
margin: "10px",
|
||||||
flexGrow: 1,
|
flexGrow: 1,
|
||||||
fontSize: "20px",
|
fontSize: "20px",
|
||||||
color: "#E5E5E5",
|
color: colors.text,
|
||||||
borderRadius: "5px",
|
borderRadius: "5px",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -104,8 +150,9 @@ function GetTOTPList(storage) {
|
|||||||
{
|
{
|
||||||
align: "center",
|
align: "center",
|
||||||
style: {
|
style: {
|
||||||
color: "#ffffff",
|
color: colors.text,
|
||||||
fontSize: "16px",
|
fontSize: "18px",
|
||||||
|
fontWeight: "500"
|
||||||
},
|
},
|
||||||
paragraph: true,
|
paragraph: true,
|
||||||
},
|
},
|
||||||
@@ -119,29 +166,30 @@ function GetTOTPList(storage) {
|
|||||||
updateStorage(storage);
|
updateStorage(storage);
|
||||||
},
|
},
|
||||||
style: {
|
style: {
|
||||||
backgroundColor: "#ba181b",
|
backgroundColor: colors.alert,
|
||||||
fontSize: "18px",
|
fontSize: "18px",
|
||||||
color: "#ffffff",
|
color: colors.text,
|
||||||
height: "fit-content",
|
height: "fit-content",
|
||||||
margin: "10px",
|
margin: "10px",
|
||||||
},
|
},
|
||||||
label: "DEL",
|
label: "Delete",
|
||||||
});
|
});
|
||||||
const text = Text(
|
const text = Text(
|
||||||
{
|
{
|
||||||
style: {
|
style: {
|
||||||
color: "#ffffff",
|
color: colors.text,
|
||||||
fontSize: "14px",
|
fontSize: "14px",
|
||||||
},
|
},
|
||||||
align: "center",
|
align: "center",
|
||||||
},
|
},
|
||||||
`${element.hashType} | ${element.digits} digits | ${element.fetchTime} seconds | offset ${element.timeOffset} seconds`
|
`${element.hashType} | ${element.digits} digits | ${element.fetchTime} seconds | ${element.timeOffset} sec offset`
|
||||||
);
|
);
|
||||||
const view = View(
|
const view = View(
|
||||||
{
|
{
|
||||||
style: {
|
style: {
|
||||||
textAlign: "center",
|
textAlign: "center",
|
||||||
border: "2px solid white",
|
backgroundColor: colors.secondaryBg,
|
||||||
|
//border: "2px solid white",
|
||||||
borderRadius: "5px",
|
borderRadius: "5px",
|
||||||
margin: "10px",
|
margin: "10px",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,41 +1,18 @@
|
|||||||
|
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")
|
|
||||||
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;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
function getHashType(algorithm) {
|
function getHashType(algorithm) {
|
||||||
if (algorithm == "SHA1") return "SHA-1";
|
if (algorithm == "SHA1") return "SHA-1";
|
||||||
@@ -43,3 +20,95 @@ function getHashType(algorithm) {
|
|||||||
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;
|
||||||
|
}
|
||||||