publish key not generated for public groups anymore, added signature creation for publish and id keys (used in main line of code, correctly initialise ur gxs services)

groupid assigned to group before service_CreateGroup now (to help with identity using pgp hashes)
fixed up dummy group creation for photo service and ui 
completed basic functions of GxsGroupDialog




git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-gxs-b1@5809 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
chrisparker126 2012-11-11 23:45:22 +00:00
parent 6906f47fa7
commit d8dc2a0420
17 changed files with 467 additions and 236 deletions

View file

@ -6,7 +6,7 @@
* *
* General Data service, interface for RetroShare. * General Data service, interface for RetroShare.
* *
* Copyright 2011-2011 by Evi-Parker Christopher * Copyright 2011-2012 by Evi-Parker Christopher
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public * modify it under the terms of the GNU Library General Public

View file

@ -154,7 +154,7 @@ bool RsGenExchange::acknowledgeTokenGrp(const uint32_t& token,
return true; return true;
} }
void RsGenExchange::generateGroupKeys(RsTlvSecurityKeySet& keySet) void RsGenExchange::generateGroupKeys(RsTlvSecurityKeySet& keySet, bool genPublishKeys)
{ {
/* create Keys */ /* create Keys */
@ -162,85 +162,96 @@ void RsGenExchange::generateGroupKeys(RsTlvSecurityKeySet& keySet)
RSA *rsa_admin = RSA_generate_key(2048, 65537, NULL, NULL); RSA *rsa_admin = RSA_generate_key(2048, 65537, NULL, NULL);
RSA *rsa_admin_pub = RSAPublicKey_dup(rsa_admin); RSA *rsa_admin_pub = RSAPublicKey_dup(rsa_admin);
// publish keys /* set admin keys */
RSA *rsa_publish = RSA_generate_key(2048, 65537, NULL, NULL);
RSA *rsa_publish_pub = RSAPublicKey_dup(rsa_admin);
/* set keys */
RsTlvSecurityKey adminKey, privAdminKey; RsTlvSecurityKey adminKey, privAdminKey;
/* set publish keys */
RsTlvSecurityKey pubKey, privPubKey;
GxsSecurity::setRSAPublicKey(adminKey, rsa_admin_pub); GxsSecurity::setRSAPublicKey(adminKey, rsa_admin_pub);
GxsSecurity::setRSAPrivateKey(privAdminKey, rsa_admin); GxsSecurity::setRSAPrivateKey(privAdminKey, rsa_admin);
GxsSecurity::setRSAPublicKey(pubKey, rsa_publish_pub);
GxsSecurity::setRSAPrivateKey(privPubKey, rsa_publish);
adminKey.startTS = time(NULL); adminKey.startTS = time(NULL);
adminKey.endTS = 0; /* no end */ adminKey.endTS = 0; /* no end */
privAdminKey.startTS = adminKey.startTS; privAdminKey.startTS = adminKey.startTS;
privAdminKey.endTS = 0; /* no end */ privAdminKey.endTS = 0; /* no end */
pubKey.startTS = adminKey.startTS;
pubKey.endTS = pubKey.startTS + 60 * 60 * 24 * 365 * 5; /* approx 5 years */
privPubKey.startTS = adminKey.startTS;
privPubKey.endTS = 0; /* no end */
// for now all public // for now all public
adminKey.keyFlags = RSTLV_KEY_DISTRIB_ADMIN | RSTLV_KEY_TYPE_PUBLIC_ONLY; adminKey.keyFlags = RSTLV_KEY_DISTRIB_ADMIN | RSTLV_KEY_TYPE_PUBLIC_ONLY;
privAdminKey.keyFlags = RSTLV_KEY_DISTRIB_ADMIN | RSTLV_KEY_TYPE_FULL; privAdminKey.keyFlags = RSTLV_KEY_DISTRIB_ADMIN | RSTLV_KEY_TYPE_FULL;
// for now all public
pubKey.keyFlags = RSTLV_KEY_DISTRIB_PUBLIC | RSTLV_KEY_TYPE_PUBLIC_ONLY;
privPubKey.keyFlags = RSTLV_KEY_DISTRIB_PRIVATE | RSTLV_KEY_TYPE_FULL;
keySet.keys[adminKey.keyId] = adminKey; keySet.keys[adminKey.keyId] = adminKey;
keySet.keys[pubKey.keyId] = pubKey;
keySet.keys[privAdminKey.keyId] = privAdminKey; keySet.keys[privAdminKey.keyId] = privAdminKey;
keySet.keys[privPubKey.keyId] = privPubKey;
// clean up // clean up
RSA_free(rsa_admin); RSA_free(rsa_admin);
RSA_free(rsa_admin_pub); RSA_free(rsa_admin_pub);
RSA_free(rsa_publish); if(genPublishKeys)
RSA_free(rsa_publish_pub); {
// publish keys
RSA *rsa_publish = RSA_generate_key(2048, 65537, NULL, NULL);
RSA *rsa_publish_pub = RSAPublicKey_dup(rsa_publish);
/* set publish keys */
RsTlvSecurityKey pubKey, privPubKey;
GxsSecurity::setRSAPublicKey(pubKey, rsa_publish_pub);
GxsSecurity::setRSAPrivateKey(privPubKey, rsa_publish);
pubKey.startTS = adminKey.startTS;
pubKey.endTS = pubKey.startTS + 60 * 60 * 24 * 365 * 5; /* approx 5 years */
privPubKey.startTS = adminKey.startTS;
privPubKey.endTS = 0; /* no end */
// for now all public
pubKey.keyFlags = RSTLV_KEY_DISTRIB_PUBLIC | RSTLV_KEY_TYPE_PUBLIC_ONLY;
privPubKey.keyFlags = RSTLV_KEY_DISTRIB_PRIVATE | RSTLV_KEY_TYPE_FULL;
keySet.keys[pubKey.keyId] = pubKey;
keySet.keys[privPubKey.keyId] = privPubKey;
RSA_free(rsa_publish);
RSA_free(rsa_publish_pub);
}
} }
bool RsGenExchange::createGroup(RsNxsGrp *grp, RsTlvSecurityKeySet& keySet) bool RsGenExchange::createGroup(RsNxsGrp *grp, RsTlvSecurityKeySet& keySet)
{ {
std::cerr << "RsGenExchange::createGroup()"; std::cerr << "RsGenExchange::createGroup()";
std::cerr << std::endl; std::cerr << std::endl;
RsGxsGrpMetaData* meta = grp->metaData; RsGxsGrpMetaData* meta = grp->metaData;
/* add keys to grp */ /* add public admin and publish keys to grp */
meta->keys = keySet;
// find private admin key // find private admin key
RsTlvSecurityKey privAdminKey; RsTlvSecurityKey privAdminKey;
std::map<std::string, RsTlvSecurityKey>::iterator mit = keySet.keys.begin(); std::map<std::string, RsTlvSecurityKey>::iterator mit = keySet.keys.begin();
bool privKeyFound = false;
for(; mit != keySet.keys.end(); mit++) for(; mit != keySet.keys.end(); mit++)
{ {
RsTlvSecurityKey& pk = mit->second; RsTlvSecurityKey& key = mit->second;
if(pk.keyFlags & (RSTLV_KEY_DISTRIB_ADMIN | RSTLV_KEY_TYPE_FULL)) // add public admin key
if(key.keyFlags & (RSTLV_KEY_DISTRIB_ADMIN | RSTLV_KEY_TYPE_PUBLIC_ONLY))
meta->keys.keys.insert(std::make_pair(key.keyId, key));
// add public publish key
if(key.keyFlags & (RSTLV_KEY_DISTRIB_PUBLIC | RSTLV_KEY_TYPE_PUBLIC_ONLY))
meta->keys.keys.insert(std::make_pair(key.keyId, key));
if(key.keyFlags & (RSTLV_KEY_DISTRIB_ADMIN | RSTLV_KEY_TYPE_FULL))
{ {
privAdminKey = pk; privAdminKey = key;
break; privKeyFound = true;
} }
} }
if(mit == keySet.keys.end()) if(!privKeyFound)
{ {
std::cerr << "RsGenExchange::createGroup() Missing ADMIN Key"; std::cerr << "RsGenExchange::createGroup() Missing private ADMIN Key";
std::cerr << std::endl; std::cerr << std::endl;
return false; return false;
@ -248,8 +259,7 @@ bool RsGenExchange::createGroup(RsNxsGrp *grp, RsTlvSecurityKeySet& keySet)
// group is self signing // group is self signing
// for the creation of group signature // for the creation of group signature
// only public admin and publish keys are present // only public admin and publish keys are present in meta
// key set
uint32_t metaDataLen = meta->serial_size(); uint32_t metaDataLen = meta->serial_size();
uint32_t allGrpDataLen = metaDataLen + grp->grp.bin_len; uint32_t allGrpDataLen = metaDataLen + grp->grp.bin_len;
char* metaData = new char[metaDataLen]; char* metaData = new char[metaDataLen];
@ -267,7 +277,14 @@ bool RsGenExchange::createGroup(RsNxsGrp *grp, RsTlvSecurityKeySet& keySet)
// add admin sign to grpMeta // add admin sign to grpMeta
meta->signSet.keySignSet[GXS_SERV::FLAG_AUTHEN_ADMIN] = adminSign; meta->signSet.keySignSet[GXS_SERV::FLAG_AUTHEN_ADMIN] = adminSign;
grp->grpId = meta->mGroupId = privAdminKey.keyId; // set meta to be transported as meta without private
// key components
grp->meta.setBinData(metaData, metaDataLen);
// but meta that is stored locally
// has all keys
// nxs net transports only bin data
meta->keys = keySet;
// clean up // clean up
delete[] allGrpData; delete[] allGrpData;
@ -282,6 +299,167 @@ bool RsGenExchange::createGroup(RsNxsGrp *grp, RsTlvSecurityKeySet& keySet)
return ok; return ok;
} }
bool RsGenExchange::createMsgSignatures(RsTlvKeySignatureSet& signSet, RsTlvBinaryData& msgData,
const RsGxsMsgMetaData& msgMeta, RsGxsGrpMetaData& grpMeta)
{
bool isParent = false;
bool needPublishSign, needIdentitySign;
bool ok = true;
uint32_t grpFlag = grpMeta.mGroupFlags;
// publish signature is determined by whether group is public or not
// for private group signature is not needed as it needs decrypting with
// the private publish key anyways
// restricted is a special case which heeds whether publish sign needs to be checked or not
// one may or may not want
if(msgMeta.mParentId.empty())
{
isParent = true;
}
else
{
isParent = false;
}
if(isParent)
{
needIdentitySign = false;
needPublishSign = false;
if(grpFlag & GXS_SERV::FLAG_PRIVACY_PUBLIC)
{
needPublishSign = false;
if(checkMsgAuthenFlag(PUBLIC_GRP_BITS, GXS_SERV::MSG_AUTHEN_ROOT_AUTHOR_SIGN))
needIdentitySign = true;
}
else if(grpFlag & GXS_SERV::FLAG_PRIVACY_RESTRICTED)
{
needPublishSign = true;
if(checkMsgAuthenFlag(RESTRICTED_GRP_BITS, GXS_SERV::MSG_AUTHEN_ROOT_AUTHOR_SIGN))
needIdentitySign = true;
}
else if(grpFlag & GXS_SERV::FLAG_PRIVACY_PRIVATE)
{
needPublishSign = false;
if(checkMsgAuthenFlag(PRIVATE_GRP_BITS, GXS_SERV::MSG_AUTHEN_ROOT_AUTHOR_SIGN))
needIdentitySign = true;
}
}else
{
if(grpFlag & GXS_SERV::FLAG_PRIVACY_PUBLIC)
{
needPublishSign = false;
if(checkMsgAuthenFlag(PUBLIC_GRP_BITS, GXS_SERV::MSG_AUTHEN_CHILD_AUTHOR_SIGN))
needIdentitySign = true;
}
else if(grpFlag & GXS_SERV::FLAG_PRIVACY_RESTRICTED)
{
if(checkMsgAuthenFlag(RESTRICTED_GRP_BITS, GXS_SERV::MSG_AUTHEN_CHILD_PUBLISH_SIGN))
needPublishSign = true;
if(checkMsgAuthenFlag(RESTRICTED_GRP_BITS, GXS_SERV::MSG_AUTHEN_CHILD_AUTHOR_SIGN))
needIdentitySign = true;
}
else if(grpFlag & GXS_SERV::FLAG_PRIVACY_PRIVATE)
{
needPublishSign = false;
if(checkMsgAuthenFlag(PRIVATE_GRP_BITS, GXS_SERV::MSG_AUTHEN_CHILD_AUTHOR_SIGN))
needIdentitySign = true;
}
}
if(needPublishSign)
{
// public and shared is publish key
RsTlvSecurityKeySet& keys = grpMeta.keys;
RsTlvSecurityKey* pubKey;
std::map<std::string, RsTlvSecurityKey>::iterator mit =
keys.keys.begin(), mit_end = keys.keys.end();
bool pub_key_found = false;
for(; mit != mit_end; mit++)
{
pub_key_found = mit->second.keyFlags & (RSTLV_KEY_DISTRIB_PRIVATE | RSTLV_KEY_TYPE_FULL);
if(pub_key_found)
break;
}
// private publish key
pubKey = &(mit->second);
RsTlvKeySignature pubSign = signSet.keySignSet[GXS_SERV::FLAG_AUTHEN_PUBLISH];
ok &= GxsSecurity::getSignature((char*)msgData.bin_data, msgData.bin_len, pubKey, pubSign);
//place signature in msg meta
signSet.keySignSet[GXS_SERV::FLAG_AUTHEN_PUBLISH] = pubSign;
}
if(needIdentitySign)
{
if(mGixs)
{
bool haveKey = mGixs->havePrivateKey(msgMeta.mAuthorId);
if(haveKey)
{
mGixs->requestPrivateKey(msgMeta.mAuthorId);
RsTlvSecurityKey authorKey;
double timeDelta = 0.002; // fast polling
time_t now = time(NULL);
// poll immediately but, don't spend more than a second polling
while( (mGixs->getPrivateKey(msgMeta.mAuthorId, authorKey) == -1) &&
((now + 1) >> time(NULL))
)
{
#ifndef WINDOWS_SYS
usleep((int) (timeDelta * 1000000));
#else
Sleep((int) (timeDelta * 1000));
#endif
}
RsTlvKeySignature sign;
ok &= GxsSecurity::getSignature((char*)msgData.bin_data, msgData.bin_len,
&authorKey, sign);
signSet.keySignSet[GXS_SERV::FLAG_AUTHEN_IDENTITY] = sign;
}else
{
ok = false;
}
}
else
{
#ifdef GEN_EXHANGE_DEBUG
std::cerr << "Gixs not enabled while request identity signature validation!" << std::endl;
#endif
}
}
return ok;
}
bool RsGenExchange::createMessage(RsNxsMsg* msg) bool RsGenExchange::createMessage(RsNxsMsg* msg)
{ {
const RsGxsGroupId& id = msg->grpId; const RsGxsGroupId& id = msg->grpId;
@ -290,78 +468,48 @@ bool RsGenExchange::createMessage(RsNxsMsg* msg)
metaMap.insert(std::make_pair(id, (RsGxsGrpMetaData*)(NULL))); metaMap.insert(std::make_pair(id, (RsGxsGrpMetaData*)(NULL)));
mDataStore->retrieveGxsGrpMetaData(metaMap); mDataStore->retrieveGxsGrpMetaData(metaMap);
bool ok = true; bool ok = true;
RSA* rsa_pub = NULL; RsGxsMsgMetaData &meta = *(msg->metaData);
if(!metaMap[id]) if(!metaMap[id])
{ {
return false; return false;
} }
else else
{ {
// get publish key // get publish key
RsGxsGrpMetaData* grpMeta = metaMap[id]; RsGxsGrpMetaData* grpMeta = metaMap[id];
// public and shared is publish key uint32_t metaDataLen = meta.serial_size();
RsTlvSecurityKeySet& keys = grpMeta->keys; uint32_t allMsgDataLen = metaDataLen + msg->msg.bin_len;
RsTlvSecurityKey* pubKey; char* metaData = new char[metaDataLen];
char* allMsgData = new char[allMsgDataLen]; // msgData + metaData
std::map<std::string, RsTlvSecurityKey>::iterator mit = meta.serialise(metaData, &metaDataLen);
keys.keys.begin(), mit_end = keys.keys.end();
bool pub_key_found = false;
for(; mit != mit_end; mit++)
{
pub_key_found = mit->second.keyFlags & (RSTLV_KEY_DISTRIB_PRIVATE | RSTLV_KEY_TYPE_FULL); // copy msg data and meta in allmsgData buffer
if(pub_key_found) memcpy(allMsgData, msg->msg.bin_data, msg->msg.bin_len);
break; memcpy(allMsgData+(msg->msg.bin_len), metaData, metaDataLen);
}
if(pub_key_found) RsTlvBinaryData msgData(0);
{
RsGxsMsgMetaData &meta = *(msg->metaData);
uint32_t metaDataLen = meta.serial_size(); msgData.setBinData(allMsgData, allMsgDataLen);
uint32_t allMsgDataLen = metaDataLen + msg->msg.bin_len;
char* metaData = new char[metaDataLen];
char* allMsgData = new char[allMsgDataLen]; // msgData + metaData
meta.serialise(metaData, &metaDataLen); // create signatures
ok &= createMsgSignatures(meta.signSet, msgData, meta, *grpMeta);
// copy msg data and meta in allmsgData buffer // get hash of msg data to create msg id
memcpy(allMsgData, msg->msg.bin_data, msg->msg.bin_len); pqihash hash;
memcpy(allMsgData+(msg->msg.bin_len), metaData, metaDataLen); hash.addData(allMsgData, allMsgDataLen);
hash.Complete(msg->msgId);
// private publish key // assign msg id to msg meta
pubKey = &(mit->second); msg->metaData->mMsgId = msg->msgId;
RsTlvKeySignatureSet& signSet = meta.signSet; delete[] metaData;
RsTlvKeySignature pubSign = signSet.keySignSet[GXS_SERV::FLAG_AUTHEN_PUBLISH]; delete[] allMsgData;
GxsSecurity::getSignature(allMsgData, allMsgDataLen, pubKey, pubSign); delete grpMeta;
// get hash of msg data to create msg id
pqihash hash;
hash.addData(allMsgData, allMsgDataLen);
hash.Complete(msg->msgId);
// assign msg id to msg meta
msg->metaData->mMsgId = msg->msgId;
//place signature in msg meta
signSet.keySignSet[GXS_SERV::FLAG_AUTHEN_PUBLISH] = pubSign;
// clean up
delete[] metaData;
delete[] allMsgData;
}
else
{
ok = false;
}
delete grpMeta;
} }
return ok; return ok;
@ -382,11 +530,11 @@ bool RsGenExchange::validateMsg(RsNxsMsg *msg, const uint32_t& grpFlag, RsTlvSec
if(msg->metaData->mParentId.empty()) if(msg->metaData->mParentId.empty())
{ {
isParent = false; isParent = true;
} }
else else
{ {
isParent = true; isParent = false;
} }
@ -464,37 +612,49 @@ bool RsGenExchange::validateMsg(RsNxsMsg *msg, const uint32_t& grpFlag, RsTlvSec
} }
if(checkIdentitySign) if(checkIdentitySign)
{ {
bool haveKey = mGixs->haveKey(metaData.mAuthorId); if(mGixs)
if(haveKey)
{ {
std::list<std::string> peers; bool haveKey = mGixs->haveKey(metaData.mAuthorId);
mGixs->requestKey(metaData.mAuthorId, peers);
RsTlvSecurityKey authorKey; if(haveKey)
double timeDelta = 0.002; // fast polling
time_t now = time(NULL);
// poll immediately but, don't spend more than a second polling
while( (mGixs->getKey(metaData.mAuthorId, authorKey) == -1) &&
((now + 1) >> time(NULL))
)
{ {
#ifndef WINDOWS_SYS std::list<std::string> peers;
usleep((int) (timeDelta * 1000000)); mGixs->requestKey(metaData.mAuthorId, peers);
#else
Sleep((int) (timeDelta * 1000));
#endif
}
RsTlvKeySignature sign = metaData.signSet.keySignSet[GXS_SERV::FLAG_AUTHEN_PUBLISH]; RsTlvSecurityKey authorKey;
valid &= GxsSecurity::validateNxsMsg(*msg, sign, authorKey);
}else double timeDelta = 0.002; // fast polling
time_t now = time(NULL);
// poll immediately but, don't spend more than a second polling
while( (mGixs->getKey(metaData.mAuthorId, authorKey) == -1) &&
((now + 1) >> time(NULL))
)
{
#ifndef WINDOWS_SYS
usleep((int) (timeDelta * 1000000));
#else
Sleep((int) (timeDelta * 1000));
#endif
}
RsTlvKeySignature sign = metaData.signSet.keySignSet[GXS_SERV::FLAG_AUTHEN_PUBLISH];
valid &= GxsSecurity::validateNxsMsg(*msg, sign, authorKey);
}else
{
valid = false;
}
}
else
{ {
#ifdef GEN_EXHANGE_DEBUG
std::cerr << "Gixs not enabled while request identity signature validation!" << std::endl;
#endif
valid = false; valid = false;
} }
} }
return valid; return valid;
@ -956,91 +1116,114 @@ void RsGenExchange::service_CreateGroup(RsGxsGrpItem* grpItem, RsTlvSecurityKeyS
void RsGenExchange::publishGrps() void RsGenExchange::publishGrps()
{ {
RsStackMutex stack(mGenMtx); RsStackMutex stack(mGenMtx);
std::map<uint32_t, RsGxsGrpItem*>::iterator mit = mGrpsToPublish.begin(); std::map<uint32_t, RsGxsGrpItem*>::iterator mit = mGrpsToPublish.begin();
std::vector<uint32_t> toRemove; std::vector<uint32_t> toRemove;
int i = 0; int i = 0;
for(; mit != mGrpsToPublish.end(); mit++) for(; mit != mGrpsToPublish.end(); mit++)
{ {
toRemove.push_back(mit->first); toRemove.push_back(mit->first);
i++; i++;
if(i > GEN_EXCH_GRP_CHUNK) break; if(i > GEN_EXCH_GRP_CHUNK) break;
RsNxsGrp* grp = new RsNxsGrp(mServType); RsNxsGrp* grp = new RsNxsGrp(mServType);
RsGxsGrpItem* grpItem = mit->second; RsGxsGrpItem* grpItem = mit->second;
RsTlvSecurityKeySet keySet; RsTlvSecurityKeySet keySet;
generateGroupKeys(keySet); generateGroupKeys(keySet,
!(grpItem->meta.mGroupFlags & GXS_SERV::FLAG_PRIVACY_PUBLIC));
service_CreateGroup(grpItem, keySet); // find private admin key
RsTlvSecurityKey privAdminKey;
std::map<std::string, RsTlvSecurityKey>::iterator mit_keys = keySet.keys.begin();
uint32_t size = mSerialiser->size(grpItem); bool privKeyFound = false;
char gData[size]; for(; mit_keys != keySet.keys.end(); mit_keys++)
bool ok = mSerialiser->serialise(grpItem, gData, &size); {
if (!ok) RsTlvSecurityKey& key = mit_keys->second;
{
std::cerr << "RsGenExchange::publishGrps() !ok ERROR After First Serialise" << std::endl;
}
grp->grp.setBinData(gData, size); if(key.keyFlags & (RSTLV_KEY_DISTRIB_ADMIN | RSTLV_KEY_TYPE_FULL))
if(ok)
{ {
grp->metaData = new RsGxsGrpMetaData(); privAdminKey = key;
grpItem->meta.mPublishTs = time(NULL); privKeyFound = true;
*(grp->metaData) = grpItem->meta; }
grp->metaData->mSubscribeFlags = GXS_SERV::GROUP_SUBSCRIBE_ADMIN; }
ok &= createGroup(grp, keySet);
if (!ok)
{
std::cerr << "RsGenExchange::publishGrps() !ok ERROR After createGroup" << std::endl;
}
size = grp->metaData->serial_size(); bool ok = true;
char mData[size];
grp->metaData->mGroupId = grp->grpId;
ok &= grp->metaData->serialise(mData, size);
if (!ok)
{
std::cerr << "RsGenExchange::publishGrps() !ok ERROR After Meta Serialise" << std::endl;
}
grp->meta.setBinData(mData, size); if(privKeyFound)
RsGxsGroupId grpId = grp->grpId; {
mDataAccess->addGroupData(grp); // get group id from private admin key id
grpItem->meta.mGroupId = grp->grpId = privAdminKey.keyId;
}
else
{
ok = false;
}
std::cerr << "RsGenExchange::publishGrps() ok -> pushing to notifies" << std::endl;
// add to published to allow acknowledgement service_CreateGroup(grpItem, keySet);
mGrpNotify.insert(std::make_pair(mit->first, grpId));
mDataAccess->updatePublicRequestStatus(mit->first, RsTokenService::GXS_REQUEST_V2_STATUS_COMPLETE); uint32_t size = mSerialiser->size(grpItem);
char gData[size];
ok = mSerialiser->serialise(grpItem, gData, &size);
if (!ok)
{
std::cerr << "RsGenExchange::publishGrps() !ok ERROR After First Serialise" << std::endl;
}
grp->grp.setBinData(gData, size);
if(ok)
{
grp->metaData = new RsGxsGrpMetaData();
grpItem->meta.mPublishTs = time(NULL);
*(grp->metaData) = grpItem->meta;
grp->metaData->mSubscribeFlags = GXS_SERV::GROUP_SUBSCRIBE_ADMIN;
ok &= createGroup(grp, keySet);
if (!ok)
{
std::cerr << "RsGenExchange::publishGrps() !ok ERROR After createGroup" << std::endl;
} }
if(!ok) RsGxsGroupId grpId = grp->grpId;
{ mDataAccess->addGroupData(grp);
std::cerr << "RsGenExchange::publishGrps() ok -> pushing to notifies" << std::endl;
// add to published to allow acknowledgement
mGrpNotify.insert(std::make_pair(mit->first, grpId));
mDataAccess->updatePublicRequestStatus(mit->first, RsTokenService::GXS_REQUEST_V2_STATUS_COMPLETE);
}
if(!ok)
{
#ifdef GEN_EXCH_DEBUG #ifdef GEN_EXCH_DEBUG
#endif #endif
std::cerr << "RsGenExchange::publishGrps() failed to publish grp " << std::endl; std::cerr << "RsGenExchange::publishGrps() failed to publish grp " << std::endl;
delete grp; delete grp;
// add to published to allow acknowledgement, grpid is empty as grp creation failed // add to published to allow acknowledgement, grpid is empty as grp creation failed
mGrpNotify.insert(std::make_pair(mit->first, RsGxsGroupId(""))); mGrpNotify.insert(std::make_pair(mit->first, RsGxsGroupId("")));
mDataAccess->updatePublicRequestStatus(mit->first, RsTokenService::GXS_REQUEST_V2_STATUS_FAILED); mDataAccess->updatePublicRequestStatus(mit->first, RsTokenService::GXS_REQUEST_V2_STATUS_FAILED);
continue; continue;
} }
delete grpItem; delete grpItem;
} }
// clear grp list as we're done publishing them and entries // clear grp list as we're done publishing them and entries
// are invalid // are invalid
for(int i = 0; i < toRemove.size(); i++) for(int i = 0; i < toRemove.size(); i++)
mGrpsToPublish.erase(toRemove[i]); mGrpsToPublish.erase(toRemove[i]);
} }
@ -1090,33 +1273,54 @@ bool RsGenExchange::getGroupKeys(const RsGxsGroupId &grpId, RsTlvSecurityKeySet
void RsGenExchange::createDummyGroup(RsGxsGrpItem *grpItem) void RsGenExchange::createDummyGroup(RsGxsGrpItem *grpItem)
{ {
RsStackMutex stack(mGenMtx); RsStackMutex stack(mGenMtx);
RsNxsGrp* grp = new RsNxsGrp(mServType); RsNxsGrp* grp = new RsNxsGrp(mServType);
uint32_t size = mSerialiser->size(grpItem); uint32_t size = mSerialiser->size(grpItem);
char gData[size]; char gData[size];
bool ok = mSerialiser->serialise(grpItem, gData, &size); bool ok = mSerialiser->serialise(grpItem, gData, &size);
grp->grp.setBinData(gData, size); grp->grp.setBinData(gData, size);
RsTlvSecurityKeySet keySet; RsTlvSecurityKeySet keySet;
generateGroupKeys(keySet); generateGroupKeys(keySet,
!(grpItem->meta.mGroupFlags & GXS_SERV::FLAG_PRIVACY_PUBLIC));
service_CreateGroup(grpItem, keySet); // find private admin key
RsTlvSecurityKey privAdminKey;
std::map<std::string, RsTlvSecurityKey>::iterator mit_keys = keySet.keys.begin();
bool privKeyFound = false;
for(; mit_keys != keySet.keys.end(); mit_keys++)
{
RsTlvSecurityKey& key = mit_keys->second;
if(key.keyFlags & (RSTLV_KEY_DISTRIB_ADMIN | RSTLV_KEY_TYPE_FULL))
{
privAdminKey = key;
privKeyFound = true;
}
}
if(privKeyFound)
{
// get group id from private admin key id
grpItem->meta.mGroupId = grp->grpId = privAdminKey.keyId;
}
else
{
ok = false;
}
service_CreateGroup(grpItem, keySet);
if(ok) if(ok)
{ {
grp->metaData = new RsGxsGrpMetaData(); grp->metaData = new RsGxsGrpMetaData();
grpItem->meta.mPublishTs = time(NULL); grpItem->meta.mPublishTs = time(NULL);
*(grp->metaData) = grpItem->meta; *(grp->metaData) = grpItem->meta;
grp->metaData->mSubscribeFlags = ~GXS_SERV::GROUP_SUBSCRIBE_MASK; grp->metaData->mSubscribeFlags = GXS_SERV::GROUP_SUBSCRIBE_ADMIN;
createGroup(grp, keySet); createGroup(grp, keySet);
size = grp->metaData->serial_size();
char mData[size];
grp->metaData->mGroupId = grp->grpId;
ok = grp->metaData->serialise(mData, size);
grp->meta.setBinData(mData, size);
mDataAccess->addGroupData(grp); mDataAccess->addGroupData(grp);
} }

View file

@ -384,7 +384,8 @@ private:
/*! /*!
* This completes the creation of an instance on RsNxsGrp * This completes the creation of an instance on RsNxsGrp
* by assigning it a groupId and signature via SHA1 and EVP_sign respectively * by assigning it a groupId and signature via SHA1 and EVP_sign respectively \n
* Meta is serialised and stored in group at this point also
* @param grp Nxs group to create * @param grp Nxs group to create
*/ */
bool createGroup(RsNxsGrp* grp, RsTlvSecurityKeySet& keySet); bool createGroup(RsNxsGrp* grp, RsTlvSecurityKeySet& keySet);
@ -398,6 +399,16 @@ private:
*/ */
bool createMessage(RsNxsMsg* msg); bool createMessage(RsNxsMsg* msg);
/*!
* convenience function to create sign
* @param signSet signatures are stored here
* @param msgData message data to be signed
* @param grpMeta the meta data for group the message belongs to
* @return false if signature creation for any required signature fails, true otherwise
*/
bool createMsgSignatures(RsTlvKeySignatureSet& signSet, RsTlvBinaryData& msgData,
const RsGxsMsgMetaData& msgMeta, RsGxsGrpMetaData& grpMeta);
/*! /*!
* check meta change is legal * check meta change is legal
* @return false if meta change is not legal * @return false if meta change is not legal
@ -407,8 +418,9 @@ private:
/*! /*!
* Generate a set of keys that can define a GXS group * Generate a set of keys that can define a GXS group
* @param keySet this is set generated keys * @param keySet this is set generated keys
* @param genPublicKeys should public keys also be generated
*/ */
void generateGroupKeys(RsTlvSecurityKeySet& keySet); void generateGroupKeys(RsTlvSecurityKeySet& keySet, bool genPublishKeys);
/*! /*!
* Attempts to validate msg * Attempts to validate msg
@ -419,8 +431,16 @@ private:
*/ */
bool validateMsg(RsNxsMsg* msg, const uint32_t& grpFlag, RsTlvSecurityKeySet& grpKeySet); bool validateMsg(RsNxsMsg* msg, const uint32_t& grpFlag, RsTlvSecurityKeySet& grpKeySet);
/*!
* Checks flag against a given privacy bit block
* @param pos Determines 8 bit wide privacy block to check
* @param flag the flag to and(&) against
* @param the result of the (bit-block & flag)
*/
bool checkMsgAuthenFlag(const PrivacyBitPos& pos, const uint8_t& flag) const; bool checkMsgAuthenFlag(const PrivacyBitPos& pos, const uint8_t& flag) const;
void groupShareKeys(std::list<std::string> peers);
private: private:
RsMutex mGenMtx; RsMutex mGenMtx;

View file

@ -363,8 +363,8 @@ void RsGxsNetService::run(){
bool RsGxsNetService::locked_checkTransacTimedOut(NxsTransaction* tr) bool RsGxsNetService::locked_checkTransacTimedOut(NxsTransaction* tr)
{ {
// return tr->mTimeOut < ((uint32_t) time(NULL)); return tr->mTimeOut < ((uint32_t) time(NULL));
return false; // return false;
} }
void RsGxsNetService::processTransactions(){ void RsGxsNetService::processTransactions(){
@ -1022,7 +1022,7 @@ void RsGxsNetService::locked_genSendMsgsTransaction(NxsTransaction* tr)
uint32_t transN = locked_getTransactionId(); uint32_t transN = locked_getTransactionId();
// store grp items to send in transaction // store msg items to send in transaction
GxsMsgResult::iterator mit = msgs.begin(); GxsMsgResult::iterator mit = msgs.begin();
std::string peerId = tr->mTransaction->PeerId(); std::string peerId = tr->mTransaction->PeerId();
uint32_t msgSize = 0; uint32_t msgSize = 0;

View file

@ -23,6 +23,9 @@
* *
*/ */
#ifndef PQI_HASH_
#define PQI_HASH_
#include <openssl/sha.h> #include <openssl/sha.h>
#include <string> #include <string>
#include <iomanip> #include <iomanip>
@ -86,4 +89,4 @@ void Complete(std::string &hash)
SHA_CTX *sha_ctx; SHA_CTX *sha_ctx;
}; };
#endif

View file

@ -42,6 +42,7 @@ class RsPostedGroup
{ {
public: public:
RsGroupMetaData mMeta; RsGroupMetaData mMeta;
std::string mDescription;
RsPostedGroup() { return; } RsPostedGroup() { return; }
}; };

View file

@ -2329,6 +2329,11 @@ int RsServer::StartupRetroShare()
RsGenExchange::setAuthenPolicyFlag(flag, photoAuthenPolicy, RsGenExchange::setAuthenPolicyFlag(flag, photoAuthenPolicy,
RsGenExchange::RESTRICTED_GRP_BITS); RsGenExchange::RESTRICTED_GRP_BITS);
// Re-enable later, photo not using gixs yet
// flag = GXS_SERV::MSG_AUTHEN_CHILD_AUTHOR_SIGN;
// RsGenExchange::setAuthenPolicyFlag(flag, photoAuthenPolicy,
// RsGenExchange::RESTRICTED_GRP_BITS);
flag = GXS_SERV::GRP_OPTION_AUTHEN_AUTHOR_SIGN; flag = GXS_SERV::GRP_OPTION_AUTHEN_AUTHOR_SIGN;
RsGenExchange::setAuthenPolicyFlag(flag, photoAuthenPolicy, RsGenExchange::setAuthenPolicyFlag(flag, photoAuthenPolicy,
RsGenExchange::GRP_OPTION_BITS); RsGenExchange::GRP_OPTION_BITS);

View file

@ -70,7 +70,7 @@ public:
RsNxsItem(uint16_t servtype, uint8_t subtype) RsNxsItem(uint16_t servtype, uint8_t subtype)
: RsItem(RS_PKT_VERSION_SERVICE, servtype, subtype), transactionNumber(0) : RsItem(RS_PKT_VERSION_SERVICE, servtype, subtype), transactionNumber(0)
{ {
setPriorityLevel(QOS_PRIORITY_RS_GXS_NET); setPriorityLevel(QOS_PRIORITY_RS_VOIP_PING);
return; return;
} }

View file

@ -90,8 +90,10 @@ p3PhotoServiceV2::p3PhotoServiceV2(RsGeneralDataService* gds, RsNetworkExchangeS
RsGxsPhotoAlbumItem* item1 = new RsGxsPhotoAlbumItem(), *item2 = new RsGxsPhotoAlbumItem(); RsGxsPhotoAlbumItem* item1 = new RsGxsPhotoAlbumItem(), *item2 = new RsGxsPhotoAlbumItem();
item1->meta.mGroupName = "Dummy Album 1"; item1->meta.mGroupName = "Dummy Album 1";
item1->meta.mGroupFlags = GXS_SERV::FLAG_PRIVACY_RESTRICTED;
item1->album.mCaption = "Dummy 1"; item1->album.mCaption = "Dummy 1";
item2->meta.mGroupName = "Dummy Album 2"; item2->meta.mGroupName = "Dummy Album 2";
item2->meta.mGroupFlags = GXS_SERV::FLAG_PRIVACY_RESTRICTED;
item2->album.mCaption = "Dummy 2"; item2->album.mCaption = "Dummy 2";
createDummyGroup(item1); createDummyGroup(item1);

View file

@ -7,6 +7,7 @@
#include "nxstestscenario.h" #include "nxstestscenario.h"
#include "gxs/rsdataservice.h" #include "gxs/rsdataservice.h"
#include "gxs/rsgxsflags.h"
#include "data_support.h" #include "data_support.h"
#include <stdio.h> #include <stdio.h>
@ -147,6 +148,8 @@ void NxsMessageTestObserver::notifyNewGroups(std::vector<RsNxsGrp *> &groups)
{ {
RsNxsGrp* grp = *vit; RsNxsGrp* grp = *vit;
RsGxsGrpMetaData* meta = new RsGxsGrpMetaData(); RsGxsGrpMetaData* meta = new RsGxsGrpMetaData();
meta->deserialise(grp->meta.bin_data, grp->meta.bin_len);
meta->mSubscribeFlags |= GXS_SERV::GROUP_SUBSCRIBE_SUBSCRIBED;
meta->mGroupId = grp->grpId; meta->mGroupId = grp->grpId;
grps.insert(std::make_pair(grp, meta)); grps.insert(std::make_pair(grp, meta));
} }

View file

@ -2,6 +2,7 @@
#include "AlbumDialog.h" #include "AlbumDialog.h"
#include "ui_AlbumDialog.h" #include "ui_AlbumDialog.h"
#include "gxs/rsgxsflags.h"
AlbumDialog::AlbumDialog(const RsPhotoAlbum& album, TokenQueue* photoQueue, RsPhotoV2* rs_Photo, QWidget *parent) : AlbumDialog::AlbumDialog(const RsPhotoAlbum& album, TokenQueue* photoQueue, RsPhotoV2* rs_Photo, QWidget *parent) :
QDialog(parent), QDialog(parent),
@ -13,6 +14,12 @@ AlbumDialog::AlbumDialog(const RsPhotoAlbum& album, TokenQueue* photoQueue, RsPh
connect(ui->pushButton_DeletePhoto, SIGNAL(clicked()), this, SLOT(deletePhoto())); connect(ui->pushButton_DeletePhoto, SIGNAL(clicked()), this, SLOT(deletePhoto()));
mPhotoDrop = ui->scrollAreaWidgetContents; mPhotoDrop = ui->scrollAreaWidgetContents;
if(!(mAlbum.mMeta.mSubscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_ADMIN))
{
ui->scrollAreaPhotos->setEnabled(false);
ui->pushButton_DeletePhoto->setEnabled(false);
}
mPhotoDrop->setPhotoItemHolder(this); mPhotoDrop->setPhotoItemHolder(this);
setUp(); setUp();
@ -32,6 +39,7 @@ void AlbumDialog::setUp()
} }
void AlbumDialog::updateAlbumPhotos(){ void AlbumDialog::updateAlbumPhotos(){
QSet<PhotoItem*> photos; QSet<PhotoItem*> photos;
mPhotoDrop->getPhotos(photos); mPhotoDrop->getPhotos(photos);

View file

@ -285,7 +285,7 @@ p, li { white-space: pre-wrap; }
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>627</width> <width>627</width>
<height>107</height> <height>116</height>
</rect> </rect>
</property> </property>
<property name="styleSheet"> <property name="styleSheet">
@ -344,7 +344,7 @@ p, li { white-space: pre-wrap; }
<item> <item>
<widget class="QPushButton" name="pushButton_PublishPhotos"> <widget class="QPushButton" name="pushButton_PublishPhotos">
<property name="text"> <property name="text">
<string>Publish Photos</string> <string>Publish Photos / Close</string>
</property> </property>
</widget> </widget>
</item> </item>

View file

@ -2,7 +2,7 @@
#include <QVBoxLayout> #include <QVBoxLayout>
#include "PhotoDialog.h" #include "PhotoDialog.h"
#include "ui_PhotoDialog.h" #include "ui_PhotoDialog.h"
#include "retroshare/rsidentity.h"
#include "AddCommentDialog.h" #include "AddCommentDialog.h"
PhotoDialog::PhotoDialog(RsPhotoV2 *rs_photo, const RsPhotoPhoto &photo, QWidget *parent) : PhotoDialog::PhotoDialog(RsPhotoV2 *rs_photo, const RsPhotoPhoto &photo, QWidget *parent) :
@ -37,8 +37,6 @@ void PhotoDialog::setUp()
ui->label_Photo->setPixmap(qtn); ui->label_Photo->setPixmap(qtn);
ui->lineEdit_Title->setText(QString::fromStdString(mPhotoDetails.mMeta.mMsgName)); ui->lineEdit_Title->setText(QString::fromStdString(mPhotoDetails.mMeta.mMsgName));
//ui->scrollAreaWidgetContents->setLayout(new QVBoxLayout());
requestComments(); requestComments();
} }

View file

@ -56,21 +56,13 @@ bool PostedGroupDialog::service_CreateGroup(uint32_t &token, const RsGroupMetaDa
{ {
// Specific Function. // Specific Function.
RsPostedGroup grp; RsPostedGroup grp;
grp.mDescription = getDescription().toStdString();
grp.mMeta = meta; grp.mMeta = meta;
rsPosted->submitGroup(token, grp); rsPosted->submitGroup(token, grp);
return true; return true;
} }
QPixmap PostedGroupDialog::service_getLogo()
{
return QPixmap(); // null pixmap
}
QString PostedGroupDialog::service_getDescription()
{
return QString();
}

View file

@ -46,19 +46,6 @@ protected:
bool service_CreateGroup(uint32_t &token, const RsGroupMetaData &meta); bool service_CreateGroup(uint32_t &token, const RsGroupMetaData &meta);
/*!
* This should return a group logo \n
* Will be called when GxsGroupDialog is initialised in show mode
*
*/
virtual QPixmap service_getLogo();
/*!
* This should return a group description string
* @return group description string
*/
virtual QString service_getDescription();
private: private:
RsPostedGroup mGrp; RsPostedGroup mGrp;

View file

@ -399,7 +399,15 @@ void GxsGroupDialog::addGroupLogo()
ui.groupLogo->setIcon(picture); ui.groupLogo->setIcon(picture);
} }
QPixmap GxsGroupDialog::getLogo()
{
return picture;
}
QString GxsGroupDialog::getDescription()
{
return ui.groupDesc->document()->toPlainText();
}
/*********************************************************************************** /***********************************************************************************
Share Lists. Share Lists.

View file

@ -149,24 +149,24 @@ protected:
/*! /*!
* Main purpose is to help tansfer meta data to service * Main purpose is to help tansfer meta data to service
* and also *
* @param token This should be set to the token retrieved * @param token This should be set to the token retrieved
* @param meta The deriving GXS service should set their grp meta to this value * @param meta The deriving GXS service should set their grp meta to this value
*/ */
virtual bool service_CreateGroup(uint32_t &token, const RsGroupMetaData &meta) = 0; virtual bool service_CreateGroup(uint32_t &token, const RsGroupMetaData &meta) = 0;
/*! /*!
* This should return a group logo \n * This returns a group logo from the ui \n
* Will be called when GxsGroupDialog is initialised in show mode * Should be calleld by deriving service
* @return The logo for the service * @return The logo for the service
*/ */
virtual QPixmap service_getLogo() = 0; QPixmap getLogo();
/*! /*!
* This should return a group description string * This returns a group description string from the ui
* @return group description string * @return group description string
*/ */
virtual QString service_getDescription() = 0; virtual QString getDescription();
private slots: private slots: