-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
52 lines (48 loc) · 1.54 KB
/
index.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
exports.create = function(accounts, certs) {
var store = {};
store.accounts = {
setKeypair: function(opts) {
var id = (opts.account && opts.account.id) || opts.email || 'default';
return accounts.updateOne({ id: id }, { $set: {
id: id,
privateKeyPem: opts.keypair.privateKeyPem,
privateKeyJwk: opts.keypair.privateKeyJwk
}}, { upsert: true });
},
checkKeypair: function(opts) {
var id = (opts.account && opts.account.id) || opts.email || 'default';
return accounts.findOne({ id: id });
}
};
store.certificates = {
setKeypair: function(opts) {
var id = (opts.certificate && (opts.certificate.kid || opts.certificate.id)) || opts.subject;
return certs.updateOne({ id: id }, { $set: {
id: id,
privateKeyPem: opts.keypair.privateKeyPem,
privateKeyJwk: opts.keypair.privateKeyJwk
}}, { upsert: true });
},
checkKeypair: function(opts) {
var id = (opts.certificate && (opts.certificate.kid || opts.certificate.id)) || opts.subject;
return certs.findOne({ id: id });
},
set: function(opts) {
var id = (opts.certificate && opts.certificate.id) || opts.subject;
return certs.updateOne({ id: id }, { $set: {
id: id,
cert: opts.pems.cert,
chain: opts.pems.chain,
subject: opts.pems.subject,
altnames: opts.pems.altnames,
issuedAt: opts.pems.issuedAt,
expiresAt: opts.pems.expiresAt
}}, { upsert: true });
},
check: function(opts) {
var id = (opts.certificate && opts.certificate.id) || opts.subject;
return certs.findOne({ id: id });
}
};
return store;
};