@@ -18,7 +18,7 @@ use util::enforcing_trait_impls::EnforcingChannelKeys;
18
18
use util:: test_utils;
19
19
use util:: events:: { Event , EventsProvider , MessageSendEvent , MessageSendEventsProvider } ;
20
20
use util:: errors:: APIError ;
21
- use util:: ser:: { Writeable , ReadableArgs } ;
21
+ use util:: ser:: { Writeable , Writer , ReadableArgs } ;
22
22
use util:: config:: UserConfig ;
23
23
use util:: logger:: Logger ;
24
24
@@ -44,7 +44,7 @@ use std::collections::{BTreeSet, HashMap, HashSet};
44
44
use std:: default:: Default ;
45
45
use std:: sync:: { Arc , Mutex } ;
46
46
use std:: sync:: atomic:: Ordering ;
47
- use std:: mem;
47
+ use std:: { mem, io } ;
48
48
49
49
use rand:: { thread_rng, Rng } ;
50
50
@@ -4972,6 +4972,20 @@ impl msgs::ChannelUpdate {
4972
4972
}
4973
4973
}
4974
4974
4975
+ struct BogusOnionHopData {
4976
+ data : Vec < u8 >
4977
+ }
4978
+ impl BogusOnionHopData {
4979
+ fn new ( orig : msgs:: OnionHopData ) -> Self {
4980
+ Self { data : orig. encode ( ) }
4981
+ }
4982
+ }
4983
+ impl Writeable for BogusOnionHopData {
4984
+ fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , io:: Error > {
4985
+ writer. write_all ( & self . data [ ..] )
4986
+ }
4987
+ }
4988
+
4975
4989
#[ test]
4976
4990
fn test_onion_failure ( ) {
4977
4991
use ln:: msgs:: ChannelUpdate ;
@@ -5001,8 +5015,14 @@ fn test_onion_failure() {
5001
5015
let cur_height = nodes[ 0 ] . node . latest_block_height . load ( Ordering :: Acquire ) as u32 + 1 ;
5002
5016
let onion_keys = onion_utils:: construct_onion_keys ( & Secp256k1 :: new ( ) , & route, & session_priv) . unwrap ( ) ;
5003
5017
let ( mut onion_payloads, _htlc_msat, _htlc_cltv) = onion_utils:: build_onion_payloads ( & route, cur_height) . unwrap ( ) ;
5004
- onion_payloads[ 0 ] . format = msgs:: OnionHopDataFormat :: BogusRealm ( 3 ) ;
5005
- msg. onion_routing_packet = onion_utils:: construct_onion_packet ( onion_payloads, onion_keys, [ 0 ; 32 ] , & payment_hash) ;
5018
+ let mut new_payloads = Vec :: new ( ) ;
5019
+ for payload in onion_payloads. drain ( ..) {
5020
+ new_payloads. push ( BogusOnionHopData :: new ( payload) ) ;
5021
+ }
5022
+ // break the first (non-final) hop payload by swapping the realm (0) byte for a byte
5023
+ // describing a length-1 TLV payload, which is obviously bogus.
5024
+ new_payloads[ 0 ] . data [ 0 ] = 1 ;
5025
+ msg. onion_routing_packet = onion_utils:: construct_onion_packet_bogus_hopdata ( new_payloads, onion_keys, [ 0 ; 32 ] , & payment_hash) ;
5006
5026
} , ||{ } , true , Some ( PERM |1 ) , Some ( msgs:: HTLCFailChannelUpdate :: ChannelClosed { short_channel_id : channels[ 1 ] . 0 . contents . short_channel_id , is_permanent : true } ) ) ; //XXX incremented channels idx here
5007
5027
5008
5028
// final node failure
@@ -5011,8 +5031,14 @@ fn test_onion_failure() {
5011
5031
let cur_height = nodes[ 0 ] . node . latest_block_height . load ( Ordering :: Acquire ) as u32 + 1 ;
5012
5032
let onion_keys = onion_utils:: construct_onion_keys ( & Secp256k1 :: new ( ) , & route, & session_priv) . unwrap ( ) ;
5013
5033
let ( mut onion_payloads, _htlc_msat, _htlc_cltv) = onion_utils:: build_onion_payloads ( & route, cur_height) . unwrap ( ) ;
5014
- onion_payloads[ 1 ] . format = msgs:: OnionHopDataFormat :: BogusRealm ( 3 ) ;
5015
- msg. onion_routing_packet = onion_utils:: construct_onion_packet ( onion_payloads, onion_keys, [ 0 ; 32 ] , & payment_hash) ;
5034
+ let mut new_payloads = Vec :: new ( ) ;
5035
+ for payload in onion_payloads. drain ( ..) {
5036
+ new_payloads. push ( BogusOnionHopData :: new ( payload) ) ;
5037
+ }
5038
+ // break the last-hop payload by swapping the realm (0) byte for a byte describing a
5039
+ // length-1 TLV payload, which is obviously bogus.
5040
+ new_payloads[ 1 ] . data [ 0 ] = 1 ;
5041
+ msg. onion_routing_packet = onion_utils:: construct_onion_packet_bogus_hopdata ( new_payloads, onion_keys, [ 0 ; 32 ] , & payment_hash) ;
5016
5042
} , ||{ } , false , Some ( PERM |1 ) , Some ( msgs:: HTLCFailChannelUpdate :: ChannelClosed { short_channel_id : channels[ 1 ] . 0 . contents . short_channel_id , is_permanent : true } ) ) ;
5017
5043
5018
5044
// the following three with run_onion_failure_test_with_fail_intercept() test only the origin node
0 commit comments