Skip to content

Commit

Permalink
Verify that the domain-name in the i= param matches (or is a subdomai…
Browse files Browse the repository at this point in the history
…n of) the d= value

Fixes issue #169
  • Loading branch information
jstedfast committed Aug 27, 2015
1 parent 632ee53 commit 57d70c4
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion MimeKit/MimeMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1566,7 +1566,7 @@ static void ValidateDkimSignatureParameters (IDictionary<string, string> paramet
out DkimCanonicalizationAlgorithm bodyAlgorithm, out string d, out string s, out string q, out string[] headers, out string bh, out string b, out int maxLength)
{
bool containsFrom = false;
string v, a, c, h, l;
string v, a, c, h, l, i;

if (!parameters.TryGetValue ("v", out v))
throw new FormatException ("Malformed DKIM-Signature header: no version parameter detected.");
Expand All @@ -1586,6 +1586,19 @@ static void ValidateDkimSignatureParameters (IDictionary<string, string> paramet
if (!parameters.TryGetValue ("d", out d))
throw new FormatException ("Malformed DKIM-Signature header: no domain parameter detected.");

if (parameters.TryGetValue ("i", out i)) {
string ident;
int at;

if ((at = i.LastIndexOf ('@')) == -1)
throw new FormatException ("Malformed DKIM-Signature header: no @ in the AUID value.");

ident = i.Substring (at + 1);

if (!ident.Equals (d, StringComparison.OrdinalIgnoreCase) && !ident.EndsWith ("." + d, StringComparison.OrdinalIgnoreCase))
throw new FormatException ("Invalid DKIM-Signature header: the domain in the AUID does not match the domain parameter.");
}

if (!parameters.TryGetValue ("s", out s))
throw new FormatException ("Malformed DKIM-Signature header: no selector parameter detected.");

Expand Down

0 comments on commit 57d70c4

Please sign in to comment.