2018-05-29 21:54:27 +02:00
|
|
|
/*******************************************************************************
|
|
|
|
* libretroshare/src/services: p3idservice.h *
|
|
|
|
* *
|
|
|
|
* libretroshare: retroshare core library *
|
|
|
|
* *
|
|
|
|
* Copyright 2012-2012 Robert Fernie <retroshare@lunamutt.com> *
|
|
|
|
* *
|
|
|
|
* This program is free software: you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU Lesser General Public License as *
|
|
|
|
* published by the Free Software Foundation, either version 3 of the *
|
|
|
|
* License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU Lesser General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License *
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
|
|
|
* *
|
|
|
|
*******************************************************************************/
|
2012-02-13 18:22:35 +00:00
|
|
|
#ifndef P3_IDENTITY_SERVICE_HEADER
|
|
|
|
#define P3_IDENTITY_SERVICE_HEADER
|
|
|
|
|
|
|
|
|
2012-10-21 15:48:18 +00:00
|
|
|
#include "retroshare/rsidentity.h" // External Interfaces.
|
|
|
|
#include "gxs/rsgenexchange.h" // GXS service.
|
|
|
|
#include "gxs/rsgixs.h" // Internal Interfaces.
|
2012-02-13 18:22:35 +00:00
|
|
|
|
2012-11-19 22:00:05 +00:00
|
|
|
#include "gxs/gxstokenqueue.h"
|
2017-04-26 14:28:25 +02:00
|
|
|
#include "rsitems/rsgxsiditems.h"
|
2012-11-19 22:00:05 +00:00
|
|
|
|
2012-02-13 18:22:35 +00:00
|
|
|
#include <map>
|
|
|
|
#include <string>
|
|
|
|
|
2012-11-03 13:15:21 +00:00
|
|
|
#include "util/rsmemcache.h"
|
2012-11-19 22:00:05 +00:00
|
|
|
#include "util/rstickevent.h"
|
2013-10-20 09:43:30 +00:00
|
|
|
#include "util/rsrecogn.h"
|
2012-11-03 13:15:21 +00:00
|
|
|
|
2012-11-05 22:28:08 +00:00
|
|
|
#include "pqi/authgpg.h"
|
|
|
|
|
2017-04-28 23:32:47 +02:00
|
|
|
#include "rsitems/rsgxsrecognitems.h"
|
2013-10-20 09:43:30 +00:00
|
|
|
|
2014-04-27 13:14:07 +00:00
|
|
|
class PgpAuxUtils;
|
|
|
|
|
2012-02-13 18:22:35 +00:00
|
|
|
/*
|
2012-06-07 17:10:47 +00:00
|
|
|
* Identity Service
|
2012-02-13 18:22:35 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2014-02-19 11:08:37 +00:00
|
|
|
#if 0
|
|
|
|
class GxsReputation
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
GxsReputation();
|
|
|
|
|
|
|
|
bool updateIdScore(bool pgpLinked, bool pgpKnown);
|
|
|
|
bool update(); // checks ranges and calculates overall score.
|
|
|
|
int mOverallScore;
|
|
|
|
int mIdScore; // PGP, Known, etc.
|
|
|
|
int mOwnOpinion;
|
|
|
|
int mPeerOpinion;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
class OpinionRequest
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
OpinionRequest(uint32_t token, RsGxsId id, bool absOpinion, int32_t score)
|
|
|
|
:mToken(token), mId(id), mAbsOpinion(absOpinion), mScore(score)
|
|
|
|
{ return; }
|
|
|
|
OpinionRequest()
|
|
|
|
:mToken(0), mId(), mAbsOpinion(false), mScore(0)
|
|
|
|
{ return; }
|
|
|
|
|
|
|
|
uint32_t mToken;
|
|
|
|
RsGxsId mId;
|
|
|
|
bool mAbsOpinion;
|
|
|
|
int32_t mScore;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-10-14 18:32:33 +00:00
|
|
|
// INTERNAL DATA TYPES.
|
2012-07-29 13:09:36 +00:00
|
|
|
// Describes data stored in GroupServiceString.
|
2012-11-05 22:28:08 +00:00
|
|
|
|
|
|
|
class SSBit
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual bool load(const std::string &input) = 0;
|
|
|
|
virtual std::string save() const = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SSGxsIdPgp: public SSBit
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SSGxsIdPgp()
|
2016-04-02 14:04:08 -04:00
|
|
|
:validatedSignature(false), lastCheckTs(0), checkAttempts(0) { return; }
|
2012-11-05 22:28:08 +00:00
|
|
|
|
|
|
|
virtual bool load(const std::string &input);
|
|
|
|
virtual std::string save() const;
|
|
|
|
|
2016-04-02 14:04:08 -04:00
|
|
|
bool validatedSignature;
|
2018-10-07 01:34:05 +02:00
|
|
|
rstime_t lastCheckTs;
|
2012-11-05 22:28:08 +00:00
|
|
|
uint32_t checkAttempts;
|
2014-03-17 20:56:06 +00:00
|
|
|
RsPgpId pgpId;
|
2012-11-05 22:28:08 +00:00
|
|
|
};
|
|
|
|
|
2013-10-20 09:43:30 +00:00
|
|
|
class SSGxsIdRecognTags: public SSBit
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SSGxsIdRecognTags()
|
|
|
|
:tagFlags(0), publishTs(0), lastCheckTs(0) { return; }
|
|
|
|
|
|
|
|
virtual bool load(const std::string &input);
|
|
|
|
virtual std::string save() const;
|
|
|
|
|
|
|
|
void setTags(bool processed, bool pending, uint32_t flags);
|
|
|
|
|
|
|
|
bool tagsProcessed() const; // have we processed?
|
|
|
|
bool tagsPending() const; // should we reprocess?
|
|
|
|
bool tagValid(int i) const;
|
|
|
|
|
2014-01-20 11:42:27 +00:00
|
|
|
uint32_t tagFlags;
|
2018-10-07 01:34:05 +02:00
|
|
|
rstime_t publishTs;
|
|
|
|
rstime_t lastCheckTs;
|
2013-10-20 09:43:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-02-19 11:08:37 +00:00
|
|
|
class SSGxsIdReputation: public SSBit
|
2012-11-05 22:28:08 +00:00
|
|
|
{
|
|
|
|
public:
|
2014-02-19 11:08:37 +00:00
|
|
|
SSGxsIdReputation()
|
|
|
|
:rep() { return; }
|
2012-11-05 22:28:08 +00:00
|
|
|
|
|
|
|
virtual bool load(const std::string &input);
|
|
|
|
virtual std::string save() const;
|
|
|
|
|
2014-02-19 11:08:37 +00:00
|
|
|
GxsReputation rep;
|
2012-11-05 22:28:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class SSGxsIdCumulator: public SSBit
|
2012-07-29 13:09:36 +00:00
|
|
|
{
|
|
|
|
public:
|
2012-11-05 22:28:08 +00:00
|
|
|
SSGxsIdCumulator()
|
|
|
|
:count(0), nullcount(0), sum(0), sumsq(0) { return; }
|
|
|
|
|
|
|
|
virtual bool load(const std::string &input);
|
|
|
|
virtual std::string save() const;
|
|
|
|
|
2012-07-29 13:09:36 +00:00
|
|
|
uint32_t count;
|
|
|
|
uint32_t nullcount;
|
|
|
|
double sum;
|
|
|
|
double sumsq;
|
|
|
|
|
|
|
|
// derived parameters:
|
|
|
|
};
|
|
|
|
|
2012-11-05 22:28:08 +00:00
|
|
|
class SSGxsIdGroup: public SSBit
|
2012-07-29 13:09:36 +00:00
|
|
|
{
|
|
|
|
public:
|
2012-11-05 22:28:08 +00:00
|
|
|
SSGxsIdGroup() { return; }
|
|
|
|
|
|
|
|
virtual bool load(const std::string &input);
|
|
|
|
virtual std::string save() const;
|
|
|
|
|
|
|
|
// pgphash status
|
|
|
|
SSGxsIdPgp pgp;
|
|
|
|
|
2013-10-20 09:43:30 +00:00
|
|
|
// recogTags.
|
|
|
|
SSGxsIdRecognTags recogntags;
|
|
|
|
|
2012-11-05 22:28:08 +00:00
|
|
|
// reputation score.
|
2014-02-19 11:08:37 +00:00
|
|
|
SSGxsIdReputation score;
|
|
|
|
|
|
|
|
// These are depreciated (will load, but not save)
|
2012-11-05 22:28:08 +00:00
|
|
|
SSGxsIdCumulator opinion;
|
|
|
|
SSGxsIdCumulator reputation;
|
2013-10-20 09:43:30 +00:00
|
|
|
|
2012-07-29 13:09:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#define ID_LOCAL_STATUS_FULL_CALC_FLAG 0x00010000
|
|
|
|
#define ID_LOCAL_STATUS_INC_CALC_FLAG 0x00020000
|
|
|
|
|
2012-10-22 20:36:28 +00:00
|
|
|
class RsGxsIdGroupItem;
|
|
|
|
|
2016-06-04 21:39:40 -04:00
|
|
|
class RsGxsIdCache
|
2012-10-21 19:15:46 +00:00
|
|
|
{
|
2016-06-02 23:47:57 -04:00
|
|
|
public:
|
|
|
|
RsGxsIdCache();
|
|
|
|
|
2016-06-04 21:39:40 -04:00
|
|
|
RsGxsIdCache(const RsGxsIdGroupItem *item, const RsTlvPublicRSAKey& in_pkey, const RsTlvPrivateRSAKey& privkey, const std::list<RsRecognTag> &tagList);
|
|
|
|
RsGxsIdCache(const RsGxsIdGroupItem *item, const RsTlvPublicRSAKey& in_pkey, const std::list<RsRecognTag> &tagList);
|
2016-06-02 23:47:57 -04:00
|
|
|
|
|
|
|
void updateServiceString(std::string serviceString);
|
2012-10-21 19:15:46 +00:00
|
|
|
|
2018-10-07 01:34:05 +02:00
|
|
|
rstime_t mPublishTs;
|
2016-06-02 23:47:57 -04:00
|
|
|
std::list<RsRecognTag> mRecognTags; // Only partially validated.
|
2013-10-20 09:43:30 +00:00
|
|
|
|
2016-06-02 23:47:57 -04:00
|
|
|
RsIdentityDetails details;
|
2016-06-04 21:39:40 -04:00
|
|
|
|
|
|
|
RsTlvPublicRSAKey pub_key;
|
|
|
|
RsTlvPrivateRSAKey priv_key;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void init(const RsGxsIdGroupItem *item, const RsTlvPublicRSAKey& in_pub_key, const RsTlvPrivateRSAKey& in_priv_key,const std::list<RsRecognTag> &tagList);
|
2012-10-21 19:15:46 +00:00
|
|
|
};
|
|
|
|
|
2017-04-08 19:07:33 +02:00
|
|
|
struct SerialisedIdentityStruct
|
|
|
|
{
|
|
|
|
unsigned char *mMem ;
|
|
|
|
uint32_t mSize ;
|
2018-10-07 01:34:05 +02:00
|
|
|
rstime_t mLastUsageTS;
|
2017-04-08 19:07:33 +02:00
|
|
|
};
|
|
|
|
|
2019-02-13 17:08:38 -03:00
|
|
|
// We cache all identities, and provide alternative (instantaneous)
|
|
|
|
// functions to extract info, rather than the horrible Token system.
|
2015-03-14 14:33:23 +00:00
|
|
|
class p3IdService: public RsGxsIdExchange, public RsIdentity, public GxsTokenQueue, public RsTickEvent, public p3Config
|
2012-10-14 18:32:33 +00:00
|
|
|
{
|
2016-07-03 18:59:30 -04:00
|
|
|
public:
|
2014-04-27 13:14:07 +00:00
|
|
|
p3IdService(RsGeneralDataService* gds, RsNetworkExchangeService* nes, PgpAuxUtils *pgpUtils);
|
2014-03-22 03:53:44 +00:00
|
|
|
|
2016-07-03 18:59:30 -04:00
|
|
|
virtual RsServiceInfo getServiceInfo();
|
|
|
|
static uint32_t idAuthenPolicy();
|
2012-11-19 22:00:05 +00:00
|
|
|
|
2012-10-28 23:13:15 +00:00
|
|
|
virtual void service_tick(); // needed for background processing.
|
2012-06-07 17:10:47 +00:00
|
|
|
|
2012-06-14 00:27:28 +00:00
|
|
|
|
2016-07-03 18:59:30 -04:00
|
|
|
/*!
|
|
|
|
* Design hack, id service must be constructed first as it
|
|
|
|
* is need for construction of subsequent net services
|
|
|
|
*/
|
|
|
|
void setNes(RsNetworkExchangeService* nes);
|
2013-11-04 14:09:32 +00:00
|
|
|
|
2012-10-14 18:32:33 +00:00
|
|
|
/* General Interface is provided by RsIdentity / RsGxsIfaceImpl. */
|
2012-06-14 00:27:28 +00:00
|
|
|
|
2012-10-14 18:32:33 +00:00
|
|
|
/* Data Specific Interface */
|
2012-06-14 00:27:28 +00:00
|
|
|
|
2019-02-13 17:08:38 -03:00
|
|
|
/// @see RsIdentity
|
|
|
|
bool getIdentitiesInfo(const std::set<RsGxsId>& ids,
|
|
|
|
std::vector<RsGxsIdGroup>& idsInfo ) override;
|
|
|
|
|
|
|
|
/// @see RsIdentity
|
|
|
|
bool getIdentitiesSummaries(std::list<RsGroupMetaData>& ids) override;
|
|
|
|
|
2012-10-21 15:48:18 +00:00
|
|
|
// These are exposed via RsIdentity.
|
2016-07-03 18:59:30 -04:00
|
|
|
virtual bool getGroupData(const uint32_t &token, std::vector<RsGxsIdGroup> &groups);
|
2017-04-10 20:02:14 +02:00
|
|
|
virtual bool getGroupSerializedData(const uint32_t &token, std::map<RsGxsId,std::string>& serialized_groups);
|
|
|
|
|
2016-07-03 18:59:30 -04:00
|
|
|
//virtual bool getMsgData(const uint32_t &token, std::vector<RsGxsIdOpinion> &opinions);
|
2012-06-14 00:27:28 +00:00
|
|
|
|
2012-10-21 15:48:18 +00:00
|
|
|
// These are local - and not exposed via RsIdentity.
|
2016-07-03 18:59:30 -04:00
|
|
|
virtual bool createGroup(uint32_t& token, RsGxsIdGroup &group);
|
|
|
|
virtual bool updateGroup(uint32_t& token, RsGxsIdGroup &group);
|
2019-02-13 17:08:38 -03:00
|
|
|
virtual bool deleteGroup(uint32_t& token, RsGxsGroupId& group);
|
2016-07-03 18:59:30 -04:00
|
|
|
//virtual bool createMsg(uint32_t& token, RsGxsIdOpinion &opinion);
|
2012-06-14 00:27:28 +00:00
|
|
|
|
2012-10-18 00:28:54 +00:00
|
|
|
/**************** RsIdentity External Interface.
|
|
|
|
* Notes:
|
2012-11-19 22:00:05 +00:00
|
|
|
*
|
|
|
|
* All the data is cached together for the moment - We should probably
|
|
|
|
* seperate and sort this out.
|
|
|
|
*
|
|
|
|
* Also need to handle Cache updates / invalidation from internal changes.
|
|
|
|
*
|
2012-10-18 00:28:54 +00:00
|
|
|
*/
|
2016-07-03 18:59:30 -04:00
|
|
|
//virtual bool getNickname(const RsGxsId &id, std::string &nickname);
|
|
|
|
virtual bool getIdDetails(const RsGxsId &id, RsIdentityDetails &details);
|
2012-11-19 22:00:05 +00:00
|
|
|
|
2019-02-13 17:08:38 -03:00
|
|
|
RS_DEPRECATED_FOR(RsReputations)
|
2016-07-03 18:59:30 -04:00
|
|
|
virtual bool submitOpinion(uint32_t& token, const RsGxsId &id,
|
|
|
|
bool absOpinion, int score);
|
2019-02-13 17:08:38 -03:00
|
|
|
|
|
|
|
/// @see RsIdentity
|
|
|
|
virtual bool createIdentity(
|
|
|
|
RsGxsId& id,
|
|
|
|
const std::string& name, const RsGxsImage& avatar = RsGxsImage(),
|
|
|
|
bool pseudonimous = true, const std::string& pgpPassword = "" ) override;
|
|
|
|
|
2016-07-03 18:59:30 -04:00
|
|
|
virtual bool createIdentity(uint32_t& token, RsIdentityParameters ¶ms);
|
2012-10-18 00:28:54 +00:00
|
|
|
|
2019-02-13 17:08:38 -03:00
|
|
|
/// @see RsIdentity
|
|
|
|
bool updateIdentity(RsGxsIdGroup& identityData) override;
|
|
|
|
|
|
|
|
RS_DEPRECATED
|
2016-07-03 18:59:30 -04:00
|
|
|
virtual bool updateIdentity(uint32_t& token, RsGxsIdGroup &group);
|
2019-02-13 17:08:38 -03:00
|
|
|
|
|
|
|
/// @see RsIdentity
|
|
|
|
bool deleteIdentity(RsGxsId& id) override;
|
|
|
|
|
|
|
|
RS_DEPRECATED
|
2016-07-03 18:59:30 -04:00
|
|
|
virtual bool deleteIdentity(uint32_t& token, RsGxsIdGroup &group);
|
2013-10-20 09:43:30 +00:00
|
|
|
|
2017-01-12 20:39:49 +01:00
|
|
|
virtual void setDeleteBannedNodesThreshold(uint32_t days) ;
|
|
|
|
virtual uint32_t deleteBannedNodesThreshold() ;
|
|
|
|
|
2016-07-03 18:59:30 -04:00
|
|
|
virtual bool parseRecognTag(const RsGxsId &id, const std::string &nickname,
|
|
|
|
const std::string &tag, RsRecognTagDetails &details);
|
|
|
|
virtual bool getRecognTagRequest(const RsGxsId &id, const std::string &comment,
|
|
|
|
uint16_t tag_class, uint16_t tag_type, std::string &tag);
|
2013-10-20 09:43:30 +00:00
|
|
|
|
2018-12-24 10:13:27 +01:00
|
|
|
virtual bool setAsRegularContact(const RsGxsId& id,bool is_a_contact) override;
|
|
|
|
virtual bool isARegularContact(const RsGxsId& id) override;
|
|
|
|
virtual void setAutoAddFriendIdsAsContact(bool b) override;
|
|
|
|
virtual bool autoAddFriendIdsAsContact() override;
|
|
|
|
|
2018-10-03 15:25:53 +02:00
|
|
|
virtual uint32_t nbRegularContacts() ;
|
2018-10-07 01:34:05 +02:00
|
|
|
virtual rstime_t getLastUsageTS(const RsGxsId &id) ;
|
2012-10-18 00:28:54 +00:00
|
|
|
|
2016-07-03 18:59:30 -04:00
|
|
|
/**************** RsGixs Implementation ***************/
|
2012-11-03 11:57:27 +00:00
|
|
|
|
2019-02-13 17:08:38 -03:00
|
|
|
/// @see RsIdentity
|
|
|
|
bool getOwnSignedIds(std::vector<RsGxsId> ids) override;
|
|
|
|
|
|
|
|
/// @see RsIdentity
|
|
|
|
bool getOwnPseudonimousIds(std::vector<RsGxsId> ids) override;
|
|
|
|
|
2018-09-06 21:15:25 +02:00
|
|
|
virtual bool getOwnIds(std::list<RsGxsId> &ownIds, bool signed_only = false);
|
2012-06-14 00:27:28 +00:00
|
|
|
|
2016-07-03 18:59:30 -04:00
|
|
|
//virtual bool getPublicKey(const RsGxsId &id, RsTlvSecurityKey &key) ;
|
|
|
|
//virtual void networkRequestPublicKey(const RsGxsId& key_id,const std::list<RsPeerId>& peer_ids) ;
|
2015-03-14 14:33:23 +00:00
|
|
|
|
2016-07-03 18:59:30 -04:00
|
|
|
virtual bool isOwnId(const RsGxsId& key_id) ;
|
2015-03-14 14:33:23 +00:00
|
|
|
|
2017-01-30 15:18:12 +01:00
|
|
|
virtual bool signData( const uint8_t* data,
|
|
|
|
uint32_t data_size,
|
|
|
|
const RsGxsId& signer_id,
|
|
|
|
RsTlvKeySignature& signature,
|
|
|
|
uint32_t& signing_error);
|
|
|
|
|
|
|
|
virtual bool validateData( const uint8_t *data, uint32_t data_size,
|
|
|
|
const RsTlvKeySignature& signature,
|
|
|
|
bool force_load, const RsIdentityUsage &info,
|
|
|
|
uint32_t& signing_error );
|
|
|
|
|
|
|
|
virtual bool encryptData( const uint8_t* decrypted_data,
|
|
|
|
uint32_t decrypted_data_size,
|
|
|
|
uint8_t*& encrypted_data,
|
|
|
|
uint32_t& encrypted_data_size,
|
|
|
|
const RsGxsId& encryption_key_id,
|
2017-01-31 20:14:17 +01:00
|
|
|
uint32_t& error_status,
|
|
|
|
bool force_load = true );
|
2017-01-30 15:18:12 +01:00
|
|
|
|
|
|
|
bool encryptData( const uint8_t* decrypted_data,
|
|
|
|
uint32_t decrypted_data_size,
|
|
|
|
uint8_t*& encrypted_data,
|
|
|
|
uint32_t& encrypted_data_size,
|
|
|
|
const std::set<RsGxsId>& encrypt_ids,
|
2017-01-31 20:14:17 +01:00
|
|
|
uint32_t& error_status, bool force_loa = true );
|
2017-01-30 15:18:12 +01:00
|
|
|
|
|
|
|
virtual bool decryptData( const uint8_t* encrypted_data,
|
|
|
|
uint32_t encrypted_data_size,
|
|
|
|
uint8_t*& decrypted_data,
|
|
|
|
uint32_t& decrypted_data_size,
|
2017-01-31 20:14:17 +01:00
|
|
|
const RsGxsId& decryption_key_id,
|
|
|
|
uint32_t& error_status,
|
|
|
|
bool force_load = true );
|
|
|
|
|
|
|
|
virtual bool decryptData(const uint8_t* encrypted_data,
|
|
|
|
uint32_t encrypted_data_size,
|
|
|
|
uint8_t*& decrypted_data,
|
|
|
|
uint32_t& decrypted_data_size,
|
|
|
|
const std::set<RsGxsId>& decrypt_ids,
|
|
|
|
uint32_t& error_status,
|
|
|
|
bool force_load = true );
|
|
|
|
|
2015-03-14 14:33:23 +00:00
|
|
|
|
2016-07-03 18:59:30 -04:00
|
|
|
virtual bool haveKey(const RsGxsId &id);
|
|
|
|
virtual bool havePrivateKey(const RsGxsId &id);
|
2015-03-14 14:33:23 +00:00
|
|
|
|
2016-07-03 18:59:30 -04:00
|
|
|
virtual bool getKey(const RsGxsId &id, RsTlvPublicRSAKey &key);
|
|
|
|
virtual bool getPrivateKey(const RsGxsId &id, RsTlvPrivateRSAKey &key);
|
2015-03-14 14:33:23 +00:00
|
|
|
|
2017-01-30 15:18:12 +01:00
|
|
|
virtual bool requestKey( const RsGxsId &id,
|
|
|
|
const std::list<RsPeerId> &peers,
|
|
|
|
const RsIdentityUsage &use_info );
|
2016-07-03 18:59:30 -04:00
|
|
|
virtual bool requestPrivateKey(const RsGxsId &id);
|
2015-03-14 14:33:23 +00:00
|
|
|
|
2019-02-13 17:08:38 -03:00
|
|
|
|
|
|
|
/// @see RsIdentity
|
|
|
|
bool identityToBase64( const RsGxsId& id,
|
|
|
|
std::string& base64String ) override;
|
|
|
|
|
|
|
|
/// @see RsIdentity
|
|
|
|
bool identityFromBase64( const std::string& base64String,
|
|
|
|
RsGxsId& id ) override;
|
|
|
|
|
2017-04-19 23:48:25 +02:00
|
|
|
virtual bool serialiseIdentityToMemory(const RsGxsId& id,
|
|
|
|
std::string& radix_string);
|
|
|
|
virtual bool deserialiseIdentityFromMemory(const std::string& radix_string,
|
|
|
|
RsGxsId* id = nullptr);
|
2012-06-14 00:27:28 +00:00
|
|
|
|
2016-07-03 18:59:30 -04:00
|
|
|
/**************** RsGixsReputation Implementation ****************/
|
2012-06-14 00:27:28 +00:00
|
|
|
|
2016-07-03 18:59:30 -04:00
|
|
|
// get Reputation.
|
2017-01-10 21:44:37 +01:00
|
|
|
#ifdef TO_BE_REMOVED
|
2016-07-03 18:59:30 -04:00
|
|
|
virtual bool haveReputation(const RsGxsId &id);
|
|
|
|
virtual bool loadReputation(const RsGxsId &id, const std::list<RsPeerId>& peers);
|
|
|
|
virtual bool getReputation(const RsGxsId &id, GixsReputation &rep);
|
2017-01-10 21:44:37 +01:00
|
|
|
#endif
|
2012-10-28 23:13:15 +00:00
|
|
|
|
2016-07-03 18:59:30 -04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
/** Notifications **/
|
|
|
|
virtual void notifyChanges(std::vector<RsGxsNotify*>& changes);
|
2012-11-05 22:28:08 +00:00
|
|
|
|
|
|
|
/** Overloaded to add PgpIdHash to Group Definition **/
|
2016-07-03 18:59:30 -04:00
|
|
|
virtual ServiceCreate_Return service_CreateGroup(RsGxsGrpItem* grpItem, RsTlvSecurityKeySet& keySet);
|
2012-10-28 23:13:15 +00:00
|
|
|
|
2016-08-04 13:12:55 +02:00
|
|
|
// Overloads RsGxsGenExchange
|
|
|
|
virtual bool acceptNewGroup(const RsGxsGrpMetaData *grpMeta) ;
|
|
|
|
|
|
|
|
// Overloaded from GxsTokenQueue for Request callbacks.
|
2016-07-03 18:59:30 -04:00
|
|
|
virtual void handleResponse(uint32_t token, uint32_t req_type);
|
2012-11-29 22:48:28 +00:00
|
|
|
|
2016-07-03 18:59:30 -04:00
|
|
|
// Overloaded from RsTickEvent.
|
|
|
|
virtual void handle_event(uint32_t event_type, const std::string &elabel);
|
2012-11-29 22:48:28 +00:00
|
|
|
|
2016-07-03 18:59:30 -04:00
|
|
|
//===================================================//
|
|
|
|
// p3Config methods //
|
|
|
|
//===================================================//
|
2015-03-14 14:33:23 +00:00
|
|
|
|
2016-07-03 18:59:30 -04:00
|
|
|
// Load/save the routing info, the pending items in transit, and the config variables.
|
|
|
|
//
|
|
|
|
virtual bool loadList(std::list<RsItem*>& items) ;
|
|
|
|
virtual bool saveList(bool& cleanup,std::list<RsItem*>& items) ;
|
2015-03-14 14:33:23 +00:00
|
|
|
|
2016-07-03 18:59:30 -04:00
|
|
|
virtual RsSerialiser *setupSerialiser() ;
|
2015-03-14 14:33:23 +00:00
|
|
|
|
|
|
|
|
2016-07-03 18:59:30 -04:00
|
|
|
private:
|
2012-06-07 17:10:47 +00:00
|
|
|
|
2016-07-03 18:59:30 -04:00
|
|
|
/************************************************************************
|
2012-10-21 19:15:46 +00:00
|
|
|
* This is the Cache for minimising calls to the DataStore.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
int cache_tick();
|
|
|
|
|
2016-07-15 16:59:57 -04:00
|
|
|
bool cache_request_load(const RsGxsId &id, const std::list<RsPeerId>& peers = std::list<RsPeerId>());
|
2012-10-21 19:15:46 +00:00
|
|
|
bool cache_start_load();
|
|
|
|
bool cache_load_for_token(uint32_t token);
|
|
|
|
|
2012-11-03 14:07:26 +00:00
|
|
|
bool cache_store(const RsGxsIdGroupItem *item);
|
2012-11-19 22:00:05 +00:00
|
|
|
bool cache_update_if_cached(const RsGxsId &id, std::string serviceString);
|
|
|
|
|
2016-07-03 18:59:30 -04:00
|
|
|
bool isPendingNetworkRequest(const RsGxsId& gxsId);
|
2016-07-15 16:59:57 -04:00
|
|
|
void requestIdsFromNet();
|
2013-11-03 23:46:34 +00:00
|
|
|
|
2012-11-19 22:00:05 +00:00
|
|
|
// Mutex protected.
|
2012-10-21 19:15:46 +00:00
|
|
|
|
2013-11-03 23:46:34 +00:00
|
|
|
//std::list<RsGxsId> mCacheLoad_ToCache;
|
2014-03-17 20:56:06 +00:00
|
|
|
std::map<RsGxsId, std::list<RsPeerId> > mCacheLoad_ToCache, mPendingCache;
|
2012-10-21 19:15:46 +00:00
|
|
|
|
2012-11-03 14:07:26 +00:00
|
|
|
// Switching to RsMemCache for Key Caching.
|
2016-06-04 21:39:40 -04:00
|
|
|
RsMemCache<RsGxsId, RsGxsIdCache> mKeyCache;
|
2012-11-03 14:07:26 +00:00
|
|
|
|
2016-07-03 18:59:30 -04:00
|
|
|
/************************************************************************
|
2012-11-19 22:00:05 +00:00
|
|
|
* Refreshing own Ids.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
bool cache_request_ownids();
|
|
|
|
bool cache_load_ownids(uint32_t token);
|
|
|
|
|
|
|
|
std::list<RsGxsId> mOwnIds;
|
2018-09-06 21:15:25 +02:00
|
|
|
std::list<RsGxsId> mOwnSignedIds;
|
2012-10-21 19:15:46 +00:00
|
|
|
|
2016-07-03 18:59:30 -04:00
|
|
|
/************************************************************************
|
2012-11-03 11:57:27 +00:00
|
|
|
* Test fns for Caching.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
bool cachetest_tick();
|
|
|
|
bool cachetest_getlist();
|
2012-11-19 22:00:05 +00:00
|
|
|
bool cachetest_handlerequest(uint32_t token);
|
2012-11-06 19:18:11 +00:00
|
|
|
|
2016-07-03 18:59:30 -04:00
|
|
|
/************************************************************************
|
2012-11-06 19:18:11 +00:00
|
|
|
* for processing background tasks that use the serviceString.
|
|
|
|
* - must be mutually exclusive to avoid clashes.
|
|
|
|
*/
|
2012-11-19 22:00:05 +00:00
|
|
|
bool CacheArbitration(uint32_t mode);
|
|
|
|
void CacheArbitrationDone(uint32_t mode);
|
2012-11-06 19:18:11 +00:00
|
|
|
|
|
|
|
bool mBgSchedule_Active;
|
|
|
|
uint32_t mBgSchedule_Mode;
|
|
|
|
|
2017-04-08 19:07:33 +02:00
|
|
|
/***********************************8
|
|
|
|
* Fonction to receive and handle group serialisation to memory
|
|
|
|
*/
|
|
|
|
|
|
|
|
virtual void handle_get_serialized_grp(uint32_t token);
|
|
|
|
|
2016-07-03 18:59:30 -04:00
|
|
|
/************************************************************************
|
2012-11-05 22:28:08 +00:00
|
|
|
* pgphash processing.
|
|
|
|
*
|
|
|
|
*/
|
2012-11-06 19:18:11 +00:00
|
|
|
bool pgphash_start();
|
2012-11-19 22:00:05 +00:00
|
|
|
bool pgphash_handlerequest(uint32_t token);
|
2012-11-05 22:28:08 +00:00
|
|
|
bool pgphash_process();
|
|
|
|
|
2016-07-03 18:59:30 -04:00
|
|
|
bool checkId(const RsGxsIdGroup &grp, RsPgpId &pgp_id, bool &error);
|
2012-11-05 22:28:08 +00:00
|
|
|
void getPgpIdList();
|
|
|
|
|
2012-11-19 22:00:05 +00:00
|
|
|
/* MUTEX PROTECTED DATA (mIdMtx - maybe should use a 2nd?) */
|
2012-11-05 22:28:08 +00:00
|
|
|
|
2014-03-17 20:56:06 +00:00
|
|
|
std::map<RsPgpId, PGPFingerprintType> mPgpFingerprintMap;
|
2012-11-05 22:28:08 +00:00
|
|
|
std::list<RsGxsIdGroup> mGroupsToProcess;
|
|
|
|
|
2016-07-03 18:59:30 -04:00
|
|
|
/************************************************************************
|
2013-10-20 09:43:30 +00:00
|
|
|
* recogn processing.
|
|
|
|
*
|
|
|
|
*/
|
2013-11-05 23:33:12 +00:00
|
|
|
bool recogn_schedule();
|
2013-10-20 09:43:30 +00:00
|
|
|
bool recogn_start();
|
|
|
|
bool recogn_handlerequest(uint32_t token);
|
|
|
|
bool recogn_process();
|
|
|
|
|
|
|
|
// helper functions.
|
|
|
|
bool recogn_extract_taginfo(const RsGxsIdGroupItem *item, std::list<RsGxsRecognTagItem *> &tagItems);
|
|
|
|
bool cache_process_recogntaginfo(const RsGxsIdGroupItem *item, std::list<RsRecognTag> &tagList);
|
|
|
|
|
|
|
|
bool recogn_checktag(const RsGxsId &id, const std::string &nickname, RsGxsRecognTagItem *item, bool doSignCheck, bool &isPending);
|
|
|
|
|
|
|
|
void loadRecognKeys();
|
|
|
|
|
2014-02-19 11:08:37 +00:00
|
|
|
|
2016-07-03 18:59:30 -04:00
|
|
|
/************************************************************************
|
2014-02-19 11:08:37 +00:00
|
|
|
* opinion processing.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool opinion_handlerequest(uint32_t token);
|
|
|
|
|
|
|
|
/* MUTEX PROTECTED DATA */
|
|
|
|
std::map<uint32_t, OpinionRequest> mPendingOpinion;
|
|
|
|
|
|
|
|
|
2013-10-29 21:29:20 +00:00
|
|
|
/************************************************************************
|
|
|
|
* for getting identities that are not present
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void checkPeerForIdentities();
|
|
|
|
|
2014-04-27 13:14:07 +00:00
|
|
|
|
2013-10-20 09:43:30 +00:00
|
|
|
/* MUTEX PROTECTED DATA (mIdMtx - maybe should use a 2nd?) */
|
|
|
|
|
|
|
|
bool checkRecognSignature_locked(std::string encoded, RSA &key, std::string signature);
|
|
|
|
bool getRecognKey_locked(std::string signer, RSA &key);
|
|
|
|
|
|
|
|
std::list<RsGxsGroupId> mRecognGroupIds;
|
|
|
|
std::list<RsGxsIdGroupItem *> mRecognGroupsToProcess;
|
2014-06-12 10:28:23 +00:00
|
|
|
std::map<RsGxsId, RsGxsRecognSignerItem *> mRecognSignKeys;
|
|
|
|
std::map<RsGxsId, uint32_t> mRecognOldSignKeys;
|
2013-10-20 09:43:30 +00:00
|
|
|
|
2016-07-03 18:59:30 -04:00
|
|
|
/************************************************************************
|
2012-10-14 18:32:33 +00:00
|
|
|
* Below is the background task for processing opinions => reputations
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-07-03 18:59:30 -04:00
|
|
|
virtual void generateDummyData();
|
2012-12-01 00:16:24 +00:00
|
|
|
void generateDummy_OwnIds();
|
|
|
|
void generateDummy_FriendPGP();
|
|
|
|
void generateDummy_UnknownPGP();
|
|
|
|
void generateDummy_UnknownPseudo();
|
2012-02-13 18:22:35 +00:00
|
|
|
|
2016-07-03 18:59:30 -04:00
|
|
|
void cleanUnusedKeys() ;
|
|
|
|
void slowIndicateConfigChanged() ;
|
2015-03-14 21:46:30 +00:00
|
|
|
|
2017-01-02 15:58:37 +01:00
|
|
|
virtual void timeStampKey(const RsGxsId& id, const RsIdentityUsage& reason) ;
|
2018-10-07 01:34:05 +02:00
|
|
|
rstime_t locked_getLastUsageTS(const RsGxsId& gxs_id);
|
2015-03-14 14:33:23 +00:00
|
|
|
|
2016-07-03 18:59:30 -04:00
|
|
|
std::string genRandomId(int len = 20);
|
2012-02-13 18:22:35 +00:00
|
|
|
|
2014-02-19 11:08:37 +00:00
|
|
|
#if 0
|
2012-11-06 19:18:11 +00:00
|
|
|
bool reputation_start();
|
|
|
|
bool reputation_continue();
|
|
|
|
|
2012-07-29 13:09:36 +00:00
|
|
|
int background_tick();
|
|
|
|
bool background_checkTokenRequest();
|
|
|
|
bool background_requestGroups();
|
|
|
|
bool background_requestNewMessages();
|
|
|
|
bool background_processNewMessages();
|
|
|
|
bool background_FullCalcRequest();
|
|
|
|
bool background_processFullCalc();
|
2016-07-03 18:59:30 -04:00
|
|
|
|
2012-07-29 13:09:36 +00:00
|
|
|
bool background_cleanup();
|
2014-02-19 11:08:37 +00:00
|
|
|
#endif
|
2012-07-29 13:09:36 +00:00
|
|
|
|
2012-02-13 18:22:35 +00:00
|
|
|
RsMutex mIdMtx;
|
|
|
|
|
2014-02-19 11:08:37 +00:00
|
|
|
#if 0
|
2012-02-13 18:22:35 +00:00
|
|
|
/***** below here is locked *****/
|
2012-07-29 13:09:36 +00:00
|
|
|
bool mLastBgCheck;
|
|
|
|
bool mBgProcessing;
|
2016-07-03 18:59:30 -04:00
|
|
|
|
2012-07-29 13:09:36 +00:00
|
|
|
uint32_t mBgToken;
|
|
|
|
uint32_t mBgPhase;
|
2016-07-03 18:59:30 -04:00
|
|
|
|
2014-03-17 20:56:06 +00:00
|
|
|
std::map<RsGxsGroupId, RsGroupMetaData> mBgGroupMap;
|
|
|
|
std::list<RsGxsGroupId> mBgFullCalcGroups;
|
2014-02-19 11:08:37 +00:00
|
|
|
#endif
|
2012-02-13 18:22:35 +00:00
|
|
|
|
2016-07-03 18:59:30 -04:00
|
|
|
/************************************************************************
|
2012-10-14 18:32:33 +00:00
|
|
|
* Other Data that is protected by the Mutex.
|
|
|
|
*/
|
2012-02-13 18:22:35 +00:00
|
|
|
|
2016-07-03 18:59:30 -04:00
|
|
|
private:
|
2013-10-29 21:29:20 +00:00
|
|
|
|
2016-12-19 20:44:15 +01:00
|
|
|
struct keyTSInfo
|
|
|
|
{
|
|
|
|
keyTSInfo() : TS(0) {}
|
|
|
|
|
2018-10-07 01:34:05 +02:00
|
|
|
rstime_t TS ;
|
|
|
|
std::map<RsIdentityUsage,rstime_t> usage_map ;
|
2016-12-19 20:44:15 +01:00
|
|
|
};
|
|
|
|
friend class IdCacheEntryCleaner;
|
|
|
|
|
2013-11-03 23:46:34 +00:00
|
|
|
std::map<uint32_t, std::set<RsGxsGroupId> > mIdsPendingCache;
|
2013-10-29 21:29:20 +00:00
|
|
|
std::map<uint32_t, std::list<RsGxsGroupId> > mGroupNotPresent;
|
2015-11-19 22:58:28 -05:00
|
|
|
std::map<RsGxsId, std::list<RsPeerId> > mIdsNotPresent;
|
2016-12-19 20:44:15 +01:00
|
|
|
std::map<RsGxsId,keyTSInfo> mKeysTS ;
|
2016-07-03 18:59:30 -04:00
|
|
|
|
2017-04-08 19:07:33 +02:00
|
|
|
std::map<RsGxsId,SerialisedIdentityStruct> mSerialisedIdentities ;
|
|
|
|
|
2016-07-03 18:59:30 -04:00
|
|
|
// keep a list of regular contacts. This is useful to sort IDs, and allow some services to priviledged ids only.
|
|
|
|
std::set<RsGxsId> mContacts;
|
2013-10-29 21:29:20 +00:00
|
|
|
RsNetworkExchangeService* mNes;
|
2014-04-27 13:14:07 +00:00
|
|
|
|
|
|
|
/**************************
|
2016-07-03 18:59:30 -04:00
|
|
|
* AuxUtils provides interface to Security Function (e.g. GPGAuth(), notify etc.)
|
2014-04-27 13:14:07 +00:00
|
|
|
* without depending directly on all these classes.
|
|
|
|
*/
|
|
|
|
|
2016-07-03 18:59:30 -04:00
|
|
|
PgpAuxUtils *mPgpUtils;
|
2015-03-14 14:33:23 +00:00
|
|
|
|
2018-10-07 01:34:05 +02:00
|
|
|
rstime_t mLastKeyCleaningTime ;
|
|
|
|
rstime_t mLastConfigUpdate ;
|
2015-04-14 20:57:40 +00:00
|
|
|
|
2019-02-13 17:08:38 -03:00
|
|
|
bool mOwnIdsLoaded;
|
|
|
|
bool ownIdsAreLoaded() { RS_STACK_MUTEX(mIdMtx); return mOwnIdsLoaded; }
|
|
|
|
|
2018-12-24 10:13:27 +01:00
|
|
|
bool mAutoAddFriendsIdentitiesAsContacts;
|
2017-01-12 20:39:49 +01:00
|
|
|
uint32_t mMaxKeepKeysBanned ;
|
2012-02-13 18:22:35 +00:00
|
|
|
};
|
|
|
|
|
2012-10-14 18:32:33 +00:00
|
|
|
#endif // P3_IDENTITY_SERVICE_HEADER
|
|
|
|
|
|
|
|
|
|
|
|
|