mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
fixed abug i introduced, copy of grp icon data made in p3distrib
- it was previously corrupting group keys added dynamics size to grps created - previously limited to 16000 bytes git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@2928 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
7cd6103ff7
commit
105e617596
@ -124,13 +124,12 @@ bool p3Blogs::getBlogInfo(std::string cId, BlogInfo &ci)
|
|||||||
ci.pop = gi->sources.size();
|
ci.pop = gi->sources.size();
|
||||||
ci.lastPost = gi->lastPost;
|
ci.lastPost = gi->lastPost;
|
||||||
|
|
||||||
if(gi->grpIcon.image_type == RSTLV_IMAGE_TYPE_PNG){
|
ci.pngChanImage = gi->grpIcon.pngImageData;
|
||||||
ci.pngChanImage = (unsigned char*) gi->grpIcon.binData.bin_data;
|
|
||||||
ci.pngImageLen = gi->grpIcon.binData.bin_len;
|
if(ci.pngChanImage != NULL)
|
||||||
}else{
|
ci.pngImageLen = gi->grpIcon.imageSize;
|
||||||
ci.pngChanImage = NULL;
|
else
|
||||||
ci.pngImageLen = 0;
|
ci.pngImageLen = 0;
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -119,15 +119,12 @@ bool p3Channels::getChannelInfo(std::string cId, ChannelInfo &ci)
|
|||||||
ci.pop = gi->sources.size();
|
ci.pop = gi->sources.size();
|
||||||
ci.lastPost = gi->lastPost;
|
ci.lastPost = gi->lastPost;
|
||||||
|
|
||||||
if(gi->grpIcon.image_type == RSTLV_IMAGE_TYPE_PNG){
|
ci.pngChanImage = gi->grpIcon.pngImageData;
|
||||||
|
|
||||||
ci.pngChanImage = (unsigned char*) gi->grpIcon.binData.bin_data;
|
if(ci.pngChanImage != NULL)
|
||||||
ci.pngImageLen = gi->grpIcon.binData.bin_len;
|
ci.pngImageLen = gi->grpIcon.imageSize;
|
||||||
}else{
|
else
|
||||||
|
|
||||||
ci.pngChanImage = NULL;
|
|
||||||
ci.pngImageLen = 0;
|
ci.pngImageLen = 0;
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -675,7 +672,7 @@ void p3Channels::cleanUpOldFiles(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
// clean up local caches
|
// clean up local caches
|
||||||
clear_local_caches(now); //how about remote caches, remember its hardwired
|
//. clear_local_caches(now); //how about remote caches, remember its hardwired
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -47,6 +47,7 @@ void setRSAPublicKey(RsTlvSecurityKey &key, RSA *rsa_pub);
|
|||||||
void setRSAPrivateKey(RsTlvSecurityKey &key, RSA *rsa_priv);
|
void setRSAPrivateKey(RsTlvSecurityKey &key, RSA *rsa_priv);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
p3GroupDistrib::p3GroupDistrib(uint16_t subtype,
|
p3GroupDistrib::p3GroupDistrib(uint16_t subtype,
|
||||||
CacheStrapper *cs, CacheTransfer *cft,
|
CacheStrapper *cs, CacheTransfer *cft,
|
||||||
std::string sourcedir, std::string storedir,
|
std::string sourcedir, std::string storedir,
|
||||||
@ -1516,9 +1517,21 @@ std::string p3GroupDistrib::createGroup(std::wstring name, std::wstring desc, ui
|
|||||||
newGrp->grpControlFlags = 0;
|
newGrp->grpControlFlags = 0;
|
||||||
|
|
||||||
// explicit member wise copy for grp image
|
// explicit member wise copy for grp image
|
||||||
newGrp->grpPixmap.binData.bin_data = pngImageData;
|
if((pngImageData != NULL) && (imageSize > 0)){
|
||||||
newGrp->grpPixmap.binData.bin_len = imageSize;
|
newGrp->grpPixmap.binData.bin_data = new unsigned char[imageSize];
|
||||||
newGrp->grpPixmap.image_type = RSTLV_IMAGE_TYPE_PNG;
|
|
||||||
|
memcpy(newGrp->grpPixmap.binData.bin_data, pngImageData,
|
||||||
|
imageSize*sizeof(unsigned char));
|
||||||
|
newGrp->grpPixmap.binData.bin_len = imageSize;
|
||||||
|
newGrp->grpPixmap.image_type = RSTLV_IMAGE_TYPE_PNG;
|
||||||
|
|
||||||
|
}else{
|
||||||
|
newGrp->grpPixmap.binData.bin_data = NULL;
|
||||||
|
newGrp->grpPixmap.binData.bin_len = 0;
|
||||||
|
newGrp->grpPixmap.image_type = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* set keys */
|
/* set keys */
|
||||||
setRSAPublicKey(newGrp->adminKey, rsa_admin_pub);
|
setRSAPublicKey(newGrp->adminKey, rsa_admin_pub);
|
||||||
@ -1589,10 +1602,10 @@ std::string p3GroupDistrib::createGroup(std::wstring name, std::wstring desc, ui
|
|||||||
|
|
||||||
newGrp->adminSignature.TlvClear();
|
newGrp->adminSignature.TlvClear();
|
||||||
|
|
||||||
RsSerialType *serialType = new RsDistribSerialiser();
|
RsSerialType *serialType = new RsDistribSerialiser();
|
||||||
|
|
||||||
char data[16000];
|
uint32_t size = serialType->size(newGrp);
|
||||||
uint32_t size = 16000;
|
char* data = new char[size];
|
||||||
|
|
||||||
serialType->serialise(newGrp, data, &size);
|
serialType->serialise(newGrp, data, &size);
|
||||||
|
|
||||||
@ -1642,8 +1655,7 @@ std::string p3GroupDistrib::createGroup(std::wstring name, std::wstring desc, ui
|
|||||||
|
|
||||||
delete adKey;
|
delete adKey;
|
||||||
delete pubKey;
|
delete pubKey;
|
||||||
|
delete[] data;
|
||||||
|
|
||||||
return grpId;
|
return grpId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1664,90 +1676,91 @@ std::string p3GroupDistrib::publishMsg(RsDistribMsg *msg, bool personalSign)
|
|||||||
RsDistribSignedMsg *signedMsg = NULL;
|
RsDistribSignedMsg *signedMsg = NULL;
|
||||||
|
|
||||||
/* ensure Group exists */
|
/* ensure Group exists */
|
||||||
{ /* STACK MUTEX */
|
{ /* STACK MUTEX */
|
||||||
RsStackMutex stack(distribMtx); /************* STACK MUTEX ************/
|
|
||||||
GroupInfo *gi = locked_getGroupInfo(grpId);
|
|
||||||
if (!gi)
|
|
||||||
{
|
|
||||||
#ifdef DISTRIB_DEBUG
|
|
||||||
std::cerr << "p3GroupDistrib::publishMsg() No Group";
|
|
||||||
std::cerr << std::endl;
|
|
||||||
#endif
|
|
||||||
return msgId;
|
|
||||||
}
|
|
||||||
|
|
||||||
/******************* FIND KEY ******************************/
|
RsStackMutex stack(distribMtx); /************* STACK MUTEX ************/
|
||||||
if (!locked_choosePublishKey(*gi))
|
GroupInfo *gi = locked_getGroupInfo(grpId);
|
||||||
{
|
if (!gi)
|
||||||
#ifdef DISTRIB_DEBUG
|
|
||||||
std::cerr << "p3GroupDistrib::publishMsg() No Publish Key(1)";
|
|
||||||
std::cerr << std::endl;
|
|
||||||
#endif
|
|
||||||
return msgId;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* find valid publish_key */
|
|
||||||
EVP_PKEY *publishKey = NULL;
|
|
||||||
std::map<std::string, GroupKey>::iterator kit;
|
|
||||||
kit = gi->publishKeys.find(gi->publishKeyId);
|
|
||||||
if (kit != gi->publishKeys.end())
|
|
||||||
{
|
|
||||||
publishKey = kit->second.key;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!publishKey)
|
|
||||||
{
|
|
||||||
#ifdef DISTRIB_DEBUG
|
|
||||||
std::cerr << "p3GroupDistrib::publishMsg() No Publish Key";
|
|
||||||
std::cerr << std::endl;
|
|
||||||
#endif
|
|
||||||
/* no publish Key */
|
|
||||||
return msgId;
|
|
||||||
}
|
|
||||||
/******************* FIND KEY ******************************/
|
|
||||||
|
|
||||||
signedMsg = new RsDistribSignedMsg();
|
|
||||||
|
|
||||||
RsSerialType *serialType = createSerialiser();
|
|
||||||
uint32_t size = serialType->size(msg);
|
|
||||||
void *data = malloc(size);
|
|
||||||
|
|
||||||
serialType->serialise(msg, data, &size);
|
|
||||||
signedMsg->packet.setBinData(data, size);
|
|
||||||
|
|
||||||
/* sign Packet */
|
|
||||||
|
|
||||||
/* calc and check signature */
|
|
||||||
EVP_MD_CTX *mdctx = EVP_MD_CTX_create();
|
|
||||||
|
|
||||||
EVP_SignInit(mdctx, EVP_sha1());
|
|
||||||
EVP_SignUpdate(mdctx, data, size);
|
|
||||||
|
|
||||||
unsigned int siglen = EVP_PKEY_size(publishKey);
|
|
||||||
unsigned char sigbuf[siglen];
|
|
||||||
int ans = EVP_SignFinal(mdctx, sigbuf, &siglen, publishKey);
|
|
||||||
|
|
||||||
/* save signature */
|
|
||||||
signedMsg->publishSignature.signData.setBinData(sigbuf, siglen);
|
|
||||||
signedMsg->publishSignature.keyId = gi->publishKeyId;
|
|
||||||
|
|
||||||
if (personalSign)
|
|
||||||
{
|
|
||||||
unsigned int siglen = EVP_PKEY_size(publishKey);
|
|
||||||
unsigned char sigbuf[siglen];
|
|
||||||
if (AuthSSL::getAuthSSL()->SignDataBin(data, size, sigbuf, &siglen))
|
|
||||||
{
|
{
|
||||||
signedMsg->personalSignature.signData.setBinData(sigbuf, siglen);
|
#ifdef DISTRIB_DEBUG
|
||||||
signedMsg->personalSignature.keyId = AuthSSL::getAuthSSL()->OwnId();
|
std::cerr << "p3GroupDistrib::publishMsg() No Group";
|
||||||
signedMsg->personalSignature.sslCert = AuthSSL::getAuthSSL()->SaveOwnCertificateToString();
|
std::cerr << std::endl;
|
||||||
|
#endif
|
||||||
|
return msgId;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* clean up */
|
/******************* FIND KEY ******************************/
|
||||||
delete serialType;
|
if (!locked_choosePublishKey(*gi))
|
||||||
EVP_MD_CTX_destroy(mdctx);
|
{
|
||||||
|
#ifdef DISTRIB_DEBUG
|
||||||
|
std::cerr << "p3GroupDistrib::publishMsg() No Publish Key(1)";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
#endif
|
||||||
|
return msgId;
|
||||||
|
}
|
||||||
|
|
||||||
} /* END STACK MUTEX */
|
/* find valid publish_key */
|
||||||
|
EVP_PKEY *publishKey = NULL;
|
||||||
|
std::map<std::string, GroupKey>::iterator kit;
|
||||||
|
kit = gi->publishKeys.find(gi->publishKeyId);
|
||||||
|
if (kit != gi->publishKeys.end())
|
||||||
|
{
|
||||||
|
publishKey = kit->second.key;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!publishKey)
|
||||||
|
{
|
||||||
|
#ifdef DISTRIB_DEBUG
|
||||||
|
std::cerr << "p3GroupDistrib::publishMsg() No Publish Key";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
#endif
|
||||||
|
/* no publish Key */
|
||||||
|
return msgId;
|
||||||
|
}
|
||||||
|
/******************* FIND KEY ******************************/
|
||||||
|
|
||||||
|
signedMsg = new RsDistribSignedMsg();
|
||||||
|
|
||||||
|
RsSerialType *serialType = createSerialiser();
|
||||||
|
uint32_t size = serialType->size(msg);
|
||||||
|
void *data = malloc(size);
|
||||||
|
serialType->serialise(msg, data, &size);
|
||||||
|
signedMsg->packet.setBinData(data, size);
|
||||||
|
|
||||||
|
/* sign Packet */
|
||||||
|
|
||||||
|
/* calc and check signature */
|
||||||
|
EVP_MD_CTX *mdctx = EVP_MD_CTX_create();
|
||||||
|
|
||||||
|
EVP_SignInit(mdctx, EVP_sha1());
|
||||||
|
EVP_SignUpdate(mdctx, data, size);
|
||||||
|
|
||||||
|
unsigned int siglen = EVP_PKEY_size(publishKey);
|
||||||
|
unsigned char sigbuf[siglen];
|
||||||
|
int ans = EVP_SignFinal(mdctx, sigbuf, &siglen, publishKey);
|
||||||
|
|
||||||
|
/* save signature */
|
||||||
|
signedMsg->publishSignature.signData.setBinData(sigbuf, siglen);
|
||||||
|
signedMsg->publishSignature.keyId = gi->publishKeyId;
|
||||||
|
|
||||||
|
if (personalSign)
|
||||||
|
{
|
||||||
|
unsigned int siglen = EVP_PKEY_size(publishKey);
|
||||||
|
unsigned char sigbuf[siglen];
|
||||||
|
if (AuthSSL::getAuthSSL()->SignDataBin(data, size, sigbuf, &siglen))
|
||||||
|
{
|
||||||
|
signedMsg->personalSignature.signData.setBinData(sigbuf, siglen);
|
||||||
|
signedMsg->personalSignature.keyId = AuthSSL::getAuthSSL()->OwnId();
|
||||||
|
signedMsg->personalSignature.sslCert = AuthSSL::getAuthSSL()->SaveOwnCertificateToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* clean up */
|
||||||
|
delete serialType;
|
||||||
|
EVP_MD_CTX_destroy(mdctx);
|
||||||
|
delete[] data;
|
||||||
|
|
||||||
|
} /* END STACK MUTEX */
|
||||||
|
|
||||||
/* extract Ids from publishSignature */
|
/* extract Ids from publishSignature */
|
||||||
signedMsg->msgId = getBinDataSign(
|
signedMsg->msgId = getBinDataSign(
|
||||||
@ -1772,6 +1785,7 @@ std::string p3GroupDistrib::publishMsg(RsDistribMsg *msg, bool personalSign)
|
|||||||
* If we pretend it is coming from an alternative source
|
* If we pretend it is coming from an alternative source
|
||||||
* it'll automatically get published with other msgs
|
* it'll automatically get published with other msgs
|
||||||
*/
|
*/
|
||||||
|
|
||||||
signedMsg->PeerId(mOwnId);
|
signedMsg->PeerId(mOwnId);
|
||||||
loadMsg(signedMsg, mOwnId, false);
|
loadMsg(signedMsg, mOwnId, false);
|
||||||
|
|
||||||
@ -1794,8 +1808,7 @@ bool p3GroupDistrib::validateDistribGrp(RsDistribGrp *newGrp)
|
|||||||
/* check signature */
|
/* check signature */
|
||||||
RsSerialType *serialType = new RsDistribSerialiser();
|
RsSerialType *serialType = new RsDistribSerialiser();
|
||||||
|
|
||||||
char data[16000];
|
|
||||||
uint32_t size = 16000;
|
|
||||||
|
|
||||||
/* copy out signature (shallow copy) */
|
/* copy out signature (shallow copy) */
|
||||||
RsTlvKeySignature tmpSign = newGrp->adminSignature;
|
RsTlvKeySignature tmpSign = newGrp->adminSignature;
|
||||||
@ -1805,6 +1818,9 @@ bool p3GroupDistrib::validateDistribGrp(RsDistribGrp *newGrp)
|
|||||||
/* clear signature */
|
/* clear signature */
|
||||||
newGrp->adminSignature.ShallowClear();
|
newGrp->adminSignature.ShallowClear();
|
||||||
|
|
||||||
|
uint32_t size = serialType->size(newGrp);
|
||||||
|
char* data = new char[size];
|
||||||
|
|
||||||
serialType->serialise(newGrp, data, &size);
|
serialType->serialise(newGrp, data, &size);
|
||||||
|
|
||||||
|
|
||||||
@ -1833,7 +1849,7 @@ bool p3GroupDistrib::validateDistribGrp(RsDistribGrp *newGrp)
|
|||||||
EVP_PKEY_free(key);
|
EVP_PKEY_free(key);
|
||||||
delete serialType;
|
delete serialType;
|
||||||
EVP_MD_CTX_destroy(mdctx);
|
EVP_MD_CTX_destroy(mdctx);
|
||||||
|
delete[] data;
|
||||||
|
|
||||||
if (ans == 1)
|
if (ans == 1)
|
||||||
return true;
|
return true;
|
||||||
@ -1879,6 +1895,7 @@ bool p3GroupDistrib::locked_checkGroupInfo(GroupInfo &info, RsDistribGrp *newGr
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* otherwise validate it */
|
/* otherwise validate it */
|
||||||
return validateDistribGrp(newGrp);
|
return validateDistribGrp(newGrp);
|
||||||
}
|
}
|
||||||
@ -1903,6 +1920,11 @@ bool p3GroupDistrib::locked_updateGroupInfo(GroupInfo &info, RsDistribGrp *newG
|
|||||||
delete info.distribGroup;
|
delete info.distribGroup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (info.grpIcon.pngImageData != NULL){
|
||||||
|
delete[] info.grpIcon.pngImageData;
|
||||||
|
info.grpIcon.imageSize = 0;
|
||||||
|
}
|
||||||
|
|
||||||
info.distribGroup = newGrp;
|
info.distribGroup = newGrp;
|
||||||
|
|
||||||
/* copy details */
|
/* copy details */
|
||||||
@ -1910,9 +1932,18 @@ bool p3GroupDistrib::locked_updateGroupInfo(GroupInfo &info, RsDistribGrp *newG
|
|||||||
info.grpDesc = newGrp->grpDesc;
|
info.grpDesc = newGrp->grpDesc;
|
||||||
info.grpCategory = newGrp->grpCategory;
|
info.grpCategory = newGrp->grpCategory;
|
||||||
info.grpFlags = newGrp->grpFlags;
|
info.grpFlags = newGrp->grpFlags;
|
||||||
info.grpIcon.binData.bin_data = newGrp->grpPixmap.binData.bin_data;
|
|
||||||
info.grpIcon.binData.bin_len = newGrp->grpPixmap.binData.bin_len;
|
if((newGrp->grpPixmap.binData.bin_data != NULL) && (newGrp->grpPixmap.binData.bin_len > 0)){
|
||||||
info.grpIcon.image_type = newGrp->grpPixmap.image_type;
|
info.grpIcon.pngImageData = new unsigned char[newGrp->grpPixmap.binData.bin_len];
|
||||||
|
|
||||||
|
memcpy(info.grpIcon.pngImageData, newGrp->grpPixmap.binData.bin_data,
|
||||||
|
newGrp->grpPixmap.binData.bin_len*sizeof(unsigned char));
|
||||||
|
|
||||||
|
info.grpIcon.imageSize = newGrp->grpPixmap.binData.bin_len;
|
||||||
|
}else{
|
||||||
|
info.grpIcon.pngImageData = NULL;
|
||||||
|
info.grpIcon.imageSize = 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* pop already calculated */
|
/* pop already calculated */
|
||||||
/* last post handled seperately */
|
/* last post handled seperately */
|
||||||
|
@ -107,6 +107,24 @@ class GroupKey
|
|||||||
EVP_PKEY *key; /// public key
|
EVP_PKEY *key; /// public key
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class GroupIcon{
|
||||||
|
public:
|
||||||
|
GroupIcon(): pngImageData(NULL), imageSize(0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
~GroupIcon(){
|
||||||
|
|
||||||
|
if((pngImageData != NULL) && (imageSize > 0))
|
||||||
|
delete[] pngImageData;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char* pngImageData;
|
||||||
|
int imageSize;
|
||||||
|
};
|
||||||
|
|
||||||
//! aggregates various information on group activities (i.e. messages, posts, etc)
|
//! aggregates various information on group activities (i.e. messages, posts, etc)
|
||||||
/*!
|
/*!
|
||||||
* The aim is to use this to keep track of group changes, so client can respond (get messages, post etc)
|
* The aim is to use this to keep track of group changes, so client can respond (get messages, post etc)
|
||||||
@ -150,7 +168,7 @@ class GroupInfo
|
|||||||
|
|
||||||
/* NOT USED YET */
|
/* NOT USED YET */
|
||||||
|
|
||||||
RsTlvImage grpIcon;
|
GroupIcon grpIcon;
|
||||||
|
|
||||||
bool publisher, allowAnon, allowUnknown;
|
bool publisher, allowAnon, allowUnknown;
|
||||||
bool subscribed, listener;
|
bool subscribed, listener;
|
||||||
@ -162,6 +180,7 @@ class GroupInfo
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
std::ostream &operator<<(std::ostream &out, const GroupInfo &info);
|
std::ostream &operator<<(std::ostream &out, const GroupInfo &info);
|
||||||
|
|
||||||
//! information on what cache stores group info
|
//! information on what cache stores group info
|
||||||
|
Loading…
Reference in New Issue
Block a user