forked from akopachov/flipper-zero_authenticator-companion
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented akopachov#33 (akopachov#34)
- Loading branch information
Showing
13 changed files
with
210 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.