Easy way to resolve DNS SRV records on Android

What is the most resource-efficient way to search for SRV records on Android, for example. in an XMPP client like yaxim ?

I know:

  • JNDI , which is part of JavaSE but not on Android
  • dnsjava , which adds 800 Kbytes of class files (580 Kbytes after ProGuard, so it will probably be difficult to separate only the files needed for SRV searches)
  • native tools, such as dig, nslookup, etc., which during static compilation have a trace similar to dnsjava, and, in addition, make it dependent on your own native code

I read the DNS Service Records Query to find the hostname and TCP / IP , but it lists only JNDI and dnsjava.

Of course, I am not the first to encounter this problem, and in Java there should be some lightweight DNS SRV resolver :-)

Edit: bonus points for submitting a DNSSEC / DANE verification request.

+6
source share
2 answers

It may be a little late, but a link to this question may help:

DNS lookup in DNS for SRV records

The answer has an external library (the most recent version, February 2015 at the time of this writing), is about 310 KB and is licensed under BSD. You can find it at http://www.dnsjava.org/download/ . All of this is part of one JAR, and it has been released since 1999.

+1
source

. , dnsjava , Google minidns. DNSSEC, API SRV-, Android.

app/build.gradle :

dependencies {
    implementation "org.minidns:minidns-hla:0.3.2"
}

Kotlin:

package com.example.app

import android.os.AsyncTask
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity

import kotlinx.android.synthetic.main.activity_main.*
import android.util.Log
import org.minidns.hla.ResolverApi
import java.io.IOException


class MainActivity : AppCompatActivity() {
    private val serviceName = "_mysrv._tcp.example.com"

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        FetchSrvRecord().execute(serviceName)
    }

    inner class FetchSrvRecord() : AsyncTask<String, Int, String>() {
        override fun doInBackground(names: Array<String>): String {
            try {
                val result = ResolverApi.INSTANCE.resolveSrv(names[0])
                if (result.wasSuccessful()) {
                    val srvRecords = result.sortedSrvResolvedAddresses
                    for (record in srvRecords) {
                        return "https://" + record.srv.target.toString()
                    }
                }
            } catch (e: IOException) {
                Log.e("PoC", "failed IO", e)
            } catch (e: Throwable) {
                Log.e("PoC", "failed", e)
            }

            return "https://example.com"
        }

        override fun onPostExecute(url: String) {
            super.onPostExecute(url);

            Log.d("PoC", "got $url");
        }
    }
}

Java/Android, , , apk.

0

All Articles