@@ -294,10 +294,21 @@ where C::Target: chain::Access, L::Target: Logger
294294}
295295
296296macro_rules! secp_verify_sig {
297- ( $secp_ctx: expr, $msg: expr, $sig: expr, $pubkey: expr ) => {
297+ ( $secp_ctx: expr, $msg: expr, $sig: expr, $pubkey: expr, $msg_type : expr ) => {
298298 match $secp_ctx. verify( $msg, $sig, $pubkey) {
299299 Ok ( _) => { } ,
300- Err ( _) => return Err ( LightningError { err: "Invalid signature from remote node" . to_owned( ) , action: ErrorAction :: IgnoreError } ) ,
300+ Err ( _) => {
301+ return Err ( LightningError {
302+ err: format!( "Invalid signature on {} message" , $msg_type) ,
303+ action: ErrorAction :: SendWarningMessage {
304+ msg: msgs:: WarningMessage {
305+ channel_id: [ 0 ; 32 ] ,
306+ data: format!( "Invalid signature on {} message" , $msg_type) ,
307+ } ,
308+ log_level: Level :: Trace ,
309+ } ,
310+ } ) ;
311+ } ,
301312 }
302313 } ;
303314}
@@ -850,7 +861,7 @@ impl NetworkGraph {
850861 /// routing messages from a source using a protocol other than the lightning P2P protocol.
851862 pub fn update_node_from_announcement < T : secp256k1:: Verification > ( & self , msg : & msgs:: NodeAnnouncement , secp_ctx : & Secp256k1 < T > ) -> Result < ( ) , LightningError > {
852863 let msg_hash = hash_to_message ! ( & Sha256dHash :: hash( & msg. contents. encode( ) [ ..] ) [ ..] ) ;
853- secp_verify_sig ! ( secp_ctx, & msg_hash, & msg. signature, & msg. contents. node_id) ;
864+ secp_verify_sig ! ( secp_ctx, & msg_hash, & msg. signature, & msg. contents. node_id, "node_announcement" ) ;
854865 self . update_node_from_announcement_intern ( & msg. contents , Some ( & msg) )
855866 }
856867
@@ -910,10 +921,10 @@ impl NetworkGraph {
910921 C :: Target : chain:: Access ,
911922 {
912923 let msg_hash = hash_to_message ! ( & Sha256dHash :: hash( & msg. contents. encode( ) [ ..] ) [ ..] ) ;
913- secp_verify_sig ! ( secp_ctx, & msg_hash, & msg. node_signature_1, & msg. contents. node_id_1) ;
914- secp_verify_sig ! ( secp_ctx, & msg_hash, & msg. node_signature_2, & msg. contents. node_id_2) ;
915- secp_verify_sig ! ( secp_ctx, & msg_hash, & msg. bitcoin_signature_1, & msg. contents. bitcoin_key_1) ;
916- secp_verify_sig ! ( secp_ctx, & msg_hash, & msg. bitcoin_signature_2, & msg. contents. bitcoin_key_2) ;
924+ secp_verify_sig ! ( secp_ctx, & msg_hash, & msg. node_signature_1, & msg. contents. node_id_1, "channel_announcement" ) ;
925+ secp_verify_sig ! ( secp_ctx, & msg_hash, & msg. node_signature_2, & msg. contents. node_id_2, "channel_announcement" ) ;
926+ secp_verify_sig ! ( secp_ctx, & msg_hash, & msg. bitcoin_signature_1, & msg. contents. bitcoin_key_1, "channel_announcement" ) ;
927+ secp_verify_sig ! ( secp_ctx, & msg_hash, & msg. bitcoin_signature_2, & msg. contents. bitcoin_key_2, "channel_announcement" ) ;
917928 self . update_channel_from_unsigned_announcement_intern ( & msg. contents , Some ( msg) , chain_access)
918929 }
919930
@@ -1239,7 +1250,7 @@ impl NetworkGraph {
12391250 secp_verify_sig ! ( ctx, & msg_hash, & sig, & PublicKey :: from_slice( channel. node_two. as_slice( ) ) . map_err( |_| LightningError {
12401251 err: "Couldn't parse source node pubkey" . to_owned( ) ,
12411252 action: ErrorAction :: IgnoreAndLog ( Level :: Debug )
1242- } ) ?) ;
1253+ } ) ?, "channel_update" ) ;
12431254 }
12441255 maybe_update_channel_info ! ( channel. two_to_one, channel. node_two) ;
12451256 } else {
@@ -1248,7 +1259,7 @@ impl NetworkGraph {
12481259 secp_verify_sig ! ( ctx, & msg_hash, & sig, & PublicKey :: from_slice( channel. node_one. as_slice( ) ) . map_err( |_| LightningError {
12491260 err: "Couldn't parse destination node pubkey" . to_owned( ) ,
12501261 action: ErrorAction :: IgnoreAndLog ( Level :: Debug )
1251- } ) ?) ;
1262+ } ) ?, "channel_update" ) ;
12521263 }
12531264 maybe_update_channel_info ! ( channel. one_to_two, channel. node_one) ;
12541265 }
@@ -1522,7 +1533,7 @@ mod tests {
15221533 contents : valid_announcement. contents . clone ( )
15231534 } ) {
15241535 Ok ( _) => panic ! ( ) ,
1525- Err ( e) => assert_eq ! ( e. err, "Invalid signature from remote node " )
1536+ Err ( e) => assert_eq ! ( e. err, "Invalid signature on node_announcement message " )
15261537 } ;
15271538
15281539 let announcement_with_data = get_signed_node_announcement ( |unsigned_announcement| {
@@ -1651,7 +1662,7 @@ mod tests {
16511662 invalid_sig_announcement. contents . excess_data = Vec :: new ( ) ;
16521663 match net_graph_msg_handler. handle_channel_announcement ( & invalid_sig_announcement) {
16531664 Ok ( _) => panic ! ( ) ,
1654- Err ( e) => assert_eq ! ( e. err, "Invalid signature from remote node " )
1665+ Err ( e) => assert_eq ! ( e. err, "Invalid signature on channel_announcement message " )
16551666 } ;
16561667
16571668 let channel_to_itself_announcement = get_signed_channel_announcement ( |_| { } , node_1_privkey, node_1_privkey, & secp_ctx) ;
@@ -1760,7 +1771,7 @@ mod tests {
17601771 invalid_sig_channel_update. signature = secp_ctx. sign ( & fake_msghash, node_1_privkey) ;
17611772 match net_graph_msg_handler. handle_channel_update ( & invalid_sig_channel_update) {
17621773 Ok ( _) => panic ! ( ) ,
1763- Err ( e) => assert_eq ! ( e. err, "Invalid signature from remote node " )
1774+ Err ( e) => assert_eq ! ( e. err, "Invalid signature on channel_update message " )
17641775 } ;
17651776 }
17661777
0 commit comments