Skip to content

Commit

Permalink
Implemented akopachov#33 (akopachov#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
akopachov authored Nov 14, 2023
1 parent 0f01ab0 commit 653e559
Show file tree
Hide file tree
Showing 13 changed files with 210 additions and 54 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
"@types/semver": "^7.5.5",
"@types/uuid": "^9.0.7",
"@types/w3c-image-capture": "^1.0.10",
"@typescript-eslint/eslint-plugin": "^6.10.0",
"@typescript-eslint/parser": "^6.10.0",
"@typescript-eslint/eslint-plugin": "^6.11.0",
"@typescript-eslint/parser": "^6.11.0",
"async-sema": "^3.1.1",
"autoprefixer": "^10.4.16",
"concurrently": "^8.2.2",
Expand Down
92 changes: 46 additions & 46 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion src/app.postcss
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,9 @@
@tailwind utilities;
@tailwind variants;

html, body { @apply h-full overflow-hidden; }
html, body { @apply h-full overflow-hidden; }

a[target="_blank"]:after {
@apply inline-block ml-1 w-4 h-4 align-baseline;
content: url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGZpbGw9Im5vbmUiIHZpZXdCb3g9IjAgMCAyNCAyNCIgc3Ryb2tlLXdpZHRoPSIxLjUiIHN0cm9rZT0iY3VycmVudENvbG9yIj4NCiAgPHBhdGggc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIiBkPSJNMTMuNSA2SDUuMjVBMi4yNSAyLjI1IDAgMDAzIDguMjV2MTAuNUEyLjI1IDIuMjUgMCAwMDUuMjUgMjFoMTAuNUEyLjI1IDIuMjUgMCAwMDE4IDE4Ljc1VjEwLjVtLTEwLjUgNkwyMSAzbTAgMGgtNS4yNU0yMSAzdjUuMjUiIC8+DQo8L3N2Zz4NCg==');
}
13 changes: 12 additions & 1 deletion src/electron.cjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
const windowStateManager = require('electron-window-state');
const { app, BrowserWindow, desktopCapturer, nativeTheme } = require('electron');
const { app, BrowserWindow, desktopCapturer, nativeTheme, shell } = require('electron');
const serve = require('electron-serve');
const path = require('path');
const Store = require('electron-store');
const log = require('electron-log');
const { autoUpdater } = require('electron-updater');
const { MainMessageHub } = require('simple-electron-ipc');

const ExternalLinkSchemaSuffix = 'external-';

try {
require('electron-reloader')(module);
} catch (e) {
Expand Down Expand Up @@ -67,6 +69,15 @@ function createWindow() {
}
});

mainWindow.webContents.setWindowOpenHandler(({ url }) => {
if (url.startsWith(ExternalLinkSchemaSuffix)) {
shell.openExternal(url.substring(ExternalLinkSchemaSuffix.length));
return { action: 'deny' };
}

return { action: 'allow' };
});

return mainWindow;
}

Expand Down
49 changes: 49 additions & 0 deletions src/lib/import/bitwarden.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import log from 'electron-log';
import { DefaultTokenCounter, DefaultTokenDuration, TokenInfo } from '$models/token-info';
import { parse } from '$lib/url-otpauth-ts/parse';
import { tokenLengthFromNumber } from '$models/token-length';
import { tokenTypeFromString } from '$models/token-type';
import { tokenHashingAlgoFromString } from '$models/token-hashing-algo';

function formatAccountName(
issuer: string | null | undefined,
account: string | null | undefined,
entryName: string | null | undefined,
) {
if (issuer && account) return `${issuer} (${account})`;
return account || issuer || entryName || '';
}

export function importFromBitwarden(data: any) {
const entries = data?.items;
if (entries === null || !Array.isArray(entries)) {
throw Error('Invalid import data file');
}

const results: TokenInfo[] = [];

for (const entry of entries) {
const totpUri = entry.login?.totp;
if (!totpUri) {
continue;
}
try {
const parsedTotpUri = parse(totpUri);
results.push(
new TokenInfo({
type: tokenTypeFromString(parsedTotpUri.type),
name: formatAccountName(parsedTotpUri.issuer, parsedTotpUri.account, entry.name),
length: tokenLengthFromNumber(parsedTotpUri.digits),
secret: parsedTotpUri.key,
duration: parsedTotpUri.period || DefaultTokenDuration,
counter: parsedTotpUri.counter || DefaultTokenCounter,
hashingAlgo: tokenHashingAlgoFromString(parsedTotpUri.algorithm),
}),
);
} catch {
log.warn(`An error occurred during parsing totp uri for item #${entry.id}`);
}
}

return results;
}
1 change: 1 addition & 0 deletions src/lib/import/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export * from './aegis-auth';
export * from './freeotpplus-auth';
export * from './2fas-auth';
export * from './uri-list';
export * from './bitwarden';
6 changes: 6 additions & 0 deletions src/routes/import/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@
<span>2FAS Authenticator</span>
</a>
</li>
<li>
<a href="/import/bitwarden" class="!rounded-xl !p-2">
<Avatar src="/authenticator-icons/bitwarden.png" width="w-12" rounded="rounded-xl" />
<span>Bitwarden</span>
</a>
</li>
<li>
<a href="/import/uri-list" class="!rounded-xl !p-2">
<div class="w-12 h-12 rounded-xl bg-white flex justify-center items-center">
Expand Down
2 changes: 1 addition & 1 deletion src/routes/import/2fas/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
const serializedParsedTokens = dataToQueryString(parsedTokens);
await goto(`/import/confirm?data=${serializedParsedTokens}`);
} else {
GlobalCommonToast.show('No tokens found', CommonToastType.Warning);
GlobalCommonToast.show('No valid tokens found', CommonToastType.Warning);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/routes/import/aegis/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
const serializedParsedTokens = dataToQueryString(parsedTokens);
await goto(`/import/confirm?data=${serializedParsedTokens}`);
} else {
GlobalCommonToast.show('No tokens found', CommonToastType.Warning);
GlobalCommonToast.show('No valid tokens found', CommonToastType.Warning);
}
}
}
Expand Down
Loading

0 comments on commit 653e559

Please sign in to comment.