From 0dbe55bd05313571bed07fb3b58b45e10a047d3f Mon Sep 17 00:00:00 2001 From: drbob Date: Tue, 1 Apr 2014 08:00:20 +0000 Subject: [PATCH] Fixed serialiser bug in RsTlvList Switched to proper Ids in gxsCircle gxsId items. Fixed up Config serialiser. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7218 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/pqi/p3peermgr.cc | 25 +++--- libretroshare/src/retroshare/rsidentity.h | 6 +- libretroshare/src/serialiser/rsconfigitems.cc | 79 +++++++------------ libretroshare/src/serialiser/rsconfigitems.h | 17 ++-- .../src/serialiser/rsgxscircleitems.cc | 37 ++------- .../src/serialiser/rsgxscircleitems.h | 14 ++-- libretroshare/src/serialiser/rsgxsiditems.cc | 6 +- libretroshare/src/serialiser/rstlvaddrs.cc | 9 --- libretroshare/src/serialiser/rstlvbase.h | 1 + libretroshare/src/serialiser/rstlvidset.h | 5 +- libretroshare/src/serialiser/rstlvlist.h | 21 ++++- libretroshare/src/services/p3idservice.cc | 51 +++--------- 12 files changed, 101 insertions(+), 170 deletions(-) diff --git a/libretroshare/src/pqi/p3peermgr.cc b/libretroshare/src/pqi/p3peermgr.cc index 3f4b3da74..622a28d4c 100644 --- a/libretroshare/src/pqi/p3peermgr.cc +++ b/libretroshare/src/pqi/p3peermgr.cc @@ -1475,9 +1475,10 @@ bool p3PeerMgrIMPL::saveList(bool &cleanup, std::list& saveData) RsPeerNetItem *item = new RsPeerNetItem(); item->clear(); - item->pid = getOwnId().toStdString(); - item->gpg_id = mOwnState.gpg_id.toStdString(); + item->peerId = getOwnId(); + item->pgpId = mOwnState.gpg_id; item->location = mOwnState.location; + #if 0 if (mOwnState.netMode & RS_NET_MODE_TRY_EXT) { @@ -1526,8 +1527,8 @@ bool p3PeerMgrIMPL::saveList(bool &cleanup, std::list& saveData) item = new RsPeerNetItem(); item->clear(); - item->pid = it->first.toStdString(); - item->gpg_id = (it->second).gpg_id.toStdString(); + item->peerId = it->first; + item->pgpId = (it->second).gpg_id; item->location = (it->second).location; item->netMode = (it->second).netMode; item->vs_disc = (it->second).vs_disc; @@ -1643,8 +1644,8 @@ bool p3PeerMgrIMPL::loadList(std::list& load) RsPeerNetItem *pitem = dynamic_cast(*it); if (pitem) { - RsPeerId peer_id(pitem->pid) ; - RsPgpId peer_pgp_id(pitem->gpg_id) ; + RsPeerId peer_id = pitem->peerId ; + RsPgpId peer_pgp_id = pitem->pgpId ; if (peer_id == ownId) { @@ -1669,7 +1670,7 @@ bool p3PeerMgrIMPL::loadList(std::list& load) #endif /* ************* */ addFriend(peer_id, peer_pgp_id, pitem->netMode, pitem->vs_disc, pitem->vs_dht, pitem->lastContact, RS_SERVICE_PERM_ALL); - setLocation(RsPeerId(pitem->pid), pitem->location); + setLocation(pitem->peerId, pitem->location); } if (pitem->netMode == RS_NET_MODE_HIDDEN) @@ -2044,15 +2045,15 @@ bool p3PeerMgrIMPL::assignPeersToGroup(const std::string &groupId, const std::li std::list::const_iterator peerIt; for (peerIt = peerIds.begin(); peerIt != peerIds.end(); peerIt++) { - std::list::iterator peerIt1 = std::find(groupItem->peerIds.begin(), groupItem->peerIds.end(), *peerIt); + std::list::iterator peerIt1 = std::find(groupItem->pgpList.ids.begin(), groupItem->pgpList.ids.end(), *peerIt); if (assign) { - if (peerIt1 == groupItem->peerIds.end()) { - groupItem->peerIds.push_back(*peerIt); + if (peerIt1 == groupItem->pgpList.ids.end()) { + groupItem->pgpList.ids.push_back(*peerIt); changed = true; } } else { - if (peerIt1 != groupItem->peerIds.end()) { - groupItem->peerIds.erase(peerIt1); + if (peerIt1 != groupItem->pgpList.ids.end()) { + groupItem->pgpList.ids.erase(peerIt1); changed = true; } } diff --git a/libretroshare/src/retroshare/rsidentity.h b/libretroshare/src/retroshare/rsidentity.h index 6febd7382..58857aa28 100644 --- a/libretroshare/src/retroshare/rsidentity.h +++ b/libretroshare/src/retroshare/rsidentity.h @@ -96,8 +96,10 @@ class RsGxsIdGroup // Actually PgpIdHash is SHA1(.mMeta.mGroupId + PGPHandler->GpgFingerprint(ownId)) // ??? 160 bits. - std::string mPgpIdHash; - std::string mPgpIdSign; // Need a signature as proof - otherwise anyone could add others Hashes. + Sha1CheckSum mPgpIdHash; + // Need a signature as proof - otherwise anyone could add others Hashes. + // This is a string, as the length is variable. + std::string mPgpIdSign; // Recognition Strings. MAX# defined above. std::list mRecognTags; diff --git a/libretroshare/src/serialiser/rsconfigitems.cc b/libretroshare/src/serialiser/rsconfigitems.cc index 243fec14f..c65fd8b2a 100644 --- a/libretroshare/src/serialiser/rsconfigitems.cc +++ b/libretroshare/src/serialiser/rsconfigitems.cc @@ -775,8 +775,8 @@ RsPeerNetItem::~RsPeerNetItem() void RsPeerNetItem::clear() { - pid.clear(); - gpg_id.clear(); + peerId.clear(); + pgpId.clear(); location.clear(); netMode = 0; vs_disc = 0; @@ -803,10 +803,10 @@ std::ostream &RsPeerNetItem::print(std::ostream &out, uint16_t indent) uint16_t int_Indent = indent + 2; printIndent(out, int_Indent); - out << "PeerId: " << pid << std::endl; + out << "PeerId: " << peerId.toStdString() << std::endl; printIndent(out, int_Indent); - out << "GPGid: " << gpg_id << std::endl; + out << "PgpId: " << pgpId.toStdString() << std::endl; printIndent(out, int_Indent); out << "location: " << location << std::endl; @@ -845,6 +845,9 @@ std::ostream &RsPeerNetItem::print(std::ostream &out, uint16_t indent) localAddrList.print(out, int_Indent); extAddrList.print(out, int_Indent); + printIndent(out, int_Indent); + out << "DomainAddr: " << domain_addr; + out << ":" << domain_port << std::endl; printRsItemEnd(out, "RsPeerNetItem", indent); return out; } @@ -854,8 +857,8 @@ std::ostream &RsPeerNetItem::print(std::ostream &out, uint16_t indent) uint32_t RsPeerConfigSerialiser::sizeNet(RsPeerNetItem *i) { uint32_t s = 8; /* header */ - s += GetTlvStringSize(i->pid); /* peerid */ - s += GetTlvStringSize(i->gpg_id); + s += RsPeerId::SIZE_IN_BYTES; + s += RsPgpId::SIZE_IN_BYTES; s += GetTlvStringSize(i->location); s += 4; /* netMode */ s += 2; /* vs_disc */ @@ -914,19 +917,18 @@ bool RsPeerConfigSerialiser::serialiseNet(RsPeerNetItem *item, void *data, uint3 offset += 8; /* add mandatory parts first */ - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_PEERID, item->pid); /* Mandatory */ - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_GPGID, item->gpg_id); /* Mandatory */ + ok &= item->peerId.serialise(data, tlvsize, offset); + ok &= item->pgpId.serialise(data, tlvsize, offset); ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_LOCATION, item->location); /* Mandatory */ ok &= setRawUInt32(data, tlvsize, &offset, item->netMode); /* Mandatory */ ok &= setRawUInt16(data, tlvsize, &offset, item->vs_disc); /* Mandatory */ ok &= setRawUInt16(data, tlvsize, &offset, item->vs_dht); /* Mandatory */ ok &= setRawUInt32(data, tlvsize, &offset, item->lastContact); /* Mandatory */ - ok &= item->localAddrV4.SetTlv(data, tlvsize, &offset); ok &= item->extAddrV4.SetTlv(data, tlvsize, &offset); ok &= item->localAddrV6.SetTlv(data, tlvsize, &offset); ok &= item->extAddrV6.SetTlv(data, tlvsize, &offset); - + ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_DYNDNS, item->dyndns); ok &= item->localAddrList.SetTlv(data, tlvsize, &offset); @@ -938,10 +940,10 @@ bool RsPeerConfigSerialiser::serialiseNet(RsPeerNetItem *item, void *data, uint3 if(offset != tlvsize) { - ok = false; #ifdef RSSERIAL_ERROR_DEBUG std::cerr << "RsPeerConfigSerialiser::serialiseNet() Size Error! " << std::endl; #endif + ok = false; } return ok; @@ -992,8 +994,8 @@ RsPeerNetItem *RsPeerConfigSerialiser::deserialiseNet(void *data, uint32_t *size offset += 8; /* get mandatory parts first */ - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_PEERID, item->pid); /* Mandatory */ - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_GPGID, item->gpg_id); /* Mandatory */ + ok &= item->peerId.deserialise(data, rssize, offset); + ok &= item->pgpId.deserialise(data, rssize, offset); ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_LOCATION, item->location); /* Mandatory */ ok &= getRawUInt32(data, rssize, &offset, &(item->netMode)); /* Mandatory */ ok &= getRawUInt16(data, rssize, &offset, &(item->vs_disc)); /* Mandatory */ @@ -1009,14 +1011,6 @@ RsPeerNetItem *RsPeerConfigSerialiser::deserialiseNet(void *data, uint32_t *size ok &= item->localAddrList.GetTlv(data, rssize, &offset); ok &= item->extAddrList.GetTlv(data, rssize, &offset); - // Allow acceptance of old format. - if (offset == rssize) - { - std::cerr << "RsPeerConfigSerialiser::deserialiseNet() Accepting Old format PeerNetItem" << std::endl; - return item; - } - - // New for V0.6. ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_DOMADDR, item->domain_addr); ok &= getRawUInt16(data, rssize, &offset, &(item->domain_port)); /* Mandatory */ @@ -1167,7 +1161,7 @@ void RsPeerGroupItem::clear() id.clear(); name.clear(); flag = 0; - peerIds.clear(); + pgpList.ids.clear(); } std::ostream &RsPeerGroupItem::print(std::ostream &out, uint16_t indent) @@ -1185,9 +1179,9 @@ std::ostream &RsPeerGroupItem::print(std::ostream &out, uint16_t indent) out << "groupFlag: " << flag << std::endl; std::list::iterator it; - for (it = peerIds.begin(); it != peerIds.end(); it++) { + for (it = pgpList.ids.begin(); it != pgpList.ids.end(); it++) { printIndent(out, int_Indent); - out << "peerId: " << *it << std::endl; + out << "peerId: " << it->toStdString() << std::endl; } printRsItemEnd(out, "RsPeerGroupItem", indent); @@ -1200,7 +1194,7 @@ void RsPeerGroupItem::set(RsGroupInfo &groupInfo) id = groupInfo.id; name = groupInfo.name; flag = groupInfo.flag; - peerIds = groupInfo.peerIds; + pgpList.ids = groupInfo.peerIds; } /* get data from RsGroupInfo to RsPeerGroupItem */ @@ -1209,7 +1203,7 @@ void RsPeerGroupItem::get(RsGroupInfo &groupInfo) groupInfo.id = id; groupInfo.name = name; groupInfo.flag = flag; - groupInfo.peerIds = peerIds; + groupInfo.peerIds = pgpList.ids; } /*************************************************************************/ @@ -1221,12 +1215,7 @@ uint32_t RsPeerConfigSerialiser::sizeGroup(RsPeerGroupItem *i) s += GetTlvStringSize(i->id); s += GetTlvStringSize(i->name); s += 4; /* flag */ - - std::list::iterator it; - for (it = i->peerIds.begin(); it != i->peerIds.end(); it++) { - s += RsPgpId::SIZE_IN_BYTES ; - } - + s += i->pgpList.TlvSize(); return s; } @@ -1259,11 +1248,7 @@ bool RsPeerConfigSerialiser::serialiseGroup(RsPeerGroupItem *item, void *data, u ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_KEY, item->id); ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_NAME, item->name); ok &= setRawUInt32(data, tlvsize, &offset, item->flag); - - std::list::iterator it; - for (it = item->peerIds.begin(); it != item->peerIds.end(); it++) { - ok &= (*it).serialise(data, tlvsize, offset) ; - } + ok &= item->pgpList.SetTlv(data, tlvsize, &offset); if(offset != tlvsize) { @@ -1312,13 +1297,7 @@ RsPeerGroupItem *RsPeerConfigSerialiser::deserialiseGroup(void *data, uint32_t * ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_KEY, item->id); ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_NAME, item->name); ok &= getRawUInt32(data, rssize, &offset, &(item->flag)); - - RsPgpId peerId; - while (offset != rssize) - { - ok &= peerId.deserialise(data, rssize, offset) ; - item->peerIds.push_back(peerId); - } + ok &= item->pgpList.GetTlv(data, rssize, &offset); if (offset != rssize) { @@ -1529,12 +1508,12 @@ uint32_t RsCacheConfigSerialiser::size(RsItem *i) uint32_t s = 8; // to store calculated size, initiailize with size of header - s += item->pid.serial_size(); + s += item->pid.serial_size(); s += 2; /* cachetypeid */ s += 2; /* cachesubid */ s += GetTlvStringSize(item->path); s += GetTlvStringSize(item->name); - s += item->hash.serial_size(); + s += item->hash.serial_size(); s += 8; /* size */ s += 4; /* recvd */ @@ -1566,12 +1545,12 @@ bool RsCacheConfigSerialiser::serialise(RsItem *i, void *data, uint32_t *size) /* add the mandatory parts first */ - ok &= item->pid.serialise(data, tlvsize, offset) ; + ok &= item->pid.serialise(data, tlvsize, offset) ; ok &= setRawUInt16(data, tlvsize, &offset, item->cachetypeid); ok &= setRawUInt16(data, tlvsize, &offset, item->cachesubid); ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_PATH, item->path); ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_NAME, item->name); - ok &= item->hash.serialise(data, tlvsize, offset) ; + ok &= item->hash.serialise(data, tlvsize, offset) ; ok &= setRawUInt64(data, tlvsize, &offset, item->size); ok &= setRawUInt32(data, tlvsize, &offset, item->recvd); @@ -1619,12 +1598,12 @@ RsItem *RsCacheConfigSerialiser::deserialise(void *data, uint32_t *size) /* get mandatory parts first */ - ok &= item->pid.deserialise(data, rssize, offset) ; + ok &= item->pid.deserialise(data, rssize, offset) ; ok &= getRawUInt16(data, rssize, &offset, &(item->cachetypeid)); ok &= getRawUInt16(data, rssize, &offset, &(item->cachesubid)); ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_PATH, item->path); ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_NAME, item->name); - ok &= item->hash.deserialise(data, rssize, offset) ; + ok &= item->hash.deserialise(data, rssize, offset) ; ok &= getRawUInt64(data, rssize, &offset, &(item->size)); ok &= getRawUInt32(data, rssize, &offset, &(item->recvd)); diff --git a/libretroshare/src/serialiser/rsconfigitems.h b/libretroshare/src/serialiser/rsconfigitems.h index 108e19550..4c14e1747 100644 --- a/libretroshare/src/serialiser/rsconfigitems.h +++ b/libretroshare/src/serialiser/rsconfigitems.h @@ -37,11 +37,6 @@ #include "serialiser/rstlvkeyvalue.h" #include "serialiser/rstlvaddrs.h" -#if 0 -#include "serialiser/rstlvbase.h" -#include "serialiser/rstlvtypes.h" -#endif - class RsGroupInfo; const uint8_t RS_PKT_TYPE_GENERAL_CONFIG = 0x01; @@ -79,9 +74,9 @@ virtual void clear(); std::ostream &print(std::ostream &out, uint16_t indent = 0); /* networking information */ - std::string pid; /* Mandatory */ - std::string gpg_id; /* Mandatory */ - std::string location; /* not Mandatory */ + RsPeerId peerId; /* Mandatory */ + RsPgpId pgpId; /* Mandatory */ + std::string location; /* Mandatory */ uint32_t netMode; /* Mandatory */ uint16_t vs_disc; /* Mandatory */ uint16_t vs_dht; /* Mandatory */ @@ -119,6 +114,8 @@ class RsPeerServicePermissionItem : public RsItem std::vector pgp_ids ; std::vector service_flags ; }; + + class RsPeerGroupItem : public RsItem { public: @@ -138,7 +135,7 @@ public: std::string name; uint32_t flag; - std::list peerIds; + RsTlvPgpIdSet pgpList; }; @@ -261,7 +258,7 @@ class RsFileTransfer: public RsItem RsTlvFileItem file; RsTlvPeerIdSet allPeerIds; - RsPeerId cPeerId; + RsPeerId cPeerId; uint16_t state; uint16_t in; diff --git a/libretroshare/src/serialiser/rsgxscircleitems.cc b/libretroshare/src/serialiser/rsgxscircleitems.cc index e02468759..b2d52f79f 100644 --- a/libretroshare/src/serialiser/rsgxscircleitems.cc +++ b/libretroshare/src/serialiser/rsgxscircleitems.cc @@ -121,26 +121,14 @@ bool RsGxsCircleGroupItem::convertFrom(const RsGxsCircleGroup &group) // Enforce the local rules. if (meta.mCircleType == GXS_CIRCLE_TYPE_LOCAL) { - std::list::const_iterator it = group.mLocalFriends.begin(); - - for(; it != group.mLocalFriends.end(); it++) - pgpIdSet.ids.push_back(it->toStdString()); + pgpIdSet.ids = group.mLocalFriends; } else { - std::list::const_iterator it = group.mInvitedMembers.begin(); - for(; it != group.mInvitedMembers.end(); it++) - { - gxsIdSet.ids.push_back(it->toStdString()); - } + gxsIdSet.ids = group.mInvitedMembers; } - const std::list& scl = group.mSubCircles; - - std::list::const_iterator cit = scl.begin(); - subCircleSet.ids.clear(); - for(; cit != scl.end(); cit++) - subCircleSet.ids.push_back(cit->toStdString()); + subCircleSet.ids = group.mSubCircles; return true; } @@ -151,27 +139,14 @@ bool RsGxsCircleGroupItem::convertTo(RsGxsCircleGroup &group) const // Enforce the local rules. if (meta.mCircleType == GXS_CIRCLE_TYPE_LOCAL) { - std::list::const_iterator it = pgpIdSet.ids.begin(); - for(; it != pgpIdSet.ids.end(); it++) - group.mLocalFriends.push_back(RsPgpId(*it)); - group.mInvitedMembers.clear(); + group.mLocalFriends = pgpIdSet.ids; } else { - group.mLocalFriends.clear(); - std::list::const_iterator cit = gxsIdSet.ids.begin(); - for(; cit != gxsIdSet.ids.end(); cit++) - group.mInvitedMembers.push_back((RsGxsId(*cit))); - + group.mInvitedMembers = gxsIdSet.ids; } - const std::list scs = subCircleSet.ids; - std::list::const_iterator cit = scs.begin(); - - group.mSubCircles.clear(); - - for(; cit != scs.end(); cit++) - group.mSubCircles.push_back(RsGxsCircleId(*cit)); + group.mSubCircles = subCircleSet.ids; return true; } diff --git a/libretroshare/src/serialiser/rsgxscircleitems.h b/libretroshare/src/serialiser/rsgxscircleitems.h index 644c9c7a4..4590bd62d 100644 --- a/libretroshare/src/serialiser/rsgxscircleitems.h +++ b/libretroshare/src/serialiser/rsgxscircleitems.h @@ -32,6 +32,7 @@ #include "serialiser/rsserial.h" #include "serialiser/rstlvitem.h" #include "serialiser/rstlvstring.h" +#include "serialiser/rstlvidset.h" #include "rsgxsitems.h" #include "retroshare/rsgxscircles.h" @@ -49,10 +50,13 @@ class RsGxsCircleGroupItem : public RsGxsGrpItem public: RsGxsCircleGroupItem(): RsGxsGrpItem(RS_SERVICE_GXS_TYPE_GXSCIRCLE, - RS_PKT_SUBTYPE_GXSCIRCLE_GROUP_ITEM), + RS_PKT_SUBTYPE_GXSCIRCLE_GROUP_ITEM) +#if 0 pgpIdSet(GXSCIRCLE_PGPIDSET), gxsIdSet(GXSCIRCLE_GXSIDSET), - subCircleSet(GXSCIRCLE_SUBCIRCLESET) { return;} + subCircleSet(GXSCIRCLE_SUBCIRCLESET) +#endif + { return;} virtual ~RsGxsCircleGroupItem() { return;} void clear(); @@ -62,9 +66,9 @@ public: bool convertTo(RsGxsCircleGroup &group) const; // DIFFERENT FROM OTHER ONES, as stupid serialisation otherwise. - RsTlvStringSet pgpIdSet; // For Local Groups. - RsTlvStringSet gxsIdSet; // For External Groups. - RsTlvStringSet subCircleSet; + RsTlvPgpIdSet pgpIdSet; // For Local Groups. + RsTlvGxsIdSet gxsIdSet; // For External Groups. + RsTlvGxsCircleIdSet subCircleSet; }; class RsGxsCircleMsgItem : public RsGxsMsgItem diff --git a/libretroshare/src/serialiser/rsgxsiditems.cc b/libretroshare/src/serialiser/rsgxsiditems.cc index 696dcf44a..abefb14d1 100644 --- a/libretroshare/src/serialiser/rsgxsiditems.cc +++ b/libretroshare/src/serialiser/rsgxsiditems.cc @@ -169,7 +169,7 @@ uint32_t RsGxsIdSerialiser::sizeGxsIdGroupItem(RsGxsIdGroupItem *item) const RsGxsIdGroup& group = item->group; uint32_t s = 8; // header - s += GetTlvStringSize(group.mPgpIdHash); + s += Sha1CheckSum::SIZE_IN_BYTES; s += GetTlvStringSize(group.mPgpIdSign); RsTlvStringSetRef set(TLV_TYPE_RECOGNSET, item->group.mRecognTags); @@ -203,7 +203,7 @@ bool RsGxsIdSerialiser::serialiseGxsIdGroupItem(RsGxsIdGroupItem *item, void *da offset += 8; /* GxsIdGroupItem */ - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_HASH_SHA1, item->group.mPgpIdHash); + ok &= item->group.mPgpIdHash.serialise(data, tlvsize, offset); ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_SIGN, item->group.mPgpIdSign); RsTlvStringSetRef set(TLV_TYPE_RECOGNSET, item->group.mRecognTags); @@ -263,7 +263,7 @@ RsGxsIdGroupItem* RsGxsIdSerialiser::deserialiseGxsIdGroupItem(void *data, uint3 /* skip the header */ offset += 8; - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_HASH_SHA1, item->group.mPgpIdHash); + ok &= item->group.mPgpIdHash.deserialise(data, rssize, offset); ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_SIGN, item->group.mPgpIdSign); RsTlvStringSetRef set(TLV_TYPE_RECOGNSET, item->group.mRecognTags); diff --git a/libretroshare/src/serialiser/rstlvaddrs.cc b/libretroshare/src/serialiser/rstlvaddrs.cc index 59617b53b..d3f7da87f 100644 --- a/libretroshare/src/serialiser/rstlvaddrs.cc +++ b/libretroshare/src/serialiser/rstlvaddrs.cc @@ -28,15 +28,6 @@ #include "serialiser/rstlvaddrs.h" #include "serialiser/rsbaseserial.h" -#if 0 -#include "rstlvtypes.h" -#include "util/rsprint.h" -#include -#include -#include -#endif - - /************************************* RsTlvIpAddress ************************************/ RsTlvIpAddress::RsTlvIpAddress() diff --git a/libretroshare/src/serialiser/rstlvbase.h b/libretroshare/src/serialiser/rstlvbase.h index 3d6863a8e..41a51e9ba 100644 --- a/libretroshare/src/serialiser/rstlvbase.h +++ b/libretroshare/src/serialiser/rstlvbase.h @@ -205,6 +205,7 @@ const uint16_t TLV_TYPE_HASHSET = 0x1022; const uint16_t TLV_TYPE_PGPIDSET = 0x1023; const uint16_t TLV_TYPE_RECOGNSET = 0x1024; const uint16_t TLV_TYPE_GXSIDSET = 0x1025; +const uint16_t TLV_TYPE_GXSCIRCLEIDSET= 0x1026; const uint16_t TLV_TYPE_SERVICESET = 0x1030; diff --git a/libretroshare/src/serialiser/rstlvidset.h b/libretroshare/src/serialiser/rstlvidset.h index d2f9fc27d..d0ceec718 100644 --- a/libretroshare/src/serialiser/rstlvidset.h +++ b/libretroshare/src/serialiser/rstlvidset.h @@ -60,7 +60,7 @@ template class t_RsTlvIdSet: public RsTlvItem ok = ok && SetTlvBase(data, tlvend, offset, TLV_TYPE, tlvsize); for(typename std::list::const_iterator it(ids.begin());it!=ids.end();++it) - ok = ok && (*it).serialise(data,size,*offset) ; + ok = ok && (*it).serialise(data,tlvend,*offset) ; return ok ; } @@ -90,7 +90,7 @@ template class t_RsTlvIdSet: public RsTlvItem while(*offset + ID_CLASS::SIZE_IN_BYTES <= tlvend) { ID_CLASS id ; - ok = ok && id.deserialise(data,size,*offset) ; + ok = ok && id.deserialise(data,tlvend,*offset) ; ids.push_back(id) ; } if(*offset != tlvend) @@ -115,6 +115,7 @@ typedef t_RsTlvIdSet RsTlvPeerIdSet ; typedef t_RsTlvIdSet RsTlvPgpIdSet ; typedef t_RsTlvIdSet RsTlvHashSet ; typedef t_RsTlvIdSet RsTlvGxsIdSet ; +typedef t_RsTlvIdSet RsTlvGxsCircleIdSet ; class RsTlvServiceIdSet: public RsTlvItem { diff --git a/libretroshare/src/serialiser/rstlvlist.h b/libretroshare/src/serialiser/rstlvlist.h index f4d256bf8..decd2bc6b 100644 --- a/libretroshare/src/serialiser/rstlvlist.h +++ b/libretroshare/src/serialiser/rstlvlist.h @@ -30,6 +30,8 @@ #include +#define TLV_DEBUG_LIST 1 + template class t_RsTlvList: public RsTlvItem { public: @@ -49,12 +51,18 @@ template class t_RsTlvList: public RsTlvItem virtual void TlvClear(){ mList.clear(); } virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset) const { - /* must check sizes */ uint32_t tlvsize = TlvSize(); uint32_t tlvend = *offset + tlvsize; + /* must check sizes */ if (size < tlvend) + { +#ifdef TLV_DEBUG_LIST + std::cerr << "RsTlvList::SetTlv() Not enough size"; + std::cerr << std::endl; +#endif return false; /* not enough space */ + } bool ok = true; @@ -64,15 +72,20 @@ template class t_RsTlvList: public RsTlvItem typename std::list::const_iterator it; for(it = mList.begin();it != mList.end(); ++it) { - ok &= it->SetTlv(data,tlvsize,offset) ; + ok &= it->SetTlv(data,tlvend,offset) ; } - return ok ; } virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset) { if (size < *offset + TLV_HEADER_SIZE) + { +#ifdef TLV_DEBUG_LIST + std::cerr << "RsTlvList::GetTlv() Not enough size"; + std::cerr << std::endl; +#endif return false; + } uint16_t tlvtype = GetTlvType( &(((uint8_t *) data)[*offset]) ); uint32_t tlvsize = GetTlvSize( &(((uint8_t *) data)[*offset]) ); @@ -96,7 +109,7 @@ template class t_RsTlvList: public RsTlvItem while(ok && ((*offset) + 6 < tlvend)) { TLV_CLASS item; - ok &= item.GetTlv(data,size,offset); + ok &= item.GetTlv(data,tlvend,offset); if (ok) { mList.push_back(item); diff --git a/libretroshare/src/services/p3idservice.cc b/libretroshare/src/services/p3idservice.cc index 08e53733d..15d219fac 100644 --- a/libretroshare/src/services/p3idservice.cc +++ b/libretroshare/src/services/p3idservice.cc @@ -42,12 +42,10 @@ * #define DEBUG_IDS 1 * #define DEBUG_RECOGN 1 * #define GXSID_GEN_DUMMY_DATA 1 - * #define ENABLE_PGP_SIGNATURES 1 ****/ #define DEBUG_IDS 1 #define DEBUG_RECOGN 1 -#define ENABLE_PGP_SIGNATURES 1 #define ID_REQUEST_LIST 0x0001 @@ -1984,9 +1982,7 @@ void p3IdService::CacheArbitrationDone(uint32_t mode) //const int SHA_DIGEST_LENGTH = 20; -typedef Sha1CheckSum GxsIdPgpHash; - -static void calcPGPHash(const RsGxsId &id, const PGPFingerprintType &pgp, GxsIdPgpHash &hash); +static void calcPGPHash(const RsGxsId &id, const PGPFingerprintType &pgp, Sha1CheckSum &hash); // Must Use meta. @@ -2078,7 +2074,7 @@ RsGenExchange::ServiceCreate_Return p3IdService::service_CreateGroup(RsGxsGrpIte if (item->group.mMeta.mGroupFlags & RSGXSID_GROUPFLAG_REALID) { /* create the hash */ - GxsIdPgpHash hash; + Sha1CheckSum hash; /* */ PGPFingerprintType ownFinger; @@ -2094,8 +2090,6 @@ RsGenExchange::ServiceCreate_Return p3IdService::service_CreateGroup(RsGxsGrpIte // } #endif - - if (!AuthGPG::getAuthGPG()->getKeyFingerprint(ownId,ownFinger)) { std::cerr << "p3IdService::service_CreateGroup() ERROR Own Finger is stuck"; @@ -2106,8 +2100,9 @@ RsGenExchange::ServiceCreate_Return p3IdService::service_CreateGroup(RsGxsGrpIte std::cerr << "p3IdService::service_CreateGroup() OwnFingerprint: " << ownFinger.toStdString(); std::cerr << std::endl; - calcPGPHash(RsGxsId(item->group.mMeta.mGroupId.toStdString()), ownFinger, hash); - item->group.mPgpIdHash = hash.toStdString(); + RsGxsId gxsId(item->group.mMeta.mGroupId.toStdString()); + calcPGPHash(gxsId, ownFinger, hash); + item->group.mPgpIdHash = hash; #ifdef DEBUG_IDS #endif // DEBUG_IDS @@ -2118,7 +2113,6 @@ RsGenExchange::ServiceCreate_Return p3IdService::service_CreateGroup(RsGxsGrpIte /* do signature */ -#ifdef ENABLE_PGP_SIGNATURES #define MAX_SIGN_SIZE 2048 uint8_t signarray[MAX_SIGN_SIZE]; unsigned int sign_size = MAX_SIGN_SIZE; @@ -2149,11 +2143,6 @@ RsGenExchange::ServiceCreate_Return p3IdService::service_CreateGroup(RsGxsGrpIte std::cerr << std::endl; } /* done! */ -#else - item->group.mPgpIdSign = ""; - createStatus = SERVICE_CREATE_SUCCESS; -#endif - } else { @@ -2425,15 +2414,8 @@ bool p3IdService::checkId(const RsGxsIdGroup &grp, RsPgpId &pgpId) std::cerr << std::endl; #endif // DEBUG_IDS - - if (grp.mPgpIdHash.length() != SHA_DIGEST_LENGTH * 2) - { - std::cerr << "ERROR PgpIdHash len:" << grp.mPgpIdHash.length(); - std::cerr << std::endl; - } - /* iterate through and check hash */ - GxsIdPgpHash ans(grp.mPgpIdHash); + Sha1CheckSum ans = grp.mPgpIdHash; #ifdef DEBUG_IDS std::cerr << "\tExpected Answer: " << ans.toStdString(); @@ -2445,14 +2427,12 @@ bool p3IdService::checkId(const RsGxsIdGroup &grp, RsPgpId &pgpId) std::map::iterator mit; for(mit = mPgpFingerprintMap.begin(); mit != mPgpFingerprintMap.end(); mit++) { - GxsIdPgpHash hash; + Sha1CheckSum hash; calcPGPHash(RsGxsId(grp.mMeta.mGroupId.toStdString()), mit->second, hash); if (ans == hash) { std::cerr << "p3IdService::checkId() HASH MATCH!"; std::cerr << std::endl; - -#ifdef ENABLE_PGP_SIGNATURES std::cerr << "p3IdService::checkId() Hash : " << hash.toStdString(); std::cerr << std::endl; @@ -2487,19 +2467,6 @@ bool p3IdService::checkId(const RsGxsIdGroup &grp, RsPgpId &pgpId) } std::cerr << strout; std::cerr << std::endl; - - -#else - pgpId = mit->first; - -#ifdef DEBUG_IDS - std::cerr << "p3IdService::checkId() Skipping Signature check for now... Hash Okay"; - std::cerr << std::endl; -#endif // DEBUG_IDS - - return true; -#endif - } } @@ -2549,7 +2516,7 @@ void p3IdService::getPgpIdList() } -void calcPGPHash(const RsGxsId &id, const PGPFingerprintType &pgp, GxsIdPgpHash &hash) +void calcPGPHash(const RsGxsId &id, const PGPFingerprintType &pgp, Sha1CheckSum &hash) { unsigned char signature[SHA_DIGEST_LENGTH]; /* hash id + pubkey => pgphash */ @@ -2559,7 +2526,7 @@ void calcPGPHash(const RsGxsId &id, const PGPFingerprintType &pgp, GxsIdPgpHash SHA1_Update(sha_ctx, id.toStdString().c_str(), id.toStdString().length()); // TO FIX ONE DAY. SHA1_Update(sha_ctx, pgp.toByteArray(), pgp.SIZE_IN_BYTES); SHA1_Final(signature, sha_ctx); - hash = GxsIdPgpHash(signature); + hash = Sha1CheckSum(signature); #ifdef DEBUG_IDS std::cerr << "calcPGPHash():";