Skip to content

Commit

Permalink
Release v1.0.2 (#1)
Browse files Browse the repository at this point in the history
- fix: properly scope the logdebug injections
  • Loading branch information
msimerson authored Apr 10, 2024
1 parent c07274e commit ed49547
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 52 deletions.
2 changes: 1 addition & 1 deletion .release
Submodule .release updated 5 files
+3 −0 CHANGELOG.md
+8 −0 base.sh
+78 −0 contributors.js
+36 −5 start.sh
+8 −7 submit.sh
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:

<selector>.\_domainkey.<domain>
<selector>.\_domainkey.<domain>

Test that your DKIM key is published properly with a DNS request like this:

Expand Down Expand Up @@ -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=).


<!-- leave these buried at the bottom of the document -->

[ci-img]: https://github.com/haraka/haraka-plugin-dkim/actions/workflows/ci.yml/badge.svg
Expand Down
91 changes: 47 additions & 44 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
{
Expand Down Expand Up @@ -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' })
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "haraka-plugin-dkim",
"version": "1.0.1",
"version": "1.0.2",
"description": "Haraka DKIM plugin",
"main": "index.js",
"files": [
Expand Down
3 changes: 1 addition & 2 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand Down

0 comments on commit ed49547

Please sign in to comment.