Skip to content

Commit 39aad47

Browse files
committed
dkim: remove "v" requirement for TXT records, require single record
Closes: #62
1 parent ed5980e commit 39aad47

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

dkim/query.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,17 @@ func queryDNSTXT(domain, selector string, txtLookup txtLookupFunc) (*queryResult
8484
// net.LookupTXT will concatenate strings contained in a single TXT record.
8585
// In other words, net.LookupTXT returns one entry per TXT record, even if
8686
// a record contains multiple strings.
87-
for _, txt := range txts {
88-
// RFC 7489 section 6.6.3 says records not starting with "v=" should be
89-
// ignored
90-
if strings.HasPrefix(txt, "v=") {
91-
return parsePublicKey(txt)
92-
}
87+
//
88+
// RFC 6376 section 3.6.2.2 says multiple TXT records lead to undefined
89+
// behavior, so reject that.
90+
switch len(txts) {
91+
case 0:
92+
return nil, permFailError("no valid key found")
93+
case 1:
94+
return parsePublicKey(txts[0])
95+
default:
96+
return nil, permFailError("multiple TXT records found for key")
9397
}
94-
95-
return nil, permFailError("no valid key found")
9698
}
9799

98100
func parsePublicKey(s string) (*queryResult, error) {

0 commit comments

Comments
 (0)