Mapping TLS Certificate Authority Sovereignty Across Nordic Municipalities
Tech Stack: Python, asyncio, Pydantic, Leaflet.js, GitHub Actions, SPARQL
Mapping TLS Certificate Authority Sovereignty Across Nordic Municipalities
Public-sector websites silently depend on TLS certificates issued by a handful of certificate authorities, most of them headquartered in the United States. When a single jurisdiction can revoke a certificate under legislation like the CLOUD Act, every municipality using that CA faces a potential kill-switch risk. I wanted to quantify and visualize this dependency across Finland, Sweden, Norway, and Denmark — so I built an automated scanning pipeline and an interactive map to make the data accessible.
1. The Problem: Invisible Infrastructure Dependencies
Every time a citizen visits a municipal website, their browser verifies a TLS certificate chain. That chain terminates at a root CA whose jurisdiction determines who ultimately controls the certificate. For most Nordic municipalities, that jurisdiction is the United States.
This raises practical questions:
- Which CAs actually issue certificates for Nordic municipal websites?
- How concentrated is the dependency on US-headquartered authorities?
- Are there municipalities already using European or domestic CAs?
These questions are difficult to answer manually across approximately 1,313 municipalities. The CA choice on a public-facing website also serves as a reliable proxy for an organization's broader procurement practices — if the website uses a US CA, other infrastructure likely does too.
2. Architecture: A Three-Phase Pipeline
The system follows a straightforward pipeline architecture:
Domain Resolution → TLS Scanning → Statistical Analysis → Map Visualization
Phase 1: Domain Resolution
Municipal domains are resolved using multiple data sources. Finnish municipalities follow predictable patterns (*.fi), but Swedish, Norwegian, and Danish domains require additional lookups via SPARQL queries against Wikidata:
import httpx
from pydantic import BaseModel, ConfigDict
class Municipality(BaseModel):
model_config = ConfigDict(frozen=True)
name: str
country: str
domain: str
wikidata_id: str | None = None
population: int | None = None
async def resolve_nordic_domains() -> list[Municipality]:
"""Resolve municipal domains from Wikidata SPARQL endpoint."""
query = """
SELECT ?item ?itemLabel ?website ?population WHERE {
?item wdt:P31 wd:Q515 .
?item wdt:P17 ?country .
VALUES ?country { wd:Q34 wd:Q35 wd:Q20 wd:Q33 }
?item wdt:P856 ?website .
OPTIONAL { ?item wdt:P1082 ?population . }
SERVICE wikibase:label { bd:serviceParam wikibase:language "en,fi,sv,no,da" }
}
"""
async with httpx.AsyncClient() as client:
response = await client.get(
"https://query.wikidata.org/sparql",
params={"query": query, "format": "json"},
)
return parse_sparql_results(response.json())
Phase 2: TLS Scanning
The scanner connects to each domain, extracts the full certificate chain, and classifies the issuing CA by jurisdiction. Asyncio enables scanning all municipalities concurrently:
import asyncio
import ssl
from dataclasses import dataclass
@dataclass(frozen=True)
class CertificateChain:
leaf_ca: str
intermediate_ca: str | None
root_ca: str
leaf_jurisdiction: str
root_jurisdiction: str
async def scan_domain(domain: str) -> CertificateChain | None:
"""Extract TLS certificate chain from a domain."""
try:
ctx = ssl.create_default_context()
reader, writer = await asyncio.wait_for(
asyncio.open_connection(domain, 443, ssl=ctx),
timeout=10.0,
)
cert = writer.get_extra_info("peercert")
ssl_object = writer.get_extra_info("ssl_object")
chain = ssl_object.get_verified_chain()
writer.close()
await writer.wait_closed()
return extract_chain_info(cert, chain)
except (asyncio.TimeoutError, ssl.SSLError, OSError):
return None
async def scan_all(municipalities: list[Municipality]) -> dict:
"""Scan all municipalities concurrently with rate limiting."""
semaphore = asyncio.Semaphore(50)
async def limited_scan(m: Municipality):
async with semaphore:
return m.domain, await scan_domain(m.domain)
results = await asyncio.gather(
*(limited_scan(m) for m in municipalities)
)
return {domain: chain for domain, chain in results if chain}
Phase 3: Risk Classification
Each municipality receives a risk score based on a weighted evidence aggregation model:
from enum import Enum
class RiskLevel(str, Enum):
CRITICAL = "critical" # All CAs in high-risk jurisdiction
HIGH = "high" # Root CA in high-risk jurisdiction
MEDIUM = "medium" # Mixed jurisdictions in chain
LOW = "low" # EU-based CAs
MINIMAL = "minimal" # Domestic or QTSP CA
# Evidence weights for sovereignty scoring
WEIGHTS = {
"leaf_certificate": 0.35,
"intermediate_ca": 0.25,
"root_ca": 0.15,
"dns_caa_record": 0.10,
"ct_logs": 0.08,
"historical_pattern": 0.07,
}
def classify_risk(chain: CertificateChain, caa_record: str | None) -> RiskLevel:
"""Classify jurisdiction risk using weighted evidence."""
score = 0.0
score += WEIGHTS["leaf_certificate"] * jurisdiction_score(chain.leaf_jurisdiction)
score += WEIGHTS["root_ca"] * jurisdiction_score(chain.root_jurisdiction)
if chain.intermediate_ca:
score += WEIGHTS["intermediate_ca"] * jurisdiction_score(
get_jurisdiction(chain.intermediate_ca)
)
if caa_record:
score += WEIGHTS["dns_caa_record"] * jurisdiction_score(
get_ca_jurisdiction(caa_record)
)
if score > 0.8:
return RiskLevel.CRITICAL
elif score > 0.6:
return RiskLevel.HIGH
elif score > 0.4:
return RiskLevel.MEDIUM
elif score > 0.2:
return RiskLevel.LOW
return RiskLevel.MINIMAL
3. Data Sources and Enrichment
The pipeline combines multiple authoritative data sources:
- GISCO LAU 2021: Geographic boundaries for all Nordic municipalities from Eurostat
- CCADB: Mozilla's Common CA Database for CA jurisdiction metadata
- Certificate Transparency logs: Historical certificate issuance data via crt.sh
- Wikidata: Municipal metadata, domains, and population figures
- DNS CAA records: Explicit CA authorization policies set by domain administrators
Certificate Transparency logs are particularly valuable — they provide a historical record of every certificate ever issued for a domain, revealing patterns and transitions between CAs over time.
4. Interactive Map with Leaflet.js
The visualization uses Leaflet.js with CARTO basemap tiles, rendering each municipality as a colored polygon based on its risk classification:
const RISK_COLORS = {
critical: '#dc2626', // Red
high: '#f97316', // Orange
medium: '#eab308', // Yellow
low: '#22c55e', // Green
minimal: '#3b82f6', // Blue
};
function createMap(municipalities) {
const map = L.map('map').setView([63.0, 18.0], 5);
L.tileLayer('https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png', {
attribution: '© OpenStreetMap contributors © CARTO',
}).addTo(map);
municipalities.forEach(({ geojson, risk, name, ca }) => {
L.geoJSON(geojson, {
style: {
fillColor: RISK_COLORS[risk],
fillOpacity: 0.6,
weight: 1,
color: '#374151',
},
})
.bindPopup(`<strong>${name}</strong><br>CA: ${ca}<br>Risk: ${risk}`)
.addTo(map);
});
}
Each polygon is interactive — clicking a municipality reveals its CA details, certificate chain, risk classification, and historical CA usage.
5. Automation with GitHub Actions
The entire pipeline runs nightly via GitHub Actions, ensuring the map always reflects the current state of certificate issuance:
name: Nightly TLS Scan
on:
schedule:
- cron: '0 2 * * *' # 02:00 UTC daily
workflow_dispatch:
jobs:
scan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: astral-sh/setup-uv@v4
- run: uv sync
- run: uv run python -m ca_sovereignty.pipeline
- run: uv run python -m ca_sovereignty.generate_site
- uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./dist
The generated static site is deployed to GitHub Pages, making the results freely accessible without any hosting costs.
6. Key Findings
The initial scan results revealed striking patterns:
- Let's Encrypt dominance: The majority of Nordic municipalities use Let's Encrypt (ISRG, US-headquartered) as their CA
- Minimal domestic CA usage: Very few municipalities use CAs headquartered in their own country or even within the EU
- Correlation with population: Larger municipalities are slightly more likely to use commercial CAs, but jurisdiction diversity remains low
- CAA adoption is rare: Most municipalities have not set DNS CAA records, meaning any trusted CA could issue certificates for their domains
These findings suggest that the Nordic public sector has a significant, largely unexamined dependency on US-jurisdiction certificate authorities.
7. Technical Decisions and Trade-offs
Why Python over Node.js/Go?
Python's asyncio provides excellent concurrency for I/O-bound scanning, Pydantic offers robust data validation with frozen models, and the data science ecosystem (for statistical analysis) is unmatched. The trade-off is slower raw execution speed, but for a nightly batch job, this is irrelevant.
Why Static Site over SPA?
The map is a static HTML page with Leaflet.js — no build step, no framework, no bundler. The data changes daily but the UI doesn't, making static generation the simplest and most reliable approach. GitHub Pages provides free, globally distributed hosting.
Why Weighted Evidence over Simple Classification?
A municipality's CA sovereignty isn't determined by a single certificate. The intermediate CA, root CA, CAA records, and CT log history all contribute to the full picture. The weighted model captures this nuance — a municipality with a European leaf certificate but a US root CA scores differently from one with a fully European chain.
8. Lessons Learned
Certificate Chains Are Messier Than Expected
Many municipalities have certificates issued by intermediate CAs owned by different companies than the root CA, due to acquisitions and cross-signing. DigiCert, for example, operates roots originally belonging to several acquired companies.
SPARQL Is Powerful but Fragile
Wikidata's SPARQL endpoint is an incredible resource for structured data about municipalities, but queries can time out or return inconsistent results. Implementing retry logic and caching query results locally was essential.
Rate Limiting Matters at Scale
Scanning 1,300+ domains simultaneously would trigger abuse detection. The asyncio semaphore approach (limiting to 50 concurrent connections) balances throughput with responsible scanning behavior.
Open Data Enables Open Analysis
The entire project relies on publicly available data — TLS certificates are public by design (Certificate Transparency), municipal boundaries are open data from Eurostat, and CA metadata comes from Mozilla's CCADB. This means the analysis is fully reproducible and auditable.
Conclusion
The CA Sovereignty Map transforms an invisible infrastructure dependency into a visible, quantifiable risk. By automating the scanning pipeline and publishing results as an interactive map, the project makes it easy for policymakers, IT administrators, and researchers to understand which foreign jurisdictions control the TLS certificates that underpin Nordic public-sector websites.
The project is open source under the EUPL-1.2 license. The full source code, methodology documentation, and self-hosting instructions are available on GitHub.
For more information: