@@ -45,6 +45,8 @@ use crate::onion_message::messenger::{MessageSendInstructions, Responder, Respon
45
45
use crate :: onion_message:: packet:: OnionMessageContents ;
46
46
use crate :: prelude:: * ;
47
47
#[ cfg( feature = "dnssec" ) ]
48
+ use crate :: sign:: EntropySource ;
49
+ #[ cfg( feature = "dnssec" ) ]
48
50
use crate :: sync:: Mutex ;
49
51
use crate :: util:: ser:: { Hostname , Readable , ReadableArgs , Writeable , Writer } ;
50
52
@@ -306,29 +308,29 @@ impl OMNameResolver {
306
308
307
309
/// Begins the process of resolving a BIP 353 Human Readable Name.
308
310
///
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 ) , ( ) > {
317
316
let dns_name =
318
317
Name :: try_from ( format ! ( "{}.user._bitcoin-payment.{}." , name. user, name. domain) ) ;
319
318
debug_assert ! (
320
319
dns_name. is_ok( ) ,
321
320
"The HumanReadableName constructor shouldn't allow names which are too long"
322
321
) ;
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 ] ) ;
324
324
if let Ok ( dns_name) = dns_name {
325
325
let start_height = self . latest_block_height . load ( Ordering :: Acquire ) as u32 ;
326
326
let mut pending_resolves = self . pending_resolves . lock ( ) . unwrap ( ) ;
327
- let context = random_context ;
327
+ let context_ret = context . clone ( ) ;
328
328
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 ( ( ) )
330
333
}
331
- name_query
332
334
}
333
335
334
336
/// Handles a [`DNSSECProof`] message, attempting to verify it and match it against a pending
0 commit comments