forked from emersion/go-msgauth
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds support for DKIM flags. fixes emersion#44
- Loading branch information
1 parent
5995b67
commit 5294351
Showing
4 changed files
with
113 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -294,3 +294,93 @@ func TestVerify_tooManySignatures(t *testing.T) { | |
t.Fatalf("Expected %v verifications, got %v", options.MaxVerifications, len(verifs)) | ||
} | ||
} | ||
|
||
const validSignatureWithSFlag = `DKIM-Signature: a=rsa-sha256; bh=2jUSOH9NhtVGCQWNr9BrIAPreKQjO6Sn7XIkfJVOzv8=; | ||
c=simple/simple; d=example.com; | ||
h=Received:From:To:Subject:Date:Message-ID; s=helsinki; t=1627654546; v=1; | ||
b=IKIukw2EoRWxb86Ke2ingZFWLoAeNnKYAwGghFe1y0bbn5QLSoyk78o36JXT8z1DzmPquMHt | ||
C//jnBna6DtqBneiKAUo3OyYmv1+EbTWWEvHGGtUkrKge2VdIXM3ttaOpuTHJRG+6irPKq0Ul4T | ||
Ofa99PVg4o6nfY6Ctakv3aYc= | ||
Received: from helsinki.example.com [192.0.2.1] | ||
by submitserver.example.com with SUBMISSION; | ||
Fri, 11 Jul 2003 21:01:54 -0700 (PDT) | ||
From: Joe Helsinki <[email protected]> | ||
To: Suzie Q <[email protected]> | ||
Subject: Is dinner ready? | ||
Date: Fri, 11 Jul 2021 21:00:37 -0700 (PDT) | ||
Message-ID: <[email protected]> | ||
Hi. | ||
We lost the game. Are you hungry yet? | ||
Joe.` | ||
|
||
var testSFlagVerification = &Verification{ | ||
Domain: "example.com", | ||
Identifier: "@example.com", | ||
HeaderKeys: []string{"Received", "From", "To", "Subject", "Date", "Message-ID"}, | ||
Time: time.Unix(1627654546, 0), | ||
} | ||
|
||
func TestVerify_SFlag(t *testing.T) { | ||
r := newMailStringReader(validSignatureWithSFlag) | ||
|
||
verifications, err := Verify(r) | ||
if err != nil { | ||
t.Fatalf("Expected no error while verifying signature with flags, got: %v", err) | ||
} else if len(verifications) != 1 { | ||
t.Fatalf("Expected exactly one verification with flags, got %v", len(verifications)) | ||
} | ||
|
||
v := verifications[0] | ||
if !reflect.DeepEqual(testSFlagVerification, v) { | ||
t.Errorf("Expected verification with flags to be \n%+v\n but got \n%+v", testSFlagVerification, v) | ||
} | ||
} | ||
|
||
const invalidSignatureWithSFlag = `DKIM-Signature: a=rsa-sha256; bh=2jUSOH9NhtVGCQWNr9BrIAPreKQjO6Sn7XIkfJVOzv8=; | ||
c=simple/simple; d=example.com; | ||
h=Received:From:To:Subject:Date:Message-ID; [email protected]; | ||
s=helsinki; t=1627654996; v=1; | ||
b=k07JuWvk3PZkanimQ0QtIXRwXC5W4EhG/0sPH+r7zWKQ731fNZE//9+ofz+vcA3K5YQ0cOR2 | ||
EXY9qjriMPHFlaYsKZ4gj5YebNhRHyjJ9xlsTPNtFLqs9wnnaKCZu3VxJpualfTaY+Vs3RMjYLq | ||
7IvOY4tqxnifJg2uFC/5kRbY= | ||
Received: from helsinki.example.com [192.0.2.1] | ||
by submitserver.example.com with SUBMISSION; | ||
Fri, 11 Jul 2003 21:01:54 -0700 (PDT) | ||
From: Joe Helsinki <[email protected]> | ||
To: Suzie Q <[email protected]> | ||
Subject: Is dinner ready? | ||
Date: Fri, 11 Jul 2021 21:00:37 -0700 (PDT) | ||
Message-ID: <[email protected]> | ||
Hi. | ||
We lost the game. Are you hungry yet? | ||
Joe.` | ||
|
||
var testSFlagVerificationFail = &Verification{ | ||
Domain: "example.com", | ||
Identifier: "[email protected]", | ||
HeaderKeys: []string{"Received", "From", "To", "Subject", "Date", "Message-ID"}, | ||
Time: time.Unix(1627654996, 0), | ||
Err: permFailError("identifier and domain mismatch"), | ||
} | ||
|
||
func TestVerify_InvalidSFlag(t *testing.T) { | ||
r := newMailStringReader(invalidSignatureWithSFlag) | ||
|
||
verifications, err := Verify(r) | ||
if err != nil { | ||
t.Fatalf("Expected no error while verifying signature with flags, got: %v", err) | ||
} else if len(verifications) != 1 { | ||
t.Fatalf("Expected exactly one verification with flags, got %v", len(verifications)) | ||
} | ||
|
||
v := verifications[0] | ||
if !reflect.DeepEqual(testSFlagVerificationFail, v) { | ||
t.Errorf("Expected verification with flags to be \n%+v\n but got \n%+v", testSFlagVerificationFail, v) | ||
} | ||
} |