@@ -216,10 +216,21 @@ where C::Target: chain::Access, L::Target: Logger
216
216
}
217
217
218
218
macro_rules! secp_verify_sig {
219
- ( $secp_ctx: expr, $msg: expr, $sig: expr, $pubkey: expr ) => {
219
+ ( $secp_ctx: expr, $msg: expr, $sig: expr, $pubkey: expr, $msg_type : expr ) => {
220
220
match $secp_ctx. verify( $msg, $sig, $pubkey) {
221
221
Ok ( _) => { } ,
222
- Err ( _) => return Err ( LightningError { err: "Invalid signature from remote node" . to_owned( ) , action: ErrorAction :: IgnoreError } ) ,
222
+ Err ( _) => {
223
+ return Err ( LightningError {
224
+ err: format!( "Invalid signature on {} message" , $msg_type) ,
225
+ action: ErrorAction :: SendWarningMessage {
226
+ msg: msgs:: WarningMessage {
227
+ channel_id: [ 0 ; 32 ] ,
228
+ data: format!( "Invalid signature on {} message" , $msg_type) ,
229
+ } ,
230
+ log_level: Level :: Trace ,
231
+ } ,
232
+ } ) ;
233
+ } ,
223
234
}
224
235
} ;
225
236
}
@@ -767,7 +778,7 @@ impl NetworkGraph {
767
778
/// routing messages from a source using a protocol other than the lightning P2P protocol.
768
779
pub fn update_node_from_announcement < T : secp256k1:: Verification > ( & self , msg : & msgs:: NodeAnnouncement , secp_ctx : & Secp256k1 < T > ) -> Result < ( ) , LightningError > {
769
780
let msg_hash = hash_to_message ! ( & Sha256dHash :: hash( & msg. contents. encode( ) [ ..] ) [ ..] ) ;
770
- secp_verify_sig ! ( secp_ctx, & msg_hash, & msg. signature, & msg. contents. node_id) ;
781
+ secp_verify_sig ! ( secp_ctx, & msg_hash, & msg. signature, & msg. contents. node_id, "node_announcement" ) ;
771
782
self . update_node_from_announcement_intern ( & msg. contents , Some ( & msg) )
772
783
}
773
784
@@ -785,7 +796,7 @@ impl NetworkGraph {
785
796
Some ( node) => {
786
797
if let Some ( node_info) = node. announcement_info . as_ref ( ) {
787
798
if node_info. last_update >= msg. timestamp {
788
- return Err ( LightningError { err : "Update older than last processed update" . to_owned ( ) , action : ErrorAction :: IgnoreAndLog ( Level :: Trace ) } ) ;
799
+ return Err ( LightningError { err : "Update older than last processed update" . to_owned ( ) , action : ErrorAction :: IgnoreAndLog ( Level :: Trace ) } ) ;
789
800
}
790
801
}
791
802
@@ -822,10 +833,10 @@ impl NetworkGraph {
822
833
C :: Target : chain:: Access ,
823
834
{
824
835
let msg_hash = hash_to_message ! ( & Sha256dHash :: hash( & msg. contents. encode( ) [ ..] ) [ ..] ) ;
825
- secp_verify_sig ! ( secp_ctx, & msg_hash, & msg. node_signature_1, & msg. contents. node_id_1) ;
826
- secp_verify_sig ! ( secp_ctx, & msg_hash, & msg. node_signature_2, & msg. contents. node_id_2) ;
827
- secp_verify_sig ! ( secp_ctx, & msg_hash, & msg. bitcoin_signature_1, & msg. contents. bitcoin_key_1) ;
828
- secp_verify_sig ! ( secp_ctx, & msg_hash, & msg. bitcoin_signature_2, & msg. contents. bitcoin_key_2) ;
836
+ secp_verify_sig ! ( secp_ctx, & msg_hash, & msg. node_signature_1, & msg. contents. node_id_1, "channel_announcement" ) ;
837
+ secp_verify_sig ! ( secp_ctx, & msg_hash, & msg. node_signature_2, & msg. contents. node_id_2, "channel_announcement" ) ;
838
+ secp_verify_sig ! ( secp_ctx, & msg_hash, & msg. bitcoin_signature_1, & msg. contents. bitcoin_key_1, "channel_announcement" ) ;
839
+ secp_verify_sig ! ( secp_ctx, & msg_hash, & msg. bitcoin_signature_2, & msg. contents. bitcoin_key_2, "channel_announcement" ) ;
829
840
self . update_channel_from_unsigned_announcement_intern ( & msg. contents , Some ( msg) , chain_access)
830
841
}
831
842
@@ -1050,13 +1061,13 @@ impl NetworkGraph {
1050
1061
if msg. flags & 1 == 1 {
1051
1062
dest_node_id = channel. node_one . clone ( ) ;
1052
1063
if let Some ( ( sig, ctx) ) = sig_info {
1053
- secp_verify_sig ! ( ctx, & msg_hash, & sig, & channel. node_two) ;
1064
+ secp_verify_sig ! ( ctx, & msg_hash, & sig, & channel. node_two, "channel_update" ) ;
1054
1065
}
1055
1066
maybe_update_channel_info ! ( channel. two_to_one, channel. node_two) ;
1056
1067
} else {
1057
1068
dest_node_id = channel. node_two . clone ( ) ;
1058
1069
if let Some ( ( sig, ctx) ) = sig_info {
1059
- secp_verify_sig ! ( ctx, & msg_hash, & sig, & channel. node_one) ;
1070
+ secp_verify_sig ! ( ctx, & msg_hash, & sig, & channel. node_one, "channel_update" ) ;
1060
1071
}
1061
1072
maybe_update_channel_info ! ( channel. one_to_two, channel. node_one) ;
1062
1073
}
@@ -1282,7 +1293,7 @@ mod tests {
1282
1293
contents : unsigned_announcement. clone ( )
1283
1294
} ) {
1284
1295
Ok ( _) => panic ! ( ) ,
1285
- Err ( e) => assert_eq ! ( e. err, "Invalid signature from remote node " )
1296
+ Err ( e) => assert_eq ! ( e. err, "Invalid signature on node_announcement message " )
1286
1297
} ;
1287
1298
1288
1299
unsigned_announcement. timestamp += 1000 ;
@@ -1480,7 +1491,7 @@ mod tests {
1480
1491
} ;
1481
1492
match net_graph_msg_handler. handle_channel_announcement ( & invalid_sig_announcement) {
1482
1493
Ok ( _) => panic ! ( ) ,
1483
- Err ( e) => assert_eq ! ( e. err, "Invalid signature from remote node " )
1494
+ Err ( e) => assert_eq ! ( e. err, "Invalid signature on channel_announcement message " )
1484
1495
} ;
1485
1496
1486
1497
unsigned_announcement. node_id_1 = PublicKey :: from_secret_key ( & secp_ctx, node_2_privkey) ;
@@ -1662,7 +1673,7 @@ mod tests {
1662
1673
1663
1674
match net_graph_msg_handler. handle_channel_update ( & invalid_sig_channel_update) {
1664
1675
Ok ( _) => panic ! ( ) ,
1665
- Err ( e) => assert_eq ! ( e. err, "Invalid signature from remote node " )
1676
+ Err ( e) => assert_eq ! ( e. err, "Invalid signature on channel_update message " )
1666
1677
} ;
1667
1678
1668
1679
}
0 commit comments