9.6. Compare anchor keys with an independent source
Feature guides / 9. Updates, rollover, and revocation · Example context
eduGAIN publishes updated keys in its EC. LIGO Wiki also receives keys through an independently authenticated operational channel. Comparing the two can reveal a stale publication or an unexpected key change before the application changes its trust configuration.
How to use it
Host and role APIs accept approved anchor pins; they do not retrieve your independent operational key source or decide whether to replace those pins. Core's compareTrustAnchorKeys() is needed for that operator check. It compares complete public sets, key identifiers, and key material. It returns a comparison report rather than updating the application's anchors. Invalid inputs are reported as input errors and do not produce a match.
import type { CryptoEngine } from "@oidfed/crypto";
import { compareTrustAnchorKeys, entityId, type JWKSet } from "@oidfed/core";
export function compareCampusKeys(
engine: CryptoEngine,
ecKeys: JWKSet,
independentlyObtainedKeys: JWKSet,
) {
return compareTrustAnchorKeys(ecKeys, independentlyObtainedKeys, entityId("https://edugain.example"), engine);
}
What your application owns
Establish the independent channel's authenticity and decide how to investigate differences during an expected rollover. Two responses from the same compromised source are not independent evidence. The helper makes no trust decision for you and does not fetch or replace pinned keys. On disagreement, retrieve both sources again as §11.3 recommends, without reusing the same cached responses. A persistent mismatch needs the operator's remediation policy. The complete comparison example shows fresh retrieval, explicit Result handling, and EC verification against independently authenticated keys.
Handle a persistent disagreement
When the comparison reports different sets or key material, preserve the report for the operator and retrieve both sources again without replaying the same cache entry. An expected rollover can explain a temporary mismatch, but it does not justify replacing pinned keys with whichever source answered last.
If the fresh sources still disagree, follow the federation's remediation procedure. That may pause new trust decisions until an operator authenticates the intended key set. Keep that administrative action separate from the comparison helper: it reports evidence and does not silently change the application's trust configuration.
Compare and retrieve again on a key mismatch
LIGO Wiki checks eduGAIN through two channels: its EC endpoint and the independent key source approved by the federation operator. §11.3 says the keys SHOULD be compared and, on disagreement, both SHOULD be retrieved again. The example makes at most two comparisons and leaves remediation to the application.
The independent retrieval callback must authenticate its source and retrieve again on each invocation. Both EC requests bypass oidfed’s statement cache. Configure the HTTP transport and independent channel to fetch fresh responses as well. An EC's self-published keys alone cannot establish the independent source's authenticity.
import {
compareTrustAnchorKeys, createTrustAnchorSet, decodeEntityConfiguration, discoverEntityFromChain,
entityId, err, fetchEntityConfiguration, InternalErrorCode, ok,
type FederationOptions, type JWKSet, type Result, type TrustAnchorKeyComparisonResult,
} from "@oidfed/core";
export async function checkCampusKeys(
// Fetch again on each call through the operator's independently authenticated channel.
retrieveIndependentKeys: () => Promise<Result<JWKSet>>,
options: FederationOptions,
): Promise<Result<TrustAnchorKeyComparisonResult>> {
const anchor = entityId("https://edugain.example");
const freshOptions = { ...options, storage: undefined };
for (let attempt = 0; attempt < 2; attempt++) {
const fetched = await fetchEntityConfiguration(anchor, freshOptions);
if (!fetched.ok) return fetched;
const independent = await retrieveIndependentKeys();
if (!independent.ok) return independent;
const decoded = decodeEntityConfiguration(fetched.value, freshOptions);
if (!decoded.ok) return decoded;
if (decoded.value.payload.iss !== anchor || decoded.value.payload.sub !== anchor) {
return err({ code: InternalErrorCode.TrustChainInvalid, description: "Unexpected anchor identity" });
}
const comparison = await compareTrustAnchorKeys(
decoded.value.payload.jwks, independent.value, anchor, freshOptions.engine, freshOptions.algorithmRegistry,
);
if (!comparison.match) {
if (attempt === 0) continue;
return ok(comparison);
}
// Decoding and comparing alone do not authenticate the EC. Verify it against the independent keys.
const verified = await discoverEntityFromChain(anchor, [fetched.value], createTrustAnchorSet([
{ entityId: anchor, jwks: independent.value },
]), freshOptions);
if (!verified.ok) {
return err({ code: InternalErrorCode.TrustChainInvalid, description: "Anchor configuration failed validation" });
}
return ok(comparison);
}
throw new Error("Unreachable comparison state");
}
Handle a failed Result as unavailable or invalid evidence. On success, inspect result.value.match and inputErrors: a persistent mismatch still requires the operator's investigation and remediation policy. Agreement and EC validation do not update the application's existing anchor configuration. Adoption of replacement keys remains a separate, authorized decision. No library timer runs this comparison for you.