Added PgpAuxUtils to allow Mocking of Pgp functions for simulations.

Cleaned up some of the debug messages.



git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7306 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2014-04-27 13:14:07 +00:00
parent 4fe6161d58
commit 23480be883
16 changed files with 490 additions and 94 deletions

View file

@ -29,9 +29,7 @@
#include "util/rsrandom.h"
#include "util/rsstring.h"
#include "pqi/authgpg.h"
#include <retroshare/rspeers.h>
#include "pgp/pgpauxutils.h"
#include <sstream>
#include <stdio.h>
@ -106,10 +104,13 @@ RsGxsCircles *rsGxsCircles = NULL;
/******************* Startup / Tick ******************************************/
/********************************************************************************/
p3GxsCircles::p3GxsCircles(RsGeneralDataService *gds, RsNetworkExchangeService *nes, p3IdService *identities)
p3GxsCircles::p3GxsCircles(RsGeneralDataService *gds, RsNetworkExchangeService *nes,
p3IdService *identities, PgpAuxUtils *pgpUtils)
: RsGxsCircleExchange(gds, nes, new RsGxsCircleSerialiser(),
RS_SERVICE_GXS_TYPE_GXSCIRCLE, identities, circleAuthenPolicy()),
RsGxsCircles(this), GxsTokenQueue(this), RsTickEvent(), mIdentities(identities),
RsGxsCircles(this), GxsTokenQueue(this), RsTickEvent(),
mIdentities(identities),
mPgpUtils(pgpUtils),
mCircleMtx("p3GxsCircles"),
mCircleCache(DEFAULT_MEM_CACHE_SIZE, "GxsCircleCache")
@ -1186,7 +1187,7 @@ bool p3GxsCircles::checkCircleCacheForAutoSubscribe(RsGxsCircleCache &cache)
}
/* if we appear in the group - then autosubscribe, and mark as processed */
const RsPgpId& ownId = AuthGPG::getAuthGPG()->getGPGOwnId();
const RsPgpId& ownId = mPgpUtils->getPGPOwnId();
std::map<RsPgpId, std::list<RsGxsId> >::iterator it = cache.mAllowedPeers.find(ownId);
if (it != cache.mAllowedPeers.end())
{

View file

@ -126,14 +126,14 @@ class RsGxsCircleCache
};
class PgpAuxUtils;
class p3GxsCircles: public RsGxsCircleExchange, public RsGxsCircles,
public GxsTokenQueue, public RsTickEvent
{
public:
p3GxsCircles(RsGeneralDataService* gds, RsNetworkExchangeService* nes,
p3IdService *identities);
p3IdService *identities, PgpAuxUtils *pgpUtils);
virtual RsServiceInfo getServiceInfo();
@ -196,6 +196,7 @@ virtual RsServiceInfo getServiceInfo();
p3IdService *mIdentities; // Needed for constructing Circle Info,
PgpAuxUtils *mPgpUtils;
RsMutex mCircleMtx; /* Locked Below Here */

View file

@ -24,16 +24,17 @@
*/
#include "services/p3idservice.h"
#include "pgp/pgpauxutils.h"
#include "serialiser/rsgxsiditems.h"
#include "retroshare/rsgxsflags.h"
#include "rsserver/p3face.h"
#include "util/rsrandom.h"
#include "util/rsstring.h"
#include "util/radix64.h"
#include "pqi/authgpg.h"
#include <retroshare/rspeers.h>
//#include "pqi/authgpg.h"
//#include <retroshare/rspeers.h>
#include <sstream>
#include <stdio.h>
@ -136,12 +137,13 @@ RsIdentity *rsIdentity = NULL;
/******************* Startup / Tick ******************************************/
/********************************************************************************/
p3IdService::p3IdService(RsGeneralDataService *gds, RsNetworkExchangeService *nes)
p3IdService::p3IdService(RsGeneralDataService *gds, RsNetworkExchangeService *nes, PgpAuxUtils *pgpUtils)
: RsGxsIdExchange(gds, nes, new RsGxsIdSerialiser(), RS_SERVICE_GXS_TYPE_GXSID, idAuthenPolicy()),
RsIdentity(this), GxsTokenQueue(this), RsTickEvent(),
mPublicKeyCache(DEFAULT_MEM_CACHE_SIZE, "GxsIdPublicKeyCache"),
mPrivateKeyCache(DEFAULT_MEM_CACHE_SIZE, "GxsIdPrivateKeyCache"),
mIdMtx("p3IdService"), mNes(nes)
mIdMtx("p3IdService"), mNes(nes),
mPgpUtils(pgpUtils)
{
mBgSchedule_Mode = 0;
mBgSchedule_Active = false;
@ -2078,7 +2080,7 @@ RsGenExchange::ServiceCreate_Return p3IdService::service_CreateGroup(RsGxsGrpIte
/* */
PGPFingerprintType ownFinger;
RsPgpId ownId(AuthGPG::getAuthGPG()->getGPGOwnId());
RsPgpId ownId(mPgpUtils->getPGPOwnId());
std::cerr << "p3IdService::service_CreateGroup() OwnPgpID: " << ownId.toStdString();
std::cerr << std::endl;
@ -2090,7 +2092,7 @@ RsGenExchange::ServiceCreate_Return p3IdService::service_CreateGroup(RsGxsGrpIte
// }
#endif
if (!AuthGPG::getAuthGPG()->getKeyFingerprint(ownId,ownFinger))
if (!mPgpUtils->getKeyFingerprint(ownId,ownFinger))
{
std::cerr << "p3IdService::service_CreateGroup() ERROR Own Finger is stuck";
std::cerr << std::endl;
@ -2118,7 +2120,7 @@ RsGenExchange::ServiceCreate_Return p3IdService::service_CreateGroup(RsGxsGrpIte
unsigned int sign_size = MAX_SIGN_SIZE;
int result ;
if (!RsServer::notify()->askForDeferredSelfSignature((void *) hash.toByteArray(), hash.SIZE_IN_BYTES, signarray, &sign_size,result))
if (!mPgpUtils->askForDeferredSelfSignature((void *) hash.toByteArray(), hash.SIZE_IN_BYTES, signarray, &sign_size,result))
{
/* error */
std::cerr << "p3IdService::service_CreateGroup() ERROR Signing stuff";
@ -2438,7 +2440,7 @@ bool p3IdService::checkId(const RsGxsIdGroup &grp, RsPgpId &pgpId)
/* miracle match! */
/* check signature too */
if (AuthGPG::getAuthGPG()->VerifySignBin((void *) hash.toByteArray(), hash.SIZE_IN_BYTES,
if (mPgpUtils->VerifySignBin((void *) hash.toByteArray(), hash.SIZE_IN_BYTES,
(unsigned char *) grp.mPgpIdSign.c_str(), grp.mPgpIdSign.length(),
mit->second))
{
@ -2488,7 +2490,7 @@ void p3IdService::getPgpIdList()
#endif // DEBUG_IDS
std::list<RsPgpId> list;
AuthGPG::getAuthGPG()->getGPGFilteredList(list);
mPgpUtils->getGPGAllList(list);
RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/
@ -2499,7 +2501,7 @@ void p3IdService::getPgpIdList()
{
RsPgpId pgpId(*it);
PGPFingerprintType fp;
AuthGPG::getAuthGPG()->getKeyFingerprint(pgpId, fp);
mPgpUtils->getKeyFingerprint(pgpId, fp);
#ifdef DEBUG_IDS
std::cerr << "p3IdService::getPgpIdList() Id: " << pgpId.toStdString() << " => " << fp.toStdString();
@ -2940,8 +2942,9 @@ void p3IdService::generateDummy_OwnIds()
/* grab all the gpg ids... and make some ids */
RsPgpId ownId = rsPeers->getGPGOwnId();
RsPgpId ownId = mPgpUtils->getPGPOwnId();
#if 0
// generate some ownIds.
//int genCount = 0;
int i;
@ -2967,6 +2970,7 @@ void p3IdService::generateDummy_OwnIds()
uint32_t dummyToken = 0;
createGroup(dummyToken, id);
}
#endif
}
@ -2977,7 +2981,7 @@ void p3IdService::generateDummy_FriendPGP()
// Now Generate for friends.
std::list<RsPgpId> gpgids;
std::list<RsPgpId>::const_iterator it;
rsPeers->getGPGAllList(gpgids);
mPgpUtils->getGPGAllList(gpgids);
RsGxsIdGroup id;
@ -2987,6 +2991,7 @@ void p3IdService::generateDummy_FriendPGP()
it = gpgids.begin();
for(int j = 0; j < idx; j++, it++) ;
#if 0
// HACK FOR DUMMY GENERATION.
id.mMeta.mAuthorId = RsGxsId::random() ;
@ -3006,6 +3011,7 @@ void p3IdService::generateDummy_FriendPGP()
uint32_t dummyToken = 0;
createGroup(dummyToken, id);
#endif
}

View file

@ -44,6 +44,8 @@
#include "serialiser/rsgxsrecognitems.h"
class PgpAuxUtils;
/*
* Identity Service
*
@ -215,7 +217,7 @@ class p3IdService: public RsGxsIdExchange, public RsIdentity,
public GxsTokenQueue, public RsTickEvent
{
public:
p3IdService(RsGeneralDataService* gds, RsNetworkExchangeService* nes);
p3IdService(RsGeneralDataService* gds, RsNetworkExchangeService* nes, PgpAuxUtils *pgpUtils);
virtual RsServiceInfo getServiceInfo();
static uint32_t idAuthenPolicy();
@ -415,6 +417,7 @@ virtual void handle_event(uint32_t event_type, const std::string &elabel);
*/
void checkPeerForIdentities();
/* MUTEX PROTECTED DATA (mIdMtx - maybe should use a 2nd?) */
bool checkRecognSignature_locked(std::string encoded, RSA &key, std::string signature);
@ -480,6 +483,13 @@ std::string genRandomId(int len = 20);
std::map<uint32_t, std::list<RsGxsGroupId> > mGroupNotPresent;
std::map<RsGxsId, std::list<RsPeerId> > mIdsNotPresent;
RsNetworkExchangeService* mNes;
/**************************
* AuxUtils provides interface to Security Function (e.g. GPGAuth(), notify etc.)
* without depending directly on all these classes.
*/
PgpAuxUtils *mPgpUtils;
};
#endif // P3_IDENTITY_SERVICE_HEADER