@@ -13,8 +13,7 @@ use std::{error, fmt};
1313use bitcoin:: secp256k1;
1414
1515use bitcoin:: secp256k1:: key:: { PublicKey , SecretKey } ;
16- use lightning:: ln:: peers:: conduit:: Conduit ;
17- use lightning:: ln:: peers:: handshake:: PeerHandshake ;
16+ use lightning:: ln:: peers:: handshake:: { CompletedHandshakeInfo , PeerHandshake } ;
1817use lightning:: ln:: peers:: transport:: IPeerHandshake ;
1918use utils:: test_logger;
2019
@@ -122,10 +121,13 @@ impl TestCtx {
122121 }
123122}
124123
125- // Common test function that sends encrypted messages between two conduits until the source data
126- // runs out.
124+ // Common test function that sends encrypted messages between an encryptor/decryptor until the source
125+ // data runs out.
127126#[ inline]
128- fn do_conduit_tests ( generator : & mut FuzzGen , initiator_conduit : & mut Conduit , responder_conduit : & mut Conduit , failures_expected : bool ) -> Result < ( ) , GeneratorFinishedError > {
127+ fn do_encrypted_communication_tests ( generator : & mut FuzzGen ,
128+ initiator_completed_handshake_info : & mut CompletedHandshakeInfo ,
129+ responder_completed_handshake_info : & mut CompletedHandshakeInfo ,
130+ failures_expected : bool ) -> Result < ( ) , GeneratorFinishedError > {
129131 // Keep sending messages back and forth until the input data is consumed
130132 loop {
131133 // Randomly generate message length
@@ -137,9 +139,9 @@ fn do_conduit_tests(generator: &mut FuzzGen, initiator_conduit: &mut Conduit, re
137139
138140 // randomly choose sender of message
139141 let receiver_unencrypted_msg = if generator. generate_bool ( ) ? {
140- let encrypted_msg = initiator_conduit . encryptor . encrypt ( sender_unencrypted_msg) ;
141- if let Ok ( _) = responder_conduit . decryptor . read ( & encrypted_msg) {
142- if let Some ( msg) = responder_conduit . decryptor . next ( ) {
142+ let encrypted_msg = initiator_completed_handshake_info . encryptor . encrypt ( sender_unencrypted_msg) ;
143+ if let Ok ( _) = responder_completed_handshake_info . decryptor . read ( & encrypted_msg) {
144+ if let Some ( msg) = responder_completed_handshake_info . decryptor . next ( ) {
143145 msg
144146 } else {
145147 assert ! ( failures_expected) ;
@@ -150,9 +152,9 @@ fn do_conduit_tests(generator: &mut FuzzGen, initiator_conduit: &mut Conduit, re
150152 return Ok ( ( ) ) ;
151153 }
152154 } else {
153- let encrypted_msg = responder_conduit . encryptor . encrypt ( sender_unencrypted_msg) ;
154- if let Ok ( _) = initiator_conduit . decryptor . read ( & encrypted_msg) {
155- if let Some ( msg) = initiator_conduit . decryptor . next ( ) {
155+ let encrypted_msg = responder_completed_handshake_info . encryptor . encrypt ( sender_unencrypted_msg) ;
156+ if let Ok ( _) = initiator_completed_handshake_info . decryptor . read ( & encrypted_msg) {
157+ if let Some ( msg) = initiator_completed_handshake_info . decryptor . next ( ) {
156158 msg
157159 } else {
158160 assert ! ( failures_expected) ;
@@ -169,33 +171,33 @@ fn do_conduit_tests(generator: &mut FuzzGen, initiator_conduit: &mut Conduit, re
169171}
170172
171173// This test completes a valid handshake based on fuzzer-provided private keys and then sends
172- // variable length encrypted messages between two conduits to validate that they can communicate.
174+ // variable length encrypted messages between two encryptor/decryptor to verify they can communicate.
173175#[ inline]
174176fn do_completed_handshake_test ( generator : & mut FuzzGen ) -> Result < ( ) , GeneratorFinishedError > {
175177 let mut test_ctx = TestCtx :: make ( generator) ?;
176178
177179 // The handshake should complete with any valid private keys
178180 let act2 = test_ctx. responder_handshake . process_act ( & test_ctx. act1 ) . unwrap ( ) . 0 . unwrap ( ) ;
179- let ( act3, ( mut initiator_conduit , responder_pubkey ) ) = match test_ctx. initiator_handshake . process_act ( & act2) {
181+ let ( act3, mut initiator_completed_handshake_info ) = match test_ctx. initiator_handshake . process_act ( & act2) {
180182 Ok ( ( Some ( act3) , Some ( completed_handshake_info) ) ) => {
181- ( act3, ( completed_handshake_info. conduit , completed_handshake_info . their_node_id ) )
183+ ( act3, completed_handshake_info)
182184 }
183185 _ => panic ! ( "handshake failed" )
184186 } ;
185187
186- let ( mut responder_conduit , initiator_pubkey ) = match test_ctx. responder_handshake . process_act ( & act3) {
188+ let mut responder_completed_handshake_info = match test_ctx. responder_handshake . process_act ( & act3) {
187189 Ok ( ( None , Some ( completed_handshake_info) ) ) => {
188- ( completed_handshake_info. conduit , completed_handshake_info . their_node_id )
190+ completed_handshake_info
189191 }
190192 _ => panic ! ( "handshake failed" )
191193 } ;
192194
193195 // The handshake should complete with each peer knowing the static_public_key of the remote peer
194- assert_eq ! ( initiator_pubkey , test_ctx. initiator_static_public_key) ;
195- assert_eq ! ( responder_pubkey , test_ctx. responder_static_public_key) ;
196+ assert_eq ! ( responder_completed_handshake_info . their_node_id , test_ctx. initiator_static_public_key) ;
197+ assert_eq ! ( initiator_completed_handshake_info . their_node_id , test_ctx. responder_static_public_key) ;
196198
197- // The nodes should be able to communicate over the conduit.
198- do_conduit_tests ( generator, & mut initiator_conduit , & mut responder_conduit , false )
199+ // The nodes should be able to communicate with the Encryptor/Decryptors
200+ do_encrypted_communication_tests ( generator, & mut initiator_completed_handshake_info , & mut responder_completed_handshake_info , false )
199201}
200202
201203// Either returns (act, false) or (random_bytes, true) where random_bytes is the same len as act
@@ -258,7 +260,7 @@ fn do_handshake_test(generator: &mut FuzzGen) -> Result<(), GeneratorFinishedErr
258260 assert ! ( used_generated_data) ;
259261 return Ok ( ( ) ) ;
260262 }
261- _ => panic ! ( "responder required to output act bytes and no conduit/pubkey " )
263+ _ => panic ! ( "responder required to output act bytes and no completed_handshake_info " )
262264 } ;
263265 }
264266 let act2 = act2_option. unwrap ( ) ;
@@ -283,7 +285,7 @@ fn do_handshake_test(generator: &mut FuzzGen) -> Result<(), GeneratorFinishedErr
283285 act3_option = Some ( act3) ;
284286 initiator_completed_handshake_info_option = Some ( completed_handshake_info_option_inner) ;
285287
286- // Valid conduit and pubkey indicates handshake is over
288+ // Valid completed_handshake_info indicates handshake is over
287289 break ;
288290 }
289291 // Partial act
@@ -293,11 +295,11 @@ fn do_handshake_test(generator: &mut FuzzGen) -> Result<(), GeneratorFinishedErr
293295 assert ! ( used_generated_data) ;
294296 return Ok ( ( ) ) ;
295297 }
296- _ => panic ! ( "initiator required to output act bytes, conduit, and pubkey " )
298+ _ => panic ! ( "initiator required to output act bytes and completed_handshake_info " )
297299 } ;
298300 }
299301
300- // Ensure we actually received act3 bytes, conduit, and remote pubkey from process_act()
302+ // Ensure we actually received act3 bytes, completed_handshake_info from process_act()
301303 let act3 = act3_option. unwrap ( ) ;
302304 let mut initiator_completed_handshake_info = initiator_completed_handshake_info_option. unwrap ( ) ;
303305
@@ -319,7 +321,7 @@ fn do_handshake_test(generator: &mut FuzzGen) -> Result<(), GeneratorFinishedErr
319321 Ok ( ( None , Some ( completed_handshake_info_inner) ) ) => {
320322 responder_completed_handshake_info = Some ( completed_handshake_info_inner) ;
321323
322- // Valid conduit and pubkey indicates handshake is over
324+ // Valid completed_handshake_info indicates handshake is over
323325 break ;
324326 } ,
325327 // partial act
@@ -329,10 +331,10 @@ fn do_handshake_test(generator: &mut FuzzGen) -> Result<(), GeneratorFinishedErr
329331 assert ! ( used_generated_data) ;
330332 return Ok ( ( ) ) ;
331333 } ,
332- _ => panic ! ( "responder required to output conduit, and pubkey " )
334+ _ => panic ! ( "responder required to output completed_handshake_info " )
333335 } ;
334336 }
335- // Ensure we actually received conduit and remote pubkey from process_act()
337+ // Ensure we actually received completed_handshake_info from process_act()
336338 let mut responder_completed_handshake_info = responder_completed_handshake_info. unwrap ( ) ;
337339
338340 // The handshake should complete with each peer knowing the static_public_key of the remote peer
@@ -345,8 +347,8 @@ fn do_handshake_test(generator: &mut FuzzGen) -> Result<(), GeneratorFinishedErr
345347 return Ok ( ( ) ) ;
346348 }
347349
348- // The nodes should be able to communicate over the conduit
349- do_conduit_tests ( generator, & mut initiator_completed_handshake_info. conduit , & mut responder_completed_handshake_info. conduit , used_generated_data)
350+ // The nodes should be able to communicate over the encryptor/decryptor
351+ do_encrypted_communication_tests ( generator, & mut initiator_completed_handshake_info, & mut responder_completed_handshake_info, used_generated_data)
350352}
351353
352354#[ inline]
0 commit comments