mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-21 04:44:25 -04:00
converted short invites to compact PGP format for increased robustness
This commit is contained in:
parent
e132ce7072
commit
9312d0cb3a
6 changed files with 187 additions and 169 deletions
|
@ -552,13 +552,13 @@ unsigned short RsCertificate::loc_port_us() const
|
||||||
return (int)ipv4_internal_ip_and_port[4]*256 + (int)ipv4_internal_ip_and_port[5] ;
|
return (int)ipv4_internal_ip_and_port[4]*256 + (int)ipv4_internal_ip_and_port[5] ;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RsCertificate::cleanCertificate( const std::string& input, std::string& output, Format& format, int& error_code, bool check_content )
|
bool RsCertificate::cleanCertificate( const std::string& input, std::string& output, Format& format, uint32_t& error_code, bool check_content )
|
||||||
{
|
{
|
||||||
if(cleanRadix64(input,output,error_code))
|
if(cleanRadix64(input,output,error_code))
|
||||||
{
|
{
|
||||||
RsPeerDetails details;
|
RsPeerDetails details;
|
||||||
|
|
||||||
if(rsPeers->parseShortInvite(output,details))
|
if(rsPeers->parseShortInvite(output,details,error_code))
|
||||||
{
|
{
|
||||||
format = RS_CERTIFICATE_SHORT_RADIX;
|
format = RS_CERTIFICATE_SHORT_RADIX;
|
||||||
return true;
|
return true;
|
||||||
|
@ -584,7 +584,7 @@ std::string RsCertificate::armouredPGPKey() const
|
||||||
|
|
||||||
// Yeah, this is simple, and that is what's good about the radix format. Can't be broken ;-)
|
// Yeah, this is simple, and that is what's good about the radix format. Can't be broken ;-)
|
||||||
//
|
//
|
||||||
bool RsCertificate::cleanRadix64(const std::string& instr,std::string& str,int& error_code)
|
bool RsCertificate::cleanRadix64(const std::string& instr,std::string& str,uint32_t& error_code)
|
||||||
{
|
{
|
||||||
error_code = RS_PEER_CERT_CLEANING_CODE_NO_ERROR ;
|
error_code = RS_PEER_CERT_CLEANING_CODE_NO_ERROR ;
|
||||||
|
|
||||||
|
|
|
@ -84,7 +84,7 @@ public:
|
||||||
|
|
||||||
static bool cleanCertificate(
|
static bool cleanCertificate(
|
||||||
const std::string& input, std::string& output,
|
const std::string& input, std::string& output,
|
||||||
RsCertificate::Format& format, int& error_code, bool check_content);
|
RsCertificate::Format& format, uint32_t& error_code, bool check_content);
|
||||||
|
|
||||||
const std::set<RsUrl>& locators() const { return mLocators; }
|
const std::set<RsUrl>& locators() const { return mLocators; }
|
||||||
|
|
||||||
|
@ -99,7 +99,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// new radix format
|
// new radix format
|
||||||
static bool cleanRadix64( const std::string& input, std::string& output, int&);
|
static bool cleanRadix64(const std::string& input, std::string& output, uint32_t &);
|
||||||
|
|
||||||
static void scan_ip( const std::string& ip_string, unsigned short port,
|
static void scan_ip( const std::string& ip_string, unsigned short port,
|
||||||
unsigned char *destination_memory );
|
unsigned char *destination_memory );
|
||||||
|
|
|
@ -130,6 +130,8 @@ const uint32_t CERTIFICATE_PARSING_ERROR_CHECKSUM_ERROR = 0x16 ;
|
||||||
const uint32_t CERTIFICATE_PARSING_ERROR_UNKNOWN_SECTION_PTAG = 0x17 ;
|
const uint32_t CERTIFICATE_PARSING_ERROR_UNKNOWN_SECTION_PTAG = 0x17 ;
|
||||||
const uint32_t CERTIFICATE_PARSING_ERROR_MISSING_CHECKSUM = 0x18 ;
|
const uint32_t CERTIFICATE_PARSING_ERROR_MISSING_CHECKSUM = 0x18 ;
|
||||||
const uint32_t CERTIFICATE_PARSING_ERROR_WRONG_VERSION = 0x19 ;
|
const uint32_t CERTIFICATE_PARSING_ERROR_WRONG_VERSION = 0x19 ;
|
||||||
|
const uint32_t CERTIFICATE_PARSING_ERROR_MISSING_PGP_FINGERPRINT = 0x1a ;
|
||||||
|
const uint32_t CERTIFICATE_PARSING_ERROR_MISSING_LOCATION_ID = 0x1b ;
|
||||||
|
|
||||||
const uint32_t PGP_KEYRING_REMOVAL_ERROR_NO_ERROR = 0x20 ;
|
const uint32_t PGP_KEYRING_REMOVAL_ERROR_NO_ERROR = 0x20 ;
|
||||||
const uint32_t PGP_KEYRING_REMOVAL_ERROR_CANT_REMOVE_SECRET_KEYS = 0x21 ;
|
const uint32_t PGP_KEYRING_REMOVAL_ERROR_CANT_REMOVE_SECRET_KEYS = 0x21 ;
|
||||||
|
@ -685,7 +687,7 @@ public:
|
||||||
* @return false if error occurred, true otherwise
|
* @return false if error occurred, true otherwise
|
||||||
*/
|
*/
|
||||||
virtual bool parseShortInvite(
|
virtual bool parseShortInvite(
|
||||||
const std::string& invite, RsPeerDetails& details ) = 0;
|
const std::string& invite, RsPeerDetails& details,uint32_t& err_code ) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Add trusted node from invite
|
* @brief Add trusted node from invite
|
||||||
|
@ -731,7 +733,7 @@ public:
|
||||||
uint32_t& errorCode ) = 0;
|
uint32_t& errorCode ) = 0;
|
||||||
|
|
||||||
// Certificate utils
|
// Certificate utils
|
||||||
virtual bool cleanCertificate(const std::string &certstr, std::string &cleanCert,bool& is_short_format,int& error_code) = 0;
|
virtual bool cleanCertificate(const std::string &certstr, std::string &cleanCert,bool& is_short_format,uint32_t& error_code) = 0;
|
||||||
virtual bool saveCertificateToFile(const RsPeerId& id, const std::string &fname) = 0;
|
virtual bool saveCertificateToFile(const RsPeerId& id, const std::string &fname) = 0;
|
||||||
virtual std::string saveCertificateToString(const RsPeerId &id) = 0;
|
virtual std::string saveCertificateToString(const RsPeerId &id) = 0;
|
||||||
|
|
||||||
|
|
|
@ -41,15 +41,8 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
const std::string CERT_SSL_ID = "--SSLID--";
|
|
||||||
const std::string CERT_LOCATION = "--LOCATION--";
|
|
||||||
const std::string CERT_LOCAL_IP = "--LOCAL--";
|
|
||||||
const std::string CERT_EXT_IP = "--EXT--";
|
|
||||||
const std::string CERT_DYNDNS = "--DYNDNS--";
|
|
||||||
|
|
||||||
//static const int MAX_TIME_KEEP_LOCATION_WITHOUT_CONTACT = 30*24*3600 ; // 30 days.
|
//static const int MAX_TIME_KEEP_LOCATION_WITHOUT_CONTACT = 30*24*3600 ; // 30 days.
|
||||||
|
|
||||||
|
|
||||||
#include "pqi/authssl.h"
|
#include "pqi/authssl.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -1147,9 +1140,31 @@ enum class RsShortInviteFieldType : uint8_t
|
||||||
* trasport layer will be implemented */
|
* trasport layer will be implemented */
|
||||||
HIDDEN_LOCATOR = 0x90,
|
HIDDEN_LOCATOR = 0x90,
|
||||||
DNS_LOCATOR = 0x91,
|
DNS_LOCATOR = 0x91,
|
||||||
EXT4_LOCATOR = 0x92,
|
EXT4_LOCATOR = 0x92
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static void addPacketHeader(RsShortInviteFieldType ptag, size_t size, unsigned char *& buf, uint32_t& offset, uint32_t& buf_size)
|
||||||
|
{
|
||||||
|
// Check that the buffer has sufficient size. If not, increase it.
|
||||||
|
|
||||||
|
while(offset + size + 6 >= buf_size)
|
||||||
|
{
|
||||||
|
unsigned char *newbuf = new unsigned char[2*buf_size] ;
|
||||||
|
|
||||||
|
memcpy(newbuf, buf, buf_size) ;
|
||||||
|
buf_size *= 2 ;
|
||||||
|
delete[] buf ;
|
||||||
|
buf = newbuf ;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write ptag and size
|
||||||
|
|
||||||
|
buf[offset] = static_cast<uint8_t>(ptag) ;
|
||||||
|
offset += 1 ;
|
||||||
|
|
||||||
|
offset += PGPKeyParser::write_125Size(&buf[offset],size) ;
|
||||||
|
}
|
||||||
|
|
||||||
bool p3Peers::getShortInvite(
|
bool p3Peers::getShortInvite(
|
||||||
std::string& invite, const RsPeerId& _sslId, bool formatRadix,
|
std::string& invite, const RsPeerId& _sslId, bool formatRadix,
|
||||||
bool bareBones, const std::string& baseUrl )
|
bool bareBones, const std::string& baseUrl )
|
||||||
|
@ -1160,22 +1175,19 @@ bool p3Peers::getShortInvite(
|
||||||
RsPeerDetails tDetails;
|
RsPeerDetails tDetails;
|
||||||
if(!getPeerDetails(sslId, tDetails)) return false;
|
if(!getPeerDetails(sslId, tDetails)) return false;
|
||||||
|
|
||||||
std::vector<uint8_t> inviteBuf(1000, 0);
|
uint32_t buf_size = 100;
|
||||||
RsGenericSerializer::SerializeContext ctx(
|
uint32_t offset = 0;
|
||||||
inviteBuf.data(), static_cast<uint32_t>(inviteBuf.size()));
|
unsigned char *buf = (unsigned char*)malloc(buf_size);
|
||||||
RsGenericSerializer::SerializeJob j = RsGenericSerializer::SERIALIZE;
|
|
||||||
|
|
||||||
RsShortInviteFieldType tType = RsShortInviteFieldType::SSL_ID;
|
addPacketHeader(RsShortInviteFieldType::SSL_ID,RsPeerId::SIZE_IN_BYTES,buf,offset,buf_size);
|
||||||
RS_SERIAL_PROCESS(tType);
|
sslId.serialise(buf,buf_size,offset);
|
||||||
RS_SERIAL_PROCESS(sslId);
|
|
||||||
|
|
||||||
tType = RsShortInviteFieldType::PGP_FINGERPRINT;
|
addPacketHeader(RsShortInviteFieldType::PGP_FINGERPRINT,RsPgpFingerprint::SIZE_IN_BYTES,buf,offset,buf_size);
|
||||||
RS_SERIAL_PROCESS(tType);
|
tDetails.fpr.serialise(buf,buf_size,offset);
|
||||||
RS_SERIAL_PROCESS(tDetails.fpr);
|
|
||||||
|
|
||||||
tType = RsShortInviteFieldType::PEER_NAME;
|
addPacketHeader(RsShortInviteFieldType::PEER_NAME,tDetails.name.size(),buf,offset,buf_size);
|
||||||
RS_SERIAL_PROCESS(tType);
|
memcpy(&buf[offset],tDetails.name.c_str(),tDetails.name.size());
|
||||||
RS_SERIAL_PROCESS(tDetails.name);
|
offset += tDetails.name.size();
|
||||||
|
|
||||||
if(!bareBones)
|
if(!bareBones)
|
||||||
{
|
{
|
||||||
|
@ -1186,46 +1198,63 @@ bool p3Peers::getShortInvite(
|
||||||
sockaddr_storage tExt;
|
sockaddr_storage tExt;
|
||||||
if(tDetails.isHiddenNode)
|
if(tDetails.isHiddenNode)
|
||||||
{
|
{
|
||||||
tType = RsShortInviteFieldType::HIDDEN_LOCATOR;
|
addPacketHeader(RsShortInviteFieldType::HIDDEN_LOCATOR,4 + 2 + tDetails.hiddenNodeAddress.size(),buf,offset,buf_size);
|
||||||
RS_SERIAL_PROCESS(tType);
|
|
||||||
RS_SERIAL_PROCESS(tDetails.hiddenType);
|
buf[offset+0] = (uint8_t)((tDetails.hiddenType >> 24) & 0xff);
|
||||||
RS_SERIAL_PROCESS(tDetails.hiddenNodeAddress);
|
buf[offset+1] = (uint8_t)((tDetails.hiddenType >> 16) & 0xff);
|
||||||
RS_SERIAL_PROCESS(tDetails.hiddenNodePort);
|
buf[offset+2] = (uint8_t)((tDetails.hiddenType >> 8) & 0xff);
|
||||||
|
buf[offset+3] = (uint8_t)((tDetails.hiddenType ) & 0xff);
|
||||||
|
|
||||||
|
buf[offset+4] = (uint8_t)((tDetails.hiddenNodePort >> 8) & 0xff);
|
||||||
|
buf[offset+5] = (uint8_t)((tDetails.hiddenNodePort ) & 0xff);
|
||||||
|
|
||||||
|
memcpy(&buf[offset+6],tDetails.hiddenNodeAddress.c_str(),tDetails.hiddenNodeAddress.size());
|
||||||
|
offset += 4 + 2 + tDetails.hiddenNodeAddress.size();
|
||||||
}
|
}
|
||||||
else if( !tDetails.dyndns.empty() &&
|
else if( !tDetails.dyndns.empty() && (tDetails.extPort || tDetails.localPort) )
|
||||||
(tDetails.extPort || tDetails.localPort) )
|
|
||||||
{
|
{
|
||||||
uint16_t tPort = tDetails.extPort ?
|
uint16_t tPort = tDetails.extPort ? tDetails.extPort : tDetails.localPort;
|
||||||
tDetails.extPort : tDetails.localPort;
|
|
||||||
tType = RsShortInviteFieldType::DNS_LOCATOR;
|
addPacketHeader(RsShortInviteFieldType::DNS_LOCATOR, 2 + tDetails.dyndns.size(),buf,offset,buf_size);
|
||||||
RS_SERIAL_PROCESS(tType);
|
|
||||||
RS_SERIAL_PROCESS(tDetails.dyndns);
|
buf[offset+0] = (uint8_t)((tPort >> 8) & 0xff);
|
||||||
RS_SERIAL_PROCESS(tPort);
|
buf[offset+1] = (uint8_t)((tPort ) & 0xff);
|
||||||
|
|
||||||
|
memcpy(&buf[offset+2],tDetails.dyndns.c_str(),tDetails.dyndns.size());
|
||||||
|
offset += 2 + tDetails.dyndns.size();
|
||||||
}
|
}
|
||||||
else if( sockaddr_storage_inet_pton(tExt, tDetails.extAddr) &&
|
else if( sockaddr_storage_inet_pton(tExt, tDetails.extAddr) &&
|
||||||
sockaddr_storage_isValidNet(tExt) &&
|
sockaddr_storage_isValidNet(tExt) &&
|
||||||
sockaddr_storage_ipv6_to_ipv4(tExt) &&
|
sockaddr_storage_ipv6_to_ipv4(tExt) &&
|
||||||
tDetails.extPort )
|
tDetails.extPort )
|
||||||
{
|
{
|
||||||
uint32_t t4Addr =
|
uint32_t t4Addr = reinterpret_cast<sockaddr_in&>(tExt).sin_addr.s_addr;
|
||||||
reinterpret_cast<sockaddr_in&>(tExt).sin_addr.s_addr;
|
|
||||||
|
|
||||||
tType = RsShortInviteFieldType::EXT4_LOCATOR;
|
addPacketHeader(RsShortInviteFieldType::EXT4_LOCATOR, 4 + 2,buf,offset,buf_size);
|
||||||
RS_SERIAL_PROCESS(tType);
|
|
||||||
RS_SERIAL_PROCESS(t4Addr);
|
buf[offset+0] = (uint8_t)((t4Addr >> 24) & 0xff);
|
||||||
RS_SERIAL_PROCESS(tDetails.extPort);
|
buf[offset+1] = (uint8_t)((t4Addr >> 16) & 0xff);
|
||||||
|
buf[offset+2] = (uint8_t)((t4Addr >> 8) & 0xff);
|
||||||
|
buf[offset+3] = (uint8_t)((t4Addr ) & 0xff);
|
||||||
|
|
||||||
|
buf[offset+4] = (uint8_t)((tDetails.extPort >> 8) & 0xff);
|
||||||
|
buf[offset+5] = (uint8_t)((tDetails.extPort ) & 0xff);
|
||||||
|
|
||||||
|
offset += 4+2;
|
||||||
}
|
}
|
||||||
else if(!tDetails.ipAddressList.empty())
|
else if(!tDetails.ipAddressList.empty())
|
||||||
{
|
{
|
||||||
const std::string& tLc = tDetails.ipAddressList.front();
|
const std::string& tLc = tDetails.ipAddressList.front();
|
||||||
std::string tLocator = tLc.substr(0, tLc.find_first_of(" ")-1);
|
std::string tLocator = tLc.substr(0, tLc.find_first_of(" ")-1);
|
||||||
tType = RsShortInviteFieldType::LOCATOR;
|
|
||||||
RS_SERIAL_PROCESS(tType);
|
addPacketHeader(RsShortInviteFieldType::LOCATOR, tLocator.size(),buf,offset,buf_size);
|
||||||
RS_SERIAL_PROCESS(tLocator);
|
memcpy(&buf[offset],tLocator.c_str(),tLocator.size());
|
||||||
|
|
||||||
|
offset += tLocator.size();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Radix64::encode(ctx.mData, static_cast<int>(ctx.mOffset), invite);
|
Radix64::encode(buf, static_cast<int>(offset), invite);
|
||||||
|
|
||||||
if(!formatRadix)
|
if(!formatRadix)
|
||||||
{
|
{
|
||||||
|
@ -1234,10 +1263,10 @@ bool p3Peers::getShortInvite(
|
||||||
invite = inviteUrl.toString();
|
invite = inviteUrl.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
return ctx.mOk;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool p3Peers::parseShortInvite(const std::string& inviteStrUrl, RsPeerDetails& details )
|
bool p3Peers::parseShortInvite(const std::string& inviteStrUrl, RsPeerDetails& details, uint32_t &err_code )
|
||||||
{
|
{
|
||||||
if(inviteStrUrl.empty())
|
if(inviteStrUrl.empty())
|
||||||
{
|
{
|
||||||
|
@ -1245,119 +1274,96 @@ bool p3Peers::parseShortInvite(const std::string& inviteStrUrl, RsPeerDetails& d
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
std::string rsInvite = inviteStrUrl;
|
||||||
const std::string* rsInvite = &inviteStrUrl;
|
|
||||||
|
|
||||||
RsUrl inviteUrl(inviteStrUrl);
|
RsUrl inviteUrl(inviteStrUrl);
|
||||||
|
|
||||||
if(inviteUrl.hasQueryK("rsInvite"))
|
if(inviteUrl.hasQueryK("rsInvite"))
|
||||||
rsInvite = inviteUrl.getQueryV("rsInvite");
|
rsInvite = *inviteUrl.getQueryV("rsInvite");
|
||||||
|
|
||||||
std::vector<uint8_t> inviteBuf = Radix64::decode(*rsInvite);
|
std::vector<uint8_t> bf = Radix64::decode(rsInvite);
|
||||||
RsGenericSerializer::SerializeContext ctx( inviteBuf.data(), static_cast<uint32_t>(inviteBuf.size()));
|
size_t size = bf.size();
|
||||||
RsGenericSerializer::SerializeJob j = RsGenericSerializer::DESERIALIZE;
|
|
||||||
|
|
||||||
while(ctx.mOk && ctx.mOffset < ctx.mSize)
|
unsigned char* buf = bf.data();
|
||||||
|
size_t total_s = 0;
|
||||||
|
|
||||||
|
while(total_s < size)
|
||||||
{
|
{
|
||||||
RsShortInviteFieldType fieldType;
|
RsShortInviteFieldType ptag = RsShortInviteFieldType(buf[0]);
|
||||||
RS_SERIAL_PROCESS(fieldType);
|
buf = &buf[1];
|
||||||
|
|
||||||
if(!ctx.mOk)
|
unsigned char *buf2 = buf;
|
||||||
|
uint32_t s = 0;
|
||||||
|
|
||||||
|
try { s = PGPKeyParser::read_125Size(buf); }
|
||||||
|
catch (...)
|
||||||
{
|
{
|
||||||
RsWarn() << __PRETTY_FUNCTION__ << " failed to parse fieldType"
|
err_code = CERTIFICATE_PARSING_ERROR_SIZE_ERROR;
|
||||||
<< std::endl;
|
return false;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (fieldType)
|
total_s += 1 + ( reinterpret_cast<size_t>(buf) - reinterpret_cast<size_t>(buf2) );
|
||||||
|
|
||||||
|
if(total_s > size)
|
||||||
|
{
|
||||||
|
err_code = CERTIFICATE_PARSING_ERROR_SIZE_ERROR;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Dbg3() << __PRETTY_FUNCTION__ << " Read ptag: "
|
||||||
|
<< static_cast<uint32_t>(ptag)
|
||||||
|
<< ", size " << s << ", total_s = " << total_s
|
||||||
|
<< ", expected total = " << size << std::endl;
|
||||||
|
|
||||||
|
switch(ptag)
|
||||||
{
|
{
|
||||||
case RsShortInviteFieldType::SSL_ID:
|
case RsShortInviteFieldType::SSL_ID:
|
||||||
RS_SERIAL_PROCESS(details.id);
|
details.id = RsPeerId::fromBufferUnsafe(buf) ;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RsShortInviteFieldType::PEER_NAME:
|
case RsShortInviteFieldType::PEER_NAME:
|
||||||
RS_SERIAL_PROCESS(details.name);
|
details.name = std::string((char*)buf,s);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RsShortInviteFieldType::PGP_FINGERPRINT:
|
case RsShortInviteFieldType::PGP_FINGERPRINT:
|
||||||
RS_SERIAL_PROCESS(details.fpr);
|
details.fpr = RsPgpFingerprint::fromBufferUnsafe(buf);
|
||||||
|
|
||||||
details.gpg_id = PGPHandler::pgpIdFromFingerprint(details.fpr);
|
details.gpg_id = PGPHandler::pgpIdFromFingerprint(details.fpr);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RsShortInviteFieldType::LOCATOR:
|
case RsShortInviteFieldType::LOCATOR:
|
||||||
{
|
{
|
||||||
std::string locatorStr;
|
std::string locatorStr((char*)buf,s);
|
||||||
RS_SERIAL_PROCESS(locatorStr);
|
details.ipAddressList.push_back(locatorStr);
|
||||||
if(ctx.mOk) details.ipAddressList.push_back(locatorStr);
|
|
||||||
else RsWarn() << __PRETTY_FUNCTION__ << " failed to parse locator"
|
|
||||||
<< std::endl;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case RsShortInviteFieldType::DNS_LOCATOR:
|
case RsShortInviteFieldType::DNS_LOCATOR:
|
||||||
RS_SERIAL_PROCESS(details.dyndns);
|
details.extPort = (((int)buf[0]) << 8) + buf[1];
|
||||||
if(!ctx.mOk)
|
details.dyndns = std::string((char*)&buf[2],s-2);
|
||||||
{
|
|
||||||
RsWarn() << __PRETTY_FUNCTION__ << " failed to parse DNS "
|
|
||||||
<< "locator host" << std::endl;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
RS_SERIAL_PROCESS(details.extPort);
|
|
||||||
if(!ctx.mOk) RsWarn() << __PRETTY_FUNCTION__ << " failed to parse "
|
|
||||||
<< "DNS locator port" << std::endl;
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RsShortInviteFieldType::EXT4_LOCATOR:
|
case RsShortInviteFieldType::EXT4_LOCATOR:
|
||||||
{
|
{
|
||||||
uint32_t t4Addr = 0;
|
uint32_t t4Addr = (((uint32_t)buf[0]) << 24)+(((uint32_t)buf[1])<<16)+(((uint32_t)buf[2])<<8) + (uint32_t)buf[3];
|
||||||
RS_SERIAL_PROCESS(t4Addr);
|
|
||||||
if(!ctx.mOk)
|
|
||||||
{
|
|
||||||
RsWarn() << __PRETTY_FUNCTION__ << " failed to parse IPv4"
|
|
||||||
<< std::endl;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
sockaddr_in tExtAddr;
|
sockaddr_in tExtAddr;
|
||||||
tExtAddr.sin_addr.s_addr = t4Addr;
|
tExtAddr.sin_addr.s_addr = t4Addr;
|
||||||
|
|
||||||
details.extAddr = rs_inet_ntoa(tExtAddr.sin_addr);
|
details.extAddr = rs_inet_ntoa(tExtAddr.sin_addr);
|
||||||
|
details.extPort = (((uint32_t)buf[4])<<8) + (uint32_t)buf[5];
|
||||||
RS_SERIAL_PROCESS(details.extPort);
|
|
||||||
if(!ctx.mOk)
|
|
||||||
RsWarn() << __PRETTY_FUNCTION__ << " failed to parse extPort"
|
|
||||||
<< std::endl;
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case RsShortInviteFieldType::HIDDEN_LOCATOR:
|
case RsShortInviteFieldType::HIDDEN_LOCATOR:
|
||||||
RS_SERIAL_PROCESS(details.hiddenType);
|
details.hiddenType = (((uint32_t)buf[0]) << 24)+(((uint32_t)buf[1])<<16)+(((uint32_t)buf[2])<<8) + (uint32_t)buf[3];
|
||||||
if(!ctx.mOk)
|
details.hiddenNodePort = (((uint32_t)buf[4]) << 8)+ (uint32_t)buf[5];
|
||||||
{
|
|
||||||
RsWarn() << __PRETTY_FUNCTION__ << " failed to parse hiddenType"
|
details.hiddenNodeAddress = std::string((char*)&buf[6],s-6);
|
||||||
<< std::endl;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RS_SERIAL_PROCESS(details.hiddenNodeAddress);
|
buf = &buf[s];
|
||||||
if(!ctx.mOk)
|
total_s += s;
|
||||||
{
|
|
||||||
RsWarn() << __PRETTY_FUNCTION__ << " failed to parse "
|
|
||||||
<< "hiddenNodeAddress" << std::endl;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
RS_SERIAL_PROCESS(details.hiddenNodePort);
|
|
||||||
if(!ctx.mOk) RsWarn() << __PRETTY_FUNCTION__ << " failed to parse "
|
|
||||||
<< "hiddenNodePort" << std::endl;
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
RsWarn() << __PRETTY_FUNCTION__ << " got unkown field type: "
|
|
||||||
<< static_cast<uint32_t>(fieldType) << std::endl;
|
|
||||||
return false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// now check if the PGP key is available. If so, add it in the PeerDetails:
|
// now check if the PGP key is available. If so, add it in the PeerDetails:
|
||||||
|
@ -1377,7 +1383,18 @@ bool p3Peers::parseShortInvite(const std::string& inviteStrUrl, RsPeerDetails& d
|
||||||
else
|
else
|
||||||
details.skip_signature_validation = true;
|
details.skip_signature_validation = true;
|
||||||
|
|
||||||
return ctx.mOk;
|
if(details.gpg_id.isNull())
|
||||||
|
{
|
||||||
|
err_code = CERTIFICATE_PARSING_ERROR_MISSING_PGP_FINGERPRINT;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(details.id.isNull())
|
||||||
|
{
|
||||||
|
err_code = CERTIFICATE_PARSING_ERROR_MISSING_LOCATION_ID;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
err_code = CERTIFICATE_PARSING_ERROR_NO_ERROR;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool p3Peers::acceptInvite( const std::string& invite,
|
bool p3Peers::acceptInvite( const std::string& invite,
|
||||||
|
@ -1566,7 +1583,7 @@ bool p3Peers::loadDetailsFromStringCert( const std::string &certstr,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool p3Peers::cleanCertificate(const std::string &certstr, std::string &cleanCert,bool& is_short_format,int& error_code)
|
bool p3Peers::cleanCertificate(const std::string &certstr, std::string &cleanCert,bool& is_short_format,uint32_t& error_code)
|
||||||
{
|
{
|
||||||
RsCertificate::Format format ;
|
RsCertificate::Format format ;
|
||||||
|
|
||||||
|
|
|
@ -145,8 +145,7 @@ public:
|
||||||
const std::string& baseUrl = "https://retroshare.me/" ) override;
|
const std::string& baseUrl = "https://retroshare.me/" ) override;
|
||||||
|
|
||||||
/// @see RsPeers
|
/// @see RsPeers
|
||||||
bool parseShortInvite(
|
bool parseShortInvite(const std::string& invite, RsPeerDetails& details, uint32_t &err_code ) override;
|
||||||
const std::string& invite, RsPeerDetails& details ) override;
|
|
||||||
|
|
||||||
/// @see RsPeers::acceptInvite
|
/// @see RsPeers::acceptInvite
|
||||||
virtual bool acceptInvite(
|
virtual bool acceptInvite(
|
||||||
|
@ -158,7 +157,7 @@ public:
|
||||||
virtual bool loadCertificateFromString(const std::string& cert, RsPeerId& ssl_id,RsPgpId& pgp_id, std::string& error_string);
|
virtual bool loadCertificateFromString(const std::string& cert, RsPeerId& ssl_id,RsPgpId& pgp_id, std::string& error_string);
|
||||||
virtual bool loadDetailsFromStringCert(const std::string &cert, RsPeerDetails &pd, uint32_t& error_code);
|
virtual bool loadDetailsFromStringCert(const std::string &cert, RsPeerDetails &pd, uint32_t& error_code);
|
||||||
|
|
||||||
virtual bool cleanCertificate(const std::string &certstr, std::string &cleanCert, bool &is_short_format, int& error_code) override;
|
virtual bool cleanCertificate(const std::string &certstr, std::string &cleanCert, bool &is_short_format, uint32_t& error_code) override;
|
||||||
virtual bool saveCertificateToFile(const RsPeerId &id, const std::string &fname);
|
virtual bool saveCertificateToFile(const RsPeerId &id, const std::string &fname);
|
||||||
virtual std::string saveCertificateToString(const RsPeerId &id);
|
virtual std::string saveCertificateToString(const RsPeerId &id);
|
||||||
|
|
||||||
|
|
|
@ -305,7 +305,7 @@ void ConnectFriendWizard::setCertificate(const QString &certificate, bool friend
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(rsPeers->parseShortInvite(certificate.toUtf8().constData(),peerDetails))
|
else if(rsPeers->parseShortInvite(certificate.toUtf8().constData(),peerDetails,cert_load_error_code))
|
||||||
{
|
{
|
||||||
mIsShortInvite = true;
|
mIsShortInvite = true;
|
||||||
|
|
||||||
|
@ -606,7 +606,7 @@ bool ConnectFriendWizard::validateCurrentPage()
|
||||||
std::string certstr = ui->friendCertEdit->toPlainText().toUtf8().constData();
|
std::string certstr = ui->friendCertEdit->toPlainText().toUtf8().constData();
|
||||||
uint32_t cert_load_error_code;
|
uint32_t cert_load_error_code;
|
||||||
|
|
||||||
if (rsPeers->loadDetailsFromStringCert(certstr, peerDetails, cert_load_error_code) || rsPeers->parseShortInvite(certstr,peerDetails))
|
if (rsPeers->loadDetailsFromStringCert(certstr, peerDetails, cert_load_error_code) || rsPeers->parseShortInvite(certstr,peerDetails,cert_load_error_code))
|
||||||
{
|
{
|
||||||
mCertificate = certstr;
|
mCertificate = certstr;
|
||||||
#ifdef FRIEND_WIZARD_DEBUG
|
#ifdef FRIEND_WIZARD_DEBUG
|
||||||
|
@ -846,7 +846,7 @@ void ConnectFriendWizard::cleanFriendCert()
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
std::string cleanCert;
|
std::string cleanCert;
|
||||||
int error_code;
|
uint32_t error_code;
|
||||||
|
|
||||||
if (rsPeers->cleanCertificate(cert, cleanCert, mIsShortInvite, error_code))
|
if (rsPeers->cleanCertificate(cert, cleanCert, mIsShortInvite, error_code))
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue