Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DNS Queries over HTTPS (DoH) support #122

Open
rekire opened this issue Oct 24, 2021 · 4 comments
Open

DNS Queries over HTTPS (DoH) support #122

rekire opened this issue Oct 24, 2021 · 4 comments

Comments

@rekire
Copy link

rekire commented Oct 24, 2021

I played today a bit more with your library and build a DoH client (in Kotlin) on top.

class DohResult(query: DnsMessage, data: ByteArray?) :
    DnsQueryResult(QueryMethod.tcp, query, DnsMessage(data))

class DohResolver : DnsClient() {
    override fun query(queryBuilder: DnsMessage.Builder): DnsQueryResult {
        val q = queryBuilder.setId(0).build()
        val output = ByteArrayOutputStream()
        q.writeTo(output, false)

        val client = OkHttpClient()
        val query = Base64.encodeToString(output.toByteArray()).trimEnd('=')
        val request = Request.Builder()
            .url("https://dns.google/dns-query?dns=$query")
            .header("Content-Type", "application/dns-message")
            .build()

        val result = client.newCall(request).execute()
        return DohResult(q, result.body?.bytes())
    }
}

@Test
fun doh() {
    println(DohResolver().query(Question("github.com", Record.TYPE.MX)))
}

Are you interested in a PR? I would improve the code before. Just wondering if this could be interested for you at all.

@MiniDNS MiniDNS deleted a comment from Slredmon Oct 25, 2021
@MiniDNS MiniDNS deleted a comment from rekire Oct 25, 2021
@Flowdalic
Copy link
Collaborator

Flowdalic commented Oct 25, 2021

Are you interested in a PR?

I always welcome contributions. 😄 However, no contribution is guranteed to be accepted as is, and, depending on the extent of the contribution, it may take a while to review. That said, here is some first, hopefully relevant, feedback:

  • It appears you implemented the DoH functionality by subclassing DnsClient. Ideally, DoH would be implemented as subclass of AbstractDnsDataSource.
  • Depending on the required dependencies for DoH, the DoH functionality should be put in a minidns-doh subproject.
  • The Implementation should be pure Java with respect to the Animal Sniffers Android compatibility checks
  • AbstractDnsDataSource has a synchronous API and an asynchronous API. Since the H in DoH stands for HTTP, a native asynchronous API should be easy to add. :)

That's it from the top of my head. It's always easier to discuss actual code, so feel encouraged to submit the a PR. ;-)

@rekire
Copy link
Author

rekire commented Oct 25, 2021

My code snip it above is a simple proof of concept which works for me.

Thank you for your feedback. I'll check if can fulfill your requirements and then I'll open a PR for that.

@Sami32
Copy link

Sami32 commented Feb 28, 2024

If it can be of some help?

dnsjava/dnsjava@9af9a0f

Duplicate of #50

@dugsmith
Copy link

Thank you @Sami32. It looks to me that something more like @rekire's solution would work better for Android, though. Am I missing something?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants