From f8b2ba50c6bf86213c87da827b6d588443b28954 Mon Sep 17 00:00:00 2001 From: Brendan Early Date: Fri, 30 Aug 2019 16:59:00 -0500 Subject: [PATCH 1/5] add settings to schema --- schema-chrome.json | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/schema-chrome.json b/schema-chrome.json index f852f93ae..a7a720a67 100644 --- a/schema-chrome.json +++ b/schema-chrome.json @@ -1,29 +1,45 @@ { "type": "object", - "properties": { "disableInstallHelp": { "title": "Disable opening help page on install", - "description": "If set to true then help page will not be opened on install.", + "description": "If set to true, then help page will not be opened on install.", "type": "boolean" }, - "disableBackup": { - "title": "Disable 3rd party backup", - "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.", - "type": "boolean" + "title": "Disable 3rd party backup", + "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.", + "type": "boolean" + }, + "disableExportImport": { + "title": "Disable import / export menu", + "description": "If set to true, then 'Export / Import' menu will be hidden.", + "type": "boolean" + }, + "disablePasswordCaching": { + "title": "Disable password caching", + "description": "If set to true, then Authenticator will never cache encryption password in the background. Normally the password is stored for as long as the browser is open, this will make Authenticator prompt for password on every open. WARNING: This will break everything that changes data with background services (E.g.: QR scanning and import page).", + "type": "boolean" }, - "storageArea": { - "title": "Storage area", - "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.", - "type": "string" + "title": "Storage area", + "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.", + "type": "string" }, - "feedbackURL": { "title": "Feedback URL", "description": "Change the URL the feedback button opens.", "type": "string" + }, + "enforcePassword": { + "title": "Enforce password", + "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.", + "type": "boolean" + }, + "enforceAutolock": { + "title": "Enforce autolock", + "description": "If any value is set, then the user will not be able to change the autolock setting. Set to a number in minutes.", + "type": "number" } } } From 6a3ee5e89a06009dbcf3184010632d4d64dad6cd Mon Sep 17 00:00:00 2001 From: Brendan Early Date: Fri, 30 Aug 2019 17:06:56 -0500 Subject: [PATCH 2/5] disableExport --- schema-chrome.json | 4 +- src/components/Popup/ExportPage.vue | 63 ++++++++++++++++------------- src/store/Menu.ts | 1 + 3 files changed, 37 insertions(+), 31 deletions(-) diff --git a/schema-chrome.json b/schema-chrome.json index a7a720a67..274716d96 100644 --- a/schema-chrome.json +++ b/schema-chrome.json @@ -11,9 +11,9 @@ "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.", "type": "boolean" }, - "disableExportImport": { + "disableExport": { "title": "Disable import / export menu", - "description": "If set to true, then 'Export / Import' menu will be hidden.", + "description": "If set to true, then export buttons will be hidden.", "type": "boolean" }, "disablePasswordCaching": { diff --git a/src/components/Popup/ExportPage.vue b/src/components/Popup/ExportPage.vue index c8cfe29df..06da2c1e5 100644 --- a/src/components/Popup/ExportPage.vue +++ b/src/components/Popup/ExportPage.vue @@ -1,35 +1,37 @@ @@ -26,6 +37,11 @@ export default Vue.extend({ confirm: "" }; }, + computed: { + enforcePassword: function() { + return this.$store.state.menu.enforcePassword; + } + }, methods: { async removePassphrase() { await this.$store.dispatch("accounts/changePassphrase", ""); diff --git a/src/store/Menu.ts b/src/store/Menu.ts index 7969c72cc..7e5b04938 100644 --- a/src/store/Menu.ts +++ b/src/store/Menu.ts @@ -11,6 +11,8 @@ export class Menu implements IModule { autolock: Number(localStorage.autolock) || 0, backupDisabled: await ManagedStorage.get("disableBackup"), exportDisabled: await ManagedStorage.get("disableExport"), + enforcePassword: await ManagedStorage.get("enforcePassword"), + enforceAutolock: await ManagedStorage.get("enforceAutolock"), storageArea: await ManagedStorage.get("storageArea"), feedbackURL: await ManagedStorage.get("feedbackURL") }, From 5738d470083090713fe90418e89886d696abd9a8 Mon Sep 17 00:00:00 2001 From: Brendan Early Date: Fri, 30 Aug 2019 17:59:53 -0500 Subject: [PATCH 5/5] enforceAutolock --- src/background.ts | 35 ++++++++++++++++--------- src/components/Popup/PrefrencesPage.vue | 10 ++++++- 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/src/background.ts b/src/background.ts index 80da5e8be..e5cfa2087 100644 --- a/src/background.ts +++ b/src/background.ts @@ -25,7 +25,6 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => { message.info.windowWidth ); } else if (message.action === "cachePassphrase") { - document.cookie = `passphrase="${message.value}${getCookieExpiry()}"`; cachedPassphrase = message.value; clearTimeout(autolockTimeout); setAutolock(); @@ -405,25 +404,37 @@ chrome.commands.onCommand.addListener(async (command: string) => { } }); -function setAutolock() { +async function setAutolock() { + const enforcedAutolock = Number(await ManagedStorage.get("enforceAutolock")); + + if (enforcedAutolock) { + if (enforcedAutolock > 0) { + document.cookie = `passphrase="${getCachedPassphrase()}${getCookieExpiry( + enforcedAutolock + )}"`; + autolockTimeout = setTimeout(() => { + cachedPassphrase = ""; + }, enforcedAutolock * 60000); + return; + } + } + if (Number(localStorage.autolock) > 0) { - document.cookie = `passphrase="${getCachedPassphrase()}${getCookieExpiry()}"`; + document.cookie = `passphrase="${getCachedPassphrase()}${getCookieExpiry( + Number(localStorage.autolock) + )}"`; autolockTimeout = setTimeout(() => { cachedPassphrase = ""; }, Number(localStorage.autolock) * 60000); } } -function getCookieExpiry() { - if (localStorage.autolock && Number(localStorage.autolock) > 0) { - const offset = Number(localStorage.autolock) * 60000; - const now = new Date().getTime(); - const autolockExpiry = new Date(now + offset).toUTCString(); +function getCookieExpiry(time: number) { + const offset = time * 60000; + const now = new Date().getTime(); + const autolockExpiry = new Date(now + offset).toUTCString(); - return `;expires=${autolockExpiry}`; - } else { - return ""; - } + return `;expires=${autolockExpiry}`; } function getCachedPassphrase() { diff --git a/src/components/Popup/PrefrencesPage.vue b/src/components/Popup/PrefrencesPage.vue index 250c34814..71153c3d5 100644 --- a/src/components/Popup/PrefrencesPage.vue +++ b/src/components/Popup/PrefrencesPage.vue @@ -32,6 +32,7 @@ min="0" style="width: 70px;" v-model="autolock" + :disabled="Boolean(enforceAutolock)" /> {{ i18n.minutes }} @@ -70,9 +71,16 @@ export default Vue.extend({ encryption(): IEncryption { return this.$store.state.accounts.encryption; }, + enforceAutolock() { + return this.$store.state.menu.enforceAutolock; + }, autolock: { get(): number { - return this.$store.state.menu.autolock; + if (this.$store.state.menu.enforceAutolock) { + return this.$store.state.menu.enforceAutolock; + } else { + return this.$store.state.menu.autolock; + } }, set(autolock: number) { this.$store.commit("menu/setAutolock", autolock);