Skip to content

Commit

Permalink
Removed UDP settings
Browse files Browse the repository at this point in the history
  • Loading branch information
varjolintu committed Nov 9, 2017
1 parent 4b0420d commit 74031b6
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 67 deletions.
49 changes: 21 additions & 28 deletions keepassxc-browser/background/keepass.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ keepass.updateCredentials = function(callback, tab, entryId, username, password,
const request = {
action: kpAction,
message: keepass.encrypt(messageData, nonce),
nonce: keepass.b64e(nonce),
nonce: nacl.util.encodeBase64(nonce),
clientID: keepass.clientID
};

Expand Down Expand Up @@ -221,7 +221,7 @@ keepass.retrieveCredentials = function(callback, tab, url, submiturl, forceCallb
const request = {
action: kpAction,
message: keepass.encrypt(messageData, nonce),
nonce: keepass.b64e(nonce),
nonce: nacl.util.encodeBase64(nonce),
clientID: keepass.clientID
};

Expand Down Expand Up @@ -285,7 +285,7 @@ keepass.generatePassword = function(callback, tab, forceCallback) {

const request = {
action: kpAction,
nonce: keepass.b64e(nonce),
nonce: nacl.util.encodeBase64(nonce),
clientID: keepass.clientID
};

Expand Down Expand Up @@ -334,7 +334,7 @@ keepass.associate = function(callback, tab) {
page.tabs[tab.id].errorMessage = null;

const kpAction = kpActions.ASSOCIATE;
const key = keepass.b64e(keepass.keyPair.publicKey);
const key = nacl.util.encodeBase64(keepass.keyPair.publicKey);
const nonce = nacl.randomBytes(keepass.keySize);

const messageData = {
Expand All @@ -345,7 +345,7 @@ keepass.associate = function(callback, tab) {
const request = {
action: kpAction,
message: keepass.encrypt(messageData, nonce),
nonce: keepass.b64e(nonce),
nonce: nacl.util.encodeBase64(nonce),
clientID: keepass.clientID
};

Expand Down Expand Up @@ -427,7 +427,7 @@ keepass.testAssociation = function(callback, tab, enableTimeout = false) {
const request = {
action: kpAction,
message: keepass.encrypt(messageData, nonce),
nonce: keepass.b64e(nonce),
nonce: nacl.util.encodeBase64(nonce),
clientID: keepass.clientID
};

Expand Down Expand Up @@ -494,7 +494,7 @@ keepass.getDatabaseHash = function(callback, tab, enableTimeout = false) {
const request = {
action: kpAction,
message: encrypted,
nonce: keepass.b64e(nonce),
nonce: nacl.util.encodeBase64(nonce),
clientID: keepass.clientID
};

Expand Down Expand Up @@ -549,15 +549,14 @@ keepass.changePublicKeys = function(tab, enableTimeout = false) {
}

const kpAction = kpActions.CHANGE_PUBLIC_KEYS;
const key = keepass.b64e(keepass.keyPair.publicKey);
const key = nacl.util.encodeBase64(keepass.keyPair.publicKey);
let nonce = nacl.randomBytes(keepass.keySize);
nonce = keepass.b64e(nonce);
keepass.clientID = keepass.b64e(nacl.randomBytes(keepass.keySize));
nonce = nacl.util.encodeBase64(nonce);
keepass.clientID = nacl.util.encodeBase64(nacl.randomBytes(keepass.keySize));

const request = {
action: kpAction,
publicKey: key,
proxyPort: (page.settings.port ? page.settings.port : 19700),
nonce: nonce,
clientID: keepass.clientID
};
Expand All @@ -573,7 +572,7 @@ keepass.changePublicKeys = function(tab, enableTimeout = false) {
}
else {
keepass.isKeePassXCAvailable = true;
console.log('Server public key: ' + keepass.b64e(keepass.serverPublicKey));
console.log('Server public key: ' + nacl.util.encodeBase64(keepass.serverPublicKey));
}
resolve(true);
});
Expand All @@ -597,7 +596,7 @@ keepass.lockDatabase = function(tab) {
const request = {
action: kpAction,
message: keepass.encrypt(messageData, nonce),
nonce: keepass.b64e(nonce),
nonce: nacl.util.encodeBase64(nonce),
clientID: keepass.clientID
};

Expand Down Expand Up @@ -627,7 +626,7 @@ keepass.lockDatabase = function(tab) {

keepass.generateNewKeyPair = function() {
keepass.keyPair = nacl.box.keyPair();
//console.log(keepass.b64e(keepass.keyPair.publicKey) + ' ' + keepass.b64e(keepass.keyPair.secretKey));
//console.log(nacl.util.encodeBase64(keepass.keyPair.publicKey) + ' ' + nacl.util.encodeBase64(keepass.keyPair.secretKey));
};

keepass.isConfigured = function() {
Expand Down Expand Up @@ -810,13 +809,14 @@ keepass.verifyKeyResponse = function(response, key, nonce) {
}

let reply = false;
if (keepass.b64d(nonce).length !== nacl.secretbox.nonceLength)
if (nacl.util.decodeBase64(nonce).length !== nacl.secretbox.nonceLength) {
return false;
}

reply = (response.nonce === nonce);

if (response.publicKey) {
keepass.serverPublicKey = keepass.b64d(response.publicKey);
keepass.serverPublicKey = nacl.util.decodeBase64(response.publicKey);
reply = true;
}

Expand All @@ -832,8 +832,9 @@ keepass.verifyResponse = function(response, nonce, id) {

keepass.associated.hash = keepass.databaseHash;

if (keepass.b64d(response.nonce).length !== nacl.secretbox.nonceLength)
if (nacl.util.decodeBase64(response.nonce).length !== nacl.secretbox.nonceLength) {
return false;
}

keepass.associated.value = (response.nonce === nonce);

Expand All @@ -856,14 +857,6 @@ keepass.handleError = function(tab, errorCode, errorMessage = '') {
}
};

keepass.b64e = function(d) {
return nacl.util.encodeBase64(d);
};

keepass.b64d = function(d) {
return nacl.util.decodeBase64(d);
};

keepass.getCryptoKey = function() {
let dbkey = null;
let dbid = null;
Expand All @@ -890,15 +883,15 @@ keepass.encrypt = function(input, nonce) {
if (keepass.serverPublicKey) {
const message = nacl.box(messageData, nonce, keepass.serverPublicKey, keepass.keyPair.secretKey);
if (message) {
return keepass.b64e(message);
return nacl.util.encodeBase64(message);
}
}
return '';
};

keepass.decrypt = function(input, nonce, toStr) {
const m = keepass.b64d(input);
const n = keepass.b64d(nonce);
const m = nacl.util.decodeBase64(input);
const n = nacl.util.decodeBase64(nonce);
const res = nacl.box.open(m, n, keepass.serverPublicKey, keepass.keyPair.secretKey);
return res;
};
6 changes: 1 addition & 5 deletions keepassxc-browser/background/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ const defaultSettings = {
autoFillAndSend: true,
usePasswordGenerator: true,
autoFillSingleEntry: false,
autoRetrieveCredentials: true,
proxyPort: '19700'
autoRetrieveCredentials: true
};

var page = {};
Expand Down Expand Up @@ -35,9 +34,6 @@ page.initSettings = function() {
if (!('autoRetrieveCredentials' in page.settings)) {
page.settings.autoRetrieveCredentials = defaultSettings.autoRetrieveCredentials;
}
if (!('port' in page.settings)) {
page.settings.port = defaultSettings.proxyPort;
}
browser.storage.local.set({'settings': page.settings});
resolve();
});
Expand Down
18 changes: 0 additions & 18 deletions keepassxc-browser/options/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -84,24 +84,6 @@ <h2>General Settings</h2>
</span>
</div>
</p>
<p>
<div class="form-group">
<label for="port">UDP port for proxy applications:</label>
<div class="control-group">
<div class="input-append">
<input type="number" id="port" placeholder="19700" value="19700" />
<button class="btn btn-sm btn-primary" id="portButton" type="button"><span class="glyphicon glyphicon-floppy-disk"></span> Save</button>
</div>
<span class="help-inline">
Change the port if you have trouble with running KeePassXC on the default port.
<br />
You have to set the same port number in KeePassXC options.
<br />
Default: 19700
</span>
</div>
</div>
</p>
<hr />
<p>
<div class="checkbox">
Expand Down
14 changes: 0 additions & 14 deletions keepassxc-browser/options/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,24 +88,10 @@ options.initGeneralSettings = function() {
}).then(options.showKeePassXCVersions);
});

$('#port').val(options.settings['port']);
$('#blinkTimeout').val(options.settings['blinkTimeout']);
$('#blinkMinTimeout').val(options.settings['blinkMinTimeout']);
$('#allowedRedirect').val(options.settings['allowedRedirect']);

$('#portButton').click(function() {
const port = $.trim($('#port').val());
const portNumber = Number(port);
if (isNaN(port) || portNumber < 1025 || portNumber > 99999) {
$('#port').closest('.control-group').addClass('error');
alert('The port number has to be in range 1025 - 99999.\nNothing saved!');
return;
}

options.settings['port'] = String(portNumber);
options.saveSetting('port');
});

$('#blinkTimeoutButton').click(function(){
const blinkTimeout = $.trim($('#blinkTimeout').val());
const blinkTimeoutval = Number(blinkTimeout);
Expand Down
3 changes: 1 addition & 2 deletions keepassxc-protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ Request:
{
"action": "change-public-keys",
"publicKey": "<current public key>",
"proxyPort": "<UDP port for proxy applications>",
"nonce": "tZvLrBzkQ9GxXq9PvKJj4iAnfPT0VZ3Q",
"clientID": "<clientID>"
}
Expand Down Expand Up @@ -250,4 +249,4 @@ Response message data (success always returns an error, decrypted):
"error": "Database not opened",
"nonce": "tZvLrBzkQ9GxXq9PvKJj4iAnfPT0VZ3Q"
}
```
```

0 comments on commit 74031b6

Please sign in to comment.