Skip to content

Commit 072675b

Browse files
committed
Allow use of OMNameResolver without validating DNSSEC expiry
While all `OMNameResolver` users should at least use the block time to avoid accepting stale DNSSEC proofs, in some cases its annoying to pipe that data through and time may not be available (e.g. in a no-std environment). Here we enable such use by exposing an additional constructor and disabling expiry validation when it is used.
1 parent 28fd617 commit 072675b

File tree

1 file changed

+29
-9
lines changed

1 file changed

+29
-9
lines changed

lightning/src/onion_message/dns_resolution.rs

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,24 @@ impl OMNameResolver {
329329
}
330330
}
331331

332+
/// Builds a new [`OMNameResolver`] which will not validate the time limits on DNSSEC proofs
333+
/// (at least until [`Self::new_best_block`] is called).
334+
///
335+
/// If possible, you should prefer [`Self::new`] so that providing stale proofs is not
336+
/// possible, however in no-std environments where there is some trust in the resolver used and
337+
/// no time source is available, this may be acceptable.
338+
///
339+
/// Note that not calling [`Self::new_best_block`] will result in requests not timing out and
340+
/// unresolved requests leaking memory. You must instead call
341+
/// [`Self::expire_pending_resolution`] as unresolved requests expire.
342+
pub fn new_without_expiry_validation() -> Self {
343+
Self {
344+
pending_resolves: Mutex::new(new_hash_map()),
345+
latest_block_time: AtomicUsize::new(0),
346+
latest_block_height: AtomicUsize::new(0),
347+
}
348+
}
349+
332350
/// Informs the [`OMNameResolver`] of the passage of time in the form of a new best Bitcoin
333351
/// block.
334352
///
@@ -461,15 +479,17 @@ impl OMNameResolver {
461479
parsed_rrs.as_ref().and_then(|rrs| verify_rr_stream(rrs).map_err(|_| &()));
462480
if let Ok(validated_rrs) = validated_rrs {
463481
let block_time = self.latest_block_time.load(Ordering::Acquire) as u64;
464-
// Block times may be up to two hours in the future and some time into the past
465-
// (we assume no more than two hours, though the actual limits are rather
466-
// complicated).
467-
// Thus, we have to let the proof times be rather fuzzy.
468-
if validated_rrs.valid_from > block_time + 60 * 2 {
469-
return None;
470-
}
471-
if validated_rrs.expires < block_time - 60 * 2 {
472-
return None;
482+
if block_time != 0 {
483+
// Block times may be up to two hours in the future and some time into the past
484+
// (we assume no more than two hours, though the actual limits are rather
485+
// complicated).
486+
// Thus, we have to let the proof times be rather fuzzy.
487+
if validated_rrs.valid_from > block_time + 60 * 2 {
488+
return None;
489+
}
490+
if validated_rrs.expires < block_time - 60 * 2 {
491+
return None;
492+
}
473493
}
474494
let resolved_rrs = validated_rrs.resolve_name(&entry.key());
475495
if resolved_rrs.is_empty() {

0 commit comments

Comments
 (0)