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 ; 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 bool PGPHandler::getKeyFingerprint(const RsPgpId& id,PGPFingerprintType& fp) const
{ {
RsStackMutex mtx(pgphandlerMtx) ; // lock access to PGP memory structures. RsStackMutex mtx(pgphandlerMtx) ; // lock access to PGP memory structures.

View file

@ -153,6 +153,7 @@ class PGPHandler
static void setPassphraseCallback(PassphraseCallback cb) ; static void setPassphraseCallback(PassphraseCallback cb) ;
static PassphraseCallback passphraseCallback() { return _passphrase_callback ; } 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. // 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()) if(sslId.isNull() || sslId == getOwnId())
{ {
@ -1095,7 +1095,13 @@ bool p3PeerMgrIMPL::addSslOnlyFriend( const RsPeerId& sslId, const RsPeerDetails
return false; 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; pstate.id = sslId;
if(!dt.name.empty()) pstate.name = dt.name; if(!dt.name.empty()) pstate.name = dt.name;
@ -2460,14 +2466,19 @@ bool p3PeerMgrIMPL::loadList(std::list<RsItem *>& load)
#endif #endif
/* ************* */ /* ************* */
// permission flags is used as a mask for the existing perms, so we set it to 0xffff // 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, RsPeerDetails det ;
pitem->lastContact, RS_NODE_PERM_ALL )) if(!rsPeers->getGPGDetails(peer_pgp_id,det))
{ {
RsInfo() << __PRETTY_FUNCTION__ << " loading SSL-only " // would be better to add flags into RsPeerNetItem so that we already have this information. However, it's possible that the PGP key
<< "friend: " << peer_id << " " << pitem->location // has been added in the meantime, so the peer would be loaded with the right pGP key attached.
<< std::endl;
addSslOnlyFriend(peer_id); 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__ << " cannot add friend friend: " << peer_id << " " << pitem->location << ". Somthing's wrong." << std::endl;
} }
setLocation(pitem->nodePeerId, pitem->location); setLocation(pitem->nodePeerId, pitem->location);
} }

View file

@ -137,6 +137,7 @@ public:
virtual bool addSslOnlyFriend( virtual bool addSslOnlyFriend(
const RsPeerId& sslId, const RsPeerId& sslId,
const RsPgpId& pgpId,
const RsPeerDetails& details = RsPeerDetails() ) = 0; const RsPeerDetails& details = RsPeerDetails() ) = 0;
virtual bool removeFriend(const RsPeerId &ssl_id, bool removePgpId) = 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, uint16_t vsDisc = RS_VS_DISC_FULL, uint16_t vsDht = RS_VS_DHT_FULL,
rstime_t lastContact = 0,ServicePermissionFlags = ServicePermissionFlags(RS_NODE_PERM_DEFAULT)); rstime_t lastContact = 0,ServicePermissionFlags = ServicePermissionFlags(RS_NODE_PERM_DEFAULT));
bool addSslOnlyFriend( bool addSslOnlyFriend(const RsPeerId& sslId, const RsPgpId &pgp_id, const RsPeerDetails& details = RsPeerDetails() ) override;
const RsPeerId& sslId,
const RsPeerDetails& details = RsPeerDetails() ) override;
virtual bool removeFriend(const RsPeerId &ssl_id, bool removePgpId); virtual bool removeFriend(const RsPeerId &ssl_id, bool removePgpId);
virtual bool removeFriend(const RsPgpId &pgp_id); 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); 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 struct RsPeerDetails : RsSerializable
{ {
RsPeerDetails(); RsPeerDetails();
@ -228,6 +236,7 @@ struct RsPeerDetails : RsSerializable
uint32_t trustLvl; uint32_t trustLvl;
uint32_t validLvl; uint32_t validLvl;
bool skip_signature_validation;
bool ownsign; /* we have signed the remote peer GPG key */ bool ownsign; /* we have signed the remote peer GPG key */
bool hasSignedMe; /* the remote peer has signed my GPG key */ bool hasSignedMe; /* the remote peer has signed my GPG key */
@ -519,6 +528,7 @@ public:
*/ */
virtual bool addSslOnlyFriend( virtual bool addSslOnlyFriend(
const RsPeerId& sslId, const RsPeerId& sslId,
const RsPgpId& pgp_id,
const RsPeerDetails& details = RsPeerDetails() ) = 0; 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); 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( bool p3Peers::addSslOnlyFriend( const RsPeerId& sslId, const RsPgpId& pgp_id,const RsPeerDetails& details )
const RsPeerId& sslId, const RsPeerDetails& details ) {
{ return mPeerMgr->addSslOnlyFriend(sslId, 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) 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"); rsInvite = inviteUrl.getQueryV("rsInvite");
std::vector<uint8_t> inviteBuf = Radix64::decode(*rsInvite); std::vector<uint8_t> inviteBuf = Radix64::decode(*rsInvite);
RsGenericSerializer::SerializeContext ctx( RsGenericSerializer::SerializeContext ctx( inviteBuf.data(), static_cast<uint32_t>(inviteBuf.size()));
inviteBuf.data(), static_cast<uint32_t>(inviteBuf.size()));
RsGenericSerializer::SerializeJob j = RsGenericSerializer::DESERIALIZE; RsGenericSerializer::SerializeJob j = RsGenericSerializer::DESERIALIZE;
while(ctx.mOk && ctx.mOffset < ctx.mSize) 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; return ctx.mOk;
} }
@ -1730,7 +1744,7 @@ RsPeerDetails::RsPeerDetails()
:isOnlyGPGdetail(false), :isOnlyGPGdetail(false),
name(""),email(""),location(""), name(""),email(""),location(""),
org(""),authcode(""), org(""),authcode(""),
trustLvl(0), validLvl(0),ownsign(false), trustLvl(0), validLvl(0),skip_signature_validation(false),ownsign(false),
hasSignedMe(false),accept_connection(false), hasSignedMe(false),accept_connection(false),
state(0),actAsServer(false), state(0),actAsServer(false),
connectPort(0), connectPort(0),

View file

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

View file

@ -922,7 +922,7 @@ void ConnectFriendWizard::accept()
return; return;
} }
if (!mCertificate.empty() && add_key_to_keyring) if(!peerDetails.skip_signature_validation && !mCertificate.empty() && add_key_to_keyring)
{ {
RsPgpId pgp_id ; RsPgpId pgp_id ;
RsPeerId ssl_id ; RsPeerId ssl_id ;
@ -940,7 +940,12 @@ void ConnectFriendWizard::accept()
if(accept_connection && !peerDetails.gpg_id.isNull()) if(accept_connection && !peerDetails.gpg_id.isNull())
{ {
std::cerr << "ConclusionPage::validatePage() accepting GPG key for connection." << std::endl; std::cerr << "ConclusionPage::validatePage() accepting GPG key for connection." << std::endl;
if(peerDetails.skip_signature_validation)
rsPeers->addSslOnlyFriend(peerDetails.id, peerDetails.gpg_id,peerDetails);
else
rsPeers->addFriend(peerDetails.id, peerDetails.gpg_id,serviceFlags()) ; rsPeers->addFriend(peerDetails.id, peerDetails.gpg_id,serviceFlags()) ;
rsPeers->setServicePermissionFlags(peerDetails.gpg_id,serviceFlags()) ; rsPeers->setServicePermissionFlags(peerDetails.gpg_id,serviceFlags()) ;
if(ui->_addIPToWhiteList_CB_2->isChecked()) if(ui->_addIPToWhiteList_CB_2->isChecked())

View file

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>600</width> <width>1100</width>
<height>400</height> <height>604</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -45,7 +45,7 @@
<item> <item>
<widget class="QRadioButton" name="foffRadioButton"> <widget class="QRadioButton" name="foffRadioButton">
<property name="text"> <property name="text">
<string>&amp;Make friend with selected friends of my friends</string> <string>Ma&amp;ke friend with selected friends of my friends</string>
</property> </property>
</widget> </widget>
</item> </item>
@ -59,7 +59,7 @@
<item> <item>
<widget class="QRadioButton" name="webmailRadioButton"> <widget class="QRadioButton" name="webmailRadioButton">
<property name="text"> <property name="text">
<string>&amp;Send an Invitation by Web Mail Providers</string> <string>Send an In&amp;vitation by Web Mail Providers</string>
</property> </property>
</widget> </widget>
</item> </item>
@ -1502,6 +1502,12 @@
</widget> </widget>
</widget> </widget>
<customwidgets> <customwidgets>
<customwidget>
<class>AvatarWidget</class>
<extends>QLabel</extends>
<header>gui/common/AvatarWidget.h</header>
<container>1</container>
</customwidget>
<customwidget> <customwidget>
<class>StyledLabel</class> <class>StyledLabel</class>
<extends>QLabel</extends> <extends>QLabel</extends>
@ -1513,12 +1519,6 @@
<header>gui/common/FriendSelectionWidget.h</header> <header>gui/common/FriendSelectionWidget.h</header>
<container>1</container> <container>1</container>
</customwidget> </customwidget>
<customwidget>
<class>AvatarWidget</class>
<extends>QLabel</extends>
<header>gui/common/AvatarWidget.h</header>
<container>1</container>
</customwidget>
<customwidget> <customwidget>
<class>DropLineEdit</class> <class>DropLineEdit</class>
<extends>QLineEdit</extends> <extends>QLineEdit</extends>
@ -1537,8 +1537,8 @@
</customwidget> </customwidget>
</customwidgets> </customwidgets>
<resources> <resources>
<include location="../icons.qrc"/>
<include location="../images.qrc"/> <include location="../images.qrc"/>
<include location="../icons.qrc"/>
</resources> </resources>
<connections/> <connections/>
</ui> </ui>