-
Notifications
You must be signed in to change notification settings - Fork 30
/
passbolt-server-key.js
53 lines (50 loc) · 1.88 KB
/
passbolt-server-key.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/**
* Passbolt ~ Open source password manager for teams
* Copyright (c) Passbolt SA (https://www.passbolt.com)
*
* Licensed under GNU Affero General Public License version 3 of the or any later version.
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Passbolt SA (https://www.passbolt.com)
* @license https://opensource.org/licenses/AGPL-3.0 AGPL License
* @link https://www.passbolt.com Passbolt(tm)
*/
const {Command} = require('commander');
const ServerKeyController = require('./app/controllers/serverKeyController.js');
/**
* Get and display the server public key
*/
(async function() {
const program = new Command();
program
.usage('[options]', 'Get the server key')
.option('--fingerprint', 'Display the fingerprint')
.option('--armored-key', 'Display the armored block (default)')
.option('--skipCertificateValidation', 'Ignore server certificate is verification errors')
.option('--domain <domain>', 'The URL of the domain to get the key from')
.option('-v, --verbose', 'Display additional debug information')
.parse(process.argv);
let serverKeyController;
try {
serverKeyController = new ServerKeyController(program, process.argv);
} catch (error) {
console.error('Could not fetch server key. Please provide a domain in app/config/config.json or using --domain.');
console.error(error.message);
process.exit(1);
}
let response;
try {
response = await serverKeyController.getPublicKey();
} catch ( error) {
console.error(error.message);
process.exit(1);
}
const {fingerprint, armoredKey} = program.opts();
if (fingerprint) {
console.log(response.body.fingerprint);
}
if (armoredKey || (!fingerprint && !armoredKey)) {
console.log(response.body.keydata);
}
})();