@@ -468,6 +468,8 @@ impl PeerChannelEncryptor {
468
468
469
469
#[ cfg( test) ]
470
470
mod tests {
471
+ use super :: LN_MAX_MSG_LEN ;
472
+
471
473
use bitcoin:: secp256k1:: key:: { PublicKey , SecretKey } ;
472
474
473
475
use hex;
@@ -714,4 +716,38 @@ mod tests {
714
716
}
715
717
}
716
718
}
719
+
720
+ #[ test]
721
+ #[ should_panic( expected = "Attempted to encrypt message longer than 65535 bytes!" ) ]
722
+ fn max_message_len_encryption ( ) {
723
+ let mut outbound_peer = get_outbound_peer_for_initiator_test_vectors ( ) ;
724
+ let msg = [ 4u8 ; LN_MAX_MSG_LEN + 1 ] ;
725
+ outbound_peer. encrypt_message ( & msg) ;
726
+ }
727
+
728
+ #[ test]
729
+ #[ should_panic( expected = "Attempted to decrypt message longer than 65535 + 16 bytes!" ) ]
730
+ 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
+ }
748
+
749
+ // MSG should not exceed LN_MAX_MSG_LEN + 16
750
+ let msg = [ 4u8 ; LN_MAX_MSG_LEN + 17 ] ;
751
+ inbound_peer. decrypt_message ( & msg) . unwrap ( ) ;
752
+ }
717
753
}
0 commit comments