mirror of
https://github.com/sct/overseerr.git
synced 2025-09-17 17:24:35 +02:00
fix(email): enclose PGP encryption logic in try/catch (#2519)
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import { randomBytes } from 'crypto';
|
import { randomBytes } from 'crypto';
|
||||||
import * as openpgp from 'openpgp';
|
import * as openpgp from 'openpgp';
|
||||||
import { Transform, TransformCallback } from 'stream';
|
import { Transform, TransformCallback } from 'stream';
|
||||||
|
import logger from '../../logger';
|
||||||
|
|
||||||
interface EncryptorOptions {
|
interface EncryptorOptions {
|
||||||
signingKey?: string;
|
signingKey?: string;
|
||||||
@@ -36,10 +37,14 @@ class PGPEncryptor extends Transform {
|
|||||||
|
|
||||||
// Actually do stuff
|
// Actually do stuff
|
||||||
_flush = async (callback: TransformCallback): Promise<void> => {
|
_flush = async (callback: TransformCallback): Promise<void> => {
|
||||||
// Reconstruct message as buffer
|
|
||||||
const message = Buffer.concat(this._messageChunks, this._messageLength);
|
const message = Buffer.concat(this._messageChunks, this._messageLength);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Reconstruct message as buffer
|
||||||
const validPublicKeys = await Promise.all(
|
const validPublicKeys = await Promise.all(
|
||||||
this._encryptionKeys.map((armoredKey) => openpgp.readKey({ armoredKey }))
|
this._encryptionKeys.map((armoredKey) =>
|
||||||
|
openpgp.readKey({ armoredKey })
|
||||||
|
)
|
||||||
);
|
);
|
||||||
let privateKey: openpgp.PrivateKey | undefined;
|
let privateKey: openpgp.PrivateKey | undefined;
|
||||||
|
|
||||||
@@ -163,6 +168,18 @@ class PGPEncryptor extends Transform {
|
|||||||
|
|
||||||
this.push(Buffer.from(emailHeadersRaw + emailPartDelimiter + body));
|
this.push(Buffer.from(emailHeadersRaw + emailPartDelimiter + body));
|
||||||
callback();
|
callback();
|
||||||
|
} catch (e) {
|
||||||
|
logger.error(
|
||||||
|
'Something went wrong while encrypting email message with OpenPGP. Sending email without encryption',
|
||||||
|
{
|
||||||
|
label: 'Notifications',
|
||||||
|
errorMessage: e.message,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
this.push(message);
|
||||||
|
callback();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user