Skip to content

Commit d4ff34e

Browse files
committed
If we're built with std, always use real time to validate DNSSEC
In cases where we're built with the `std` feature, we can assume that `SystemTime` works, so we should use it to validate that DNSSEC proofs we receive are currently valid, even if we don't have block time data.
1 parent 072675b commit d4ff34e

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

lightning/src/onion_message/dns_resolution.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -478,16 +478,23 @@ impl OMNameResolver {
478478
let validated_rrs =
479479
parsed_rrs.as_ref().and_then(|rrs| verify_rr_stream(rrs).map_err(|_| &()));
480480
if let Ok(validated_rrs) = validated_rrs {
481-
let block_time = self.latest_block_time.load(Ordering::Acquire) as u64;
482-
if block_time != 0 {
481+
let mut time = self.latest_block_time.load(Ordering::Acquire) as u64;
482+
#[cfg(feature = "std")]
483+
{
484+
use std::time::{SystemTime, UNIX_EPOCH};
485+
let now = SystemTime::now().duration_since(UNIX_EPOCH);
486+
time = now.expect("Time must be > 1970").as_secs();
487+
}
488+
if time != 0 {
483489
// Block times may be up to two hours in the future and some time into the past
484490
// (we assume no more than two hours, though the actual limits are rather
485491
// complicated).
486492
// Thus, we have to let the proof times be rather fuzzy.
487-
if validated_rrs.valid_from > block_time + 60 * 2 {
493+
let max_time_offset = if cfg!(feature = "std") { 0 } else { 60 * 2 };
494+
if validated_rrs.valid_from > time + max_time_offset {
488495
return None;
489496
}
490-
if validated_rrs.expires < block_time - 60 * 2 {
497+
if validated_rrs.expires < time - max_time_offset {
491498
return None;
492499
}
493500
}

0 commit comments

Comments
 (0)