emailengine-app 2.80.0 → 2.81.0
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.
- package/.dockerignore +44 -0
- package/.github/docker-smoke-test.sh +16 -0
- package/.github/workflows/deploy.yml +4 -0
- package/.github/workflows/release.yaml +4 -0
- package/.github/workflows/test.yml +2 -0
- package/.release-please-manifest.json +1 -1
- package/CHANGELOG.md +56 -0
- package/Dockerfile +17 -9
- package/README.md +6 -0
- package/data/google-crawlers.json +1 -1
- package/docker-compose.yml +7 -1
- package/lib/api-routes/account-routes.js +239 -73
- package/lib/api-routes/blocklist-routes.js +24 -0
- package/lib/api-routes/delivery-test-routes.js +6 -0
- package/lib/api-routes/gateway-routes.js +30 -0
- package/lib/api-routes/license-routes.js +10 -0
- package/lib/api-routes/mcp-oauth-routes.js +3 -3
- package/lib/api-routes/mcp-routes.js +39 -21
- package/lib/api-routes/oauth2-app-routes.js +38 -1
- package/lib/api-routes/outbox-routes.js +6 -0
- package/lib/api-routes/permission-map.js +212 -42
- package/lib/api-routes/pubsub-routes.js +8 -0
- package/lib/api-routes/route-helpers.js +58 -11
- package/lib/api-routes/settings-routes.js +50 -4
- package/lib/api-routes/stats-routes.js +6 -0
- package/lib/api-routes/template-routes.js +21 -0
- package/lib/api-routes/token-routes.js +34 -2
- package/lib/api-routes/webhook-route-routes.js +13 -0
- package/lib/autodetect-imap-settings.js +4 -4
- package/lib/email-client/base-client.js +6 -3
- package/lib/email-client/credential-errors.js +4 -0
- package/lib/email-client/imap/login-failure.js +52 -0
- package/lib/email-client/imap/subconnection.js +2 -1
- package/lib/email-client/imap-client.js +3 -6
- package/lib/enum-descriptions.js +12 -2
- package/lib/imapproxy/imap-server.js +1 -1
- package/lib/mcp/oauth.js +46 -8
- package/lib/mcp/protocol.js +78 -35
- package/lib/mcp/tools.js +53 -17
- package/lib/privileged-settings.js +147 -0
- package/lib/schemas.js +60 -16
- package/lib/sentry.js +13 -2
- package/lib/settings.js +13 -0
- package/lib/tls/catalog.js +428 -0
- package/lib/tls/context.js +87 -161
- package/lib/tls/listeners.js +62 -0
- package/lib/tls/provision.js +1 -1
- package/lib/tls/status.js +128 -79
- package/lib/tls/store.js +3 -2
- package/lib/token-permission-view.js +253 -102
- package/lib/token-permissions.js +176 -26
- package/lib/tokens.js +7 -6
- package/lib/tools.js +5 -3
- package/lib/ui-routes/account-routes.js +195 -61
- package/lib/ui-routes/admin-config-routes.js +41 -21
- package/lib/ui-routes/admin-entities-routes.js +32 -22
- package/lib/ui-routes/mcp-consent-routes.js +72 -31
- package/lib/ui-routes/tls-config-routes.js +121 -74
- package/package.json +16 -16
- package/sbom.json +1 -1
- package/server.js +7 -1
- package/static/css/flyonui.css +1 -1
- package/static/css/public.css +41 -0
- package/static/css/src/app.tailwind.css +135 -4
- package/static/js/public.js +218 -0
- package/static/js/ui.js +89 -36
- package/static/licenses.html +55 -37
- package/translations/README.md +4 -3
- package/translations/de.mo +0 -0
- package/translations/de.po +296 -185
- package/translations/en.po +220 -128
- package/translations/es.mo +0 -0
- package/translations/es.po +558 -0
- package/translations/et.mo +0 -0
- package/translations/et.po +288 -181
- package/translations/fr.mo +0 -0
- package/translations/fr.po +295 -183
- package/translations/it.mo +0 -0
- package/translations/it.po +558 -0
- package/translations/ja.mo +0 -0
- package/translations/ja.po +268 -192
- package/translations/locales.json +24 -0
- package/translations/messages.pot +179 -127
- package/translations/nl.mo +0 -0
- package/translations/nl.po +288 -175
- package/translations/pl.mo +0 -0
- package/translations/pl.po +294 -181
- package/translations/sv.mo +0 -0
- package/translations/sv.po +555 -0
- package/translations/tr.mo +0 -0
- package/translations/tr.po +555 -0
- package/update-info.sh +12 -6
- package/views/account/login-redirect.hbs +6 -5
- package/views/account/passkeys.hbs +8 -8
- package/views/account/security.hbs +2 -2
- package/views/accounts/account.hbs +19 -21
- package/views/accounts/browse.hbs +1 -1
- package/views/accounts/edit.hbs +15 -15
- package/views/accounts/index.hbs +3 -3
- package/views/accounts/register/imap-server.hbs +27 -173
- package/views/accounts/register/validating.hbs +139 -0
- package/views/config/ai.hbs +15 -17
- package/views/config/branding.hbs +7 -7
- package/views/config/document-store/chat.hbs +9 -8
- package/views/config/document-store/index.hbs +14 -15
- package/views/config/document-store/mappings/index.hbs +5 -6
- package/views/config/document-store/mappings/new.hbs +1 -2
- package/views/config/document-store/pre-processing/index.hbs +4 -4
- package/views/config/email-processing.hbs +6 -6
- package/views/config/imap-proxy.hbs +7 -8
- package/views/config/license.hbs +9 -9
- package/views/config/logging.hbs +5 -7
- package/views/config/mcp.hbs +90 -58
- package/views/config/network.hbs +4 -4
- package/views/config/oauth/app.hbs +12 -12
- package/views/config/oauth/index.hbs +6 -6
- package/views/config/oauth/subscriptions.hbs +9 -9
- package/views/config/security.hbs +5 -7
- package/views/config/service.hbs +11 -10
- package/views/config/smtp.hbs +9 -12
- package/views/config/tls-upload.hbs +3 -3
- package/views/config/tls.hbs +281 -182
- package/views/config/webhooks.hbs +12 -15
- package/views/dashboard.hbs +9 -8
- package/views/gateways/edit.hbs +3 -3
- package/views/gateways/gateway.hbs +3 -3
- package/views/gateways/index.hbs +6 -6
- package/views/gateways/new.hbs +3 -3
- package/views/internals/index.hbs +15 -13
- package/views/layout/app.hbs +6 -6
- package/views/layout/login.hbs +32 -19
- package/views/layout/main.hbs +2 -2
- package/views/layout/prompt.hbs +15 -18
- package/views/layout/public.hbs +1 -1
- package/views/mcp/authorize.hbs +47 -45
- package/views/partials/accounts_table.hbs +5 -5
- package/views/partials/ace_assets.hbs +1 -1
- package/views/partials/add_account_modal.hbs +4 -4
- package/views/partials/address_list.hbs +4 -4
- package/views/partials/filter_editor_js.hbs +2 -2
- package/views/partials/gateway_form.hbs +5 -5
- package/views/partials/gateway_js.hbs +1 -1
- package/views/partials/mcp_access_levels.hbs +16 -9
- package/views/partials/mcp_account_limit.hbs +2 -2
- package/views/partials/mcp_tool_count.hbs +15 -14
- package/views/partials/oauth_config_header.hbs +2 -2
- package/views/partials/oauth_form.hbs +37 -42
- package/views/partials/public_alerts.hbs +1 -1
- package/views/partials/public_test_labels.hbs +15 -0
- package/views/partials/public_theme_init.hbs +1 -1
- package/views/partials/security_header.hbs +2 -2
- package/views/partials/template_form.hbs +4 -4
- package/views/partials/theme_init.hbs +1 -1
- package/views/partials/tls_security_card.hbs +4 -1
- package/views/partials/ui/form-field.hbs +6 -1
- package/views/partials/ui/setting-ref.hbs +12 -7
- package/views/partials/ui/stat-card.hbs +4 -1
- package/views/partials/ui/tabs.hbs +3 -7
- package/views/partials/webhook_form.hbs +9 -12
- package/views/partials/webhooks_editor_functions.hbs +1 -1
- package/views/reference/index.hbs +3 -3
- package/views/reference/redirect.hbs +1 -1
- package/views/reference/tag.hbs +1 -1
- package/views/reference/token.hbs +4 -4
- package/views/suppression-lists/index.hbs +8 -6
- package/views/suppression-lists/list.hbs +13 -8
- package/views/templates/edit.hbs +1 -1
- package/views/templates/index.hbs +10 -11
- package/views/templates/template.hbs +5 -5
- package/views/tokens/index.hbs +17 -17
- package/views/tokens/new.hbs +190 -93
- package/views/unsubscribe.hbs +1 -1
- package/views/webhooks/edit.hbs +1 -1
- package/views/webhooks/index.hbs +10 -11
- package/views/webhooks/new.hbs +1 -1
- package/views/webhooks/webhook.hbs +5 -6
- package/workers/api.js +9 -8
- package/workers/smtp.js +1 -1
package/lib/tls/context.js
CHANGED
|
@@ -13,6 +13,9 @@
|
|
|
13
13
|
// hostname are usually different names, and a client connecting to smtp.example.com has to be
|
|
14
14
|
// offered a certificate for smtp.example.com, not for the admin UI's.
|
|
15
15
|
//
|
|
16
|
+
// Which certificate answers which name, and which one is the listener's default, is decided by
|
|
17
|
+
// lib/tls/catalog.js (listenerView()); this module only turns that view into secure contexts.
|
|
18
|
+
//
|
|
16
19
|
// Everything a handshake needs is computed in refresh(): the certificates are parsed once there,
|
|
17
20
|
// not per connection. The SNI callback is on the accept path of the SMTP server, the IMAP proxy
|
|
18
21
|
// and the API's HTTPS listener, so anything it does is done once per client.
|
|
@@ -22,16 +25,9 @@ const config = require('@zone-eu/wild-config');
|
|
|
22
25
|
|
|
23
26
|
const settings = require('../settings');
|
|
24
27
|
const { hasEnvValue, readEnvValue, getBoolean } = require('../tools');
|
|
25
|
-
const {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
getSelfSignedCertificate,
|
|
29
|
-
getAcmeCertificate,
|
|
30
|
-
parseCertificate,
|
|
31
|
-
coversHostname,
|
|
32
|
-
describeX509,
|
|
33
|
-
normalizeHostname
|
|
34
|
-
} = require('./store');
|
|
28
|
+
const { hostnamesFrom, getSelfSignedCertificate, parseCertificate, describeX509 } = require('./store');
|
|
29
|
+
const { TLS_CERTIFICATE_SETTINGS, SELF_SIGNED_ID, listenerByKey } = require('./listeners');
|
|
30
|
+
const { sourcesFor, listCertificates, entryForName, listenerView } = require('./catalog');
|
|
35
31
|
|
|
36
32
|
/**
|
|
37
33
|
* The certificate plus whatever chain came with it, which is what a TLS context wants.
|
|
@@ -87,83 +83,29 @@ function handshakeOptionsFrom(source) {
|
|
|
87
83
|
return options;
|
|
88
84
|
}
|
|
89
85
|
|
|
90
|
-
// Which stored sources the operator's choice admits. The setting is the certificate SOURCE, so it
|
|
91
|
-
// has to decide what is served and not only whether an order is placed: picking "self-signed only"
|
|
92
|
-
// while a Let's Encrypt certificate was still being served is the same class of bug this rework
|
|
93
|
-
// exists to remove - the UI describing behaviour the code does not have.
|
|
94
|
-
//
|
|
95
|
-
// Material from the environment is admitted by every mode. It is not a source EmailEngine chose.
|
|
96
|
-
const MODE_SOURCES = {
|
|
97
|
-
acme: { manual: true, acme: true },
|
|
98
|
-
manual: { manual: true, acme: false },
|
|
99
|
-
'self-signed': { manual: false, acme: false }
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
function sourcesFor(mode) {
|
|
103
|
-
return MODE_SOURCES[mode] || MODE_SOURCES.acme;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Material for one name, in the precedence order lib/tls/store.js documents. The self-signed
|
|
108
|
-
* fallback is not here: it covers every configured name at once and is resolved by the caller when
|
|
109
|
-
* nothing else answered.
|
|
110
|
-
*
|
|
111
|
-
* @param {Object} opts
|
|
112
|
-
* @param {Object} [opts.certs] @postalsys/certs handler, or null to skip the ACME source
|
|
113
|
-
* @param {string} opts.hostname Name being resolved
|
|
114
|
-
* @param {Object} [opts.sources] Which stored sources the configured mode admits
|
|
115
|
-
* @param {Object} [opts.env] Material from the environment or config file
|
|
116
|
-
* @param {Object} [opts.envX509] That certificate, parsed once
|
|
117
|
-
* @param {Object} [opts.manual] Pre-loaded uploaded certificate, so one lookup serves every name
|
|
118
|
-
* @param {Object} [opts.manualX509] That certificate, parsed once
|
|
119
|
-
* @param {Object} [opts.logger] Logger for a stored certificate that could not be read
|
|
120
|
-
* @returns {Promise<Object|false>} Material, or false when only the fallback is left
|
|
121
|
-
*/
|
|
122
|
-
async function resolveHostname(opts) {
|
|
123
|
-
const { certs, hostname, env, envX509, manual, manualX509, logger } = opts;
|
|
124
|
-
const sources = opts.sources || sourcesFor('acme');
|
|
125
|
-
|
|
126
|
-
// An explicit instruction from the operator, and the only source not stored in Redis. Applied
|
|
127
|
-
// per name like every other source: a listener told to serve one certificate should still
|
|
128
|
-
// offer a second configured hostname the certificate that actually covers it.
|
|
129
|
-
if (env && coversHostname(envX509, hostname)) {
|
|
130
|
-
return env;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
if (sources.manual && manual && coversHostname(manualX509, hostname)) {
|
|
134
|
-
return manual;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
if (sources.acme) {
|
|
138
|
-
return (await getAcmeCertificate(certs, hostname, logger)) || false;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
return false;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
86
|
/**
|
|
145
87
|
* Builds a listener's TLS material and keeps it refreshable.
|
|
146
88
|
*
|
|
147
89
|
* @param {Object} opts
|
|
148
90
|
* @param {Object} [opts.certs] @postalsys/certs handler
|
|
149
91
|
* @param {Object} opts.logger Worker logger
|
|
150
|
-
* @param {
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
92
|
+
* @param {string} [opts.listener] Which listener this is (`api`, `smtp`, `imapProxy`): whose
|
|
93
|
+
* environment material is its own, and which setting holds the
|
|
94
|
+
* certificate it presents by default
|
|
95
|
+
* @param {Object} [opts.listenerOptions] The listener's own TLS options, for the handshake
|
|
96
|
+
* settings (ciphers, version bounds, a client CA). The
|
|
97
|
+
* certificate material in them is read from the environment
|
|
98
|
+
* by the catalog instead, so every worker sees the same bytes
|
|
154
99
|
* @returns {Promise<Object>} `{ options, active, source, refresh() }`
|
|
155
100
|
*/
|
|
156
101
|
async function createTlsContext(opts) {
|
|
157
102
|
const { certs, logger } = opts || {};
|
|
158
|
-
const
|
|
103
|
+
const listener = (opts && listenerByKey(opts.listener)) || null;
|
|
159
104
|
|
|
160
|
-
//
|
|
161
|
-
//
|
|
162
|
-
//
|
|
163
|
-
const handshake = handshakeOptionsFrom(listenerOptions);
|
|
164
|
-
const envMaterial =
|
|
165
|
-
(opts && opts.envMaterial) ||
|
|
166
|
-
(listenerOptions ? { cert: listenerOptions.cert, key: listenerOptions.key, ca: listenerOptions.ca, passphrase: listenerOptions.passphrase } : null);
|
|
105
|
+
// Snapshotted here rather than read per refresh: a listener writes the resolved options back
|
|
106
|
+
// into the same object it passed in, so re-reading it later would mean reading this module's
|
|
107
|
+
// own output back as if the operator had configured it.
|
|
108
|
+
const handshake = handshakeOptionsFrom((opts && opts.listenerOptions) || null);
|
|
167
109
|
|
|
168
110
|
// The state the SNI callback reads. Replaced wholesale by refresh(), so a handshake either sees
|
|
169
111
|
// the previous set or the new one, never a half-built one.
|
|
@@ -179,35 +121,32 @@ async function createTlsContext(opts) {
|
|
|
179
121
|
const secureContextOptions = material =>
|
|
180
122
|
Object.assign({}, handshake, { cert: fullChain(material), key: material.privateKey, passphrase: material.passphrase });
|
|
181
123
|
|
|
182
|
-
|
|
124
|
+
// A catalog entry with a context built for it. The self-signed entry is listed without
|
|
125
|
+
// material until something needs it, and generated material may be newer than what the
|
|
126
|
+
// catalog peeked, so the material is parsed again here rather than taken off the entry.
|
|
127
|
+
const buildEntry = (entry, material) => {
|
|
183
128
|
try {
|
|
184
129
|
return {
|
|
185
|
-
|
|
130
|
+
id: entry.id,
|
|
186
131
|
material,
|
|
187
132
|
x509: parseCertificate(material.cert),
|
|
188
133
|
context: tls.createSecureContext(secureContextOptions(material))
|
|
189
134
|
};
|
|
190
135
|
} catch (err) {
|
|
191
136
|
if (logger) {
|
|
192
|
-
logger.error({ msg: 'Failed to build a TLS context',
|
|
137
|
+
logger.error({ msg: 'Failed to build a TLS context', id: entry.id, source: material.source, err });
|
|
193
138
|
}
|
|
194
139
|
return null;
|
|
195
140
|
}
|
|
196
141
|
};
|
|
197
142
|
|
|
198
143
|
// Stable across refreshes, so the options object handed to a listener stays valid while the
|
|
199
|
-
// material behind it is replaced.
|
|
144
|
+
// material behind it is replaced. The rule is entryForName(): the default certificate for
|
|
145
|
+
// every name it covers and for a client that names none, otherwise the certificate resolved
|
|
146
|
+
// for the name, otherwise the default again.
|
|
200
147
|
const contextFor = servername => {
|
|
201
|
-
const
|
|
202
|
-
|
|
203
|
-
if (name) {
|
|
204
|
-
const match = state.entries.find(entry => coversHostname(entry.x509, name));
|
|
205
|
-
if (match) {
|
|
206
|
-
return match.context;
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
return state.fallback && state.fallback.context;
|
|
148
|
+
const entry = entryForName(servername, state);
|
|
149
|
+
return entry ? entry.context : null;
|
|
211
150
|
};
|
|
212
151
|
|
|
213
152
|
const sniCallback = (servername, cb) => {
|
|
@@ -216,75 +155,62 @@ async function createTlsContext(opts) {
|
|
|
216
155
|
};
|
|
217
156
|
|
|
218
157
|
const refresh = async () => {
|
|
219
|
-
const
|
|
220
|
-
envMaterial && envMaterial.cert && envMaterial.key
|
|
221
|
-
? {
|
|
222
|
-
source: 'env',
|
|
223
|
-
cert: envMaterial.cert,
|
|
224
|
-
ca: [].concat(envMaterial.ca || []).filter(entry => entry),
|
|
225
|
-
privateKey: envMaterial.key,
|
|
226
|
-
passphrase: envMaterial.passphrase
|
|
227
|
-
}
|
|
228
|
-
: null;
|
|
229
|
-
const envX509 = env ? parseCertificate(env.cert) : null;
|
|
230
|
-
|
|
231
|
-
// The uploaded certificate is loaded whether or not the environment supplied one: both are
|
|
232
|
-
// applied per name, so a listener pinned to one certificate still has to offer a second
|
|
233
|
-
// configured hostname the uploaded certificate that covers it.
|
|
234
|
-
const [hostnames, mode, manual] = await Promise.all([getCertificateHostnames(), settings.get('tlsProvisioning'), getManualCertificate()]);
|
|
235
|
-
|
|
236
|
-
const sources = sourcesFor(mode);
|
|
237
|
-
const manualX509 = manual ? parseCertificate(manual.cert) : null;
|
|
238
|
-
|
|
239
|
-
// Resolved concurrently: each hostname is an independent pair of Redis reads and a key
|
|
240
|
-
// decrypt, and this runs before the listener binds its port in every worker that serves
|
|
241
|
-
// TLS. Order is preserved, which is what makes entries[0] the primary name.
|
|
242
|
-
const resolved = await Promise.all(hostnames.map(hostname => resolveHostname({ certs, hostname, sources, env, envX509, manual, manualX509, logger })));
|
|
243
|
-
|
|
244
|
-
const entries = [];
|
|
245
|
-
for (let i = 0; i < hostnames.length; i++) {
|
|
246
|
-
if (!resolved[i]) {
|
|
247
|
-
continue;
|
|
248
|
-
}
|
|
249
|
-
const entry = buildEntry(hostnames[i], resolved[i]);
|
|
250
|
-
if (entry) {
|
|
251
|
-
entries.push(entry);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
158
|
+
const values = await settings.getMulti('serviceUrl', 'tlsHostnames', 'tlsProvisioning', ...TLS_CERTIFICATE_SETTINGS);
|
|
254
159
|
|
|
255
|
-
|
|
256
|
-
// In order: the certificate for the primary name; then material the operator supplied, even
|
|
257
|
-
// when it covers none of the configured names, because they configured this listener with
|
|
258
|
-
// it on purpose; then any certificate at all; then the self-signed fallback, because a
|
|
259
|
-
// listener that has been switched on has to start. Decided before the self-signed entry
|
|
260
|
-
// joins the list, so it stays the last resort for the default context too.
|
|
261
|
-
let fallback = entries.find(entry => coversHostname(entry.x509, hostnames[0])) || null;
|
|
160
|
+
const hostnames = hostnamesFrom(values);
|
|
262
161
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
}
|
|
162
|
+
// Everything the instance holds, with keys: this is the one read of the stores per
|
|
163
|
+
// refresh, and it runs before the listener binds its port
|
|
164
|
+
const catalog = await listCertificates({ certs, hostnames, logger, withPrivateKey: true });
|
|
266
165
|
|
|
267
|
-
|
|
268
|
-
|
|
166
|
+
const view = listenerView({
|
|
167
|
+
catalog,
|
|
168
|
+
hostnames,
|
|
169
|
+
sources: sourcesFor(values.tlsProvisioning),
|
|
170
|
+
listener: listener && listener.key,
|
|
171
|
+
requested: listener ? values[listener.settingKey] : null
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
if (view.selection === 'missing' && logger) {
|
|
175
|
+
logger.warn({
|
|
176
|
+
msg: 'The certificate this listener was told to present no longer exists, presenting the automatic choice',
|
|
177
|
+
listener: listener && listener.key,
|
|
178
|
+
requested: view.requested,
|
|
179
|
+
fallback: view.fallback && view.fallback.id
|
|
180
|
+
});
|
|
269
181
|
}
|
|
270
182
|
|
|
271
|
-
//
|
|
272
|
-
//
|
|
273
|
-
//
|
|
274
|
-
//
|
|
275
|
-
//
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
entries.push(selfSigned);
|
|
284
|
-
fallback = fallback || selfSigned;
|
|
183
|
+
// Generated only when something needs it - as the default, or for a name nothing else
|
|
184
|
+
// covers: once every name has a certificate of its own there is nothing for it to answer
|
|
185
|
+
// for, and generating it anyway would put a certificate on the page that no listener
|
|
186
|
+
// serves. The store hands back what it holds, or replaces one that no longer covers the
|
|
187
|
+
// configured names.
|
|
188
|
+
let selfSigned = view.needsSelfSigned ? await getSelfSignedCertificate(hostnames, logger) : null;
|
|
189
|
+
const materialOf = entry => (entry.id === SELF_SIGNED_ID ? selfSigned : entry.material);
|
|
190
|
+
|
|
191
|
+
const built = new Map();
|
|
192
|
+
const build = entry => {
|
|
193
|
+
if (!entry || !materialOf(entry)) {
|
|
194
|
+
return null;
|
|
285
195
|
}
|
|
196
|
+
if (!built.has(entry.id)) {
|
|
197
|
+
built.set(entry.id, buildEntry(entry, materialOf(entry)));
|
|
198
|
+
}
|
|
199
|
+
return built.get(entry.id);
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
let fallback = build(view.fallback);
|
|
203
|
+
|
|
204
|
+
// A default whose context cannot be built - an encrypted operator key with no passphrase
|
|
205
|
+
// - has been reported above; the listener still starts, on the fallback, rather than
|
|
206
|
+
// refusing to bind with nothing to serve
|
|
207
|
+
if (!fallback) {
|
|
208
|
+
selfSigned = selfSigned || (await getSelfSignedCertificate(hostnames, logger));
|
|
209
|
+
fallback = build(catalog.find(entry => entry.id === SELF_SIGNED_ID));
|
|
286
210
|
}
|
|
287
211
|
|
|
212
|
+
const entries = view.entries.map(build).filter(entry => entry);
|
|
213
|
+
|
|
288
214
|
state = {
|
|
289
215
|
hostnames,
|
|
290
216
|
entries,
|
|
@@ -312,22 +238,22 @@ async function createTlsContext(opts) {
|
|
|
312
238
|
return (state.fallback && state.fallback.material.source) || null;
|
|
313
239
|
},
|
|
314
240
|
|
|
315
|
-
// What the listener is serving, for the admin UI's listener table and the state
|
|
241
|
+
// What the listener is serving by default, for the admin UI's listener table and the state
|
|
242
|
+
// payload. The store's own shape rather than a hand-picked subset of it: the page that
|
|
243
|
+
// renders this reports a certificate that is not valid yet and lists the names it covers.
|
|
316
244
|
get active() {
|
|
317
245
|
if (!state.fallback) {
|
|
318
246
|
return null;
|
|
319
247
|
}
|
|
320
248
|
|
|
321
|
-
|
|
322
|
-
// this reports a certificate that is not valid yet and lists the names it covers, and
|
|
323
|
-
// neither field was here to report.
|
|
249
|
+
const material = state.fallback.material;
|
|
324
250
|
return Object.assign(
|
|
325
251
|
{
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
//
|
|
329
|
-
|
|
330
|
-
|
|
252
|
+
id: state.fallback.id,
|
|
253
|
+
source: material.source,
|
|
254
|
+
// What the id is made of, so a page can name the certificate without the store
|
|
255
|
+
listener: material.listener || null,
|
|
256
|
+
hostname: material.hostname || null
|
|
331
257
|
},
|
|
332
258
|
describeX509(state.fallback.x509) || {}
|
|
333
259
|
);
|
|
@@ -373,4 +299,4 @@ async function applyTlsContext(opts) {
|
|
|
373
299
|
return { updated: true, tls: active };
|
|
374
300
|
}
|
|
375
301
|
|
|
376
|
-
module.exports = { createTlsContext, applyTlsContext,
|
|
302
|
+
module.exports = { createTlsContext, applyTlsContext, apiTlsConfig };
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// The listeners that terminate TLS, and the grammar of a certificate id. Nothing else: this is
|
|
4
|
+
// required by lib/tools.js (the reload contract), lib/schemas.js (the settings schema) and
|
|
5
|
+
// lib/tls/catalog.js alike, so it must not require any of them back.
|
|
6
|
+
//
|
|
7
|
+
// Ids are stable strings, because they are stored in settings and posted by forms:
|
|
8
|
+
//
|
|
9
|
+
// env:api, env:smtp, env:imapProxy material from that listener's environment prefix or the
|
|
10
|
+
// config file
|
|
11
|
+
// manual the certificate uploaded through the admin UI
|
|
12
|
+
// acme:<hostname> the Let's Encrypt certificate for that configured name
|
|
13
|
+
// self-signed the generated fallback covering every configured name
|
|
14
|
+
//
|
|
15
|
+
// `auto` is not an id: it is what a listener's setting holds when EmailEngine is to decide.
|
|
16
|
+
|
|
17
|
+
// In the order the page lists them. `settingKey` holds the id of the certificate that listener
|
|
18
|
+
// presents by default; `envPrefix` is where its own operator-supplied material comes from.
|
|
19
|
+
const LISTENERS = Object.freeze([
|
|
20
|
+
Object.freeze({
|
|
21
|
+
key: 'api',
|
|
22
|
+
name: 'Admin UI and API',
|
|
23
|
+
// No page of its own: TLS for this listener is an environment switch, not a setting
|
|
24
|
+
configuredAt: null,
|
|
25
|
+
envPrefix: 'EENGINE_API_TLS_',
|
|
26
|
+
envNote: 'EENGINE_API_TLS_* or [api.tls] in the config file',
|
|
27
|
+
settingKey: 'apiTLSCertificate'
|
|
28
|
+
}),
|
|
29
|
+
Object.freeze({
|
|
30
|
+
key: 'smtp',
|
|
31
|
+
name: 'SMTP server',
|
|
32
|
+
configuredAt: '/admin/config/smtp',
|
|
33
|
+
envPrefix: 'EENGINE_SMTP_TLS_',
|
|
34
|
+
envNote: 'EENGINE_SMTP_TLS_*',
|
|
35
|
+
settingKey: 'smtpServerTLSCertificate'
|
|
36
|
+
}),
|
|
37
|
+
Object.freeze({
|
|
38
|
+
key: 'imapProxy',
|
|
39
|
+
name: 'IMAP proxy',
|
|
40
|
+
configuredAt: '/admin/config/imap-proxy',
|
|
41
|
+
envPrefix: 'EENGINE_IMAPPROXY_TLS_',
|
|
42
|
+
envNote: 'EENGINE_IMAPPROXY_TLS_*',
|
|
43
|
+
settingKey: 'imapProxyServerTLSCertificate'
|
|
44
|
+
})
|
|
45
|
+
]);
|
|
46
|
+
|
|
47
|
+
// The settings that name each listener's default certificate
|
|
48
|
+
const TLS_CERTIFICATE_SETTINGS = Object.freeze(LISTENERS.map(listener => listener.settingKey));
|
|
49
|
+
|
|
50
|
+
const AUTO = 'auto';
|
|
51
|
+
const MANUAL_ID = 'manual';
|
|
52
|
+
const SELF_SIGNED_ID = 'self-signed';
|
|
53
|
+
|
|
54
|
+
// What a setting may hold. The acme part is a hostname the way the certificate stores spell one,
|
|
55
|
+
// lower-cased; the listener part is case-sensitive because the ids are, and a form never types them.
|
|
56
|
+
const CERTIFICATE_ID_PATTERN = /^(auto|manual|self-signed|env:(api|smtp|imapProxy)|acme:[a-z0-9._:-]+)$/;
|
|
57
|
+
|
|
58
|
+
function listenerByKey(key) {
|
|
59
|
+
return LISTENERS.find(listener => listener.key === key) || null;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
module.exports = { LISTENERS, TLS_CERTIFICATE_SETTINGS, AUTO, MANUAL_ID, SELF_SIGNED_ID, CERTIFICATE_ID_PATTERN, listenerByKey };
|
package/lib/tls/provision.js
CHANGED
|
@@ -420,7 +420,7 @@ async function requestProvisioning(opts) {
|
|
|
420
420
|
if (mode !== 'acme') {
|
|
421
421
|
reason = 'Automatic certificates are switched off for this instance';
|
|
422
422
|
} else if (!eligible.includes(hostname)) {
|
|
423
|
-
reason = `Let's Encrypt
|
|
423
|
+
reason = `Let's Encrypt cannot validate ${hostname}. Automatic certificates need a public domain name.`;
|
|
424
424
|
} else if (inFlight.has(hostname)) {
|
|
425
425
|
// Already ordering. Saying so beats silently starting a second order, and beats
|
|
426
426
|
// overwriting the state the running order is reporting through.
|