2008-01-25 02:58:29 -05:00
|
|
|
/*
|
|
|
|
* libretroshare/src/rsserver: p3peers.cc
|
|
|
|
*
|
|
|
|
* RetroShare C++ Interface.
|
|
|
|
*
|
|
|
|
* Copyright 2004-2008 by Robert Fernie.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License Version 2 as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
* USA.
|
|
|
|
*
|
|
|
|
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "rsserver/p3peers.h"
|
2009-02-08 09:30:28 -05:00
|
|
|
#include "rsserver/p3face.h"
|
2008-01-25 02:58:29 -05:00
|
|
|
#include "pqi/p3connmgr.h"
|
2010-01-13 15:56:55 -05:00
|
|
|
#include "pqi/authssl.h"
|
2010-01-13 15:58:58 -05:00
|
|
|
#include "pqi/authgpg.h"
|
2009-02-08 09:30:28 -05:00
|
|
|
#include <rsiface/rsinit.h>
|
2008-01-25 02:58:29 -05:00
|
|
|
|
|
|
|
#include <iostream>
|
2008-06-19 17:34:13 -04:00
|
|
|
#include <fstream>
|
2008-01-25 02:58:29 -05:00
|
|
|
#include <sstream>
|
|
|
|
|
2009-05-25 07:38:47 -04:00
|
|
|
#ifdef RS_USE_PGPSSL
|
|
|
|
#include <gpgme.h>
|
|
|
|
#endif
|
2009-05-23 11:07:35 -04:00
|
|
|
|
2008-11-09 17:17:20 -05:00
|
|
|
/**************** PQI_USE_XPGP ******************/
|
|
|
|
#if defined(PQI_USE_XPGP)
|
|
|
|
#include "pqi/authxpgp.h"
|
|
|
|
#else /* X509 Certificates */
|
|
|
|
/**************** PQI_USE_XPGP ******************/
|
|
|
|
#include "pqi/authssl.h"
|
|
|
|
#endif /* X509 Certificates */
|
|
|
|
/**************** PQI_USE_XPGP ******************/
|
|
|
|
|
2008-06-19 17:34:13 -04:00
|
|
|
|
2008-01-25 02:58:29 -05:00
|
|
|
RsPeers *rsPeers = NULL;
|
|
|
|
|
2008-06-13 11:42:08 -04:00
|
|
|
/*******
|
|
|
|
* #define P3PEERS_DEBUG 1
|
|
|
|
*******/
|
|
|
|
|
2008-01-25 02:58:29 -05:00
|
|
|
static uint32_t RsPeerTranslateTrust(uint32_t trustLvl);
|
|
|
|
int ensureExtension(std::string &name, std::string def_ext);
|
|
|
|
|
|
|
|
std::string RsPeerTrustString(uint32_t trustLvl)
|
|
|
|
{
|
2009-05-23 11:07:35 -04:00
|
|
|
|
2008-01-25 02:58:29 -05:00
|
|
|
std::string str;
|
2009-05-23 11:07:35 -04:00
|
|
|
|
|
|
|
#ifdef RS_USE_PGPSSL
|
|
|
|
switch(trustLvl)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case GPGME_VALIDITY_UNKNOWN:
|
|
|
|
str = "GPGME_VALIDITY_UNKNOWN";
|
|
|
|
break;
|
|
|
|
case GPGME_VALIDITY_UNDEFINED:
|
|
|
|
str = "GPGME_VALIDITY_UNDEFINED";
|
|
|
|
break;
|
|
|
|
case GPGME_VALIDITY_NEVER:
|
|
|
|
str = "GPGME_VALIDITY_NEVER";
|
|
|
|
break;
|
|
|
|
case GPGME_VALIDITY_MARGINAL:
|
|
|
|
str = "GPGME_VALIDITY_MARGINAL";
|
|
|
|
break;
|
|
|
|
case GPGME_VALIDITY_FULL:
|
|
|
|
str = "GPGME_VALIDITY_FULL";
|
|
|
|
break;
|
|
|
|
case GPGME_VALIDITY_ULTIMATE:
|
|
|
|
str = "GPGME_VALIDITY_ULTIMATE";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return str;
|
|
|
|
#endif
|
|
|
|
|
2008-01-25 02:58:29 -05:00
|
|
|
if (trustLvl == RS_TRUST_LVL_GOOD)
|
|
|
|
{
|
|
|
|
str = "Good";
|
|
|
|
}
|
|
|
|
else if (trustLvl == RS_TRUST_LVL_MARGINAL)
|
|
|
|
{
|
|
|
|
str = "Marginal";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
str = "No Trust";
|
|
|
|
}
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::string RsPeerStateString(uint32_t state)
|
|
|
|
{
|
|
|
|
std::string str;
|
|
|
|
if (state & RS_PEER_STATE_CONNECTED)
|
|
|
|
{
|
|
|
|
str = "Connected";
|
|
|
|
}
|
2008-02-28 10:58:54 -05:00
|
|
|
else if (state & RS_PEER_STATE_UNREACHABLE)
|
|
|
|
{
|
|
|
|
str = "Unreachable";
|
|
|
|
}
|
2008-01-25 02:58:29 -05:00
|
|
|
else if (state & RS_PEER_STATE_ONLINE)
|
|
|
|
{
|
|
|
|
str = "Available";
|
|
|
|
}
|
|
|
|
else if (state & RS_PEER_STATE_FRIEND)
|
|
|
|
{
|
|
|
|
str = "Offline";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
str = "Neighbour";
|
|
|
|
}
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string RsPeerNetModeString(uint32_t netModel)
|
|
|
|
{
|
|
|
|
std::string str;
|
|
|
|
if (netModel == RS_NETMODE_EXT)
|
|
|
|
{
|
|
|
|
str = "External Port";
|
|
|
|
}
|
|
|
|
else if (netModel == RS_NETMODE_UPNP)
|
|
|
|
{
|
|
|
|
str = "Ext (UPnP)";
|
|
|
|
}
|
|
|
|
else if (netModel == RS_NETMODE_UDP)
|
|
|
|
{
|
|
|
|
str = "UDP Mode";
|
|
|
|
}
|
2008-02-28 10:58:54 -05:00
|
|
|
else if (netModel == RS_NETMODE_UNREACHABLE)
|
|
|
|
{
|
|
|
|
str = "UDP Mode (Unreachable)";
|
|
|
|
}
|
2008-01-25 02:58:29 -05:00
|
|
|
else
|
|
|
|
{
|
|
|
|
str = "Unknown NetMode";
|
|
|
|
}
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string RsPeerLastConnectString(uint32_t lastConnect)
|
|
|
|
{
|
|
|
|
std::ostringstream out;
|
|
|
|
out << lastConnect << " secs ago";
|
|
|
|
return out.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-13 15:56:55 -05:00
|
|
|
p3Peers::p3Peers(p3ConnectMgr *cm)
|
|
|
|
:mConnMgr(cm)
|
2008-01-25 02:58:29 -05:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Updates ... */
|
|
|
|
bool p3Peers::FriendsChanged()
|
|
|
|
{
|
|
|
|
#ifdef P3PEERS_DEBUG
|
|
|
|
std::cerr << "p3Peers::FriendsChanged()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* TODO */
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool p3Peers::OthersChanged()
|
|
|
|
{
|
|
|
|
#ifdef P3PEERS_DEBUG
|
|
|
|
std::cerr << "p3Peers::OthersChanged()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* TODO */
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Peer Details (Net & Auth) */
|
|
|
|
std::string p3Peers::getOwnId()
|
|
|
|
{
|
|
|
|
#ifdef P3PEERS_DEBUG
|
|
|
|
std::cerr << "p3Peers::getOwnId()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
2010-01-13 15:58:58 -05:00
|
|
|
return AuthSSL::getAuthSSL()->OwnId();
|
2008-01-25 02:58:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
bool p3Peers::getOnlineList(std::list<std::string> &ids)
|
|
|
|
{
|
|
|
|
#ifdef P3PEERS_DEBUG
|
|
|
|
std::cerr << "p3Peers::getOnlineList()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* get from mConnectMgr */
|
|
|
|
mConnMgr->getOnlineList(ids);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool p3Peers::getFriendList(std::list<std::string> &ids)
|
|
|
|
{
|
|
|
|
#ifdef P3PEERS_DEBUG
|
|
|
|
std::cerr << "p3Peers::getFriendList()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* get from mConnectMgr */
|
|
|
|
mConnMgr->getFriendList(ids);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool p3Peers::getOthersList(std::list<std::string> &ids)
|
|
|
|
{
|
|
|
|
#ifdef P3PEERS_DEBUG
|
|
|
|
std::cerr << "p3Peers::getOthersList()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* get from mAuthMgr */
|
2010-01-13 15:58:58 -05:00
|
|
|
AuthSSL::getAuthSSL()->getAllList(ids);
|
2008-01-25 02:58:29 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-06-16 16:37:48 -04:00
|
|
|
bool p3Peers::isOnline(std::string id)
|
|
|
|
{
|
|
|
|
#ifdef P3PEERS_DEBUG
|
|
|
|
std::cerr << "p3Peers::isOnline() " << id;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* get from mConnectMgr */
|
|
|
|
peerConnectState state;
|
|
|
|
if (mConnMgr->getFriendNetStatus(id, state) &&
|
|
|
|
(state.state & RS_PEER_S_CONNECTED))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-12-23 11:23:54 -05:00
|
|
|
bool p3Peers::isTrustingMe(std::string id) const
|
|
|
|
{
|
2010-01-13 15:58:58 -05:00
|
|
|
return AuthSSL::getAuthSSL()->isTrustingMe(id) ;
|
2008-12-23 11:23:54 -05:00
|
|
|
}
|
|
|
|
|
2008-01-25 02:58:29 -05:00
|
|
|
bool p3Peers::isFriend(std::string id)
|
|
|
|
{
|
|
|
|
#ifdef P3PEERS_DEBUG
|
|
|
|
std::cerr << "p3Peers::isFriend() " << id;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* get from mConnectMgr */
|
|
|
|
peerConnectState state;
|
|
|
|
if (mConnMgr->getFriendNetStatus(id, state) &&
|
|
|
|
(state.state & RS_PEER_S_FRIEND))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-11-07 17:06:12 -05:00
|
|
|
static struct sockaddr_in getPreferredAddress( const struct sockaddr_in& addr1,time_t ts1,
|
|
|
|
const struct sockaddr_in& addr2,time_t ts2,
|
|
|
|
const struct sockaddr_in& addr3,time_t ts3)
|
|
|
|
{
|
|
|
|
time_t ts = ts1 ;
|
|
|
|
struct sockaddr_in addr = addr1 ;
|
|
|
|
|
|
|
|
if(ts2 > ts && strcmp(inet_ntoa(addr2.sin_addr),"0.0.0.0")) { ts = ts2 ; addr = addr2 ; }
|
|
|
|
if(ts3 > ts && strcmp(inet_ntoa(addr3.sin_addr),"0.0.0.0")) { ts = ts3 ; addr = addr3 ; }
|
|
|
|
|
|
|
|
return addr ;
|
|
|
|
}
|
|
|
|
|
2008-01-25 02:58:29 -05:00
|
|
|
bool p3Peers::getPeerDetails(std::string id, RsPeerDetails &d)
|
|
|
|
{
|
|
|
|
#ifdef P3PEERS_DEBUG
|
|
|
|
std::cerr << "p3Peers::getPeerDetails() " << id;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* get from mAuthMgr (first) */
|
2010-01-13 15:56:55 -05:00
|
|
|
sslcert authDetail;
|
2010-01-13 15:58:58 -05:00
|
|
|
if (!AuthSSL::getAuthSSL()->getCertDetails(id, authDetail))
|
2008-01-25 02:58:29 -05:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-01-13 16:01:06 -05:00
|
|
|
d.fpr = authDetail.fpr;
|
|
|
|
d.id = authDetail.id;
|
|
|
|
d.name = authDetail.name;
|
|
|
|
d.email = authDetail.email;
|
|
|
|
d.location = authDetail.location;
|
|
|
|
d.org = authDetail.org;
|
|
|
|
d.signers = authDetail.signers;
|
2008-01-25 02:58:29 -05:00
|
|
|
|
2010-01-13 16:01:06 -05:00
|
|
|
d.issuer = authDetail.issuer;
|
2009-08-09 09:06:24 -04:00
|
|
|
|
2010-01-13 16:05:38 -05:00
|
|
|
d.ownsign = AuthGPG::getAuthGPG()->isPGPSigned(AuthSSL::getAuthSSL()->getGPGId(id));
|
2008-01-25 02:58:29 -05:00
|
|
|
|
|
|
|
|
|
|
|
/* generate */
|
|
|
|
d.authcode = "AUTHCODE";
|
|
|
|
|
|
|
|
/* get from mConnectMgr */
|
|
|
|
peerConnectState pcs;
|
|
|
|
|
2010-01-13 15:58:58 -05:00
|
|
|
if (id == AuthSSL::getAuthSSL()->OwnId())
|
2008-02-07 11:18:34 -05:00
|
|
|
{
|
|
|
|
mConnMgr->getOwnNetStatus(pcs);
|
|
|
|
}
|
|
|
|
else if (!mConnMgr->getFriendNetStatus(id, pcs))
|
2008-01-25 02:58:29 -05:00
|
|
|
{
|
|
|
|
if (!mConnMgr->getOthersNetStatus(id, pcs))
|
|
|
|
{
|
|
|
|
/* fill in blank data */
|
|
|
|
d.localPort = 0;
|
|
|
|
d.extPort = 0;
|
|
|
|
d.lastConnect = 0;
|
|
|
|
d.connectPeriod = 0;
|
|
|
|
d.state = 0;
|
|
|
|
d.netMode = 0;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-11 11:43:51 -05:00
|
|
|
//TODO : check use of this details
|
2009-11-07 17:06:12 -05:00
|
|
|
// From all addresses, show the most recent one if no address is currently in use.
|
2009-11-11 11:43:51 -05:00
|
|
|
struct sockaddr_in best_local_addr = (!strcmp(inet_ntoa(pcs.currentlocaladdr.sin_addr),"0.0.0.0"))?getPreferredAddress(pcs.dht.laddr,pcs.dht.ts,pcs.disc.laddr,pcs.disc.ts,pcs.peer.laddr,pcs.peer.ts):pcs.currentlocaladdr ;
|
|
|
|
struct sockaddr_in best_servr_addr = (!strcmp(inet_ntoa(pcs.currentserveraddr.sin_addr),"0.0.0.0"))?getPreferredAddress(pcs.dht.raddr,pcs.dht.ts,pcs.disc.raddr,pcs.disc.ts,pcs.peer.raddr,pcs.peer.ts):pcs.currentserveraddr ;
|
2009-11-07 17:06:12 -05:00
|
|
|
|
|
|
|
|
2008-01-25 02:58:29 -05:00
|
|
|
/* fill from pcs */
|
|
|
|
|
2009-11-07 17:06:12 -05:00
|
|
|
d.localAddr = inet_ntoa(best_local_addr.sin_addr);
|
|
|
|
d.localPort = ntohs(best_local_addr.sin_port);
|
|
|
|
d.extAddr = inet_ntoa(best_servr_addr.sin_addr);
|
|
|
|
d.extPort = ntohs(best_servr_addr.sin_port);
|
2008-02-07 11:18:34 -05:00
|
|
|
d.lastConnect = pcs.lastcontact;
|
2008-01-25 02:58:29 -05:00
|
|
|
d.connectPeriod = 0;
|
2009-11-11 17:12:50 -05:00
|
|
|
std::list<std::string> ipAddressList;
|
|
|
|
std::list<IpAddressTimed> pcsList = pcs.getIpAddressList();
|
|
|
|
for (std::list<IpAddressTimed>::iterator ipListIt = pcsList.begin(); ipListIt!=(pcsList.end()); ipListIt++) {
|
|
|
|
std::ostringstream toto;
|
2009-12-15 12:47:43 -05:00
|
|
|
toto << ntohs(ipListIt->ipAddr.sin_port) << " " << (time(NULL) - ipListIt->seenTime) << " sec";
|
|
|
|
ipAddressList.push_back(std::string(inet_ntoa(ipListIt->ipAddr.sin_addr)) + ":" + toto.str());
|
2009-11-11 17:12:50 -05:00
|
|
|
}
|
|
|
|
d.ipAddressList = ipAddressList;
|
|
|
|
|
2008-01-25 02:58:29 -05:00
|
|
|
|
|
|
|
/* Translate */
|
|
|
|
|
|
|
|
d.state = 0;
|
|
|
|
if (pcs.state & RS_PEER_S_FRIEND)
|
|
|
|
d.state |= RS_PEER_STATE_FRIEND;
|
|
|
|
if (pcs.state & RS_PEER_S_ONLINE)
|
|
|
|
d.state |= RS_PEER_STATE_ONLINE;
|
|
|
|
if (pcs.state & RS_PEER_S_CONNECTED)
|
|
|
|
d.state |= RS_PEER_STATE_CONNECTED;
|
2008-02-28 10:58:54 -05:00
|
|
|
if (pcs.state & RS_PEER_S_UNREACHABLE)
|
|
|
|
d.state |= RS_PEER_STATE_UNREACHABLE;
|
2008-01-25 02:58:29 -05:00
|
|
|
|
2008-02-26 11:14:13 -05:00
|
|
|
switch(pcs.netMode & RS_NET_MODE_ACTUAL)
|
2008-02-07 11:18:34 -05:00
|
|
|
{
|
|
|
|
case RS_NET_MODE_EXT:
|
|
|
|
d.netMode = RS_NETMODE_EXT;
|
|
|
|
break;
|
2008-02-26 11:14:13 -05:00
|
|
|
case RS_NET_MODE_UPNP:
|
|
|
|
d.netMode = RS_NETMODE_UPNP;
|
2008-02-07 11:18:34 -05:00
|
|
|
break;
|
2008-02-26 11:14:13 -05:00
|
|
|
case RS_NET_MODE_UDP:
|
2008-02-28 10:58:54 -05:00
|
|
|
d.netMode = RS_NETMODE_UDP;
|
|
|
|
break;
|
|
|
|
case RS_NET_MODE_UNREACHABLE:
|
2008-02-07 11:18:34 -05:00
|
|
|
case RS_NET_MODE_UNKNOWN:
|
|
|
|
default:
|
2008-02-28 10:58:54 -05:00
|
|
|
d.netMode = RS_NETMODE_UNREACHABLE;
|
2008-02-07 11:18:34 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-02-26 11:14:13 -05:00
|
|
|
if (pcs.netMode & RS_NET_MODE_TRY_EXT)
|
|
|
|
{
|
|
|
|
d.tryNetMode = RS_NETMODE_EXT;
|
|
|
|
}
|
|
|
|
else if (pcs.netMode & RS_NET_MODE_TRY_UPNP)
|
|
|
|
{
|
|
|
|
d.tryNetMode = RS_NETMODE_UPNP;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
d.tryNetMode = RS_NETMODE_UDP;
|
|
|
|
}
|
|
|
|
|
2008-02-07 11:18:34 -05:00
|
|
|
d.visState = 0;
|
|
|
|
if (!(pcs.visState & RS_VIS_STATE_NODISC))
|
|
|
|
{
|
|
|
|
d.visState |= RS_VS_DISC_ON;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(pcs.visState & RS_VIS_STATE_NODHT))
|
|
|
|
{
|
|
|
|
d.visState |= RS_VS_DHT_ON;
|
|
|
|
}
|
2008-01-25 02:58:29 -05:00
|
|
|
|
2008-03-02 09:25:59 -05:00
|
|
|
|
|
|
|
/* Finally determine AutoConnect Status */
|
|
|
|
std::ostringstream autostr;
|
|
|
|
if (pcs.inConnAttempt)
|
|
|
|
{
|
2009-12-13 16:59:26 -05:00
|
|
|
if (pcs.currentConnAddrAttempt.type & RS_NET_CONN_TUNNEL) {
|
|
|
|
autostr << "Trying tunnel connection";
|
|
|
|
} else if (pcs.currentConnAddrAttempt.type & RS_NET_CONN_TCP_ALL) {
|
|
|
|
autostr << "Trying TCP : " << inet_ntoa(pcs.currentConnAddrAttempt.addr.sin_addr) << ":" << ntohs(pcs.currentConnAddrAttempt.addr.sin_port);
|
|
|
|
} else if (pcs.currentConnAddrAttempt.type & RS_NET_CONN_UDP_ALL) {
|
|
|
|
autostr << "Trying UDP : " << inet_ntoa(pcs.currentConnAddrAttempt.addr.sin_addr) << ":" << ntohs(pcs.currentConnAddrAttempt.addr.sin_port);
|
|
|
|
}
|
2008-03-02 09:25:59 -05:00
|
|
|
}
|
2008-03-26 11:35:09 -04:00
|
|
|
else if (pcs.state & RS_PEER_S_CONNECTED)
|
|
|
|
{
|
|
|
|
if (pcs.connecttype == RS_NET_CONN_TCP_ALL)
|
|
|
|
{
|
2008-07-10 17:26:10 -04:00
|
|
|
autostr << "Connected: TCP";
|
2008-03-26 11:35:09 -04:00
|
|
|
}
|
|
|
|
else if (pcs.connecttype == RS_NET_CONN_UDP_ALL)
|
|
|
|
{
|
2008-07-10 17:26:10 -04:00
|
|
|
autostr << "Connected: UDP";
|
2008-03-26 11:35:09 -04:00
|
|
|
}
|
2009-12-13 16:59:26 -05:00
|
|
|
else if (pcs.connecttype == RS_NET_CONN_TUNNEL)
|
|
|
|
{
|
|
|
|
autostr << "Connected: Tunnel";
|
|
|
|
}
|
|
|
|
else
|
2008-03-26 11:35:09 -04:00
|
|
|
{
|
2008-07-10 17:26:10 -04:00
|
|
|
autostr << "Connected: Unknown";
|
2008-03-26 11:35:09 -04:00
|
|
|
}
|
|
|
|
}
|
2008-03-02 09:25:59 -05:00
|
|
|
else
|
|
|
|
{
|
2008-07-10 17:26:10 -04:00
|
|
|
autostr << RsPeerStateString(pcs.state);
|
2008-03-02 09:25:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
d.autoconnect = autostr.str();
|
|
|
|
|
2008-01-25 02:58:29 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-17 07:45:06 -05:00
|
|
|
std::string p3Peers::getPeerPGPName(std::string id)
|
|
|
|
{
|
|
|
|
/* get from mAuthMgr as it should have more peers? */
|
2010-01-13 15:58:58 -05:00
|
|
|
return AuthSSL::getAuthSSL()->getIssuerName(id);
|
2009-11-17 07:45:06 -05:00
|
|
|
}
|
|
|
|
|
2008-01-25 02:58:29 -05:00
|
|
|
std::string p3Peers::getPeerName(std::string id)
|
|
|
|
{
|
|
|
|
#ifdef P3PEERS_DEBUG
|
|
|
|
std::cerr << "p3Peers::getPeerName() " << id;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* get from mAuthMgr as it should have more peers? */
|
2010-01-13 15:58:58 -05:00
|
|
|
return AuthSSL::getAuthSSL()->getName(id);
|
2008-01-25 02:58:29 -05:00
|
|
|
}
|
|
|
|
|
2009-05-23 11:07:35 -04:00
|
|
|
|
|
|
|
bool p3Peers::getPGPFriendList(std::list<std::string> &ids)
|
|
|
|
{
|
|
|
|
#ifdef P3PEERS_DEBUG
|
|
|
|
std::cerr << "p3Peers::getPGPFriendList()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
std::list<std::string> certids;
|
|
|
|
std::list<std::string>::iterator it;
|
|
|
|
|
|
|
|
mConnMgr->getFriendList(certids);
|
|
|
|
|
|
|
|
/* get from mAuthMgr (first) */
|
|
|
|
for(it = certids.begin(); it != certids.end(); it++)
|
|
|
|
{
|
2010-01-13 15:56:55 -05:00
|
|
|
sslcert detail;
|
2010-01-13 15:58:58 -05:00
|
|
|
if (!AuthSSL::getAuthSSL()->getCertDetails(*it, detail))
|
2009-05-23 11:07:35 -04:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef P3PEERS_DEBUG
|
|
|
|
std::cerr << "p3Peers::getPGPFriendList() Cert Id: " << *it;
|
2010-01-13 16:01:06 -05:00
|
|
|
std::cerr << " Issuer: " << detail.issuer;
|
2009-05-23 11:07:35 -04:00
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
if (!mAuthMgr->isPGPvalid(detail.issuer))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-01-13 16:01:06 -05:00
|
|
|
if (ids.end() == std::find(ids.begin(),ids.end(),detail.issuer))
|
2009-05-23 11:07:35 -04:00
|
|
|
{
|
|
|
|
|
|
|
|
#ifdef P3PEERS_DEBUG
|
|
|
|
std::cerr << "p3Peers::getPGPFriendList() Adding Friend: ";
|
2010-01-13 16:01:06 -05:00
|
|
|
std::cerr << detail.issuer;
|
2009-05-23 11:07:35 -04:00
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
2010-01-13 16:01:06 -05:00
|
|
|
ids.push_back(detail.issuer);
|
2009-05-23 11:07:35 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool p3Peers::getPGPAllList(std::list<std::string> &ids)
|
|
|
|
{
|
|
|
|
#ifdef P3PEERS_DEBUG
|
|
|
|
std::cerr << "p3Peers::getPGPOthersList()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* get from mAuthMgr */
|
2010-01-13 15:58:58 -05:00
|
|
|
AuthGPG::getAuthGPG()->getPGPAllList(ids);
|
2009-05-23 11:07:35 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string p3Peers::getPGPOwnId()
|
|
|
|
{
|
|
|
|
#ifdef P3PEERS_DEBUG
|
|
|
|
std::cerr << "p3Peers::getPGPOwnId()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* get from mAuthMgr */
|
2010-01-13 15:58:58 -05:00
|
|
|
return AuthGPG::getAuthGPG()->PGPOwnId();
|
2009-05-23 11:07:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-01-25 02:58:29 -05:00
|
|
|
/* Add/Remove Friends */
|
|
|
|
bool p3Peers::addFriend(std::string id)
|
|
|
|
{
|
|
|
|
#ifdef P3PEERS_DEBUG
|
|
|
|
std::cerr << "p3Peers::addFriend() " << id;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return mConnMgr->addFriend(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool p3Peers::removeFriend(std::string id)
|
|
|
|
{
|
|
|
|
#ifdef P3PEERS_DEBUG
|
|
|
|
std::cerr << "p3Peers::removeFriend() " << id;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return mConnMgr->removeFriend(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Network Stuff */
|
|
|
|
bool p3Peers::connectAttempt(std::string id)
|
|
|
|
{
|
|
|
|
#ifdef P3PEERS_DEBUG
|
|
|
|
std::cerr << "p3Peers::connectAttempt() " << id;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return mConnMgr->retryConnect(id);
|
|
|
|
}
|
|
|
|
|
2009-04-05 09:04:18 -04:00
|
|
|
void p3Peers::getIPServersList(std::list<std::string>& ip_servers)
|
|
|
|
{
|
|
|
|
mConnMgr->getIPServersList(ip_servers) ;
|
|
|
|
}
|
|
|
|
void p3Peers::allowServerIPDetermination(bool b)
|
|
|
|
{
|
|
|
|
mConnMgr->setIPServersEnabled(b) ;
|
|
|
|
}
|
2009-12-13 16:59:26 -05:00
|
|
|
|
|
|
|
void p3Peers::allowTunnelConnection(bool b)
|
|
|
|
{
|
|
|
|
std::cerr << "p3Peers::allowTunnelConnection() set tunnel to : " << b << std::endl;
|
|
|
|
mConnMgr->setTunnelConnection(b) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool p3Peers::getAllowServerIPDetermination()
|
2009-04-05 09:04:18 -04:00
|
|
|
{
|
|
|
|
return mConnMgr->getIPServersEnabled() ;
|
|
|
|
}
|
|
|
|
|
2009-12-13 16:59:26 -05:00
|
|
|
bool p3Peers::getAllowTunnelConnection()
|
|
|
|
{
|
|
|
|
std::cerr << "p3Peers::getAllowTunnelConnection() tunnel is : " << mConnMgr->getTunnelConnection() << std::endl;
|
|
|
|
return mConnMgr->getTunnelConnection() ;
|
|
|
|
}
|
|
|
|
|
2008-01-25 02:58:29 -05:00
|
|
|
bool p3Peers::setLocalAddress(std::string id, std::string addr_str, uint16_t port)
|
|
|
|
{
|
|
|
|
#ifdef P3PEERS_DEBUG
|
|
|
|
std::cerr << "p3Peers::setLocalAddress() " << id;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct sockaddr_in addr;
|
|
|
|
addr.sin_family = AF_INET;
|
|
|
|
addr.sin_port = htons(port);
|
|
|
|
|
|
|
|
int ret = 1;
|
|
|
|
/********************************** WINDOWS/UNIX SPECIFIC PART *******************/
|
|
|
|
#ifndef WINDOWS_SYS
|
|
|
|
if (ret && (0 != inet_aton(addr_str.c_str(), &(addr.sin_addr))))
|
|
|
|
#else
|
|
|
|
addr.sin_addr.s_addr = inet_addr(addr_str.c_str());
|
|
|
|
if (ret)
|
|
|
|
#endif
|
|
|
|
/********************************** WINDOWS/UNIX SPECIFIC PART *******************/
|
|
|
|
{
|
|
|
|
return mConnMgr->setLocalAddress(id, addr);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool p3Peers::setExtAddress(std::string id, std::string addr_str, uint16_t port)
|
|
|
|
{
|
|
|
|
#ifdef P3PEERS_DEBUG
|
|
|
|
std::cerr << "p3Peers::setExtAddress() " << id;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct sockaddr_in addr;
|
|
|
|
addr.sin_family = AF_INET;
|
|
|
|
addr.sin_port = htons(port);
|
|
|
|
|
|
|
|
int ret = 1;
|
|
|
|
/********************************** WINDOWS/UNIX SPECIFIC PART *******************/
|
|
|
|
#ifndef WINDOWS_SYS
|
|
|
|
if (ret && (0 != inet_aton(addr_str.c_str(), &(addr.sin_addr))))
|
|
|
|
#else
|
|
|
|
addr.sin_addr.s_addr = inet_addr(addr_str.c_str());
|
|
|
|
if (ret)
|
|
|
|
#endif
|
|
|
|
/********************************** WINDOWS/UNIX SPECIFIC PART *******************/
|
|
|
|
{
|
|
|
|
return mConnMgr->setExtAddress(id, addr);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-07 11:18:34 -05:00
|
|
|
bool p3Peers::setNetworkMode(std::string id, uint32_t extNetMode)
|
2008-01-25 02:58:29 -05:00
|
|
|
{
|
|
|
|
#ifdef P3PEERS_DEBUG
|
|
|
|
std::cerr << "p3Peers::setNetworkMode() " << id;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
2008-02-07 11:18:34 -05:00
|
|
|
/* translate */
|
|
|
|
uint32_t netMode = 0;
|
|
|
|
switch(extNetMode)
|
|
|
|
{
|
|
|
|
case RS_NETMODE_EXT:
|
|
|
|
netMode = RS_NET_MODE_EXT;
|
|
|
|
break;
|
|
|
|
case RS_NETMODE_UPNP:
|
|
|
|
netMode = RS_NET_MODE_UPNP;
|
|
|
|
break;
|
2008-02-26 11:14:13 -05:00
|
|
|
case RS_NETMODE_UDP:
|
|
|
|
netMode = RS_NET_MODE_UDP;
|
|
|
|
break;
|
2008-02-28 10:58:54 -05:00
|
|
|
case RS_NETMODE_UNREACHABLE:
|
|
|
|
netMode = RS_NET_MODE_UNREACHABLE;
|
|
|
|
break;
|
2008-02-26 11:14:13 -05:00
|
|
|
default:
|
|
|
|
break;
|
2008-02-07 11:18:34 -05:00
|
|
|
}
|
|
|
|
|
2008-01-25 02:58:29 -05:00
|
|
|
return mConnMgr->setNetworkMode(id, netMode);
|
|
|
|
}
|
|
|
|
|
2008-02-07 11:18:34 -05:00
|
|
|
|
2009-03-18 15:33:30 -04:00
|
|
|
bool
|
|
|
|
p3Peers::setVisState(std::string id, uint32_t extVisState)
|
2008-02-07 11:18:34 -05:00
|
|
|
{
|
|
|
|
#ifdef P3PEERS_DEBUG
|
|
|
|
std::cerr << "p3Peers::setVisState() " << id;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
uint32_t visState = 0;
|
|
|
|
if (!(extVisState & RS_VS_DHT_ON))
|
|
|
|
visState |= RS_VIS_STATE_NODHT;
|
|
|
|
if (!(extVisState & RS_VS_DISC_ON))
|
|
|
|
visState |= RS_VIS_STATE_NODISC;
|
|
|
|
|
|
|
|
return mConnMgr->setVisState(id, visState);
|
|
|
|
}
|
|
|
|
|
2009-03-18 15:33:30 -04:00
|
|
|
//===========================================================================
|
2008-01-25 02:58:29 -05:00
|
|
|
/* Auth Stuff */
|
2009-03-18 15:33:30 -04:00
|
|
|
std::string
|
|
|
|
p3Peers::GetRetroshareInvite()
|
2008-01-25 02:58:29 -05:00
|
|
|
{
|
|
|
|
#ifdef P3PEERS_DEBUG
|
|
|
|
std::cerr << "p3Peers::GetRetroshareInvite()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
2009-05-23 11:07:35 -04:00
|
|
|
std::cerr << "p3Peers::GetRetroshareInvite()";
|
|
|
|
std::cerr << std::endl;
|
2009-02-08 09:30:28 -05:00
|
|
|
|
2010-01-13 15:58:58 -05:00
|
|
|
std::string ownId = AuthSSL::getAuthSSL()->OwnId();
|
|
|
|
std::string certstr = AuthSSL::getAuthSSL()->SaveCertificateToString(ownId);
|
|
|
|
std::string name = AuthSSL::getAuthSSL()->getName(ownId);
|
2008-01-25 02:58:29 -05:00
|
|
|
|
2010-01-13 15:58:58 -05:00
|
|
|
std::string pgpownId = AuthGPG::getAuthGPG()->PGPOwnId();
|
|
|
|
std::string pgpcertstr = AuthGPG::getAuthGPG()->SaveCertificateToString(pgpownId);
|
2008-01-25 02:58:29 -05:00
|
|
|
|
2009-05-23 11:07:35 -04:00
|
|
|
std::cerr << "p3Peers::GetRetroshareInvite() SSL Cert:";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
std::cerr << certstr;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
|
|
|
std::cerr << "p3Peers::GetRetroshareInvite() PGP Cert:";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
std::cerr << pgpcertstr;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
|
|
|
std::string combinedcerts = certstr;
|
|
|
|
combinedcerts += '\n';
|
|
|
|
combinedcerts += pgpcertstr;
|
|
|
|
combinedcerts += '\n';
|
|
|
|
|
|
|
|
return combinedcerts;
|
2008-01-25 02:58:29 -05:00
|
|
|
}
|
|
|
|
|
2009-03-18 15:33:30 -04:00
|
|
|
//===========================================================================
|
|
|
|
|
2008-01-25 02:58:29 -05:00
|
|
|
bool p3Peers::LoadCertificateFromFile(std::string fname, std::string &id)
|
|
|
|
{
|
|
|
|
#ifdef P3PEERS_DEBUG
|
|
|
|
std::cerr << "p3Peers::LoadCertificateFromFile() ";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
2010-01-13 15:58:58 -05:00
|
|
|
return AuthSSL::getAuthSSL()->LoadCertificateFromFile(fname, id);
|
2008-01-25 02:58:29 -05:00
|
|
|
}
|
|
|
|
|
2009-05-23 11:07:35 -04:00
|
|
|
|
|
|
|
bool splitCerts(std::string in, std::string &sslcert, std::string &pgpcert)
|
|
|
|
{
|
|
|
|
std::cerr << "splitCerts():" << in;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
|
|
|
/* search for -----END CERTIFICATE----- */
|
|
|
|
std::string sslend("-----END CERTIFICATE-----");
|
|
|
|
std::string pgpend("-----END PGP PUBLIC KEY BLOCK-----");
|
|
|
|
size_t pos = in.find(sslend);
|
|
|
|
size_t pos2 = in.find(pgpend);
|
|
|
|
size_t ssllen, pgplen;
|
|
|
|
|
|
|
|
if (pos != std::string::npos)
|
|
|
|
{
|
|
|
|
std::cerr << "splitCerts(): Found SSL Cert";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
|
|
|
ssllen = pos + sslend.length();
|
|
|
|
sslcert = in.substr(0, ssllen);
|
|
|
|
|
|
|
|
if (pos2 != std::string::npos)
|
|
|
|
{
|
|
|
|
std::cerr << "splitCerts(): Found SSL + PGP Cert";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
|
|
|
pgplen = pos2 + pgpend.length() - ssllen;
|
|
|
|
pgpcert = in.substr(ssllen, pgplen);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (pos2 != std::string::npos)
|
|
|
|
{
|
|
|
|
std::cerr << "splitCerts(): Found PGP Cert Only";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
|
|
|
pgplen = pos2 + pgpend.length();
|
|
|
|
pgpcert = in.substr(0, pgplen);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-01-25 02:58:29 -05:00
|
|
|
bool p3Peers::LoadCertificateFromString(std::string cert, std::string &id)
|
|
|
|
{
|
|
|
|
#ifdef P3PEERS_DEBUG
|
|
|
|
std::cerr << "p3Peers::LoadCertificateFromString() ";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
2009-05-23 11:07:35 -04:00
|
|
|
std::string sslcert;
|
|
|
|
std::string pgpcert;
|
|
|
|
bool ret = false;
|
|
|
|
if (splitCerts(cert, sslcert, pgpcert))
|
|
|
|
{
|
|
|
|
if (pgpcert != "")
|
|
|
|
{
|
|
|
|
std::cerr << "pgpcert .... " << std::endl;
|
|
|
|
std::cerr << pgpcert << std::endl;
|
|
|
|
|
2010-01-13 15:58:58 -05:00
|
|
|
ret = AuthGPG::getAuthGPG()->LoadCertificateFromString(pgpcert);
|
2009-05-23 11:07:35 -04:00
|
|
|
}
|
|
|
|
if (sslcert != "")
|
|
|
|
{
|
|
|
|
std::cerr << "sslcert .... " << std::endl;
|
|
|
|
std::cerr << sslcert << std::endl;
|
|
|
|
|
2010-01-13 15:58:58 -05:00
|
|
|
ret = AuthSSL::getAuthSSL()->LoadCertificateFromString(sslcert, id);
|
2009-05-23 11:07:35 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2008-01-25 02:58:29 -05:00
|
|
|
}
|
|
|
|
|
2009-05-23 11:07:35 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-01-25 02:58:29 -05:00
|
|
|
bool p3Peers::SaveCertificateToFile(std::string id, std::string fname)
|
|
|
|
{
|
|
|
|
#ifdef P3PEERS_DEBUG
|
|
|
|
std::cerr << "p3Peers::SaveCertificateToFile() " << id;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
ensureExtension(fname, "pqi");
|
|
|
|
|
2010-01-13 15:58:58 -05:00
|
|
|
return AuthSSL::getAuthSSL()->SaveCertificateToFile(id, fname);
|
2008-01-25 02:58:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string p3Peers::SaveCertificateToString(std::string id)
|
|
|
|
{
|
|
|
|
#ifdef P3PEERS_DEBUG
|
|
|
|
std::cerr << "p3Peers::SaveCertificateToString() " << id;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
2010-01-13 15:58:58 -05:00
|
|
|
return AuthSSL::getAuthSSL()->SaveCertificateToString(id);
|
2008-01-25 02:58:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
bool p3Peers::AuthCertificate(std::string id, std::string code)
|
|
|
|
{
|
|
|
|
#ifdef P3PEERS_DEBUG
|
|
|
|
std::cerr << "p3Peers::AuthCertificate() " << id;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
2010-01-13 15:58:58 -05:00
|
|
|
if (AuthSSL::getAuthSSL()->AuthCertificate(id))
|
2008-01-25 02:58:29 -05:00
|
|
|
{
|
2009-05-23 11:07:35 -04:00
|
|
|
#ifdef P3PEERS_DEBUG
|
|
|
|
std::cerr << "p3Peers::AuthCertificate() OK ... Adding as Friend";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
2008-01-25 02:58:29 -05:00
|
|
|
/* add in as a friend */
|
|
|
|
return mConnMgr->addFriend(id);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool p3Peers::SignCertificate(std::string id)
|
|
|
|
{
|
|
|
|
#ifdef P3PEERS_DEBUG
|
|
|
|
std::cerr << "p3Peers::SignCertificate() " << id;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
2010-01-13 15:58:58 -05:00
|
|
|
return AuthSSL::getAuthSSL()->SignCertificate(id);
|
2008-01-25 02:58:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
bool p3Peers::TrustCertificate(std::string id, bool trust)
|
|
|
|
{
|
|
|
|
#ifdef P3PEERS_DEBUG
|
|
|
|
std::cerr << "p3Peers::TrustCertificate() " << id;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
2010-01-13 15:58:58 -05:00
|
|
|
return AuthSSL::getAuthSSL()->TrustCertificate(id, trust);
|
2008-01-25 02:58:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int ensureExtension(std::string &name, std::string def_ext)
|
|
|
|
{
|
|
|
|
/* if it has an extension, don't change */
|
|
|
|
int len = name.length();
|
|
|
|
int extpos = name.find_last_of('.');
|
|
|
|
|
|
|
|
std::ostringstream out;
|
|
|
|
out << "ensureExtension() name: " << name << std::endl;
|
|
|
|
out << "\t\t extpos: " << extpos;
|
|
|
|
out << " len: " << len << std::endl;
|
|
|
|
|
|
|
|
/* check that the '.' has between 1 and 4 char after it (an extension) */
|
|
|
|
if ((extpos > 0) && (extpos < len - 1) && (extpos + 6 > len))
|
|
|
|
{
|
|
|
|
/* extension there */
|
|
|
|
std::string curext = name.substr(extpos, len);
|
|
|
|
out << "ensureExtension() curext: " << curext << std::endl;
|
|
|
|
std::cerr << out.str();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (extpos != len - 1)
|
|
|
|
{
|
|
|
|
name += ".";
|
|
|
|
}
|
|
|
|
name += def_ext;
|
|
|
|
|
|
|
|
out << "ensureExtension() added ext: " << name << std::endl;
|
|
|
|
|
|
|
|
std::cerr << out.str();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
RsPeerDetails::RsPeerDetails()
|
2010-01-13 16:05:38 -05:00
|
|
|
:trustLvl(0), ownsign(false), state(0), netMode(0),
|
2008-01-25 02:58:29 -05:00
|
|
|
lastConnect(0), connectPeriod(0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::ostream &operator<<(std::ostream &out, const RsPeerDetails &detail)
|
|
|
|
{
|
|
|
|
out << "RsPeerDetail: " << detail.name << " <" << detail.id << ">";
|
|
|
|
out << std::endl;
|
|
|
|
|
|
|
|
out << " email: " << detail.email;
|
|
|
|
out << " location:" << detail.location;
|
|
|
|
out << " org: " << detail.org;
|
|
|
|
out << std::endl;
|
|
|
|
|
|
|
|
out << " fpr: " << detail.fpr;
|
|
|
|
out << " authcode:" << detail.authcode;
|
|
|
|
out << std::endl;
|
|
|
|
|
|
|
|
out << " signers:";
|
|
|
|
out << std::endl;
|
|
|
|
|
|
|
|
std::list<std::string>::const_iterator it;
|
|
|
|
for(it = detail.signers.begin();
|
|
|
|
it != detail.signers.end(); it++)
|
|
|
|
{
|
|
|
|
out << "\t" << *it;
|
|
|
|
out << std::endl;
|
|
|
|
}
|
|
|
|
out << std::endl;
|
|
|
|
|
|
|
|
out << " trustLvl: " << detail.trustLvl;
|
2010-01-13 16:05:38 -05:00
|
|
|
out << " ownSign: " << detail.ownsign;
|
2008-01-25 02:58:29 -05:00
|
|
|
out << std::endl;
|
|
|
|
|
|
|
|
out << " state: " << detail.state;
|
|
|
|
out << " netMode: " << detail.netMode;
|
|
|
|
out << std::endl;
|
|
|
|
|
|
|
|
out << " localAddr: " << detail.localAddr;
|
|
|
|
out << ":" << detail.localPort;
|
|
|
|
out << std::endl;
|
|
|
|
out << " extAddr: " << detail.extAddr;
|
|
|
|
out << ":" << detail.extPort;
|
|
|
|
out << std::endl;
|
|
|
|
|
|
|
|
|
|
|
|
out << " lastConnect: " << detail.lastConnect;
|
|
|
|
out << " connectPeriod: " << detail.connectPeriod;
|
|
|
|
out << std::endl;
|
|
|
|
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/********** TRANSLATION ****/
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t RsPeerTranslateTrust(uint32_t trustLvl)
|
|
|
|
{
|
2008-11-09 11:52:14 -05:00
|
|
|
/**************** PQI_USE_XPGP ******************/
|
|
|
|
#if defined(PQI_USE_XPGP)
|
2008-01-25 02:58:29 -05:00
|
|
|
switch(trustLvl)
|
|
|
|
{
|
|
|
|
case TRUST_SIGN_OWN:
|
|
|
|
case TRUST_SIGN_TRSTED:
|
|
|
|
case TRUST_SIGN_AUTHEN:
|
|
|
|
return RS_TRUST_LVL_GOOD;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TRUST_SIGN_BASIC:
|
|
|
|
return RS_TRUST_LVL_MARGINAL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TRUST_SIGN_UNTRUSTED:
|
|
|
|
case TRUST_SIGN_UNKNOWN:
|
|
|
|
case TRUST_SIGN_NONE:
|
|
|
|
default:
|
|
|
|
return RS_TRUST_LVL_UNKNOWN;
|
|
|
|
break;
|
|
|
|
}
|
2008-11-09 11:52:14 -05:00
|
|
|
#else /* X509 Certificates */
|
|
|
|
/**************** PQI_USE_XPGP ******************/
|
|
|
|
#endif /* X509 Certificates */
|
|
|
|
/**************** PQI_USE_XPGP ******************/
|
|
|
|
|
2008-01-25 02:58:29 -05:00
|
|
|
return RS_TRUST_LVL_UNKNOWN;
|
|
|
|
}
|
|
|
|
|