Merge pull request from csoler/v0.6-ShortInvites

fixed error handling when you enter your own certificate in connect f…
This commit is contained in:
csoler 2019-09-30 21:46:52 +02:00 committed by GitHub
commit f04b32eef8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 4 deletions
libretroshare/src/rsserver
retroshare-gui/src/gui/connect

@ -1148,6 +1148,7 @@ enum class RsShortInviteFieldType : uint8_t
PEER_NAME = 0x01,
LOCATOR = 0x02,
PGP_FINGERPRINT = 0x03,
CHECKSUM = 0x04,
/* The following will be deprecated, and ported to LOCATOR when generic
* trasport layer will be implemented */
@ -1266,6 +1267,17 @@ bool p3Peers::getShortInvite(
offset += tLocator.size();
}
}
uint32_t computed_crc = PGPKeyManagement::compute24bitsCRC(buf,offset) ;
// handle endian issues.
unsigned char mem[3] ;
mem[0] = computed_crc & 0xff ;
mem[1] = (computed_crc >> 8 ) & 0xff ;
mem[2] = (computed_crc >> 16) & 0xff ;
addPacketHeader( RsShortInviteFieldType::CHECKSUM,3,buf,offset,buf_size);
memcpy(&buf[offset],mem,3);
offset += 3;
Radix64::encode(buf, static_cast<int>(offset), invite);
@ -1299,6 +1311,7 @@ bool p3Peers::parseShortInvite(const std::string& inviteStrUrl, RsPeerDetails& d
unsigned char* buf = bf.data();
size_t total_s = 0;
bool CRC_ok = false ; // not checked yet
while(total_s < size)
{
@ -1373,6 +1386,25 @@ bool p3Peers::parseShortInvite(const std::string& inviteStrUrl, RsPeerDetails& d
details.hiddenNodeAddress = std::string((char*)&buf[6],s-6);
break;
case RsShortInviteFieldType::CHECKSUM:
{
if(s != 3 || total_s+3 != size) // make sure the checksum is the last section
{
err_code = CERTIFICATE_PARSING_ERROR_INVALID_CHECKSUM_SECTION;
return false;
}
uint32_t computed_crc = PGPKeyManagement::compute24bitsCRC(bf.data(),size-5);
uint32_t certificate_crc = static_cast<uint32_t>( buf[0] + (buf[1] << 8) + (buf[2] << 16) );
if(computed_crc != certificate_crc)
{
err_code = CERTIFICATE_PARSING_ERROR_CHECKSUM_ERROR;
return false;
}
CRC_ok = true;
break;
}
}
buf = &buf[s];
@ -1396,6 +1428,11 @@ bool p3Peers::parseShortInvite(const std::string& inviteStrUrl, RsPeerDetails& d
else
details.skip_pgp_signature_validation = true;
if(!CRC_ok)
{
err_code = CERTIFICATE_PARSING_ERROR_CHECKSUM_ERROR;
return false;
}
if(details.gpg_id.isNull())
{
err_code = CERTIFICATE_PARSING_ERROR_MISSING_PGP_FINGERPRINT;

@ -596,7 +596,7 @@ static void sendMail(QString sAddress, QString sSubject, QString sBody)
bool ConnectFriendWizard::validateCurrentPage()
{
error = true;
error = false;
switch ((Page) currentId()) {
case Page_WebMail:
@ -616,14 +616,14 @@ bool ConnectFriendWizard::validateCurrentPage()
if(peerDetails.id == rsPeers->getOwnId())
{
setField("errorMessage", tr("This is your own certificate! You would not want to make friend with yourself. Wouldn't you?") ) ;
error = false;
error = true;
}
break;
}
// error message
setField("errorMessage", tr("Certificate Load Failed") + ": \n\n" + getErrorString(cert_load_error_code)) ;
error = false;
error = true;
break;
}
case Page_ErrorMessage:
@ -638,7 +638,7 @@ bool ConnectFriendWizard::validateCurrentPage()
int ConnectFriendWizard::nextId() const
{
switch ((Page) currentId()) {
case Page_Text: return Page_Conclusion;
case Page_Text: return error?Page_ErrorMessage:Page_Conclusion;
case Page_WebMail:
case Page_ErrorMessage:
case Page_Conclusion: