Skip to content

Commit eaa1e2e

Browse files
committed
f take an entropysource to force rng use
1 parent 7018be4 commit eaa1e2e

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

lightning/src/onion_message/dns_resolution.rs

+14-12
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ use crate::onion_message::messenger::{MessageSendInstructions, Responder, Respon
4545
use crate::onion_message::packet::OnionMessageContents;
4646
use crate::prelude::*;
4747
#[cfg(feature = "dnssec")]
48+
use crate::sign::EntropySource;
49+
#[cfg(feature = "dnssec")]
4850
use crate::sync::Mutex;
4951
use crate::util::ser::{Hostname, Readable, ReadableArgs, Writeable, Writer};
5052

@@ -306,29 +308,29 @@ impl OMNameResolver {
306308

307309
/// Begins the process of resolving a BIP 353 Human Readable Name.
308310
///
309-
/// The given `random_context` must be a [`DNSResolverContext`] with a fresh, unused random
310-
/// nonce which is included in the blinded path which will be set as the reply path when
311-
/// sending the returned [`DNSSECQuery`].
312-
///
313-
/// Returns a [`DNSSECQuery`] onion message which should be sent to a resolver on success.
314-
pub fn resolve_name(
315-
&self, payment_id: PaymentId, name: HumanReadableName, random_context: DNSResolverContext,
316-
) -> Result<DNSSECQuery, ()> {
311+
/// Returns a [`DNSSECQuery`] onion message and a [`DNSResolverContext`] which should be sent
312+
/// to a resolver (with the context used to generate the blinded response path) on success.
313+
pub fn resolve_name<ES: EntropySource + ?Sized>(
314+
&self, payment_id: PaymentId, name: HumanReadableName, entropy_source: &ES,
315+
) -> Result<(DNSSECQuery, DNSResolverContext), ()> {
317316
let dns_name =
318317
Name::try_from(format!("{}.user._bitcoin-payment.{}.", name.user, name.domain));
319318
debug_assert!(
320319
dns_name.is_ok(),
321320
"The HumanReadableName constructor shouldn't allow names which are too long"
322321
);
323-
let name_query = dns_name.clone().map(|q| DNSSECQuery(q));
322+
let mut context = DNSResolverContext { nonce: [0; 16] };
323+
context.nonce.copy_from_slice(&entropy_source.get_secure_random_bytes()[..16]);
324324
if let Ok(dns_name) = dns_name {
325325
let start_height = self.latest_block_height.load(Ordering::Acquire) as u32;
326326
let mut pending_resolves = self.pending_resolves.lock().unwrap();
327-
let context = random_context;
327+
let context_ret = context.clone();
328328
let resolution = PendingResolution { start_height, context, name, payment_id };
329-
pending_resolves.entry(dns_name).or_insert_with(Vec::new).push(resolution);
329+
pending_resolves.entry(dns_name.clone()).or_insert_with(Vec::new).push(resolution);
330+
Ok((DNSSECQuery(dns_name), context_ret))
331+
} else {
332+
Err(())
330333
}
331-
name_query
332334
}
333335

334336
/// Handles a [`DNSSECProof`] message, attempting to verify it and match it against a pending

0 commit comments

Comments
 (0)