Skip to content

Commit b9511ba

Browse files
authored
More policies (#385)
More policies
2 parents 8a0de27 + 5738d47 commit b9511ba

File tree

8 files changed

+132
-56
lines changed

8 files changed

+132
-56
lines changed

schema-chrome.json

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,40 @@
11
{
22
"type": "object",
3-
43
"properties": {
54
"disableInstallHelp": {
65
"title": "Disable opening help page on install",
7-
"description": "If set to true then help page will not be opened on install.",
6+
"description": "If set to true, then help page will not be opened on install.",
87
"type": "boolean"
98
},
10-
119
"disableBackup": {
12-
"title": "Disable 3rd party backup",
13-
"description": "If set to true then 3rd party backup options will be hidden. If 3rd party backup is already configured for a user this will not stop it.",
14-
"type": "boolean"
10+
"title": "Disable 3rd party backup",
11+
"description": "If set to true, then 3rd party backup options will be hidden. If 3rd party backup is already configured for a user this will not stop it.",
12+
"type": "boolean"
13+
},
14+
"disableExport": {
15+
"title": "Disable import / export menu",
16+
"description": "If set to true, then export buttons will be hidden.",
17+
"type": "boolean"
1518
},
16-
1719
"storageArea": {
18-
"title": "Storage area",
19-
"description": "Set to 'sync' or 'local'. If set will force user to use specified storage area. This setting will not check if a user is currently using another storage space and may hide data.",
20-
"type": "string"
20+
"title": "Storage area",
21+
"description": "Set to 'sync' or 'local'. If set will force user to use specified storage area. This setting will not check if a user is currently using another storage space and may hide data.",
22+
"type": "string"
2123
},
22-
2324
"feedbackURL": {
2425
"title": "Feedback URL",
2526
"description": "Change the URL the feedback button opens.",
2627
"type": "string"
28+
},
29+
"enforcePassword": {
30+
"title": "Enforce password",
31+
"description": "If set to true, then user will be prompted to set a password before adding an account (if none set) and the remove password button will be hidden.",
32+
"type": "boolean"
33+
},
34+
"enforceAutolock": {
35+
"title": "Enforce autolock",
36+
"description": "If any value is set, then the user will not be able to change the autolock setting. Set to a number in minutes.",
37+
"type": "number"
2738
}
2839
}
2940
}

src/background.ts

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
2525
message.info.windowWidth
2626
);
2727
} else if (message.action === "cachePassphrase") {
28-
document.cookie = `passphrase="${message.value}${getCookieExpiry()}"`;
2928
cachedPassphrase = message.value;
3029
clearTimeout(autolockTimeout);
3130
setAutolock();
@@ -412,9 +411,25 @@ chrome.commands.onCommand.addListener(async (command: string) => {
412411
}
413412
});
414413

415-
function setAutolock() {
414+
async function setAutolock() {
415+
const enforcedAutolock = Number(await ManagedStorage.get("enforceAutolock"));
416+
417+
if (enforcedAutolock) {
418+
if (enforcedAutolock > 0) {
419+
document.cookie = `passphrase="${getCachedPassphrase()}${getCookieExpiry(
420+
enforcedAutolock
421+
)}"`;
422+
autolockTimeout = setTimeout(() => {
423+
cachedPassphrase = "";
424+
}, enforcedAutolock * 60000);
425+
return;
426+
}
427+
}
428+
416429
if (Number(localStorage.autolock) > 0) {
417-
document.cookie = `passphrase="${getCachedPassphrase()}${getCookieExpiry()}"`;
430+
document.cookie = `passphrase="${getCachedPassphrase()}${getCookieExpiry(
431+
Number(localStorage.autolock)
432+
)}"`;
418433
autolockTimeout = setTimeout(() => {
419434
cachedPassphrase = "";
420435
const id = contentTab.id;
@@ -425,16 +440,12 @@ function setAutolock() {
425440
}
426441
}
427442

428-
function getCookieExpiry() {
429-
if (localStorage.autolock && Number(localStorage.autolock) > 0) {
430-
const offset = Number(localStorage.autolock) * 60000;
431-
const now = new Date().getTime();
432-
const autolockExpiry = new Date(now + offset).toUTCString();
443+
function getCookieExpiry(time: number) {
444+
const offset = time * 60000;
445+
const now = new Date().getTime();
446+
const autolockExpiry = new Date(now + offset).toUTCString();
433447

434-
return `;expires=${autolockExpiry}`;
435-
} else {
436-
return "";
437-
}
448+
return `;expires=${autolockExpiry}`;
438449
}
439450

440451
function getCachedPassphrase() {

src/components/Popup/ExportPage.vue

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,37 @@
11
<template>
22
<div>
3-
<div class="text warning" v-if="!encryption.getEncryptionStatus()">
4-
{{ i18n.export_info }}
3+
<div v-show="!exportDisabled">
4+
<div class="text warning" v-if="!encryption.getEncryptionStatus()">
5+
{{ i18n.export_info }}
6+
</div>
7+
<div class="text warning" v-if="unsupportedAccounts">
8+
{{ i18n.otp_unsupported_warn }}
9+
</div>
10+
<a
11+
download="authenticator.txt"
12+
v-bind:href="exportOneLineOtpAuthFile"
13+
v-if="!unsupportedAccounts"
14+
class="button"
15+
target="_blank"
16+
>{{ i18n.download_backup }}</a
17+
>
18+
<a
19+
download="authenticator.json"
20+
v-bind:href="exportFile"
21+
class="button"
22+
target="_blank"
23+
v-else
24+
>{{ i18n.download_backup }}</a
25+
>
26+
<a
27+
download="authenticator.json"
28+
v-bind:href="exportEncryptedFile"
29+
v-if="encryption.getEncryptionStatus()"
30+
class="button"
31+
target="_blank"
32+
>{{ i18n.download_enc_backup }}</a
33+
>
534
</div>
6-
<div class="text warning" v-if="unsupportedAccounts">
7-
{{ i18n.otp_unsupported_warn }}
8-
</div>
9-
<a
10-
download="authenticator.txt"
11-
v-bind:href="exportOneLineOtpAuthFile"
12-
v-if="!unsupportedAccounts"
13-
class="button"
14-
target="_blank"
15-
>{{ i18n.download_backup }}</a
16-
>
17-
<a
18-
download="authenticator.json"
19-
v-bind:href="exportFile"
20-
class="button"
21-
target="_blank"
22-
v-else
23-
>{{ i18n.download_backup }}</a
24-
>
25-
<a
26-
download="authenticator.json"
27-
v-bind:href="exportEncryptedFile"
28-
v-if="encryption.getEncryptionStatus()"
29-
class="button"
30-
target="_blank"
31-
>{{ i18n.download_enc_backup }}</a
32-
>
3335
<a class="button" href="import.html" target="_blank">{{
3436
i18n.import_backup
3537
}}</a>
@@ -57,6 +59,9 @@ export default Vue.extend({
5759
computed: {
5860
encryption: function() {
5961
return this.$store.state.accounts.encryption;
62+
},
63+
exportDisabled: function() {
64+
return this.$store.state.menu.exportDisabled;
6065
}
6166
}
6267
});

src/components/Popup/MainBody.vue

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ export default Vue.extend({
6060
computed,
6161
methods: {
6262
showInfo(page: string) {
63+
if (page === "AddMethodPage") {
64+
if (
65+
this.$store.state.menu.enforcePassword &&
66+
!this.$store.state.accounts.encryption.getEncryptionStatus()
67+
) {
68+
page = "SetPasswordPage";
69+
}
70+
}
71+
6372
this.$store.commit("style/showInfo");
6473
this.$store.commit("currentView/changeView", page);
6574
},

src/components/Popup/MainHeader.vue

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,14 @@ export default Vue.extend({
104104
return;
105105
},
106106
async beginCapture() {
107+
if (
108+
this.$store.state.menu.enforcePassword &&
109+
!this.$store.state.accounts.encryption.getEncryptionStatus()
110+
) {
111+
this.$store.commit("style/showInfo");
112+
this.$store.commit("currentView/changeView", "SetPasswordPage");
113+
return;
114+
}
107115
// Insert content script
108116
await new Promise(
109117
(resolve: () => void, reject: (reason: Error) => void) => {

src/components/Popup/PrefrencesPage.vue

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
min="0"
3333
style="width: 70px;"
3434
v-model="autolock"
35+
:disabled="Boolean(enforceAutolock)"
3536
/>
3637
<span style="margin-top: 10px;">{{ i18n.minutes }}</span>
3738
</div>
@@ -70,9 +71,16 @@ export default Vue.extend({
7071
encryption(): IEncryption {
7172
return this.$store.state.accounts.encryption;
7273
},
74+
enforceAutolock() {
75+
return this.$store.state.menu.enforceAutolock;
76+
},
7377
autolock: {
7478
get(): number {
75-
return this.$store.state.menu.autolock;
79+
if (this.$store.state.menu.enforceAutolock) {
80+
return this.$store.state.menu.enforceAutolock;
81+
} else {
82+
return this.$store.state.menu.autolock;
83+
}
7684
},
7785
set(autolock: number) {
7886
this.$store.commit("menu/setAutolock", autolock);

src/components/Popup/SetPasswordPage.vue

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,20 @@
1010
v-model="confirm"
1111
v-on:keyup.enter="changePassphrase()"
1212
/>
13-
<div id="security-save" v-on:click="changePassphrase()">{{ i18n.ok }}</div>
14-
<div id="security-remove" v-on:click="removePassphrase()">
15-
{{ i18n.remove }}
13+
<div v-show="!enforcePassword">
14+
<div id="security-save" v-on:click="changePassphrase()">
15+
{{ i18n.ok }}
16+
</div>
17+
<div id="security-remove" v-on:click="removePassphrase()">
18+
{{ i18n.remove }}
19+
</div>
20+
</div>
21+
<div
22+
class="button-small"
23+
v-show="enforcePassword"
24+
v-on:click="changePassphrase()"
25+
>
26+
{{ i18n.ok }}
1627
</div>
1728
</div>
1829
</template>
@@ -26,20 +37,30 @@ export default Vue.extend({
2637
confirm: ""
2738
};
2839
},
40+
computed: {
41+
enforcePassword: function() {
42+
return this.$store.state.menu.enforcePassword;
43+
}
44+
},
2945
methods: {
3046
async removePassphrase() {
3147
await this.$store.dispatch("accounts/changePassphrase", "");
3248
this.$store.commit("notification/alert", this.i18n.updateSuccess);
3349
return;
3450
},
3551
async changePassphrase() {
52+
if (this.phrase === "") {
53+
return;
54+
}
55+
3656
if (this.phrase !== this.confirm) {
3757
this.$store.commit("notification/alert", this.i18n.phrase_not_match);
3858
return;
3959
}
4060
4161
await this.$store.dispatch("accounts/changePassphrase", this.phrase);
4262
this.$store.commit("notification/alert", this.i18n.updateSuccess);
63+
this.$store.commit("style/hideInfo");
4364
return;
4465
}
4566
}

src/store/Menu.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ export class Menu implements IModule {
1010
useHighContrast: localStorage.highContrast === "true",
1111
autolock: Number(localStorage.autolock) || 0,
1212
backupDisabled: await ManagedStorage.get("disableBackup"),
13+
exportDisabled: await ManagedStorage.get("disableExport"),
14+
enforcePassword: await ManagedStorage.get("enforcePassword"),
15+
enforceAutolock: await ManagedStorage.get("enforceAutolock"),
1316
storageArea: await ManagedStorage.get("storageArea"),
1417
feedbackURL: await ManagedStorage.get("feedbackURL")
1518
},

0 commit comments

Comments
 (0)