mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-02-25 09:11:28 -05:00
Merge pull request #1581 from G10h4ck/rsidentity_jsonapi
Improve rsidentity JSON API
This commit is contained in:
commit
420f5f3271
@ -23,6 +23,7 @@
|
|||||||
|
|
||||||
#include "retroshare/rsids.h"
|
#include "retroshare/rsids.h"
|
||||||
#include "retroshare/rstypes.h"
|
#include "retroshare/rstypes.h"
|
||||||
|
#include "util/rsdeprecate.h"
|
||||||
|
|
||||||
/* This is a small collection of PGP functions that are widely used in libretroshare.
|
/* This is a small collection of PGP functions that are widely used in libretroshare.
|
||||||
* This interface class allows these functions to be easily mocked for testing.
|
* This interface class allows these functions to be easily mocked for testing.
|
||||||
@ -40,6 +41,9 @@ class PgpAuxUtils
|
|||||||
|
|
||||||
virtual bool parseSignature(unsigned char *sign, unsigned int signlen, RsPgpId& issuer) const =0;
|
virtual bool parseSignature(unsigned char *sign, unsigned int signlen, RsPgpId& issuer) const =0;
|
||||||
virtual bool VerifySignBin(const void *data, uint32_t len, unsigned char *sign, unsigned int signlen, const PGPFingerprintType& withfingerprint) = 0;
|
virtual bool VerifySignBin(const void *data, uint32_t len, unsigned char *sign, unsigned int signlen, const PGPFingerprintType& withfingerprint) = 0;
|
||||||
|
|
||||||
|
/** @deprecated this method depends on retroshare-gui to work */
|
||||||
|
RS_DEPRECATED_FOR("AuthGPG::SignDataBin")
|
||||||
virtual bool askForDeferredSelfSignature(const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen,int& signature_result, std::string reason) = 0;
|
virtual bool askForDeferredSelfSignature(const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen,int& signature_result, std::string reason) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -244,14 +244,22 @@ struct RsIdentityUsage : RsSerializable
|
|||||||
CIRCLE_MEMBERSHIP_CHECK = 0x13
|
CIRCLE_MEMBERSHIP_CHECK = 0x13
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
RS_DEPRECATED
|
||||||
RsIdentityUsage( uint16_t service, const RsIdentityUsage::UsageCode& code,
|
RsIdentityUsage( uint16_t service, const RsIdentityUsage::UsageCode& code,
|
||||||
const RsGxsGroupId& gid = RsGxsGroupId(),
|
const RsGxsGroupId& gid = RsGxsGroupId(),
|
||||||
const RsGxsMessageId& mid = RsGxsMessageId(),
|
const RsGxsMessageId& mid = RsGxsMessageId(),
|
||||||
uint64_t additional_id=0,
|
uint64_t additional_id=0,
|
||||||
const std::string& comment = std::string() );
|
const std::string& comment = std::string() );
|
||||||
|
|
||||||
|
RsIdentityUsage( RsServiceType service,
|
||||||
|
RsIdentityUsage::UsageCode code,
|
||||||
|
const RsGxsGroupId& gid = RsGxsGroupId(),
|
||||||
|
const RsGxsMessageId& mid = RsGxsMessageId(),
|
||||||
|
uint64_t additional_id=0,
|
||||||
|
const std::string& comment = std::string() );
|
||||||
|
|
||||||
/// Id of the service using that identity, as understood by rsServiceControl
|
/// Id of the service using that identity, as understood by rsServiceControl
|
||||||
uint16_t mServiceId;
|
RsServiceType mServiceId;
|
||||||
|
|
||||||
/** Specific code to use. Will allow forming the correct translated message
|
/** Specific code to use. Will allow forming the correct translated message
|
||||||
* in the GUI if necessary. */
|
* in the GUI if necessary. */
|
||||||
@ -504,6 +512,14 @@ struct RsIdentity : RsGxsIfaceHelper
|
|||||||
*/
|
*/
|
||||||
virtual void setDeleteBannedNodesThreshold(uint32_t days) = 0;
|
virtual void setDeleteBannedNodesThreshold(uint32_t days) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief request details of a not yet known identity to the network
|
||||||
|
* @jsonapi{development}
|
||||||
|
* @param[in] id id of the identity to request
|
||||||
|
* @return false on error, true otherwise
|
||||||
|
*/
|
||||||
|
virtual bool requestIdentity(const RsGxsId& id) = 0;
|
||||||
|
|
||||||
|
|
||||||
RS_DEPRECATED
|
RS_DEPRECATED
|
||||||
virtual bool getGroupSerializedData(
|
virtual bool getGroupSerializedData(
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* libretroshare/src/retroshare: rsinit.h *
|
* libretroshare/src/retroshare: rsinit.h *
|
||||||
* *
|
* *
|
||||||
* libretroshare: retroshare core library *
|
* Copyright (C) 2004-2014 Robert Fernie <retroshare@lunamutt.com> *
|
||||||
* *
|
* Copyright (C) 2016-2019 Gioacchino Mazzurco <gio@altermundi.net> *
|
||||||
* Copyright 2004-2006 by Robert Fernie <retroshare@lunamutt.com> *
|
|
||||||
* *
|
* *
|
||||||
* This program is free software: you can redistribute it and/or modify *
|
* This program is free software: you can redistribute it and/or modify *
|
||||||
* it under the terms of the GNU Lesser General Public License as *
|
* it under the terms of the GNU Lesser General Public License as *
|
||||||
@ -19,8 +18,10 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
||||||
* *
|
* *
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
#ifndef RETROSHARE_INIT_INTERFACE_H
|
#pragma once
|
||||||
#define RETROSHARE_INIT_INTERFACE_H
|
|
||||||
|
/// RetroShare initialization and login API
|
||||||
|
|
||||||
|
|
||||||
// Initialize ok, result >= 0
|
// Initialize ok, result >= 0
|
||||||
#define RS_INIT_OK 0 // Initialize ok
|
#define RS_INIT_OK 0 // Initialize ok
|
||||||
@ -30,13 +31,6 @@
|
|||||||
#define RS_INIT_BASE_DIR_ERROR -2 // AuthGPG::InitAuth failed
|
#define RS_INIT_BASE_DIR_ERROR -2 // AuthGPG::InitAuth failed
|
||||||
#define RS_INIT_NO_KEYRING -3 // Keyring is empty. Need to import it.
|
#define RS_INIT_NO_KEYRING -3 // Keyring is empty. Need to import it.
|
||||||
|
|
||||||
|
|
||||||
/****
|
|
||||||
* #define RS_USE_PGPSSL 1
|
|
||||||
***/
|
|
||||||
|
|
||||||
#define RS_USE_PGPSSL 1
|
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <map>
|
#include <map>
|
||||||
@ -340,5 +334,3 @@ struct RsLoginHelper
|
|||||||
*/
|
*/
|
||||||
bool isLoggedIn();
|
bool isLoggedIn();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* libretroshare/src/retroshare: rsinit.cc *
|
* libretroshare/src/retroshare: rsinit.cc *
|
||||||
* *
|
* *
|
||||||
* libretroshare: retroshare core library *
|
* Copyright (C) 2004-2014 Robert Fernie <retroshare@lunamutt.com> *
|
||||||
* *
|
* Copyright (C) 2016-2019 Gioacchino Mazzurco <gio@altermundi.net> *
|
||||||
* Copyright 2004-2006 by Robert Fernie <retroshare@lunamutt.com> *
|
|
||||||
* *
|
* *
|
||||||
* This program is free software: you can redistribute it and/or modify *
|
* This program is free software: you can redistribute it and/or modify *
|
||||||
* it under the terms of the GNU Lesser General Public License as *
|
* it under the terms of the GNU Lesser General Public License as *
|
||||||
@ -20,8 +19,7 @@
|
|||||||
* *
|
* *
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
/* This is an updated startup class. Class variables are hidden from
|
/// RetroShare initialization and login API implementation
|
||||||
* the GUI / External via a hidden class */
|
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* libretroshare/src/services: p3idservice.cc *
|
* libretroshare/src/services: p3idservice.cc *
|
||||||
* *
|
* *
|
||||||
* libretroshare: retroshare core library *
|
* Copyright (C) 2012-2014 Robert Fernie <retroshare@lunamutt.com> *
|
||||||
* *
|
* Copyright (C) 2017-2019 Gioacchino Mazzurco <gio@altermundi.net> *
|
||||||
* Copyright 2012-2012 Robert Fernie <retroshare@lunamutt.com> *
|
|
||||||
* Copyright (C) 2018 Gioacchino Mazzurco <gio@eigenlab.org> *
|
|
||||||
* *
|
* *
|
||||||
* This program is free software: you can redistribute it and/or modify *
|
* This program is free software: you can redistribute it and/or modify *
|
||||||
* it under the terms of the GNU Lesser General Public License as *
|
* it under the terms of the GNU Lesser General Public License as *
|
||||||
@ -20,8 +18,14 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
||||||
* *
|
* *
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
|
/// RetroShare GXS identities service
|
||||||
|
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <sstream>
|
||||||
|
#include <cstdio>
|
||||||
|
|
||||||
#include "services/p3idservice.h"
|
#include "services/p3idservice.h"
|
||||||
#include "pgp/pgpauxutils.h"
|
#include "pgp/pgpauxutils.h"
|
||||||
@ -36,15 +40,9 @@
|
|||||||
#include "crypto/hashstream.h"
|
#include "crypto/hashstream.h"
|
||||||
#include "gxs/gxssecurity.h"
|
#include "gxs/gxssecurity.h"
|
||||||
#include "retroshare/rspeers.h"
|
#include "retroshare/rspeers.h"
|
||||||
|
#include "retroshare/rsnotify.h"
|
||||||
|
|
||||||
|
|
||||||
//#include "pqi/authgpg.h"
|
|
||||||
|
|
||||||
//#include <retroshare/rspeers.h>
|
|
||||||
|
|
||||||
#include <sstream>
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
/****
|
/****
|
||||||
* #define DEBUG_IDS 1
|
* #define DEBUG_IDS 1
|
||||||
* #define DEBUG_RECOGN 1
|
* #define DEBUG_RECOGN 1
|
||||||
@ -71,7 +69,7 @@ static const uint32_t MAX_DELAY_BEFORE_CLEANING= 1800 ; // clean old keys eve
|
|||||||
|
|
||||||
static const uint32_t MAX_SERIALISED_IDENTITY_AGE = 600 ; // after 10 mins, a serialised identity record must be renewed.
|
static const uint32_t MAX_SERIALISED_IDENTITY_AGE = 600 ; // after 10 mins, a serialised identity record must be renewed.
|
||||||
|
|
||||||
RsIdentity *rsIdentity = NULL;
|
RsIdentity* rsIdentity = nullptr;
|
||||||
|
|
||||||
/******
|
/******
|
||||||
* Some notes:
|
* Some notes:
|
||||||
@ -910,40 +908,75 @@ bool p3IdService::createIdentity(
|
|||||||
const std::string& name, const RsGxsImage& avatar,
|
const std::string& name, const RsGxsImage& avatar,
|
||||||
bool pseudonimous, const std::string& pgpPassword)
|
bool pseudonimous, const std::string& pgpPassword)
|
||||||
{
|
{
|
||||||
if(!pgpPassword.empty())
|
bool ret = true;
|
||||||
std::cerr<< __PRETTY_FUNCTION__ << " Warning! PGP Password handling "
|
|
||||||
<< "not implemented yet!" << std::endl;
|
|
||||||
|
|
||||||
RsIdentityParameters params;
|
RsIdentityParameters params;
|
||||||
|
uint32_t token = 0;
|
||||||
|
RsGroupMetaData meta;
|
||||||
|
RsTokenService::GxsRequestStatus wtStatus = RsTokenService::CANCELLED;
|
||||||
|
|
||||||
|
if(!pseudonimous && !pgpPassword.empty())
|
||||||
|
{
|
||||||
|
if(!rsNotify->cachePgpPassphrase(pgpPassword))
|
||||||
|
{
|
||||||
|
RsErr() << __PRETTY_FUNCTION__ << " Failure caching password"
|
||||||
|
<< std::endl;
|
||||||
|
ret = false;
|
||||||
|
goto LabelCreateIdentityCleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!rsNotify->setDisableAskPassword(true))
|
||||||
|
{
|
||||||
|
RsErr() << __PRETTY_FUNCTION__ << " Failure disabling password user"
|
||||||
|
<< " request" << std::endl;
|
||||||
|
ret = false;
|
||||||
|
goto LabelCreateIdentityCleanup;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
params.isPgpLinked = !pseudonimous;
|
params.isPgpLinked = !pseudonimous;
|
||||||
params.nickname = name;
|
params.nickname = name;
|
||||||
params.mImage = avatar;
|
params.mImage = avatar;
|
||||||
|
|
||||||
uint32_t token;
|
|
||||||
if(!createIdentity(token, params))
|
if(!createIdentity(token, params))
|
||||||
{
|
{
|
||||||
std::cerr << __PRETTY_FUNCTION__ << " Error! Failed creating group."
|
RsErr() << __PRETTY_FUNCTION__ << " Failed creating GXS group."
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
return false;
|
ret = false;
|
||||||
|
goto LabelCreateIdentityCleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(waitToken(token) != RsTokenService::COMPLETE)
|
/* Use custom timeout for waitToken because creating identities involves
|
||||||
|
* creating multiple signatures, which can take a lot of time expecially on
|
||||||
|
* slow hardware like phones or embedded devices */
|
||||||
|
if( (wtStatus = waitToken(
|
||||||
|
token, std::chrono::seconds(10), std::chrono::milliseconds(20) ))
|
||||||
|
!= RsTokenService::COMPLETE )
|
||||||
{
|
{
|
||||||
std::cerr << __PRETTY_FUNCTION__ << " Error! GXS operation failed."
|
RsErr() << __PRETTY_FUNCTION__ << " waitToken("<< token
|
||||||
<< std::endl;
|
<< ") failed with: " << wtStatus << std::endl;
|
||||||
return false;
|
ret = false;
|
||||||
|
goto LabelCreateIdentityCleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
RsGroupMetaData meta;
|
|
||||||
if(!RsGenExchange::getPublishedGroupMeta(token, meta))
|
if(!RsGenExchange::getPublishedGroupMeta(token, meta))
|
||||||
{
|
{
|
||||||
std::cerr << __PRETTY_FUNCTION__ << "Error! Failure getting updated "
|
RsErr() << __PRETTY_FUNCTION__ << " Failure getting updated group data."
|
||||||
<< " group data." << std::endl;
|
<< std::endl;
|
||||||
return false;
|
ret = false;
|
||||||
|
goto LabelCreateIdentityCleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
id = RsGxsId(meta.mGroupId);
|
id = RsGxsId(meta.mGroupId);
|
||||||
return true;
|
|
||||||
|
|
||||||
|
LabelCreateIdentityCleanup:
|
||||||
|
if(!pseudonimous && !pgpPassword.empty())
|
||||||
|
{
|
||||||
|
rsNotify->setDisableAskPassword(false);
|
||||||
|
rsNotify->clearPgpPassphrase();
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool p3IdService::createIdentity(uint32_t& token, RsIdentityParameters ¶ms)
|
bool p3IdService::createIdentity(uint32_t& token, RsIdentityParameters ¶ms)
|
||||||
@ -1153,6 +1186,16 @@ static void mergeIds(std::map<RsGxsId,std::list<RsPeerId> >& idmap,const RsGxsId
|
|||||||
old_peers.push_back(*it) ;
|
old_peers.push_back(*it) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool p3IdService::requestIdentity(const RsGxsId& id)
|
||||||
|
{
|
||||||
|
RsIdentityUsage usageInfo( RsServiceType::GXSID,
|
||||||
|
RsIdentityUsage::IDENTITY_DATA_UPDATE );
|
||||||
|
std::list<RsPeerId> onlinePeers;
|
||||||
|
|
||||||
|
return rsPeers && rsPeers->getOnlineList(onlinePeers)
|
||||||
|
&& requestKey(id, onlinePeers, usageInfo);
|
||||||
|
}
|
||||||
|
|
||||||
bool p3IdService::requestKey(const RsGxsId &id, const std::list<RsPeerId>& peers,const RsIdentityUsage& use_info)
|
bool p3IdService::requestKey(const RsGxsId &id, const std::list<RsPeerId>& peers,const RsIdentityUsage& use_info)
|
||||||
{
|
{
|
||||||
if(id.isNull())
|
if(id.isNull())
|
||||||
@ -3299,13 +3342,10 @@ static void calcPGPHash(const RsGxsId &id, const PGPFingerprintType &pgp, Sha1Ch
|
|||||||
|
|
||||||
|
|
||||||
// Must Use meta.
|
// Must Use meta.
|
||||||
RsGenExchange::ServiceCreate_Return p3IdService::service_CreateGroup(RsGxsGrpItem* grpItem, RsTlvSecurityKeySet& keySet)
|
RsGenExchange::ServiceCreate_Return p3IdService::service_CreateGroup(
|
||||||
|
RsGxsGrpItem* grpItem, RsTlvSecurityKeySet& keySet )
|
||||||
{
|
{
|
||||||
|
Dbg2() << __PRETTY_FUNCTION__ << std::endl;
|
||||||
#ifdef DEBUG_IDS
|
|
||||||
std::cerr << "p3IdService::service_CreateGroup()";
|
|
||||||
std::cerr << std::endl;
|
|
||||||
#endif // DEBUG_IDS
|
|
||||||
|
|
||||||
RsGxsIdGroupItem *item = dynamic_cast<RsGxsIdGroupItem *>(grpItem);
|
RsGxsIdGroupItem *item = dynamic_cast<RsGxsIdGroupItem *>(grpItem);
|
||||||
if (!item)
|
if (!item)
|
||||||
@ -3315,18 +3355,12 @@ RsGenExchange::ServiceCreate_Return p3IdService::service_CreateGroup(RsGxsGrpIte
|
|||||||
return SERVICE_CREATE_FAIL;
|
return SERVICE_CREATE_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG_IDS
|
|
||||||
std::cerr << "p3IdService::service_CreateGroup() Item is:";
|
|
||||||
std::cerr << std::endl;
|
|
||||||
item->print(std::cerr);
|
|
||||||
std::cerr << std::endl;
|
|
||||||
#endif // DEBUG_IDS
|
|
||||||
|
|
||||||
item->meta.mGroupId.clear();
|
item->meta.mGroupId.clear();
|
||||||
|
|
||||||
/********************* TEMP HACK UNTIL GXS FILLS IN GROUP_ID *****************/
|
/********************* TEMP HACK UNTIL GXS FILLS IN GROUP_ID *****************/
|
||||||
// find private admin key
|
// find private admin key
|
||||||
for(std::map<RsGxsId, RsTlvPrivateRSAKey>::iterator mit = keySet.private_keys.begin();mit != keySet.private_keys.end(); ++mit)
|
for( std::map<RsGxsId, RsTlvPrivateRSAKey>::iterator mit =
|
||||||
|
keySet.private_keys.begin(); mit != keySet.private_keys.end(); ++mit )
|
||||||
if(mit->second.keyFlags == (RSTLV_KEY_DISTRIB_ADMIN | RSTLV_KEY_TYPE_FULL))
|
if(mit->second.keyFlags == (RSTLV_KEY_DISTRIB_ADMIN | RSTLV_KEY_TYPE_FULL))
|
||||||
{
|
{
|
||||||
item->meta.mGroupId = RsGxsGroupId(mit->second.keyId);
|
item->meta.mGroupId = RsGxsGroupId(mit->second.keyId);
|
||||||
@ -3335,8 +3369,7 @@ RsGenExchange::ServiceCreate_Return p3IdService::service_CreateGroup(RsGxsGrpIte
|
|||||||
|
|
||||||
if(item->meta.mGroupId.isNull())
|
if(item->meta.mGroupId.isNull())
|
||||||
{
|
{
|
||||||
std::cerr << "p3IdService::service_CreateGroup() ERROR no admin key";
|
RsErr() << __PRETTY_FUNCTION__ << " missing admin key!" << std::endl;
|
||||||
std::cerr << std::endl;
|
|
||||||
return SERVICE_CREATE_FAIL;
|
return SERVICE_CREATE_FAIL;
|
||||||
}
|
}
|
||||||
mKeysTS[RsGxsId(item->meta.mGroupId)].TS = time(NULL) ;
|
mKeysTS[RsGxsId(item->meta.mGroupId)].TS = time(NULL) ;
|
||||||
@ -3386,8 +3419,7 @@ RsGenExchange::ServiceCreate_Return p3IdService::service_CreateGroup(RsGxsGrpIte
|
|||||||
/* create the hash */
|
/* create the hash */
|
||||||
Sha1CheckSum hash;
|
Sha1CheckSum hash;
|
||||||
|
|
||||||
/* */
|
RsPgpFingerprint ownFinger;
|
||||||
PGPFingerprintType ownFinger;
|
|
||||||
RsPgpId ownId(mPgpUtils->getPGPOwnId());
|
RsPgpId ownId(mPgpUtils->getPGPOwnId());
|
||||||
|
|
||||||
#ifdef DEBUG_IDS
|
#ifdef DEBUG_IDS
|
||||||
@ -3404,8 +3436,8 @@ RsGenExchange::ServiceCreate_Return p3IdService::service_CreateGroup(RsGxsGrpIte
|
|||||||
|
|
||||||
if(!mPgpUtils->getKeyFingerprint(ownId,ownFinger))
|
if(!mPgpUtils->getKeyFingerprint(ownId,ownFinger))
|
||||||
{
|
{
|
||||||
std::cerr << "p3IdService::service_CreateGroup() ERROR Own Finger is stuck";
|
RsErr() << __PRETTY_FUNCTION__
|
||||||
std::cerr << std::endl;
|
<< " failure retriving own PGP fingerprint" << std::endl;
|
||||||
return SERVICE_CREATE_FAIL; // abandon attempt!
|
return SERVICE_CREATE_FAIL; // abandon attempt!
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3430,59 +3462,68 @@ RsGenExchange::ServiceCreate_Return p3IdService::service_CreateGroup(RsGxsGrpIte
|
|||||||
#define MAX_SIGN_SIZE 2048
|
#define MAX_SIGN_SIZE 2048
|
||||||
uint8_t signarray[MAX_SIGN_SIZE];
|
uint8_t signarray[MAX_SIGN_SIZE];
|
||||||
unsigned int sign_size = MAX_SIGN_SIZE;
|
unsigned int sign_size = MAX_SIGN_SIZE;
|
||||||
int result ;
|
|
||||||
|
|
||||||
memset(signarray,0,MAX_SIGN_SIZE) ; // just in case.
|
memset(signarray,0,MAX_SIGN_SIZE) ; // just in case.
|
||||||
|
|
||||||
mPgpUtils->askForDeferredSelfSignature((void *) hash.toByteArray(), hash.SIZE_IN_BYTES, signarray, &sign_size,result, "p3IdService::service_CreateGroup()") ;
|
/* -10 is never returned by askForDeferredSelfSignature therefore we can
|
||||||
|
* use it to properly detect and handle the case libretroshare is being
|
||||||
|
* used outside retroshare-gui */
|
||||||
|
int result = -10;
|
||||||
|
|
||||||
|
/* This method is DEPRECATED we call it only for retrocompatibility with
|
||||||
|
* retroshare-gui, when called from something different then
|
||||||
|
* retroshare-gui for example retroshare-service it miserably fail! */
|
||||||
|
mPgpUtils->askForDeferredSelfSignature(
|
||||||
|
static_cast<const void*>(hash.toByteArray()),
|
||||||
|
hash.SIZE_IN_BYTES, signarray, &sign_size, result,
|
||||||
|
__PRETTY_FUNCTION__ );
|
||||||
|
|
||||||
|
/* If askForDeferredSelfSignature left result untouched it means
|
||||||
|
* libretroshare is being used by something different then
|
||||||
|
* retroshare-gui so try calling AuthGPG::getAuthGPG()->SignDataBin
|
||||||
|
* directly */
|
||||||
|
if( result == -10 )
|
||||||
|
result = AuthGPG::getAuthGPG()->SignDataBin(
|
||||||
|
static_cast<const void*>(hash.toByteArray()),
|
||||||
|
hash.SIZE_IN_BYTES, signarray, &sign_size,
|
||||||
|
__PRETTY_FUNCTION__ )
|
||||||
|
?
|
||||||
|
SELF_SIGNATURE_RESULT_SUCCESS :
|
||||||
|
SELF_SIGNATURE_RESULT_FAILED;
|
||||||
|
|
||||||
/* error */
|
|
||||||
switch(result)
|
switch(result)
|
||||||
{
|
{
|
||||||
case SELF_SIGNATURE_RESULT_PENDING : createStatus = SERVICE_CREATE_FAIL_TRY_LATER;
|
case SELF_SIGNATURE_RESULT_PENDING:
|
||||||
std::cerr << "p3IdService::service_CreateGroup() signature still pending" << std::endl;
|
createStatus = SERVICE_CREATE_FAIL_TRY_LATER;
|
||||||
|
Dbg1() << __PRETTY_FUNCTION__ << " signature still pending"
|
||||||
|
<< std::endl;
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
case SELF_SIGNATURE_RESULT_FAILED: return SERVICE_CREATE_FAIL ;
|
|
||||||
std::cerr << "p3IdService::service_CreateGroup() signature failed" << std::endl;
|
|
||||||
break ;
|
|
||||||
|
|
||||||
case SELF_SIGNATURE_RESULT_SUCCESS:
|
case SELF_SIGNATURE_RESULT_SUCCESS:
|
||||||
{
|
{
|
||||||
// Additional consistency checks.
|
// Additional consistency checks.
|
||||||
|
|
||||||
if(sign_size == MAX_SIGN_SIZE)
|
if(sign_size == MAX_SIGN_SIZE)
|
||||||
{
|
{
|
||||||
std::cerr << "Inconsistent result. Signature uses full buffer. This is probably an error." << std::endl;
|
RsErr() << __PRETTY_FUNCTION__ << "Inconsistent result. "
|
||||||
return SERVICE_CREATE_FAIL; // abandon attempt!
|
<< "Signature uses full buffer. This is probably an "
|
||||||
|
<< "error." << std::endl;
|
||||||
|
return SERVICE_CREATE_FAIL;
|
||||||
}
|
}
|
||||||
#ifdef DEBUG_IDS
|
|
||||||
std::cerr << "p3IdService::service_CreateGroup() Signature: ";
|
|
||||||
std::string strout;
|
|
||||||
#endif
|
|
||||||
/* push binary into string -> really bad! */
|
/* push binary into string -> really bad! */
|
||||||
item->mPgpIdSign = "";
|
item->mPgpIdSign = "";
|
||||||
for(unsigned int i = 0; i < sign_size; i++)
|
for(unsigned int i = 0; i < sign_size; i++)
|
||||||
{
|
item->mPgpIdSign += static_cast<char>(signarray[i]);
|
||||||
#ifdef DEBUG_IDS
|
|
||||||
rs_sprintf_append(strout, "%02x", (uint32_t) signarray[i]);
|
|
||||||
#endif
|
|
||||||
item->mPgpIdSign += signarray[i];
|
|
||||||
}
|
|
||||||
createStatus = SERVICE_CREATE_SUCCESS;
|
|
||||||
|
|
||||||
#ifdef DEBUG_IDS
|
|
||||||
std::cerr << strout;
|
|
||||||
std::cerr << std::endl;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/* done! */
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
createStatus = SERVICE_CREATE_SUCCESS;
|
createStatus = SERVICE_CREATE_SUCCESS;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
case SELF_SIGNATURE_RESULT_FAILED: /* fall-through */
|
||||||
|
default:
|
||||||
|
RsErr() << __PRETTY_FUNCTION__ << " signature failed with: "
|
||||||
|
<< result << std::endl;
|
||||||
|
return SERVICE_CREATE_FAIL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else createStatus = SERVICE_CREATE_SUCCESS;
|
||||||
|
|
||||||
// Enforce no AuthorId.
|
// Enforce no AuthorId.
|
||||||
item->meta.mAuthorId.clear() ;
|
item->meta.mAuthorId.clear() ;
|
||||||
@ -3494,15 +3535,16 @@ RsGenExchange::ServiceCreate_Return p3IdService::service_CreateGroup(RsGxsGrpIte
|
|||||||
// this allows the user interface
|
// this allows the user interface
|
||||||
// to see the grp id on the list of ownIds immediately after the group was created
|
// to see the grp id on the list of ownIds immediately after the group was created
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mIdMtx);
|
RS_STACK_MUTEX(mIdMtx);
|
||||||
RsGxsId gxsId(item->meta.mGroupId);
|
RsGxsId gxsId(item->meta.mGroupId);
|
||||||
if (std::find(mOwnIds.begin(), mOwnIds.end(), gxsId) == mOwnIds.end())
|
if (std::find(mOwnIds.begin(), mOwnIds.end(), gxsId) == mOwnIds.end())
|
||||||
{
|
{
|
||||||
mOwnIds.push_back(gxsId);
|
mOwnIds.push_back(gxsId);
|
||||||
mKeysTS[gxsId].TS = time(NULL) ;
|
mKeysTS[gxsId].TS = time(nullptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Dbg2() << __PRETTY_FUNCTION__ << " returns: " << createStatus << std::endl;
|
||||||
return createStatus;
|
return createStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4681,11 +4723,33 @@ void RsGxsIdGroup::serial_process(
|
|||||||
}
|
}
|
||||||
|
|
||||||
RsIdentityUsage::RsIdentityUsage(
|
RsIdentityUsage::RsIdentityUsage(
|
||||||
uint16_t service, const RsIdentityUsage::UsageCode& code,
|
RsServiceType service, RsIdentityUsage::UsageCode code,
|
||||||
const RsGxsGroupId& gid, const RsGxsMessageId& mid,
|
const RsGxsGroupId& gid, const RsGxsMessageId& mid,
|
||||||
uint64_t additional_id, const std::string& comment ) :
|
uint64_t additional_id, const std::string& comment ) :
|
||||||
mServiceId(service), mUsageCode(code), mGrpId(gid), mMsgId(mid),
|
mServiceId(service), mUsageCode(code), mGrpId(gid), mMsgId(mid),
|
||||||
mAdditionalId(additional_id), mComment(comment)
|
mAdditionalId(additional_id), mComment(comment)
|
||||||
|
{
|
||||||
|
/* This is a hack, since it will hash also mHash, but because it is
|
||||||
|
* initialized to 0, and only computed in the constructor here, it should
|
||||||
|
* be ok. */
|
||||||
|
librs::crypto::HashStream hs(librs::crypto::HashStream::SHA1);
|
||||||
|
|
||||||
|
hs << static_cast<uint32_t>(service); // G10h4ck: Why uint32 if it's 16 bits?
|
||||||
|
hs << static_cast<uint8_t>(code);
|
||||||
|
hs << gid;
|
||||||
|
hs << mid;
|
||||||
|
hs << static_cast<uint64_t>(additional_id);
|
||||||
|
hs << comment;
|
||||||
|
|
||||||
|
mHash = hs.hash();
|
||||||
|
}
|
||||||
|
|
||||||
|
RsIdentityUsage::RsIdentityUsage(
|
||||||
|
uint16_t service, const RsIdentityUsage::UsageCode& code,
|
||||||
|
const RsGxsGroupId& gid, const RsGxsMessageId& mid,
|
||||||
|
uint64_t additional_id,const std::string& comment ) :
|
||||||
|
mServiceId(static_cast<RsServiceType>(service)), mUsageCode(code),
|
||||||
|
mGrpId(gid), mMsgId(mid), mAdditionalId(additional_id), mComment(comment)
|
||||||
{
|
{
|
||||||
#ifdef DEBUG_IDS
|
#ifdef DEBUG_IDS
|
||||||
std::cerr << "New identity usage: " << std::endl;
|
std::cerr << "New identity usage: " << std::endl;
|
||||||
@ -4702,7 +4766,7 @@ RsIdentityUsage::RsIdentityUsage(
|
|||||||
* be ok. */
|
* be ok. */
|
||||||
librs::crypto::HashStream hs(librs::crypto::HashStream::SHA1) ;
|
librs::crypto::HashStream hs(librs::crypto::HashStream::SHA1) ;
|
||||||
|
|
||||||
hs << (uint32_t)service ;
|
hs << (uint32_t)service ; // G10h4ck: Why uint32 if it's 16 bits?
|
||||||
hs << (uint8_t)code ;
|
hs << (uint8_t)code ;
|
||||||
hs << gid ;
|
hs << gid ;
|
||||||
hs << mid ;
|
hs << mid ;
|
||||||
@ -4717,4 +4781,5 @@ RsIdentityUsage::RsIdentityUsage(
|
|||||||
}
|
}
|
||||||
|
|
||||||
RsIdentityUsage::RsIdentityUsage() :
|
RsIdentityUsage::RsIdentityUsage() :
|
||||||
mServiceId(0), mUsageCode(UNKNOWN_USAGE), mAdditionalId(0) {}
|
mServiceId(RsServiceType::NONE), mUsageCode(UNKNOWN_USAGE), mAdditionalId(0)
|
||||||
|
{}
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* libretroshare/src/services: p3idservice.h *
|
* libretroshare/src/services: p3idservice.h *
|
||||||
* *
|
* *
|
||||||
* libretroshare: retroshare core library *
|
* Copyright (C) 2012-2014 Robert Fernie <retroshare@lunamutt.com> *
|
||||||
* *
|
* Copyright (C) 2017-2019 Gioacchino Mazzurco <gio@altermundi.net> *
|
||||||
* Copyright 2012-2012 Robert Fernie <retroshare@lunamutt.com> *
|
|
||||||
* *
|
* *
|
||||||
* This program is free software: you can redistribute it and/or modify *
|
* This program is free software: you can redistribute it and/or modify *
|
||||||
* it under the terms of the GNU Lesser General Public License as *
|
* it under the terms of the GNU Lesser General Public License as *
|
||||||
@ -21,23 +20,22 @@
|
|||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
/// RetroShare GXS identities service
|
||||||
|
|
||||||
#include "retroshare/rsidentity.h" // External Interfaces.
|
|
||||||
#include "gxs/rsgenexchange.h" // GXS service.
|
|
||||||
#include "gxs/rsgixs.h" // Internal Interfaces.
|
|
||||||
|
|
||||||
#include "gxs/gxstokenqueue.h"
|
|
||||||
#include "rsitems/rsgxsiditems.h"
|
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "retroshare/rsidentity.h" // External Interfaces.
|
||||||
|
#include "gxs/rsgenexchange.h" // GXS service.
|
||||||
|
#include "gxs/rsgixs.h" // Internal Interfaces.
|
||||||
|
#include "util/rsdebug.h"
|
||||||
|
#include "gxs/gxstokenqueue.h"
|
||||||
|
#include "rsitems/rsgxsiditems.h"
|
||||||
#include "util/rsmemcache.h"
|
#include "util/rsmemcache.h"
|
||||||
#include "util/rstickevent.h"
|
#include "util/rstickevent.h"
|
||||||
#include "util/rsrecogn.h"
|
#include "util/rsrecogn.h"
|
||||||
#include "util/rsdebug.h"
|
|
||||||
#include "pqi/authgpg.h"
|
#include "pqi/authgpg.h"
|
||||||
|
|
||||||
#include "rsitems/rsgxsrecognitems.h"
|
#include "rsitems/rsgxsrecognitems.h"
|
||||||
|
|
||||||
class PgpAuxUtils;
|
class PgpAuxUtils;
|
||||||
@ -370,6 +368,9 @@ public:
|
|||||||
virtual bool deserialiseIdentityFromMemory(const std::string& radix_string,
|
virtual bool deserialiseIdentityFromMemory(const std::string& radix_string,
|
||||||
RsGxsId* id = nullptr);
|
RsGxsId* id = nullptr);
|
||||||
|
|
||||||
|
/// @see RsIdentity
|
||||||
|
bool requestIdentity(const RsGxsId& id) override;
|
||||||
|
|
||||||
/**************** RsGixsReputation Implementation ****************/
|
/**************** RsGixsReputation Implementation ****************/
|
||||||
|
|
||||||
// get Reputation.
|
// get Reputation.
|
||||||
@ -620,5 +621,5 @@ private:
|
|||||||
bool mAutoAddFriendsIdentitiesAsContacts;
|
bool mAutoAddFriendsIdentitiesAsContacts;
|
||||||
uint32_t mMaxKeepKeysBanned ;
|
uint32_t mMaxKeepKeysBanned ;
|
||||||
|
|
||||||
RS_SET_CONTEXT_DEBUG_LEVEL(4);
|
RS_SET_CONTEXT_DEBUG_LEVEL(1)
|
||||||
};
|
};
|
||||||
|
@ -1988,10 +1988,10 @@ QString IdDialog::createUsageString(const RsIdentityUsage& u) const
|
|||||||
|
|
||||||
switch(u.mServiceId)
|
switch(u.mServiceId)
|
||||||
{
|
{
|
||||||
case RS_SERVICE_GXS_TYPE_CHANNELS: service_name = tr("Channels") ;service_type = RetroShareLink::TYPE_CHANNEL ; break ;
|
case RsServiceType::CHANNELS: service_name = tr("Channels") ;service_type = RetroShareLink::TYPE_CHANNEL ; break ;
|
||||||
case RS_SERVICE_GXS_TYPE_FORUMS: service_name = tr("Forums") ; service_type = RetroShareLink::TYPE_FORUM ; break ;
|
case RsServiceType::FORUMS: service_name = tr("Forums") ; service_type = RetroShareLink::TYPE_FORUM ; break ;
|
||||||
case RS_SERVICE_GXS_TYPE_POSTED: service_name = tr("Posted") ; service_type = RetroShareLink::TYPE_POSTED ; break ;
|
case RsServiceType::POSTED: service_name = tr("Posted") ; service_type = RetroShareLink::TYPE_POSTED ; break ;
|
||||||
case RS_SERVICE_TYPE_CHAT: service_name = tr("Chat") ; service_type = RetroShareLink::TYPE_CHAT_ROOM ; break ;
|
case RsServiceType::CHAT: service_name = tr("Chat") ; service_type = RetroShareLink::TYPE_CHAT_ROOM ; break ;
|
||||||
default:
|
default:
|
||||||
service_name = tr("Unknown"); service_type = RetroShareLink::TYPE_UNKNOWN ;
|
service_name = tr("Unknown"); service_type = RetroShareLink::TYPE_UNKNOWN ;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user