From 20408ab48bb9264b00ebea7a819366a8fac93804 Mon Sep 17 00:00:00 2001 From: Aaron Wood Date: Tue, 25 Feb 2020 22:17:12 -0800 Subject: [PATCH 1/3] Prevent possible divide-by-zero scenario --- .../java/com/aaronjwood/portauthority/utils/UserPreference.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/aaronjwood/portauthority/utils/UserPreference.java b/app/src/main/java/com/aaronjwood/portauthority/utils/UserPreference.java index 50dfb3ad..b2fbca77 100644 --- a/app/src/main/java/com/aaronjwood/portauthority/utils/UserPreference.java +++ b/app/src/main/java/com/aaronjwood/portauthority/utils/UserPreference.java @@ -175,7 +175,7 @@ public static int getPortRangeHigh(@NonNull Context context) { public static int getPortScanThreads(@NonNull Context context) { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); String threads = preferences.getString(PORT_SCAN_THREADS, DEFAULT_PORT_SCAN_THREADS); - if (threads.isEmpty()) { + if (threads.isEmpty() || threads.equals("0")) { return Integer.parseInt(DEFAULT_PORT_SCAN_THREADS); } From 0ad13bcb285753c50cf478b8cedd7e3d77b95b5c Mon Sep 17 00:00:00 2001 From: Aaron Wood Date: Mon, 2 Mar 2020 00:14:57 -0800 Subject: [PATCH 2/3] Switch to MiniDNS --- app/build.gradle | 2 +- app/proguard-rules.pro | 6 -- .../portauthority/activity/DnsActivity.java | 11 +-- .../async/DnsLookupAsyncTask.java | 83 ++++++------------- .../aaronjwood/portauthority/network/Dns.java | 22 ----- app/src/main/res/layout/activity_dns.xml | 2 +- app/src/main/res/values-fr/array.xml | 14 +++- app/src/main/res/values-ja/array.xml | 16 +++- app/src/main/res/values/array.xml | 13 ++- build.gradle | 2 +- 10 files changed, 68 insertions(+), 103 deletions(-) delete mode 100644 app/src/main/java/com/aaronjwood/portauthority/network/Dns.java diff --git a/app/build.gradle b/app/build.gradle index 45ca7951..d6a703b9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -71,7 +71,7 @@ dependencies { implementation 'com.android.support:appcompat-v7:28.0.0' implementation 'com.squareup.okhttp3:okhttp:3.12.9' // Anything past 3.12.x will break our Android 4 support! implementation 'jcifs:jcifs:1.3.17' - implementation 'dnsjava:dnsjava:3.0.1' + implementation 'org.minidns:minidns-hla:0.3.2' debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.2' testImplementation 'junit:junit:4.12' testImplementation 'org.mockito:mockito-core:1.10.19' diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index 26ef9e2c..0b7eb396 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -1,9 +1,3 @@ --dontnote org.xbill.DNS.spi.DNSJavaNameServiceDescriptor --dontwarn org.xbill.DNS.spi.DNSJavaNameServiceDescriptor --keep class org.xbill.** { *; } --keepattributes EnclosingMethod --keepattributes InnerClasses - -dontwarn okhttp3.** -dontwarn okio.** -dontwarn javax.annotation.** diff --git a/app/src/main/java/com/aaronjwood/portauthority/activity/DnsActivity.java b/app/src/main/java/com/aaronjwood/portauthority/activity/DnsActivity.java index 53ad15a0..8e9c649e 100644 --- a/app/src/main/java/com/aaronjwood/portauthority/activity/DnsActivity.java +++ b/app/src/main/java/com/aaronjwood/portauthority/activity/DnsActivity.java @@ -11,9 +11,8 @@ import android.widget.Toast; import com.aaronjwood.portauthority.R; -import com.aaronjwood.portauthority.network.Dns; +import com.aaronjwood.portauthority.async.DnsLookupAsyncTask; import com.aaronjwood.portauthority.response.DnsAsyncResponse; -import com.aaronjwood.portauthority.utils.Errors; import com.aaronjwood.portauthority.utils.UserPreference; public final class DnsActivity extends AppCompatActivity implements DnsAsyncResponse { @@ -93,13 +92,7 @@ public void onClick(View view) { if (recordType != null) { String recordName = recordType.toString(); Toast.makeText(getApplicationContext(), getResources().getString(R.string.startingDnsLookup), Toast.LENGTH_SHORT).show(); - try { - Dns.lookup(domain, recordName, DnsActivity.this); - } catch (NoSuchFieldException e) { - Errors.showError(getApplicationContext(), e.getLocalizedMessage()); - } catch (IllegalAccessException e) { - Errors.showError(getApplicationContext(), e.getLocalizedMessage()); - } + new DnsLookupAsyncTask(DnsActivity.this).execute(domain, recordName); } } }); diff --git a/app/src/main/java/com/aaronjwood/portauthority/async/DnsLookupAsyncTask.java b/app/src/main/java/com/aaronjwood/portauthority/async/DnsLookupAsyncTask.java index 4713dc08..cde4d9c5 100644 --- a/app/src/main/java/com/aaronjwood/portauthority/async/DnsLookupAsyncTask.java +++ b/app/src/main/java/com/aaronjwood/portauthority/async/DnsLookupAsyncTask.java @@ -1,21 +1,17 @@ package com.aaronjwood.portauthority.async; -import android.content.Context; import android.os.AsyncTask; import com.aaronjwood.portauthority.response.DnsAsyncResponse; -import org.xbill.DNS.ExtendedResolver; -import org.xbill.DNS.Lookup; -import org.xbill.DNS.Record; -import org.xbill.DNS.Resolver; -import org.xbill.DNS.TextParseException; -import org.xbill.DNS.config.AndroidResolverConfigProvider; -import org.xbill.DNS.config.InitializationException; +import org.minidns.hla.ResolverApi; +import org.minidns.hla.ResolverResult; +import org.minidns.record.Data; +import org.minidns.record.Record; +import java.io.IOException; import java.lang.ref.WeakReference; -import java.net.InetSocketAddress; -import java.net.UnknownHostException; +import java.util.Set; public class DnsLookupAsyncTask extends AsyncTask { @@ -39,61 +35,34 @@ public DnsLookupAsyncTask(DnsAsyncResponse delegate) { @Override protected String doInBackground(String... params) { String domain = params[0]; - int recordType = Integer.parseInt(params[1]); - AndroidResolverConfigProvider resolverCfg = new AndroidResolverConfigProvider(); - Context ctx = (Context) this.delegate.get(); - AndroidResolverConfigProvider.setContext(ctx); + String recordType = params[1]; + ResolverResult result; try { - resolverCfg.initialize(); - String[] servers = new String[resolverCfg.servers().size()]; - for (int i = 0; i < resolverCfg.servers().size(); i++) { - InetSocketAddress server = resolverCfg.servers().get(i); - servers[i] = server.getHostName(); + Class dataClass = Record.TYPE.valueOf(recordType).getDataClass(); + if (dataClass == null) { + return "Record type " + recordType + " not supported"; } - Resolver resolver = new ExtendedResolver(servers); - Lookup lookup = new Lookup(domain, recordType); - lookup.setResolver(resolver); - Record[] records = lookup.run(); - if (records == null || records.length == 0) { - return "No records found."; - } + result = ResolverApi.INSTANCE.resolve(domain, dataClass); + } catch (IOException e) { + return "Error performing lookup on type " + recordType + ": " + e.getMessage(); + } - StringBuilder answer = new StringBuilder(); - for (Record record : records) { - String rClass = this.parseRecordClass(record.getDClass()); - answer.append(String.format("%s\t\t\t\t%s\t\t\t\t%s\t\t\t\t%s%n%n", record.getName(), record.getTTL(), rClass, record.rdataToString())); - } + if (!result.wasSuccessful()) { + return "Lookup of type " + recordType + " failed with response code " + result.getResponseCode(); + } - return answer.toString(); - } catch (TextParseException e) { - return "Error performing lookup: " + e.getMessage(); - } catch (InitializationException e) { - return "Error initializing resolver: " + e.getMessage(); - } catch (UnknownHostException e) { - return "Resolver host is unknown:: " + e.getMessage(); + Set answers = result.getAnswers(); + if (answers.isEmpty()) { + return "No records found for type " + recordType; } - } - /** - * Determines the string representation of the DNS record class - * - * @param recordClass Numeric record class - * @return Human readable record class - */ - private String parseRecordClass(int recordClass) { - switch (recordClass) { - case 1: - return "IN"; - case 2: - return "CS"; - case 3: - return "CH"; - case 4: - return "HS"; - default: - return "IN"; + StringBuilder out = new StringBuilder(); + for (Data answer : answers) { + out.append(answer.toString()).append("\n\n"); } + + return out.toString(); } /** diff --git a/app/src/main/java/com/aaronjwood/portauthority/network/Dns.java b/app/src/main/java/com/aaronjwood/portauthority/network/Dns.java deleted file mode 100644 index d1dae467..00000000 --- a/app/src/main/java/com/aaronjwood/portauthority/network/Dns.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.aaronjwood.portauthority.network; - -import com.aaronjwood.portauthority.async.DnsLookupAsyncTask; -import com.aaronjwood.portauthority.response.DnsAsyncResponse; - -import org.xbill.DNS.Type; - -public final class Dns { - - /** - * Kicks off a DNS lookup - * - * @param domain Domain name - * @param recordType The type of DNS record to look up - * @param delegate Delegate to be called when the lookup has finished - */ - public static void lookup(String domain, String recordType, DnsAsyncResponse delegate) throws NoSuchFieldException, IllegalAccessException { - String type = Integer.toString(Type.class.getField(recordType).getInt(null)); - new DnsLookupAsyncTask(delegate).execute(domain, type); - } - -} diff --git a/app/src/main/res/layout/activity_dns.xml b/app/src/main/res/layout/activity_dns.xml index 5032cf67..20fd873f 100644 --- a/app/src/main/res/layout/activity_dns.xml +++ b/app/src/main/res/layout/activity_dns.xml @@ -49,7 +49,7 @@ android:scrollbars="vertical" android:textColor="@color/white" android:textIsSelectable="true" - android:textSize="12sp" /> + android:textSize="14sp" /> \u2601 Scanner l\'hôte WAN + \u263c Hôte de réveil \u2194 Recherche DNS @@ -26,17 +27,22 @@ Type d\'Enregistrement A - A6 AAAA AFSDB APL + CAA + CDNSKEY + CDS CERT CNAME + CSYNC DHCID DLV DNAME DNSKEY DS + HINFO + HIP IPSECKEY KEY KX @@ -47,14 +53,18 @@ NSEC NSEC3 NSEC3PARAM + OPENPGPKEY PTR - RP RRSIG + RP SIG SOA SRV SSHFP + TA + TKEY TLSA + TSIG TXT URI diff --git a/app/src/main/res/values-ja/array.xml b/app/src/main/res/values-ja/array.xml index 845cd602..a129cfdd 100644 --- a/app/src/main/res/values-ja/array.xml +++ b/app/src/main/res/values-ja/array.xml @@ -16,25 +16,33 @@ \u2601 WAN ホストをスキャン + \u263c ウェイクアップホスト \u2194 DNS 検索 + \u2195 OUIデータベースの更新 + \u2195 ポートデータベースの更新 \u2699 設定 レコードタイプ A - A6 AAAA AFSDB APL + CAA + CDNSKEY + CDS CERT CNAME + CSYNC DHCID DLV DNAME DNSKEY DS + HINFO + HIP IPSECKEY KEY KX @@ -45,14 +53,18 @@ NSEC NSEC3 NSEC3PARAM + OPENPGPKEY PTR - RP RRSIG + RP SIG SOA SRV SSHFP + TA + TKEY TLSA + TSIG TXT URI diff --git a/app/src/main/res/values/array.xml b/app/src/main/res/values/array.xml index baed5e2b..1b9507ce 100644 --- a/app/src/main/res/values/array.xml +++ b/app/src/main/res/values/array.xml @@ -27,17 +27,22 @@ Record Type A - A6 AAAA AFSDB APL + CAA + CDNSKEY + CDS CERT CNAME + CSYNC DHCID DLV DNAME DNSKEY DS + HINFO + HIP IPSECKEY KEY KX @@ -48,14 +53,18 @@ NSEC NSEC3 NSEC3PARAM + OPENPGPKEY PTR - RP RRSIG + RP SIG SOA SRV SSHFP + TA + TKEY TLSA + TSIG TXT URI diff --git a/build.gradle b/build.gradle index 6f44b497..6e82ccde 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ buildscript { google() } dependencies { - classpath 'com.android.tools.build:gradle:3.6.0' + classpath 'com.android.tools.build:gradle:3.6.1' classpath 'org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.4' } } From 966377703dfc5dfa6250104e2871310129c6980b Mon Sep 17 00:00:00 2001 From: Aaron Wood Date: Mon, 2 Mar 2020 00:19:31 -0800 Subject: [PATCH 3/3] Bump versions --- app/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index d6a703b9..b1807080 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -22,8 +22,8 @@ android { defaultConfig { minSdkVersion 14 targetSdkVersion 29 - versionCode 59 - versionName "2.3.1" + versionCode 60 + versionName "2.3.2" applicationId "com.aaronjwood.portauthority" setProperty("archivesBaseName", "PortAuthority-$versionName") }