@@ -484,6 +484,36 @@ mod tests {
484
484
outbound_peer
485
485
}
486
486
487
+ fn get_inbound_peer_for_test_vectors ( ) -> PeerChannelEncryptor {
488
+ // transport-responder successful handshake
489
+ let our_node_id = SecretKey :: from_slice ( & hex:: decode ( "2121212121212121212121212121212121212121212121212121212121212121" ) . unwrap ( ) [ ..] ) . unwrap ( ) ;
490
+ let our_ephemeral = SecretKey :: from_slice ( & hex:: decode ( "2222222222222222222222222222222222222222222222222222222222222222" ) . unwrap ( ) [ ..] ) . unwrap ( ) ;
491
+
492
+ let mut inbound_peer = PeerChannelEncryptor :: new_inbound ( & our_node_id) ;
493
+
494
+ let act_one = hex:: decode ( "00036360e856310ce5d294e8be33fc807077dc56ac80d95d9cd4ddbd21325eff73f70df6086551151f58b8afe6c195782c6a" ) . unwrap ( ) . to_vec ( ) ;
495
+ assert_eq ! ( inbound_peer. process_act_one_with_keys( & act_one[ ..] , & our_node_id, our_ephemeral. clone( ) ) . unwrap( ) [ ..] , hex:: decode( "0002466d7fcae563e5cb09a0d1870bb580344804617879a14949cf22285f1bae3f276e2470b93aac583c9ef6eafca3f730ae" ) . unwrap( ) [ ..] ) ;
496
+
497
+ let act_three = hex:: decode ( "00b9e3a702e93e3a9948c2ed6e5fd7590a6e1c3a0344cfc9d5b57357049aa22355361aa02e55a8fc28fef5bd6d71ad0c38228dc68b1c466263b47fdf31e560e139ba" ) . unwrap ( ) . to_vec ( ) ;
498
+ // test vector doesn't specify the initiator static key, but it's the same as the one
499
+ // from transport-initiator successful handshake
500
+ assert_eq ! ( inbound_peer. process_act_three( & act_three[ ..] ) . unwrap( ) . serialize( ) [ ..] , hex:: decode( "034f355bdcb7cc0af728ef3cceb9615d90684bb5b2ca5f859ab0f0b704075871aa" ) . unwrap( ) [ ..] ) ;
501
+
502
+ match inbound_peer. noise_state {
503
+ NoiseState :: Finished { sk, sn, sck, rk, rn, rck } => {
504
+ assert_eq ! ( sk, hex:: decode( "bb9020b8965f4df047e07f955f3c4b88418984aadc5cdb35096b9ea8fa5c3442" ) . unwrap( ) [ ..] ) ;
505
+ assert_eq ! ( sn, 0 ) ;
506
+ assert_eq ! ( sck, hex:: decode( "919219dbb2920afa8db80f9a51787a840bcf111ed8d588caf9ab4be716e42b01" ) . unwrap( ) [ ..] ) ;
507
+ assert_eq ! ( rk, hex:: decode( "969ab31b4d288cedf6218839b27a3e2140827047f2c0f01bf5c04435d43511a9" ) . unwrap( ) [ ..] ) ;
508
+ assert_eq ! ( rn, 0 ) ;
509
+ assert_eq ! ( rck, hex:: decode( "919219dbb2920afa8db80f9a51787a840bcf111ed8d588caf9ab4be716e42b01" ) . unwrap( ) [ ..] ) ;
510
+ } ,
511
+ _ => panic ! ( )
512
+ }
513
+
514
+ inbound_peer
515
+ }
516
+
487
517
#[ test]
488
518
fn noise_initiator_test_vectors ( ) {
489
519
let our_node_id = SecretKey :: from_slice ( & hex:: decode ( "1111111111111111111111111111111111111111111111111111111111111111" ) . unwrap ( ) [ ..] ) . unwrap ( ) ;
@@ -542,28 +572,7 @@ mod tests {
542
572
let our_ephemeral = SecretKey :: from_slice ( & hex:: decode ( "2222222222222222222222222222222222222222222222222222222222222222" ) . unwrap ( ) [ ..] ) . unwrap ( ) ;
543
573
544
574
{
545
- // transport-responder successful handshake
546
- let mut inbound_peer = PeerChannelEncryptor :: new_inbound ( & our_node_id) ;
547
-
548
- let act_one = hex:: decode ( "00036360e856310ce5d294e8be33fc807077dc56ac80d95d9cd4ddbd21325eff73f70df6086551151f58b8afe6c195782c6a" ) . unwrap ( ) . to_vec ( ) ;
549
- assert_eq ! ( inbound_peer. process_act_one_with_keys( & act_one[ ..] , & our_node_id, our_ephemeral. clone( ) ) . unwrap( ) [ ..] , hex:: decode( "0002466d7fcae563e5cb09a0d1870bb580344804617879a14949cf22285f1bae3f276e2470b93aac583c9ef6eafca3f730ae" ) . unwrap( ) [ ..] ) ;
550
-
551
- let act_three = hex:: decode ( "00b9e3a702e93e3a9948c2ed6e5fd7590a6e1c3a0344cfc9d5b57357049aa22355361aa02e55a8fc28fef5bd6d71ad0c38228dc68b1c466263b47fdf31e560e139ba" ) . unwrap ( ) . to_vec ( ) ;
552
- // test vector doesn't specify the initiator static key, but it's the same as the one
553
- // from transport-initiator successful handshake
554
- assert_eq ! ( inbound_peer. process_act_three( & act_three[ ..] ) . unwrap( ) . serialize( ) [ ..] , hex:: decode( "034f355bdcb7cc0af728ef3cceb9615d90684bb5b2ca5f859ab0f0b704075871aa" ) . unwrap( ) [ ..] ) ;
555
-
556
- match inbound_peer. noise_state {
557
- NoiseState :: Finished { sk, sn, sck, rk, rn, rck } => {
558
- assert_eq ! ( sk, hex:: decode( "bb9020b8965f4df047e07f955f3c4b88418984aadc5cdb35096b9ea8fa5c3442" ) . unwrap( ) [ ..] ) ;
559
- assert_eq ! ( sn, 0 ) ;
560
- assert_eq ! ( sck, hex:: decode( "919219dbb2920afa8db80f9a51787a840bcf111ed8d588caf9ab4be716e42b01" ) . unwrap( ) [ ..] ) ;
561
- assert_eq ! ( rk, hex:: decode( "969ab31b4d288cedf6218839b27a3e2140827047f2c0f01bf5c04435d43511a9" ) . unwrap( ) [ ..] ) ;
562
- assert_eq ! ( rn, 0 ) ;
563
- assert_eq ! ( rck, hex:: decode( "919219dbb2920afa8db80f9a51787a840bcf111ed8d588caf9ab4be716e42b01" ) . unwrap( ) [ ..] ) ;
564
- } ,
565
- _ => panic ! ( )
566
- }
575
+ let _ = get_inbound_peer_for_test_vectors ( ) ;
567
576
}
568
577
{
569
578
// transport-responder act1 short read test
@@ -662,35 +671,7 @@ mod tests {
662
671
}
663
672
}
664
673
665
- let mut inbound_peer;
666
-
667
- {
668
- // transport-responder successful handshake
669
- let our_node_id = SecretKey :: from_slice ( & hex:: decode ( "2121212121212121212121212121212121212121212121212121212121212121" ) . unwrap ( ) [ ..] ) . unwrap ( ) ;
670
- let our_ephemeral = SecretKey :: from_slice ( & hex:: decode ( "2222222222222222222222222222222222222222222222222222222222222222" ) . unwrap ( ) [ ..] ) . unwrap ( ) ;
671
-
672
- inbound_peer = PeerChannelEncryptor :: new_inbound ( & our_node_id) ;
673
-
674
- let act_one = hex:: decode ( "00036360e856310ce5d294e8be33fc807077dc56ac80d95d9cd4ddbd21325eff73f70df6086551151f58b8afe6c195782c6a" ) . unwrap ( ) . to_vec ( ) ;
675
- assert_eq ! ( inbound_peer. process_act_one_with_keys( & act_one[ ..] , & our_node_id, our_ephemeral. clone( ) ) . unwrap( ) [ ..] , hex:: decode( "0002466d7fcae563e5cb09a0d1870bb580344804617879a14949cf22285f1bae3f276e2470b93aac583c9ef6eafca3f730ae" ) . unwrap( ) [ ..] ) ;
676
-
677
- let act_three = hex:: decode ( "00b9e3a702e93e3a9948c2ed6e5fd7590a6e1c3a0344cfc9d5b57357049aa22355361aa02e55a8fc28fef5bd6d71ad0c38228dc68b1c466263b47fdf31e560e139ba" ) . unwrap ( ) . to_vec ( ) ;
678
- // test vector doesn't specify the initiator static key, but it's the same as the one
679
- // from transport-initiator successful handshake
680
- assert_eq ! ( inbound_peer. process_act_three( & act_three[ ..] ) . unwrap( ) . serialize( ) [ ..] , hex:: decode( "034f355bdcb7cc0af728ef3cceb9615d90684bb5b2ca5f859ab0f0b704075871aa" ) . unwrap( ) [ ..] ) ;
681
-
682
- match inbound_peer. noise_state {
683
- NoiseState :: Finished { sk, sn, sck, rk, rn, rck } => {
684
- assert_eq ! ( sk, hex:: decode( "bb9020b8965f4df047e07f955f3c4b88418984aadc5cdb35096b9ea8fa5c3442" ) . unwrap( ) [ ..] ) ;
685
- assert_eq ! ( sn, 0 ) ;
686
- assert_eq ! ( sck, hex:: decode( "919219dbb2920afa8db80f9a51787a840bcf111ed8d588caf9ab4be716e42b01" ) . unwrap( ) [ ..] ) ;
687
- assert_eq ! ( rk, hex:: decode( "969ab31b4d288cedf6218839b27a3e2140827047f2c0f01bf5c04435d43511a9" ) . unwrap( ) [ ..] ) ;
688
- assert_eq ! ( rn, 0 ) ;
689
- assert_eq ! ( rck, hex:: decode( "919219dbb2920afa8db80f9a51787a840bcf111ed8d588caf9ab4be716e42b01" ) . unwrap( ) [ ..] ) ;
690
- } ,
691
- _ => panic ! ( )
692
- }
693
- }
674
+ let mut inbound_peer = get_inbound_peer_for_test_vectors ( ) ;
694
675
695
676
for i in 0 ..1005 {
696
677
let msg = [ 0x68 , 0x65 , 0x6c , 0x6c , 0x6f ] ;
@@ -728,23 +709,7 @@ mod tests {
728
709
#[ test]
729
710
#[ should_panic( expected = "Attempted to decrypt message longer than 65535 + 16 bytes!" ) ]
730
711
fn max_message_len_decryption ( ) {
731
- let mut inbound_peer;
732
-
733
- {
734
- // transport-responder successful handshake
735
- let our_node_id = SecretKey :: from_slice ( & hex:: decode ( "2121212121212121212121212121212121212121212121212121212121212121" ) . unwrap ( ) [ ..] ) . unwrap ( ) ;
736
- let our_ephemeral = SecretKey :: from_slice ( & hex:: decode ( "2222222222222222222222222222222222222222222222222222222222222222" ) . unwrap ( ) [ ..] ) . unwrap ( ) ;
737
-
738
- inbound_peer = PeerChannelEncryptor :: new_inbound ( & our_node_id) ;
739
-
740
- let act_one = hex:: decode ( "00036360e856310ce5d294e8be33fc807077dc56ac80d95d9cd4ddbd21325eff73f70df6086551151f58b8afe6c195782c6a" ) . unwrap ( ) . to_vec ( ) ;
741
- assert_eq ! ( inbound_peer. process_act_one_with_keys( & act_one[ ..] , & our_node_id, our_ephemeral. clone( ) ) . unwrap( ) [ ..] , hex:: decode( "0002466d7fcae563e5cb09a0d1870bb580344804617879a14949cf22285f1bae3f276e2470b93aac583c9ef6eafca3f730ae" ) . unwrap( ) [ ..] ) ;
742
-
743
- let act_three = hex:: decode ( "00b9e3a702e93e3a9948c2ed6e5fd7590a6e1c3a0344cfc9d5b57357049aa22355361aa02e55a8fc28fef5bd6d71ad0c38228dc68b1c466263b47fdf31e560e139ba" ) . unwrap ( ) . to_vec ( ) ;
744
- // test vector doesn't specify the initiator static key, but it's the same as the one
745
- // from transport-initiator successful handshake
746
- assert_eq ! ( inbound_peer. process_act_three( & act_three[ ..] ) . unwrap( ) . serialize( ) [ ..] , hex:: decode( "034f355bdcb7cc0af728ef3cceb9615d90684bb5b2ca5f859ab0f0b704075871aa" ) . unwrap( ) [ ..] ) ;
747
- }
712
+ let mut inbound_peer = get_inbound_peer_for_test_vectors ( ) ;
748
713
749
714
// MSG should not exceed LN_MAX_MSG_LEN + 16
750
715
let msg = [ 4u8 ; LN_MAX_MSG_LEN + 17 ] ;
0 commit comments