From 4ddb443cc5ec4522b540b8e034c083c8d159de25 Mon Sep 17 00:00:00 2001 From: mike31 Date: Thu, 18 Apr 2019 16:34:22 +0300 Subject: [PATCH] Signatures in chunk exchange --- src/community/community.cpp | 8 ++++---- src/community/community.h | 8 ++++---- src/protocol/relay.cpp | 9 +++++++-- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/community/community.cpp b/src/community/community.cpp index df1fd459..e390ce55 100644 --- a/src/community/community.cpp +++ b/src/community/community.cpp @@ -93,14 +93,14 @@ bool mc_EnterpriseFeatures::OFF_GetScriptsToVerify(map& mapReadPerm return true; } -bool mc_EnterpriseFeatures::OFF_VerifySignatureScripts(uint32_t msg_type_in,mc_OffchainMessageID& msg_id_received,mc_OffchainMessageID& msg_id_to_respond,uint32_t flags_in, - vector& vPayloadIn,vector& vSigScriptsToVerify,string& strError) +bool mc_EnterpriseFeatures::OFF_VerifySignatureScripts(uint32_t msg_type,mc_OffchainMessageID& msg_id,mc_OffchainMessageID& msg_id_to_respond,uint32_t flags, + vector& vPayload,vector& vSigScriptsToVerify,string& strError,int& dos_score) { return true; } -bool mc_EnterpriseFeatures::OFF_CreateSignatureScripts(uint32_t msg_type_in,mc_OffchainMessageID& msg_id_received,mc_OffchainMessageID& msg_id_to_respond,uint32_t flags_in, - vector& vPayloadIn,set& vAddresses,vector& vSigScripts,string& strError) +bool mc_EnterpriseFeatures::OFF_CreateSignatureScripts(uint32_t msg_type,mc_OffchainMessageID& msg_id,mc_OffchainMessageID& msg_id_to_respond,uint32_t flags, + vector& vPayload,set& vAddresses,vector& vSigScripts,string& strError) { return true; } diff --git a/src/community/community.h b/src/community/community.h index 9081e973..ae0c434a 100644 --- a/src/community/community.h +++ b/src/community/community.h @@ -54,10 +54,10 @@ typedef struct mc_EnterpriseFeatures map& mapReadPermissionedStreams,string& strError); bool OFF_ProcessChunkResponse(mc_RelayRequest *request,mc_RelayResponse *response,map * request_pairs,mc_ChunkCollector* collector); bool OFF_GetScriptsToVerify(map& mapReadPermissionedStreams,vector& vSigScriptsIn,vector& vSigScriptsToVerify,string& strError); - bool OFF_VerifySignatureScripts(uint32_t msg_type_in,mc_OffchainMessageID& msg_id_received,mc_OffchainMessageID& msg_id_to_respond,uint32_t flags_in, - vector& vPayloadIn,vector& vSigScriptsToVerify,string& strError); - bool OFF_CreateSignatureScripts(uint32_t msg_type_in,mc_OffchainMessageID& msg_id_received,mc_OffchainMessageID& msg_id_to_respond,uint32_t flags_in, - vector& vPayloadIn,set& vAddresses,vector& vSigScripts,string& strError); + bool OFF_VerifySignatureScripts(uint32_t msg_type,mc_OffchainMessageID& msg_id,mc_OffchainMessageID& msg_id_to_respond,uint32_t flags, + vector& vPayload,vector& vSigScriptsToVerify,string& strError,int& dos_score); + bool OFF_CreateSignatureScripts(uint32_t msg_type,mc_OffchainMessageID& msg_id,mc_OffchainMessageID& msg_id_to_respond,uint32_t flags, + vector& vPayload,set& vAddresses,vector& vSigScripts,string& strError); bool OFF_GetPayloadForReadPermissioned(vector* payload,string& strError); uint32_t OFF_SupportedEncryptionOptions(uint32_t min_options); diff --git a/src/protocol/relay.cpp b/src/protocol/relay.cpp index 174a908a..34dd4c2e 100644 --- a/src/protocol/relay.cpp +++ b/src/protocol/relay.cpp @@ -2399,11 +2399,16 @@ bool mc_RelayManager::ProcessRelay( CNode* pfrom, msg_type_response_ptr,&flags_response,vPayloadResponse,vSigScriptsRespond, msg_type_relay_ptr,&flags_relay,vPayloadRelay,vSigScriptsRelay,strError)) { - if(!pEF->OFF_VerifySignatureScripts(msg_type_in,msg_id_received,msg_id_to_respond,flags_in,vPayloadIn,vSigScriptsToVerify,strError)) + int dos_score=0; + if(!pEF->OFF_VerifySignatureScripts(msg_type_in,msg_id_received,msg_id_to_respond,flags_in,vPayloadIn,vSigScriptsToVerify,strError,dos_score)) { LogPrintf("ProcessOffchain() : Error processing %s (request %s) from peer %d: %s\n",mc_MsgTypeStr(msg_type_in).c_str(), msg_id_received.ToString().c_str(),pfrom->GetId(),strError.c_str()); - return false; + if(dos_score) + { + return state.DoS(dos_score, error("ProcessOffchain() : Invalid sigScript"),REJECT_INVALID, "bad-sigscript"); + } + return false; } if(msg_type_response_ptr && *msg_type_response_ptr) {