Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronjwood committed Mar 2, 2020
2 parents ce56779 + 9663777 commit a365e70
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 106 deletions.
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down Expand Up @@ -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'
Expand Down
6 changes: 0 additions & 6 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -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.**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String, Void, String> {

Expand All @@ -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<? extends Data> 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<Data> 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<? extends Data> 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();
}

/**
Expand Down
22 changes: 0 additions & 22 deletions app/src/main/java/com/aaronjwood/portauthority/network/Dns.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_dns.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
android:scrollbars="vertical"
android:textColor="@color/white"
android:textIsSelectable="true"
android:textSize="12sp" />
android:textSize="14sp" />

<LinearLayout
style="?attr/buttonBarButtonStyle"
Expand Down
14 changes: 12 additions & 2 deletions app/src/main/res/values-fr/array.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
</string-array>
<string-array name="upperDrawer">
<item>\u2601 Scanner l\'hôte WAN</item>
<item>\u263c Hôte de réveil</item>
<item>\u2194 Recherche DNS</item>
</string-array>
<string-array name="lowerDrawer">
Expand All @@ -26,17 +27,22 @@
<string-array name="records">
<item>Type d\'Enregistrement</item>
<item>A</item>
<item>A6</item>
<item>AAAA</item>
<item>AFSDB</item>
<item>APL</item>
<item>CAA</item>
<item>CDNSKEY</item>
<item>CDS</item>
<item>CERT</item>
<item>CNAME</item>
<item>CSYNC</item>
<item>DHCID</item>
<item>DLV</item>
<item>DNAME</item>
<item>DNSKEY</item>
<item>DS</item>
<item>HINFO</item>
<item>HIP</item>
<item>IPSECKEY</item>
<item>KEY</item>
<item>KX</item>
Expand All @@ -47,14 +53,18 @@
<item>NSEC</item>
<item>NSEC3</item>
<item>NSEC3PARAM</item>
<item>OPENPGPKEY</item>
<item>PTR</item>
<item>RP</item>
<item>RRSIG</item>
<item>RP</item>
<item>SIG</item>
<item>SOA</item>
<item>SRV</item>
<item>SSHFP</item>
<item>TA</item>
<item>TKEY</item>
<item>TLSA</item>
<item>TSIG</item>
<item>TXT</item>
<item>URI</item>
</string-array>
Expand Down
16 changes: 14 additions & 2 deletions app/src/main/res/values-ja/array.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,33 @@
</string-array>
<string-array name="upperDrawer">
<item>\u2601 WAN ホストをスキャン</item>
<item>\u263c ウェイクアップホスト</item>
<item>\u2194 DNS 検索</item>
</string-array>
<string-array name="lowerDrawer">
<item>\u2195 OUIデータベースの更新</item>
<item>\u2195 ポートデータベースの更新</item>
<item>\u2699 設定</item>
</string-array>
<string-array name="records">
<item>レコードタイプ</item>
<item>A</item>
<item>A6</item>
<item>AAAA</item>
<item>AFSDB</item>
<item>APL</item>
<item>CAA</item>
<item>CDNSKEY</item>
<item>CDS</item>
<item>CERT</item>
<item>CNAME</item>
<item>CSYNC</item>
<item>DHCID</item>
<item>DLV</item>
<item>DNAME</item>
<item>DNSKEY</item>
<item>DS</item>
<item>HINFO</item>
<item>HIP</item>
<item>IPSECKEY</item>
<item>KEY</item>
<item>KX</item>
Expand All @@ -45,14 +53,18 @@
<item>NSEC</item>
<item>NSEC3</item>
<item>NSEC3PARAM</item>
<item>OPENPGPKEY</item>
<item>PTR</item>
<item>RP</item>
<item>RRSIG</item>
<item>RP</item>
<item>SIG</item>
<item>SOA</item>
<item>SRV</item>
<item>SSHFP</item>
<item>TA</item>
<item>TKEY</item>
<item>TLSA</item>
<item>TSIG</item>
<item>TXT</item>
<item>URI</item>
</string-array>
Expand Down
13 changes: 11 additions & 2 deletions app/src/main/res/values/array.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,22 @@
<string-array name="records">
<item>Record Type</item>
<item>A</item>
<item>A6</item>
<item>AAAA</item>
<item>AFSDB</item>
<item>APL</item>
<item>CAA</item>
<item>CDNSKEY</item>
<item>CDS</item>
<item>CERT</item>
<item>CNAME</item>
<item>CSYNC</item>
<item>DHCID</item>
<item>DLV</item>
<item>DNAME</item>
<item>DNSKEY</item>
<item>DS</item>
<item>HINFO</item>
<item>HIP</item>
<item>IPSECKEY</item>
<item>KEY</item>
<item>KX</item>
Expand All @@ -48,14 +53,18 @@
<item>NSEC</item>
<item>NSEC3</item>
<item>NSEC3PARAM</item>
<item>OPENPGPKEY</item>
<item>PTR</item>
<item>RP</item>
<item>RRSIG</item>
<item>RP</item>
<item>SIG</item>
<item>SOA</item>
<item>SRV</item>
<item>SSHFP</item>
<item>TA</item>
<item>TKEY</item>
<item>TLSA</item>
<item>TSIG</item>
<item>TXT</item>
<item>URI</item>
</string-array>
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}
Expand Down

0 comments on commit a365e70

Please sign in to comment.