Resolve the identity's public key: local cache first, then the server. The attestation's `attributed_to` is a `did:atomic:` (or `did:key:`) fingerprint of the signing key. ANY key used for verification — cached or freshly fetched — must fingerprint-match the sidecar's signer; the cache is only a byte source, never a trust source. A cached key that fails the gate (or that has expired/rotated) fal
(
&self,
name: &str,
node: &atomic_canonical::CanonicalNode,
)
| 171 | /// through to a fresh server fetch; only a fresh server key that itself |
| 172 | /// fails the gate is a hard error. |
| 173 | async fn resolve_remote( |
| 174 | &self, |
| 175 | name: &str, |
| 176 | node: &atomic_canonical::CanonicalNode, |
| 177 | ) -> CliResult<ResolvedKey> { |
| 178 | // The cache is namespaced by server, so we need the URL before the |
| 179 | // lookup. `apex_server_url` is a pure local config read — the |
| 180 | // offline-first property of the cache is preserved. |
| 181 | let server_url = apex_server_url(self.server.as_deref())?; |
| 182 | let mut cache = key_cache::PublicKeyCache::open(); |
| 183 | |
| 184 | // 1) Local cache first — repeat/offline verifies skip the network. |
| 185 | if let Some(cached) = cache.get(&server_url, name) { |
| 186 | if let Ok(key) = PublicKey::from_base32(&cached.public_key) { |
| 187 | match node.attributed_to.as_deref() { |
| 188 | // Cached key gate-matches the signer → use it. |
| 189 | Some(did) if did_matches_public_key(did, &key) => { |
| 190 | return Ok(ResolvedKey { |
| 191 | key, |
| 192 | source: cached.source_line(), |
| 193 | }) |
| 194 | } |
| 195 | // No signer recorded → nothing to gate, trust the cache |
| 196 | // exactly like the server path trusts a fresh fetch. |
| 197 | None => { |
| 198 | return Ok(ResolvedKey { |
| 199 | key, |
| 200 | source: cached.source_line(), |
| 201 | }) |
| 202 | } |
| 203 | // Gate miss: fall through and re-fetch — the signer may |
| 204 | // have rotated keys. |
| 205 | _ => {} |
| 206 | } |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | // 2) Fresh fetch from the configured storage server. |
| 211 | let client = build_apex_client(self.server.as_deref()).await?; |
| 212 | |
| 213 | let info = client |
| 214 | .resolve_identity_by_name(name) |
| 215 | .await |
| 216 | .map_err(remote_err)?; |
| 217 | |
| 218 | let encoded = info |
| 219 | .public_key |
| 220 | .as_deref() |
| 221 | .ok_or_else(|| CliError::RemoteError { |
| 222 | message: format!( |
| 223 | "server resolved identity '{name}' but did not return its public key; \ |
| 224 | the server may not support public-key resolution yet — fetch the key \ |
| 225 | manually with `atomic identity lookup-key <key>`" |
| 226 | ), |
| 227 | url: None, |
| 228 | })?; |
| 229 | |
| 230 | let key = PublicKey::from_base32(encoded).map_err(|e| CliError::RemoteError { |
no test coverage detected