diff --git a/libretroshare/src/pqi/cleanupxpgp.cc b/libretroshare/src/pqi/cleanupxpgp.cc index 8e74ba4f0..c2ed8858c 100644 --- a/libretroshare/src/pqi/cleanupxpgp.cc +++ b/libretroshare/src/pqi/cleanupxpgp.cc @@ -27,7 +27,7 @@ #include #include //strlen #include - +#include /* Method for cleaning up the certificate. This method removes any unnecessay white spaces and unnecessary new line characters in the certificate. Also it makes sure that there are 64 characters per line in @@ -41,8 +41,10 @@ end tag we take care of cases like ----- END XPGP . Here extra empty spaces h introduced and the actual tag should have been -----END XPGP */ -std::string cleanUpCertificate(const std::string& badCertificate) + +std::string cleanUpCertificate(const std::string& badCertificate,int& error_code) { + error_code = RS_PEER_CERT_CLEANING_CODE_UNKOWN_ERROR ; // default /* Buffer for storing the cleaned certificate. In certain cases the cleanCertificate can be larger than the badCertificate @@ -79,11 +81,14 @@ std::string cleanUpCertificate(const std::string& badCertificate) //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. + 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=badCertificate.find(commonTag,tmpIdx))!=std::string::npos) @@ -114,12 +119,14 @@ std::string cleanUpCertificate(const std::string& badCertificate) if(!found) { std::cerr<<"Certificate corrupted beyond repair: No <------BEGIN > tag"< tag"< tag"<=lengthOfCert) { std::cerr<<"Certificate corrupted beyond repair: No <------END > tag"<=endCertStartIdx1) + { + std::cerr<<"Certificate corrupted beyond repair: No checksum, or no newline after first tag"<toPlainText().toUtf8().constData(); std::string cleanCert; + int error_code ; - if (rsPeers->cleanCertificate(cert, cleanCert)) { + if (rsPeers->cleanCertificate(cert, cleanCert,error_code)) { friendCertEdit->setText(QString::fromStdString(cleanCert)); + + if(error_code > 0) + { + QString msg ; + + switch(error_code) + { + case RS_PEER_CERT_CLEANING_CODE_NO_BEGIN_TAG: msg = tr("No or misspelled BEGIN tag found") ; + break ; + case RS_PEER_CERT_CLEANING_CODE_NO_END_TAG: msg = tr("No or misspelled END tag found") ; + break ; + case RS_PEER_CERT_CLEANING_CODE_NO_CHECKSUM: msg = tr("No checksum found (the last 5 chars should be separated by a '=' char), or no newline after tag line (e.g. line beginning with Version:)") ; + break ; + default: + msg = tr("Unknown error. Your cert is probably not even a certificate.") ; + break ; + } + QMessageBox::information(NULL,tr("Certificate cleaning error"),msg) ; + } } + QFont font("Courier New",10,50,false); + font.setStyleHint(QFont::TypeWriter,QFont::PreferMatch); + font.setStyle(QFont::StyleNormal); + friendCertEdit->setFont(font); } //