From ed4954709a1189d3d433fc813ddd4ce2ad4bb859 Mon Sep 17 00:00:00 2001 From: Matt Simerson Date: Wed, 10 Apr 2024 13:00:59 -0700 Subject: [PATCH] Release v1.0.2 (#1) - fix: properly scope the logdebug injections --- .release | 2 +- CHANGELOG.md | 7 +++- README.md | 5 ++- index.js | 91 ++++++++++++++++++++++++++------------------------- package.json | 2 +- test/index.js | 3 +- 6 files changed, 58 insertions(+), 52 deletions(-) diff --git a/.release b/.release index 7cd5707..e5763bc 160000 --- a/.release +++ b/.release @@ -1 +1 @@ -Subproject commit 7cd5707f7d69f8d4dca1ec407ada911890e59d0a +Subproject commit e5763bcea4decd4298e432b2d6251a364f755c12 diff --git a/CHANGELOG.md b/CHANGELOG.md index e463f57..3b08685 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,8 +4,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/). ### Unreleased +### [1.0.2] - 2024-04-10 + +- fix: properly scope the logdebug injections + ### 1.0.0 - 2024-04-09 - repackaged from haraka/Haraka -[1.0.0]: https://github.com/haraka/haraka-plugin-template/releases/tag/v1.0.0 +[1.0.0]: https://github.com/haraka/haraka-plugin-dkim/releases/tag/v1.0.0 +[1.0.2]: https://github.com/haraka/haraka-plugin-dkim/releases/tag/v1.0.2 diff --git a/README.md b/README.md index dd1b024..4533ad8 100644 --- a/README.md +++ b/README.md @@ -88,7 +88,7 @@ selector = name domain = name ``` -* headers: the list of headers that should be signed, separated by commas, colons or semi-colons. Signing prevents tampering with the specified headers. The 'From' header is required by the RFC and will be added if missing. +- headers: the list of headers that should be signed, separated by commas, colons or semi-colons. Signing prevents tampering with the specified headers. The 'From' header is required by the RFC and will be added if missing. ## Single Domain Configuration @@ -97,7 +97,7 @@ To sign all messages with a single DKIM key, you must set the selector and domai - selector - Set this to the selector name published in DNS under the \_domainkey sub-domain of the domain referenced below. - domain - Set this to the domain name that will be used to sign messages which don't match a per-domain DKIM key. The DNS TXT entry for: - .\_domainkey. + .\_domainkey. Test that your DKIM key is published properly with a DNS request like this: @@ -143,7 +143,6 @@ You can add `--debug` to the option arguments to see a full trace of the process This plugin and underlying library do not currently support DKIM body length limits (l=). - [ci-img]: https://github.com/haraka/haraka-plugin-dkim/actions/workflows/ci.yml/badge.svg diff --git a/index.js b/index.js index 102cb50..2915df2 100644 --- a/index.js +++ b/index.js @@ -11,14 +11,22 @@ const dkim = require('./lib/dkim') const { DKIMVerifyStream, DKIMSignStream } = dkim exports.register = function () { + const plugin = this this.load_dkim_ini() + dkim.DKIMObject.prototype.debug = (str) => { + plugin.logdebug(str) + } + + DKIMVerifyStream.prototype.debug = (str) => { + plugin.logdebug(str) + } + this.register_hook('data_post', 'dkim_verify') this.register_hook('queue_outbound', 'hook_pre_send_trans_email') } exports.load_dkim_ini = function () { - this.cfg = this.config.get( 'dkim.ini', { @@ -295,55 +303,50 @@ exports.get_sender_domain = function (connection) { return domain } -dkim.DKIMObject.prototype.debug = (str) => { - exports.logdebug(str) -} - -DKIMVerifyStream.prototype.debug = (str) => { - exports.logdebug(str) -} - exports.dkim_verify = function (next, connection) { const txn = connection?.transaction if (!txn) return next() - const verifier = new DKIMVerifyStream(this.cfg.verify, (err, result, results) => { - if (err) { - txn.results.add(this, { err }) - return next() - } - if (!results || results.length === 0) { - txn.results.add(this, { skip: 'no/bad dkim signature' }) - return next(CONT, 'no/bad signature') - } - results.forEach((res) => { - let res_err = '' - if (res.error) res_err = ` (${res.error})` - connection.auth_results( - `dkim=${res.result}${res_err} header.i=${res.identity} header.d=${res.domain} header.s=${res.selector}`, - ) - connection.loginfo( - this, - `identity="${res.identity}" domain="${res.domain}" selector="${res.selector}" result=${res.result} ${res_err}`, - ) - - // save to ResultStore - const rs_obj = JSON.parse(JSON.stringify(res)) - if (res.result === 'pass') { - rs_obj.pass = res.domain - } else if (res.result === 'fail') { - rs_obj.fail = res.domain + res_err - } else { - rs_obj.err = res.domain + res_err + const verifier = new DKIMVerifyStream( + this.cfg.verify, + (err, result, results) => { + if (err) { + txn.results.add(this, { err }) + return next() + } + if (!results || results.length === 0) { + txn.results.add(this, { skip: 'no/bad dkim signature' }) + return next(CONT, 'no/bad signature') + } + for (const res of results) { + let res_err = '' + if (res.error) res_err = ` (${res.error})` + connection.auth_results( + `dkim=${res.result}${res_err} header.i=${res.identity} header.d=${res.domain} header.s=${res.selector}`, + ) + connection.loginfo( + this, + `identity="${res.identity}" domain="${res.domain}" selector="${res.selector}" result=${res.result} ${res_err}`, + ) + + // save to ResultStore + const rs_obj = JSON.parse(JSON.stringify(res)) + if (res.result === 'pass') { + rs_obj.pass = res.domain + } else if (res.result === 'fail') { + rs_obj.fail = res.domain + res_err + } else { + rs_obj.err = res.domain + res_err + } + txn.results.add(this, rs_obj) } - txn.results.add(this, rs_obj) - }) - connection.logdebug(this, JSON.stringify(results)) - // Store results for other plugins - txn.notes.dkim_results = results - next() - }) + connection.logdebug(this, JSON.stringify(results)) + // Store results for other plugins + txn.notes.dkim_results = results + next() + }, + ) txn.message_stream.pipe(verifier, { line_endings: '\r\n' }) } diff --git a/package.json b/package.json index a059644..411c8d5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "haraka-plugin-dkim", - "version": "1.0.1", + "version": "1.0.2", "description": "Haraka DKIM plugin", "main": "index.js", "files": [ diff --git a/test/index.js b/test/index.js index 9d887d1..01d5312 100644 --- a/test/index.js +++ b/test/index.js @@ -7,12 +7,11 @@ const fixtures = require('haraka-test-fixtures') beforeEach(() => { this.plugin = new fixtures.plugin('dkim') - this.plugin.config.root_path = path.resolve('test','config') + this.plugin.config.root_path = path.resolve('test', 'config') delete this.plugin.config.overrides_path }) describe('plugin', () => { - it('loads', () => { assert.ok(this.plugin) })