Skip to content

Commit

Permalink
Reformat DKIM signature to multiline (#2991)
Browse files Browse the repository at this point in the history
* Reformat DKIM-Signature to multiline
* Update Changes.md
  • Loading branch information
superman20 authored Oct 26, 2021
1 parent fc48c28 commit 5415b10
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@

## NEXT - 2021-MM-DD

### Changes

- reformat dkim signature to multi-line #2991

## 2.8.28 - 2021-10-14

Expand Down
8 changes: 6 additions & 2 deletions plugins/dkim_sign.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,14 @@ class DKIMSignStream extends Stream {
}

// Create DKIM header
let dkim_header = `v=1;a=rsa-sha256;bh=${bodyhash};c=relaxed/simple;d=${this.domain_name};h=${headers.join(':')};s=${this.selector};b=`;
let dkim_header = `v=1; a=rsa-sha256; c=relaxed/simple; d=${this.domain_name}; s=${this.selector}; h=${headers.join(':')}; bh=${bodyhash}; b=`;
this.signer.update(`dkim-signature:${dkim_header}`);
const signature = this.signer.sign(this.private_key, 'base64');
dkim_header += signature;
dkim_header = `v=1; a=rsa-sha256; c=relaxed/simple;\r\n\td=${this.domain_name}; s=${this.selector};\r\n\th=${headers.join(':')};\r\n\tbh=${bodyhash};\r\n\tb=`;
dkim_header += signature.substring(0,74);
for (let i=74; i<signature.length; i+=76) {
dkim_header += `\r\n\t${signature.substring(i, i+76)}`;
}

if (this.end_callback) this.end_callback(null, dkim_header);
this.end_callback = null;
Expand Down
2 changes: 1 addition & 1 deletion tests/plugins/dkim_signer.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ frcCV1k9oG9oKj3dpUqdJg1PxRT2RSN/XKdLCPjaYaY=
function getValueFromDKIM (dkim_header, key) {
const kv = dkim_header.split(';');
for (let i = 0, len = kv.length; i < len; i++) {
const arr = kv[i].match(/^([^=]+)=(.*)$/);
const arr = kv[i].match(/^\s*([^=]+)=(.*)$/);
if (arr[1] === key) {
return arr[2];
}
Expand Down

0 comments on commit 5415b10

Please sign in to comment.