Test failure with extra headers in message

Bug #737311 reported by Scott Kitterman
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
dkimpy
Fix Released
High
Stuart Gathman

Bug Description

The attached message, when used as test.message in the test suite fails the sign/verification test. If you remove the headers above From: then it works. That shouldn't matter.

Revision history for this message
Scott Kitterman (kitterman) wrote :
Revision history for this message
Stuart Gathman (stuart-gathman) wrote :

Added test case to trunk. This seems to be fixed as of at least 0.4.2 - please confirm that test case would trigger the bug. What version was it broken with? Changing the status to fixed (if I'm allowed).

Changed in pydkim:
status: Confirmed → Fix Released
Revision history for this message
Stuart Gathman (stuart-gathman) wrote :

Oops, found typo in test case. Now test case confirms bug. :-}

Changed in pydkim:
status: Fix Released → In Progress
Revision history for this message
Stuart Gathman (stuart-gathman) wrote :

I split out a select_headers function, which should help debug this.

Changed in pydkim:
milestone: none → 0.5
Revision history for this message
Stuart Gathman (stuart-gathman) wrote :

It fails when there is more than one header field with the same name and different values. I can simplify the test case now.

Revision history for this message
Stuart Gathman (stuart-gathman) wrote :

Problem is that verify calls hash_headers(), which hashes repeat headers from last to first, whereas sign does its own header hashing, which hashes repeat headers from first to last.

Revision history for this message
Stuart Gathman (stuart-gathman) wrote :

Fixed sign to call hash_headers just like verify. Test case now passes.

Revision history for this message
Stuart Gathman (stuart-gathman) wrote :

Fix sign to use hash_headers like verify does.

Changed in pydkim:
assignee: nobody → Stuart Gathman (stuart-gathman)
status: In Progress → Fix Committed
Revision history for this message
Scott Kitterman (kitterman) wrote :

So they are both last to first now? I'm curious why you did last to first? The DKIM RFCs don't help answering this question for two headers with the same name, but for different headers it mandates hashing using the ordering in h= (rfc 4871 3.7). Based on that, I would have thought first to last would be more 'expected'.

Thoughts?

Revision history for this message
Scott Kitterman (kitterman) wrote :

The h= discussion in 3.5 is even stronger. "The field MUST contain the complete list of header fields in the order presented to the signing algorithm." Those two together (3.5 and 3.7) I think mean it has to be first to last. (nevermind if i misunderstood your comment, I didn't check the code).

Revision history for this message
Scott Kitterman (kitterman) wrote :

For completeness ...

If it's the same header repeated, last to first is correct:

Signers choosing to sign an existing header field that occurs more than once in the message (such as Received) MUST sign the physically last instance of that header field in the header block. Signers wishing to sign multiple instances of such a header field MUST include the header field name multiple times in the h= tag of the DKIM-Signature header field, and MUST sign such header fields in order from the bottom of the header field block to the top. The signer MAY include more instances of a header field name in h= than there are actual corresponding header fields to indicate that additional header fields of that name SHOULD NOT be added.

Revision history for this message
Stuart Gathman (stuart-gathman) wrote :

Yes, both sign repeated headers last to first now according to spec.

However, the old code removed non-existing headers from include_headers. The new code does not. This means that verify will fail if any header mentioned in include_headers but not in the signed message (or mentioned in include_headers more times than it occurs in the message) is subsequently added to the message. This is documented feature in the RFC, so I think this is the way specifying an exact list with include_headers should work.

The solution for bug #799175 will provide SHOULD and FROZEN header lists, which sign the listed headers N and N+1 times respectively, where N is the number of occurrences in the message.

Changed in pydkim:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Bug attachments

Remote bug watches

Bug watches keep track of this bug in other bug trackers.