paulc / dnslib

A Python library to encode/decode DNS wire-format packets
https://github.com/paulc/dnslib
BSD 2-Clause "Simplified" License
295 stars 84 forks source link

DNSLabels are not hashed case-insensitively #22

Closed Tugzrida closed 3 years ago

Tugzrida commented 3 years ago

I'm not sure if there's a reason behind this, but the __eq__ method of DNSLabel allows for case-insensitive comparison, whereas __hash__, matchSuffix and stripSuffix are case sensitive.

My use case is storing some records in a dict keyed by name and to get it to work properly now requires manually converting everything to lowercase before searching.

paulc commented 3 years ago

That's a good point - Need to think about matchSuffix and stripSuffix but hash should definitely be case-insensitive. Fixed in 0.9.15

antonio-salguero commented 2 years ago

@paulc wanted to ask what the status of matchSuffix is, will there also be a fix here ?

NiKiZe commented 2 years ago

I just got an issue with matchSuffix as well. I belive that it (at least most of the time) should be case insensitive https://datatracker.ietf.org/doc/html/rfc4343

>>> from dnslib.dns import DNSLabel
>>> l = DNSLabel("test.example.Com")
>>> l
<DNSLabel: 'test.example.Com.'>
>>> l.matchSuffix("example.Com")
True
>>> l.matchSuffix("example.com")
False
>>>

The last command is False, expected True

It is seen in the wild that requests are coming in especially as .ip6.arpa. and .IP6.ARPA.