emailengine-app 2.79.8 → 2.80.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/.github/dependabot.yml +22 -0
- package/.github/workflows/test.yml +39 -0
- package/.release-please-manifest.json +1 -1
- package/CHANGELOG.md +69 -0
- package/DOCKER_DEPLOYMENT.md +6 -7
- package/Dockerfile +35 -11
- package/config/default.toml +7 -2
- package/copy-static-files.sh +23 -5
- package/data/google-crawlers.json +1 -1
- package/encrypt.js +43 -0
- package/lib/account/account-state.js +62 -0
- package/lib/account.js +60 -3
- package/lib/api-routes/account-routes.js +20 -0
- package/lib/api-routes/bull-board-routes.js +3 -2
- package/lib/api-routes/index.js +1 -1
- package/lib/api-routes/route-helpers.js +8 -0
- package/lib/api-routes/settings-routes.js +17 -2
- package/lib/auth-token.js +73 -2
- package/lib/autodetect-imap-settings.js +379 -69
- package/lib/cert-handler.js +62 -0
- package/lib/consts.js +58 -7
- package/lib/db.js +12 -0
- package/lib/egress-fetch.js +145 -0
- package/lib/email-client/base-client.js +234 -66
- package/lib/email-client/credential-errors.js +118 -0
- package/lib/email-client/gmail/gmail-api.js +2 -1
- package/lib/email-client/gmail-client.js +70 -64
- package/lib/email-client/imap/connection-errors.js +52 -0
- package/lib/email-client/imap/listing-diff.js +47 -6
- package/lib/email-client/imap/mailbox.js +457 -379
- package/lib/email-client/imap/subconnection.js +15 -11
- package/lib/email-client/imap/sync-operations.js +46 -59
- package/lib/email-client/imap-client.js +136 -95
- package/lib/email-client/message-builder.js +11 -11
- package/lib/email-client/outlook/graph-api.js +2 -1
- package/lib/email-client/outlook-client.js +219 -106
- package/lib/export.js +35 -2
- package/lib/handlebars-helpers.js +129 -0
- package/lib/imap-proxy-auth.js +96 -21
- package/lib/imapproxy/imap-core/README.md +1 -0
- package/lib/imapproxy/imap-core/lib/tls-options.js +5 -46
- package/lib/imapproxy/imap-server.js +56 -66
- package/lib/lua/h-del-if-equals.lua +39 -0
- package/lib/lua/h-set-if-equals.lua +39 -0
- package/lib/openapi/index.js +3 -0
- package/lib/outbox.js +28 -3
- package/lib/rate-limit.js +23 -4
- package/lib/routes-ui.js +4 -34
- package/lib/schemas.js +42 -3
- package/lib/security-headers.js +411 -0
- package/lib/sentry.js +36 -4
- package/lib/smtp-auth.js +86 -7
- package/lib/tls/context.js +376 -0
- package/lib/tls/der.js +223 -0
- package/lib/tls/provision.js +555 -0
- package/lib/tls/self-signed.js +282 -0
- package/lib/tls/status.js +431 -0
- package/lib/tls/store.js +666 -0
- package/lib/tools.js +337 -147
- package/lib/ui-routes/account-routes.js +47 -33
- package/lib/ui-routes/admin-config-routes.js +22 -1
- package/lib/ui-routes/auth-routes.js +16 -1
- package/lib/ui-routes/export-routes.js +4 -0
- package/lib/ui-routes/internals-routes.js +3 -5
- package/lib/ui-routes/mcp-consent-routes.js +7 -0
- package/lib/ui-routes/network-config-routes.js +58 -48
- package/lib/ui-routes/route-helpers.js +24 -8
- package/lib/ui-routes/smtp-test-routes.js +7 -0
- package/lib/ui-routes/tls-config-routes.js +581 -0
- package/lib/utils/mailbox-path.js +51 -0
- package/lib/utils/severity.js +31 -0
- package/lib/webhook-egress.js +5 -0
- package/package.json +21 -24
- package/sbom.json +1 -1
- package/server.js +53 -36
- package/static/css/flyonui.css +1 -1
- package/static/css/src/app.tailwind.css +11 -0
- package/static/js/ace/css/ace.css +1462 -0
- package/static/js/ace/css/kuroir-1.png +0 -0
- package/static/js/ace/css/kuroir-2.png +0 -0
- package/static/js/ace/css/main-1.png +0 -0
- package/static/js/ace/css/main-10.svg +4 -0
- package/static/js/ace/css/main-11.svg +5 -0
- package/static/js/ace/css/main-12.svg +4 -0
- package/static/js/ace/css/main-13.png +0 -0
- package/static/js/ace/css/main-14.png +0 -0
- package/static/js/ace/css/main-15.png +0 -0
- package/static/js/ace/css/main-16.png +0 -0
- package/static/js/ace/css/main-17.png +0 -0
- package/static/js/ace/css/main-18.png +0 -0
- package/static/js/ace/css/main-19.png +0 -0
- package/static/js/ace/css/main-2.png +0 -0
- package/static/js/ace/css/main-20.png +0 -0
- package/static/js/ace/css/main-21.png +0 -0
- package/static/js/ace/css/main-22.png +0 -0
- package/static/js/ace/css/main-23.png +0 -0
- package/static/js/ace/css/main-24.png +0 -0
- package/static/js/ace/css/main-25.svg +1 -0
- package/static/js/ace/css/main-26.png +0 -0
- package/static/js/ace/css/main-3.png +0 -0
- package/static/js/ace/css/main-4.png +0 -0
- package/static/js/ace/css/main-5.svg +7 -0
- package/static/js/ace/css/main-6.svg +9 -0
- package/static/js/ace/css/main-7.svg +7 -0
- package/static/js/ace/css/main-8.svg +9 -0
- package/static/js/ace/css/main-9.svg +6 -0
- package/static/js/ace/css/theme/kuroir.css +78 -0
- package/static/js/ace/css/theme/tomorrow_night.css +128 -0
- package/static/js/ace/css/theme/tomorrow_night_eighties.css +128 -0
- package/static/js/ace/css/theme/xcode.css +106 -0
- package/static/js/ace/css/tomorrow_night-1.png +0 -0
- package/static/js/ace/css/tomorrow_night-2.png +0 -0
- package/static/js/ace/css/tomorrow_night_eighties-1.png +0 -0
- package/static/js/ace/css/tomorrow_night_eighties-2.png +0 -0
- package/static/js/ace/css/xcode-1.png +0 -0
- package/static/js/ace/css/xcode-2.png +0 -0
- package/static/js/app.js +34 -0
- package/static/js/ee-client.js +256 -102
- package/static/js/public.js +13 -2
- package/static/js/ui.js +40 -25
- package/static/licenses.html +393 -1282
- package/static/vendor/simplewebauthn/browser.min.js +2 -2
- package/translations/messages.pot +203 -157
- package/views/account/login-redirect.hbs +22 -0
- package/views/accounts/account.hbs +15 -37
- package/views/accounts/browse.hbs +3 -1
- package/views/accounts/edit.hbs +1 -1
- package/views/accounts/register/imap-server.hbs +1 -1
- package/views/config/ai.hbs +1 -1
- package/views/config/branding.hbs +2 -2
- package/views/config/document-store/chat.hbs +1 -1
- package/views/config/document-store/index.hbs +1 -1
- package/views/config/imap-proxy.hbs +1 -4
- package/views/config/license.hbs +1 -1
- package/views/config/mcp.hbs +1 -1
- package/views/config/network.hbs +14 -16
- package/views/config/oauth/app.hbs +2 -2
- package/views/config/service.hbs +1 -1
- package/views/config/smtp.hbs +1 -4
- package/views/config/tls-upload.hbs +81 -0
- package/views/config/tls.hbs +492 -0
- package/views/config/webhooks.hbs +2 -2
- package/views/error.hbs +4 -2
- package/views/internals/index.hbs +1 -1
- package/views/layout/app.hbs +3 -11
- package/views/mcp/authorize.hbs +1 -1
- package/views/partials/ace_assets.hbs +13 -0
- package/views/partials/add_account_modal.hbs +1 -1
- package/views/partials/address_list.hbs +4 -4
- package/views/partials/filter_editor_js.hbs +2 -2
- package/views/partials/gateway_js.hbs +1 -1
- package/views/partials/oauth_form.hbs +1 -1
- package/views/partials/public_theme_init.hbs +1 -1
- package/views/partials/side_menu.hbs +1 -0
- package/views/partials/template_form.hbs +2 -2
- package/views/partials/test_send.hbs +7 -4
- package/views/partials/theme_init.hbs +1 -1
- package/views/partials/tls_security_card.hbs +25 -53
- package/views/partials/ui/alert-banner.hbs +3 -2
- package/views/partials/ui/badge.hbs +6 -2
- package/views/partials/ui/btn.hbs +5 -2
- package/views/partials/ui/details.hbs +2 -2
- package/views/partials/webhooks_editor_functions.hbs +1 -1
- package/views/reference/redirect.hbs +1 -1
- package/views/templates/template.hbs +2 -2
- package/views/tokens/new.hbs +1 -1
- package/views/unsubscribe.hbs +1 -1
- package/views/webhooks/webhook.hbs +2 -2
- package/workers/api.js +131 -242
- package/workers/export.js +1 -5
- package/workers/imap-proxy.js +4 -1
- package/workers/imap.js +1 -3
- package/workers/smtp.js +59 -83
- package/workers/submit.js +6 -12
- package/workers/webhooks.js +6 -17
- package/static/front/EmailEngine_logo_horiz.png +0 -0
- package/static/front/EmailEngine_logo_vert.png +0 -0
- package/static/front/index.html +0 -57
- package/static/front/logo.png +0 -0
- package/static/vendor/handlebars/handlebars.min-v4.7.9.js +0 -29
- package/views/partials/tls_security_js.hbs +0 -64
- package/views/partials/tls_security_modal.hbs +0 -22
package/lib/tls/der.js
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Minimal DER writer for the self-signed certificate builder in lib/tls/self-signed.js.
|
|
4
|
+
//
|
|
5
|
+
// EmailEngine needs to mint one X.509 certificate: a short-lived, self-signed leaf that lets a TLS
|
|
6
|
+
// listener start when no real certificate is available. Node's crypto can generate the key pair and
|
|
7
|
+
// produce the signature but cannot assemble a certificate, and every library that can is either
|
|
8
|
+
// unmaintained or several megabytes of ASN.1 machinery for the one structure we emit. This is the
|
|
9
|
+
// subset that structure needs, written so each function maps to a line of RFC 5280.
|
|
10
|
+
//
|
|
11
|
+
// Encoding only. Nothing here parses attacker-controlled input; the one reader (readTlv) walks a
|
|
12
|
+
// SubjectPublicKeyInfo that Node itself produced a moment earlier.
|
|
13
|
+
|
|
14
|
+
const net = require('net');
|
|
15
|
+
const ipaddr = require('ipaddr.js');
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* DER length octets: short form below 128, long form above it.
|
|
19
|
+
*
|
|
20
|
+
* @param {number} length Content length in bytes
|
|
21
|
+
* @returns {Buffer} Encoded length
|
|
22
|
+
*/
|
|
23
|
+
function encodeLength(length) {
|
|
24
|
+
if (length < 0x80) {
|
|
25
|
+
return Buffer.from([length]);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const bytes = [];
|
|
29
|
+
let value = length;
|
|
30
|
+
while (value > 0) {
|
|
31
|
+
bytes.unshift(value & 0xff);
|
|
32
|
+
value = Math.floor(value / 256);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return Buffer.from([0x80 | bytes.length, ...bytes]);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Tag-length-value, the shape every DER element has.
|
|
40
|
+
*
|
|
41
|
+
* @param {number} tag Identifier octet
|
|
42
|
+
* @param {Buffer|Buffer[]} content Content octets, concatenated when an array
|
|
43
|
+
* @returns {Buffer} Encoded element
|
|
44
|
+
*/
|
|
45
|
+
function tlv(tag, content) {
|
|
46
|
+
const body = Buffer.isBuffer(content) ? content : Buffer.concat(content);
|
|
47
|
+
return Buffer.concat([Buffer.from([tag]), encodeLength(body.length), body]);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const sequence = content => tlv(0x30, content);
|
|
51
|
+
const set = content => tlv(0x31, content);
|
|
52
|
+
const octetString = content => tlv(0x04, content);
|
|
53
|
+
const bitString = content => tlv(0x03, Buffer.concat([Buffer.from([0]), Buffer.isBuffer(content) ? content : Buffer.concat(content)]));
|
|
54
|
+
const boolean = value => tlv(0x01, Buffer.from([value ? 0xff : 0x00]));
|
|
55
|
+
const nullValue = () => tlv(0x05, Buffer.alloc(0));
|
|
56
|
+
const utf8String = value => tlv(0x0c, Buffer.from(value, 'utf-8'));
|
|
57
|
+
|
|
58
|
+
// Constructed context-specific tag, the [n] EXPLICIT of the ASN.1 modules.
|
|
59
|
+
const explicit = (tagNumber, content) => tlv(0xa0 | tagNumber, content);
|
|
60
|
+
|
|
61
|
+
// Primitive context-specific tag, the [n] IMPLICIT that GeneralName uses for its choices.
|
|
62
|
+
const implicit = (tagNumber, content) => tlv(0x80 | tagNumber, content);
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* A non-negative INTEGER. DER integers are signed, so a value whose top bit is set gains a leading
|
|
66
|
+
* zero octet, and leading zero octets that are not needed are stripped.
|
|
67
|
+
*
|
|
68
|
+
* @param {Buffer|number} value Magnitude, big-endian when a Buffer
|
|
69
|
+
* @returns {Buffer} Encoded INTEGER
|
|
70
|
+
*/
|
|
71
|
+
function integer(value) {
|
|
72
|
+
let bytes;
|
|
73
|
+
|
|
74
|
+
if (typeof value === 'number') {
|
|
75
|
+
bytes = [];
|
|
76
|
+
let remaining = value;
|
|
77
|
+
do {
|
|
78
|
+
bytes.unshift(remaining & 0xff);
|
|
79
|
+
remaining = Math.floor(remaining / 256);
|
|
80
|
+
} while (remaining > 0);
|
|
81
|
+
bytes = Buffer.from(bytes);
|
|
82
|
+
} else {
|
|
83
|
+
bytes = Buffer.from(value);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
let start = 0;
|
|
87
|
+
while (start < bytes.length - 1 && bytes[start] === 0 && !(bytes[start + 1] & 0x80)) {
|
|
88
|
+
start++;
|
|
89
|
+
}
|
|
90
|
+
bytes = bytes.subarray(start);
|
|
91
|
+
|
|
92
|
+
if (bytes[0] & 0x80) {
|
|
93
|
+
bytes = Buffer.concat([Buffer.from([0]), bytes]);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return tlv(0x02, bytes);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* An OBJECT IDENTIFIER from its dotted form. The first two arcs share one octet; every later arc is
|
|
101
|
+
* base-128 with the continuation bit set on all but its last octet.
|
|
102
|
+
*
|
|
103
|
+
* @param {string} dotted e.g. "2.5.29.17"
|
|
104
|
+
* @returns {Buffer} Encoded OID
|
|
105
|
+
*/
|
|
106
|
+
function oid(dotted) {
|
|
107
|
+
const arcs = dotted.split('.').map(Number);
|
|
108
|
+
const bytes = [40 * arcs[0] + arcs[1]];
|
|
109
|
+
|
|
110
|
+
for (let i = 2; i < arcs.length; i++) {
|
|
111
|
+
const chunk = [arcs[i] & 0x7f];
|
|
112
|
+
let remaining = Math.floor(arcs[i] / 128);
|
|
113
|
+
while (remaining > 0) {
|
|
114
|
+
chunk.unshift((remaining & 0x7f) | 0x80);
|
|
115
|
+
remaining = Math.floor(remaining / 128);
|
|
116
|
+
}
|
|
117
|
+
bytes.push(...chunk);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return tlv(0x06, Buffer.from(bytes));
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* A Time, in the representation RFC 5280 requires for the year: UTCTime through 2049,
|
|
125
|
+
* GeneralizedTime from 2050.
|
|
126
|
+
*
|
|
127
|
+
* @param {Date} date The instant to encode
|
|
128
|
+
* @returns {Buffer} Encoded Time
|
|
129
|
+
*/
|
|
130
|
+
function time(date) {
|
|
131
|
+
const pad = value => String(value).padStart(2, '0');
|
|
132
|
+
const year = date.getUTCFullYear();
|
|
133
|
+
const rest = `${pad(date.getUTCMonth() + 1)}${pad(date.getUTCDate())}${pad(date.getUTCHours())}${pad(date.getUTCMinutes())}${pad(date.getUTCSeconds())}Z`;
|
|
134
|
+
|
|
135
|
+
if (year >= 1950 && year < 2050) {
|
|
136
|
+
return tlv(0x17, Buffer.from(`${pad(year % 100)}${rest}`, 'latin1'));
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return tlv(0x18, Buffer.from(`${year}${rest}`, 'latin1'));
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* A BIT STRING carrying named bits, as KeyUsage does. Trailing unused bits are counted, and DER
|
|
144
|
+
* requires the trailing zero bits to be dropped.
|
|
145
|
+
*
|
|
146
|
+
* @param {number[]} bits Bit numbers to set, counted from the most significant bit of the first octet
|
|
147
|
+
* @returns {Buffer} Encoded BIT STRING
|
|
148
|
+
*/
|
|
149
|
+
function namedBits(bits) {
|
|
150
|
+
const highest = Math.max(...bits);
|
|
151
|
+
const octets = Buffer.alloc(Math.floor(highest / 8) + 1);
|
|
152
|
+
|
|
153
|
+
for (const bit of bits) {
|
|
154
|
+
octets[Math.floor(bit / 8)] |= 0x80 >> (bit % 8);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const unused = 7 - (highest % 8);
|
|
158
|
+
return tlv(0x03, Buffer.concat([Buffer.from([unused]), octets]));
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* An IP address as the octet string an iPAddress GeneralName carries: four octets for IPv4, sixteen
|
|
163
|
+
* for IPv6. `::` expansion and IPv4-mapped tails are ipaddr.js's problem, not ours - it is already
|
|
164
|
+
* a dependency and already the address parser everywhere else in the tree.
|
|
165
|
+
*
|
|
166
|
+
* @param {string} address Textual address
|
|
167
|
+
* @returns {Buffer|false} Address octets, or false when the address does not parse
|
|
168
|
+
*/
|
|
169
|
+
function ipToBuffer(address) {
|
|
170
|
+
if (!net.isIP(address)) {
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
try {
|
|
175
|
+
return Buffer.from(ipaddr.parse(address).toByteArray());
|
|
176
|
+
} catch (err) {
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Reads one DER element. Used on a SubjectPublicKeyInfo that Node produced, to reach the public key
|
|
183
|
+
* bits the subject key identifier is computed over.
|
|
184
|
+
*
|
|
185
|
+
* @param {Buffer} buf Buffer to read from
|
|
186
|
+
* @param {number} [offset] Where the element starts
|
|
187
|
+
* @returns {Object} `{ tag, contentStart, contentLength, end }`
|
|
188
|
+
*/
|
|
189
|
+
function readTlv(buf, offset = 0) {
|
|
190
|
+
const tag = buf[offset];
|
|
191
|
+
let pos = offset + 1;
|
|
192
|
+
let length = buf[pos++];
|
|
193
|
+
|
|
194
|
+
if (length & 0x80) {
|
|
195
|
+
const count = length & 0x7f;
|
|
196
|
+
length = 0;
|
|
197
|
+
for (let i = 0; i < count; i++) {
|
|
198
|
+
length = length * 256 + buf[pos++];
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
return { tag, contentStart: pos, contentLength: length, end: pos + length };
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
module.exports = {
|
|
206
|
+
encodeLength,
|
|
207
|
+
tlv,
|
|
208
|
+
sequence,
|
|
209
|
+
set,
|
|
210
|
+
octetString,
|
|
211
|
+
bitString,
|
|
212
|
+
boolean,
|
|
213
|
+
nullValue,
|
|
214
|
+
utf8String,
|
|
215
|
+
explicit,
|
|
216
|
+
implicit,
|
|
217
|
+
integer,
|
|
218
|
+
oid,
|
|
219
|
+
time,
|
|
220
|
+
namedBits,
|
|
221
|
+
ipToBuffer,
|
|
222
|
+
readTlv
|
|
223
|
+
};
|