mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-13 08:29:32 -05:00
NETWORK REWORK (cont)
* removing old tests and unused code. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3220 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
bfa9965c9b
commit
713d956882
@ -1,362 +0,0 @@
|
||||
|
||||
|
||||
#include "pqi/p3connmgr.h"
|
||||
|
||||
|
||||
/***** Test for the new DHT system *****/
|
||||
|
||||
|
||||
#include "util/rsnet.h"
|
||||
#include "util/rsthreads.h"
|
||||
#include "util/rsprint.h"
|
||||
#include "pqi/p3dhtmgr.h"
|
||||
#include "pqi/p3connmgr.h"
|
||||
#include "pqi/pqisecurity.h"
|
||||
#include "pqi/pqipersongrp.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
#include "tcponudp/udpsorter.h"
|
||||
|
||||
/***** Test Framework *****/
|
||||
|
||||
const int NumOfPeers = 10;
|
||||
std::string peerIds[NumOfPeers] =
|
||||
{"PEER01",
|
||||
"PEER02", /* Always online, no notify */
|
||||
"PEER03", /* notify/online at 20sec */
|
||||
"PEER04", /* Always online, notify at 30 sec */
|
||||
"PEER05",
|
||||
"PEER06", /* notify/online at 50sec */
|
||||
"PEER07",
|
||||
"PEER08",
|
||||
"PEER09", /* notify/online at 80sec */
|
||||
"PEER10"};
|
||||
|
||||
#define STUN_PORT 7777
|
||||
|
||||
std::string ownId = "OWNID-AAAA";
|
||||
time_t ownPublishTs;
|
||||
|
||||
RsMutex frmMtx;
|
||||
std::list<std::string> searchIds;
|
||||
std::list<uint32_t> searchModes;
|
||||
|
||||
std::map<std::string, bool> onlineMap;
|
||||
std::map<uint32_t, std::string> notifyMap;
|
||||
|
||||
void initTestData()
|
||||
{
|
||||
ownPublishTs = 0;
|
||||
/* setup Peers that are online always */
|
||||
bool online;
|
||||
uint32_t ts;
|
||||
for(int i = 0; i < NumOfPeers; i++)
|
||||
{
|
||||
online = false;
|
||||
if ((i == 1) || (i == 3))
|
||||
{
|
||||
online = true;
|
||||
}
|
||||
onlineMap[peerIds[i]] = online;
|
||||
|
||||
if ((i == 2) || (i == 3) ||
|
||||
(i == 5) || (i == 8))
|
||||
{
|
||||
ts = i * 10;
|
||||
notifyMap[ts] = peerIds[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void respondPublish()
|
||||
{
|
||||
frmMtx.lock(); /* LOCK TEST FRAMEWORK MUTEX */
|
||||
if (!ownPublishTs)
|
||||
{
|
||||
std::cerr << "Own ID first published!" << std::endl;
|
||||
ownPublishTs = time(NULL);
|
||||
}
|
||||
frmMtx.unlock(); /* UNLOCK TEST FRAMEWORK MUTEX */
|
||||
}
|
||||
|
||||
void respondSearch(p3DhtMgr *mgr, std::string id, uint32_t mode)
|
||||
{
|
||||
std::cerr << "Checking for Search Results" << std::endl;
|
||||
time_t now = time(NULL);
|
||||
bool doNotify = false;
|
||||
bool doOnline = false;
|
||||
std::string notifyId;
|
||||
|
||||
frmMtx.lock(); /* LOCK TEST FRAMEWORK MUTEX */
|
||||
if ((mode == DHT_MODE_NOTIFY) && (ownPublishTs))
|
||||
{
|
||||
/* */
|
||||
std::map<uint32_t, std::string>::iterator it;
|
||||
uint32_t delta_t = now - ownPublishTs;
|
||||
it = notifyMap.begin();
|
||||
if (it != notifyMap.end())
|
||||
{
|
||||
if (it->first <= delta_t)
|
||||
{
|
||||
notifyId = it->second;
|
||||
onlineMap[notifyId] = true;
|
||||
notifyMap.erase(it);
|
||||
doNotify = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (mode == DHT_MODE_SEARCH)
|
||||
{
|
||||
|
||||
/* translate */
|
||||
std::map<std::string, bool>::iterator mit;
|
||||
for(mit = onlineMap.begin(); (mit != onlineMap.end()) &&
|
||||
(RsUtil::HashId(mit->first, false) != id); mit++);
|
||||
|
||||
if (mit != onlineMap.end())
|
||||
{
|
||||
doOnline = mit->second;
|
||||
}
|
||||
}
|
||||
|
||||
frmMtx.unlock(); /* UNLOCK TEST FRAMEWORK MUTEX */
|
||||
|
||||
uint32_t type = 0;
|
||||
|
||||
struct sockaddr_in laddr;
|
||||
inet_aton("10.0.0.129", &(laddr.sin_addr));
|
||||
laddr.sin_port = htons(7812);
|
||||
laddr.sin_family = AF_INET;
|
||||
|
||||
struct sockaddr_in raddr;
|
||||
inet_aton("127.0.0.1", &(raddr.sin_addr));
|
||||
raddr.sin_port = htons(STUN_PORT);
|
||||
raddr.sin_family = AF_INET;
|
||||
|
||||
if (doNotify)
|
||||
{
|
||||
std::cerr << "Responding to Notify: id:" << notifyId << std::endl;
|
||||
mgr->dhtResultNotify(RsUtil::HashId(notifyId, true));
|
||||
}
|
||||
|
||||
if (doOnline)
|
||||
{
|
||||
std::cerr << "Responding to Search" << std::endl;
|
||||
mgr->dhtResultSearch(id, laddr, raddr, type, "");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/***** Test Framework *****/
|
||||
|
||||
class DhtMgrTester: public p3DhtMgr
|
||||
{
|
||||
|
||||
/* Implementation */
|
||||
public:
|
||||
|
||||
DhtMgrTester(std::string id, pqiConnectCb *cb)
|
||||
:p3DhtMgr(id, cb)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* Blocking calls (only from thread) */
|
||||
virtual bool dhtPublish(std::string id,
|
||||
struct sockaddr_in &laddr, struct sockaddr_in &raddr,
|
||||
uint32_t type, std::string sign)
|
||||
{
|
||||
std::cerr << "DhtMgrTester::dhtPublish() id: " << RsUtil::BinToHex(id);
|
||||
std::cerr << " laddr: " << inet_ntoa(laddr.sin_addr) << " lport: " << ntohs(laddr.sin_port);
|
||||
std::cerr << " raddr: " << inet_ntoa(raddr.sin_addr) << " rport: " << ntohs(raddr.sin_port);
|
||||
std::cerr << " type: " << type << " sign: " << sign;
|
||||
std::cerr << std::endl;
|
||||
|
||||
respondPublish();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool dhtNotify(std::string peerid, std::string ownid, std::string sign)
|
||||
{
|
||||
std::cerr << "DhtMgrTester::dhtNotify() id: " << RsUtil::BinToHex(peerid) << ", ownId: " << RsUtil::BinToHex(ownId);
|
||||
std::cerr << " sign: " << sign;
|
||||
std::cerr << std::endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool dhtSearch(std::string id, uint32_t mode)
|
||||
{
|
||||
std::cerr << "DhtMgrTester::dhtSearch(id: " << RsUtil::BinToHex(id) << ", mode: " << mode << ")" << std::endl;
|
||||
|
||||
frmMtx.lock(); /* LOCK TEST FRAMEWORK MUTEX */
|
||||
searchIds.push_back(id);
|
||||
searchModes.push_back(mode);
|
||||
frmMtx.unlock(); /* LOCK TEST FRAMEWORK MUTEX */
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
/* OVERLOAD THE ConnMgr - to insert peers */
|
||||
class p3TestConnMgr: public p3ConnectMgr
|
||||
{
|
||||
public:
|
||||
p3TestConnMgr(int mode)
|
||||
:p3ConnectMgr(new p3DummyAuthMgr()), mTestMode(mode) { return; }
|
||||
|
||||
protected:
|
||||
/* must be virtual for testing */
|
||||
virtual void loadConfiguration()
|
||||
{
|
||||
|
||||
/* setup own address */
|
||||
ownState.id = ownId;
|
||||
ownState.name = "SELF NAME";
|
||||
ownState.localaddr.sin_family = AF_INET;
|
||||
inet_aton("127.0.0.1", &(ownState.localaddr.sin_addr));
|
||||
ownState.localaddr.sin_port = htons(7812);
|
||||
ownState.netMode = RS_NET_MODE_UDP;
|
||||
ownState.visState = RS_VIS_STATE_STD;
|
||||
|
||||
/* others not important */
|
||||
//ownState.state = 0;
|
||||
//ownState.actions = 0;
|
||||
|
||||
|
||||
if (mTestMode == 1) /* Add to Stun List */
|
||||
{
|
||||
for(int i = 0; i < NumOfPeers; i++)
|
||||
{
|
||||
mStunList.push_back(peerIds[i]);
|
||||
}
|
||||
}
|
||||
else if (mTestMode == 2) /* add to peers */
|
||||
{
|
||||
/* add in as peers */
|
||||
//addPeer();
|
||||
for(int i = 0; i < NumOfPeers; i++)
|
||||
{
|
||||
if (i < 5)
|
||||
{
|
||||
mStunList.push_back(RsUtil::HashId(peerIds[i]));
|
||||
}
|
||||
else
|
||||
{
|
||||
addFriend(peerIds[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
uint32_t mTestMode;
|
||||
};
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
time_t startTime = time(NULL);
|
||||
/* setup system */
|
||||
initTestData();
|
||||
|
||||
/* setup a Stunner to respond to ConnMgr */
|
||||
|
||||
struct sockaddr_in saddr;
|
||||
saddr.sin_family = AF_INET;
|
||||
inet_aton("127.0.0.1", &(saddr.sin_addr));
|
||||
saddr.sin_port = htons(STUN_PORT);
|
||||
UdpSorter stunner(saddr); /* starts a receiving thread */
|
||||
|
||||
p3TestConnMgr connMgr(2);
|
||||
DhtMgrTester dhtTester(ownId, &connMgr);
|
||||
|
||||
/* now add in some peers */
|
||||
connMgr.setDhtMgr(&dhtTester);
|
||||
connMgr.setUpnpMgr(NULL);
|
||||
|
||||
/************ ADD pqipersongrp as pqimonitor *****************/
|
||||
|
||||
SecurityPolicy *pol = secpolicy_create();
|
||||
unsigned long flags = 0;
|
||||
pqipersongrp *pqipg = new pqipersongrpDummy(pol, flags);
|
||||
|
||||
connMgr.addMonitor(pqipg);
|
||||
|
||||
/************ ADD pqipersongrp as pqimonitor *****************/
|
||||
|
||||
|
||||
/* startup dht */
|
||||
std::cerr << "Starting up DhtTester()" << std::endl;
|
||||
dhtTester.start();
|
||||
|
||||
/* wait for a little before switching on */
|
||||
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
||||
#ifndef WINDOWS_SYS
|
||||
sleep(1);
|
||||
#else
|
||||
Sleep(1000);
|
||||
#endif
|
||||
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
||||
|
||||
std::cerr << "Switching on DhtTester()" << std::endl;
|
||||
dhtTester.setDhtOn(true);
|
||||
|
||||
/* wait loop */
|
||||
while(1)
|
||||
{
|
||||
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
||||
#ifndef WINDOWS_SYS
|
||||
sleep(1);
|
||||
#else
|
||||
Sleep(1000);
|
||||
#endif
|
||||
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
||||
|
||||
connMgr.tick();
|
||||
pqipg->tick();
|
||||
|
||||
/* handle async search */
|
||||
frmMtx.lock(); /* LOCK TEST FRAMEWORK MUTEX */
|
||||
|
||||
std::string id;
|
||||
uint32_t mode;
|
||||
bool doRespond = false;
|
||||
if (searchIds.size() > 0)
|
||||
{
|
||||
id = searchIds.front();
|
||||
mode = searchModes.front();
|
||||
doRespond = true;
|
||||
searchIds.pop_front();
|
||||
searchModes.pop_front();
|
||||
}
|
||||
|
||||
frmMtx.unlock(); /* UNLOCK TEST FRAMEWORK MUTEX */
|
||||
|
||||
if (doRespond)
|
||||
{
|
||||
respondSearch(&dhtTester, id, mode);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,310 +0,0 @@
|
||||
|
||||
|
||||
/***** Test for the new DHT system *****/
|
||||
|
||||
|
||||
#include "pqi/pqinetwork.h"
|
||||
|
||||
#include "util/rsnet.h"
|
||||
#include "util/rsthreads.h"
|
||||
#include "util/rsprint.h"
|
||||
|
||||
#include "pqi/p3dhtmgr.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
|
||||
/***** Test Framework *****/
|
||||
|
||||
const int NumOfPeers = 10;
|
||||
std::string peerIds[NumOfPeers] =
|
||||
{"PEER01",
|
||||
"PEER02", /* Always online, no notify */
|
||||
"PEER03", /* notify/online at 20sec */
|
||||
"PEER04", /* Always online, notify at 30 sec */
|
||||
"PEER05",
|
||||
"PEER06", /* notify/online at 50sec */
|
||||
"PEER07",
|
||||
"PEER08",
|
||||
"PEER09", /* notify/online at 80sec */
|
||||
"PEER10"};
|
||||
|
||||
std::string ownId = "AAAA";
|
||||
time_t ownPublishTs;
|
||||
|
||||
RsMutex frmMtx;
|
||||
std::list<std::string> searchIds;
|
||||
std::list<uint32_t> searchModes;
|
||||
|
||||
std::map<std::string, bool> onlineMap;
|
||||
std::map<uint32_t, std::string> notifyMap;
|
||||
|
||||
void initTestData()
|
||||
{
|
||||
ownPublishTs = 0;
|
||||
/* setup Peers that are online always */
|
||||
bool online;
|
||||
uint32_t ts;
|
||||
for(int i = 0; i < NumOfPeers; i++)
|
||||
{
|
||||
online = false;
|
||||
if ((i == 1) || (i == 3))
|
||||
{
|
||||
online = true;
|
||||
}
|
||||
onlineMap[peerIds[i]] = online;
|
||||
|
||||
if ((i == 2) || (i == 3) ||
|
||||
(i == 5) || (i == 8))
|
||||
{
|
||||
ts = i * 10;
|
||||
notifyMap[ts] = peerIds[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void respondPublish()
|
||||
{
|
||||
frmMtx.lock(); /* LOCK TEST FRAMEWORK MUTEX */
|
||||
if (!ownPublishTs)
|
||||
{
|
||||
std::cerr << "Own ID first published!" << std::endl;
|
||||
ownPublishTs = time(NULL);
|
||||
}
|
||||
frmMtx.unlock(); /* UNLOCK TEST FRAMEWORK MUTEX */
|
||||
}
|
||||
|
||||
void respondSearch(p3DhtMgr *mgr, std::string id, uint32_t mode)
|
||||
{
|
||||
std::cerr << "Checking for Search Results" << std::endl;
|
||||
time_t now = time(NULL);
|
||||
bool doNotify = false;
|
||||
bool doOnline = false;
|
||||
std::string notifyId;
|
||||
|
||||
frmMtx.lock(); /* LOCK TEST FRAMEWORK MUTEX */
|
||||
if ((mode == DHT_MODE_NOTIFY) && (ownPublishTs))
|
||||
{
|
||||
/* */
|
||||
std::map<uint32_t, std::string>::iterator it;
|
||||
uint32_t delta_t = now - ownPublishTs;
|
||||
it = notifyMap.begin();
|
||||
if (it != notifyMap.end())
|
||||
{
|
||||
if (it->first <= delta_t)
|
||||
{
|
||||
notifyId = it->second;
|
||||
onlineMap[notifyId] = true;
|
||||
notifyMap.erase(it);
|
||||
doNotify = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (mode == DHT_MODE_SEARCH)
|
||||
{
|
||||
/* translate */
|
||||
std::map<std::string, bool>::iterator mit;
|
||||
for(mit = onlineMap.begin(); (mit != onlineMap.end()) &&
|
||||
(RsUtil::HashId(mit->first, false) != id); mit++);
|
||||
|
||||
if (mit != onlineMap.end())
|
||||
{
|
||||
doOnline = mit->second;
|
||||
}
|
||||
}
|
||||
|
||||
frmMtx.unlock(); /* UNLOCK TEST FRAMEWORK MUTEX */
|
||||
|
||||
uint32_t type = 0;
|
||||
|
||||
struct sockaddr_in laddr;
|
||||
inet_aton("10.0.0.129", &(laddr.sin_addr));
|
||||
laddr.sin_port = htons(7812);
|
||||
laddr.sin_family = AF_INET;
|
||||
|
||||
struct sockaddr_in raddr;
|
||||
inet_aton("10.0.0.19", &(raddr.sin_addr));
|
||||
raddr.sin_port = htons(7812);
|
||||
raddr.sin_family = AF_INET;
|
||||
|
||||
if (doNotify)
|
||||
{
|
||||
std::cerr << "Responding to Notify" << std::endl;
|
||||
mgr->dhtResultNotify(RsUtil::HashId(notifyId, true));
|
||||
}
|
||||
|
||||
if (doOnline)
|
||||
{
|
||||
std::cerr << "Responding to Search" << std::endl;
|
||||
mgr->dhtResultSearch(id, laddr, raddr, type, "");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/***** Test Framework *****/
|
||||
|
||||
|
||||
|
||||
|
||||
class DhtMgrTester: public p3DhtMgr
|
||||
{
|
||||
|
||||
/* Implementation */
|
||||
public:
|
||||
|
||||
DhtMgrTester(std::string id, pqiConnectCb *cb)
|
||||
:p3DhtMgr(id, cb)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/* Blocking calls (only from thread) */
|
||||
virtual bool dhtPublish(std::string id,
|
||||
struct sockaddr_in &laddr, struct sockaddr_in &raddr,
|
||||
uint32_t type, std::string sign)
|
||||
{
|
||||
std::cerr << "DhtMgrTester::dhtPublish() id: " << RsUtil::BinToHex(id);
|
||||
std::cerr << " laddr: " << inet_ntoa(laddr.sin_addr) << " lport: " << ntohs(laddr.sin_port);
|
||||
std::cerr << " raddr: " << inet_ntoa(raddr.sin_addr) << " rport: " << ntohs(raddr.sin_port);
|
||||
std::cerr << " type: " << type << " sign: " << sign;
|
||||
std::cerr << std::endl;
|
||||
|
||||
respondPublish();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool dhtNotify(std::string peerid, std::string ownid, std::string sign)
|
||||
{
|
||||
std::cerr << "DhtMgrTester::dhtNotify() id: " << RsUtil::BinToHex(peerid) << ", ownId: " << RsUtil::BinToHex(ownId);
|
||||
std::cerr << " sign: " << sign;
|
||||
std::cerr << std::endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool dhtSearch(std::string id, uint32_t mode)
|
||||
{
|
||||
std::cerr << "DhtMgrTester::dhtSearch(id: " << RsUtil::BinToHex(id) << ", mode: " << mode << ")" << std::endl;
|
||||
|
||||
frmMtx.lock(); /* LOCK TEST FRAMEWORK MUTEX */
|
||||
searchIds.push_back(id);
|
||||
searchModes.push_back(mode);
|
||||
frmMtx.unlock(); /* LOCK TEST FRAMEWORK MUTEX */
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
time_t startTime = time(NULL);
|
||||
bool haveOwnAddress = false;
|
||||
/* setup system */
|
||||
initTestData();
|
||||
|
||||
pqiConnectCbDummy cbTester;
|
||||
DhtMgrTester dhtTester(ownId, &cbTester);
|
||||
|
||||
/* now add in some peers */
|
||||
|
||||
/* startup dht */
|
||||
std::cerr << "Starting up DhtTester()" << std::endl;
|
||||
dhtTester.start();
|
||||
|
||||
/* wait for a little before switching on */
|
||||
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
||||
#ifndef WINDOWS_SYS
|
||||
sleep(1);
|
||||
#else
|
||||
Sleep(1000);
|
||||
#endif
|
||||
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
||||
|
||||
std::cerr << "Switching on DhtTester()" << std::endl;
|
||||
dhtTester.enable(true);
|
||||
|
||||
std::cerr << "Adding a List of Peers" << std::endl;
|
||||
for(int i = 0; i < NumOfPeers; i++)
|
||||
{
|
||||
dhtTester.findPeer(peerIds[i]);
|
||||
}
|
||||
|
||||
|
||||
/* wait loop */
|
||||
while(1)
|
||||
{
|
||||
std::cerr << "Main waiting..." << std::endl;
|
||||
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
||||
#ifndef WINDOWS_SYS
|
||||
sleep(3);
|
||||
#else
|
||||
Sleep(3000);
|
||||
#endif
|
||||
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
||||
|
||||
|
||||
/* handle async search */
|
||||
frmMtx.lock(); /* LOCK TEST FRAMEWORK MUTEX */
|
||||
|
||||
std::string id;
|
||||
uint32_t mode;
|
||||
bool doRespond = false;
|
||||
if (searchIds.size() > 0)
|
||||
{
|
||||
id = searchIds.front();
|
||||
mode = searchModes.front();
|
||||
doRespond = true;
|
||||
searchIds.pop_front();
|
||||
searchModes.pop_front();
|
||||
}
|
||||
|
||||
frmMtx.unlock(); /* UNLOCK TEST FRAMEWORK MUTEX */
|
||||
|
||||
if (doRespond)
|
||||
{
|
||||
respondSearch(&dhtTester, id, mode);
|
||||
}
|
||||
|
||||
if (!haveOwnAddress)
|
||||
{
|
||||
if (time(NULL) - startTime > 20)
|
||||
{
|
||||
std::cerr << "Setting Own Address!" << std::endl;
|
||||
haveOwnAddress = true;
|
||||
|
||||
uint32_t type = DHT_ADDR_UDP;
|
||||
|
||||
struct sockaddr_in laddr;
|
||||
inet_aton("10.0.0.111", &(laddr.sin_addr));
|
||||
laddr.sin_port = htons(7812);
|
||||
laddr.sin_family = AF_INET;
|
||||
|
||||
struct sockaddr_in raddr;
|
||||
inet_aton("10.0.0.11", &(raddr.sin_addr));
|
||||
raddr.sin_port = htons(7812);
|
||||
raddr.sin_family = AF_INET;
|
||||
|
||||
dhtTester.setExternalInterface(laddr, raddr, type);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,76 +0,0 @@
|
||||
|
||||
#include "pqi/authgpg.h"
|
||||
|
||||
const std::string key_path("./tmp/privkey.pem");
|
||||
const std::string passwd("8764");
|
||||
const std::string gpg_passwd("aaaa");
|
||||
const std::string name("Test X509");
|
||||
const std::string email("test@email.com");
|
||||
const std::string org("Org");
|
||||
const std::string loc("Loc");
|
||||
const std::string state("State");
|
||||
const std::string country("GB");
|
||||
|
||||
int main()
|
||||
{
|
||||
/* Init the auth manager */
|
||||
|
||||
GPGAuthMgr mgr;
|
||||
|
||||
|
||||
/* Select which GPG Keys we use */
|
||||
|
||||
/* print all keys */
|
||||
mgr.printKeys();
|
||||
|
||||
std::list<std::string> idList;
|
||||
mgr.availablePGPCertificates(idList);
|
||||
|
||||
if (idList.size() < 1)
|
||||
{
|
||||
fprintf(stderr, "No GPG Certificate to use!\n");
|
||||
exit(1);
|
||||
}
|
||||
std::string id = idList.front();
|
||||
fprintf(stderr, "Using GPG Certificate:%s \n", id.c_str());
|
||||
|
||||
std::string noname;
|
||||
mgr.GPGInit(id);
|
||||
mgr.LoadGPGPassword(gpg_passwd);
|
||||
|
||||
/* Init SSL library */
|
||||
mgr.InitAuth(NULL, NULL, NULL);
|
||||
|
||||
/* then try to generate and sign a X509 certificate */
|
||||
int nbits_in = 2048;
|
||||
std::string errString;
|
||||
|
||||
/* Generate a Certificate Request */
|
||||
X509_REQ *req = GenerateX509Req(key_path, passwd, name, email, org,
|
||||
loc, state, country, nbits_in, errString);
|
||||
|
||||
// setup output.
|
||||
BIO *bio_out = NULL;
|
||||
bio_out = BIO_new(BIO_s_file());
|
||||
BIO_set_fp(bio_out,stdout,BIO_NOCLOSE);
|
||||
|
||||
/* Print it out */
|
||||
int nmflag = 0;
|
||||
int reqflag = 0;
|
||||
|
||||
X509_REQ_print_ex(bio_out, req, nmflag, reqflag);
|
||||
|
||||
X509 *x509 = mgr.SignX509Req(req, 100, gpg_passwd);
|
||||
|
||||
X509_print_ex(bio_out, x509, nmflag, reqflag);
|
||||
|
||||
BIO_flush(bio_out);
|
||||
BIO_free(bio_out);
|
||||
|
||||
/* now try to validate it */
|
||||
mgr.AuthX509(x509);
|
||||
|
||||
//sleep(10);
|
||||
}
|
||||
|
||||
|
@ -1,264 +0,0 @@
|
||||
/*
|
||||
* libretroshare/src/pqi net_test.cc
|
||||
*
|
||||
* 3P/PQI network interface for RetroShare.
|
||||
*
|
||||
* Copyright 2007-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".
|
||||
*
|
||||
*/
|
||||
|
||||
/******
|
||||
* NETWORKING Test to check Big/Little Endian behaviour
|
||||
* as well as socket behaviour
|
||||
*
|
||||
*/
|
||||
|
||||
#include "pqi/pqinetwork.h"
|
||||
#include "util/rsnet.h"
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
|
||||
bool test_byte_manipulation();
|
||||
bool test_address_manipulation();
|
||||
bool test_address_listen();
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
|
||||
test_byte_manipulation();
|
||||
test_address_manipulation();
|
||||
test_address_listen();
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* test 1: byte manipulation */
|
||||
bool test_byte_manipulation()
|
||||
{
|
||||
uint64_t num1 = 0x0000000000000000ffULL; /* 255 */
|
||||
uint64_t num2 = 0x00000000000000ff00ULL; /* */
|
||||
|
||||
uint64_t n_num1 = htonll(num1);
|
||||
uint64_t n_num2 = htonll(num2);
|
||||
|
||||
uint64_t h_num1 = ntohll(n_num1);
|
||||
uint64_t h_num2 = ntohll(n_num2);
|
||||
|
||||
std::ostringstream out;
|
||||
out << std::hex;
|
||||
out << "num1: " << num1 << " netOrder: " << n_num1 << " hostOrder: " << h_num1 << std::endl;
|
||||
out << "num2: " << num2 << " netOrder: " << n_num2 << " hostOrder: " << h_num2 << std::endl;
|
||||
|
||||
std::cerr << out.str();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
const char * loopback_addrstr = "127.0.0.1";
|
||||
const char * localnet1_addrstr = "192.168.0.1";
|
||||
const char * localnet2_addrstr = "10.0.0.1";
|
||||
const char * localnet3_addrstr = "10.5.63.78";
|
||||
const char * localnet4_addrstr = "192.168.74.91";
|
||||
|
||||
/* test 2: address manipulation */
|
||||
bool test_address_manipulation()
|
||||
{
|
||||
struct sockaddr_in loopback_addr;
|
||||
struct sockaddr_in localnet1_addr;
|
||||
struct sockaddr_in localnet2_addr;
|
||||
struct sockaddr_in localnet3_addr;
|
||||
struct sockaddr_in localnet4_addr;
|
||||
|
||||
/* setup some addresses */
|
||||
inet_aton(loopback_addrstr, &(loopback_addr.sin_addr));
|
||||
inet_aton(localnet1_addrstr, &(localnet1_addr.sin_addr));
|
||||
inet_aton(localnet2_addrstr, &(localnet2_addr.sin_addr));
|
||||
inet_aton(localnet3_addrstr, &(localnet3_addr.sin_addr));
|
||||
inet_aton(localnet4_addrstr, &(localnet4_addr.sin_addr));
|
||||
|
||||
|
||||
std::cerr << "Loopback Addr" << inet_ntoa(loopback_addr.sin_addr);
|
||||
std::cerr << std::endl;
|
||||
|
||||
std::cerr << "Localnet1 Addr" << inet_ntoa(localnet1_addr.sin_addr);
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "Localnet2 Addr" << inet_ntoa(localnet2_addr.sin_addr);
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "Localnet3 Addr" << inet_ntoa(localnet3_addr.sin_addr);
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "Localnet4 Addr" << inet_ntoa(localnet4_addr.sin_addr);
|
||||
std::cerr << std::endl;
|
||||
std::cerr << std::endl;
|
||||
|
||||
std::cerr << "Test 1a - networks";
|
||||
std::cerr << std::endl;
|
||||
|
||||
struct sockaddr_in addr_ans, addr1, addr2;
|
||||
|
||||
inet_aton("127.0.0.0", &(addr_ans.sin_addr));
|
||||
addr1.sin_addr.s_addr = inet_netof(loopback_addr.sin_addr);
|
||||
addr2.sin_addr.s_addr = inet_network(loopback_addrstr);
|
||||
|
||||
std::cerr << "Loopback Net(expected): 127.0.0.0 ->" << inet_ntoa(addr_ans.sin_addr);
|
||||
std::cerr << " Net(1):" << inet_ntoa(addr1.sin_addr);
|
||||
std::cerr << " Net(2):" << inet_ntoa(addr2.sin_addr);
|
||||
std::cerr << std::endl;
|
||||
|
||||
inet_aton("192.168.0.0", &(addr_ans.sin_addr));
|
||||
addr1.sin_addr.s_addr = inet_netof(localnet1_addr.sin_addr);
|
||||
addr2.sin_addr.s_addr = inet_network(localnet1_addrstr);
|
||||
|
||||
std::cerr << "Localnet1 Net(expected): 192.168.0.0 ->" << inet_ntoa(addr_ans.sin_addr);
|
||||
std::cerr << " Net(1):" << inet_ntoa(addr1.sin_addr);
|
||||
std::cerr << " Net(2):" << inet_ntoa(addr2.sin_addr);
|
||||
std::cerr << std::endl;
|
||||
|
||||
inet_aton("10.0.0.0", &(addr_ans.sin_addr));
|
||||
addr1.sin_addr.s_addr = inet_netof(localnet2_addr.sin_addr);
|
||||
addr2.sin_addr.s_addr = inet_network(localnet2_addrstr);
|
||||
|
||||
std::cerr << "Localnet2 Net(expected): 10.0.0.0 ->" << inet_ntoa(addr_ans.sin_addr);
|
||||
std::cerr << " Net(1):" << inet_ntoa(addr1.sin_addr);
|
||||
std::cerr << " Net(2):" << inet_ntoa(addr2.sin_addr);
|
||||
std::cerr << std::endl;
|
||||
|
||||
|
||||
inet_aton("10.0.0.0", &(addr_ans.sin_addr));
|
||||
addr1.sin_addr.s_addr = inet_netof(localnet3_addr.sin_addr);
|
||||
addr2.sin_addr.s_addr = inet_network(localnet3_addrstr);
|
||||
|
||||
std::cerr << "Localnet3 Net(expected): 10.0.0.0 ->" << inet_ntoa(addr_ans.sin_addr);
|
||||
std::cerr << " Net(1):" << inet_ntoa(addr1.sin_addr);
|
||||
std::cerr << " Net(2):" << inet_ntoa(addr2.sin_addr);
|
||||
std::cerr << std::endl;
|
||||
|
||||
|
||||
inet_aton("192.168.0.0", &(addr_ans.sin_addr));
|
||||
addr1.sin_addr.s_addr = inet_netof(localnet4_addr.sin_addr);
|
||||
addr2.sin_addr.s_addr = inet_network(localnet4_addrstr);
|
||||
|
||||
std::cerr << "Localnet4 Net(expected): 192.168.0.0 -> " << inet_ntoa(addr_ans.sin_addr);
|
||||
std::cerr << " Net(1):" << inet_ntoa(addr1.sin_addr);
|
||||
std::cerr << " Net(2):" << inet_ntoa(addr2.sin_addr);
|
||||
std::cerr << std::endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#if 0
|
||||
|
||||
std::ostream &showSocketError(std::ostream &out);
|
||||
|
||||
std::string socket_errorType(int err);
|
||||
int sockaddr_cmp(struct sockaddr_in &addr1, struct sockaddr_in &addr2 );
|
||||
int inaddr_cmp(struct sockaddr_in addr1, struct sockaddr_in addr1 );
|
||||
int inaddr_cmp(struct sockaddr_in addr1, unsigned long);
|
||||
|
||||
std::list<std::string> getLocalInterfaces(); // returns all possible addrs.
|
||||
bool isExternalNet(struct in_addr *addr); // if Valid & is not Private or Loopback.
|
||||
bool isPrivateNet(struct in_addr *addr); // if inside 10.0.0.0 or
|
||||
// other then firewalled.
|
||||
bool isLoopbackNet(struct in_addr *addr);
|
||||
bool sameNet(struct in_addr *addr, struct in_addr *addr2);
|
||||
bool isValidNet(struct in_addr *addr);
|
||||
|
||||
// checks (addr1 & 255.255.255.0) == (addr2 & 255.255.255.0)
|
||||
bool isSameSubnet(struct in_addr *addr1, struct in_addr *addr2);
|
||||
|
||||
|
||||
struct in_addr getPreferredInterface(); // returns best addr.
|
||||
|
||||
in_addr_t pqi_inet_netof(struct in_addr addr); // our implementation.
|
||||
|
||||
bool LookupDNSAddr(std::string name, struct sockaddr_in &addr);
|
||||
|
||||
/* universal socket interface */
|
||||
|
||||
int unix_close(int sockfd);
|
||||
int unix_socket(int domain, int type, int protocol);
|
||||
int unix_fcntl_nonblock(int sockfd);
|
||||
int unix_connect(int sockfd, const struct sockaddr *serv_addr, socklen_t addrlen);
|
||||
int unix_getsockopt_error(int sockfd, int *err);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
bool test_bind_addr(struct sockaddr_in addr);
|
||||
|
||||
bool test_address_listen()
|
||||
{
|
||||
struct sockaddr_in addr1, addr2, addr3;
|
||||
|
||||
sockaddr_clear(&addr1);
|
||||
addr1.sin_family = AF_INET;
|
||||
inet_aton(loopback_addrstr, &(addr1.sin_addr));
|
||||
addr1.sin_port = htons(12345);
|
||||
|
||||
sockaddr_clear(&addr2);
|
||||
addr2.sin_family = AF_INET;
|
||||
addr2.sin_addr = getPreferredInterface(); // returns best addr.
|
||||
addr2.sin_port = htons(13245);
|
||||
|
||||
sockaddr_clear(&addr3);
|
||||
addr3.sin_family = AF_INET;
|
||||
addr3.sin_addr = getPreferredInterface(); // returns best addr.
|
||||
addr3.sin_port = htons(23451);
|
||||
|
||||
/* test bind to loopback, and preferred interfaces */
|
||||
test_bind_addr(addr1);
|
||||
test_bind_addr(addr2);
|
||||
test_bind_addr(addr3);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool test_bind_addr(struct sockaddr_in addr)
|
||||
{
|
||||
|
||||
int err;
|
||||
|
||||
std::cerr << "test_bind_addr()";
|
||||
std::cerr << std::endl;
|
||||
|
||||
std::cerr << "\tAddress Family: " << (int) addr.sin_family;
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "\tAddress: " << inet_ntoa(addr.sin_addr);
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "\tPort: " << ntohs(addr.sin_port);
|
||||
std::cerr << std::endl;
|
||||
|
||||
int sockfd = unix_socket(PF_INET, SOCK_STREAM, 0);
|
||||
|
||||
if (0 != (err = bind(sockfd, (struct sockaddr *) &addr, sizeof(addr))))
|
||||
{
|
||||
std::cerr << " Failed to Bind to Local Address!" << std::endl;
|
||||
showSocketError(std::cerr);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
std::cerr << " Successfully Bound Socket to Address" << std::endl;
|
||||
unix_close(sockfd);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1,268 +0,0 @@
|
||||
/*
|
||||
* libretroshare/src/pqi net_test.cc
|
||||
*
|
||||
* 3P/PQI network interface for RetroShare.
|
||||
*
|
||||
* Copyright 2007-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".
|
||||
*
|
||||
*/
|
||||
|
||||
/******
|
||||
* NETWORKING Test to check Big/Little Endian behaviour
|
||||
* as well as socket behaviour
|
||||
*
|
||||
*/
|
||||
|
||||
#include "pqi/pqinetwork.h"
|
||||
#include "util/rsnet.h"
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include "util/utest.h"
|
||||
|
||||
const char * loopback_addrstr = "127.0.0.1";
|
||||
|
||||
const char * localnet1_addrstr = "10.0.0.1";
|
||||
const char * localnet2_addrstr = "169.254.0.1";
|
||||
const char * localnet3_addrstr = "172.16.0.1";
|
||||
const char * localnet4_addrstr = "192.168.1.1";
|
||||
|
||||
const char * localnet5_addrstr = "10.4.28.34";
|
||||
const char * localnet6_addrstr = "169.254.1.81";
|
||||
const char * localnet7_addrstr = "172.20.9.201";
|
||||
const char * localnet8_addrstr = "192.168.1.254";
|
||||
|
||||
const char * external_addrstr = "74.125.19.99"; /* google */
|
||||
const char * invalid_addrstr = "AAA.BBB.256.256";
|
||||
|
||||
int test_isExternalNet();
|
||||
int test_isPrivateNet();
|
||||
int test_isLoopbackNet();
|
||||
int test_sameNet();
|
||||
int test_isValidNet();
|
||||
int test_isSameSubnet();
|
||||
int test_pqi_inet_netof();
|
||||
|
||||
INITTEST();
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
std::cerr << "net_test1" << std::endl;
|
||||
|
||||
test_isExternalNet();
|
||||
test_isPrivateNet();
|
||||
test_isLoopbackNet();
|
||||
test_sameNet();
|
||||
test_isValidNet();
|
||||
test_isSameSubnet();
|
||||
test_pqi_inet_netof();
|
||||
|
||||
FINALREPORT("net_test1");
|
||||
|
||||
return TESTRESULT();
|
||||
}
|
||||
|
||||
int test_isExternalNet()
|
||||
{
|
||||
struct in_addr loopback_addr;
|
||||
struct in_addr localnet1_addr;
|
||||
struct in_addr localnet2_addr;
|
||||
struct in_addr localnet3_addr;
|
||||
struct in_addr localnet4_addr;
|
||||
struct in_addr external_addr;
|
||||
struct in_addr invalid_addr;
|
||||
struct in_addr invalid_addr2;
|
||||
|
||||
inet_aton(loopback_addrstr, &loopback_addr);
|
||||
inet_aton(localnet1_addrstr, &localnet1_addr);
|
||||
inet_aton(localnet2_addrstr, &localnet2_addr);
|
||||
inet_aton(localnet3_addrstr, &localnet3_addr);
|
||||
inet_aton(localnet4_addrstr, &localnet4_addr);
|
||||
inet_aton(external_addrstr, &external_addr);
|
||||
invalid_addr.s_addr = 0;
|
||||
invalid_addr2.s_addr = -1;
|
||||
|
||||
CHECK(isExternalNet(&loopback_addr)==false);
|
||||
CHECK(isExternalNet(&localnet1_addr)==false);
|
||||
CHECK(isExternalNet(&localnet2_addr)==false);
|
||||
CHECK(isExternalNet(&localnet3_addr)==false);
|
||||
CHECK(isExternalNet(&localnet4_addr)==false);
|
||||
CHECK(isExternalNet(&external_addr)==true);
|
||||
CHECK(isExternalNet(&invalid_addr)==false);
|
||||
CHECK(isExternalNet(&invalid_addr2)==false);
|
||||
|
||||
REPORT("isExternalNet()");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int test_isPrivateNet()
|
||||
{
|
||||
struct in_addr loopback_addr;
|
||||
struct in_addr localnet1_addr;
|
||||
struct in_addr localnet2_addr;
|
||||
struct in_addr localnet3_addr;
|
||||
struct in_addr localnet4_addr;
|
||||
struct in_addr external_addr;
|
||||
|
||||
inet_aton(loopback_addrstr, &loopback_addr);
|
||||
inet_aton(localnet1_addrstr, &localnet1_addr);
|
||||
inet_aton(localnet2_addrstr, &localnet2_addr);
|
||||
inet_aton(localnet3_addrstr, &localnet3_addr);
|
||||
inet_aton(localnet4_addrstr, &localnet4_addr);
|
||||
inet_aton(external_addrstr, &external_addr);
|
||||
|
||||
CHECK(isPrivateNet(&loopback_addr)==false); //loopback not considered a "private network"
|
||||
CHECK(isPrivateNet(&localnet1_addr)==true);
|
||||
CHECK(isPrivateNet(&localnet2_addr)==true);
|
||||
CHECK(isPrivateNet(&localnet3_addr)==true);
|
||||
CHECK(isPrivateNet(&localnet4_addr)==true);
|
||||
CHECK(isPrivateNet(&external_addr)==false);
|
||||
|
||||
REPORT("isPrivateNet()");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int test_isLoopbackNet()
|
||||
{
|
||||
struct in_addr loopback_addr;
|
||||
struct in_addr localnet1_addr;
|
||||
struct in_addr external_addr;
|
||||
|
||||
inet_aton(loopback_addrstr, &loopback_addr);
|
||||
inet_aton(localnet1_addrstr, &localnet1_addr);
|
||||
inet_aton(external_addrstr, &external_addr);
|
||||
|
||||
CHECK(isLoopbackNet(&loopback_addr)==true);
|
||||
CHECK(isLoopbackNet(&localnet1_addr)==false);
|
||||
CHECK(isLoopbackNet(&external_addr)==false);
|
||||
|
||||
REPORT("isLoopbackNet()");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int test_sameNet()
|
||||
{
|
||||
struct in_addr localnet1_addr;
|
||||
struct in_addr localnet2_addr;
|
||||
struct in_addr localnet3_addr;
|
||||
struct in_addr localnet4_addr;
|
||||
struct in_addr localnet5_addr;
|
||||
struct in_addr localnet6_addr;
|
||||
struct in_addr localnet7_addr;
|
||||
struct in_addr localnet8_addr;
|
||||
struct in_addr external_addr;
|
||||
|
||||
inet_aton(localnet1_addrstr, &localnet1_addr);
|
||||
inet_aton(localnet2_addrstr, &localnet2_addr);
|
||||
inet_aton(localnet3_addrstr, &localnet3_addr);
|
||||
inet_aton(localnet4_addrstr, &localnet4_addr);
|
||||
inet_aton(localnet5_addrstr, &localnet5_addr);
|
||||
inet_aton(localnet6_addrstr, &localnet6_addr);
|
||||
inet_aton(localnet7_addrstr, &localnet7_addr);
|
||||
inet_aton(localnet8_addrstr, &localnet8_addr);
|
||||
inet_aton(external_addrstr, &external_addr);
|
||||
|
||||
CHECK(sameNet(&localnet1_addr, &localnet5_addr)==true);
|
||||
CHECK(sameNet(&localnet2_addr, &localnet6_addr)==true);
|
||||
CHECK(sameNet(&localnet3_addr, &localnet7_addr)==true);
|
||||
CHECK(sameNet(&localnet4_addr, &localnet8_addr)==true);
|
||||
CHECK(sameNet(&localnet1_addr, &external_addr)==false);
|
||||
CHECK(sameNet(&localnet2_addr, &external_addr)==false);
|
||||
CHECK(sameNet(&localnet3_addr, &external_addr)==false);
|
||||
CHECK(sameNet(&localnet4_addr, &external_addr)==false);
|
||||
|
||||
REPORT("sameNet()");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int test_isValidNet()
|
||||
{
|
||||
struct in_addr localnet1_addr;
|
||||
struct in_addr invalid_addr;
|
||||
|
||||
inet_aton(localnet1_addrstr, &localnet1_addr);
|
||||
CHECK(isValidNet(&localnet1_addr)==true);
|
||||
|
||||
CHECK(inet_aton(invalid_addrstr, &invalid_addr)==0);
|
||||
std::cerr << inet_ntoa(invalid_addr) << std::endl;
|
||||
//CHECK(isValidNet(&invalid_addr)==false);
|
||||
|
||||
REPORT("isValidNet()");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int test_isSameSubnet()
|
||||
{
|
||||
struct in_addr localnet1_addr;
|
||||
struct in_addr classc1_addr;
|
||||
struct in_addr classc2_addr;
|
||||
|
||||
inet_aton(localnet1_addrstr, &localnet1_addr);
|
||||
//random class C addresses
|
||||
inet_aton("197.67.28.93", &classc1_addr);
|
||||
inet_aton("197.67.28.3", &classc2_addr);
|
||||
|
||||
CHECK(isSameSubnet(&localnet1_addr, &classc1_addr)==false);
|
||||
CHECK(isSameSubnet(&classc1_addr, &classc2_addr)==true);
|
||||
|
||||
REPORT("isSameSubnet()");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int test_pqi_inet_netof()
|
||||
{
|
||||
struct in_addr localnet1_addr;
|
||||
struct in_addr localnet2_addr;
|
||||
struct in_addr localnet3_addr;
|
||||
struct in_addr localnet4_addr;
|
||||
struct in_addr localnet5_addr;
|
||||
struct in_addr localnet6_addr;
|
||||
struct in_addr localnet7_addr;
|
||||
struct in_addr localnet8_addr;
|
||||
struct in_addr external_addr;
|
||||
|
||||
inet_aton(localnet1_addrstr, &localnet1_addr);
|
||||
inet_aton(localnet2_addrstr, &localnet2_addr);
|
||||
inet_aton(localnet3_addrstr, &localnet3_addr);
|
||||
inet_aton(localnet4_addrstr, &localnet4_addr);
|
||||
inet_aton(localnet5_addrstr, &localnet5_addr);
|
||||
inet_aton(localnet6_addrstr, &localnet6_addr);
|
||||
inet_aton(localnet7_addrstr, &localnet7_addr);
|
||||
inet_aton(localnet8_addrstr, &localnet8_addr);
|
||||
inet_aton(external_addrstr, &external_addr);
|
||||
|
||||
CHECK(pqi_inet_netof(localnet1_addr)==htonl(10<<24));
|
||||
CHECK(pqi_inet_netof(localnet2_addr)==htonl(169<<24 | 254<<16));
|
||||
CHECK(pqi_inet_netof(localnet3_addr)==htonl(172<<24 | 16<<16));
|
||||
CHECK(pqi_inet_netof(localnet4_addr)==htonl(192<<24 | 168<<16 | 1<<8));
|
||||
CHECK(pqi_inet_netof(localnet5_addr)==htonl(10<<24));
|
||||
CHECK(pqi_inet_netof(localnet6_addr)==htonl(169<<24 | 254<<16));
|
||||
CHECK(pqi_inet_netof(localnet7_addr)==htonl(172<<24 | 20<<16));
|
||||
CHECK(pqi_inet_netof(localnet8_addr)==htonl(192<<24 | 168<<16 | 1<<8));
|
||||
CHECK(pqi_inet_netof(external_addr)==htonl(74<<24));
|
||||
|
||||
REPORT("pqi_inet_netof()");
|
||||
|
||||
return 1;
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
/*
|
||||
* libretroshare/src/pqi net_test.cc
|
||||
*
|
||||
* 3P/PQI network interface for RetroShare.
|
||||
*
|
||||
* Copyright 2007-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".
|
||||
*
|
||||
*/
|
||||
|
||||
/******
|
||||
* NETWORKING Test to check Big/Little Endian behaviour
|
||||
* as well as socket behaviour
|
||||
*
|
||||
*/
|
||||
|
||||
#include "pqi/pqinetwork.h"
|
||||
#include "util/rsnet.h"
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
|
||||
bool test_iface();
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
|
||||
test_iface();
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* test 1: byte manipulation */
|
||||
bool test_iface()
|
||||
{
|
||||
struct in_addr pref_iface = getPreferredInterface();
|
||||
std::list<std::string> ifaces = getLocalInterfaces();
|
||||
std::list<std::string>::iterator it;
|
||||
std::cerr << "test_iface()" << std::endl;
|
||||
for(it = ifaces.begin(); it != ifaces.end(); it++)
|
||||
{
|
||||
std::cerr << "available iface: " << *it << std::endl;
|
||||
}
|
||||
std::cerr << "preferred " << inet_ntoa(pref_iface) << std::endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1,413 +0,0 @@
|
||||
/*
|
||||
* "$Id: pqi_base.cc,v 1.17 2007-03-31 09:41:32 rmf24 Exp $"
|
||||
*
|
||||
* 3P/PQI network interface for RetroShare.
|
||||
*
|
||||
* Copyright 2004-2006 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 "pqi/pqi_base.h"
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
// local functions.
|
||||
int pqiroute_setshift(ChanId *item, int chan);
|
||||
int pqiroute_getshift(ChanId *item);
|
||||
|
||||
// these ones are also exported!
|
||||
int pqicid_clear(ChanId *cid);
|
||||
int pqicid_copy(const ChanId *cid, ChanId *newcid);
|
||||
int pqicid_cmp(const ChanId *cid1, ChanId *cid2);
|
||||
|
||||
// Helper functions for the PQInterface.
|
||||
|
||||
static int next_search_id = 1;
|
||||
|
||||
int getPQIsearchId()
|
||||
{
|
||||
return next_search_id++;
|
||||
}
|
||||
|
||||
|
||||
// CHANID Operations.
|
||||
int pqicid_clear(ChanId *cid)
|
||||
{
|
||||
for(int i = 0; i < 10; i++)
|
||||
{
|
||||
cid -> route[i] = 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int pqicid_copy(const ChanId *cid, ChanId *newcid)
|
||||
{
|
||||
for(int i = 0; i < 10; i++)
|
||||
{
|
||||
(newcid -> route)[i] = (cid -> route)[i];
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int pqicid_cmp(const ChanId *cid1, ChanId *cid2)
|
||||
{
|
||||
int ret = 0;
|
||||
for(int i = 0; i < 10; i++)
|
||||
{
|
||||
ret = cid1->route[i] - cid2->route[i];
|
||||
if (ret != 0)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int pqiroute_getshift(ChanId *id)
|
||||
{
|
||||
int *array = id -> route;
|
||||
int next = array[0];
|
||||
|
||||
// shift.
|
||||
for(int i = 0; i < 10 - 1; i++)
|
||||
{
|
||||
array[i] = array[i+1];
|
||||
}
|
||||
array[10 - 1] = 0;
|
||||
|
||||
return next;
|
||||
}
|
||||
|
||||
int pqiroute_setshift(ChanId *id, int chan)
|
||||
{
|
||||
int *array = id -> route;
|
||||
|
||||
// shift.
|
||||
for(int i = 10 - 1; i > 0; i--)
|
||||
{
|
||||
array[i] = array[i-1];
|
||||
}
|
||||
array[0] = chan;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/****************** PERSON DETAILS ***********************/
|
||||
|
||||
Person::Person()
|
||||
:dhtFound(false), dhtFlags(0),
|
||||
lc_timestamp(0), lr_timestamp(0),
|
||||
nc_timestamp(0), nc_timeintvl(5),
|
||||
name("Unknown"), status(PERSON_STATUS_MANUAL)
|
||||
|
||||
|
||||
{
|
||||
for(int i = 0; i < (signed) sizeof(lastaddr); i++)
|
||||
{
|
||||
((unsigned char *) (&lastaddr))[i] = 0;
|
||||
((unsigned char *) (&localaddr))[i] = 0;
|
||||
((unsigned char *) (&serveraddr))[i] = 0;
|
||||
((unsigned char *) (&dhtaddr))[i] = 0;
|
||||
}
|
||||
pqicid_clear(&cid);
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Person::~Person()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
int Person::cidpop()
|
||||
{
|
||||
return pqiroute_getshift(&cid);
|
||||
}
|
||||
|
||||
void Person::cidpush(int id)
|
||||
{
|
||||
pqiroute_setshift(&cid, id);
|
||||
return;
|
||||
}
|
||||
|
||||
bool Person::Group(std::string in)
|
||||
{
|
||||
std::list<std::string>::iterator it;
|
||||
for(it = groups.begin(); it != groups.end(); it++)
|
||||
{
|
||||
if (in == (*it))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
int Person::addGroup(std::string in)
|
||||
{
|
||||
groups.push_back(in);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int Person::removeGroup(std::string in)
|
||||
{
|
||||
std::list<std::string>::iterator it;
|
||||
for(it = groups.begin(); it != groups.end(); it++)
|
||||
{
|
||||
if (in == (*it))
|
||||
{
|
||||
groups.erase(it);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool Person::Valid()
|
||||
{
|
||||
return (status & PERSON_STATUS_VALID);
|
||||
}
|
||||
|
||||
void Person::Valid(bool b)
|
||||
{
|
||||
if (b)
|
||||
status |= PERSON_STATUS_VALID;
|
||||
else
|
||||
status &= ~PERSON_STATUS_VALID;
|
||||
}
|
||||
|
||||
bool Person::Accepted()
|
||||
{
|
||||
return (status & PERSON_STATUS_ACCEPTED);
|
||||
}
|
||||
|
||||
void Person::Accepted(bool b)
|
||||
{
|
||||
if (b)
|
||||
status |= PERSON_STATUS_ACCEPTED;
|
||||
else
|
||||
status &= ~PERSON_STATUS_ACCEPTED;
|
||||
}
|
||||
|
||||
bool Person::InUse()
|
||||
{
|
||||
return (status & PERSON_STATUS_INUSE);
|
||||
}
|
||||
|
||||
void Person::InUse(bool b)
|
||||
{
|
||||
if (b)
|
||||
status |= PERSON_STATUS_INUSE;
|
||||
else
|
||||
status &= ~(PERSON_STATUS_INUSE);
|
||||
}
|
||||
|
||||
|
||||
bool Person::Listening()
|
||||
{
|
||||
return (status & PERSON_STATUS_LISTENING);
|
||||
}
|
||||
|
||||
void Person::Listening(bool b)
|
||||
{
|
||||
if (b)
|
||||
status |= PERSON_STATUS_LISTENING;
|
||||
else
|
||||
status &= ~PERSON_STATUS_LISTENING;
|
||||
}
|
||||
|
||||
bool Person::Connected()
|
||||
{
|
||||
return (status & PERSON_STATUS_CONNECTED);
|
||||
}
|
||||
|
||||
void Person::Connected(bool b)
|
||||
{
|
||||
if (b)
|
||||
status |= PERSON_STATUS_CONNECTED;
|
||||
else
|
||||
status &= ~PERSON_STATUS_CONNECTED;
|
||||
}
|
||||
|
||||
bool Person::WillListen()
|
||||
{
|
||||
return (status & PERSON_STATUS_WILL_LISTEN);
|
||||
}
|
||||
|
||||
void Person::WillListen(bool b)
|
||||
{
|
||||
if (b)
|
||||
status |= PERSON_STATUS_WILL_LISTEN;
|
||||
else
|
||||
status &= ~PERSON_STATUS_WILL_LISTEN;
|
||||
}
|
||||
|
||||
bool Person::WillConnect()
|
||||
{
|
||||
return (status & PERSON_STATUS_WILL_CONNECT);
|
||||
}
|
||||
|
||||
void Person::WillConnect(bool b)
|
||||
{
|
||||
if (b)
|
||||
status |= PERSON_STATUS_WILL_CONNECT;
|
||||
else
|
||||
status &= ~PERSON_STATUS_WILL_CONNECT;
|
||||
}
|
||||
|
||||
bool Person::Manual()
|
||||
{
|
||||
return (status & PERSON_STATUS_MANUAL);
|
||||
}
|
||||
|
||||
void Person::Manual(bool b)
|
||||
{
|
||||
if (b)
|
||||
status |= PERSON_STATUS_MANUAL;
|
||||
else
|
||||
status &= ~PERSON_STATUS_MANUAL;
|
||||
}
|
||||
|
||||
bool Person::Firewalled()
|
||||
{
|
||||
return (status & PERSON_STATUS_FIREWALLED);
|
||||
}
|
||||
|
||||
void Person::Firewalled(bool b)
|
||||
{
|
||||
if (b)
|
||||
status |= PERSON_STATUS_FIREWALLED;
|
||||
else
|
||||
status &= ~PERSON_STATUS_FIREWALLED;
|
||||
}
|
||||
|
||||
bool Person::Forwarded()
|
||||
{
|
||||
return (status & PERSON_STATUS_FORWARDED);
|
||||
}
|
||||
|
||||
void Person::Forwarded(bool b)
|
||||
{
|
||||
if (b)
|
||||
status |= PERSON_STATUS_FORWARDED;
|
||||
else
|
||||
status &= ~PERSON_STATUS_FORWARDED;
|
||||
}
|
||||
|
||||
bool Person::Local()
|
||||
{
|
||||
return (status & PERSON_STATUS_LOCAL);
|
||||
}
|
||||
|
||||
void Person::Local(bool b)
|
||||
{
|
||||
if (b)
|
||||
status |= PERSON_STATUS_LOCAL;
|
||||
else
|
||||
status &= ~PERSON_STATUS_LOCAL;
|
||||
}
|
||||
|
||||
|
||||
bool Person::Trusted()
|
||||
{
|
||||
return (status & PERSON_STATUS_TRUSTED);
|
||||
}
|
||||
|
||||
void Person::Trusted(bool b)
|
||||
{
|
||||
if (b)
|
||||
status |= PERSON_STATUS_TRUSTED;
|
||||
else
|
||||
status &= ~PERSON_STATUS_TRUSTED;
|
||||
}
|
||||
|
||||
|
||||
unsigned int Person::Status()
|
||||
{
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
void Person::Status(unsigned int s)
|
||||
{
|
||||
status = s;
|
||||
}
|
||||
|
||||
std::string Person::Name()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
void Person::Name(std::string n)
|
||||
{
|
||||
name = n;
|
||||
}
|
||||
|
||||
/* Dynamic Address Foundation */
|
||||
bool Person::hasDHT()
|
||||
{
|
||||
return dhtFound;
|
||||
}
|
||||
|
||||
void Person::setDHT(struct sockaddr_in addr, unsigned int flags)
|
||||
{
|
||||
dhtFound = true;
|
||||
dhtFlags = flags;
|
||||
dhtaddr = addr;
|
||||
}
|
||||
|
||||
/* GUI Flags */
|
||||
bool Person::InChat()
|
||||
{
|
||||
return (status & PERSON_STATUS_INCHAT);
|
||||
}
|
||||
|
||||
void Person::InChat(bool b)
|
||||
{
|
||||
if (b)
|
||||
status |= PERSON_STATUS_INCHAT;
|
||||
else
|
||||
status &= ~PERSON_STATUS_INCHAT;
|
||||
}
|
||||
|
||||
bool Person::InMessage()
|
||||
{
|
||||
return (status & PERSON_STATUS_INMSG);
|
||||
}
|
||||
|
||||
void Person::InMessage(bool b)
|
||||
{
|
||||
if (b)
|
||||
status |= PERSON_STATUS_INMSG;
|
||||
else
|
||||
status &= ~PERSON_STATUS_INMSG;
|
||||
}
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,195 +0,0 @@
|
||||
#ifndef MRK_SSL_CERT_HEADER
|
||||
#define MRK_SSL_CERT_HEADER
|
||||
|
||||
/*
|
||||
* Core PQI networking: sslcert.h
|
||||
*
|
||||
* 3P/PQI network interface for RetroShare.
|
||||
*
|
||||
* Copyright 2004-2006 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 <openssl/ssl.h>
|
||||
#include <openssl/evp.h>
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
#include "pqi_base.h"
|
||||
#include "pqinetwork.h"
|
||||
|
||||
#include "pqiindic.h"
|
||||
|
||||
|
||||
// helper fns.
|
||||
int printSSLError(SSL *ssl, int retval, int err, unsigned long err2, std::ostream &out);
|
||||
std::string getX509NameString(X509_NAME *name);
|
||||
std::string getX509CNString(X509_NAME *name);
|
||||
|
||||
std::string getX509OrgString(X509_NAME *name);
|
||||
std::string getX509LocString(X509_NAME *name);
|
||||
std::string getX509CountryString(X509_NAME *name);
|
||||
|
||||
|
||||
/* definitions -> functions to be defined */
|
||||
std::string convert_to_str(certsign &sign);
|
||||
bool convert_to_certsign(std::string id, certsign &sign);
|
||||
|
||||
class sslroot;
|
||||
|
||||
class cert: public Person
|
||||
{
|
||||
public:
|
||||
cert();
|
||||
virtual ~cert();
|
||||
|
||||
virtual std::string Signature();
|
||||
std::string Hash();
|
||||
void Hash(std::string);
|
||||
|
||||
X509 *certificate;
|
||||
std::string hash;
|
||||
};
|
||||
|
||||
|
||||
// returns pointer to static variable.
|
||||
// which must be inited..
|
||||
sslroot *getSSLRoot();
|
||||
|
||||
class sslroot
|
||||
{
|
||||
public:
|
||||
sslroot();
|
||||
int active();
|
||||
int setcertdir(char *path);
|
||||
int initssl(const char *srvr_cert, const char *priv_key,
|
||||
const char *CA_file, const char *passwd);
|
||||
int closessl();
|
||||
|
||||
/* Context handling */
|
||||
SSL_CTX *getCTX();
|
||||
|
||||
/* Certificate handling */
|
||||
int compareCerts(cert *a, cert *b);
|
||||
|
||||
// network interface.
|
||||
|
||||
// program interface.
|
||||
int addCertificate(cert *c);
|
||||
int addUntrustedCertificate(cert *c);
|
||||
int removeCertificate(cert *);
|
||||
|
||||
// Creation of Certificates.... (From X509)
|
||||
// Core functions....
|
||||
cert *checkDuplicateX509(X509 *x);
|
||||
cert *checkPeerX509(X509 *x);
|
||||
cert *makeCertificate(X509 *c);
|
||||
cert *registerCertificate(X509 *nc, struct sockaddr_in, bool in);
|
||||
|
||||
int validateCertificate(cert *c);
|
||||
|
||||
// depreciated...
|
||||
cert *findpeercert(const char *name);
|
||||
//int loadpeercert(const char *fname);
|
||||
//int savepeercert(const char *fname);
|
||||
|
||||
// Configuration Handling...
|
||||
int setConfigDirs(const char *cdir, const char *ndir);
|
||||
|
||||
// these save both the certificates + the settings.
|
||||
int saveCertificates(const char *fname);
|
||||
int saveCertificates();
|
||||
int loadCertificates(const char *fname);
|
||||
|
||||
// with a hash check/recalc in there for good measure.
|
||||
cert * loadcertificate(const char* fname, std::string hash);
|
||||
int savecertificate(cert *c, const char* fname);
|
||||
|
||||
// digest hashing /signing or encrypting interface.
|
||||
int hashFile(std::string fname, unsigned char *hash, unsigned int hlen);
|
||||
int hashDigest(char *data, unsigned int dlen, unsigned char *hash, unsigned int hlen);
|
||||
int signDigest(EVP_PKEY *key, char *data, unsigned int dlen, unsigned char *hash, unsigned int hlen);
|
||||
int verifyDigest(EVP_PKEY *key, char *data, unsigned int dlen, unsigned char *enc, unsigned int elen);
|
||||
int generateKeyPair(EVP_PKEY *keypair, unsigned int keylen);
|
||||
|
||||
|
||||
|
||||
int printCertificate(cert *, std::ostream &out);
|
||||
/****** REMOVED!
|
||||
*
|
||||
*
|
||||
std::list<std::string> listCertificates();
|
||||
*
|
||||
*
|
||||
****/
|
||||
|
||||
std::list<cert *> &getCertList();
|
||||
|
||||
cert * getOwnCert();
|
||||
int checkNetAddress();
|
||||
|
||||
// extra list for certs that aren't in main list.
|
||||
cert * getCollectedCert();
|
||||
bool collectedCerts();
|
||||
|
||||
bool CertsChanged();
|
||||
bool CertsMajorChanged();
|
||||
void IndicateCertsChanged();
|
||||
|
||||
std::string getSetting(std::string opt);
|
||||
void setSetting(std::string opt, std::string val);
|
||||
|
||||
|
||||
/* Fns for relating cert signatures to structures */
|
||||
cert *findcertsign(certsign &sign);
|
||||
int getcertsign(cert *c, certsign &sign);
|
||||
int addtosignmap(cert *);
|
||||
|
||||
private: /* data */
|
||||
std::list<cert *> peercerts;
|
||||
std::list<cert *> allcerts;
|
||||
std::list<cert *> collectedcerts;
|
||||
|
||||
// whenever a cert is added, it should also be put in the map.
|
||||
std::map<certsign, cert *> signmap;
|
||||
|
||||
|
||||
|
||||
// General Configuration System
|
||||
// easy it put it here - so it can be signed easily.
|
||||
std::map<std::string, std::string> settings;
|
||||
|
||||
std::string certdir;
|
||||
std::string neighbourdir;
|
||||
std::string certfile;
|
||||
|
||||
SSL_CTX *sslctx;
|
||||
int init;
|
||||
|
||||
Indicator certsChanged;
|
||||
Indicator certsMajorChanged;
|
||||
|
||||
EVP_PKEY *pkey;
|
||||
|
||||
cert *own_cert;
|
||||
|
||||
};
|
||||
|
||||
#endif // MRK_SSL_CERT_HEADER
|
@ -1,44 +0,0 @@
|
||||
|
||||
|
||||
/***** Extract XPGP Id *****/
|
||||
|
||||
#include "pqi/authxpgp.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if (argc < 2)
|
||||
{
|
||||
std::cerr << "Usage: " << argv[0] << " <certfile>";
|
||||
std::cerr << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
std::string userName, userId;
|
||||
|
||||
if (LoadCheckXPGPandGetName(argv[1], userName, userId))
|
||||
{
|
||||
std::cerr << "Cert Ok: name: " << userName;
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "id = \"" << userId << "\"";
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Cert Check Failed";
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,221 +0,0 @@
|
||||
/*
|
||||
* "$Id: xpgpcert.h,v 1.9 2007-04-15 18:45:18 rmf24 Exp $"
|
||||
*
|
||||
* 3P/PQI network interface for RetroShare.
|
||||
*
|
||||
* Copyright 2004-2006 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".
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifndef MRK_SSL_XPGP_CERT_HEADER
|
||||
#define MRK_SSL_XPGP_CERT_HEADER
|
||||
|
||||
/* This is the trial XPGP version
|
||||
*
|
||||
* It has to be compiled against XPGP ssl version.
|
||||
* this is only a hacked up version, merging
|
||||
* (so both can operate in parallel will happen later)
|
||||
*
|
||||
*/
|
||||
|
||||
#include <openssl/ssl.h>
|
||||
#include <openssl/evp.h>
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
#include "pqi_base.h"
|
||||
#include "pqinetwork.h"
|
||||
|
||||
#include "pqiindic.h"
|
||||
|
||||
|
||||
// helper fns.
|
||||
int printSSLError(SSL *ssl, int retval, int err, unsigned long err2, std::ostream &out);
|
||||
std::string getX509NameString(X509_NAME *name);
|
||||
std::string getX509CNString(X509_NAME *name);
|
||||
|
||||
std::string getX509OrgString(X509_NAME *name);
|
||||
std::string getX509LocString(X509_NAME *name);
|
||||
std::string getX509CountryString(X509_NAME *name);
|
||||
|
||||
int LoadCheckXPGPandGetName(const char *cert_file, std::string &userName);
|
||||
|
||||
std::string convert_to_str(certsign &sign);
|
||||
bool convert_to_certsign(std::string id, certsign &sign);
|
||||
|
||||
class sslroot;
|
||||
|
||||
class cert: public Person
|
||||
{
|
||||
public:
|
||||
cert();
|
||||
virtual ~cert();
|
||||
|
||||
virtual std::string Signature();
|
||||
std::string Hash();
|
||||
void Hash(std::string);
|
||||
std::string PeerId() { return Signature(); }
|
||||
|
||||
XPGP *certificate;
|
||||
std::string hash;
|
||||
std::string peerid;
|
||||
};
|
||||
|
||||
|
||||
// returns pointer to static variable.
|
||||
// which must be inited..
|
||||
sslroot *getSSLRoot();
|
||||
|
||||
class sslroot
|
||||
{
|
||||
public:
|
||||
sslroot();
|
||||
int active();
|
||||
int setcertdir(char *path);
|
||||
int initssl(const char *srvr_cert, const char *priv_key,
|
||||
const char *passwd);
|
||||
int closessl();
|
||||
|
||||
/* Context handling */
|
||||
SSL_CTX *getCTX();
|
||||
|
||||
/* Certificate handling */
|
||||
int compareCerts(cert *a, cert *b);
|
||||
|
||||
// network interface.
|
||||
|
||||
// program interface.
|
||||
int addCertificate(cert *c);
|
||||
int addUntrustedCertificate(cert *c);
|
||||
int addCollectedCertificate(cert *c);
|
||||
|
||||
int removeCertificate(cert *);
|
||||
|
||||
// Creation of Certificates.... (From X509)
|
||||
// Core functions....
|
||||
cert *checkDuplicateXPGP(XPGP *x);
|
||||
cert *checkPeerXPGP(XPGP *x);
|
||||
cert *makeCertificateXPGP(XPGP *c);
|
||||
cert *registerCertificateXPGP(XPGP *nc, struct sockaddr_in, bool in);
|
||||
|
||||
int validateCertificateXPGP(cert *c);
|
||||
|
||||
/* Fns specific to XPGP */
|
||||
int checkAuthCertificate(cert *xpgp);
|
||||
int signCertificate(cert *);
|
||||
int trustCertificate(cert *, bool totrust);
|
||||
int superNodeMode();
|
||||
int loadInitialTrustedPeer(std::string tp_file);
|
||||
|
||||
// depreciated...
|
||||
cert *findpeercert(const char *name);
|
||||
//int loadpeercert(const char *fname);
|
||||
//int savepeercert(const char *fname);
|
||||
|
||||
// Configuration Handling...
|
||||
int setConfigDirs(const char *cdir, const char *ndir);
|
||||
|
||||
// these save both the certificates + the settings.
|
||||
int saveCertificates(const char *fname);
|
||||
int saveCertificates();
|
||||
int loadCertificates(const char *fname);
|
||||
|
||||
// with a hash check/recalc in there for good measure.
|
||||
cert * loadcertificate(const char* fname, std::string hash);
|
||||
int savecertificate(cert *c, const char* fname);
|
||||
|
||||
// for sending stuff as text
|
||||
cert * loadCertFromString(std::string pem);
|
||||
std::string saveCertAsString(cert *c);
|
||||
|
||||
// digest hashing /signing or encrypting interface.
|
||||
int hashFile(std::string fname, unsigned char *hash, unsigned int hlen);
|
||||
int hashDigest(char *data, unsigned int dlen, unsigned char *hash, unsigned int hlen);
|
||||
int signDigest(EVP_PKEY *key, char *data, unsigned int dlen, unsigned char *hash, unsigned int hlen);
|
||||
int verifyDigest(EVP_PKEY *key, char *data, unsigned int dlen, unsigned char *enc, unsigned int elen);
|
||||
int generateKeyPair(EVP_PKEY *keypair, unsigned int keylen);
|
||||
|
||||
|
||||
|
||||
int printCertificate(cert *, std::ostream &out);
|
||||
/* removing the list of certificate names - ambiguity!
|
||||
*
|
||||
std::list<std::string> listCertificates();
|
||||
*
|
||||
*/
|
||||
|
||||
std::list<cert *> &getCertList();
|
||||
|
||||
cert * getOwnCert();
|
||||
int checkNetAddress();
|
||||
|
||||
// extra list for certs that aren't in main list.
|
||||
cert * getCollectedCert();
|
||||
bool collectedCerts();
|
||||
|
||||
bool CertsChanged();
|
||||
bool CertsMajorChanged();
|
||||
void IndicateCertsChanged();
|
||||
|
||||
std::string getSetting(std::string opt);
|
||||
void setSetting(std::string opt, std::string val);
|
||||
|
||||
|
||||
/* Fns for relating cert signatures to structures */
|
||||
cert *findPeerId(std::string id);
|
||||
cert *findcertsign(certsign &sign);
|
||||
int getcertsign(cert *c, certsign &sign);
|
||||
int addtosignmap(cert *);
|
||||
|
||||
private: /* data */
|
||||
std::list<cert *> peercerts;
|
||||
std::list<cert *> allcerts;
|
||||
std::list<cert *> collectedcerts;
|
||||
|
||||
// whenever a cert is added, it should also be put in the map.
|
||||
std::map<certsign, cert *> signmap;
|
||||
|
||||
|
||||
|
||||
// General Configuration System
|
||||
// easy it put it here - so it can be signed easily.
|
||||
std::map<std::string, std::string> settings;
|
||||
|
||||
std::string certdir;
|
||||
std::string neighbourdir;
|
||||
std::string certfile;
|
||||
|
||||
SSL_CTX *sslctx;
|
||||
int init;
|
||||
|
||||
Indicator certsChanged;
|
||||
Indicator certsMajorChanged;
|
||||
|
||||
EVP_PKEY *pkey;
|
||||
|
||||
cert *own_cert;
|
||||
|
||||
XPGP_KEYRING *pgp_keyring;
|
||||
|
||||
};
|
||||
|
||||
#endif // MRK_SSL_XPGP_CERT_HEADER
|
Loading…
Reference in New Issue
Block a user