mosajjal / dnsclient

A simple DNS Client API for Go
GNU General Public License v2.0
3 stars 1 forks source link

Fix DoH base64 encoding #1

Closed masihyeganeh closed 1 year ago

masihyeganeh commented 1 year ago

Thanks for your awesome package. I'm trying to debug the problem I have with your sniproxy and I ended up with using DoH, but I see that TrimSuffix can't actually trim =s if there are more than one, but TrimRight does. Please make sure that I'm not wrong about it and please accept this small PR if I'm right. Thanks

mosajjal commented 1 year ago

you're right that TrimRight removes more than one = char if the request has it.

I'll update the base64 encoder to use RawStdEncoding which automatically omit padding.

masihyeganeh commented 1 year ago

Perfect. But one quick note here about DoH specification in RFC 8484 :

When the HTTP method is GET, the single variable "dns" is defined as the content of the DNS request (as described in Section 6, encoded with base64url (RFC4648).

So, the encoding should be URL instead of standard: RFC 4648 without the = at the end but with - and _ instead of + and /

mosajjal commented 1 year ago

looking at the RFC, sounds like RawURLEncoding makes more sense than RawStdEncoding. in Go's stdlib logs the same RFC is mentioned as well: image

and the alphabet mentioned in stdlib corroborates the same: image

I'll update the code. Thanks for pointing this out :)