attempt to make GPG errors more verbose at cert exchange time

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4096 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2011-03-15 23:15:46 +00:00
parent 2399978102
commit 7049920f68
5 changed files with 27 additions and 17 deletions

View File

@ -80,7 +80,7 @@ static gpg_error_t keySignCallback(void *, gpgme_status_code_t, \
static gpg_error_t trustCallback(void *, gpgme_status_code_t, \
const char *, int);
static void ProcessPGPmeError(gpgme_error_t ERR);
static std::string ProcessPGPmeError(gpgme_error_t ERR);
/* Function to sign X509_REQ via GPGme.
*/
@ -416,7 +416,8 @@ void AuthGPGimpl::processServices()
#endif
/* load the certificate */
LoadCertificateFromString(loadOrSave->m_certGpg, loadOrSave->m_certGpgId);
std::string error_string ;
LoadCertificateFromString(loadOrSave->m_certGpg, loadOrSave->m_certGpgId,error_string);
} else {
/* process save operation */
@ -823,16 +824,22 @@ bool AuthGPGimpl::printKeys()
return printOwnKeys_locked();
}
void ProcessPGPmeError(gpgme_error_t ERR)
std::string ProcessPGPmeError(gpgme_error_t ERR)
{
gpgme_err_code_t code = gpgme_err_code(ERR);
gpgme_err_source_t src = gpgme_err_source(ERR);
std::ostringstream ss ;
if(code > 0)
{
std::cerr << "GPGme ERROR: Code: " << code << " Source: " << src << std::endl;
std::cerr << "GPGme ERROR: " << gpgme_strerror(ERR) << std::endl;
ss << "GPGme ERROR: Code: " << code << " Source: " << src << std::endl;
ss << "GPGme ERROR: " << gpgme_strerror(ERR) << std::endl;
}
else
return std::string("Unknown error") ;
return ss.str() ;
}
void print_pgpme_verify_summary(unsigned int summary)
@ -1394,12 +1401,10 @@ std::string AuthGPGimpl::SaveCertificateToString(const std::string &id)
}
/* import to GnuPG and other Certificates */
bool AuthGPGimpl::LoadCertificateFromString(const std::string &str, std::string &gpg_id)
bool AuthGPGimpl::LoadCertificateFromString(const std::string &str, std::string &gpg_id,std::string& error_string)
{
if (str == "") {
#ifdef GPG_DEBUG
std::cerr << "AuthGPGimpl::LoadCertificateFromString() cert is empty string, returning false." << std::endl;
#endif
error_string = "Certificate is an empty string." ;
return false;
}
int imported = 0;
@ -1415,8 +1420,11 @@ bool AuthGPGimpl::LoadCertificateFromString(const std::string &str, std::string
#endif
gpgme_data_t gpgmeData;
if (GPG_ERR_NO_ERROR != gpgme_data_new_from_mem(&gpgmeData, cleancert.c_str(), cleancert.length(), 1))
gpg_error_t ERR ;
if (GPG_ERR_NO_ERROR != (ERR = gpgme_data_new_from_mem(&gpgmeData, cleancert.c_str(), cleancert.length(), 1)))
{
error_string = ProcessPGPmeError(ERR) ;
std::cerr << "Error create Data" << std::endl;
return false;
}
@ -1424,9 +1432,10 @@ bool AuthGPGimpl::LoadCertificateFromString(const std::string &str, std::string
/* move string data to gpgmeData */
gpgme_set_armor (CTX, 1);
if (GPG_ERR_NO_ERROR != gpgme_op_import (CTX,gpgmeData))
if (GPG_ERR_NO_ERROR != (ERR = gpgme_op_import (CTX,gpgmeData)))
{
std::cerr << "AuthGPGimpl::LoadCertificateFromString() Error Importing Certificate" << std::endl;
error_string = ProcessPGPmeError(ERR) ;
gpgme_data_release (gpgmeData);
return false ;
}
@ -1436,6 +1445,7 @@ bool AuthGPGimpl::LoadCertificateFromString(const std::string &str, std::string
if(res == NULL || res->imports == NULL) {
gpgme_data_release (gpgmeData);
error_string = "Certificate is corrupted." ;
return false ;
}

View File

@ -212,7 +212,7 @@ virtual bool isGPGId(const std::string &id) = 0;
* STAGE 4: Loading and Saving Certificates. (Strings and Files)
*
****/
virtual bool LoadCertificateFromString(const std::string &pem, std::string &gpg_id) = 0;
virtual bool LoadCertificateFromString(const std::string &pem, std::string &gpg_id,std::string& error_string) = 0;
virtual std::string SaveCertificateToString(const std::string &id) = 0;
/*********************************************************************************/
@ -332,7 +332,7 @@ virtual bool isGPGId(const std::string &id);
* STAGE 4: Loading and Saving Certificates. (Strings and Files)
*
****/
virtual bool LoadCertificateFromString(const std::string &pem, std::string &gpg_id);
virtual bool LoadCertificateFromString(const std::string &pem, std::string &gpg_id,std::string& error_string);
virtual std::string SaveCertificateToString(const std::string &id);
/*********************************************************************************/

View File

@ -215,7 +215,7 @@ virtual std::string GetRetroshareInvite(const std::string& ssl_id) = 0;
virtual std::string GetRetroshareInvite() = 0;
virtual bool loadCertificateFromFile(const std::string &fname, std::string &ssl_id, std::string &gpg_id) = 0;
virtual bool loadDetailsFromStringCert(const std::string &certGPG, RsPeerDetails &pd) = 0;
virtual bool loadDetailsFromStringCert(const std::string &certGPG, RsPeerDetails &pd,std::string& error_string) = 0;
virtual bool saveCertificateToFile(const std::string &id, const std::string &fname) = 0;
virtual std::string saveCertificateToString(const std::string &id) = 0;

View File

@ -959,7 +959,7 @@ bool p3Peers::loadCertificateFromFile(const std::string &fname, std::string &id
bool p3Peers::loadDetailsFromStringCert(const std::string &certstr, RsPeerDetails &pd)
bool p3Peers::loadDetailsFromStringCert(const std::string &certstr, RsPeerDetails &pd,std::string& error_string)
{
#ifdef P3PEERS_DEBUG
std::cerr << "p3Peers::LoadCertificateFromString() ";
@ -978,7 +978,7 @@ bool p3Peers::loadDetailsFromStringCert(const std::string &certstr, RsPeerDetai
std::string pgpCert = certstr.substr(0, parsePosition);
std::string gpg_id;
std::string cleancert = cleanUpCertificate(pgpCert);
AuthGPG::getAuthGPG()->LoadCertificateFromString(cleancert, gpg_id);
AuthGPG::getAuthGPG()->LoadCertificateFromString(cleancert, gpg_id,error_string);
AuthGPG::getAuthGPG()->getGPGDetails(gpg_id, pd);
if (gpg_id == "") {
return false;

View File

@ -94,7 +94,7 @@ virtual std::string GetRetroshareInvite(const std::string& ssl_id);
virtual std::string GetRetroshareInvite();
virtual bool loadCertificateFromFile(const std::string &fname, std::string &id, std::string &gpg_id);
virtual bool loadDetailsFromStringCert(const std::string &cert, RsPeerDetails &pd);
virtual bool loadDetailsFromStringCert(const std::string &cert, RsPeerDetails &pd,std::string& error_string);
virtual bool saveCertificateToFile(const std::string &id, const std::string &fname);
virtual std::string saveCertificateToString(const std::string &id);