nodemailer-openpgp
Advanced tools
Comparing version 1.2.0 to 2.0.0
@@ -39,77 +39,70 @@ 'use strict'; | ||
_flush(done) { | ||
//var signature = dkimSign(this._message, this.options); | ||
let message = Buffer.concat(this._messageChunks, this._messageLength); | ||
(async () => { | ||
//var signature = dkimSign(this._message, this.options); | ||
let message = Buffer.concat(this._messageChunks, this._messageLength); | ||
let privKey; | ||
let pubKeys = []; | ||
[].concat(this.options.encryptionKeys || []).forEach(pubKey => { | ||
let keys; | ||
try { | ||
keys = openpgp.key.readArmored(pubKey.toString()).keys; | ||
pubKeys = pubKeys.concat(keys); | ||
} catch (E) { | ||
// just ignore if failed | ||
let privKey; | ||
const pubKeys = await Promise.all(this.options.encryptionKeys.map(armoredKey => openpgp.readKey({ armoredKey }))); | ||
if (!pubKeys.length) { | ||
this.push(message); | ||
return done(); | ||
} | ||
}); | ||
if (!pubKeys.length) { | ||
this.push(message); | ||
return done(); | ||
} | ||
if (this.options.signingKey) { | ||
try { | ||
privKey = await openpgp.readKey({ | ||
armoredKey: this.options.signingKey.toString() | ||
}); | ||
if (this.options.signingKey) { | ||
try { | ||
privKey = openpgp.key.readArmored(this.options.signingKey.toString()).keys[0]; | ||
if (this.options.passphrase && !privKey.decrypt(this.options.passphrase)) { | ||
privKey = false; | ||
if (this.options.passphrase && !(await privKey.decrypt(this.options.passphrase))) { | ||
privKey = false; | ||
} | ||
} catch (E) { | ||
// just ignore if failed | ||
} | ||
} catch (E) { | ||
// just ignore if failed | ||
} | ||
} | ||
let messageParts = message.toString().split('\r\n\r\n'); | ||
let header = messageParts.shift(); | ||
let headers = []; | ||
let bodyHeaders = []; | ||
let lastHeader = false; | ||
let boundary = 'nm_' + crypto.randomBytes(14).toString('hex'); | ||
header.split('\r\n').forEach((line, i) => { | ||
if (!i || !lastHeader || !/^\s/.test(line)) { | ||
lastHeader = [line]; | ||
if (/^(content-type|content-transfer-encoding):/i.test(line)) { | ||
bodyHeaders.push(lastHeader); | ||
let messageParts = message.toString().split('\r\n\r\n'); | ||
let header = messageParts.shift(); | ||
let headers = []; | ||
let bodyHeaders = []; | ||
let lastHeader = false; | ||
let boundary = 'nm_' + crypto.randomBytes(14).toString('hex'); | ||
header.split('\r\n').forEach((line, i) => { | ||
if (!i || !lastHeader || !/^\s/.test(line)) { | ||
lastHeader = [line]; | ||
if (/^(content-type|content-transfer-encoding):/i.test(line)) { | ||
bodyHeaders.push(lastHeader); | ||
} else { | ||
headers.push(lastHeader); | ||
} | ||
} else { | ||
headers.push(lastHeader); | ||
lastHeader.push(line); | ||
} | ||
} else { | ||
lastHeader.push(line); | ||
} | ||
}); | ||
headers.push(['Content-Type: multipart/encrypted; protocol="application/pgp-encrypted";'], [' boundary="' + boundary + '"']); | ||
}); | ||
headers.push(['Content-Type: multipart/encrypted; protocol="application/pgp-encrypted";'], [' boundary="' + boundary + '"']); | ||
headers.push(['Content-Description: OpenPGP encrypted message']); | ||
headers.push(['Content-Transfer-Encoding: 7bit']); | ||
headers.push(['Content-Description: OpenPGP encrypted message']); | ||
headers.push(['Content-Transfer-Encoding: 7bit']); | ||
headers = headers.map(line => line.join('\r\n')).join('\r\n'); | ||
bodyHeaders = bodyHeaders.map(line => line.join('\r\n')).join('\r\n'); | ||
headers = headers.map(line => line.join('\r\n')).join('\r\n'); | ||
bodyHeaders = bodyHeaders.map(line => line.join('\r\n')).join('\r\n'); | ||
let body = messageParts.join('\r\n\r\n'); | ||
let body = messageParts.join('\r\n\r\n'); | ||
const data = `${bodyHeaders} \r\n\r\n ${body}`; | ||
let options = { | ||
data: bodyHeaders + '\r\n\r\n' + body, | ||
publicKeys: pubKeys, | ||
armor: true | ||
}; | ||
let options = { | ||
message: openpgp.Message.fromText(data), | ||
publicKeys: pubKeys, | ||
armor: true | ||
}; | ||
if (privKey) { | ||
options.privateKeys = privKey; | ||
} | ||
if (privKey) { | ||
options.privateKeys = privKey; | ||
} | ||
openpgp | ||
.encrypt(options) | ||
.then(ciphertext => { | ||
let encrypted = ciphertext.data; | ||
let body = | ||
try { | ||
const encrypted = await openpgp.encrypt(options); | ||
const mailBody = | ||
'This is an OpenPGP/MIME encrypted message\r\n\r\n' + | ||
@@ -136,6 +129,8 @@ '--' + | ||
this.push(Buffer.from(headers + '\r\n\r\n' + body)); | ||
done(); | ||
}) | ||
.catch(done); | ||
this.push(Buffer.from(`${headers}\r\n\r\n${mailBody}`)); | ||
return done(); | ||
} catch (E) { | ||
return done(); | ||
} | ||
})(); | ||
} | ||
@@ -151,4 +146,4 @@ } | ||
*/ | ||
module.exports.openpgpEncrypt = function(options) { | ||
return function(mail, callback) { | ||
module.exports.openpgpEncrypt = function (options) { | ||
return function (mail, callback) { | ||
if (!mail.data.encryptionKeys || (Array.isArray(mail.data.encryptionKeys) && !mail.data.encryptionKeys.length)) { | ||
@@ -155,0 +150,0 @@ return setImmediate(callback); |
{ | ||
"name": "nodemailer-openpgp", | ||
"version": "1.2.0", | ||
"version": "2.0.0", | ||
"description": "Encrypt Nodemailer messages with PGP", | ||
@@ -23,16 +23,19 @@ "main": "lib/nodemailer-openpgp", | ||
"homepage": "https://github.com/nodemailer/nodemailer-openpgp", | ||
"engines": { | ||
"node": ">=12" | ||
}, | ||
"dependencies": { | ||
"openpgp": "3.0.11" | ||
"openpgp": "5.0.0-1" | ||
}, | ||
"devDependencies": { | ||
"chai": "^4.1.2", | ||
"eslint-config-nodemailer": "^1.2.0", | ||
"grunt": "^1.0.3", | ||
"grunt-cli": "^1.2.0", | ||
"grunt-eslint": "^21.0.0", | ||
"grunt-mocha-test": "^0.13.3", | ||
"mocha": "^5.2.0", | ||
"nodemailer": "^4.6.7", | ||
"nodemailer-stub-transport": "^1.1.0" | ||
"chai": "4.1.2", | ||
"eslint-config-nodemailer": "1.2.0", | ||
"grunt": "1.0.3", | ||
"grunt-cli": "1.2.0", | ||
"grunt-eslint": "23.0.0", | ||
"grunt-mocha-test": "0.13.3", | ||
"mocha": "8.3.2", | ||
"nodemailer": "6.5.0", | ||
"nodemailer-stub-transport": "1.1.0" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15921
7
151
+ Addedopenpgp@5.0.0-1(transitive)
- Removedaddress-rfc2822@2.2.2(transitive)
- Removedasmcrypto.js@0.22.0(transitive)
- Removedbase64-js@1.5.1(transitive)
- Removedbuffer@5.7.1(transitive)
- Removedemail-addresses@5.0.0(transitive)
- Removedencoding@0.1.13(transitive)
- Removedgraceful-fs@4.2.11(transitive)
- Removedhash.js@1.1.7(transitive)
- Removediconv-lite@0.6.3(transitive)
- Removedieee754@1.2.1(transitive)
- Removedimurmurhash@0.1.4(transitive)
- Removedis-stream@1.1.0(transitive)
- Removednode-fetch@1.7.3(transitive)
- Removednode-localstorage@1.3.1(transitive)
- Removedopenpgp@3.0.11(transitive)
- Removedpako@1.0.11(transitive)
- Removedrusha@0.8.14(transitive)
- Removedslide@1.1.6(transitive)
- Removedwrite-file-atomic@1.3.4(transitive)
Updatedopenpgp@5.0.0-1