Skip to content
8 changes: 4 additions & 4 deletions .github/workflows/keys.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: keys

# The banks' DKIM keys are pinned in the code (KEY_FINGERPRINTS in AirBank and FioCz). Once a day this compares them with what DNS
# publishes, validated through DNSSEC from the root, and opens an issue when they differ: a bank that rotated its key,
# a forged key, or a root key rollover the built-in trust anchors miss. Until a release pins the new key, readers on the
# old one get Unverified, so the issue is the start of a release.
# The banks' DKIM keys are pinned in the code (KEY_FINGERPRINTS in AirBank, FioCz and KomercniBanka). Once a day this
# compares them with what DNS publishes, validated through DNSSEC from the root, and opens an issue when they differ:
# a bank that rotated its key, a forged key, or a root key rollover the built-in trust anchors miss. Until a release
# pins the new key, readers on the old one get Unverified, so the issue is the start of a release.
on:
workflow_dispatch:
schedule:
Expand Down
4 changes: 4 additions & 0 deletions modules/bank-notifications/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import org.gradle.api.tasks.testing.logging.TestExceptionFormat

plugins {
`java-library`
}
Expand Down Expand Up @@ -93,4 +95,6 @@ val checkKeys =
classpath = sourceSets.test.get().runtimeClasspath
useJUnitPlatform { includeTags("live") }
outputs.upToDateWhen { false }
// The message says why a key was refused; the default format prints only the exception's class.
testLogging { exceptionFormat = TestExceptionFormat.FULL }
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ public List<String> getRecords(CharSequence method, CharSequence selector, CharS
int rcode = response.getRcode();
if (rcode == Rcode.SERVFAIL) {
// ValidatingResolver answers SERVFAIL for a bogus answer as well as for a broken upstream; neither is a
// key.
throw new PermFailException("DNSSEC validation of " + name + " failed");
// key. Its reason tells the two apart.
throw new PermFailException("DNSSEC validation of " + name + " failed" + reason(response));
}
if (!response.getHeader().getFlag(Flags.AD)) {
throw new PermFailException("the answer for " + name + " is not DNSSEC-secure");
throw new PermFailException("the answer for " + name + " is not DNSSEC-secure" + reason(response));
}
if (rcode != Rcode.NOERROR) {
throw new PermFailException("no key at " + name + ": " + Rcode.string(rcode));
Expand All @@ -73,6 +73,16 @@ public List<String> getRecords(CharSequence method, CharSequence selector, CharS
return records;
}

/** ValidatingResolver's own explanation, a TXT record of a private class in the additional section, or nothing. */
private static String reason(Message response) {
for (Record record : response.getSection(Section.ADDITIONAL)) {
if (record.getDClass() == ValidatingResolver.VALIDATION_REASON_QCLASS && record instanceof TXTRecord txt) {
return ": " + String.join("", txt.getStrings());
}
}
return "";
}

/** Sends the queries through the machine's own resolvers and validates every answer here. */
static DnssecKeyLookup usingSystemResolvers() {
ExtendedResolver upstream = new ExtendedResolver();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,36 @@ private void assertPublishesOnlyPinnedKeys(String selector, String domain) throw
}
}

// Each refusal is pinned to its kind and carries the validator's reason. A broken resolver fails every validation,
// so the two unsigned zones then go red here instead of passing for the wrong reason. The reason is a record that
// dnsjava's ValidatingResolver adds to its answer, so a dnsjava upgrade that stops adding it turns these red too.
@Test
void refusesABogusAnswer() {
// A zone kept deliberately broken for testing validators.
assertThrows(PermFailException.class, () -> dns.getRecords("dns/txt", "x", "dnssec-failed.org"));
PermFailException refused =
assertThrows(PermFailException.class, () -> dns.getRecords("dns/txt", "x", "dnssec-failed.org"));
assertRefusedAs("DNSSEC validation of x._domainkey.dnssec-failed.org failed: ", refused);
}

@Test
void stillRefusesCsobSlovakia() {
// ČSOB SK pins no key, so DNSSEC alone would decide; csob.sk is not signed, so its e-mails stay Unverified.
assertThrows(PermFailException.class, () -> dns.getRecords("dns/txt", "x", "csob.sk"));
PermFailException refused =
assertThrows(PermFailException.class, () -> dns.getRecords("dns/txt", "x", "csob.sk"));
assertRefusedAs("the answer for x._domainkey.csob.sk is not DNSSEC-secure: ", refused);
}

@Test
void refusesAnUnsignedZone() {
// google.com is not DNSSEC-signed; its DKIM key would come back, unproven.
assertThrows(PermFailException.class, () -> dns.getRecords("dns/txt", "20230601", "google.com"));
PermFailException refused =
assertThrows(PermFailException.class, () -> dns.getRecords("dns/txt", "20230601", "google.com"));
assertRefusedAs("the answer for 20230601._domainkey.google.com is not DNSSEC-secure: ", refused);
}

private static void assertRefusedAs(String prefix, PermFailException refused) {
String message = Objects.requireNonNull(refused.getMessage());
assertTrue(message.startsWith(prefix) && message.length() > prefix.length(), message);
}

private static PublicKey publicKey(String record) throws Exception {
Expand Down