mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-02 14:16:16 -04:00
merged upstream/master
This commit is contained in:
commit
6848a586f3
94 changed files with 1618 additions and 758 deletions
|
@ -4,6 +4,7 @@
|
|||
* libretroshare: retroshare core library *
|
||||
* *
|
||||
* Copyright 2016 Cyril Soler <csoler@users.sourceforge.net> *
|
||||
* Copyright 2018 Gioacchino Mazzurco <gio@eigenlab.org> *
|
||||
* *
|
||||
* This program is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
|
@ -32,25 +33,21 @@
|
|||
|
||||
//#define DEBUG_RSCERTIFICATE
|
||||
|
||||
static const std::string PGP_CERTIFICATE_START ( "-----BEGIN PGP PUBLIC KEY BLOCK-----" );
|
||||
static const std::string PGP_CERTIFICATE_END ( "-----END PGP PUBLIC KEY BLOCK-----" );
|
||||
static const std::string EXTERNAL_IP_BEGIN_SECTION ( "--EXT--" );
|
||||
static const std::string LOCAL_IP_BEGIN_SECTION ( "--LOCAL--" );
|
||||
static const std::string SSLID_BEGIN_SECTION ( "--SSLID--" );
|
||||
static const std::string LOCATION_BEGIN_SECTION ( "--LOCATION--" );
|
||||
static const std::string HIDDEN_NODE_BEGIN_SECTION ( "--HIDDEN--" );
|
||||
static const uint8_t CERTIFICATE_VERSION_06 = 0x06;
|
||||
|
||||
static const uint8_t CERTIFICATE_PTAG_PGP_SECTION = 0x01 ;
|
||||
static const uint8_t CERTIFICATE_PTAG_EXTIPANDPORT_SECTION = 0x02 ;
|
||||
static const uint8_t CERTIFICATE_PTAG_LOCIPANDPORT_SECTION = 0x03 ;
|
||||
static const uint8_t CERTIFICATE_PTAG_DNS_SECTION = 0x04 ;
|
||||
static const uint8_t CERTIFICATE_PTAG_SSLID_SECTION = 0x05 ;
|
||||
static const uint8_t CERTIFICATE_PTAG_NAME_SECTION = 0x06 ;
|
||||
static const uint8_t CERTIFICATE_PTAG_CHECKSUM_SECTION = 0x07 ;
|
||||
static const uint8_t CERTIFICATE_PTAG_HIDDENNODE_SECTION = 0x08 ;
|
||||
static const uint8_t CERTIFICATE_PTAG_VERSION_SECTION = 0x09 ;
|
||||
|
||||
static const uint8_t CERTIFICATE_VERSION_06 = 0x06 ;
|
||||
enum CertificatePtag : uint8_t
|
||||
{
|
||||
CERTIFICATE_PTAG_PGP_SECTION = 0x01,
|
||||
CERTIFICATE_PTAG_EXTIPANDPORT_SECTION = 0x02,
|
||||
CERTIFICATE_PTAG_LOCIPANDPORT_SECTION = 0x03,
|
||||
CERTIFICATE_PTAG_DNS_SECTION = 0x04,
|
||||
CERTIFICATE_PTAG_SSLID_SECTION = 0x05,
|
||||
CERTIFICATE_PTAG_NAME_SECTION = 0x06,
|
||||
CERTIFICATE_PTAG_CHECKSUM_SECTION = 0x07,
|
||||
CERTIFICATE_PTAG_HIDDENNODE_SECTION = 0x08,
|
||||
CERTIFICATE_PTAG_VERSION_SECTION = 0x09,
|
||||
CERTIFICATE_PTAG_EXTRA_LOCATOR = 10
|
||||
};
|
||||
|
||||
static bool is_acceptable_radix64Char(char c)
|
||||
{
|
||||
|
@ -116,6 +113,14 @@ std::string RsCertificate::toStdString() const
|
|||
|
||||
addPacket( CERTIFICATE_PTAG_NAME_SECTION , (unsigned char *)location_name.c_str() ,location_name.length() , buf, p, BS ) ;
|
||||
addPacket( CERTIFICATE_PTAG_SSLID_SECTION , location_id.toByteArray() ,location_id.SIZE_IN_BYTES, buf, p, BS ) ;
|
||||
|
||||
for (const RsUrl& locator : mLocators)
|
||||
{
|
||||
std::string urlStr(locator.toString());
|
||||
addPacket( CERTIFICATE_PTAG_EXTRA_LOCATOR,
|
||||
(unsigned char *) urlStr.c_str(), urlStr.size(),
|
||||
buf, p, BS );
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t computed_crc = PGPKeyManagement::compute24bitsCRC(buf,p) ;
|
||||
|
@ -216,7 +221,10 @@ RsCertificate::RsCertificate(const RsPeerDetails& Detail, const unsigned char *b
|
|||
memset(ipv4_external_ip_and_port,0,6) ;
|
||||
}
|
||||
|
||||
dns_name = Detail.dyndns ;
|
||||
dns_name = Detail.dyndns;
|
||||
|
||||
for(auto&& ipr : Detail.ipAddressList)
|
||||
mLocators.insert(RsUrl(ipr.substr(0, ipr.find(' '))));
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -275,19 +283,19 @@ bool RsCertificate::initFromString(const std::string& instr,uint32_t& err_code)
|
|||
std::vector<uint8_t> bf = Radix64::decode(str) ;
|
||||
size_t size = bf.size();
|
||||
|
||||
bool checksum_check_passed = false ;
|
||||
unsigned char *buf = bf.data() ;
|
||||
size_t total_s = 0 ;
|
||||
only_pgp = true ;
|
||||
uint8_t certificate_version = 0x00 ;
|
||||
bool checksum_check_passed = false;
|
||||
unsigned char *buf = bf.data();
|
||||
size_t total_s = 0;
|
||||
only_pgp = true;
|
||||
uint8_t certificate_version = 0x00;
|
||||
|
||||
while(total_s < size)
|
||||
{
|
||||
uint8_t ptag = buf[0];
|
||||
buf = &buf[1] ;
|
||||
buf = &buf[1];
|
||||
|
||||
unsigned char *buf2 = buf ;
|
||||
uint32_t s = PGPKeyParser::read_125Size(buf) ;
|
||||
unsigned char *buf2 = buf;
|
||||
uint32_t s = PGPKeyParser::read_125Size(buf);
|
||||
|
||||
total_s += 1 + ((unsigned long)buf-(unsigned long)buf2) ;
|
||||
|
||||
|
@ -302,90 +310,80 @@ bool RsCertificate::initFromString(const std::string& instr,uint32_t& err_code)
|
|||
#endif
|
||||
switch(ptag)
|
||||
{
|
||||
case CERTIFICATE_PTAG_VERSION_SECTION: certificate_version = buf[0] ;
|
||||
buf = &buf[s] ;
|
||||
break ;
|
||||
|
||||
|
||||
case CERTIFICATE_PTAG_PGP_SECTION: binary_pgp_key = new unsigned char[s] ;
|
||||
memcpy(binary_pgp_key,buf,s) ;
|
||||
binary_pgp_key_size = s ;
|
||||
buf = &buf[s] ;
|
||||
break ;
|
||||
|
||||
case CERTIFICATE_PTAG_NAME_SECTION: location_name = std::string((char *)buf,s) ;
|
||||
buf = &buf[s] ;
|
||||
break ;
|
||||
|
||||
case CERTIFICATE_PTAG_SSLID_SECTION:
|
||||
if(s != location_id.SIZE_IN_BYTES)
|
||||
{
|
||||
err_code = CERTIFICATE_PARSING_ERROR_INVALID_LOCATION_ID ;
|
||||
return false ;
|
||||
}
|
||||
|
||||
location_id = RsPeerId(buf) ;
|
||||
buf = &buf[s] ;
|
||||
only_pgp = false ;
|
||||
break ;
|
||||
|
||||
case CERTIFICATE_PTAG_DNS_SECTION: dns_name = std::string((char *)buf,s) ;
|
||||
buf = &buf[s] ;
|
||||
break ;
|
||||
|
||||
case CERTIFICATE_PTAG_HIDDENNODE_SECTION:
|
||||
hidden_node_address = std::string((char *)buf,s);
|
||||
hidden_node = true;
|
||||
buf = &buf[s];
|
||||
|
||||
break ;
|
||||
|
||||
case CERTIFICATE_PTAG_LOCIPANDPORT_SECTION:
|
||||
if(s != 6)
|
||||
|
||||
{
|
||||
err_code = CERTIFICATE_PARSING_ERROR_INVALID_LOCAL_IP;
|
||||
return false ;
|
||||
}
|
||||
|
||||
memcpy(ipv4_internal_ip_and_port,buf,s) ;
|
||||
buf = &buf[s] ;
|
||||
break ;
|
||||
case CERTIFICATE_PTAG_EXTIPANDPORT_SECTION:
|
||||
if(s != 6)
|
||||
{
|
||||
err_code = CERTIFICATE_PARSING_ERROR_INVALID_EXTERNAL_IP;
|
||||
return false ;
|
||||
}
|
||||
|
||||
memcpy(ipv4_external_ip_and_port,buf,s) ;
|
||||
buf = &buf[s] ;
|
||||
break ;
|
||||
case CERTIFICATE_PTAG_CHECKSUM_SECTION:
|
||||
{
|
||||
if(s != 3 || total_s+3 != size)
|
||||
{
|
||||
err_code = CERTIFICATE_PARSING_ERROR_INVALID_CHECKSUM_SECTION ;
|
||||
return false ;
|
||||
}
|
||||
uint32_t computed_crc = PGPKeyManagement::compute24bitsCRC(bf.data(),size-5) ;
|
||||
uint32_t certificate_crc = buf[0] + (buf[1] << 8) + (buf[2] << 16) ;
|
||||
|
||||
if(computed_crc != certificate_crc)
|
||||
{
|
||||
err_code = CERTIFICATE_PARSING_ERROR_CHECKSUM_ERROR ;
|
||||
return false ;
|
||||
}
|
||||
else
|
||||
checksum_check_passed = true ;
|
||||
}
|
||||
break ;
|
||||
default:
|
||||
std::cerr << "(WW) unknwown PTAG 0x" << std::hex << ptag << std::dec << " in certificate! Ignoring it." << std::endl;
|
||||
buf = &buf[s] ;
|
||||
break ;
|
||||
case CERTIFICATE_PTAG_VERSION_SECTION:
|
||||
certificate_version = buf[0];
|
||||
break;
|
||||
case CERTIFICATE_PTAG_PGP_SECTION:
|
||||
binary_pgp_key = new unsigned char[s];
|
||||
memcpy(binary_pgp_key,buf,s);
|
||||
binary_pgp_key_size = s;
|
||||
break;
|
||||
case CERTIFICATE_PTAG_NAME_SECTION:
|
||||
location_name = std::string((char *)buf,s);
|
||||
break;
|
||||
case CERTIFICATE_PTAG_SSLID_SECTION:
|
||||
if(s != location_id.SIZE_IN_BYTES)
|
||||
{
|
||||
err_code = CERTIFICATE_PARSING_ERROR_INVALID_LOCATION_ID;
|
||||
return false;
|
||||
}
|
||||
location_id = RsPeerId(buf);
|
||||
only_pgp = false;
|
||||
break;
|
||||
case CERTIFICATE_PTAG_DNS_SECTION:
|
||||
dns_name = std::string((char *)buf,s);
|
||||
break;
|
||||
case CERTIFICATE_PTAG_HIDDENNODE_SECTION:
|
||||
hidden_node_address = std::string((char *)buf,s);
|
||||
hidden_node = true;
|
||||
break;
|
||||
case CERTIFICATE_PTAG_LOCIPANDPORT_SECTION:
|
||||
if(s != 6)
|
||||
{
|
||||
err_code = CERTIFICATE_PARSING_ERROR_INVALID_LOCAL_IP;
|
||||
return false;
|
||||
}
|
||||
memcpy(ipv4_internal_ip_and_port,buf,s);
|
||||
break;
|
||||
case CERTIFICATE_PTAG_EXTIPANDPORT_SECTION:
|
||||
if(s != 6)
|
||||
{
|
||||
err_code = CERTIFICATE_PARSING_ERROR_INVALID_EXTERNAL_IP;
|
||||
return false;
|
||||
}
|
||||
memcpy(ipv4_external_ip_and_port,buf,s);
|
||||
break;
|
||||
case CERTIFICATE_PTAG_CHECKSUM_SECTION:
|
||||
{
|
||||
if(s != 3 || total_s+3 != size)
|
||||
{
|
||||
err_code =
|
||||
CERTIFICATE_PARSING_ERROR_INVALID_CHECKSUM_SECTION;
|
||||
return false;
|
||||
}
|
||||
uint32_t computed_crc =
|
||||
PGPKeyManagement::compute24bitsCRC(bf.data(),size-5);
|
||||
uint32_t certificate_crc =
|
||||
buf[0] + (buf[1] << 8) + (buf[2] << 16);
|
||||
if(computed_crc != certificate_crc)
|
||||
{
|
||||
err_code = CERTIFICATE_PARSING_ERROR_CHECKSUM_ERROR;
|
||||
return false;
|
||||
}
|
||||
else checksum_check_passed = true;
|
||||
break;
|
||||
}
|
||||
case CERTIFICATE_PTAG_EXTRA_LOCATOR:
|
||||
mLocators.insert(RsUrl(std::string((char *)buf, s)));
|
||||
break;
|
||||
default:
|
||||
std::cerr << "(WW) unknwown PTAG 0x" << std::hex << ptag
|
||||
<< std::dec << " in certificate! Ignoring it."
|
||||
<< std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
buf = &buf[s];
|
||||
total_s += s ;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,9 +22,30 @@
|
|||
#pragma once
|
||||
|
||||
#pragma once
|
||||
/*
|
||||
* RetroShare
|
||||
*
|
||||
* Copyright (C) 2012-2014 Cyril Soler <csoler@users.sourceforge.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "retroshare/rstypes.h"
|
||||
#include "util/rsurl.h"
|
||||
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <retroshare/rstypes.h>
|
||||
|
||||
class RsPeerDetails ;
|
||||
|
||||
|
@ -65,6 +86,7 @@ class RsCertificate
|
|||
size_t pgp_key_size() const { return binary_pgp_key_size ; }
|
||||
|
||||
static bool cleanCertificate(const std::string& input, std::string& output, RsCertificate::Format& format, int& error_code, bool check_content) ;
|
||||
const std::set<RsUrl>& locators() const { return mLocators; }
|
||||
|
||||
private:
|
||||
static bool cleanCertificate(const std::string& input,std::string& output,int&) ; // new radix format
|
||||
|
@ -92,6 +114,7 @@ class RsCertificate
|
|||
std::string pgp_version ;
|
||||
std::string dns_name ;
|
||||
std::string hidden_node_address;
|
||||
std::set<RsUrl> mLocators;
|
||||
|
||||
bool only_pgp ; // does the cert contain only pgp info?
|
||||
bool hidden_node; // IP or hidden Node Address.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue