roster-server 2.2.10 → 2.2.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/package.json +12 -3
  2. package/tasks/lessons.md +1 -0
  3. package/vendor/greenlock/.prettierrc +8 -0
  4. package/vendor/greenlock/LICENSE +312 -0
  5. package/vendor/greenlock/MIGRATION_GUIDE.md +403 -0
  6. package/vendor/greenlock/README.md +667 -0
  7. package/vendor/greenlock/accounts.js +218 -0
  8. package/vendor/greenlock/bin/add.js +72 -0
  9. package/vendor/greenlock/bin/certonly.js +368 -0
  10. package/vendor/greenlock/bin/config.js +77 -0
  11. package/vendor/greenlock/bin/defaults.js +58 -0
  12. package/vendor/greenlock/bin/greenlock.js +26 -0
  13. package/vendor/greenlock/bin/init.js +159 -0
  14. package/vendor/greenlock/bin/lib/cli.js +230 -0
  15. package/vendor/greenlock/bin/lib/flags.js +385 -0
  16. package/vendor/greenlock/bin/remove.js +46 -0
  17. package/vendor/greenlock/bin/tmpl/app.tmpl.js +9 -0
  18. package/vendor/greenlock/bin/tmpl/cluster.tmpl.js +30 -0
  19. package/vendor/greenlock/bin/tmpl/greenlock.tmpl.js +13 -0
  20. package/vendor/greenlock/bin/tmpl/server.tmpl.js +20 -0
  21. package/vendor/greenlock/bin/update.js +62 -0
  22. package/vendor/greenlock/certificates.js +324 -0
  23. package/vendor/greenlock/errors.js +58 -0
  24. package/vendor/greenlock/greenlock.js +621 -0
  25. package/vendor/greenlock/greenlockrc.js +169 -0
  26. package/vendor/greenlock/lib/challenges-wrapper.js +88 -0
  27. package/vendor/greenlock/lib/directory-url.js +44 -0
  28. package/vendor/greenlock/lib/init.js +191 -0
  29. package/vendor/greenlock/lib/manager-wrapper.js +625 -0
  30. package/vendor/greenlock/lib/rc.js +70 -0
  31. package/vendor/greenlock/logo/beaker-browser-301x112.png +0 -0
  32. package/vendor/greenlock/logo/from-not-secure-to-secure-url-bar.png +0 -0
  33. package/vendor/greenlock/logo/greenlock-1063x250.png +0 -0
  34. package/vendor/greenlock/logo/greenlock-850x200.png +0 -0
  35. package/vendor/greenlock/logo/ibm-301x112.png +0 -0
  36. package/vendor/greenlock/logo/telebit-301x112.png +0 -0
  37. package/vendor/greenlock/order.js +63 -0
  38. package/vendor/greenlock/package-lock.json +140 -0
  39. package/vendor/greenlock/package.json +56 -0
  40. package/vendor/greenlock/plugins.js +270 -0
  41. package/vendor/greenlock/tests/cli.sh +31 -0
  42. package/vendor/greenlock/tests/index.js +53 -0
  43. package/vendor/greenlock/user-events.js +7 -0
  44. package/vendor/greenlock/utils.js +281 -0
  45. package/vendor/greenlock-express/greenlock-shim.js +3 -1
  46. package/vendor/greenlock-express/package.json +0 -1
@@ -0,0 +1,324 @@
1
+ 'use strict';
2
+
3
+ var C = module.exports;
4
+ var U = require('./utils.js');
5
+ var CSR = require('@root/csr');
6
+ var Enc = require('@root/encoding');
7
+ var Keypairs = require('@root/keypairs');
8
+
9
+ var pending = {};
10
+ var rawPending = {};
11
+
12
+ // What the abbreviations mean
13
+ //
14
+ // gnlkc => greenlock
15
+ // mconf => manager config
16
+ // db => greenlock store instance
17
+ // acme => instance of ACME.js
18
+ // chs => instances of challenges
19
+ // acc => account
20
+ // args => site / extra options
21
+
22
+ // Certificates
23
+ C._getOrOrder = function(gnlck, mconf, db, acme, chs, acc, args) {
24
+ var email = args.subscriberEmail || mconf.subscriberEmail;
25
+
26
+ var id = args.altnames
27
+ .slice(0)
28
+ .sort()
29
+ .join(' ');
30
+ if (pending[id]) {
31
+ return pending[id];
32
+ }
33
+
34
+ pending[id] = C._rawGetOrOrder(
35
+ gnlck,
36
+ mconf,
37
+ db,
38
+ acme,
39
+ chs,
40
+ acc,
41
+ email,
42
+ args
43
+ )
44
+ .then(function(pems) {
45
+ delete pending[id];
46
+ return pems;
47
+ })
48
+ .catch(function(err) {
49
+ delete pending[id];
50
+ throw err;
51
+ });
52
+
53
+ return pending[id];
54
+ };
55
+
56
+ // Certificates
57
+ C._rawGetOrOrder = function(gnlck, mconf, db, acme, chs, acc, email, args) {
58
+ return C._check(gnlck, mconf, db, args).then(function(pems) {
59
+ // Nice and fresh? We're done!
60
+ if (pems) {
61
+ if (!C._isStale(gnlck, mconf, args, pems)) {
62
+ // return existing unexpired (although potentially stale) certificates when available
63
+ // there will be an additional .renewing property if the certs are being asynchronously renewed
64
+ //pems._type = 'current';
65
+ return pems;
66
+ }
67
+ }
68
+
69
+ // We're either starting fresh or freshening up...
70
+ var p = C._rawOrder(gnlck, mconf, db, acme, chs, acc, email, args);
71
+ var evname = pems ? 'cert_renewal' : 'cert_issue';
72
+ p.then(function(newPems) {
73
+ // notify in the background
74
+ var renewAt = C._renewWithStagger(gnlck, mconf, args, newPems);
75
+ gnlck._notify(evname, {
76
+ renewAt: renewAt,
77
+ subject: args.subject,
78
+ altnames: args.altnames
79
+ });
80
+ gnlck._notify('_cert_issue', {
81
+ renewAt: renewAt,
82
+ subject: args.subject,
83
+ altnames: args.altnames,
84
+ pems: newPems
85
+ });
86
+ }).catch(function(err) {
87
+ if (!err.context) {
88
+ err.context = evname;
89
+ }
90
+ err.subject = args.subject;
91
+ err.altnames = args.altnames;
92
+ gnlck._notify('error', err);
93
+ });
94
+
95
+ // No choice but to hang tight and wait for it
96
+ if (
97
+ !pems ||
98
+ pems.renewAt < Date.now() - 24 * 60 * 60 * 1000 ||
99
+ pems.expiresAt <= Date.now() + 24 * 60 * 60 * 1000
100
+ ) {
101
+ return p;
102
+ }
103
+
104
+ // Wait it out
105
+ // TODO should we call this waitForRenewal?
106
+ if (args.waitForRenewal) {
107
+ return p;
108
+ }
109
+
110
+ // Let the certs renew in the background
111
+ return pems;
112
+ });
113
+ };
114
+
115
+ // we have another promise here because it the optional renewal
116
+ // may resolve in a different stack than the returned pems
117
+ C._rawOrder = function(gnlck, mconf, db, acme, chs, acc, email, args) {
118
+ var id = args.altnames
119
+ .slice(0)
120
+ .sort()
121
+ .join(' ');
122
+ if (rawPending[id]) {
123
+ return rawPending[id];
124
+ }
125
+
126
+ var keyType = args.serverKeyType || mconf.serverKeyType;
127
+ var query = {
128
+ subject: args.subject,
129
+ certificate: args.certificate || {},
130
+ directoryUrl:
131
+ args.directoryUrl ||
132
+ mconf.directoryUrl ||
133
+ gnlck._defaults.directoryUrl
134
+ };
135
+ rawPending[id] = U._getOrCreateKeypair(db, args.subject, query, keyType)
136
+ .then(function(kresult) {
137
+ var serverKeypair = kresult.keypair;
138
+ var domains = args.altnames.slice(0);
139
+
140
+ return CSR.csr({
141
+ jwk: serverKeypair.privateKeyJwk || serverKeypair.private,
142
+ domains: domains,
143
+ encoding: 'der'
144
+ })
145
+ .then(function(csrDer) {
146
+ // TODO let CSR support 'urlBase64' ?
147
+ return Enc.bufToUrlBase64(csrDer);
148
+ })
149
+ .then(function(csr) {
150
+ function notify(ev, opts) {
151
+ gnlck._notify(ev, opts);
152
+ }
153
+ var certReq = {
154
+ debug: args.debug || gnlck._defaults.debug,
155
+
156
+ challenges: chs,
157
+ account: acc, // only used if accounts.key.kid exists
158
+ accountKey:
159
+ acc.keypair.privateKeyJwk || acc.keypair.private,
160
+ keypair: acc.keypair, // TODO
161
+ csr: csr,
162
+ domains: domains, // because ACME.js v3 uses `domains` still, actually
163
+ onChallengeStatus: notify,
164
+ notify: notify // TODO
165
+
166
+ // TODO handle this in acme-v2
167
+ //subject: args.subject,
168
+ //altnames: args.altnames.slice(0),
169
+ };
170
+ return acme.certificates
171
+ .create(certReq)
172
+ .then(U._attachCertInfo);
173
+ })
174
+ .then(function(pems) {
175
+ if (kresult.exists) {
176
+ return pems;
177
+ }
178
+ query.keypair = serverKeypair;
179
+ return db.setKeypair(query, serverKeypair).then(function() {
180
+ return pems;
181
+ });
182
+ });
183
+ })
184
+ .then(function(pems) {
185
+ // TODO put this in the docs
186
+ // { cert, chain, privkey, subject, altnames, issuedAt, expiresAt }
187
+ // Note: the query has been updated
188
+ query.pems = pems;
189
+ return db.set(query);
190
+ })
191
+ .then(function() {
192
+ return C._check(gnlck, mconf, db, args);
193
+ })
194
+ .then(function(bundle) {
195
+ // TODO notify Manager
196
+ delete rawPending[id];
197
+ return bundle;
198
+ })
199
+ .catch(function(err) {
200
+ // Todo notify manager
201
+ delete rawPending[id];
202
+ throw err;
203
+ });
204
+
205
+ return rawPending[id];
206
+ };
207
+
208
+ // returns pems, if they exist
209
+ C._check = function(gnlck, mconf, db, args) {
210
+ var query = {
211
+ subject: args.subject,
212
+ // may contain certificate.id
213
+ certificate: args.certificate,
214
+ directoryUrl:
215
+ args.directoryUrl ||
216
+ mconf.directoryUrl ||
217
+ gnlck._defaults.directoryUrl
218
+ };
219
+ return db.check(query).then(function(pems) {
220
+ if (!pems) {
221
+ return null;
222
+ }
223
+
224
+ pems = U._attachCertInfo(pems);
225
+
226
+ // For eager management
227
+ if (args.subject && !U._certHasDomain(pems, args.subject)) {
228
+ // TODO report error, but continue the process as with no cert
229
+ return null;
230
+ }
231
+
232
+ // For lazy SNI requests
233
+ if (args.domain && !U._certHasDomain(pems, args.domain)) {
234
+ // TODO report error, but continue the process as with no cert
235
+ return null;
236
+ }
237
+
238
+ return U._getKeypair(db, args.subject, query)
239
+ .then(function(keypair) {
240
+ return Keypairs.export({
241
+ jwk: keypair.privateKeyJwk || keypair.private,
242
+ encoding: 'pem'
243
+ }).then(function(pem) {
244
+ pems.privkey = pem;
245
+ return pems;
246
+ });
247
+ })
248
+ .catch(function() {
249
+ // TODO report error, but continue the process as with no cert
250
+ return null;
251
+ });
252
+ });
253
+ };
254
+
255
+ // Certificates
256
+ C._isStale = function(gnlck, mconf, args, pems) {
257
+ if (args.duplicate) {
258
+ return true;
259
+ }
260
+
261
+ var renewAt = C._renewableAt(gnlck, mconf, args, pems);
262
+
263
+ if (Date.now() >= renewAt) {
264
+ return true;
265
+ }
266
+
267
+ return false;
268
+ };
269
+
270
+ C._renewWithStagger = function(gnlck, mconf, args, pems) {
271
+ var renewOffset = C._renewOffset(gnlck, mconf, args, pems);
272
+ var renewStagger;
273
+ try {
274
+ renewStagger = U._parseDuration(
275
+ args.renewStagger || mconf.renewStagger || 0
276
+ );
277
+ } catch (e) {
278
+ renewStagger = U._parseDuration(
279
+ args.renewStagger || mconf.renewStagger
280
+ );
281
+ }
282
+
283
+ // TODO check this beforehand
284
+ if (!args.force && renewStagger / renewOffset >= 0.5) {
285
+ renewStagger = renewOffset * 0.1;
286
+ }
287
+
288
+ if (renewOffset > 0) {
289
+ // stagger forward, away from issued at
290
+ return Math.round(
291
+ pems.issuedAt + renewOffset + Math.random() * renewStagger
292
+ );
293
+ }
294
+
295
+ // stagger backward, toward issued at
296
+ return Math.round(
297
+ pems.expiresAt + renewOffset - Math.random() * renewStagger
298
+ );
299
+ };
300
+ C._renewOffset = function(gnlck, mconf, args /*, pems*/) {
301
+ var renewOffset = U._parseDuration(
302
+ args.renewOffset || mconf.renewOffset || 0
303
+ );
304
+ var week = 1000 * 60 * 60 * 24 * 6;
305
+ if (!args.force && Math.abs(renewOffset) < week) {
306
+ throw new Error(
307
+ 'developer error: `renewOffset` should always be at least a week, use `force` to not safety-check renewOffset'
308
+ );
309
+ }
310
+ return renewOffset;
311
+ };
312
+ C._renewableAt = function(gnlck, mconf, args, pems) {
313
+ if (args.renewAt) {
314
+ return args.renewAt;
315
+ }
316
+
317
+ var renewOffset = C._renewOffset(gnlck, mconf, args, pems);
318
+
319
+ if (renewOffset > 0) {
320
+ return pems.issuedAt + renewOffset;
321
+ }
322
+
323
+ return pems.expiresAt + renewOffset;
324
+ };
@@ -0,0 +1,58 @@
1
+ 'use strict';
2
+
3
+ var E = module.exports;
4
+
5
+ function create(code, msg) {
6
+ E[code] = function(ctx, msg2) {
7
+ var err = new Error(msg);
8
+ err.code = code;
9
+ err.context = ctx;
10
+ if (msg2) {
11
+ err.message += ': ' + msg2;
12
+ }
13
+ /*
14
+ Object.keys(extras).forEach(function(k) {
15
+ if ('message' === k) {
16
+ err.message += ': ' + extras[k];
17
+ } else {
18
+ err[k] = extras[k];
19
+ }
20
+ });
21
+ */
22
+ return err;
23
+ };
24
+ }
25
+
26
+ // TODO open issues and link to them as the error url
27
+ create(
28
+ 'NO_MAINTAINER',
29
+ 'please supply `maintainerEmail` as a contact for security and critical bug notices'
30
+ );
31
+ create(
32
+ 'BAD_ORDER',
33
+ 'altnames should be in deterministic order, with subject as the first altname'
34
+ );
35
+ create('NO_SUBJECT', 'no certificate subject given');
36
+ create(
37
+ 'NO_SUBSCRIBER',
38
+ 'please supply `subscriberEmail` as a contact for failed renewal and certificate revocation'
39
+ );
40
+ create(
41
+ 'INVALID_SUBSCRIBER',
42
+ '`subscriberEmail` is not a valid address, please check for typos'
43
+ );
44
+ create(
45
+ 'INVALID_HOSTNAME',
46
+ 'valid hostnames must be restricted to a-z0-9_.- and contain at least one "."'
47
+ );
48
+ create(
49
+ 'INVALID_DOMAIN',
50
+ 'one or more domains do not exist on public DNS SOA record'
51
+ );
52
+ create(
53
+ 'NOT_UNIQUE',
54
+ 'found duplicate domains, or a subdomain that overlaps a wildcard'
55
+ );
56
+
57
+ // exported for testing only
58
+ E._create = create;