@@ -13,8 +13,7 @@ use std::{error, fmt};
13
13
use bitcoin:: secp256k1;
14
14
15
15
use 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 } ;
18
17
use lightning:: ln:: peers:: transport:: IPeerHandshake ;
19
18
use utils:: test_logger;
20
19
@@ -122,10 +121,13 @@ impl TestCtx {
122
121
}
123
122
}
124
123
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.
127
126
#[ 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 > {
129
131
// Keep sending messages back and forth until the input data is consumed
130
132
loop {
131
133
// Randomly generate message length
@@ -137,9 +139,9 @@ fn do_conduit_tests(generator: &mut FuzzGen, initiator_conduit: &mut Conduit, re
137
139
138
140
// randomly choose sender of message
139
141
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 ( ) {
143
145
msg
144
146
} else {
145
147
assert ! ( failures_expected) ;
@@ -150,9 +152,9 @@ fn do_conduit_tests(generator: &mut FuzzGen, initiator_conduit: &mut Conduit, re
150
152
return Ok ( ( ) ) ;
151
153
}
152
154
} 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 ( ) {
156
158
msg
157
159
} else {
158
160
assert ! ( failures_expected) ;
@@ -169,33 +171,33 @@ fn do_conduit_tests(generator: &mut FuzzGen, initiator_conduit: &mut Conduit, re
169
171
}
170
172
171
173
// 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.
173
175
#[ inline]
174
176
fn do_completed_handshake_test ( generator : & mut FuzzGen ) -> Result < ( ) , GeneratorFinishedError > {
175
177
let mut test_ctx = TestCtx :: make ( generator) ?;
176
178
177
179
// The handshake should complete with any valid private keys
178
180
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) {
180
182
Ok ( ( Some ( act3) , Some ( completed_handshake_info) ) ) => {
181
- ( act3, ( completed_handshake_info. conduit , completed_handshake_info . their_node_id ) )
183
+ ( act3, completed_handshake_info)
182
184
}
183
185
_ => panic ! ( "handshake failed" )
184
186
} ;
185
187
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) {
187
189
Ok ( ( None , Some ( completed_handshake_info) ) ) => {
188
- ( completed_handshake_info. conduit , completed_handshake_info . their_node_id )
190
+ completed_handshake_info
189
191
}
190
192
_ => panic ! ( "handshake failed" )
191
193
} ;
192
194
193
195
// 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) ;
196
198
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 )
199
201
}
200
202
201
203
// 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
258
260
assert ! ( used_generated_data) ;
259
261
return Ok ( ( ) ) ;
260
262
}
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 " )
262
264
} ;
263
265
}
264
266
let act2 = act2_option. unwrap ( ) ;
@@ -283,7 +285,7 @@ fn do_handshake_test(generator: &mut FuzzGen) -> Result<(), GeneratorFinishedErr
283
285
act3_option = Some ( act3) ;
284
286
initiator_completed_handshake_info_option = Some ( completed_handshake_info_option_inner) ;
285
287
286
- // Valid conduit and pubkey indicates handshake is over
288
+ // Valid completed_handshake_info indicates handshake is over
287
289
break ;
288
290
}
289
291
// Partial act
@@ -293,11 +295,11 @@ fn do_handshake_test(generator: &mut FuzzGen) -> Result<(), GeneratorFinishedErr
293
295
assert ! ( used_generated_data) ;
294
296
return Ok ( ( ) ) ;
295
297
}
296
- _ => panic ! ( "initiator required to output act bytes, conduit, and pubkey " )
298
+ _ => panic ! ( "initiator required to output act bytes and completed_handshake_info " )
297
299
} ;
298
300
}
299
301
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()
301
303
let act3 = act3_option. unwrap ( ) ;
302
304
let mut initiator_completed_handshake_info = initiator_completed_handshake_info_option. unwrap ( ) ;
303
305
@@ -319,7 +321,7 @@ fn do_handshake_test(generator: &mut FuzzGen) -> Result<(), GeneratorFinishedErr
319
321
Ok ( ( None , Some ( completed_handshake_info_inner) ) ) => {
320
322
responder_completed_handshake_info = Some ( completed_handshake_info_inner) ;
321
323
322
- // Valid conduit and pubkey indicates handshake is over
324
+ // Valid completed_handshake_info indicates handshake is over
323
325
break ;
324
326
} ,
325
327
// partial act
@@ -329,10 +331,10 @@ fn do_handshake_test(generator: &mut FuzzGen) -> Result<(), GeneratorFinishedErr
329
331
assert ! ( used_generated_data) ;
330
332
return Ok ( ( ) ) ;
331
333
} ,
332
- _ => panic ! ( "responder required to output conduit, and pubkey " )
334
+ _ => panic ! ( "responder required to output completed_handshake_info " )
333
335
} ;
334
336
}
335
- // Ensure we actually received conduit and remote pubkey from process_act()
337
+ // Ensure we actually received completed_handshake_info from process_act()
336
338
let mut responder_completed_handshake_info = responder_completed_handshake_info. unwrap ( ) ;
337
339
338
340
// 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
345
347
return Ok ( ( ) ) ;
346
348
}
347
349
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)
350
352
}
351
353
352
354
#[ inline]
0 commit comments