fixed code for certificate link generation.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@5420 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2012-08-14 19:31:47 +00:00
parent a940537331
commit b714d68523
5 changed files with 48 additions and 20 deletions

View File

@ -61,7 +61,7 @@ class PGPKeyManagement
static void findLengthOfMinimalKey(const unsigned char *keydata,size_t key_len,size_t& minimal_key_len) ;
static std::string makeArmouredKey(const unsigned char *keydata,size_t key_size,const std::string& version_string) ;
private:
// Computes the 24 bits CRC checksum necessary to all PGP data.
//
static uint32_t compute24bitsCRC(unsigned char *data,size_t len) ;

View File

@ -265,6 +265,7 @@ virtual bool getAllowTunnelConnection() = 0 ;
/* Auth Stuff */
virtual std::string GetRetroshareInvite(const std::string& ssl_id,bool include_signatures,bool old_format = false) = 0;
virtual bool GetPGPBase64StringAndCheckSum(const std::string& gpg_id,std::string& gpg_base64_string,std::string& gpg_base64_checksum) = 0 ;
virtual std::string GetRetroshareInvite(bool include_signatures,bool old_format = false) = 0;
virtual bool hasExportMinimal() = 0 ;

View File

@ -23,6 +23,9 @@
*
*/
#include "util/radix64.h"
#include "pgp/pgpkeyutil.h"
#include "rsserver/p3peers.h"
#include "rsserver/p3face.h"
@ -819,6 +822,31 @@ p3Peers::GetRetroshareInvite(bool include_signatures,bool old_format)
return GetRetroshareInvite(getOwnId(),include_signatures,old_format);
}
bool p3Peers::GetPGPBase64StringAndCheckSum( const std::string& gpg_id,
std::string& gpg_base64_string,
std::string& gpg_base64_checksum)
{
gpg_base64_string = "" ;
gpg_base64_checksum = "" ;
unsigned char *mem_block ;
size_t mem_block_size ;
if(!AuthGPG::getAuthGPG()->exportPublicKey(PGPIdType(gpg_id),mem_block,mem_block_size,false,false))
return false ;
Radix64::encode((const char *)mem_block,mem_block_size,gpg_base64_string) ;
uint32_t crc = PGPKeyManagement::compute24bitsCRC((unsigned char *)mem_block,mem_block_size) ;
unsigned char tmp[3] = { (crc >> 16) & 0xff, (crc >> 8) & 0xff, crc & 0xff } ;
Radix64::encode((const char *)tmp,3,gpg_base64_checksum) ;
delete[] mem_block ;
return true ;
}
std::string p3Peers::GetRetroshareInvite(const std::string& ssl_id,bool include_signatures,bool old_format)
{
#ifdef P3PEERS_DEBUG
@ -874,7 +902,7 @@ bool p3Peers::loadCertificateFromFile(const std::string &/*fname*/, std::string
return false;
}
bool p3Peers::loadDetailsFromStringCert(const std::string &certstr, RsPeerDetails &pd,std::string& error_string)
bool p3Peers::loadDetailsFromStringCert(const std::string &certstr, RsPeerDetails &pd,std::string& /*error_string*/)
{
#ifdef P3PEERS_DEBUG
std::cerr << "p3Peers::LoadCertificateFromString() ";

View File

@ -96,6 +96,8 @@ virtual bool getAllowTunnelConnection() ;
virtual std::string GetRetroshareInvite(const std::string& ssl_id,bool include_signatures,bool old_format = false);
// same but for own id
virtual std::string GetRetroshareInvite(bool include_signatures,bool old_format = false);
virtual bool GetPGPBase64StringAndCheckSum(const std::string& gpg_id,std::string& gpg_base64_string,std::string& gpg_base64_checksum) ;
virtual bool hasExportMinimal() ;
virtual bool loadCertificateFromFile(const std::string &fname, std::string &id, std::string &gpg_id);

View File

@ -286,42 +286,39 @@ bool RetroShareLink::createCertificate(const std::string& ssl_or_gpg_id)
// This is baaaaaad code:
// - we should not need to parse and re-read a cert in old format.
//
std::string invite = rsPeers->GetRetroshareInvite(ssl_or_gpg_id, false,true) ;
if(invite == "")
{
std::cerr << "RetroShareLink::createPerson() Couldn't get retroshare invite for ssl id: " << ssl_or_gpg_id << std::endl;
return false;
}
RsPeerDetails detail;
if (rsPeers->getPeerDetails(ssl_or_gpg_id, detail) == false) {
std::cerr << "RetroShareLink::createPerson() Couldn't find peer id " << ssl_or_gpg_id << std::endl;
return false;
}
//_ssl_id = QString::fromStdString(id);
QString gpg_base_64 = QString::fromStdString(invite).section("\n\n",1).section("-----",0,0) ;
std::string gpg_base_64_str = "" ;
std::string gpg_base_64_checksum_str = "" ;
_GPGBase64CheckSum = gpg_base_64.section("=",-1,-1).section("\n",0,0) ;
gpg_base_64 = gpg_base_64.section("\n=",0,0) ;
if(!rsPeers->GetPGPBase64StringAndCheckSum(detail.gpg_id,gpg_base_64_str,gpg_base_64_checksum_str))
return false ;
_GPGBase64String = QString::fromStdString(gpg_base_64_str) ;
_GPGBase64CheckSum = QString::fromStdString(gpg_base_64_checksum_str) ;
_type = TYPE_CERTIFICATE;
_GPGid = QString::fromStdString(detail.gpg_id).right(8);
if (detail.isOnlyGPGdetail) {
if(detail.isOnlyGPGdetail)
{
_SSLid.clear();
_location.clear();
_ext_ip_port.clear();
_loc_ip_port.clear();
} else {
}
else
{
_SSLid = QString::fromStdString(ssl_or_gpg_id) ;
_location = QString::fromUtf8(detail.location.c_str()) ;
_ext_ip_port = QString::fromStdString(invite).section("--EXT--",1,1) ;
QString lst = QString::fromStdString(invite).section("--EXT--",0,0) ;
_loc_ip_port = lst.section("--LOCAL--",1,1) ;
_ext_ip_port = QString::fromStdString(detail.extAddr) + ":" + QString::number(detail.extPort) + ";" ;
_loc_ip_port = QString::fromStdString(detail.localAddr) + ":" + QString::number(detail.localPort) + ";" ;
}
_GPGBase64String = gpg_base_64.replace("\n","") ;
_name = QString::fromUtf8(detail.name.c_str()) ;
std::cerr << "Found gpg base 64 string = " << _GPGBase64String.toStdString() << std::endl;