Skip to content

Commit

Permalink
fix otp type for export
Browse files Browse the repository at this point in the history
  • Loading branch information
Sneezry committed Sep 11, 2024
1 parent cfd775f commit 29b2b95
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 19 deletions.
19 changes: 3 additions & 16 deletions src/components/Popup/BackupPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
<script lang="ts">
import Vue from "vue";
import { isSafari } from "../../browser";
import { OTPType } from "../../models/otp";
export default Vue.extend({
data: function () {
Expand Down Expand Up @@ -212,25 +213,11 @@ function getOneLineOtpBackupFile(entryData: { [hash: string]: RawOTPStorage }) {
? otpStorage.issuer + ":" + (otpStorage.account || "")
: otpStorage.account || "";
let type = "";
// We may have already have some error OTP type entries in the storage
// totp = 1
// hotp = 2
// battle = 3
// steam = 4
// hex = 5
// hhex = 6
if (
otpStorage.type === OTPType.totp ||
otpStorage.type === OTPType.hex ||
(otpStorage.type as unknown) === 1 ||
(otpStorage.type as unknown) === 5
) {
if (otpStorage.type === OTPType.totp || otpStorage.type === OTPType.hex) {
type = OTPType.totp;
} else if (
otpStorage.type === OTPType.hotp ||
otpStorage.type === OTPType.hhex ||
(otpStorage.type as unknown) === 2 ||
(otpStorage.type as unknown) === 6
otpStorage.type === OTPType.hhex
) {
type = OTPType.hotp;
} else {
Expand Down
49 changes: 48 additions & 1 deletion src/models/otp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,30 @@ export class OTPEntry implements OTPEntryInterface {
this.secret = entry.secret;
}

this.type = entry.type;
// We may have already had some error OTP type entries in the storage
// totp = 1
// hotp = 2
// battle = 3
// steam = 4
// hex = 5
// hhex = 6

if ((entry.type as unknown) === 1) {
this.type = OTPType.totp;
} else if ((entry.type as unknown) === 2) {
this.type = OTPType.hotp;
} else if ((entry.type as unknown) === 3) {
this.type = OTPType.battle;
} else if ((entry.type as unknown) === 4) {
this.type = OTPType.steam;
} else if ((entry.type as unknown) === 5) {
this.type = OTPType.hex;
} else if ((entry.type as unknown) === 6) {
this.type = OTPType.hhex;
} else {
this.type = entry.type;
}

if (entry.issuer) {
this.issuer = entry.issuer;
} else {
Expand Down Expand Up @@ -225,6 +248,30 @@ export class OTPEntry implements OTPEntryInterface {
this.secret = decryptedData.secret;
this.type = decryptedData.type || OTPType.totp;

// We may have already had some error OTP type entries in the storage
// totp = 1
// hotp = 2
// battle = 3
// steam = 4
// hex = 5
// hhex = 6

if ((decryptedData.type as unknown) === 1) {
this.type = OTPType.totp;
} else if ((decryptedData.type as unknown) === 2) {
this.type = OTPType.hotp;
} else if ((decryptedData.type as unknown) === 3) {
this.type = OTPType.battle;
} else if ((decryptedData.type as unknown) === 4) {
this.type = OTPType.steam;
} else if ((decryptedData.type as unknown) === 5) {
this.type = OTPType.hex;
} else if ((decryptedData.type as unknown) === 6) {
this.type = OTPType.hhex;
} else {
this.type = OTPType.totp;
}

if (this.type !== OTPType.hotp && this.type !== OTPType.hhex) {
this.generate();
}
Expand Down
28 changes: 26 additions & 2 deletions src/models/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -630,8 +630,32 @@ export class EntryStorage {
default:
// we need correct the type here
// and save it
type = OTPType.totp;
entryData.type = OTPType.totp;

// We may have already had some error OTP type entries in the storage
// totp = 1
// hotp = 2
// battle = 3
// steam = 4
// hex = 5
// hhex = 6

if ((entryData.type as unknown) === 1) {
type = OTPType.totp;
} else if ((entryData.type as unknown) === 2) {
type = OTPType.hotp;
} else if ((entryData.type as unknown) === 3) {
type = OTPType.battle;
} else if ((entryData.type as unknown) === 4) {
type = OTPType.steam;
} else if ((entryData.type as unknown) === 5) {
type = OTPType.hex;
} else if ((entryData.type as unknown) === 6) {
type = OTPType.hhex;
} else {
type = OTPType.totp;
}

entryData.type = type;
}

let period: number | undefined;
Expand Down

0 comments on commit 29b2b95

Please sign in to comment.