From ba4593313802eb087365ce970e8f34cc5e4148dd Mon Sep 17 00:00:00 2001 From: chrisparker126 Date: Sat, 19 Jun 2010 15:24:35 +0000 Subject: [PATCH] made sure encrypted messages are stored in cache and signature creation and verification done correctly in this case git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3163 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/services/p3distrib.cc | 29 +++++++++++++++++-------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/libretroshare/src/services/p3distrib.cc b/libretroshare/src/services/p3distrib.cc index 2464fff55..3d9505e18 100644 --- a/libretroshare/src/services/p3distrib.cc +++ b/libretroshare/src/services/p3distrib.cc @@ -631,18 +631,23 @@ void p3GroupDistrib::loadMsg(RsDistribSignedMsg *newMsg, std::string src, bool l return; } + void *temp_ptr = newMsg->packet.bin_data; + int temp_len = newMsg->packet.bin_len; + if(git->second.grpFlags & RS_DISTRIB_ENCRYPTED){ - void *out_data = NULL; - int outlen = 0; + void *out_data = NULL; + int out_len = 0; + + if(decrypt(out_data, out_len, newMsg->packet.bin_data, newMsg->packet.bin_len, newMsg->grpId)){ + newMsg->packet.TlvShallowClear(); + newMsg->packet.setBinData(out_data, out_len); + delete[] (unsigned char*) out_data; - if(decrypt(out_data, outlen, newMsg->packet.bin_data, newMsg->packet.bin_len, newMsg->grpId)){ - newMsg->packet.TlvClear(); - newMsg->packet.setBinData(out_data, outlen); }else{ - if((out_data != NULL) && (outlen != 0)) - delete[] out_data; + if((out_data != NULL) && (out_len != 0)) + delete[] (unsigned char*) out_data; return; } @@ -694,6 +699,12 @@ void p3GroupDistrib::loadMsg(RsDistribSignedMsg *newMsg, std::string src, bool l std::cerr << "p3GroupDistrib::loadMsg() To be Published!"; std::cerr << std::endl; #endif + + if(git->second.grpFlags & RS_DISTRIB_ENCRYPTED){ + newMsg->packet.TlvClear(); + newMsg->packet.setBinData(temp_ptr, temp_len); + } + locked_toPublishMsg(newMsg); } else @@ -2128,7 +2139,7 @@ std::string p3GroupDistrib::publishMsg(RsDistribMsg *msg, bool personalSign) EVP_MD_CTX *mdctx = EVP_MD_CTX_create(); EVP_SignInit(mdctx, EVP_sha1()); - EVP_SignUpdate(mdctx, out_data, size); + EVP_SignUpdate(mdctx, out_data, out_size); unsigned int siglen = EVP_PKEY_size(publishKey); unsigned char sigbuf[siglen]; @@ -2142,7 +2153,7 @@ std::string p3GroupDistrib::publishMsg(RsDistribMsg *msg, bool personalSign) { unsigned int siglen = EVP_PKEY_size(publishKey); unsigned char sigbuf[siglen]; - if (AuthSSL::getAuthSSL()->SignDataBin(out_data, size, sigbuf, &siglen)) + if (AuthSSL::getAuthSSL()->SignDataBin(out_data, out_size, sigbuf, &siglen)) { signedMsg->personalSignature.signData.setBinData(sigbuf, siglen); signedMsg->personalSignature.keyId = AuthSSL::getAuthSSL()->OwnId();