Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
env: CACHE_NAME=LINTSPACES
- stage: test
name: Build Firefox and run addons-linter
script: npm install --only=production addons-linter && npm run firefox && addons-linter
script: npm install --only=production -g addons-linter && npm run firefox && addons-linter
firefox
env: CACHE_NAME=FIREFOXLINTER
- stage: test
Expand Down
6 changes: 6 additions & 0 deletions _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,12 @@
"loading": {
"message": "Loading..."
},
"autolock": {
"message": "Lock after"
},
"minutes": {
"message": "minutes"
},
"advanced": {
"message": "Advanced"
},
Expand Down
43 changes: 10 additions & 33 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 55 additions & 7 deletions src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { EntryStorage, ManagedStorage } from "./models/storage";
import { Dropbox, Drive } from "./models/backup";

let cachedPassphrase = "";
let autolockTimeout: number;

chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.action === "position") {
if (!sender.tab) {
Expand All @@ -23,13 +25,20 @@ 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();
} else if (message.action === "passphrase") {
sendResponse(cachedPassphrase);
sendResponse(getCachedPassphrase());
} else if (["dropbox", "drive"].indexOf(message.action) > -1) {
getBackupToken(message.action);
} else if (message.action === "lock") {
cachedPassphrase = "";
document.cookie = 'passphrase=";expires=Thu, 01 Jan 1970 00:00:00 GMT"';
} else if (message.action === "resetAutolock") {
clearTimeout(autolockTimeout);
setAutolock();
}
});

Expand Down Expand Up @@ -276,12 +285,12 @@ function getBackupToken(service: string) {
xhr.open(
"POST",
"https://www.googleapis.com/oauth2/v4/token?client_id=" +
getCredentials().drive.client_id +
"&client_secret=" +
getCredentials().drive.client_secret +
"&code=" +
value +
"&redirect_uri=https://authenticator.cc/oauth&grant_type=authorization_code"
getCredentials().drive.client_id +
"&client_secret=" +
getCredentials().drive.client_secret +
"&code=" +
value +
"&redirect_uri=https://authenticator.cc/oauth&grant_type=authorization_code"
);
xhr.setRequestHeader("Accept", "application/json");
xhr.setRequestHeader(
Expand Down Expand Up @@ -395,3 +404,42 @@ chrome.commands.onCommand.addListener(async (command: string) => {
break;
}
});

function setAutolock() {
if (Number(localStorage.autolock) > 0) {
document.cookie = `passphrase="${getCachedPassphrase()}${getCookieExpiry()}"`;
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();

return `;expires=${autolockExpiry}`;
} else {
return "";
}
}

function getCachedPassphrase() {
if (cachedPassphrase) {
return cachedPassphrase;
}

const cookie = document.cookie;
const cookieMatch = cookie
? document.cookie.match(/passphrase=([^;]*)/)
: null;
const cookiePassphrase =
cookieMatch && cookieMatch.length > 1 ? cookieMatch[1] : null;
if (cookiePassphrase) {
return cookiePassphrase;
}

return "";
}
1 change: 0 additions & 1 deletion src/components/Popup/MainHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ export default Vue.extend({
this.$store.commit("accounts/stopFilter");
},
lock() {
document.cookie = 'passphrase=";expires=Thu, 01 Jan 1970 00:00:00 GMT"';
chrome.runtime.sendMessage({ action: "lock" }, window.close);
return;
},
Expand Down
23 changes: 23 additions & 0 deletions src/components/Popup/PrefrencesPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@
<label class="combo-label">{{ i18n.use_high_contrast }}</label>
<input class="checkbox" type="checkbox" v-model="useHighContrast" />
</div>
<div style="display: flex;" v-show="encryption.getEncryptionStatus()">
<label style="margin-left: 20px;">{{ i18n.autolock }}</label>
<input
class="input"
type="number"
min="0"
style="width: 70px;"
v-model="autolock"
/>
<span style="margin-top: 10px;">{{ i18n.minutes }}</span>
</div>
<div class="button" v-on:click="popOut()">{{ i18n.popout }}</div>
</div>
</template>
Expand Down Expand Up @@ -55,6 +66,18 @@ export default Vue.extend({
set(useHighContrast: boolean) {
this.$store.commit("menu/setHighContrast", useHighContrast);
}
},
encryption(): IEncryption {
return this.$store.state.accounts.encryption;
},
autolock: {
get(): number {
return this.$store.state.menu.autolock;
},
set(autolock: number) {
this.$store.commit("menu/setAutolock", autolock);
chrome.runtime.sendMessage({ action: "resetAutolock" });
}
}
},
methods: {
Expand Down
1 change: 1 addition & 0 deletions src/definitions/module-interface.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ interface VuexConstructor {
interface MenuState {
version: String;
zoom: Number;
autolock: Number;
useAutofill: Boolean;
useHighContrast: Boolean;
backupDisabled: Boolean;
Expand Down
10 changes: 0 additions & 10 deletions src/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,6 @@ init();
function getCachedPassphrase() {
return new Promise(
(resolve: (value: string) => void, reject: (reason: Error) => void) => {
const cookie = document.cookie;
const cookieMatch = cookie
? document.cookie.match(/passphrase=([^;]*)/)
: null;
const cachedPassphrase =
cookieMatch && cookieMatch.length > 1 ? cookieMatch[1] : null;
if (cachedPassphrase) {
return resolve(cachedPassphrase);
}

chrome.runtime.sendMessage(
{ action: "passphrase" },
(passphrase: string) => {
Expand Down
17 changes: 0 additions & 17 deletions src/store/Accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ export class Accounts implements IModule {
state.commit("style/hideInfo", null, { root: true });

if (!state.getters.currentlyEncrypted) {
document.cookie = "passphrase=" + password;
chrome.runtime.sendMessage({
action: "cachePassphrase",
value: password
Expand All @@ -181,7 +180,6 @@ export class Accounts implements IModule {
);

state.state.encryption.updateEncryptionPassword(password);
document.cookie = "passphrase=" + password;
chrome.runtime.sendMessage({
action: "cachePassphrase",
value: password
Expand Down Expand Up @@ -354,21 +352,6 @@ export class Accounts implements IModule {
private getCachedPassphrase() {
return new Promise(
(resolve: (value: string) => void, reject: (reason: Error) => void) => {
const cookie = document.cookie;
const cookieMatch = cookie
? document.cookie.match(/passphrase=([^;]*)/)
: null;
const cachedPassphrase =
cookieMatch && cookieMatch.length > 1 ? cookieMatch[1] : null;
const cachedPassphraseLocalStorage = localStorage.encodedPhrase
? CryptoJS.AES.decrypt(localStorage.encodedPhrase, "").toString(
CryptoJS.enc.Utf8
)
: "";
if (cachedPassphrase || cachedPassphraseLocalStorage) {
return resolve(cachedPassphrase || cachedPassphraseLocalStorage);
}

chrome.runtime.sendMessage(
{ action: "passphrase" },
(passphrase: string) => {
Expand Down
5 changes: 5 additions & 0 deletions src/store/Menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export class Menu implements IModule {
zoom: Number(localStorage.zoom) || 100,
useAutofill: localStorage.autofill === "true",
useHighContrast: localStorage.highContrast === "true",
autolock: Number(localStorage.autolock) || 0,
backupDisabled: await ManagedStorage.get("disableBackup"),
storageArea: await ManagedStorage.get("storageArea"),
feedbackURL: await ManagedStorage.get("feedbackURL")
Expand All @@ -25,6 +26,10 @@ export class Menu implements IModule {
setHighContrast(state: MenuState, useHighContrast: boolean) {
state.useHighContrast = useHighContrast;
localStorage.highContrast = useHighContrast;
},
setAutolock(state: MenuState, autolock: number) {
state.autolock = autolock;
localStorage.autolock = autolock;
}
},
namespaced: true
Expand Down