diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 8620c3b..cde1e80 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -9,17 +9,13 @@
-
+
-
-
-
-
-
-
-
-
-
+
+
+
+
+
@@ -220,7 +216,7 @@
-
+
@@ -236,27 +232,6 @@
-
- 1639873968721
-
-
-
- 1639873968721
-
-
- 1639877382813
-
-
-
- 1639877382813
-
-
- 1639877406997
-
-
-
- 1639877406997
-
1639919328172
@@ -579,7 +554,28 @@
1650777604133
-
+
+ 1660895487646
+
+
+
+ 1660895487646
+
+
+ 1664434861734
+
+
+
+ 1664434861734
+
+
+ 1664917496663
+
+
+
+ 1664917496663
+
+
@@ -610,9 +606,6 @@
-
-
-
@@ -635,7 +628,10 @@
-
+
+
+
+
diff --git a/DNSResolver.iml b/DNSResolver.iml
index 4e0229c..74ce009 100644
--- a/DNSResolver.iml
+++ b/DNSResolver.iml
@@ -10,19 +10,21 @@
-
-
-
-
+
+
+
+
+
+
-
+
-
-
-
-
-
+
+
+
+
+
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 261d1f1..4acf536 100644
--- a/pom.xml
+++ b/pom.xml
@@ -13,7 +13,7 @@
com.squareup.okhttp3
okhttp
- 4.9.3
+ 4.10.0
commons-net
@@ -28,7 +28,7 @@
commons-io
commons-io
- 2.10.0
+ 2.11.0
org.json
@@ -38,24 +38,22 @@
com.google.code.gson
gson
- 2.9.0
+ 2.10
-
dnsjava
dnsjava
- 3.5.1
+ 3.5.2
-
org.slf4j
slf4j-api
- 1.7.36
+ 2.0.5
org.slf4j
slf4j-log4j12
- 1.7.36
+ 2.0.5
@@ -63,34 +61,24 @@
live
${project.name}
-
ch.luatan.DNSResolver.DNSResolver
-
downloads
-
Simon Schmid
-
1.0
-
https://update.dnsresolver.ch/v1/${app.mode}
-
- pi@192.168.0.111:/var/www/update.dnsresolver.ch/public_html/v1/${app.mode}
-
+ simon@192.168.0.220:/var/www/update.dnsresolver.ch/public_html/v1/${app.mode}
${project.build.directory}/DNSResolver
-
${project.build.directory}/installer
-
true
-
UTF-8
1
0.0.6
diff --git a/src/main/java/ch/luatan/DNSResolver/Data/Resolver/DNSJavaResolver.java b/src/main/java/ch/luatan/DNSResolver/Data/Resolver/DNSJavaResolver.java
index 2737405..5928bc1 100644
--- a/src/main/java/ch/luatan/DNSResolver/Data/Resolver/DNSJavaResolver.java
+++ b/src/main/java/ch/luatan/DNSResolver/Data/Resolver/DNSJavaResolver.java
@@ -18,30 +18,28 @@
import java.util.regex.Pattern;
public class DNSJavaResolver implements Resolvable {
- static String ROOT = ". IN DS 20326 8 2 E06D44B80B8F1D39A95C0B0D7C65D08458E880409BBC683457104237C7F8EC8D";
- private boolean useDnssec = true;
+ private final static String ROOT = ". IN DS 20326 8 2 E06D44B80B8F1D39A95C0B0D7C65D08458E880409BBC683457104237C7F8EC8D";
private final List errors = new LinkedList<>();
+ private boolean useDnssec = true;
private Message answer;
@Override
public void resolve(String domain, Type type, String dnsServer) {
domain = domain + (!domain.endsWith(".") ? "." : "");
+ ValidatingResolver vr = null;
try {
org.xbill.DNS.Record query = org.xbill.DNS.Record.newRecord(Name.fromConstantString(domain), org.xbill.DNS.Type.value(type.toString()), DClass.IN);
- //run validating resolver for dnssec
- ValidatingResolver vr = new ValidatingResolver(getSimpleResolver(dnsServer));
+ vr = new ValidatingResolver(getSimpleResolver(dnsServer, Duration.ofSeconds(2)));
vr.loadTrustAnchors(new ByteArrayInputStream(ROOT.getBytes(StandardCharsets.US_ASCII)));
- // query the DNS-Zone
Message message = Message.newQuery(query);
if (!useDnssec) {
message.getHeader().setFlag(Flags.CD);
}
answer = vr.send(message);
- // Hanlde RFC8482
- if (!anyQueryAllowed()) {
- DNSResolver.LOGGER.info("ANY Request for " + domain + " was blocked due to RFC8482");
+ if (!checkRFC8482()) {
+ DNSResolver.LOGGER.info("ANY Request for " + domain + " was blocked due to RFC84482");
DNSResolver.LOGGER.info("Trying to resolve all Types manually");
resolveInMultipleRequests(vr, domain);
}
@@ -50,8 +48,13 @@ public void resolve(String domain, Type type, String dnsServer) {
errors.add("Unknown Host: " + dnsServer);
e.printStackTrace();
} catch (IOException e) {
- e.printStackTrace();
- errors.add(e.getMessage());
+ if (dnsServer.isEmpty()) {
+ // Hot Fix Timeout
+ resolveInMultipleRequests(vr, domain);
+ } else {
+ e.printStackTrace();
+ errors.add(e.getMessage());
+ }
}
if (answer == null) {
@@ -123,8 +126,8 @@ public String validateDNSSEC() {
}
@Override
- public void ignoreDNSSEC() {
- useDnssec = false;
+ public void useDNSSEC(boolean value) {
+ useDnssec = value;
}
private void addErrors(List records) {
@@ -135,7 +138,19 @@ private void addErrors(List records) {
});
}
- private boolean anyQueryAllowed() {
+ private Resolver getSimpleResolver(String dnsServer, Duration duration) throws UnknownHostException {
+ SimpleResolver sr;
+ if (!dnsServer.isEmpty()) {
+ sr = new SimpleResolver(dnsServer);
+ } else {
+ sr = new SimpleResolver("8.8.8.8");
+ }
+ sr.setTimeout(duration);
+
+ return sr;
+ }
+
+ private boolean checkRFC8482() {
for (org.xbill.DNS.Record rec : answer.getSection(Section.ANSWER)) {
if (rec instanceof HINFORecord && ((HINFORecord) rec).getCPU().equals("RFC8482")) {
return false;
@@ -146,6 +161,9 @@ private boolean anyQueryAllowed() {
private void resolveInMultipleRequests(Resolver resolver, String domain) {
List typeList = new LinkedList<>(EnumSet.allOf(DNSType.class));
+ if (answer == null) {
+ answer = new Message();
+ }
typeList.add(AdditionalTypes.NS);
typeList.forEach(value -> {
org.xbill.DNS.Record rec = org.xbill.DNS.Record.newRecord(Name.fromConstantString(domain), org.xbill.DNS.Type.value(value.toString()), DClass.IN);
@@ -159,16 +177,4 @@ private void resolveInMultipleRequests(Resolver resolver, String domain) {
}
});
}
-
- private Resolver getSimpleResolver(String dnsServer) throws UnknownHostException {
- SimpleResolver sr;
- if (!dnsServer.isEmpty()) {
- sr = new SimpleResolver(dnsServer);
- } else {
- sr = new SimpleResolver("8.8.8.8");
- }
- sr.setTimeout(Duration.ofSeconds(5));
-
- return sr;
- }
}
diff --git a/src/main/java/ch/luatan/DNSResolver/Data/Resolver/DefaultResolver.java b/src/main/java/ch/luatan/DNSResolver/Data/Resolver/DefaultResolver.java
index 004764d..6deef9a 100644
--- a/src/main/java/ch/luatan/DNSResolver/Data/Resolver/DefaultResolver.java
+++ b/src/main/java/ch/luatan/DNSResolver/Data/Resolver/DefaultResolver.java
@@ -40,6 +40,25 @@ public void resolve(String domain, Type type, String dnsServer) {
}
}
+ public List getRecords(Type type) {
+ List list = new ArrayList<>();
+ for (Record record : records) {
+ if (record.getType().equals(type)) {
+ list.add(record);
+ }
+ }
+ return list;
+ }
+
+ @Override
+ public String validateDNSSEC() {
+ return "Not implemented!";
+ }
+
+ @Override
+ public void useDNSSEC(boolean value) {
+ }
+
private void setNameServer() {
if (Domain.isSubdomain(hostname)) {
String origHost = hostname;
@@ -133,24 +152,4 @@ private void addMessage(String message) {
DNSResolver.LOGGER.error(message);
createRecord(message, SpecialType.MSG);
}
-
- public List getRecords(Type type) {
- List list = new ArrayList<>();
- for (Record record : records) {
- if (record.getType().equals(type)) {
- list.add(record);
- }
- }
- return list;
- }
-
- @Override
- public String validateDNSSEC() {
- return "Not implemented!";
- }
-
- @Override
- public void ignoreDNSSEC() {
-
- }
}
\ No newline at end of file
diff --git a/src/main/java/ch/luatan/DNSResolver/Data/Resolver/Resolvable.java b/src/main/java/ch/luatan/DNSResolver/Data/Resolver/Resolvable.java
index 0dfcbc3..9769885 100644
--- a/src/main/java/ch/luatan/DNSResolver/Data/Resolver/Resolvable.java
+++ b/src/main/java/ch/luatan/DNSResolver/Data/Resolver/Resolvable.java
@@ -15,5 +15,5 @@ public interface Resolvable {
String validateDNSSEC();
- void ignoreDNSSEC();
+ void useDNSSEC(boolean value);
}
diff --git a/src/main/java/ch/luatan/DNSResolver/Data/Whois/Whois.java b/src/main/java/ch/luatan/DNSResolver/Data/Whois/Whois.java
index 593ff6d..f69005d 100644
--- a/src/main/java/ch/luatan/DNSResolver/Data/Whois/Whois.java
+++ b/src/main/java/ch/luatan/DNSResolver/Data/Whois/Whois.java
@@ -38,7 +38,6 @@ public static List getWhois(String domainName, String whoisServer) {
DNSResolver.LOGGER.error(e.getMessage());
}
- //remove comments
whoisData = whoisData.replaceAll("([%#].*[\\S\\s])|(.*REDACTED.*[\\S\\s])|(For more info.[\\S\\s]*)", "").replaceAll("\r", "");
//split by lines
String[] tokens = whoisData.split("\\n");
diff --git a/src/main/java/ch/luatan/DNSResolver/Model/Tasks/DnsTask.java b/src/main/java/ch/luatan/DNSResolver/Model/Tasks/DnsTask.java
index a10da5d..fd251c6 100644
--- a/src/main/java/ch/luatan/DNSResolver/Model/Tasks/DnsTask.java
+++ b/src/main/java/ch/luatan/DNSResolver/Model/Tasks/DnsTask.java
@@ -27,7 +27,7 @@ public DnsTask(String host, String dnsServer) {
this.dnsServer = dnsServer;
query = new DNSJavaResolver();
if (DNSResolver.isIgnoreDNSSEC() || !dnsServer.isEmpty()) {
- query.ignoreDNSSEC();
+ query.useDNSSEC(true);
}
result = new ArrayList<>();
}
diff --git a/src/main/java/ch/luatan/DNSResolver/Model/Tasks/GetWhoisTask.java b/src/main/java/ch/luatan/DNSResolver/Model/Tasks/GetWhoisTask.java
index 3b4ed04..a655c95 100644
--- a/src/main/java/ch/luatan/DNSResolver/Model/Tasks/GetWhoisTask.java
+++ b/src/main/java/ch/luatan/DNSResolver/Model/Tasks/GetWhoisTask.java
@@ -3,10 +3,10 @@
import ch.luatan.DNSResolver.Data.API.API;
import ch.luatan.DNSResolver.Data.API.Nic;
+import ch.luatan.DNSResolver.Data.Whois.Whois;
import ch.luatan.DNSResolver.Model.Caching.WhoisDataCache;
import ch.luatan.DNSResolver.Model.Utils.Config;
import ch.luatan.DNSResolver.Model.Utils.Domain;
-import ch.luatan.DNSResolver.Data.Whois.Whois;
import ch.luatan.DNSResolver.Model.Whois.WhoisServer;
import ch.luatan.DNSResolver.Model.Whois.WhoisServerSearch;
import javafx.concurrent.Task;
@@ -19,12 +19,11 @@
public class GetWhoisTask extends Task> {
private final StringBuilder linkText = new StringBuilder();
- private final List regexPreambles = new ArrayList<>(Arrays.asList("registrar", "registrar-name", "organization"));
+ private final List regexPreambles = new ArrayList<>(Arrays.asList("registrar", "registrar-name"));
private String host;
private List res;
private WhoisDataCache cache;
-
public GetWhoisTask(String host) {
this.host = Domain.trimDomain(host);
}
@@ -32,25 +31,17 @@ public GetWhoisTask(String host) {
@Override
protected List call() {
res = new ArrayList<>();
- // Don't run if host is not set
if (host == null) {
return res;
}
-
- // Checks if the domain is the maindomain
if (Domain.isSubdomain(host)) {
host = Domain.getMainDomain(host);
}
-
- // Check if this whois is cached
if (Config.CACHING) {
cache = new WhoisDataCache(host);
-
if (cache.isCached()) {
try {
res = cache.load();
-
- //set cached sign
setLinkRegistrar();
linkText.append(" (cached)");
updateMessage(linkText.toString());
@@ -62,14 +53,11 @@ protected List call() {
return res;
}
}
-
String ext = Domain.getExtension(host);
- //choose between implementations of the Whois API depending on domain extension
API api;
if (ext.equals(".ch") | ext.equals(".li")) {
api = new Nic();
} else {
- //get Whoisserver from IANNA
WhoisServerSearch serverSearch = new WhoisServerSearch();
WhoisServer server = serverSearch.search(ext);
if (server == null) {
@@ -79,10 +67,7 @@ protected List call() {
}
res = api.query(host);
-
- // displays the registrar of the domain in the link
setLinkRegistrar();
-
if (Config.CACHING) {
cache.write(res);
}
@@ -98,14 +83,6 @@ private void setLinkRegistrar() {
updateMessage(linkText.toString());
}
- private String buildRegex() {
- // join all possible staring Strings to a preamble
- String preamble = "(?:" + String.join("|", regexPreambles) + ")";
- //handles spaces and stuff, also gets the result in the registrar group
- String regexValue = "(?:[:\\n])(?:[:\\n\\W\\r]+)?(?.+)";
- return "^" + preamble + regexValue;
- }
-
private String searchWhois(String regex) {
Pattern input = Pattern.compile(regex, Pattern.CASE_INSENSITIVE + Pattern.MULTILINE);
Pattern de = Pattern.compile("(?:Status:)\\W(connect)", Pattern.CASE_INSENSITIVE + Pattern.MULTILINE);
@@ -113,18 +90,15 @@ private String searchWhois(String regex) {
if (res.isEmpty()) {
return "";
}
-
StringBuilder sb = new StringBuilder();
-
for (String line : res) {
sb.append(line.trim()).append("\n");
}
-
Matcher matcher = input.matcher(sb.toString());
if (matcher.find()) {
+
return matcher.group(1).trim();
}
-
matcher = de.matcher(sb.toString());
if (matcher.find()) {
return "Registred";
@@ -132,4 +106,9 @@ private String searchWhois(String regex) {
return "";
}
+ private String buildRegex() {
+ String preamble = "(?:" + String.join("|", regexPreambles) + ")";
+ String regexBody = "(?:\\n\\W?organization)?:\\W?(?.+)";
+ return "^" + preamble + regexBody;
+ }
}
diff --git a/src/main/java/ch/luatan/DNSResolver/Model/Whois/WhoisServerSearch.java b/src/main/java/ch/luatan/DNSResolver/Model/Whois/WhoisServerSearch.java
index d95d346..3a5239d 100644
--- a/src/main/java/ch/luatan/DNSResolver/Model/Whois/WhoisServerSearch.java
+++ b/src/main/java/ch/luatan/DNSResolver/Model/Whois/WhoisServerSearch.java
@@ -16,7 +16,6 @@ public class WhoisServerSearch {
private final Map> tempValues = new LinkedHashMap<>();
public WhoisServer search(String ext) {
- //check if it is a ccTLD with multiple parts
String[] ext_parts = ext.split("[.]");
if (ext_parts.length > 1) {
ext = ext_parts[ext_parts.length-1];
@@ -29,17 +28,12 @@ public WhoisServer search(String ext) {
e.printStackTrace();
}
}
-
- //create dataset
createMap(ext);
-
- // dont return anything, if essential values are missing
if (tempValues.isEmpty() || !tempValues.containsKey("whois")) {
return null;
}
- // init and declare Server data
WhoisServer server = new WhoisServer(tempValues.get("domain").get(0), tempValues.get("whois").get(0));
-
+ System.out.println(server.getWhois());
server.setContacts(createContacts());
server.setCreated(tempValues.get("created").get(0));
server.setChanged(tempValues.get("changed").get(0));
@@ -98,7 +92,6 @@ private List createContacts() {
try {
addresses.add(tempValues.get("address").get(j));
} catch (IndexOutOfBoundsException e) {
- //shit happens
e.printStackTrace();
}
}