Skip to content

Commit

Permalink
Merge branch 'Develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Luatan committed Dec 11, 2022
2 parents d799941 + 6a4a855 commit 7826add
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 151 deletions.
70 changes: 33 additions & 37 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 12 additions & 10 deletions DNSResolver.iml
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,21 @@
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: com.squareup.okhttp3:okhttp:4.9.3" level="project" />
<orderEntry type="library" name="Maven: com.squareup.okio:okio:2.8.0" level="project" />
<orderEntry type="library" name="Maven: org.jetbrains.kotlin:kotlin-stdlib-common:1.4.0" level="project" />
<orderEntry type="library" name="Maven: org.jetbrains.kotlin:kotlin-stdlib:1.4.10" level="project" />
<orderEntry type="library" name="Maven: com.squareup.okhttp3:okhttp:4.10.0" level="project" />
<orderEntry type="library" name="Maven: com.squareup.okio:okio-jvm:3.0.0" level="project" />
<orderEntry type="library" name="Maven: org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.31" level="project" />
<orderEntry type="library" name="Maven: org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.5.31" level="project" />
<orderEntry type="library" name="Maven: org.jetbrains.kotlin:kotlin-stdlib-common:1.5.31" level="project" />
<orderEntry type="library" name="Maven: org.jetbrains.kotlin:kotlin-stdlib:1.6.20" level="project" />
<orderEntry type="library" name="Maven: org.jetbrains:annotations:13.0" level="project" />
<orderEntry type="library" name="Maven: commons-net:commons-net:3.8.0" level="project" />
<orderEntry type="library" name="Maven: no.tornado:fxlauncher:1.0.21" level="project" />
<orderEntry type="library" name="Maven: commons-io:commons-io:2.10.0" level="project" />
<orderEntry type="library" name="Maven: commons-io:commons-io:2.11.0" level="project" />
<orderEntry type="library" name="Maven: org.json:json:20210307" level="project" />
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.9.0" level="project" />
<orderEntry type="library" name="Maven: dnsjava:dnsjava:3.5.1" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.36" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-reload4j:1.7.36" level="project" />
<orderEntry type="library" name="Maven: ch.qos.reload4j:reload4j:1.2.19" level="project" />
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.10" level="project" />
<orderEntry type="library" name="Maven: dnsjava:dnsjava:3.5.2" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:2.0.5" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-reload4j:2.0.5" level="project" />
<orderEntry type="library" name="Maven: ch.qos.reload4j:reload4j:1.2.22" level="project" />
</component>
</module>
26 changes: 7 additions & 19 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.9.3</version>
<version>4.10.0</version>
</dependency>
<dependency>
<groupId>commons-net</groupId>
Expand All @@ -28,7 +28,7 @@
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.10.0</version>
<version>2.11.0</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
Expand All @@ -38,59 +38,47 @@
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.9.0</version>
<version>2.10</version>
</dependency>
<!-- https://mvnrepository.com/artifact/dnsjava/dnsjava -->
<dependency>
<groupId>dnsjava</groupId>
<artifactId>dnsjava</artifactId>
<version>3.5.1</version>
<version>3.5.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.36</version>
<version>2.0.5</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.36</version>
<version>2.0.5</version>
</dependency>
</dependencies>

<properties>
<app.mode>live</app.mode>
<!-- Installer Filename without suffix -->
<app.filename>${project.name}</app.filename>

<!-- The JavaFX Application class name -->
<app.mainClass>ch.luatan.DNSResolver.DNSResolver</app.mainClass>

<!-- Optional override to specify where the cached files are stored. Default is current working directory -->
<app.cacheDir>downloads</app.cacheDir>

<!-- The Application vendor used by javapackager -->
<app.vendor>Simon Schmid</app.vendor>

<!-- The Application version used by javapackager -->
<app.version>1.0</app.version>

<!-- Base URL where you will host the application artifacts -->
<app.url>https://update.dnsresolver.ch/v1/${app.mode}</app.url>

<!-- Optional scp target for application artifacts hosted at the above url -->
<app.deploy.target>[email protected]:/var/www/update.dnsresolver.ch/public_html/v1/${app.mode}</app.deploy.target>

<app.deploy.target>[email protected]:/var/www/update.dnsresolver.ch/public_html/v1/${app.mode}</app.deploy.target>
<!-- The app and launcher will be assembled in this folder -->
<app.dir>${project.build.directory}/DNSResolver</app.dir>

<!-- Native installers will be built in this folder -->
<app.installerdir>${project.build.directory}/installer</app.installerdir>

<!-- Should the client downgrade if the server version is older than the local version? -->
<app.acceptDowngrade>true</app.acceptDowngrade>

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<javafx.version>1</javafx.version>
<javafx.maven.plugin.version>0.0.6</javafx.maven.plugin.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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);
}
Expand All @@ -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) {
Expand Down Expand Up @@ -123,8 +126,8 @@ public String validateDNSSEC() {
}

@Override
public void ignoreDNSSEC() {
useDnssec = false;
public void useDNSSEC(boolean value) {
useDnssec = value;
}

private void addErrors(List<Record> records) {
Expand All @@ -135,7 +138,19 @@ private void addErrors(List<Record> 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;
Expand All @@ -146,6 +161,9 @@ private boolean anyQueryAllowed() {

private void resolveInMultipleRequests(Resolver resolver, String domain) {
List<Type> 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);
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,25 @@ public void resolve(String domain, Type type, String dnsServer) {
}
}

public List<Record> getRecords(Type type) {
List<Record> 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;
Expand Down Expand Up @@ -133,24 +152,4 @@ private void addMessage(String message) {
DNSResolver.LOGGER.error(message);
createRecord(message, SpecialType.MSG);
}

public List<Record> getRecords(Type type) {
List<Record> 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() {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ public interface Resolvable {

String validateDNSSEC();

void ignoreDNSSEC();
void useDNSSEC(boolean value);
}
Loading

0 comments on commit 7826add

Please sign in to comment.