| 1 |
/* |
| 2 |
* Copyright 2015-2020 the original author or authors |
| 3 |
* |
| 4 |
* This software is licensed under the Apache License, Version 2.0, |
| 5 |
* the GNU Lesser General Public License version 2 or later ("LGPL") |
| 6 |
* and the WTFPL. |
| 7 |
* You may choose either license to govern your use of this software only |
| 8 |
* upon the condition that you accept all of the terms of either |
| 9 |
* the Apache License 2.0, the LGPL 2.1+ or the WTFPL. |
| 10 |
*/ |
| 11 |
package org.minidns.integrationtest; |
| 12 |
|
| 13 |
import java.io.IOException; |
| 14 |
import java.util.Iterator; |
| 15 |
|
| 16 |
import org.junit.Ignore; |
| 17 |
import org.minidns.cache.LruCache; |
| 18 |
import org.minidns.dnssec.DnssecClient; |
| 19 |
import org.minidns.dnssec.DnssecQueryResult; |
| 20 |
import org.minidns.dnssec.DnssecUnverifiedReason; |
| 21 |
import org.minidns.dnssec.DnssecValidationFailedException; |
| 22 |
import org.minidns.record.Record; |
| 23 |
|
| 24 |
import static org.junit.jupiter.api.Assertions.assertFalse; |
| 25 |
|
| 26 |
public class DnssecTest { |
| 27 |
|
| 28 |
@Ignore |
| 29 |
@IntegrationTest |
| 30 |
public static void testOarcDaneBadSig() throws Exception { |
| 31 |
DnssecClient client = new DnssecClient(new LruCache(1024)); |
| 32 |
assertFalse(client.queryDnssec("_443._tcp.bad-sig.dane.dns-oarc.net", Record.TYPE.TLSA).isAuthenticData()); |
| 33 |
} |
| 34 |
|
| 35 |
@IntegrationTest |
| 36 |
public static void testUniDueSigOk() throws IOException { |
| 37 |
DnssecClient client = new DnssecClient(new LruCache(1024)); |
| 38 |
assertAuthentic(client.queryDnssec("sigok.verteiltesysteme.net", Record.TYPE.A)); |
| 39 |
} |
| 40 |
|
| 41 |
@IntegrationTest(expected = DnssecValidationFailedException.class) |
| 42 |
public static void testUniDueSigFail() throws IOException { |
| 43 |
DnssecClient client = new DnssecClient(new LruCache(1024)); |
| 44 |
client.query("sigfail.verteiltesysteme.net", Record.TYPE.A); |
| 45 |
} |
| 46 |
|
| 47 |
@IntegrationTest |
| 48 |
public static void testCloudFlare() throws IOException { |
| 49 |
DnssecClient client = new DnssecClient(new LruCache(1024)); |
| 50 |
assertAuthentic(client.queryDnssec("www.cloudflare-dnssec-auth.com", Record.TYPE.A)); |
| 51 |
} |
| 52 |
|
| 53 |
private static void assertAuthentic(DnssecQueryResult dnssecMessage) { |
| 54 |
if (dnssecMessage.isAuthenticData()) return; |
| 55 |
|
| 56 |
StringBuilder sb = new StringBuilder(); |
| 57 |
sb.append("Answer should contain authentic data while it does not. Reasons:\n"); |
| 58 |
for (Iterator<DnssecUnverifiedReason> it = dnssecMessage.getUnverifiedReasons().iterator(); it.hasNext(); ) { |
| 59 |
DnssecUnverifiedReason unverifiedReason = it.next(); |
| 60 |
sb.append(unverifiedReason); |
| 61 |
if (it.hasNext()) sb.append('\n'); |
| 62 |
} |
| 63 |
throw new AssertionError(sb.toString()); |
| 64 |
} |
| 65 |
} |