This repository was archived by the owner on Apr 15, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
100 additions
and
16 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,28 @@ | ||
package dkim | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
const dnsPublicKey = "v=DKIM1; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQ" + | ||
"KBgQDwIRP/UC3SBsEmGqZ9ZJW3/DkMoGeLnQg1fWn7/zYt" + | ||
"IxN2SnFCjxOCKG9v3b4jYfcTNh5ijSsq631uBItLa7od+v" + | ||
"/RtdC2UzJ1lWT947qR+Rcac2gbto/NMqJ0fzfVjH4OuKhi" + | ||
"tdY9tf6mcwGjaNBcWToIMmPSPDdQPNUYckcQ2QIDAQAB" | ||
|
||
const dnsEd25519PublicKey = "v=DKIM1; k=ed25519; p=11qYAYKxCrfVS/7TyWQHOg7hcvPapiMlrwIaaPcHURo=" | ||
|
||
func init() { | ||
queryMethods["dns/txt"] = queryTest | ||
} | ||
|
||
func queryTest(domain, selector string) (*queryResult, error) { | ||
return parsePublicKey(dnsPublicKey) | ||
record := selector + "._domainkey." + domain | ||
switch record { | ||
case "brisbane._domainkey.example.com", "brisbane._domainkey.example.org", "test._domainkey.football.example.com": | ||
return parsePublicKey(dnsPublicKey) | ||
case "brisbane._domainkey.football.example.com": | ||
return parsePublicKey(dnsEd25519PublicKey) | ||
} | ||
return nil, fmt.Errorf("unknown test DNS record %v", record) | ||
} |
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 |
---|---|---|
@@ -1,9 +1,11 @@ | ||
package dkim | ||
|
||
import ( | ||
"io" | ||
"reflect" | ||
"strings" | ||
"testing" | ||
"time" | ||
) | ||
|
||
const verifiedMailString = `DKIM-Signature: v=1; a=rsa-sha256; s=brisbane; d=example.com; | ||
|
@@ -37,8 +39,12 @@ var testVerification = &Verification{ | |
BodyLength: -1, | ||
} | ||
|
||
func newMailStringReader(s string) io.Reader { | ||
return strings.NewReader(strings.Replace(s, "\n", "\r\n", -1)) | ||
} | ||
|
||
func TestVerify(t *testing.T) { | ||
r := strings.NewReader(strings.Replace(verifiedMailString, "\n", "\r\n", -1)) | ||
r := newMailStringReader(verifiedMailString) | ||
|
||
verifications, err := Verify(r) | ||
if err != nil { | ||
|
@@ -52,3 +58,54 @@ func TestVerify(t *testing.T) { | |
t.Errorf("Expected verification to be \n%+v\n but got \n%+v", testVerification, v) | ||
} | ||
} | ||
|
||
const verifiedEd25519MailString = `DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; | ||
d=football.example.com; [email protected]; | ||
q=dns/txt; s=brisbane; t=1528637909; h=from : to : | ||
subject : date : message-id : from : subject : date; | ||
bh=2jUSOH9NhtVGCQWNr9BrIAPreKQjO6Sn7XIkfJVOzv8=; | ||
b=/gCrinpcQOoIfuHNQIbq4pgh9kyIK3AQUdt9OdqQehSwhEIug4D11Bus | ||
Fa3bT3FY5OsU7ZbnKELq+eXdp1Q1Dw== | ||
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; | ||
d=football.example.com; [email protected]; | ||
q=dns/txt; s=test; t=1528637909; h=from : to : subject : | ||
date : message-id : from : subject : date; | ||
bh=2jUSOH9NhtVGCQWNr9BrIAPreKQjO6Sn7XIkfJVOzv8=; | ||
b=F45dVWDfMbQDGHJFlXUNB2HKfbCeLRyhDXgFpEL8GwpsRe0IeIixNTe3 | ||
DhCVlUrSjV4BwcVcOF6+FF3Zo9Rpo1tFOeS9mPYQTnGdaSGsgeefOsk2Jz | ||
dA+L10TeYt9BgDfQNZtKdN1WO//KgIqXP7OdEFE4LjFYNcUxZQ4FADY+8= | ||
From: Joe SixPack <[email protected]> | ||
To: Suzie Q <[email protected]> | ||
Subject: Is dinner ready? | ||
Date: Fri, 11 Jul 2003 21:00:37 -0700 (PDT) | ||
Message-ID: <[email protected]> | ||
Hi. | ||
We lost the game. Are you hungry yet? | ||
Joe.` | ||
|
||
var testEd25519Verification = &Verification{ | ||
Domain: "football.example.com", | ||
Identifier: "@football.example.com", | ||
HeaderKeys: []string{"from", "to", "subject", "date", "message-id", "from", "subject", "date"}, | ||
BodyLength: -1, | ||
Time: time.Unix(1528637909, 0), | ||
} | ||
|
||
func TestVerify_ed25519(t *testing.T) { | ||
r := newMailStringReader(verifiedEd25519MailString) | ||
|
||
verifications, err := Verify(r) | ||
if err != nil { | ||
t.Fatalf("Expected no error while verifying signature, got: %v", err) | ||
} else if len(verifications) != 2 { | ||
t.Fatalf("Expected exactly two verifications, got %v", len(verifications)) | ||
} | ||
|
||
v := verifications[0] | ||
if !reflect.DeepEqual(testEd25519Verification, v) { | ||
t.Errorf("Expected verification to be \n%+v\n but got \n%+v", testEd25519Verification, v) | ||
} | ||
} |