Skip to content

Commit 37fb8bd

Browse files
committedMay 15, 2020
Add support to replace a server public key
1 parent 6e8f37a commit 37fb8bd

17 files changed

+407
-18
lines changed
 

‎.editorconfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ root = true
66
[*]
77
indent_style = space
88
end_of_line = lf
9-
insert_final_newline = true
9+
insert_final_newline = false
1010
trim_trailing_whitespace = true
1111

1212
[*.js]

‎dist/chrome/passbolt-2.12.2-debug.crx

2.2 KB
Binary file not shown.
+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"debug": false,
2+
"debug": true,
33
"log": {
4-
"level": 0,
5-
"console": false
4+
"level": 3,
5+
"console": true
66
}
77
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* Passbolt ~ Open source password manager for teams
3+
* Copyright (c) Passbolt SA (https://www.passbolt.com)
4+
*
5+
* Licensed under GNU Affero General Public License version 3 of the or any later version.
6+
* For full copyright and license information, please see the LICENSE.txt
7+
* Redistributions of files must retain the above copyright notice.
8+
*
9+
* @copyright Copyright (c) Passbolt SA (https://www.passbolt.com)
10+
* @license https://opensource.org/licenses/AGPL-3.0 AGPL License
11+
* @link https://www.passbolt.com Passbolt(tm)
12+
* @since 2.13.0
13+
*/
14+
const Config = require('../../model/config');
15+
const {GpgAuth} = require('../../model/gpgauth');
16+
const {Keyring} = require('../../model/keyring');
17+
18+
class AuthUpdateServerKeyController {
19+
20+
constructor(worker, requestId) {
21+
this.worker = worker;
22+
this.requestId = requestId;
23+
this.auth = new GpgAuth();
24+
this.keyring = new Keyring();
25+
}
26+
27+
async main() {
28+
try {
29+
const domain = Config.read('user.settings.trustedDomain');
30+
const serverKey = await this.auth.getServerKey(domain);
31+
await this.keyring.importServerPublicKey(serverKey.keydata, domain);
32+
this.worker.port.emit(this.requestId, 'SUCCESS', domain);
33+
} catch (error) {
34+
this.worker.port.emit(this.requestId, 'ERROR', this.worker.port.getEmitableError(error));
35+
}
36+
}
37+
}
38+
39+
exports.AuthUpdateServerKeyController = AuthUpdateServerKeyController;

‎src/all/background_page/event/authEvents.js

+20-9
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
* @copyright (c) 2019 Passbolt SA
77
* @licence GNU Affero General Public License http://www.gnu.org/licenses/agpl-3.0.en.html
88
*/
9-
const AuthController = require('../controller/authController').AuthController;
10-
const AuthCheckStatusController = require('../controller/auth/authCheckStatusController').AuthCheckStatusController;
11-
const AuthIsAuthenticatedController = require('../controller/auth/authIsAuthenticatedController').AuthIsAuthenticatedController;
12-
const AuthIsMfaRequiredController = require('../controller/auth/authIsMfaRequiredController').AuthIsMfaRequiredController;
13-
const GpgAuth = require('../model/gpgauth').GpgAuth;
9+
const {AuthController} = require('../controller/authController');
10+
const {AuthCheckStatusController} = require('../controller/auth/authCheckStatusController');
11+
const {AuthIsAuthenticatedController} = require('../controller/auth/authIsAuthenticatedController');
12+
const {AuthIsMfaRequiredController} = require('../controller/auth/authIsMfaRequiredController');
13+
const {AuthUpdateServerKeyController} = require('../controller/auth/authUpdateServerKeyController');
14+
const {GpgAuth} = require('../model/gpgauth');
1415
const Worker = require('../model/worker');
1516

1617
const listen = function (worker) {
17-
1818
/*
1919
* Check if the user is authenticated.
2020
*
@@ -79,11 +79,11 @@ const listen = function (worker) {
7979
/*
8080
* Get the password server key for a given domain.
8181
*
82-
* @listens passbolt.auth.getServerKey
82+
* @listens passbolt.auth.get-server-key
8383
* @param requestId {uuid} The request identifier
8484
* @param domain {string} The server's domain
8585
*/
86-
worker.port.on('passbolt.auth.getServerKey', function (requestId, domain) {
86+
worker.port.on('passbolt.auth.get-server-key', function (requestId, domain) {
8787
var gpgauth = new GpgAuth();
8888
gpgauth.getServerKey(domain).then(
8989
function success(msg) {
@@ -95,6 +95,17 @@ const listen = function (worker) {
9595
);
9696
});
9797

98+
/*
99+
* Get the password server key for a given domain.
100+
*
101+
* @listens passbolt.auth.replace-server-key
102+
* @param requestId {uuid} The request identifier
103+
*/
104+
worker.port.on('passbolt.auth.replace-server-key', async function (requestId) {
105+
const controller = new AuthUpdateServerKeyController(worker, requestId);
106+
await controller.main();
107+
});
108+
98109
/*
99110
* Attempt to login the current user.
100111
*
@@ -108,7 +119,7 @@ const listen = function (worker) {
108119
* @param redirect {string} The uri to redirect the user after login
109120
*/
110121
worker.port.on('passbolt.auth.login', function (requestId, passphrase, remember, redirect) {
111-
var auth = new AuthController(worker, requestId);
122+
const auth = new AuthController(worker, requestId);
112123
auth.login(passphrase, remember, redirect);
113124
});
114125

‎src/all/content_scripts/js/login/login.js

+18-2
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,29 @@ $(function () {
8282
}
8383
// All other cases.
8484
else {
85-
passbolt.html.loadTemplate('.login.form', 'login/feedbackLoginOops.ejs');
85+
passbolt.login.onStep0ChangeKey();
86+
// passbolt.html.loadTemplate('.login.form', 'login/feedbackLoginOops.ejs');
8687
}
8788
}
8889
);
8990
passbolt.login.onStep1RequestPassphrase();
9091
};
9192

93+
/**
94+
* Insert the passphrase dialog iframe.
95+
*/
96+
passbolt.login.onStep0ChangeKey = function () {
97+
// Inject the change key dialog iframe into the web page DOM.
98+
// piggy back on login form page mod / port
99+
const iframeId = 'passbolt-iframe-login-change-key';
100+
const port = passphraseIframeId;
101+
const className = 'loading';
102+
const appendTo = '.login.form';
103+
const style = 'width:330px;height:250px;';
104+
$(appendTo).empty();
105+
passbolt.html.insertIframe(iframeId, appendTo, className, null, null, style, port);
106+
};
107+
92108
/**
93109
* Insert the passphrase dialog iframe.
94110
*/
@@ -152,4 +168,4 @@ $(function () {
152168

153169
passbolt.login.init();
154170
});
155-
undefined; // result must be structured-clonable data
171+
undefined; // result must be structured-clonable data

‎src/all/data/ejs/login/changeKey.ejs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<h3>The server key has changed!</h3>
2+
<p>
3+
For
4+
<a href="https://help.passbolt.com/start/key-change" target="_blank" target="_blank" rel="noopener noreferrer">
5+
security reasons</a>, please confirm with your IT administrator that this is
6+
a change they initiated.
7+
</p>
8+
<div class="input checkbox required">
9+
<input type="checkbox" id="js_server_key_change_confirm" value="legit"/>
10+
<label for="js_server_key_change_confirm">I have checked, all is fine.</label>
11+
</div><br>
12+
<div class="actions-wrapper center">
13+
<a id="js_server_key_change_submit" class="button primary big disabled" href="#" role="button">Accept new key</a>
14+
</div>
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<h2>Oops, something went wrong.</h2>
2+
<p>
3+
There was an internal error when trying to add the new key.
4+
Please contact your administrator for more information, or refresh the page
5+
to retry.
6+
</p>
7+
<p>
8+
<em><?= message ?></em>
9+
</p>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<h2>Success!</h2>
2+
<p>
3+
The key was changed.
4+
You are good to go. Click on the button bellow or refresh the page to retry.
5+
</p>
6+
<div class="actions-wrapper center">
7+
<a class="button primary big" href="<?= domain ?>" role="button" target="_parent" rel="noopener noreferrer">
8+
Retry login
9+
</a>
10+
</div>

‎src/all/data/js/lib/html.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -103,22 +103,26 @@ passbolt.templates = window.templates;
103103
passbolt.html.getBrowserName = getBrowserName;
104104

105105
/**
106+
* InsertIframe
106107
*
107108
* @param iframeId string
108109
* @param iframeUrlOptions Object
109110
* @param appendTo string acting as jQuery selector
110111
* @param className string (optional)
112+
* @param style string (optional)
113+
* @param port string (optional)
111114
* @returns {*|jQuery|HTMLElement}
112115
*/
113-
var insertIframe = function (iframeId, appendTo, className, iframeUrlOptions, insertMode, style) {
116+
var insertIframe = function (iframeId, appendTo, className, iframeUrlOptions, insertMode, style, port) {
114117
// set defaults
115118
const mode = insertMode || 'append';
116119
const css = style || '';
117120
const urlOptions = iframeUrlOptions || {};
118121
const cssClass = className || '';
119122

120123
// build iframe url
121-
var iframeUrl = chrome.runtime.getURL('data/' + iframeId +'.html') + `?passbolt=${iframeId}&`;
124+
var port = port ? port : iframeId;
125+
var iframeUrl = chrome.runtime.getURL('data/' + iframeId +'.html') + `?passbolt=${port}&`;
122126
let optionUrl = [];
123127
for (var options in urlOptions)
124128
if (iframeUrlOptions.hasOwnProperty(options)) {
+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/**
2+
* Login form.
3+
*
4+
* @copyright (c) 2020 Passbolt SA
5+
* @licence GNU Affero General Public License http://www.gnu.org/licenses/agpl-3.0.en.html
6+
*/
7+
8+
$(function () {
9+
10+
let $changeConfirm = null,
11+
$changeSubmit = null;
12+
13+
/**
14+
* Initialize the master password dialog.
15+
*/
16+
const init = function () {
17+
// Load the page template.
18+
loadTemplate()
19+
.then(initEventsListeners)
20+
// Mark the iframe container as ready.
21+
.then(function () {
22+
passbolt.message.emit('passbolt.auth.remove-class', '#passbolt-iframe-login-form', 'loading');
23+
passbolt.message.emit('passbolt.auth.add-class', '#passbolt-iframe-login-form', 'ready');
24+
}, function(error) {
25+
console.error(error);
26+
console.error('Something went wrong when initializing loginChangeKey.js');
27+
});
28+
};
29+
30+
/**
31+
* Load the page template and initialize the constiables relative to it.
32+
* @returns {Promise}
33+
*/
34+
const loadTemplate = function () {
35+
return passbolt.html.loadTemplate('body', 'login/changeKey.ejs', 'html',
36+
{})
37+
.then(function success() {
38+
$changeConfirm = $('#js_server_key_change_confirm');
39+
$changeSubmit = $('#js_server_key_change_submit');
40+
});
41+
};
42+
43+
/**
44+
* Init the events listeners.
45+
* The events can come from the following sources : addon, page or DOM.
46+
*/
47+
const initEventsListeners = function () {
48+
$changeConfirm.on('click', onChangeConfirm);
49+
$changeSubmit.on('click', onLoginSubmit);
50+
};
51+
52+
const onChangeConfirm = function() {
53+
$changeSubmit.toggleClass('disabled');
54+
}
55+
56+
const onLoginSubmit = function() {
57+
if($changeSubmit.hasClass('disabled')) {
58+
// do nothing
59+
} else {
60+
passbolt.request('passbolt.auth.replace-server-key').then(
61+
function success(domain) {
62+
passbolt.html.loadTemplate('body', 'login/changeKeySuccess.ejs','html',
63+
{domain: domain}
64+
);
65+
},
66+
function error(error) {
67+
passbolt.html.loadTemplate('body', 'login/changeKeyOops.ejs', 'html',
68+
{message: error.message}
69+
);
70+
}
71+
);
72+
}
73+
}
74+
75+
// Init the login form.
76+
init();
77+
78+
});

‎src/all/data/js/setup/step/domainCheck.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ $(function () {
135135
* @private
136136
*/
137137
step._fetchServerKey = function (domain) {
138-
return passbolt.request('passbolt.auth.getServerKey', domain)
138+
return passbolt.request('passbolt.auth.get-server-key', domain)
139139
.then(function (serverKey) {
140140
step._data.serverKey = serverKey.keydata;
141141
return serverKey.keydata;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!DOCTYPE html>
2+
<html lang="en" class="alpha version passboltplugin">
3+
<head>
4+
<meta charset="utf-8"/>
5+
<link href="css/themes/default/ext_iframe.min.css" media="all" rel="stylesheet">
6+
<script src="vendors/jquery.js"></script>
7+
<script src="tpl/login.js"></script>
8+
<script src="js/lib/port.js"></script>
9+
<script src="js/lib/request.js"></script>
10+
<script src="js/lib/message.js"></script>
11+
<script src="js/lib/html.js"></script>
12+
<script src="js/login/loginChangeKey.js"></script>
13+
</head>
14+
<body class="iframe">
15+
</body>
16+
</html>

‎src/all/data/tpl/login.js

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
window.templates = window.templates || {};
22
window.templates.login = window.templates.login || {};
3+
window.templates.login.changeKey = require('./login/changeKey.js');
4+
window.templates.login.changeKeyOops = require('./login/changeKeyOops.js');
5+
window.templates.login.changeKeySuccess = require('./login/changeKeySuccess.js');
36
window.templates.login.feedbackLoginError = require('./login/feedbackLoginError.js');
47
window.templates.login.feedbackLoginNoUser = require('./login/feedbackLoginNoUser.js');
58
window.templates.login.feedbackLoginOops = require('./login/feedbackLoginOops.js');

0 commit comments

Comments
 (0)
Please sign in to comment.