fixed up addign friend from short invite

This commit is contained in:
csoler 2019-06-09 23:49:31 +02:00
parent 4bd5aaa9b2
commit fb52f6717c
No known key found for this signature in database
GPG key ID: 7BCA522266C0804C
9 changed files with 90 additions and 44 deletions

View file

@ -1571,6 +1571,11 @@ void PGPHandler::locked_updateOwnSignatureFlag(PGPCertificateInfo& cert,const Rs
cert._flags &= ~PGPCertificateInfo::PGP_CERTIFICATE_FLAG_HAS_SIGNED_ME ;
}
RsPgpId PGPHandler::pgpIdFromFingerprint(const PGPFingerprintType& f)
{
return RsPgpId(f.toByteArray() + _RsIdSize::PGP_FINGERPRINT - _RsIdSize::PGP_ID);
}
bool PGPHandler::getKeyFingerprint(const RsPgpId& id,PGPFingerprintType& fp) const
{
RsStackMutex mtx(pgphandlerMtx) ; // lock access to PGP memory structures.

View file

@ -153,6 +153,7 @@ class PGPHandler
static void setPassphraseCallback(PassphraseCallback cb) ;
static PassphraseCallback passphraseCallback() { return _passphrase_callback ; }
static RsPgpId pgpIdFromFingerprint(const PGPFingerprintType& f) ;
// Gets info about the key. Who are the signers, what's the owner's name, etc.
//

View file

@ -1065,7 +1065,7 @@ bool p3PeerMgrIMPL::addFriend(const RsPeerId& input_id, const RsPgpId& input_gpg
}
bool p3PeerMgrIMPL::addSslOnlyFriend( const RsPeerId& sslId, const RsPeerDetails& dt )
bool p3PeerMgrIMPL::addSslOnlyFriend( const RsPeerId& sslId, const RsPgpId& pgp_id,const RsPeerDetails& dt )
{
if(sslId.isNull() || sslId == getOwnId())
{
@ -1095,7 +1095,13 @@ bool p3PeerMgrIMPL::addSslOnlyFriend( const RsPeerId& sslId, const RsPeerDetails
return false;
}
pstate.gpg_id.clear();
if(pgp_id.isNull())
{
RsErr() << "Null pgp id for friend added with skip_pgp_signature_validaiton flag. This is not allowed." << std::endl;
return false;
}
pstate.gpg_id = pgp_id;
pstate.id = sslId;
if(!dt.name.empty()) pstate.name = dt.name;
@ -2460,14 +2466,19 @@ bool p3PeerMgrIMPL::loadList(std::list<RsItem *>& load)
#endif
/* ************* */
// permission flags is used as a mask for the existing perms, so we set it to 0xffff
if(!addFriend( peer_id, peer_pgp_id, pitem->netMode,
pitem->vs_disc, pitem->vs_dht,
pitem->lastContact, RS_NODE_PERM_ALL ))
RsPeerDetails det ;
if(!rsPeers->getGPGDetails(peer_pgp_id,det))
{
// would be better to add flags into RsPeerNetItem so that we already have this information. However, it's possible that the PGP key
// has been added in the meantime, so the peer would be loaded with the right pGP key attached.
RsInfo() << __PRETTY_FUNCTION__ << " loading SSL-only " << "friend: " << peer_id << " " << pitem->location << std::endl;
addSslOnlyFriend(peer_id,peer_pgp_id);
}
else if(!addFriend( peer_id, peer_pgp_id, pitem->netMode, pitem->vs_disc, pitem->vs_dht, pitem->lastContact, RS_NODE_PERM_ALL ))
{
RsInfo() << __PRETTY_FUNCTION__ << " loading SSL-only "
<< "friend: " << peer_id << " " << pitem->location
<< std::endl;
addSslOnlyFriend(peer_id);
RsInfo() << __PRETTY_FUNCTION__ << " cannot add friend friend: " << peer_id << " " << pitem->location << ". Somthing's wrong." << std::endl;
}
setLocation(pitem->nodePeerId, pitem->location);
}

View file

@ -137,6 +137,7 @@ public:
virtual bool addSslOnlyFriend(
const RsPeerId& sslId,
const RsPgpId& pgpId,
const RsPeerDetails& details = RsPeerDetails() ) = 0;
virtual bool removeFriend(const RsPeerId &ssl_id, bool removePgpId) = 0;
@ -256,9 +257,7 @@ public:
uint16_t vsDisc = RS_VS_DISC_FULL, uint16_t vsDht = RS_VS_DHT_FULL,
rstime_t lastContact = 0,ServicePermissionFlags = ServicePermissionFlags(RS_NODE_PERM_DEFAULT));
bool addSslOnlyFriend(
const RsPeerId& sslId,
const RsPeerDetails& details = RsPeerDetails() ) override;
bool addSslOnlyFriend(const RsPeerId& sslId, const RsPgpId &pgp_id, const RsPeerDetails& details = RsPeerDetails() ) override;
virtual bool removeFriend(const RsPeerId &ssl_id, bool removePgpId);
virtual bool removeFriend(const RsPgpId &pgp_id);

View file

@ -205,6 +205,14 @@ std::string RsPeerNetModeString(uint32_t netModel);
std::string RsPeerLastConnectString(uint32_t lastConnect);
/* We should definitely split this into 2 sub-structures:
* PGP info (or profile info) with all info related to PGP keys
* peer info: all network related information
*
* Plus top level information:
* isOnlyPgpDetail (this could be obsolete if the methods to query about PGP info is a different function)
* peer Id
*/
struct RsPeerDetails : RsSerializable
{
RsPeerDetails();
@ -228,6 +236,7 @@ struct RsPeerDetails : RsSerializable
uint32_t trustLvl;
uint32_t validLvl;
bool skip_signature_validation;
bool ownsign; /* we have signed the remote peer GPG key */
bool hasSignedMe; /* the remote peer has signed my GPG key */
@ -519,6 +528,7 @@ public:
*/
virtual bool addSslOnlyFriend(
const RsPeerId& sslId,
const RsPgpId& pgp_id,
const RsPeerDetails& details = RsPeerDetails() ) = 0;
/**

View file

@ -765,9 +765,10 @@ bool p3Peers::addFriend(const RsPeerId &ssl_id, const RsPgpId &gpg_id,ServicePe
return mPeerMgr->addFriend(ssl_id, gpg_id, RS_NET_MODE_UDP, RS_VS_DISC_FULL, RS_VS_DHT_FULL, now, perm_flags);
}
bool p3Peers::addSslOnlyFriend(
const RsPeerId& sslId, const RsPeerDetails& details )
{ return mPeerMgr->addSslOnlyFriend(sslId, details); }
bool p3Peers::addSslOnlyFriend( const RsPeerId& sslId, const RsPgpId& pgp_id,const RsPeerDetails& details )
{
return mPeerMgr->addSslOnlyFriend(sslId, pgp_id,details);
}
bool p3Peers::removeKeysFromPGPKeyring(const std::set<RsPgpId>& pgp_ids,std::string& backup_file,uint32_t& error_code)
{
@ -1241,8 +1242,7 @@ bool p3Peers::parseShortInvite(const std::string& inviteStrUrl, RsPeerDetails& d
rsInvite = inviteUrl.getQueryV("rsInvite");
std::vector<uint8_t> inviteBuf = Radix64::decode(*rsInvite);
RsGenericSerializer::SerializeContext ctx(
inviteBuf.data(), static_cast<uint32_t>(inviteBuf.size()));
RsGenericSerializer::SerializeContext ctx( inviteBuf.data(), static_cast<uint32_t>(inviteBuf.size()));
RsGenericSerializer::SerializeJob j = RsGenericSerializer::DESERIALIZE;
while(ctx.mOk && ctx.mOffset < ctx.mSize)
@ -1346,6 +1346,20 @@ bool p3Peers::parseShortInvite(const std::string& inviteStrUrl, RsPeerDetails& d
}
}
// now check if the PGP key is available. If so, add it in the PeerDetails:
RsPeerDetails pgp_det ;
if(getGPGDetails(PGPHandler::pgpIdFromFingerprint(details.fpr),pgp_det) && pgp_det.fpr == details.fpr)
{
details.issuer = pgp_det.issuer;
details.gpg_id = pgp_det.gpg_id;
details.gpgSigners = pgp_det.gpgSigners;
details.trustLvl = pgp_det.trustLvl;
details.validLvl = pgp_det.validLvl;
details.ownsign = pgp_det.ownsign;
details.hasSignedMe = pgp_det.hasSignedMe;
details.accept_connection = pgp_det.accept_connection;
}
return ctx.mOk;
}
@ -1730,7 +1744,7 @@ RsPeerDetails::RsPeerDetails()
:isOnlyGPGdetail(false),
name(""),email(""),location(""),
org(""),authcode(""),
trustLvl(0), validLvl(0),ownsign(false),
trustLvl(0), validLvl(0),skip_signature_validation(false),ownsign(false),
hasSignedMe(false),accept_connection(false),
state(0),actAsServer(false),
connectPort(0),

View file

@ -97,6 +97,7 @@ public:
/// @see RsPeers
bool addSslOnlyFriend(
const RsPeerId& sslId,
const RsPgpId& pgp_id,
const RsPeerDetails& details = RsPeerDetails() ) override;
virtual bool removeFriend(const RsPgpId& gpgid);