mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
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:
parent
18944404cc
commit
25d721b6fe
@ -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;
|
||||
long keylen = key.keyData.bin_len;
|
||||
@ -489,7 +489,7 @@ void GxsSecurity::setRSAPrivateKey(RsTlvSecurityKey & key, RSA *rsa_priv)
|
||||
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;
|
||||
long keylen = key.keyData.bin_len;
|
||||
|
@ -51,14 +51,14 @@ public:
|
||||
* @param key RsTlvSecurityKey to extract public RSA key from
|
||||
* @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
|
||||
* @param key RsTlvSecurityKey to extract private RSA key from
|
||||
* @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
|
||||
|
@ -118,6 +118,8 @@ void RsGenExchange::tick()
|
||||
|
||||
publishMsgs();
|
||||
|
||||
processGroupUpdatePublish();
|
||||
|
||||
processRecvdData();
|
||||
|
||||
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)
|
||||
{
|
||||
std::cerr << "RsGenExchange::createGroup()";
|
||||
@ -1818,6 +1868,9 @@ void RsGenExchange::processGroupUpdatePublish()
|
||||
grpMeta.insert(std::make_pair(groupId, (RsGxsGrpMetaData*)(NULL)));
|
||||
}
|
||||
|
||||
if(grpMeta.empty())
|
||||
return;
|
||||
|
||||
mDataStore->retrieveGxsGrpMetaData(grpMeta);
|
||||
|
||||
// now
|
||||
@ -1832,20 +1885,23 @@ void RsGenExchange::processGroupUpdatePublish()
|
||||
assignMetaUpdates(gup.grpItem->meta, gup.mUpdateMeta);
|
||||
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.mStartTS = time(NULL);
|
||||
ggps.mLastAttemptTS = 0;
|
||||
mGrpsToPublish.push_back(ggps);
|
||||
ggps.mPrivateKeys = meta->keys;
|
||||
generatePublicFromPrivateKeys(ggps.mPrivateKeys, ggps.mPublicKeys);
|
||||
ggps.mHaveKeys = true;
|
||||
ggps.mStartTS = time(NULL);
|
||||
ggps.mLastAttemptTS = 0;
|
||||
ggps.mIsUpdate = true;
|
||||
mGrpsToPublish.push_back(ggps);
|
||||
}else
|
||||
{
|
||||
delete gup.grpItem;
|
||||
mDataAccess->updatePublicRequestStatus(gup.mToken, RsTokenService::GXS_REQUEST_V2_STATUS_FAILED);
|
||||
delete gup.grpItem;
|
||||
mDataAccess->updatePublicRequestStatus(gup.mToken, RsTokenService::GXS_REQUEST_V2_STATUS_FAILED);
|
||||
}
|
||||
|
||||
delete meta;
|
||||
}
|
||||
|
||||
mGroupUpdatePublish.clear();
|
||||
@ -1853,43 +1909,39 @@ void RsGenExchange::processGroupUpdatePublish()
|
||||
|
||||
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();
|
||||
for(; mit != updates->end(); mit++)
|
||||
{
|
||||
const UpdateItem* item = mit->second;
|
||||
RsGxsGroupUpdateMeta::UpdateType utype = mit->first;
|
||||
|
||||
if(utype == RsGxsGroupUpdateMeta::NAME)
|
||||
{
|
||||
const StringUpdateItem* sitem = NULL;
|
||||
|
||||
if((sitem = dynamic_cast<const StringUpdateItem*>(item)) != NULL)
|
||||
{
|
||||
meta.mGroupName = sitem->getUpdate();
|
||||
}
|
||||
}
|
||||
if(mit->first == RsGxsGroupUpdateMeta::NAME)
|
||||
meta.mGroupName = mit->second;
|
||||
}
|
||||
}
|
||||
|
||||
bool RsGenExchange::splitKeys(const RsTlvSecurityKeySet& keySet, RsTlvSecurityKeySet& privateKeySet, RsTlvSecurityKeySet& publicKeySet)
|
||||
bool RsGenExchange::checkKeys(const RsTlvSecurityKeySet& keySet)
|
||||
{
|
||||
|
||||
typedef std::map<std::string, RsTlvSecurityKey> keyMap;
|
||||
const keyMap& allKeys = keySet.keys;
|
||||
keyMap::const_iterator cit = allKeys.begin();
|
||||
|
||||
bool adminFound = false, publishFound = false;
|
||||
for(; cit != allKeys.end(); cit++)
|
||||
{
|
||||
const RsTlvSecurityKey& key = cit->second;
|
||||
if(key.keyFlags & RSTLV_KEY_TYPE_PUBLIC_ONLY)
|
||||
publicKeySet.keys.insert(std::make_pair(key.keyId, key));
|
||||
else if(key.keyFlags & RSTLV_KEY_TYPE_FULL)
|
||||
privateKeySet.keys.insert(std::make_pair(key.keyId, key));
|
||||
const RsTlvSecurityKey& key = cit->second;
|
||||
if(key.keyFlags & RSTLV_KEY_TYPE_FULL)
|
||||
{
|
||||
if(key.keyFlags & RSTLV_KEY_DISTRIB_ADMIN)
|
||||
adminFound = true;
|
||||
|
||||
if(key.keyFlags & RSTLV_KEY_DISTRIB_PRIVATE)
|
||||
publishFound = true;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// 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()
|
||||
@ -1962,10 +2014,6 @@ void RsGenExchange::publishGrps()
|
||||
// get group id from private admin key id
|
||||
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);
|
||||
|
||||
|
||||
|
@ -712,11 +712,20 @@ private:
|
||||
/*!
|
||||
* Generate a set of keys that can define a GXS group
|
||||
* @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
|
||||
*/
|
||||
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
|
||||
* @param msg message to be validated
|
||||
@ -763,14 +772,11 @@ private:
|
||||
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 privateKeySet contains the publish and admin private keys
|
||||
* @param publicKeySet contains the publish and admin public keys
|
||||
* @return false, if 2 private and public keys are not found in keySet
|
||||
* @return false, if private admin and publish keys cannot be found, true otherwise
|
||||
*/
|
||||
bool splitKeys(const RsTlvSecurityKeySet& keySet, RsTlvSecurityKeySet& privateKeySet,
|
||||
RsTlvSecurityKeySet& publicKeySet);
|
||||
bool checkKeys(const RsTlvSecurityKeySet& keySet);
|
||||
|
||||
/*!
|
||||
* Convenience function for assigning the meta update items to the actual group meta
|
||||
|
@ -169,28 +169,18 @@ public:
|
||||
// expand as support is added for other utypes
|
||||
enum UpdateType { DESCRIPTION, NAME };
|
||||
|
||||
RsGxsGroupUpdateMeta(const std::string& groupId);
|
||||
~RsGxsGroupUpdateMeta()
|
||||
{
|
||||
GxsMetaUpdate::iterator mit = mUpdates.begin();
|
||||
for(; mit != mUpdates.end(); mit++)
|
||||
delete mit->second;
|
||||
}
|
||||
RsGxsGroupUpdateMeta(const std::string& groupId) : mGroupId(groupId) {}
|
||||
|
||||
typedef std::map<UpdateType, UpdateItem*> GxsMetaUpdate;
|
||||
typedef std::map<UpdateType, std::string> GxsMetaUpdate;
|
||||
|
||||
/*!
|
||||
* Only one item of a utype can exist
|
||||
* @param utype the type of meta update
|
||||
* @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;
|
||||
if ((mit = mUpdates.find(utype)) != mUpdates.end())
|
||||
mUpdates[utype] = item;
|
||||
else
|
||||
delete mUpdates[utype];
|
||||
mUpdates[utype] = update;
|
||||
}
|
||||
|
||||
/*!
|
||||
@ -199,9 +189,8 @@ public:
|
||||
*/
|
||||
bool removeUpdateType(UpdateType utype){ return mUpdates.erase(utype) == 1; }
|
||||
|
||||
const GxsMetaUpdate* getUpdate() { return &mUpdates; }
|
||||
|
||||
const std::string& getGroupId() { return mGroupId; }
|
||||
const GxsMetaUpdate* getUpdates() const { return &mUpdates; }
|
||||
const std::string& getGroupId() const { return mGroupId; }
|
||||
|
||||
private:
|
||||
|
||||
|
@ -219,12 +219,13 @@ bool p3GxsForums::updateGroup(uint32_t &token, RsGxsGroupUpdateMeta& meta, RsGxs
|
||||
{
|
||||
std::cerr << "p3GxsForums::createGroup()" << std::endl;
|
||||
|
||||
if(group.mMeta.mGroupId.empty())
|
||||
if(meta.getGroupId().empty())
|
||||
return false;
|
||||
|
||||
RsGxsForumGroupItem* grpItem = new RsGxsForumGroupItem();
|
||||
grpItem->mGroup = group;
|
||||
grpItem->meta = group.mMeta;
|
||||
grpItem->meta = group.mMeta;
|
||||
grpItem->meta.mGroupId = meta.getGroupId();
|
||||
|
||||
RsGenExchange::updateGroup(token, meta, grpItem);
|
||||
return true;
|
||||
|
@ -343,15 +343,10 @@ void GxsGroupDialog::editGroup()
|
||||
}
|
||||
|
||||
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.
|
||||
meta.mGroupName = std::string(name.toUtf8());
|
||||
|
||||
meta.mGroupFlags = flags;
|
||||
meta.mSignFlags = getGroupSignFlags();
|
||||
|
||||
if (service_CreateGroup(token, meta))
|
||||
if (service_EditGroup(token, updateMeta))
|
||||
{
|
||||
// get the Queue to handle response.
|
||||
if(mTokenQueue != NULL)
|
||||
|
@ -163,13 +163,21 @@ protected:
|
||||
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 meta The deriving GXS service should set their grp meta to this value
|
||||
*/
|
||||
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
|
||||
* Should be calleld by deriving service
|
||||
@ -216,6 +224,8 @@ private:
|
||||
uint32_t mReadonlyFlags;
|
||||
uint32_t mDefaultsFlags;
|
||||
|
||||
protected:
|
||||
|
||||
/** Qt Designer generated object */
|
||||
Ui::GxsGroupDialog ui;
|
||||
};
|
||||
|
@ -95,8 +95,17 @@ bool GxsForumGroupDialog::service_CreateGroup(uint32_t &token, const RsGroupMeta
|
||||
// Specific Function.
|
||||
RsGxsForumGroup grp;
|
||||
grp.mMeta = meta;
|
||||
//grp.mDescription = std::string(desc.toUtf8());
|
||||
grp.mDescription = std::string(ui.groupDesc->toPlainText().toUtf8());
|
||||
|
||||
rsGxsForums->createGroup(token, grp);
|
||||
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;
|
||||
}
|
||||
|
@ -37,6 +37,7 @@ protected:
|
||||
virtual void initUi();
|
||||
virtual QPixmap serviceImage();
|
||||
virtual bool service_CreateGroup(uint32_t &token, const RsGroupMetaData &meta);
|
||||
virtual bool service_EditGroup(uint32_t &token, RsGxsGroupUpdateMeta &updateMeta);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user