Skip to content

Commit

Permalink
config: add verify.enabled setting
Browse files Browse the repository at this point in the history
  • Loading branch information
msimerson committed Apr 15, 2024
1 parent 17b3b38 commit 06d074f
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 11 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).

### Unreleased

### [1.0.3] - 2024-04-15

- config: add `verify.enabled` setting

### [1.0.2] - 2024-04-10

- fix: properly scope the logdebug injections
Expand All @@ -14,3 +18,4 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).

[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
[1.0.3]: https://github.com/haraka/haraka-plugin-dkim/releases/tag/v1.0.3
2 changes: 2 additions & 0 deletions config/dkim.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ headers = From, Sender, Reply-To, Subject, Date, Message-ID, To, Cc, MIME-Versio


[verify]
enabled = true

; Recommended (but not default) values presented below.

; in secs
Expand Down
22 changes: 17 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,23 @@ exports.register = function () {
plugin.logdebug(str)
}

this.register_hook('data_post', 'dkim_verify')
this.register_hook('queue_outbound', 'hook_pre_send_trans_email')
if (this.cfg.verify.enabled) {
this.register_hook('data_post', 'dkim_verify')
}

if (this.cfg.sign.enabled) {
this.register_hook('queue_outbound', 'hook_pre_send_trans_email')
}
}

exports.load_dkim_ini = function () {
this.cfg = this.config.get(
'dkim.ini',
{
booleans: ['-sign.enabled'],
booleans: [
'-sign.enabled',
'+verify.enabled',
],
},
() => {
this.load_dkim_ini()
Expand All @@ -42,8 +50,10 @@ exports.load_dkim_ini = function () {
this.cfg.verify.timeout = this.timeout ? this.timeout - 1 : 29
}

this.load_dkim_default_key()
this.cfg.headers_to_sign = this.get_headers_to_sign()
if (this.cfg.sign.enabled) {
this.load_dkim_default_key()
this.cfg.headers_to_sign = this.get_headers_to_sign()
}
}

// dkim_signer
Expand Down Expand Up @@ -304,6 +314,8 @@ exports.get_sender_domain = function (connection) {
}

exports.dkim_verify = function (next, connection) {
if (!this.cfg.verify.enabled) return next()

const txn = connection?.transaction
if (!txn) return next()

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "haraka-plugin-dkim",
"version": "1.0.2",
"version": "1.0.3",
"description": "Haraka DKIM plugin",
"main": "index.js",
"files": [
Expand All @@ -16,8 +16,8 @@
"prettier": "npx prettier . --check",
"prettier:fix": "npx prettier . --write --log-level=warn",
"test": "node --test",
"versions": "npx @msimerson/dependency-version-checker check",
"versions:fix": "npx @msimerson/dependency-version-checker update"
"versions": "npx dependency-version-checker check",
"versions:fix": "npx dependency-version-checker update"
},
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion test/dkim_sign.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ beforeEach(() => {
this.plugin = new fixtures.plugin('dkim')

this.connection = fixtures.connection.createConnection()
this.connection.transaction = fixtures.transaction.createTransaction()
this.connection.init_transaction()
})

describe('get_sender_domain', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/dkim_signer.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ beforeEach(() => {
this.plugin = new fixtures.plugin('dkim')

this.connection = fixtures.connection.createConnection()
this.connection.transaction = fixtures.transaction.createTransaction()
this.connection.init_transaction()
// this.connection.transaction.mail_from = {}
})

Expand Down
2 changes: 1 addition & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('uses text fixtures', () => {

it('sets up a transaction', () => {
this.connection = fixtures.connection.createConnection({})
this.connection.transaction = fixtures.transaction.createTransaction({})
this.connection.init_transaction()
assert.ok(this.connection.transaction.header)
})
})
Expand Down

0 comments on commit 06d074f

Please sign in to comment.