1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
//! # pkix-aia-http
//!
//! Reference synchronous HTTP fetcher for
//! [`pkix-aia`](https://docs.rs/pkix-aia)'s
//! [`AiaFetcher`] trait.
//!
//! AIA (Authority Information Access, RFC 5280 §4.2.2.1) is the
//! extension that carries `caIssuers` URIs pointing at the
//! certificate's issuer. Chain-build code can follow these URIs to
//! fetch missing intermediates when the caller-supplied chain is
//! incomplete. This crate plugs an HTTP transport into the
//! [`AiaFetcher`] trait so the chain-build flow in `pkix-chain`
//! can resolve `caIssuers` URIs whose scheme is `http://` or
//! `https://`.
//!
//! ## Quick start
//!
//! ```no_run
//! use pkix_aia::AiaFetcher;
//! use pkix_aia_http::HttpFetcher;
//!
//! let fetcher = HttpFetcher::new();
//! let der_bytes = fetcher.fetch("http://ca.example/intermediate.crt")?;
//! println!("fetched {} bytes", der_bytes.len());
//! # Ok::<(), pkix_aia::AiaError>(())
//! ```
//!
//! ## Design parallel: `pkix-revocation-http`
//!
//! This crate intentionally mirrors `pkix-revocation-http`'s
//! `UreqFetcher` shape: the same `ureq` dependency, the same
//! response-size cap pattern, the same HTTPS-via-rustls feature
//! configuration, the same "construct once, fetch many times"
//! idiom. Callers running both crates in the same process can
//! configure a custom `ureq::Agent` once and pass it to both
//! fetchers via the `with_agent` builders, sharing connection
//! pools.
//!
//! The split into a separate crate per use case
//! (`pkix-revocation-http` for CRL / OCSP, `pkix-aia-http` for AIA)
//! follows the workspace's one-callback-per-crate convention. The
//! revocation and AIA seams in `pkix-chain` are independent: a
//! caller can use AIA without revocation, revocation without AIA,
//! or both. Each adapter crate is independently optional.
//!
//! ## What is fetched
//!
//! [`HttpFetcher::fetch`] issues a synchronous HTTP `GET` against
//! the supplied `uri`. The response body is returned verbatim as
//! `Vec<u8>`; parsing the bytes as a DER X.509 certificate is the
//! caller's responsibility (typically delegated to
//! `pkix-path-builder` or `pkix-chain`).
//!
//! Non-HTTP URI schemes (e.g. `ldap://`, `ftp://`) return
//! [`AiaError::UriUnsupported`] immediately, before any network
//! I/O.
//!
//! ## Limits
//!
//! - **Body size cap** — responses larger than
//! [`DEFAULT_MAX_RESPONSE_SIZE`] (1 MiB) are rejected with
//! [`AiaError::ResponseTooLarge`]. Override via
//! [`HttpFetcher::with_max_response_size`]. Real-world
//! intermediate CA certs are typically well under 4 KiB; 1 MiB is
//! a generous fail-closed default for an untrusted endpoint.
//! - **Timeout** — `ureq`'s built-in agent timeouts apply. Construct
//! a custom [`ureq::Agent`] with explicit timeouts and pass via
//! [`HttpFetcher::with_agent`] if you need a specific bound.
//! - **No retry, no backoff, no caching** — these are caller-side
//! concerns. Wrap [`HttpFetcher`] with a caching layer
//! (`pkix-aia`'s rustdoc has a `CachingFetcher` worked example)
//! or retry adapter as needed.
//! - **HTTPS via rustls** — workspace pin
//! `ureq = { features = ["rustls"] }`. Consumers with custom TLS
//! requirements (PSK, client auth at the AIA endpoint, exotic
//! trust roots) should construct their own [`ureq::Agent`] and
//! inject via [`HttpFetcher::with_agent`].
//!
//! ## # Limitations
//!
//! - Synchronous only. An async parallel (mirroring
//! `pkix-revocation-http`'s `AsyncHttpCrlFetcher` /
//! `AsyncHttpOcspFetcher`) is filed as PKIX-zkjb.5.1, deferred
//! until consumer demand surfaces.
//! - No LDAP transport. RFC 5280 §4.2.2.1 permits any URI scheme in
//! AIA `accessLocation` `GeneralName`s; in practice HTTP and HTTPS
//! dominate. An `ldap://` fetcher could ship as a sibling
//! `pkix-aia-ldap` crate if demand surfaces.
//! - No HTTP/2 connection pooling tuning beyond `ureq::Agent`'s
//! defaults. Sharing an agent across many fetches (the default
//! when you construct one [`HttpFetcher`] and keep it) reuses
//! connections; per-request tuning is not exposed.
//!
//! Tracked as PKIX-zkjb.5 in the project beads.
use Read;
use Duration;
use ;
/// Default cap on a single response body's size, in bytes.
///
/// 1 MiB. Real-world intermediate CA certificates are well under
/// 4 KiB; the generous default leaves headroom for unusual bundles
/// (e.g. a server that returns a `application/pkcs7-mime` `certs-only`
/// SignedData wrapping multiple certs) without enabling
/// denial-of-service through unbounded body growth. Callers can
/// raise the cap via [`HttpFetcher::with_max_response_size`] if
/// their environment has unusually large issuer-cert blobs.
pub const DEFAULT_MAX_RESPONSE_SIZE: usize = 1024 * 1024;
/// Default per-request timeout.
///
/// 10 seconds. AIA fetches happen in the synchronous path of chain
/// validation; a long stall blocks the caller. The 10-second default
/// is generous enough for slow CA endpoints and tight enough that a
/// dead endpoint surfaces as [`AiaError::Timeout`] rather than
/// stalling the calling thread indefinitely.
pub const DEFAULT_TIMEOUT: Duration = from_secs;
/// HTTP transport backed by `ureq`.
///
/// `HttpFetcher` is a thin adapter from [`pkix_aia::AiaFetcher`]
/// onto a [`ureq::Agent`]. It performs synchronous HTTP `GET`
/// against the
/// caller-supplied URI, bounds response body size, and translates
/// `ureq` failure modes into [`AiaError`] variants.
///
/// Construct with [`HttpFetcher::new`] for sensible defaults, or
/// [`HttpFetcher::with_agent`] to inject a pre-configured
/// [`ureq::Agent`] (custom TLS config, proxies, additional
/// timeouts, etc.).
///
/// `HttpFetcher` is `Send + Sync`; a single instance can be shared
/// across threads. The underlying agent reuses HTTP connections, so
/// keeping one instance per process is more efficient than
/// constructing a fresh one per fetch.
/// Return `true` when `uri` begins with `http://` or `https://`,
/// case-insensitively (RFC 3986 §3.1: scheme is case-insensitive).
/// Translate a `ureq::Error` into an [`AiaError`].
///
/// `ureq` 3.x surfaces HTTP error statuses as
/// `Error::StatusCode(code)` when `http_status_as_error` is on (the
/// default). All other failures — DNS resolution, connection
/// refused, TLS handshake, body decode — surface through
/// [`AiaError::IoFailure`]. Per-request timeouts surface as
/// [`AiaError::Timeout`].
// ---------------------------------------------------------------------------
// Send + Sync invariant (AGENTS.md non-negotiable #6 / PKIX-2l0v.2)
// ---------------------------------------------------------------------------
const _: fn = ;
// ---------------------------------------------------------------------------
// Compile-shape and constructor tests
// ---------------------------------------------------------------------------
//
// End-to-end behavioural verification (HTTP responses, body caps in
// flight, status mapping, timeout enforcement) lives in
// `tests/integration.rs` because it requires a live local HTTP
// server. The tests here just prove that the type compiles,
// implements the trait, and that constructors honour their inputs.