DNS over HTTPS (DoH) in Pharo
Hi, Today Firefox switched over to using 'DNS over HTTPS (DoH)' by default. https://blog.mozilla.org/netpolicy/2020/02/25/the-facts-mozillas-dns-over-ht... We can do this in Pharo as well, even out of the box (minus the interpretation of the results, but still). First, what is this ? A good description is: https://developers.cloudflare.com/1.1.1.1/dns-over-https/ Using the Cloudflare server, we can do the following in Pharo, using the JSON wire format. ZnClient new url: 'https://cloudflare-dns.com/dns-query'; accept: 'application/dns-json'; queryAt: #name put: 'pharo.org'; queryAt: #type put: 'A'; contentReader: [ :entity | STONJSON fromString: entity contents ]; get. The actual address can be accessed inside the returned result. SocketAddress fromDottedString: (((ZnClient new url: 'https://cloudflare-dns.com/dns-query'; accept: 'application/dns-json'; queryAt: #name put: 'pharo.org'; queryAt: #type put: 'A'; contentReader: [ :entity | STONJSON fromString: entity contents ]; get) at: #Answer) first at: #data). If you load the following code, https://github.com/svenvc/NeoDNS it is just as easy to use the binary UDP wire format. ZnClient new url: 'https://cloudflare-dns.com/dns-query'; accept: 'application/dns-message'; contentWriter: [ :message | ZnEntity with: message asByteArray type: 'application/dns-message' ]; contentReader: [ :entity | DNSMessage readFrom: entity readStream ]; contents: (DNSMessage addressByName: 'pharo.org'); post. Again, the actual address can be accessed inside the returned object. (ZnClient new url: 'https://cloudflare-dns.com/dns-query'; accept: 'application/dns-message'; contentWriter: [ :message | ZnEntity with: message asByteArray type: 'application/dns-message' ]; contentReader: [ :entity | DNSMessage readFrom: entity readStream ]; contents: (DNSMessage addressByName: 'pharo.org'); post) answers first address. Incidentally, a more robust answer can be got as follows: NeoSimplifiedDNSClient default addressForName: 'pharo.org'. Sven
Sven, Thank you very much. The new package is really well done (again ;-). For others/future readers: although not explicitly explained so by Sven, the first examples will not work for all addresses. The first address returned by the Cloudflare API can be another named address instead of IP address (a kind of redirect). Therefore using the new package is more than just robust, it offers more functionality as well. Don't be shy, use the full package and use the NeoSimplifiedDNSClient class! Trying all (except last) examples using 'www.nos.nl' as hostname will result in an error, because the first answered address will be 'nos.nl'. The second answered address wil be the actual IP address. Regards, Erik -- Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html
participants (2)
-
Erik Stel -
Sven Van Caekenberghe