Skip to content

Commit 0f82943

Browse files
authored
Merge pull request #433 from Authenticator-Extension/algo+digits
Algorithim & digits support
2 parents 6bd906d + 8115026 commit 0f82943

File tree

13 files changed

+240
-92
lines changed

13 files changed

+240
-92
lines changed

_locales/en/messages.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,5 +321,11 @@
321321
},
322322
"invalid": {
323323
"message": "Invalid"
324+
},
325+
"digits": {
326+
"message": "Digits"
327+
},
328+
"algorithm": {
329+
"message": "Algorithm"
324330
}
325331
}

package-lock.json

Lines changed: 11 additions & 41 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
"@types/argon2-browser": "^1.6.0",
2424
"@types/chrome": "^0.0.86",
2525
"@types/crypto-js": "^3.1.43",
26-
"@types/jssha": "2.0.0",
2726
"@types/uuid": "^3.4.5",
2827
"base64-loader": "^1.0.0",
2928
"fork-ts-checker-webpack-plugin": "^1.3.5",
@@ -42,7 +41,6 @@
4241
"dependencies": {
4342
"argon2-browser": "^1.12.0",
4443
"crypto-js": "^3.1.9-1",
45-
"jssha": "^2.3.1",
4644
"qrcode-generator": "^1.4.3",
4745
"qrcode-reader": "^1.0.4",
4846
"uuid": "^3.3.3",

src/background.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,12 @@ async function getTotp(text: string) {
126126
if (!label || !parameterPart) {
127127
chrome.tabs.sendMessage(id, { action: "errorqr" });
128128
} else {
129-
let account = "";
130129
let secret = "";
131-
let issuer = "";
132-
let period: number | undefined = undefined;
130+
let account: string | undefined;
131+
let issuer: string | undefined;
132+
let algorithm: string | undefined;
133+
let period: number | undefined;
134+
let digits: number | undefined;
133135

134136
try {
135137
label = decodeURIComponent(label);
@@ -163,6 +165,11 @@ async function getTotp(text: string) {
163165
isNaN(period) || period < 0 || period > 60 || 60 % period !== 0
164166
? undefined
165167
: period;
168+
} else if (parameter[0].toLowerCase() === "digits") {
169+
digits = Number(parameter[1]);
170+
digits = isNaN(digits) || digits === 0 ? 6 : digits;
171+
} else if (parameter[0].toLowerCase() === "algorithm") {
172+
algorithm = parameter[1];
166173
}
167174
});
168175

@@ -203,6 +210,12 @@ async function getTotp(text: string) {
203210
if (period) {
204211
entryData[hash].period = period;
205212
}
213+
if (digits) {
214+
entryData[hash].digits = digits;
215+
}
216+
if (algorithm) {
217+
entryData[hash].algorithm = algorithm;
218+
}
206219
if (
207220
(await EntryStorage.hasEncryptedEntry()) !==
208221
encryption.getEncryptionStatus()

src/components/Popup/AddAccountPage.vue

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,19 @@
1616
v-model.number="newAccount.period"
1717
v-bind:disabled="newAccount.type === OTPType.hotp"
1818
/>
19+
<label class="combo-label">{{ i18n.digits }}</label>
20+
<select v-model="newAccount.digits">
21+
<option value="6">6</option>
22+
<option value="8">8</option>
23+
</select>
24+
<br />
25+
<label class="combo-label">{{ i18n.algorithm }}</label>
26+
<select v-model="newAccount.algorithm">
27+
<option v-bind:value="OTPAlgorithm.SHA1">SHA-1</option>
28+
<option v-bind:value="OTPAlgorithm.SHA256">SHA-256</option>
29+
<option v-bind:value="OTPAlgorithm.SHA512">SHA-512</option>
30+
</select>
31+
<br />
1932
<label class="combo-label">{{ i18n.type }}</label>
2033
<select v-model="newAccount.type">
2134
<option v-bind:value="OTPType.totp">{{ i18n.based_on_time }}</option>
@@ -30,7 +43,7 @@
3043
<script lang="ts">
3144
import Vue from "vue";
3245
import { mapState } from "vuex";
33-
import { OTPType, OTPEntry } from "../../models/otp";
46+
import { OTPType, OTPEntry, OTPAlgorithm } from "../../models/otp";
3447
3548
export default Vue.extend({
3649
data: function(): {
@@ -40,6 +53,8 @@ export default Vue.extend({
4053
secret: string;
4154
type: OTPType;
4255
period: number | undefined;
56+
digits: number;
57+
algorithm: OTPAlgorithm;
4358
};
4459
} {
4560
return {
@@ -48,11 +63,13 @@ export default Vue.extend({
4863
account: "",
4964
secret: "",
5065
type: OTPType.totp,
51-
period: undefined
66+
period: undefined,
67+
digits: 6,
68+
algorithm: OTPAlgorithm.SHA1
5269
}
5370
};
5471
},
55-
computed: mapState("accounts", ["OTPType"]),
72+
computed: mapState("accounts", ["OTPType", "OTPAlgorithm"]),
5673
methods: {
5774
async addNewAccount() {
5875
this.newAccount.secret = this.newAccount.secret.replace(/ /g, "");
@@ -104,7 +121,9 @@ export default Vue.extend({
104121
encrypted: false,
105122
secret: this.newAccount.secret,
106123
counter: 0,
107-
period: this.newAccount.period
124+
period: this.newAccount.period,
125+
digits: this.newAccount.digits,
126+
algorithm: this.newAccount.algorithm
108127
},
109128
this.$store.state.accounts.encryption
110129
);

src/components/Popup/EntryComponent.vue

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
import Vue from "vue";
7272
import { mapState } from "vuex";
7373
import * as QRGen from "qrcode-generator";
74-
import { OTPEntry, OTPType, CodeState } from "../../models/otp";
74+
import { OTPEntry, OTPType, CodeState, OTPAlgorithm } from "../../models/otp";
7575
7676
import IconMinusCircle from "../../../svg/minus-circle.svg";
7777
import IconRedo from "../../../svg/redo.svg";
@@ -248,8 +248,12 @@ function getQrUrl(entry: OTPEntry) {
248248
(entry.type === OTPType.hotp || entry.type === OTPType.hhex
249249
? "&counter=" + entry.counter
250250
: "") +
251-
(entry.type === OTPType.totp && entry.period
251+
(entry.type === OTPType.totp && entry.period !== 30
252252
? "&period=" + entry.period
253+
: "") +
254+
(entry.digits !== 6 ? "&digits=" + entry.digits : "") +
255+
(entry.algorithm !== OTPAlgorithm.SHA1
256+
? "&algorithm=" + OTPAlgorithm[entry.algorithm]
253257
: "");
254258
const qr = QRGen(0, "L");
255259
qr.addData(otpauth);

src/components/Popup/ExportPage.vue

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,15 @@ function getOneLineOtpBackupFile(entryData: { [hash: string]: OTPStorage }) {
9999
const otpAuthLines: string[] = [];
100100
for (const hash of Object.keys(entryData)) {
101101
const otpStorage = entryData[hash];
102-
otpStorage.issuer = removeUnsafeData(otpStorage.issuer);
103-
otpStorage.account = removeUnsafeData(otpStorage.account);
102+
if (otpStorage.issuer) {
103+
otpStorage.issuer = removeUnsafeData(otpStorage.issuer);
104+
}
105+
if (otpStorage.account) {
106+
otpStorage.account = removeUnsafeData(otpStorage.account);
107+
}
104108
const label = otpStorage.issuer
105-
? otpStorage.issuer + ":" + otpStorage.account
106-
: otpStorage.account;
109+
? otpStorage.issuer + ":" + (otpStorage.account || "")
110+
: otpStorage.account || "";
107111
let type = "";
108112
if (otpStorage.type === "totp" || otpStorage.type === "hex") {
109113
type = "totp";
@@ -124,7 +128,9 @@ function getOneLineOtpBackupFile(entryData: { [hash: string]: OTPStorage }) {
124128
(type === "hotp" ? "&counter=" + otpStorage.counter : "") +
125129
(type === "totp" && otpStorage.period
126130
? "&period=" + otpStorage.period
127-
: "");
131+
: "") +
132+
(otpStorage.digits ? "&digits=" + otpStorage.digits : "") +
133+
(otpStorage.algorithm ? "&algorithm=" + otpStorage.algorithm : "");
128134
129135
otpAuthLines.push(otpAuthLine);
130136
}

0 commit comments

Comments
 (0)