mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
removed code for old certificate format.
git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.6-initdev@7041 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
06a582564d
commit
efd1447a84
@ -136,7 +136,7 @@ RsCertificate::RsCertificate(const std::string& str)
|
|||||||
{
|
{
|
||||||
uint32_t err_code ;
|
uint32_t err_code ;
|
||||||
|
|
||||||
if(!initFromString(str,err_code)) // && !initFromString_oldFormat(str,err_code))
|
if(!initFromString(str,err_code))
|
||||||
throw err_code ;
|
throw err_code ;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -435,12 +435,6 @@ unsigned short RsCertificate::loc_port_us() const
|
|||||||
|
|
||||||
bool RsCertificate::cleanCertificate(const std::string& input,std::string& output,Format& format,int& error_code)
|
bool RsCertificate::cleanCertificate(const std::string& input,std::string& output,Format& format,int& error_code)
|
||||||
{
|
{
|
||||||
// if(cleanCertificate_oldFormat(input,output,error_code))
|
|
||||||
// {
|
|
||||||
// format = RS_CERTIFICATE_OLD_FORMAT ;
|
|
||||||
// return true ;
|
|
||||||
// }
|
|
||||||
|
|
||||||
if(cleanCertificate(input,output,error_code))
|
if(cleanCertificate(input,output,error_code))
|
||||||
{
|
{
|
||||||
format = RS_CERTIFICATE_RADIX ;
|
format = RS_CERTIFICATE_RADIX ;
|
||||||
@ -494,576 +488,7 @@ bool RsCertificate::cleanCertificate(const std::string& instr,std::string& str,i
|
|||||||
return true ;
|
return true ;
|
||||||
}
|
}
|
||||||
|
|
||||||
// All the code below should be removed when in 0.6. Certificates will only use the new format.
|
|
||||||
//
|
|
||||||
bool RsCertificate::cleanCertificate_oldFormat(const std::string& certstr,std::string& cleanCertificate,int& error_code)
|
|
||||||
{
|
|
||||||
error_code = RS_PEER_CERT_CLEANING_CODE_UNKOWN_ERROR ; // default
|
|
||||||
const std::string& badCertificate(certstr) ;
|
|
||||||
|
|
||||||
std::string pgpend("-----END PGP PUBLIC KEY BLOCK-----");
|
|
||||||
|
|
||||||
size_t pos = certstr.find(pgpend);
|
|
||||||
std::string peer_info ;
|
|
||||||
std::string cert ;
|
|
||||||
|
|
||||||
if (pos != std::string::npos)
|
|
||||||
{
|
|
||||||
pos += pgpend.length();
|
|
||||||
cert = certstr.substr(0, pos);
|
|
||||||
if (pos + 1 < certstr.length())
|
|
||||||
peer_info = certstr.substr(pos + 1);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
error_code = RS_PEER_CERT_CLEANING_CODE_NO_END_TAG ;
|
|
||||||
return false ;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(cert.empty())
|
|
||||||
return false ;
|
|
||||||
|
|
||||||
/*
|
|
||||||
Buffer for storing the cleaned certificate. In certain cases the
|
|
||||||
cleanCertificate can be larger than the badCertificate
|
|
||||||
*/
|
|
||||||
cleanCertificate = "";
|
|
||||||
//The entire certificate begin tag
|
|
||||||
const char * beginCertTag="-----BEGIN";
|
|
||||||
//The entire certificate end tag
|
|
||||||
const char * endCertTag="-----END";
|
|
||||||
//Tag containing dots. The common part of both start and end tags
|
|
||||||
const char * commonTag="-----";
|
|
||||||
//Only BEGIN part of the begin tag
|
|
||||||
const char * beginTag="BEGIN";
|
|
||||||
//Only END part of the end tag
|
|
||||||
const char * endTag="END";
|
|
||||||
//The start index of the ----- part of the certificate begin tag
|
|
||||||
size_t beginCertStartIdx1=0;
|
|
||||||
//The start index of the BEGIN part of the certificate begin tag
|
|
||||||
size_t beginCertStartIdx2=0;
|
|
||||||
//The start index of the end part(-----) of the certificate begin tag. The begin tag ends with -----. Example -----BEGIN XPGP CERTIFICATE-----
|
|
||||||
size_t beginCertEndIdx=0;
|
|
||||||
//The start index of the ----- part of the certificate end tag
|
|
||||||
size_t endCertStartIdx1=0;
|
|
||||||
//The start index of the END part of the certificate end tag
|
|
||||||
size_t endCertStartIdx2=0;
|
|
||||||
//The start index of the end part(-----) of the certificate end tag. The begin tag ends with -----. Example -----BEGIN XPGP CERTIFICATE-----
|
|
||||||
size_t endCertEndIdx=0;
|
|
||||||
//The length of the bad certificate.
|
|
||||||
size_t lengthOfCert=certstr.length();
|
|
||||||
//The current index value in the bad certificate
|
|
||||||
size_t currBadCertIdx=0;
|
|
||||||
//Temporary index value
|
|
||||||
size_t tmpIdx=0;
|
|
||||||
//Boolean flag showing if the begin tag or the end tag has been found
|
|
||||||
bool found=false;
|
|
||||||
/*
|
|
||||||
Calculating the value of the beginCertStartIdx1 and beginCertStartIdx2. Here
|
|
||||||
we first locate the occurance of ----- and then the location of BEGIN. Next
|
|
||||||
we check if there are any non space or non new-line characters between their
|
|
||||||
occureance. If there are any other characters between the two(----- and
|
|
||||||
BEGIN), other than space and new line then it means that it is the
|
|
||||||
certificate begin tag. Here we take care of the fact that we may have
|
|
||||||
introduced some spaces and newlines in the begin tag by mistake. This takes
|
|
||||||
care of the spaces and newlines between ----- and BEGIN.
|
|
||||||
*/
|
|
||||||
|
|
||||||
while(found==false && (beginCertStartIdx1=certstr.find(commonTag,tmpIdx))!=std::string::npos)
|
|
||||||
{
|
|
||||||
beginCertStartIdx2=certstr.find(beginTag,beginCertStartIdx1+strlen(commonTag));
|
|
||||||
tmpIdx=beginCertStartIdx1+strlen(commonTag);
|
|
||||||
if(beginCertStartIdx2!=std::string::npos)
|
|
||||||
{
|
|
||||||
found=true;
|
|
||||||
for(size_t i=beginCertStartIdx1+strlen(commonTag);i<beginCertStartIdx2;i++)
|
|
||||||
{
|
|
||||||
if(certstr[i]!=' ' && certstr[i]!='\n' )
|
|
||||||
{
|
|
||||||
found=false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
begin tag not found
|
|
||||||
*/
|
|
||||||
if(!found)
|
|
||||||
{
|
|
||||||
std::cerr<<"Certificate corrupted beyond repair: No <------BEGIN > tag"<<std::endl;
|
|
||||||
error_code = RS_PEER_CERT_CLEANING_CODE_NO_BEGIN_TAG ;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
beginCertEndIdx=certstr.find(commonTag,beginCertStartIdx2);
|
|
||||||
if(beginCertEndIdx==std::string::npos)
|
|
||||||
{
|
|
||||||
std::cerr<<"Certificate corrupted beyond repair: No <------BEGIN > tag"<<std::endl;
|
|
||||||
error_code = RS_PEER_CERT_CLEANING_CODE_NO_BEGIN_TAG ;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
tmpIdx=beginCertEndIdx+strlen(commonTag);
|
|
||||||
found=false;
|
|
||||||
/*
|
|
||||||
Calculating the value of the endCertStartIdx1 and endCertStartIdx2. Here we first locate the occurance of ----- and then
|
|
||||||
the location of END. Next we check if there are any non space or non new-line characters between their occureance. If there are any other
|
|
||||||
characters between the two(----- and END), other than space and new line then it means that it is the certificate end tag.
|
|
||||||
Here we take care of the fact that we may have introduced some spaces and newlines in the end tag by mistake. This
|
|
||||||
takes care of the spaces and newlines between ----- and END.
|
|
||||||
*/
|
|
||||||
while(found==false && (endCertStartIdx1=certstr.find(commonTag,tmpIdx))!=std::string::npos)
|
|
||||||
{
|
|
||||||
endCertStartIdx2=certstr.find(endTag,endCertStartIdx1+strlen(commonTag));
|
|
||||||
tmpIdx=endCertStartIdx1+strlen(commonTag);
|
|
||||||
if(endCertStartIdx2!=std::string::npos)
|
|
||||||
{
|
|
||||||
found=true;
|
|
||||||
for(size_t i=endCertStartIdx1+strlen(commonTag);i<endCertStartIdx2;i++)
|
|
||||||
{
|
|
||||||
if(certstr[i]!=' '&& certstr[i]!='\n')
|
|
||||||
{
|
|
||||||
found=false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
end tag not found
|
|
||||||
*/
|
|
||||||
if(!found)
|
|
||||||
{
|
|
||||||
std::cerr<<"Certificate corrupted beyond repair: No <------END > tag"<<std::endl;
|
|
||||||
error_code = RS_PEER_CERT_CLEANING_CODE_NO_END_TAG ;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
endCertEndIdx=certstr.find(commonTag,endCertStartIdx2);
|
|
||||||
if(endCertEndIdx==std::string::npos || endCertEndIdx>=lengthOfCert)
|
|
||||||
{
|
|
||||||
std::cerr<<"Certificate corrupted beyond repair: No <------END > tag"<<std::endl;
|
|
||||||
error_code = RS_PEER_CERT_CLEANING_CODE_NO_END_TAG ;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
Copying the begin tag(-----BEGIN) to the clean certificate
|
|
||||||
*/
|
|
||||||
cleanCertificate += beginCertTag;
|
|
||||||
currBadCertIdx=beginCertStartIdx2+strlen(beginTag);
|
|
||||||
/*
|
|
||||||
Copying the name of the tag e.g XPGP CERTIFICATE. At the same time remove any white spaces and new line
|
|
||||||
characters.
|
|
||||||
*/
|
|
||||||
while(currBadCertIdx<beginCertEndIdx)
|
|
||||||
{
|
|
||||||
if(badCertificate[currBadCertIdx]=='\n')
|
|
||||||
{
|
|
||||||
currBadCertIdx++;
|
|
||||||
}
|
|
||||||
else if(badCertificate[currBadCertIdx]==' ' && (badCertificate[currBadCertIdx-1]==' '|| badCertificate[currBadCertIdx-1]=='\n') )
|
|
||||||
{
|
|
||||||
currBadCertIdx++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
cleanCertificate += badCertificate[currBadCertIdx];
|
|
||||||
currBadCertIdx++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
If the last character is a space we need to remove it.
|
|
||||||
*/
|
|
||||||
if(cleanCertificate.substr(cleanCertificate.length()-1, 1) == " ")
|
|
||||||
{
|
|
||||||
cleanCertificate.erase(cleanCertificate.length()-1);
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
Copying the end part of the certificate start tag(-----).
|
|
||||||
*/
|
|
||||||
cleanCertificate += commonTag;
|
|
||||||
cleanCertificate += "\n";
|
|
||||||
currBadCertIdx=currBadCertIdx+strlen(commonTag);
|
|
||||||
/*
|
|
||||||
Remove the white spaces between the end of the certificate begin tag and the actual
|
|
||||||
start of the certificate.
|
|
||||||
*/
|
|
||||||
while(badCertificate[currBadCertIdx]=='\n'|| badCertificate[currBadCertIdx]==' ')
|
|
||||||
{
|
|
||||||
currBadCertIdx++;
|
|
||||||
}
|
|
||||||
|
|
||||||
//keep the armor header
|
|
||||||
std::list<std::string> header;
|
|
||||||
header.push_back("Version");
|
|
||||||
header.push_back("Comment");
|
|
||||||
header.push_back("MessageID");
|
|
||||||
header.push_back("Hash");
|
|
||||||
header.push_back("Charset");
|
|
||||||
|
|
||||||
for (std::list<std::string>::iterator headerIt = header.begin (); headerIt != header.end(); headerIt++)
|
|
||||||
{
|
|
||||||
if (badCertificate.substr(currBadCertIdx, (*headerIt).length()) == *headerIt)
|
|
||||||
{
|
|
||||||
cleanCertificate += badCertificate.substr(currBadCertIdx, (*headerIt).length());
|
|
||||||
currBadCertIdx += (*headerIt).length();
|
|
||||||
while(currBadCertIdx<endCertStartIdx1 && badCertificate[currBadCertIdx]!='\n')
|
|
||||||
{
|
|
||||||
cleanCertificate += badCertificate[currBadCertIdx];
|
|
||||||
currBadCertIdx++;
|
|
||||||
}
|
|
||||||
cleanCertificate += "\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//add empty line after armor header
|
|
||||||
cleanCertificate += "\n";
|
|
||||||
|
|
||||||
//Start of the actual certificate. Remove spaces in the certificate
|
|
||||||
//and make sure there are 64 characters per line in the
|
|
||||||
//new cleaned certificate
|
|
||||||
int cntPerLine=0;
|
|
||||||
while(currBadCertIdx<endCertStartIdx1)
|
|
||||||
{
|
|
||||||
if(cntPerLine==64)
|
|
||||||
{
|
|
||||||
cleanCertificate += "\n";
|
|
||||||
cntPerLine=0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(badCertificate[currBadCertIdx]=='=') /* checksum */
|
|
||||||
break;
|
|
||||||
else if(badCertificate[currBadCertIdx]=='\t')
|
|
||||||
currBadCertIdx++;
|
|
||||||
else if(badCertificate[currBadCertIdx]==' ')
|
|
||||||
currBadCertIdx++;
|
|
||||||
else if(badCertificate[currBadCertIdx]=='\n')
|
|
||||||
currBadCertIdx++;
|
|
||||||
else if(is_acceptable_radix64Char(badCertificate[currBadCertIdx]))
|
|
||||||
{
|
|
||||||
cleanCertificate += badCertificate[currBadCertIdx];
|
|
||||||
cntPerLine++;
|
|
||||||
currBadCertIdx++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
std::cerr << "Warning: Invalid character in radix certificate encoding: " << badCertificate[currBadCertIdx] << std::endl;
|
|
||||||
currBadCertIdx++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(currBadCertIdx>=endCertStartIdx1)
|
|
||||||
{
|
|
||||||
std::cerr<<"Certificate corrupted beyond repair: No checksum, or no newline after first tag"<<std::endl;
|
|
||||||
error_code = RS_PEER_CERT_CLEANING_CODE_NO_CHECKSUM ;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
while(currBadCertIdx < endCertStartIdx1 && (badCertificate[currBadCertIdx] == '=' || badCertificate[currBadCertIdx] == ' ' || badCertificate[currBadCertIdx] == '\n' ))
|
|
||||||
currBadCertIdx++ ;
|
|
||||||
|
|
||||||
switch(cntPerLine % 4)
|
|
||||||
{
|
|
||||||
case 0: break ;
|
|
||||||
case 1: std::cerr<<"Certificate corrupted beyond repair: wrongnumber of chars on last line (n%4=1)"<<std::endl;
|
|
||||||
error_code = RS_PEER_CERT_CLEANING_CODE_WRONG_NUMBER;
|
|
||||||
return false ;
|
|
||||||
case 2: cleanCertificate += "==" ;
|
|
||||||
break ;
|
|
||||||
case 3: cleanCertificate += "=" ;
|
|
||||||
break ;
|
|
||||||
}
|
|
||||||
cleanCertificate += "\n=";
|
|
||||||
|
|
||||||
// if (badCertificate[currBadCertIdx] == '=')
|
|
||||||
// {
|
|
||||||
/* checksum */
|
|
||||||
|
|
||||||
while(currBadCertIdx<endCertStartIdx1)
|
|
||||||
{
|
|
||||||
if (badCertificate[currBadCertIdx]==' ')
|
|
||||||
{
|
|
||||||
currBadCertIdx++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
else if(badCertificate[currBadCertIdx]=='\n')
|
|
||||||
{
|
|
||||||
currBadCertIdx++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
cleanCertificate += badCertificate[currBadCertIdx];
|
|
||||||
cntPerLine++;
|
|
||||||
currBadCertIdx++;
|
|
||||||
}
|
|
||||||
// }
|
|
||||||
|
|
||||||
if(cleanCertificate.substr(cleanCertificate.length()-1,1)!="\n")
|
|
||||||
{
|
|
||||||
cleanCertificate += "\n";
|
|
||||||
// std::cerr<<"zeeeee"<<std::endl;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// std::cerr<<"zooooo"<<std::endl;
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
Copying the begining part of the certificate end tag. Copying
|
|
||||||
-----END part of the tag.
|
|
||||||
*/
|
|
||||||
cleanCertificate += endCertTag;
|
|
||||||
currBadCertIdx=endCertStartIdx2+strlen(endTag);
|
|
||||||
/*
|
|
||||||
Copying the name of the certificate e.g XPGP CERTIFICATE. The end tag also has the
|
|
||||||
the name of the tag.
|
|
||||||
*/
|
|
||||||
while(currBadCertIdx<endCertEndIdx)
|
|
||||||
{
|
|
||||||
if(badCertificate[currBadCertIdx]=='\n')
|
|
||||||
{
|
|
||||||
currBadCertIdx++;
|
|
||||||
}
|
|
||||||
else if( badCertificate[currBadCertIdx]==' ' && (badCertificate[currBadCertIdx-1]==' '|| badCertificate[currBadCertIdx-1]=='\n'))
|
|
||||||
{
|
|
||||||
currBadCertIdx++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
cleanCertificate += badCertificate[currBadCertIdx];
|
|
||||||
currBadCertIdx++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
If the last character is a space we need to remove it.
|
|
||||||
*/
|
|
||||||
if(cleanCertificate.substr(cleanCertificate.length()-1,1)==" ")
|
|
||||||
{
|
|
||||||
cleanCertificate.erase(cleanCertificate.length()-1);
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
Copying the end part(-----) of the end tag in the certificate.
|
|
||||||
*/
|
|
||||||
cleanCertificate += commonTag;
|
|
||||||
cleanCertificate += "\n";
|
|
||||||
|
|
||||||
error_code = RS_PEER_CERT_CLEANING_CODE_NO_ERROR ;
|
|
||||||
|
|
||||||
cleanCertificate += peer_info ;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string RsCertificate::toStdString_oldFormat() const
|
|
||||||
{
|
|
||||||
return std::string() ;
|
|
||||||
|
|
||||||
// not supported anymore.
|
|
||||||
//
|
|
||||||
std::string res ;
|
|
||||||
|
|
||||||
res += PGPKeyManagement::makeArmouredKey(binary_pgp_key,binary_pgp_key_size,pgp_version) ;
|
|
||||||
|
|
||||||
if(only_pgp)
|
|
||||||
return res ;
|
|
||||||
|
|
||||||
res += SSLID_BEGIN_SECTION ;
|
|
||||||
res += location_id.toStdString(false) ;
|
|
||||||
res += ";" ;
|
|
||||||
res += LOCATION_BEGIN_SECTION ;
|
|
||||||
res += location_name ;
|
|
||||||
res += ";\n" ;
|
|
||||||
|
|
||||||
if (hidden_node)
|
|
||||||
{
|
|
||||||
std::ostringstream os ;
|
|
||||||
os << HIDDEN_NODE_BEGIN_SECTION;
|
|
||||||
os << hidden_node_address << ";";
|
|
||||||
|
|
||||||
res += os.str() ;
|
|
||||||
res += "\n" ;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
std::ostringstream os ;
|
|
||||||
os << LOCAL_IP_BEGIN_SECTION ;
|
|
||||||
os << (int)ipv4_internal_ip_and_port[0] << "." << (int)ipv4_internal_ip_and_port[1] << "." << (int)ipv4_internal_ip_and_port[2] << "." << (int)ipv4_internal_ip_and_port[3] ;
|
|
||||||
os << ":" ;
|
|
||||||
os << ipv4_internal_ip_and_port[4]*256+ipv4_internal_ip_and_port[5] ;
|
|
||||||
os << ";" ;
|
|
||||||
|
|
||||||
os << EXTERNAL_IP_BEGIN_SECTION ;
|
|
||||||
os << (int)ipv4_external_ip_and_port[0] << "." << (int)ipv4_external_ip_and_port[1] << "." << (int)ipv4_external_ip_and_port[2] << "." << (int)ipv4_external_ip_and_port[3] ;
|
|
||||||
os << ":" ;
|
|
||||||
os << ipv4_external_ip_and_port[4]*256+ipv4_external_ip_and_port[5] ;
|
|
||||||
os << ";" ;
|
|
||||||
|
|
||||||
res += os.str() ;
|
|
||||||
res += "\n" ;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return res ;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool RsCertificate::initFromString_oldFormat(const std::string& certstr,uint32_t& /*err_code*/)
|
|
||||||
{
|
|
||||||
return false ; // this format is not supported anymore.
|
|
||||||
|
|
||||||
//parse the text to get ip address
|
|
||||||
try
|
|
||||||
{
|
|
||||||
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--";
|
|
||||||
|
|
||||||
std::string cert;
|
|
||||||
std::string peerInfo;
|
|
||||||
|
|
||||||
/* search for -----END CERTIFICATE----- */
|
|
||||||
std::string pgpend("-----END PGP PUBLIC KEY BLOCK-----");
|
|
||||||
|
|
||||||
size_t pos = certstr.find(pgpend);
|
|
||||||
|
|
||||||
if (pos != std::string::npos)
|
|
||||||
{
|
|
||||||
pos += pgpend.length();
|
|
||||||
cert = certstr.substr(0, pos);
|
|
||||||
if (pos + 1 < certstr.length())
|
|
||||||
peerInfo = certstr.substr(pos + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(cert.empty())
|
|
||||||
return false ;
|
|
||||||
|
|
||||||
// find radix 64 part.
|
|
||||||
|
|
||||||
std::string radix_cert = PGPKeyParser::extractRadixPartFromArmouredKey(certstr,pgp_version) ;
|
|
||||||
|
|
||||||
char *key_bin ;
|
|
||||||
Radix64::decode(radix_cert,key_bin,binary_pgp_key_size) ;
|
|
||||||
|
|
||||||
binary_pgp_key = (unsigned char *)key_bin ;
|
|
||||||
only_pgp = true ;
|
|
||||||
|
|
||||||
#ifdef P3PEERS_DEBUG
|
|
||||||
std::cerr << "Parsing cert for sslid, location, ext and local address details. : " << certstr << std::endl;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//let's parse the ssl id
|
|
||||||
size_t parsePosition = peerInfo.find(CERT_SSL_ID);
|
|
||||||
std::cerr << "sslid position : " << parsePosition << std::endl;
|
|
||||||
if (parsePosition != std::string::npos) {
|
|
||||||
parsePosition += CERT_SSL_ID.length();
|
|
||||||
std::string subCert = peerInfo.substr(parsePosition);
|
|
||||||
parsePosition = subCert.find(";");
|
|
||||||
if (parsePosition != std::string::npos) {
|
|
||||||
std::string ssl_id = subCert.substr(0, parsePosition);
|
|
||||||
std::cerr << "SSL id : " << ssl_id << std::endl;
|
|
||||||
|
|
||||||
location_id = SSLIdType(ssl_id) ;
|
|
||||||
only_pgp = false ;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//let's parse the location
|
|
||||||
parsePosition = peerInfo.find(CERT_LOCATION);
|
|
||||||
std::cerr << "location position : " << parsePosition << std::endl;
|
|
||||||
if (parsePosition != std::string::npos) {
|
|
||||||
parsePosition += CERT_LOCATION.length();
|
|
||||||
std::string subCert = peerInfo.substr(parsePosition);
|
|
||||||
parsePosition = subCert.find(";");
|
|
||||||
if (parsePosition != std::string::npos) {
|
|
||||||
std::string location = subCert.substr(0, parsePosition);
|
|
||||||
std::cerr << "location : " << location << std::endl;
|
|
||||||
|
|
||||||
location_name = location;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//let's parse ip local address
|
|
||||||
parsePosition = peerInfo.find(CERT_LOCAL_IP);
|
|
||||||
std::cerr << "local ip position : " << parsePosition << std::endl;
|
|
||||||
if (parsePosition != std::string::npos) {
|
|
||||||
parsePosition += CERT_LOCAL_IP.length();
|
|
||||||
std::string subCert = peerInfo.substr(parsePosition);
|
|
||||||
parsePosition = subCert.find(":");
|
|
||||||
if (parsePosition != std::string::npos) {
|
|
||||||
std::string local_ip = subCert.substr(0, parsePosition);
|
|
||||||
std::cerr << "Local Ip : " << local_ip << std::endl;
|
|
||||||
|
|
||||||
unsigned short localPort ;
|
|
||||||
|
|
||||||
//let's parse local port
|
|
||||||
subCert = subCert.substr(parsePosition + 1);
|
|
||||||
parsePosition = subCert.find(";");
|
|
||||||
if (parsePosition != std::string::npos) {
|
|
||||||
std::string local_port = subCert.substr(0, parsePosition);
|
|
||||||
std::cerr << "Local port : " << local_port << std::endl;
|
|
||||||
sscanf(local_port.c_str(), "%hu", &localPort);
|
|
||||||
}
|
|
||||||
|
|
||||||
scan_ip(local_ip,localPort,ipv4_internal_ip_and_port) ;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//let's parse ip ext address
|
|
||||||
parsePosition = peerInfo.find(CERT_EXT_IP);
|
|
||||||
std::cerr << "Ext ip position : " << parsePosition << std::endl;
|
|
||||||
if (parsePosition != std::string::npos) {
|
|
||||||
parsePosition = parsePosition + CERT_EXT_IP.length();
|
|
||||||
std::string subCert = peerInfo.substr(parsePosition);
|
|
||||||
parsePosition = subCert.find(":");
|
|
||||||
if (parsePosition != std::string::npos) {
|
|
||||||
std::string ext_ip = subCert.substr(0, parsePosition);
|
|
||||||
std::cerr << "Ext Ip : " << ext_ip << std::endl;
|
|
||||||
|
|
||||||
unsigned short extPort ;
|
|
||||||
//let's parse ext port
|
|
||||||
subCert = subCert.substr(parsePosition + 1);
|
|
||||||
parsePosition = subCert.find(";");
|
|
||||||
if (parsePosition != std::string::npos) {
|
|
||||||
std::string ext_port = subCert.substr(0, parsePosition);
|
|
||||||
std::cerr << "Ext port : " << ext_port << std::endl;
|
|
||||||
sscanf(ext_port.c_str(), "%hu", &extPort);
|
|
||||||
}
|
|
||||||
|
|
||||||
scan_ip(ext_ip,extPort,ipv4_external_ip_and_port) ;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//let's parse DynDNS
|
|
||||||
parsePosition = peerInfo.find(CERT_DYNDNS);
|
|
||||||
std::cerr << "location DynDNS : " << parsePosition << std::endl;
|
|
||||||
if (parsePosition != std::string::npos) {
|
|
||||||
parsePosition += CERT_DYNDNS.length();
|
|
||||||
std::string subCert = peerInfo.substr(parsePosition);
|
|
||||||
parsePosition = subCert.find(";");
|
|
||||||
if (parsePosition != std::string::npos) {
|
|
||||||
std::string DynDNS = subCert.substr(0, parsePosition);
|
|
||||||
std::cerr << "DynDNS : " << DynDNS << std::endl;
|
|
||||||
|
|
||||||
dns_name = DynDNS;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
catch (...)
|
|
||||||
{
|
|
||||||
std::cerr << "ConnectFriendWizard : Parse ip address error." << std::endl;
|
|
||||||
return false ;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,7 +15,6 @@ class RsCertificate
|
|||||||
typedef enum { RS_CERTIFICATE_OLD_FORMAT, RS_CERTIFICATE_RADIX } Format ;
|
typedef enum { RS_CERTIFICATE_OLD_FORMAT, RS_CERTIFICATE_RADIX } Format ;
|
||||||
|
|
||||||
// Constructs from text.
|
// Constructs from text.
|
||||||
// - old format: The input string must comply with the GPG format (See RFC4880)
|
|
||||||
// - new format: The input string should only contain radix chars and spaces/LF/tabs.
|
// - new format: The input string should only contain radix chars and spaces/LF/tabs.
|
||||||
//
|
//
|
||||||
RsCertificate(const std::string& input_string) ;
|
RsCertificate(const std::string& input_string) ;
|
||||||
@ -29,7 +28,6 @@ class RsCertificate
|
|||||||
virtual ~RsCertificate();
|
virtual ~RsCertificate();
|
||||||
|
|
||||||
// Outut to text
|
// Outut to text
|
||||||
std::string toStdString_oldFormat() const ;
|
|
||||||
std::string toStdString() const ;
|
std::string toStdString() const ;
|
||||||
|
|
||||||
std::string ext_ip_string() const ;
|
std::string ext_ip_string() const ;
|
||||||
@ -51,11 +49,9 @@ class RsCertificate
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
static bool cleanCertificate(const std::string& input,std::string& output,int&) ; // new radix format
|
static bool cleanCertificate(const std::string& input,std::string& output,int&) ; // new radix format
|
||||||
static bool cleanCertificate_oldFormat(const std::string& input,std::string& output,int&) ; // old text format
|
|
||||||
static void scan_ip(const std::string& ip_string, unsigned short port,unsigned char *destination_memory) ;
|
static void scan_ip(const std::string& ip_string, unsigned short port,unsigned char *destination_memory) ;
|
||||||
|
|
||||||
bool initFromString(const std::string& str,uint32_t& err_code) ;
|
bool initFromString(const std::string& str,uint32_t& err_code) ;
|
||||||
bool initFromString_oldFormat(const std::string& str,uint32_t& err_code) ;
|
|
||||||
|
|
||||||
static void addPacket(uint8_t ptag, const unsigned char *mem, size_t size, unsigned char *& buf, size_t& offset, size_t& buf_size) ;
|
static void addPacket(uint8_t ptag, const unsigned char *mem, size_t size, unsigned char *& buf, size_t& offset, size_t& buf_size) ;
|
||||||
|
|
||||||
|
@ -342,9 +342,9 @@ class RsPeers
|
|||||||
virtual bool getAllowServerIPDetermination() = 0 ;
|
virtual bool getAllowServerIPDetermination() = 0 ;
|
||||||
|
|
||||||
/* Auth Stuff */
|
/* Auth Stuff */
|
||||||
virtual std::string GetRetroshareInvite(const std::string& ssl_id,bool include_signatures,bool old_format = false) = 0;
|
virtual std::string GetRetroshareInvite(const std::string& ssl_id,bool include_signatures) = 0;
|
||||||
virtual bool GetPGPBase64StringAndCheckSum(const std::string& gpg_id,std::string& gpg_base64_string,std::string& gpg_base64_checksum) = 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 std::string GetRetroshareInvite(bool include_signatures) = 0;
|
||||||
virtual bool hasExportMinimal() = 0 ;
|
virtual bool hasExportMinimal() = 0 ;
|
||||||
|
|
||||||
// Add keys to the keyring
|
// Add keys to the keyring
|
||||||
|
@ -958,9 +958,9 @@ bool p3Peers::setProxyServer(const std::string &addr_str, const uint16_t port)
|
|||||||
//===========================================================================
|
//===========================================================================
|
||||||
/* Auth Stuff */
|
/* Auth Stuff */
|
||||||
std::string
|
std::string
|
||||||
p3Peers::GetRetroshareInvite(bool include_signatures,bool old_format)
|
p3Peers::GetRetroshareInvite(bool include_signatures)
|
||||||
{
|
{
|
||||||
return GetRetroshareInvite(getOwnId(),include_signatures,old_format);
|
return GetRetroshareInvite(getOwnId(),include_signatures);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool p3Peers::GetPGPBase64StringAndCheckSum( const std::string& gpg_id,
|
bool p3Peers::GetPGPBase64StringAndCheckSum( const std::string& gpg_id,
|
||||||
@ -988,7 +988,7 @@ bool p3Peers::GetPGPBase64StringAndCheckSum( const std::string& gpg_id,
|
|||||||
return true ;
|
return true ;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string p3Peers::GetRetroshareInvite(const std::string& ssl_id,bool include_signatures,bool old_format)
|
std::string p3Peers::GetRetroshareInvite(const std::string& ssl_id,bool include_signatures)
|
||||||
{
|
{
|
||||||
#ifdef P3PEERS_DEBUG
|
#ifdef P3PEERS_DEBUG
|
||||||
std::cerr << "p3Peers::GetRetroshareInvite()" << std::endl;
|
std::cerr << "p3Peers::GetRetroshareInvite()" << std::endl;
|
||||||
@ -1011,10 +1011,7 @@ std::string p3Peers::GetRetroshareInvite(const std::string& ssl_id,bool include_
|
|||||||
|
|
||||||
RsCertificate cert( Detail,mem_block,mem_block_size ) ;
|
RsCertificate cert( Detail,mem_block,mem_block_size ) ;
|
||||||
|
|
||||||
if(old_format)
|
return cert.toStdString() ;
|
||||||
return cert.toStdString_oldFormat() ;
|
|
||||||
else
|
|
||||||
return cert.toStdString() ;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,9 +102,9 @@ virtual bool getAllowServerIPDetermination() ;
|
|||||||
|
|
||||||
/* Auth Stuff */
|
/* Auth Stuff */
|
||||||
// Get the invitation (GPG cert + local/ext address + SSL id for the given peer)
|
// Get the invitation (GPG cert + local/ext address + SSL id for the given peer)
|
||||||
virtual std::string GetRetroshareInvite(const std::string& ssl_id,bool include_signatures,bool old_format = false);
|
virtual std::string GetRetroshareInvite(const std::string& ssl_id,bool include_signatures);
|
||||||
// same but for own id
|
// same but for own id
|
||||||
virtual std::string GetRetroshareInvite(bool include_signatures,bool old_format = false);
|
virtual std::string GetRetroshareInvite(bool include_signatures);
|
||||||
virtual bool GetPGPBase64StringAndCheckSum(const std::string& gpg_id,std::string& gpg_base64_string,std::string& gpg_base64_checksum) ;
|
virtual bool GetPGPBase64StringAndCheckSum(const std::string& gpg_id,std::string& gpg_base64_string,std::string& gpg_base64_checksum) ;
|
||||||
|
|
||||||
virtual bool hasExportMinimal() ;
|
virtual bool hasExportMinimal() ;
|
||||||
|
@ -400,7 +400,7 @@ void ConfCertDialog::loadInvitePage()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string invite = rsPeers->GetRetroshareInvite(detail.id,ui._shouldAddSignatures_CB->isChecked(),ui._useOldFormat_CB->isChecked()) ; // this needs to be a SSL id
|
std::string invite = rsPeers->GetRetroshareInvite(detail.id,ui._shouldAddSignatures_CB->isChecked()) ; // this needs to be a SSL id
|
||||||
|
|
||||||
ui.userCertificateText->setReadOnly(true);
|
ui.userCertificateText->setReadOnly(true);
|
||||||
ui.userCertificateText->setMinimumHeight(200);
|
ui.userCertificateText->setMinimumHeight(200);
|
||||||
|
@ -668,7 +668,7 @@ void ConnectFriendWizard::accept()
|
|||||||
|
|
||||||
void ConnectFriendWizard::updateOwnCert()
|
void ConnectFriendWizard::updateOwnCert()
|
||||||
{
|
{
|
||||||
std::string invite = rsPeers->GetRetroshareInvite(ui->userCertIncludeSignaturesButton->isChecked(),ui->userCertOldFormatButton->isChecked());
|
std::string invite = rsPeers->GetRetroshareInvite(ui->userCertIncludeSignaturesButton->isChecked());
|
||||||
|
|
||||||
std::cerr << "TextPage() getting Invite: " << invite << std::endl;
|
std::cerr << "TextPage() getting Invite: " << invite << std::endl;
|
||||||
|
|
||||||
|
@ -112,7 +112,7 @@ void
|
|||||||
CryptoPage::load()
|
CryptoPage::load()
|
||||||
{
|
{
|
||||||
/* Loads ouer default Puplickey */
|
/* Loads ouer default Puplickey */
|
||||||
ui.certplainTextEdit->setPlainText(QString::fromUtf8(rsPeers->GetRetroshareInvite(ui._includeSignatures_CB->isChecked(),ui._useOldFormat_CB->isChecked()).c_str()));
|
ui.certplainTextEdit->setPlainText(QString::fromUtf8(rsPeers->GetRetroshareInvite(ui._includeSignatures_CB->isChecked()).c_str()));
|
||||||
}
|
}
|
||||||
void
|
void
|
||||||
CryptoPage::copyRSLink()
|
CryptoPage::copyRSLink()
|
||||||
|
Loading…
Reference in New Issue
Block a user