https://github.com/relaycorp/doh-jvm
Basic DNS-over-HTTPS library for the JVM
https://github.com/relaycorp/doh-jvm
android dns-over-https doh java jvm kotlin
Last synced: 6 months ago
JSON representation
Basic DNS-over-HTTPS library for the JVM
- Host: GitHub
- URL: https://github.com/relaycorp/doh-jvm
- Owner: relaycorp
- License: apache-2.0
- Created: 2020-12-26T15:57:47.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2024-04-15T03:27:55.000Z (over 1 year ago)
- Last Synced: 2024-04-17T02:31:44.618Z (over 1 year ago)
- Topics: android, dns-over-https, doh, java, jvm, kotlin
- Language: Kotlin
- Homepage: https://central.sonatype.com/search?q=doh&namespace=tech.relaycorp
- Size: 1.12 MB
- Stars: 9
- Watchers: 2
- Forks: 2
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# DNS-over-HTTPS (DoH) client for the JVM and Android
This library implements a DNS-over-HTTPS (DoH) client for the JVM 8+ and Android 5+. By default, it connects to Cloudflare's DoH resolver, but any RFC 8484-compliant resolver can be used.
Behind the scenes, this client uses OkHTTP via KTor in order to get coroutine support and keep a connection pool.
For privacy reasons, HTTP requests are made with the POST method, but we'd welcome a PR to support GET requests optionally.
For security reasons, DNSSEC validation can't be turned off, but we're open to consider toggling DNSSEC validation if there's a good reason to do so and a PR is subsequently proposed.
## Install
You can get this library from [Maven Central](https://search.maven.org/artifact/tech.relaycorp/doh).
## Usage
The client has a very simple interface. For example, to resolve the `A` record(s) for `example.com`, you'd just do:
```kotlin
var aRecords : List? = null
val doh = DoHClient()
doh.use {
aRecords = doh.lookUp("example.com", "A").data
}
```Make sure to wrap your code around `.use { ... }` or call `.close()` after using the client in order to release the underlying resources.
If you don't wish to use the default resolver (Cloudflare), pass the DoH resolver URL to the constructor of `DoHClient`.
[Read the API documentation online](https://docs.relaycorp.tech/doh-jvm).
## Comparison with other JVM DoH clients
- [`org.xbill.DNS.DohResolver`](https://javadoc.io/doc/dnsjava/dnsjava/latest/org/xbill/DNS/DohResolver.html) is a proof-of-concept implementation with documented shortcomings that make it unsuitable for production environments.
- [`dohjava`](https://github.com/NUMtechnology/dohjava) is undocumented, seemed abandoned, and a cursory code review uncovered issues such as:
- It creates a single-use, blocking HTTP client.
- It only supports GET requests, which makes responses cacheable, but is [bad for privacy](https://developers.google.com/speed/public-dns/docs/doh#privacy_best_practices).
- [`okhttp3.dnsoverhttps.DnsOverHttps`](https://square.github.io/okhttp/3.x/okhttp-dnsoverhttps/okhttp3/dnsoverhttps/DnsOverHttps.html) only supports `A`/`AAAA` records because it appears to be only meant to be used with OkHTTP.## Contributing
We love contributions! If you haven't contributed to a Relaycorp project before, please take a minute to [read our guidelines](https://github.com/relaycorp/.github/blob/master/CONTRIBUTING.md) first.