pub struct HttpDidDocFetcher { /* private fields */ }Expand description
Native HTTPS DID-document fetcher with a TTL cache.
Mirrors the JWKS fetch+cache posture in FederationKeyResolver
(crates/hyprstream/src/auth/federation.rs): HTTPS-only by default, a
reqwest client with a request timeout, and a single Mutex-guarded cache
so concurrent misses for the same URL serialize on one fetch. The cache key
is the resolved document URL.
HTTPS is required (did:web mandates it). A Mutex (not RwLock) serializes
reads and writes so a second waiter re-checks after the first finishes.
§SSRF / DoS hardening
- No redirects. The client is built with
[
reqwest::redirect::Policy::none()]: the did:web spec retrieves the document by a direct HTTPS GET, so an upstream302tohttp://169.254.169.254/…orhttp://127.0.0.1:…cannot bypass the https-only check (SSRF). The https-only check on the resolved URL is kept. - Bounded body. Responses are read with a [
MAX_DID_DOC_BYTES] ceiling (read N+1 bytes; error if exceeded) before JSON parsing — bounds memory. - Bounded cache. The TTL cache is capped at [
MAX_CACHE_ENTRIES] (sweep-expired + evict-oldest on insert) so an attacker-driven flood of distinct DIDs cannot grow it without bound. Failures are never cached.
Implementations§
Source§impl HttpDidDocFetcher
impl HttpDidDocFetcher
Sourcepub fn new(ttl: Duration) -> Result<Self>
pub fn new(ttl: Duration) -> Result<Self>
Construct a fetcher with a cache TTL (mirrors the JWKS cache TTL default of one hour; callers honoring per-issuer TTL should pass it through).
Returns Err if the reqwest client fails to build — propagated rather
than swallowed (a unwrap_or_default() would yield a client WITHOUT the
configured timeout/redirect policy, defeating the SSRF/DoS hardening).
Sourcepub fn with_extra_root(ttl: Duration, extra_root_pem: &[u8]) -> Result<Self>
pub fn with_extra_root(ttl: Duration, extra_root_pem: &[u8]) -> Result<Self>
Construct a fetcher that additionally trusts an extra root certificate
(PEM), for private-PKI deployments whose did:web host terminates TLS
with an internal CA. This ADDS a trust anchor — the public WebPKI roots
remain enabled, and all other hardening (https-only, no redirects,
timeouts, size cap) is unchanged. Returns Err on an unreadable or
malformed PEM rather than silently degrading.
Trait Implementations§
Source§impl Default for HttpDidDocFetcher
impl Default for HttpDidDocFetcher
Source§impl DidDocFetcher for HttpDidDocFetcher
impl DidDocFetcher for HttpDidDocFetcher
Auto Trait Implementations§
impl !Freeze for HttpDidDocFetcher
impl !RefUnwindSafe for HttpDidDocFetcher
impl Send for HttpDidDocFetcher
impl Sync for HttpDidDocFetcher
impl Unpin for HttpDidDocFetcher
impl UnsafeUnpin for HttpDidDocFetcher
impl !UnwindSafe for HttpDidDocFetcher
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more