TLS trust bypass: AIA chain completer installs the downloaded certificate as a trust anchor
Anyone between you and the server (dodgy Wi-Fi, say) can get their own certificate trusted and quietly rewrite the calendars KashCal subscribes to.
- org.onekash.kashcal
- Affected
<= 2026.08.19Patched2026.08.20
Published · 2 min read
Summary
AiaCertificateChainCompleter completes broken TLS chains by downloading the intermediate named in the leaf's AIA extension. The bug is in buildTrustManager: it copies the system CAs into a KeyStore, adds the downloaded cert with combinedStore.setCertificateEntry("aia-intermediate", intermediate), then tmf.init(combinedStore). TrustManagerFactory.init(KeyStore) treats every entry as a trust anchor, so the downloaded cert becomes a root in its own right and its signature is never checked against a system root. The class comment says the opposite, that "a rogue intermediate is rejected".
Every input to that anchor is attacker-controlled on the network path. IcsFetcher and the settings validator both catch SSLHandshakeException and call the fallback, so an attacker's own untrusted cert triggers it. getLeafCertificate grabs the leaf over a trust-all socket with no hostname check, extractAiaCaIssuersUrl reads the caIssuers URL from it, and downloadCertificate fetches it over plain HTTP. The attacker serves their own CA there, it's installed as a trust anchor, and the request is retried with a leaf whose SAN is the target host, so hostname verification (kept on) passes. Both call sites ship in release, and IcsRefreshWorker runs the ICS path on a background schedule, so it fires with no user interaction.
Proof of concept
Compiled the real AiaCertificateChainCompleter.kt unchanged (kotlinc 2.3.21, okhttp 5.4.0) and drove buildTrustManager. Make an attacker CA and a leaf for caldav.victim.example (that name in the SAN) signed by it. buildTrustManager(attackerCA) returns a trust manager that accepts the leaf, which chains only to the attacker CA. With the JVM's 144 real system roots also in the store, the leaf is still accepted; drop the attacker CA and it's rejected. So the downloaded cert alone validates the attacker's chain. Happy to share the harness.
Impact
An on-path attacker (rogue Wi-Fi, DNS spoofing) gets a full TLS bypass on ICS subscription fetches. That channel carries no credentials, so the realistic damage is silent injection or modification of subscribed calendar content - titles, locations, URLs, reminders. They also read the request URL, exposing any token in a secret feed link. intermediateCache is process-static keyed by hostname, so one poisoning lasts until the app restarts.
Caveat
I'd call this high, not critical: a complete defeat of transport security, but bounded to the unauthenticated ICS path and needing an on-path position. I reproduced the trust-anchor bypass directly; I haven't run a full device MITM, so the end-to-end attack is reasoned from the code. The fix is to treat the downloaded cert as an intermediate that must still chain to a system root (validate with PKIX / CertPathValidator against the system anchors), not as a trust anchor.