@social-mail/social-mail-web-server 1.8.372 → 1.8.374
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/dist/common/globalEnv.d.ts +4 -0
- package/dist/common/globalEnv.d.ts.map +1 -1
- package/dist/common/globalEnv.js +4 -0
- package/dist/common/globalEnv.js.map +1 -1
- package/dist/server/services/encryption/EncryptionService.d.ts +4 -0
- package/dist/server/services/encryption/EncryptionService.d.ts.map +1 -1
- package/dist/server/services/encryption/EncryptionService.js +14 -9
- package/dist/server/services/encryption/EncryptionService.js.map +1 -1
- package/dist/server/smtp/services/CachedEmailService.d.ts.map +1 -1
- package/dist/server/smtp/services/CachedEmailService.js +13 -2
- package/dist/server/smtp/services/CachedEmailService.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/common/globalEnv.ts +4 -0
- package/src/server/services/encryption/EncryptionService.ts +15 -9
- package/src/server/smtp/services/CachedEmailService.ts +12 -2
package/package.json
CHANGED
package/src/common/globalEnv.ts
CHANGED
|
@@ -45,6 +45,10 @@ export const globalEnv = {
|
|
|
45
45
|
senderEmailForNotification: process.env.SOCIAL_MAIL_SENDER_EMAIL_FOR_NOTIFICATION,
|
|
46
46
|
cdn,
|
|
47
47
|
cdnOrHost: cdn ?? host,
|
|
48
|
+
emailContentProxy: {
|
|
49
|
+
host: process.env.SOCIAL_MAIL_HOSTS_EMAIL_CONTENT || null,
|
|
50
|
+
encryptionKey: process.env.SOCIAL_MAIL_HOSTS_EMAIL_CONTENT_PUBLIC_KEY || process.env.SOCIAL_MAIL_PUBLIC_KEY
|
|
51
|
+
},
|
|
48
52
|
path: process.env.SOCIAL_MAIL_PATH || "/",
|
|
49
53
|
links: {
|
|
50
54
|
login: process.env.SOCIAL_MAIL_LINKS_LOGIN || process.env.SOCIAL_MAIL_EXTERNAL_LOGIN,
|
|
@@ -7,6 +7,11 @@ const cache = new Map<string, { key, encryptionIV }>();
|
|
|
7
7
|
@RegisterSingleton
|
|
8
8
|
export default class EncryptionService {
|
|
9
9
|
|
|
10
|
+
global = {
|
|
11
|
+
encrypt: (text: string, publicKey, host: string) => this.encrypt(text, publicKey, "base64url", host),
|
|
12
|
+
decrypt: (text: string, publicKey, host: string) => this.decrypt(text, publicKey, "base64url", host)
|
|
13
|
+
};
|
|
14
|
+
|
|
10
15
|
general = {
|
|
11
16
|
encrypt: (text: string) => this.encrypt(text, globalEnv.publicKey, "base64url"),
|
|
12
17
|
decrypt: (text: string) => this.decrypt(text, globalEnv.publicKey, "base64url")
|
|
@@ -17,23 +22,24 @@ export default class EncryptionService {
|
|
|
17
22
|
decrypt: (text: string) => this.decrypt(text, globalEnv.secretKey)
|
|
18
23
|
};
|
|
19
24
|
|
|
20
|
-
private encrypt(text: string, secretKey = globalEnv.secretKey, encoding: Encoding = "hex") {
|
|
21
|
-
const { key, encryptionIV} = this.createKey(secretKey);
|
|
25
|
+
private encrypt(text: string, secretKey = globalEnv.secretKey, encoding: Encoding = "hex", host = globalEnv.host) {
|
|
26
|
+
const { key, encryptionIV} = this.createKey(secretKey, host);
|
|
22
27
|
const cipher = crypto.createCipheriv("aes-256-cbc", key, encryptionIV);
|
|
23
28
|
return (cipher.update(text, "utf-8", encoding)
|
|
24
29
|
+ cipher.final(encoding)).replaceAll("=", "*");
|
|
25
30
|
}
|
|
26
31
|
|
|
27
|
-
private decrypt(text: string, secretKey = globalEnv.secretKey, encoding: Encoding = "hex") {
|
|
28
|
-
const { key, encryptionIV} = this.createKey(secretKey);
|
|
32
|
+
private decrypt(text: string, secretKey = globalEnv.secretKey, encoding: Encoding = "hex", host = globalEnv.host) {
|
|
33
|
+
const { key, encryptionIV} = this.createKey(secretKey, host);
|
|
29
34
|
text = text.replaceAll("*" , "=");
|
|
30
35
|
const decipher = crypto.createDecipheriv("aes-256-cbc", key, encryptionIV);
|
|
31
36
|
return decipher.update(text, encoding, "utf-8") + decipher.final("utf-8");
|
|
32
37
|
}
|
|
33
38
|
|
|
34
|
-
private createKey(secretKey: string) {
|
|
39
|
+
private createKey(secretKey: string, host) {
|
|
35
40
|
|
|
36
|
-
|
|
41
|
+
const cacheKey = `${host}:${secretKey}`;
|
|
42
|
+
let result = cache.get(cacheKey);
|
|
37
43
|
if(!result) {
|
|
38
44
|
const key = crypto.createHash("sha512")
|
|
39
45
|
.update(secretKey)
|
|
@@ -41,12 +47,12 @@ export default class EncryptionService {
|
|
|
41
47
|
.substring(0, 32);
|
|
42
48
|
|
|
43
49
|
const encryptionIV = crypto.createHash("sha512")
|
|
44
|
-
.update(
|
|
50
|
+
.update(host)
|
|
45
51
|
.digest("hex")
|
|
46
52
|
.substring(0, 16);
|
|
47
53
|
result = { key, encryptionIV };
|
|
48
|
-
cache.set(
|
|
49
|
-
setTimeout(() => cache.delete(
|
|
54
|
+
cache.set(cacheKey, result);
|
|
55
|
+
setTimeout(() => cache.delete(cacheKey), 60000);
|
|
50
56
|
}
|
|
51
57
|
return result;
|
|
52
58
|
}
|
|
@@ -10,6 +10,7 @@ import EmailLogService from "../../services/email-logs/EmailLogService.js";
|
|
|
10
10
|
import EncryptionService from "../../services/encryption/EncryptionService.js";
|
|
11
11
|
import { LocalFile } from "@entity-access/server-pages/dist/core/LocalFile.js";
|
|
12
12
|
import BlogContentTransformer from "../../services/dom/BlogContentTransformer.js";
|
|
13
|
+
import { globalEnv } from "../../../common/globalEnv.js";
|
|
13
14
|
|
|
14
15
|
@RegisterScoped
|
|
15
16
|
export default class CachedEmailService {
|
|
@@ -33,7 +34,6 @@ export default class CachedEmailService {
|
|
|
33
34
|
|
|
34
35
|
const factory = async () => {
|
|
35
36
|
|
|
36
|
-
const ei = this.encryptionService.general.encrypt(emailID.toString());
|
|
37
37
|
|
|
38
38
|
let logFile: EmailLog;
|
|
39
39
|
|
|
@@ -69,12 +69,22 @@ export default class CachedEmailService {
|
|
|
69
69
|
}
|
|
70
70
|
const htmlService = ServiceProvider.resolve(this, BlogContentTransformer);
|
|
71
71
|
if (status !== "draft") {
|
|
72
|
+
let ei;
|
|
73
|
+
let prefix;
|
|
74
|
+
const { host, encryptionKey } = globalEnv.emailContentProxy;
|
|
75
|
+
if (host) {
|
|
76
|
+
ei = this.encryptionService.global.encrypt(emailID.toString(), encryptionKey, host);
|
|
77
|
+
prefix = `https://${host}/api/emails/d/${ei}/${emailID}/`;
|
|
78
|
+
} else {
|
|
79
|
+
ei = this.encryptionService.general.encrypt(emailID.toString());
|
|
80
|
+
prefix = `/api/emails/d/${ei}/${emailID}/`;
|
|
81
|
+
}
|
|
72
82
|
html = await htmlService.sanitizeExternalResources({
|
|
73
83
|
html,
|
|
74
84
|
emailID,
|
|
75
85
|
messageID: void 0,
|
|
76
86
|
senderDomain,
|
|
77
|
-
prefix
|
|
87
|
+
prefix,
|
|
78
88
|
blog
|
|
79
89
|
});
|
|
80
90
|
}
|