Skip to content

Commit

Permalink
Select group when adding new credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
varjolintu committed Mar 9, 2019
1 parent c3a3602 commit 0c17791
Show file tree
Hide file tree
Showing 11 changed files with 503 additions and 144 deletions.
32 changes: 32 additions & 0 deletions keepassxc-browser/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,22 @@
"message": "Please choose the credentials you want to update.",
"description": "A popup message shown choosing what credentials user wants to update."
},
"popupRememberChooseGroup": {
"message": "Please choose the group you want to add the new credentials.",
"description": "A popup message shown choosing what group user wants to use for new credentials."
},
"popupRememberErrorDefaultGroupNotFound": {
"message": "Error: Specified default group not found.",
"description": "Error message shown when default group set cannot be found."
},
"popupRememberErrorPasswordNotChanged": {
"message": "Error: Credentials not updated. The password has not been changed.",
"description": "Error message shown when credential password is not changed."
},
"popupRememberErrorCannotSaveCredentials": {
"message": "Error: Credentials cannot be saved or updated.",
"description": "Error message shown when credentials cannot be saved or updated."
},
"popupLoginText": {
"message": "Select the login information you would like to get entered into the page.",
"description": "A popup message shown when one or multiple credentials are present."
Expand Down Expand Up @@ -447,6 +463,22 @@
"message": "Maximum (Number of) Redirects:",
"description": "RMaximum (Number of) Redirects options text."
},
"optionsLabelDefaultGroup": {
"message": "Default group for saving new passwords:",
"description": "Default group options text."
},
"optionsDefaultGroupHelpText": {
"message": "Separate the group with slashes, for example: Group/ChildGroup.",
"description": "Default group help text."
},
"optionsLabelDefaultGroupCheckboxText": {
"message": "Always ask where to save new credentials",
"description": "Default group checkbox help text."
},
"optionsLabelDefaultGroupCheckboxHelpText": {
"message": "When enabled, the popup shows a group listing.",
"description": "Default checkbox explanation help text."
},
"optionsCheckboxUsePasswordGenerator": {
"message": "Activate password generator.",
"description": "Activate password generator checkbox text."
Expand Down
10 changes: 5 additions & 5 deletions keepassxc-browser/background/browserAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,13 @@ browserAction.stackPop = function(tabId) {

browserAction.stackPush = function(data, tabId) {
const id = tabId || page.currentTabId;
browserAction.removeLevelFromStack(null, {'id': id}, data.level, '<=', true);
browserAction.removeLevelFromStack(null, { 'id': id }, data.level, '<=', true);
page.tabs[id].stack.push(data);
};

browserAction.stackUnshift = function(data, tabId) {
const id = tabId || page.currentTabId;
browserAction.removeLevelFromStack(null, {'id': id}, data.level, '<=', true);
browserAction.removeLevelFromStack(null, { 'id': id }, data.level, '<=', true);
page.tabs[id].stack.unshift(data);
};

Expand All @@ -193,7 +193,7 @@ browserAction.removeRememberPopup = function(callback, tab, removeImmediately) {
const currentMS = Date.now();
if (removeImmediately || (data.visibleForPageUpdates <= 0 && data.redirectOffset > 0)) {
browserAction.stackPop(tab.id);
browserAction.show(null, {"id": tab.id});
browserAction.show(null, { 'id': tab.id });
page.clearCredentials(tab.id);
} else if (!isNaN(data.visibleForPageUpdates) && data.redirectOffset > 0 && currentMS >= data.redirectOffset) {
data.visibleForPageUpdates -= 1;
Expand All @@ -202,7 +202,7 @@ browserAction.removeRememberPopup = function(callback, tab, removeImmediately) {
};

browserAction.setRememberPopup = function(tabId, username, password, url, usernameExists, credentialsList) {
browser.storage.local.get({'settings': {}}).then(function(item) {
browser.storage.local.get({ 'settings': {} }).then(function(item) {
const settings = item.settings;

// Don't show anything if the site is in the ignore
Expand Down Expand Up @@ -233,7 +233,7 @@ browserAction.setRememberPopup = function(tabId, username, password, url, userna
index: 0,
counter: 0,
max: 2,
icons: ['icon_remember_red_background_19x19.png', 'icon_remember_red_lock_19x19.png']
icons: [ 'icon_remember_red_background_19x19.png', 'icon_remember_red_lock_19x19.png' ]
},
icon: 'icon_remember_red_background_19x19.png',
popup: 'popup_remember.html'
Expand Down
1 change: 1 addition & 0 deletions keepassxc-browser/background/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ kpxcEvent.messageHandlers = {
'check_update_keepassxc': kpxcEvent.onCheckUpdateKeePassXC,
'generate_password': keepass.generatePassword,
'get_connected_database': kpxcEvent.onGetConnectedDatabase,
'get_database_groups': keepass.getDatabaseGroups,
'get_keepassxc_versions': kpxcEvent.onGetKeePassXCVersions,
'get_status': kpxcEvent.onGetStatus,
'get_tab_information': kpxcEvent.onGetTabInformation,
Expand Down
80 changes: 76 additions & 4 deletions keepassxc-browser/background/keepass.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ const kpActions = {
CHANGE_PUBLIC_KEYS: 'change-public-keys',
LOCK_DATABASE: 'lock-database',
DATABASE_LOCKED: 'database-locked',
DATABASE_UNLOCKED: 'database-unlocked'
DATABASE_UNLOCKED: 'database-unlocked',
GET_DATABASE_GROUPS: 'get-database-groups'
};

const kpErrors = {
Expand Down Expand Up @@ -127,11 +128,11 @@ keepass.sendNativeMessage = function(request, enableTimeout = false) {
});
};

keepass.addCredentials = function(callback, tab, username, password, url) {
keepass.updateCredentials(callback, tab, null, username, password, url);
keepass.addCredentials = function(callback, tab, username, password, url, group, groupUuid) {
keepass.updateCredentials(callback, tab, null, username, password, url, group, groupUuid);
};

keepass.updateCredentials = function(callback, tab, entryId, username, password, url) {
keepass.updateCredentials = function(callback, tab, entryId, username, password, url, group, groupUuid) {
page.debug('keepass.updateCredentials(callback, {1}, {2}, {3}, [password], {4})', tab.id, entryId, username, url);
if (tab && page.tabs[tab.id]) {
page.tabs[tab.id].errorMessage = null;
Expand Down Expand Up @@ -162,6 +163,11 @@ keepass.updateCredentials = function(callback, tab, entryId, username, password,
messageData.uuid = entryId;
}

if (group && groupUuid) {
messageData.group = group;
messageData.groupUuid = groupUuid;
}

const request = {
action: kpAction,
message: keepass.encrypt(messageData, nonce),
Expand Down Expand Up @@ -678,6 +684,72 @@ keepass.lockDatabase = function(tab) {
});
};

keepass.getDatabaseGroups = function(callback, tab) {
keepass.testAssociation((taResponse) => {
if (!taResponse) {
browserAction.showDefault(null, tab);
callback([]);
return;
}

if (tab && page.tabs[tab.id]) {
page.tabs[tab.id].errorMessage = null;
}

if (!keepass.isConnected) {
callback([]);
return;
}

let groups = [];
const kpAction = kpActions.GET_DATABASE_GROUPS;
const nonce = keepass.getNonce();
const incrementedNonce = keepass.incrementedNonce(nonce);

const messageData = {
action: kpAction
};

const request = {
action: kpAction,
message: keepass.encrypt(messageData, nonce),
nonce: nonce,
clientID: keepass.clientID
};

keepass.sendNativeMessage(request).then((response) => {
if (response.message && response.nonce) {
const res = keepass.decrypt(response.message, response.nonce);
if (!res) {
keepass.handleError(tab, kpErrors.CANNOT_DECRYPT_MESSAGE);
callback([]);
return;
}

const message = nacl.util.encodeUTF8(res);
const parsed = JSON.parse(message);

if (keepass.verifyResponse(parsed, incrementedNonce)) {
groups = parsed.groups;
groups.defaultGroup = page.settings.defaultGroup;
groups.defaultGroupAlwaysAsk = page.settings.defaultGroupAlwaysAsk;
keepass.updateLastUsed(keepass.databaseHash);
callback(groups);
} else {
console.log('getDatabaseGroups rejected');
callback([]);
}
} else if (response.error && response.errorCode) {
keepass.handleError(tab, response.errorCode, response.error);
callback([]);
} else {
browserAction.showDefault(null, tab);
callback([]);
}
});
}, tab, false);
};

keepass.generateNewKeyPair = function() {
keepass.keyPair = nacl.box.keyPair();
//console.log(nacl.util.encodeBase64(keepass.keyPair.publicKey) + ' ' + nacl.util.encodeBase64(keepass.keyPair.secretKey));
Expand Down
4 changes: 4 additions & 0 deletions keepassxc-browser/options/options.css
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ h2+hr {
width: 75%;
}

#defaultGroup {
width: 50%;
}

tr.clone {
display: none;
}
Expand Down
24 changes: 24 additions & 0 deletions keepassxc-browser/options/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,30 @@ <h3 data-i18n="optionsKeyboardShortcutsHeader"></h3>
</div>
</p>
<hr />
<p>
<div class="form-group">
<label for="defaultGroup" data-i18n="optionsLabelDefaultGroup"></label>
<div class="control-group">
<div class="input-append">
<input type="text" id="defaultGroup" placeholder="KeePassXC-Browser Passwords">
<button class="btn btn-sm btn-primary" id="defaultGroupButton" type="button"><span class="glyphicon glyphicon-floppy-disk"></span> <span data-i18n="optionsButtonSave"/></button>
<button class="btn btn-sm btn-danger" id="defaultGroupButtonReset"><span class="glyphicon glyphicon-remove-sign"></span> <span data-i18n="optionsButtonReset"></span></button>
</div>
</div>
<span class="help-block">
<span data-i18n="optionsDefaultGroupHelpText"></span>
<br />
<span data-i18n="optionsDefault"></span> KeePassXC-Browser Passwords
</span>
<div class="checkbox">
<label class="checkbox">
<input type="checkbox" name="defaultGroupAlwaysAsk" value="true" /><span data-i18n="optionsLabelDefaultGroupCheckboxText"></span>
</label>
<span class="help-block" data-i18n="optionsLabelDefaultGroupCheckboxHelpText"></span>
</div>
</div>
</p>
<hr />
<p>
<div class="checkbox">
<label class="checkbox">
Expand Down
35 changes: 34 additions & 1 deletion keepassxc-browser/options/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ options.saveSettingsPromise = function() {
options.saveSetting = function(name) {
const id = '#' + name;
$(id).closest('.control-group').removeClass('error').addClass('success');
setTimeout(() => { $(id).closest('.control-group').removeClass('success'); }, 2500);
setTimeout(() => {
$(id).closest('.control-group').removeClass('success');
}, 2500);

browser.storage.local.set({ 'settings': options.settings });
browser.runtime.sendMessage({
Expand All @@ -79,6 +81,11 @@ options.saveKeyRing = function() {
options.initGeneralSettings = function() {
$('#tab-general-settings input[type=checkbox]').each(function() {
$(this).attr('checked', options.settings[$(this).attr('name')]);
if ($(this).attr('name') === 'defaultGroupAlwaysAsk' && $(this).attr('checked')) {
$('#defaultGroup').prop('disabled', true);
$('#defaultGroupButton').prop('disabled', true);
$('#defaultGroupButtonReset').prop('disabled', true);
}
});

$('#tab-general-settings input[type=checkbox]').change(function() {
Expand All @@ -87,10 +94,22 @@ options.initGeneralSettings = function() {
options.saveSettingsPromise().then((x) => {
if (name === 'autoFillAndSend') {
browser.runtime.sendMessage({ action: 'init_http_auth' });
} else if (name === 'defaultGroupAlwaysAsk') {
if ($(this).is(':checked')) {
$('#defaultGroup').prop('disabled', true);
$('#defaultGroupButton').prop('disabled', true);
$('#defaultGroupButtonReset').prop('disabled', true);
} else {
$('#defaultGroup').prop('disabled', false);
$('#defaultGroupButton').prop('disabled', false);
$('#defaultGroupButtonReset').prop('disabled', false);
}
}
});
});

$('#tab-general-settings input#defaultGroup').val(options.settings['defaultGroup']);

$('#tab-general-settings input[type=radio]').each(function() {
if ($(this).val() === options.settings[$(this).attr('name')]) {
$(this).attr('checked', options.settings[$(this).attr('name')]);
Expand Down Expand Up @@ -155,6 +174,20 @@ options.initGeneralSettings = function() {
options.settings['allowedRedirect'] = allowedRedirectval;
options.saveSetting('allowedRedirect');
});

$('#defaultGroupButton').click(function() {
const value = $('#defaultGroup').val();
if (value.length > 0) {
options.settings['defaultGroup'] = value;
options.saveSettings();
}
});

$('#defaultGroupButtonReset').click(function() {
$('#defaultGroup').val('');
options.settings['defaultGroup'] = '';
options.saveSettings();
});
};

options.showKeePassXCVersions = function(response) {
Expand Down
25 changes: 23 additions & 2 deletions keepassxc-browser/popups/popup.css
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ body {
font-size: 80%;
color: #787878;
}
#list {
padding-left: 0px;
}
#child {
border-top: 0px;
}
#update-available {
padding-top: 10px;
margin-top: 10px;
Expand All @@ -64,9 +70,24 @@ body {
}
#login-filter {
outline:none;
border-radius: 4px 0 0 4px;
border-radius: 4px;
border: 1px solid #ccc;
margin-bottom: 5px;
padding: 2px 10px;
width: 100%;
}
}
.credentials .groups {
display: none;
border-top: 1px solid #333;
}
.connected-database {
display: none;
font-size: 85%;
color: #787878;
}
.credentials .username-new {
display: none;
}
.credentials .username-exists {
display: none;
}
18 changes: 7 additions & 11 deletions keepassxc-browser/popups/popup_remember.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,6 @@
<script type="text/javascript" src="../options/bootstrap.min.js" /></script>
<script type="text/javascript" src="popup_functions.js"></script>
<script type="text/javascript" src="popup_remember.js"></script>
<style type="text/css">
.credentials {display: none; border-top: 1px solid #333;}
.connected-database {display: none; font-size: 85%; color: #787878;}
.credentials .username-new {display: none;}
.credentials .username-exists {display: none;}
.small { font-weight: bold; }
.small .normal { font-weight: normal; }
.info { font-weight: normal; }
</style>
</head>
<body>
<div class="buttons">
Expand All @@ -41,11 +32,16 @@
<p data-i18n="popupRememberSaving" i18n-placeholder="<span></span><em></em>"></p>
</div>

<div class="credentials">
<div class="credentials" style="display: none;">
<p class="username-new"><span data-i18n="popupRememberNewUsername" i18n-placeholder="<strong></strong>"></span></p>
<p class="username-exists"><span data-i18n="popupRememberUsernameExists" i18n-placeholder="<strong></strong>"></span></p>
<p data-i18n="popupRememberChooseCredentials"></p>
<ul id="list"></ul>
<ul id="list" class="list-group"></ul>
</div>

<div class="groups" style="display: none;">
<p data-i18n="popupRememberChooseGroup"></p>
<ul id="list" class="list-group"></ul>
</div>
<script type="text/javascript" src="../translate.js"></script>
</body>
Expand Down
Loading

0 comments on commit 0c17791

Please sign in to comment.