Skip to content

Commit 8a2613f

Browse files
author
Corentin Mors
authored
Fix otpauth parsing issue (#301)
Fix #299
1 parent b84d24b commit 8a2613f

File tree

5 files changed

+14
-8
lines changed

5 files changed

+14
-8
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@dashlane/cli",
3-
"version": "6.2447.1",
3+
"version": "6.2447.2",
44
"description": "Manage your Dashlane vault through a CLI tool",
55
"type": "module",
66
"main": "dist/index.cjs",

src/cliVersion.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { CliVersion } from './types.js';
22

3-
export const CLI_VERSION: CliVersion = { major: 6, minor: 2447, patch: 1 };
3+
export const CLI_VERSION: CliVersion = { major: 6, minor: 2447, patch: 2 };
44
export const breakingChangesVersions: CliVersion[] = [];
55

66
export const cliVersionToString = (version: CliVersion): string => {

src/command-handlers/passwords.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export const runPassword = async (
4848
result = selectedCredential.password;
4949
break;
5050
case 'otp':
51-
if (!selectedCredential.otpSecret || !selectedCredential.otpUrl) {
51+
if (!selectedCredential.otpSecret && !selectedCredential.otpUrl) {
5252
throw new Error('No OTP found for this credential.');
5353
}
5454
if (selectedCredential.otpSecret) {

src/index.ts

+3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
#!/usr/bin/env node
22
import { Command } from 'commander';
3+
import process from 'process';
34

45
import { cliVersionToString, CLI_VERSION } from './cliVersion.js';
56
import { rootCommands } from './commands/index.js';
67
import { initDeviceCredentials, initStagingCheck, initTeamDeviceCredentials } from './utils/index.js';
78
import { errorColor, initLogger } from './logger.js';
89

10+
process.removeAllListeners('warning');
11+
912
const debugLevel = process.argv.indexOf('--debug') !== -1 ? 'debug' : 'info';
1013

1114
initLogger({ debugLevel });

src/modules/crypto/otpauth.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ interface Otpauth {
1313
secret: string;
1414
algorithm: HashAlgorithms;
1515
digits: number;
16-
period: number;
17-
counter: number;
16+
period?: number;
17+
counter?: number;
1818
}
1919

2020
const matchAlgorithm = (algorithm: string): HashAlgorithms => {
@@ -40,9 +40,9 @@ const parseOtpauth = (uri: string): Otpauth => {
4040
issuer: searchParams.get('issuer') ?? '',
4141
secret: searchParams.get('secret') ?? '',
4242
algorithm: matchAlgorithm(searchParams.get('algorithm') ?? 'SHA1'),
43-
digits: Number(searchParams.get('digits') ?? 0),
44-
period: Number(searchParams.get('period') ?? 0),
45-
counter: Number(searchParams.get('counter') ?? 0),
43+
digits: Number(searchParams.get('digits') ?? 6),
44+
period: Number(searchParams.get('period')),
45+
counter: Number(searchParams.get('counter')),
4646
};
4747
};
4848

@@ -66,6 +66,9 @@ export const generateOtpFromUri = (uri: string): GenerateOtpOutput => {
6666
};
6767
return { token: authenticator.generate(otpauth.secret), remainingTime: authenticator.timeRemaining() };
6868
case 'hotp':
69+
if (otpauth.counter === undefined) {
70+
throw new Error('Counter is required for HOTP');
71+
}
6972
hotp.options = { algorithm: otpauth.algorithm, digits: otpauth.digits };
7073
return { token: hotp.generate(otpauth.secret, otpauth.counter), remainingTime: null };
7174
default:

0 commit comments

Comments
 (0)