Code change to test group edit

- can modify group names and content now
 
 Group edit code fixes

git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-gxs_finale@6811 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
chrisparker126 2013-10-06 21:07:31 +00:00
parent 18944404cc
commit 25d721b6fe
10 changed files with 133 additions and 74 deletions

View File

@ -38,7 +38,7 @@ GxsSecurity::~GxsSecurity()
{ {
} }
RSA *GxsSecurity::extractPublicKey(RsTlvSecurityKey& key) RSA *GxsSecurity::extractPublicKey(const RsTlvSecurityKey& key)
{ {
const unsigned char *keyptr = (const unsigned char *) key.keyData.bin_data; const unsigned char *keyptr = (const unsigned char *) key.keyData.bin_data;
long keylen = key.keyData.bin_len; long keylen = key.keyData.bin_len;
@ -489,7 +489,7 @@ void GxsSecurity::setRSAPrivateKey(RsTlvSecurityKey & key, RSA *rsa_priv)
key.keyId = keyId; key.keyId = keyId;
} }
RSA *GxsSecurity::extractPrivateKey(RsTlvSecurityKey & key) RSA *GxsSecurity::extractPrivateKey(const RsTlvSecurityKey & key)
{ {
const unsigned char *keyptr = (const unsigned char *) key.keyData.bin_data; const unsigned char *keyptr = (const unsigned char *) key.keyData.bin_data;
long keylen = key.keyData.bin_len; long keylen = key.keyData.bin_len;

View File

@ -51,14 +51,14 @@ public:
* @param key RsTlvSecurityKey to extract public RSA key from * @param key RsTlvSecurityKey to extract public RSA key from
* @return pointer to the public RSA key if successful, null otherwise * @return pointer to the public RSA key if successful, null otherwise
*/ */
static RSA *extractPublicKey(RsTlvSecurityKey &key); static RSA *extractPublicKey(const RsTlvSecurityKey &key);
/*! /*!
* extracts the public key from an RsTlvSecurityKey * extracts the public key from an RsTlvSecurityKey
* @param key RsTlvSecurityKey to extract private RSA key from * @param key RsTlvSecurityKey to extract private RSA key from
* @return pointer to the private RSA key if successful, null otherwise * @return pointer to the private RSA key if successful, null otherwise
*/ */
static RSA *extractPrivateKey(RsTlvSecurityKey &key); static RSA *extractPrivateKey(const RsTlvSecurityKey &key);
/*! /*!
* stores the rsa public key in a RsTlvSecurityKey * stores the rsa public key in a RsTlvSecurityKey

View File

@ -118,6 +118,8 @@ void RsGenExchange::tick()
publishMsgs(); publishMsgs();
processGroupUpdatePublish();
processRecvdData(); processRecvdData();
if(!mNotifications.empty()) if(!mNotifications.empty())
@ -278,6 +280,54 @@ void RsGenExchange::generateGroupKeys(RsTlvSecurityKeySet& privatekeySet,
} }
} }
void RsGenExchange::generatePublicFromPrivateKeys(const RsTlvSecurityKeySet &privatekeySet,
RsTlvSecurityKeySet &publickeySet)
{
// actually just copy settings of one key except mark its key flags public
typedef std::map<std::string, RsTlvSecurityKey> keyMap;
const keyMap& allKeys = privatekeySet.keys;
keyMap::const_iterator cit = allKeys.begin();
bool adminFound = false, publishFound = false;
for(; cit != allKeys.end(); cit++)
{
const RsTlvSecurityKey& privKey = cit->second;
if(privKey.keyFlags & RSTLV_KEY_TYPE_FULL)
{
RsTlvSecurityKey pubKey;
pubKey = privKey;
RSA *rsaPrivKey = NULL, *rsaPubKey = NULL;
rsaPrivKey = GxsSecurity::extractPrivateKey(privKey);
if(rsaPrivKey)
rsaPubKey = RSAPublicKey_dup(rsaPrivKey);
if(rsaPrivKey && rsaPubKey)
{
GxsSecurity::setRSAPublicKey(pubKey, rsaPubKey);
if(pubKey.keyFlags & RSTLV_KEY_DISTRIB_ADMIN)
pubKey.keyFlags = RSTLV_KEY_DISTRIB_ADMIN | RSTLV_KEY_TYPE_PUBLIC_ONLY;
if(pubKey.keyFlags & RSTLV_KEY_DISTRIB_PRIVATE)
pubKey.keyFlags = RSTLV_KEY_DISTRIB_PRIVATE | RSTLV_KEY_TYPE_PUBLIC_ONLY;
publickeySet.keys.insert(std::make_pair(pubKey.keyId, pubKey));
}
if(rsaPrivKey)
RSA_free(rsaPrivKey);
if(rsaPubKey)
RSA_free(rsaPubKey);
}
}
}
uint8_t RsGenExchange::createGroup(RsNxsGrp *grp, RsTlvSecurityKeySet& privateKeySet, RsTlvSecurityKeySet& publicKeySet) uint8_t RsGenExchange::createGroup(RsNxsGrp *grp, RsTlvSecurityKeySet& privateKeySet, RsTlvSecurityKeySet& publicKeySet)
{ {
std::cerr << "RsGenExchange::createGroup()"; std::cerr << "RsGenExchange::createGroup()";
@ -1818,6 +1868,9 @@ void RsGenExchange::processGroupUpdatePublish()
grpMeta.insert(std::make_pair(groupId, (RsGxsGrpMetaData*)(NULL))); grpMeta.insert(std::make_pair(groupId, (RsGxsGrpMetaData*)(NULL)));
} }
if(grpMeta.empty())
return;
mDataStore->retrieveGxsGrpMetaData(grpMeta); mDataStore->retrieveGxsGrpMetaData(grpMeta);
// now // now
@ -1832,20 +1885,23 @@ void RsGenExchange::processGroupUpdatePublish()
assignMetaUpdates(gup.grpItem->meta, gup.mUpdateMeta); assignMetaUpdates(gup.grpItem->meta, gup.mUpdateMeta);
GxsGrpPendingSign ggps(gup.grpItem, ggps.mToken); GxsGrpPendingSign ggps(gup.grpItem, ggps.mToken);
bool split = splitKeys(meta->keys, ggps.mPrivateKeys, ggps.mPublicKeys); bool publishAndAdminPrivatePresent = checkKeys(meta->keys);
if(split) if(publishAndAdminPrivatePresent)
{ {
ggps.mHaveKeys = true; ggps.mPrivateKeys = meta->keys;
ggps.mStartTS = time(NULL); generatePublicFromPrivateKeys(ggps.mPrivateKeys, ggps.mPublicKeys);
ggps.mLastAttemptTS = 0; ggps.mHaveKeys = true;
mGrpsToPublish.push_back(ggps); ggps.mStartTS = time(NULL);
ggps.mLastAttemptTS = 0;
ggps.mIsUpdate = true;
mGrpsToPublish.push_back(ggps);
}else }else
{ {
delete gup.grpItem; delete gup.grpItem;
mDataAccess->updatePublicRequestStatus(gup.mToken, RsTokenService::GXS_REQUEST_V2_STATUS_FAILED); mDataAccess->updatePublicRequestStatus(gup.mToken, RsTokenService::GXS_REQUEST_V2_STATUS_FAILED);
} }
delete meta;
} }
mGroupUpdatePublish.clear(); mGroupUpdatePublish.clear();
@ -1853,43 +1909,39 @@ void RsGenExchange::processGroupUpdatePublish()
void RsGenExchange::assignMetaUpdates(RsGroupMetaData& meta, const RsGxsGroupUpdateMeta metaUpdate) const void RsGenExchange::assignMetaUpdates(RsGroupMetaData& meta, const RsGxsGroupUpdateMeta metaUpdate) const
{ {
const RsGxsGroupUpdateMeta::GxsMetaUpdate* updates; const RsGxsGroupUpdateMeta::GxsMetaUpdate* updates = metaUpdate.getUpdates();
RsGxsGroupUpdateMeta::GxsMetaUpdate::const_iterator mit = updates->begin(); RsGxsGroupUpdateMeta::GxsMetaUpdate::const_iterator mit = updates->begin();
for(; mit != updates->end(); mit++) for(; mit != updates->end(); mit++)
{ {
const UpdateItem* item = mit->second;
RsGxsGroupUpdateMeta::UpdateType utype = mit->first;
if(utype == RsGxsGroupUpdateMeta::NAME) if(mit->first == RsGxsGroupUpdateMeta::NAME)
{ meta.mGroupName = mit->second;
const StringUpdateItem* sitem = NULL;
if((sitem = dynamic_cast<const StringUpdateItem*>(item)) != NULL)
{
meta.mGroupName = sitem->getUpdate();
}
}
} }
} }
bool RsGenExchange::splitKeys(const RsTlvSecurityKeySet& keySet, RsTlvSecurityKeySet& privateKeySet, RsTlvSecurityKeySet& publicKeySet) bool RsGenExchange::checkKeys(const RsTlvSecurityKeySet& keySet)
{ {
typedef std::map<std::string, RsTlvSecurityKey> keyMap; typedef std::map<std::string, RsTlvSecurityKey> keyMap;
const keyMap& allKeys = keySet.keys; const keyMap& allKeys = keySet.keys;
keyMap::const_iterator cit = allKeys.begin(); keyMap::const_iterator cit = allKeys.begin();
bool adminFound = false, publishFound = false;
for(; cit != allKeys.end(); cit++) for(; cit != allKeys.end(); cit++)
{ {
const RsTlvSecurityKey& key = cit->second; const RsTlvSecurityKey& key = cit->second;
if(key.keyFlags & RSTLV_KEY_TYPE_PUBLIC_ONLY) if(key.keyFlags & RSTLV_KEY_TYPE_FULL)
publicKeySet.keys.insert(std::make_pair(key.keyId, key)); {
else if(key.keyFlags & RSTLV_KEY_TYPE_FULL) if(key.keyFlags & RSTLV_KEY_DISTRIB_ADMIN)
privateKeySet.keys.insert(std::make_pair(key.keyId, key)); adminFound = true;
if(key.keyFlags & RSTLV_KEY_DISTRIB_PRIVATE)
publishFound = true;
}
} }
// user must have both private and public parts of publish and admin keys // user must have both private and public parts of publish and admin keys
return (privateKeySet.keys.size() == 2) && (publicKeySet.keys.size() == 2); return adminFound && publishFound;
} }
void RsGenExchange::publishGrps() void RsGenExchange::publishGrps()
@ -1962,10 +2014,6 @@ void RsGenExchange::publishGrps()
// get group id from private admin key id // get group id from private admin key id
grpItem->meta.mGroupId = grp->grpId = privAdminKey.keyId; grpItem->meta.mGroupId = grp->grpId = privAdminKey.keyId;
// what!? this will remove the private keys!
privatekeySet.keys.insert(publicKeySet.keys.begin(),
publicKeySet.keys.end());
ServiceCreate_Return ret = service_CreateGroup(grpItem, privatekeySet); ServiceCreate_Return ret = service_CreateGroup(grpItem, privatekeySet);

View File

@ -712,11 +712,20 @@ private:
/*! /*!
* Generate a set of keys that can define a GXS group * Generate a set of keys that can define a GXS group
* @param privatekeySet contains private generated keys * @param privatekeySet contains private generated keys
* @param privatekeySet contains public generated keys (counterpart of private) * @param publickeySet contains public generated keys (counterpart of private)
* @param genPublicKeys should publish key pair also be generated * @param genPublicKeys should publish key pair also be generated
*/ */
void generateGroupKeys(RsTlvSecurityKeySet& privatekeySet, RsTlvSecurityKeySet& publickeySet, bool genPublishKeys); void generateGroupKeys(RsTlvSecurityKeySet& privatekeySet, RsTlvSecurityKeySet& publickeySet, bool genPublishKeys);
/*!
* Generate public set of keys from their private counterparts
* No keys will be generated if one fails
* @param privatekeySet contains private generated keys
* @param publickeySet contains public generated keys (counterpart of private)
* @return false if key gen failed for a key set
*/
void generatePublicFromPrivateKeys(const RsTlvSecurityKeySet& privatekeySet, RsTlvSecurityKeySet& publickeySet);
/*! /*!
* Attempts to validate msg signatures * Attempts to validate msg signatures
* @param msg message to be validated * @param msg message to be validated
@ -763,14 +772,11 @@ private:
bool updateValid(RsGxsGrpMetaData& oldGrp, RsNxsGrp& newGrp) const; bool updateValid(RsGxsGrpMetaData& oldGrp, RsNxsGrp& newGrp) const;
/*! /*!
* convenience function for splitting key sets into private and public * convenience function for checking private publish and admin keys are present
* @param keySet The keys set to split into a private and public set * @param keySet The keys set to split into a private and public set
* @param privateKeySet contains the publish and admin private keys * @return false, if private admin and publish keys cannot be found, true otherwise
* @param publicKeySet contains the publish and admin public keys
* @return false, if 2 private and public keys are not found in keySet
*/ */
bool splitKeys(const RsTlvSecurityKeySet& keySet, RsTlvSecurityKeySet& privateKeySet, bool checkKeys(const RsTlvSecurityKeySet& keySet);
RsTlvSecurityKeySet& publicKeySet);
/*! /*!
* Convenience function for assigning the meta update items to the actual group meta * Convenience function for assigning the meta update items to the actual group meta

View File

@ -169,28 +169,18 @@ public:
// expand as support is added for other utypes // expand as support is added for other utypes
enum UpdateType { DESCRIPTION, NAME }; enum UpdateType { DESCRIPTION, NAME };
RsGxsGroupUpdateMeta(const std::string& groupId); RsGxsGroupUpdateMeta(const std::string& groupId) : mGroupId(groupId) {}
~RsGxsGroupUpdateMeta()
{
GxsMetaUpdate::iterator mit = mUpdates.begin();
for(; mit != mUpdates.end(); mit++)
delete mit->second;
}
typedef std::map<UpdateType, UpdateItem*> GxsMetaUpdate; typedef std::map<UpdateType, std::string> GxsMetaUpdate;
/*! /*!
* Only one item of a utype can exist * Only one item of a utype can exist
* @param utype the type of meta update * @param utype the type of meta update
* @param item update item containing the change value * @param item update item containing the change value
*/ */
void setMetaUpdate(UpdateType utype, UpdateItem* item) void setMetaUpdate(UpdateType utype, const std::string& update)
{ {
GxsMetaUpdate::iterator mit; mUpdates[utype] = update;
if ((mit = mUpdates.find(utype)) != mUpdates.end())
mUpdates[utype] = item;
else
delete mUpdates[utype];
} }
/*! /*!
@ -199,9 +189,8 @@ public:
*/ */
bool removeUpdateType(UpdateType utype){ return mUpdates.erase(utype) == 1; } bool removeUpdateType(UpdateType utype){ return mUpdates.erase(utype) == 1; }
const GxsMetaUpdate* getUpdate() { return &mUpdates; } const GxsMetaUpdate* getUpdates() const { return &mUpdates; }
const std::string& getGroupId() const { return mGroupId; }
const std::string& getGroupId() { return mGroupId; }
private: private:

View File

@ -219,12 +219,13 @@ bool p3GxsForums::updateGroup(uint32_t &token, RsGxsGroupUpdateMeta& meta, RsGxs
{ {
std::cerr << "p3GxsForums::createGroup()" << std::endl; std::cerr << "p3GxsForums::createGroup()" << std::endl;
if(group.mMeta.mGroupId.empty()) if(meta.getGroupId().empty())
return false; return false;
RsGxsForumGroupItem* grpItem = new RsGxsForumGroupItem(); RsGxsForumGroupItem* grpItem = new RsGxsForumGroupItem();
grpItem->mGroup = group; grpItem->mGroup = group;
grpItem->meta = group.mMeta; grpItem->meta = group.mMeta;
grpItem->meta.mGroupId = meta.getGroupId();
RsGenExchange::updateGroup(token, meta, grpItem); RsGenExchange::updateGroup(token, meta, grpItem);
return true; return true;

View File

@ -343,15 +343,10 @@ void GxsGroupDialog::editGroup()
} }
uint32_t token; uint32_t token;
RsGroupMetaData meta; RsGxsGroupUpdateMeta updateMeta(mGrpMeta.mGroupId);
updateMeta.setMetaUpdate(RsGxsGroupUpdateMeta::NAME, std::string(name.toUtf8()));
// Fill in the MetaData as best we can. if (service_EditGroup(token, updateMeta))
meta.mGroupName = std::string(name.toUtf8());
meta.mGroupFlags = flags;
meta.mSignFlags = getGroupSignFlags();
if (service_CreateGroup(token, meta))
{ {
// get the Queue to handle response. // get the Queue to handle response.
if(mTokenQueue != NULL) if(mTokenQueue != NULL)

View File

@ -163,13 +163,21 @@ protected:
void setUiText(UiType uiType, const QString &text); void setUiText(UiType uiType, const QString &text);
/*! /*!
* Main purpose is to help tansfer meta data to service * It is up to the service to do the actual group creation
* * Service can also modify initial meta going into group
* @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;
/*!
* It is up to the service to do the actual group editing
* TODO: make pure virtual
* @param token This should be set to the token retrieved
* @param meta The deriving GXS service should set their grp meta to this value
*/
virtual bool service_EditGroup(uint32_t &token, RsGxsGroupUpdateMeta &updateMeta) {}
/*! /*!
* This returns a group logo from the ui \n * This returns a group logo from the ui \n
* Should be calleld by deriving service * Should be calleld by deriving service
@ -216,6 +224,8 @@ private:
uint32_t mReadonlyFlags; uint32_t mReadonlyFlags;
uint32_t mDefaultsFlags; uint32_t mDefaultsFlags;
protected:
/** Qt Designer generated object */ /** Qt Designer generated object */
Ui::GxsGroupDialog ui; Ui::GxsGroupDialog ui;
}; };

View File

@ -95,8 +95,17 @@ bool GxsForumGroupDialog::service_CreateGroup(uint32_t &token, const RsGroupMeta
// Specific Function. // Specific Function.
RsGxsForumGroup grp; RsGxsForumGroup grp;
grp.mMeta = meta; grp.mMeta = meta;
//grp.mDescription = std::string(desc.toUtf8()); grp.mDescription = std::string(ui.groupDesc->toPlainText().toUtf8());
rsGxsForums->createGroup(token, grp); rsGxsForums->createGroup(token, grp);
return true; return true;
} }
bool GxsForumGroupDialog::service_EditGroup(uint32_t &token, RsGxsGroupUpdateMeta &updateMeta)
{
RsGxsForumGroup grp;
grp.mDescription = std::string(ui.groupDesc->toPlainText().toUtf8());
rsGxsForums->updateGroup(token, updateMeta, grp);
return true;
}

View File

@ -37,6 +37,7 @@ protected:
virtual void initUi(); virtual void initUi();
virtual QPixmap serviceImage(); virtual QPixmap serviceImage();
virtual bool service_CreateGroup(uint32_t &token, const RsGroupMetaData &meta); virtual bool service_CreateGroup(uint32_t &token, const RsGroupMetaData &meta);
virtual bool service_EditGroup(uint32_t &token, RsGxsGroupUpdateMeta &updateMeta);
}; };
#endif #endif