-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapi.js
More file actions
107 lines (83 loc) · 3.05 KB
/
Copy pathapi.js
File metadata and controls
107 lines (83 loc) · 3.05 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
'use strict';
// Custom modules
const auth = require('./api/components/auth.js');
const certapi = require('./api/certificate.js');
const caapi = require('./api/ca.js');
const usrapi = require('./api/user.js');
const apipath = '/api/v1';
const USER_AUTH = 1;
const ADMIN_AUTH = 0;
let acceptBasic = false;
if (global.config.server.secure.mutualAuth === false) {
acceptBasic = true;
}
/**
* Initializes Public API paths.
*/
const initPublicAPI = function(app) {
app.get('/ca/:caroot/:caname/', function(req, res) {
req.params.chain = false;
caapi.get(req, res);
});
app.get('/ca/:caroot/:caname/chain/', function(req, res) {
req.params.chain = true;
caapi.get(req, res);
});
app.get('/authorities/', function(req, res) {
caapi.list(req, res);
});
app.put('/certificate/info/', function(req, res) {
certapi.certificate.info(req, res);
});
};
/**
* Initializes Private API paths.
*/
const initAPI = function(app) {
// Users
app.post(apipath + '/user/', auth.authenticate(ADMIN_AUTH, false), function(req, res) {
usrapi.create(req, res);
});
app.get(apipath + '/user/:name/', auth.authenticate(ADMIN_AUTH, false), function(req, res) {
usrapi.getPair(req, res);
});
app.delete(apipath + '/user/:name', auth.authenticate(ADMIN_AUTH, false), function(req, res) {
usrapi.remove(req, res);
});
// Certificates
app.put(apipath + '/certificate/verify/', auth.authenticate(USER_AUTH, acceptBasic), function(req, res) {
certapi.certificate.verify(req, res);
});
app.post(apipath + '/certificate/private/', auth.authenticate(USER_AUTH, acceptBasic), function(req, res) {
certapi.certificate.privates(req, res);
});
app.post(apipath + '/certificate/sign/', auth.authenticate(USER_AUTH, acceptBasic), function(req, res) {
certapi.certificate.signing(req, res);
});
app.post(apipath + '/certificate/pair/', auth.authenticate(USER_AUTH, acceptBasic), function(req, res) {
certapi.certificate.pairCreation(req, res);
});
app.post(apipath + '/certificate/revoke/', auth.authenticate(ADMIN_AUTH, false), function(req, res) {
certapi.certificate.revokeDomain(req, res);
});
app.delete(apipath + '/certificate/:caroot/:caname/:serial/', auth.authenticate(ADMIN_AUTH, false), function(req, res) {
certapi.certificate.revoke(req, res);
});
app.get(apipath + '/certificates/', auth.authenticate(ADMIN_AUTH, false), function(req, res) {
certapi.certificates.list(req, res);
});
// Authority
app.post(apipath + '/ca/root/', auth.authenticate(ADMIN_AUTH, false), function(req, res) {
caapi.root(req, res);
});
app.post(apipath + '/ca/intermediate/', auth.authenticate(ADMIN_AUTH, false), function(req, res) {
caapi.intermediate(req, res);
});
app.put(apipath + '/ca/import/', auth.authenticate(ADMIN_AUTH, false), function(req, res) {
caapi.import(req, res);
});
};
module.exports = {
initAPI,
initPublicAPI
};