Changed some parameters from "std::string" to "const std::string&" in rsinit.h.

Log the error messages from gpgme (ProcessPGPmeError) to stderr.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4560 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2011-08-12 20:02:00 +00:00
parent 70d02c718d
commit 43c0594d18
5 changed files with 94 additions and 137 deletions

View file

@ -93,7 +93,7 @@ gpgcert::~gpgcert()
{
if (key)
{
gpgme_key_unref(key);
gpgme_key_unref(key);
}
}
@ -904,8 +904,9 @@ bool AuthGPGimpl::DoOwnSignature(const void *data, unsigned int datalen, void *b
gpg_error_t ERR;
if (GPG_ERR_NO_ERROR != (ERR = gpgme_op_sign(CTX,gpgmeData, gpgmeSig, mode)))
{
ProcessPGPmeError(ERR);
std::cerr << "AuthGPGimpl::Sign FAILED ERR: " << ERR << std::endl;
std::cerr << "AuthGPGimpl::Sign FAILED ERR: " << ERR << std::endl;
std::cerr << ProcessPGPmeError(ERR) << std::endl;
gpgme_data_release(gpgmeSig);
gpgme_data_release(gpgmeData);
gpgme_signers_clear(CTX);
@ -997,11 +998,11 @@ bool AuthGPGimpl::VerifySignature(const void *data, int datalen, const void *sig
gpgme_set_armor (CTX, 0);
gpgme_error_t ERR;
if (GPG_ERR_NO_ERROR != (ERR = gpgme_op_verify(CTX,gpgmeSig, gpgmeData, NULL)))
{
ProcessPGPmeError(ERR);
std::cerr << "AuthGPGimpl::Verify FAILED" << std::endl;
}
if (GPG_ERR_NO_ERROR != (ERR = gpgme_op_verify(CTX,gpgmeSig, gpgmeData, NULL)))
{
std::cerr << "AuthGPGimpl::Verify FAILED" << std::endl;
std::cerr << ProcessPGPmeError(ERR) << std::endl;
}
gpgme_verify_result_t res = gpgme_op_verify_result(CTX);
@ -1084,8 +1085,8 @@ bool AuthGPGimpl::GeneratePGPCertificate(std::string name, std::string email,
if(GPG_ERR_NO_ERROR != (ERR = gpgme_op_genkey(CTX, setKeyPairParams(true, 2048, name, "generated by Retroshare", email, \
passwd).c_str(), NULL, NULL))) {
ProcessPGPmeError(ERR);
std::cerr << "Error generating the key" << std::endl;
std::cerr << ProcessPGPmeError(ERR) << std::endl;
return 0;
}
@ -1202,37 +1203,38 @@ bool AuthGPGimpl::getGPGDetails(const std::string &id, RsPeerDetails &d)
return false;
}
bool AuthGPGimpl::decryptText(gpgme_data_t CIPHER, gpgme_data_t PLAIN) {
RsStackMutex stack(gpgMtxEngine); /******* LOCKED ******/
gpgme_set_armor (CTX, 1);
bool AuthGPGimpl::decryptText(gpgme_data_t CIPHER, gpgme_data_t PLAIN)
{
RsStackMutex stack(gpgMtxEngine); /******* LOCKED ******/
gpgme_set_armor (CTX, 1);
gpg_error_t ERR;
cleanupZombies(2); // cleanup zombies under OSX. (Called before gpgme operation)
if (GPG_ERR_NO_ERROR != (ERR = gpgme_op_decrypt (CTX, CIPHER, PLAIN)))
{
ProcessPGPmeError(ERR);
std::cerr << "AuthGPGimpl::decryptText() Error decrypting text." << std::endl;
std::cerr << "AuthGPGimpl::decryptText() Error decrypting text" << std::endl;
std::cerr << ProcessPGPmeError(ERR) << std::endl;
return false;
}
return true;
}
bool AuthGPGimpl::encryptText(gpgme_data_t PLAIN, gpgme_data_t CIPHER) {
RsStackMutex stack(gpgMtxEngine); /******* LOCKED ******/
bool AuthGPGimpl::encryptText(gpgme_data_t PLAIN, gpgme_data_t CIPHER)
{
RsStackMutex stack(gpgMtxEngine); /******* LOCKED ******/
gpgme_encrypt_flags_t* flags = new gpgme_encrypt_flags_t();
gpgme_key_t keys[2] = {mOwnGpgCert.key, NULL};
gpgme_set_armor (CTX, 1);
gpgme_set_armor (CTX, 1);
gpg_error_t ERR;
cleanupZombies(2); // cleanup zombies under OSX. (Called before gpgme operation)
if (GPG_ERR_NO_ERROR != (ERR = gpgme_op_encrypt(CTX, keys, *flags, PLAIN, CIPHER)))
{
ProcessPGPmeError(ERR);
std::cerr << "AuthGPGimpl::encryptText() Error encrypting text." << std::endl;
std::cerr << "AuthGPGimpl::encryptText() Error encrypting text" << std::endl;
std::cerr << ProcessPGPmeError(ERR) << std::endl;
return false;
}
@ -1415,13 +1417,13 @@ bool AuthGPGimpl::LoadCertificateFromString(const std::string &str, std::string
#endif
gpgme_data_t gpgmeData;
gpg_error_t ERR ;
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;
error_string = ProcessPGPmeError(ERR) ;
std::cerr << "Error create Data: " << error_string << std::endl;
return false;
}
/* move string data to gpgmeData */
@ -1869,7 +1871,7 @@ static gpg_error_t keySignCallback(void *opaque, gpgme_status_code_t status, \
fprintf(stderr,"keySignCallback Error status\n");
ProcessPGPmeError(params->err);
std::cerr << ProcessPGPmeError(params->err) << std::endl;
return params->err;
}
@ -2107,7 +2109,7 @@ static gpg_error_t keySignCallback(void *opaque, gpgme_status_code_t status, \
}
fprintf(stderr,"keySignCallback Error status\n");
ProcessPGPmeError(params->err);
std::cerr << ProcessPGPmeError(params->err) << std::endl;
return params->err;
}

View file

@ -72,11 +72,9 @@ class RsInit
* Account Details (Combined GPG+SSL Setup)
*/
static bool getPreferedAccountId(std::string &id);
static bool getPGPEngineFileName(std::string &fileName);
static bool getPGPEngineFileName(std::string &fileName);
static bool getAccountIds(std::list<std::string> &ids);
static bool getAccountDetails(std::string id,
std::string &gpgId, std::string &gpgName,
std::string &gpgEmail, std::string &sslName);
static bool getAccountDetails(std::string id, std::string &gpgId, std::string &gpgName, std::string &gpgEmail, std::string &sslName);
static bool ValidateCertificate(std::string &userName) ;
@ -85,24 +83,24 @@ class RsInit
* Generating GPGme Account
*/
static int GetPGPLogins(std::list<std::string> &pgpIds);
static int GetPGPLoginDetails(std::string id, std::string &name, std::string &email);
static bool GeneratePGPCertificate(std::string name, std::string email, std::string passwd, std::string &pgpId, std::string &errString);
static int GetPGPLoginDetails(const std::string& id, std::string &name, std::string &email);
static bool GeneratePGPCertificate(const std::string&, const std::string& email, const std::string& passwd, std::string &pgpId, std::string &errString);
/*!
* Login GGP
*/
static bool SelectGPGAccount(const std::string& gpgId);
static bool LoadGPGPassword(std::string passwd);
static bool LoadGPGPassword(const std::string& passwd);
/*!
* Create SSL Certificates
*/
static bool GenerateSSLCertificate(std::string name, std::string org, std::string loc, std::string country, std::string passwd, std::string &sslId, std::string &errString);
static bool GenerateSSLCertificate(const std::string& name, const std::string& org, const std::string& loc, const std::string& country, const std::string& passwd, std::string &sslId, std::string &errString);
/*!
* intialises directories for passwords and ssl keys
*/
static bool LoadPassword(std::string id, std::string passwd) ;
static bool LoadPassword(const std::string& id, const std::string& passwd) ;
/*!
* Final Certificate load. This can be called if:
@ -112,8 +110,7 @@ class RsInit
* This wrapper is used to lock the profile first before
* finalising the login
*/
static int LockAndLoadCertificates(bool autoLoginNT, std::string& lockFilePath);
static int LockAndLoadCertificates(bool autoLoginNT, std::string& lockFilePath);
/*!
* Post Login Options
@ -140,10 +137,10 @@ class RsInit
static void setupBaseDir();
/* Account Details */
static bool get_configinit(std::string dir, std::string &id);
static bool create_configinit(std::string dir, std::string id);
static bool get_configinit(const std::string& dir, std::string &id);
static bool create_configinit(const std::string& dir, const std::string& id);
static bool setupAccount(std::string accountdir);
static bool setupAccount(const std::string& accountdir);
/* Auto Login */
static bool RsStoreAutoLogin() ;
@ -158,6 +155,4 @@ class RsInit
};
#endif

View file

@ -1047,7 +1047,7 @@ int RsInit::GetPGPLogins(std::list<std::string> &pgpIds) {
return 1;
}
int RsInit::GetPGPLoginDetails(std::string id, std::string &name, std::string &email)
int RsInit::GetPGPLoginDetails(const std::string& id, std::string &name, std::string &email)
{
#ifdef GPG_DEBUG
std::cerr << "RsInit::GetPGPLoginDetails for \"" << id << "\"" << std::endl;
@ -1076,7 +1076,7 @@ int RsInit::LockConfigDirectory(const std::string& accountDir, std::string& lock
{
const std::string lockFile = accountDir + "/" + "lock";
lockFilePath = lockFile;
lockFilePath = lockFile;
/******************************** WINDOWS/UNIX SPECIFIC PART ******************/
#ifndef WINDOWS_SYS
if(RsInitConfig::lockHandle != -1)
@ -1191,13 +1191,14 @@ bool RsInit::SelectGPGAccount(const std::string& gpgId)
}
bool RsInit::GeneratePGPCertificate(std::string name, std::string email, std::string passwd, std::string &pgpId, std::string &errString) {
return AuthGPG::getAuthGPG()->GeneratePGPCertificate(name, email, passwd, pgpId, errString);
bool RsInit::GeneratePGPCertificate(const std::string& name, const std::string& email, const std::string& passwd, std::string &pgpId, std::string &errString)
{
return AuthGPG::getAuthGPG()->GeneratePGPCertificate(name, email, passwd, pgpId, errString);
}
/* Create SSL Certificates */
bool RsInit::GenerateSSLCertificate(std::string gpg_id, std::string org, std::string loc, std::string country, std::string passwd, std::string &sslId, std::string &errString)
bool RsInit::GenerateSSLCertificate(const std::string& gpg_id, const std::string& org, const std::string& loc, const std::string& country, const std::string& passwd, std::string &sslId, std::string &errString)
{
// generate the private_key / certificate.
// save to file.
@ -1213,7 +1214,7 @@ bool RsInit::GenerateSSLCertificate(std::string gpg_id, std::string org, std
int nbits = 2048;
std::string name = AuthGPG::getAuthGPG()->getGPGName(gpg_id);
std::string name = AuthGPG::getAuthGPG()->getGPGName(gpg_id);
// Create the filename .....
// Temporary Directory for creating files....
@ -1248,7 +1249,7 @@ bool RsInit::GenerateSSLCertificate(std::string gpg_id, std::string org, std
nbits, errString);
long days = 3000;
X509 *x509 = AuthSSL::getAuthSSL()->SignX509ReqWithGPG(req, days);
X509 *x509 = AuthSSL::getAuthSSL()->SignX509ReqWithGPG(req, days);
X509_REQ_free(req);
if (x509 == NULL) {
@ -1262,43 +1263,43 @@ bool RsInit::GenerateSSLCertificate(std::string gpg_id, std::string org, std
gen_ok = true;
/* Print the signed Certificate! */
BIO *bio_out = NULL;
bio_out = BIO_new(BIO_s_file());
BIO_set_fp(bio_out,stdout,BIO_NOCLOSE);
BIO *bio_out = NULL;
bio_out = BIO_new(BIO_s_file());
BIO_set_fp(bio_out,stdout,BIO_NOCLOSE);
/* Print it out */
int nmflag = 0;
int reqflag = 0;
/* Print it out */
int nmflag = 0;
int reqflag = 0;
X509_print_ex(bio_out, x509, nmflag, reqflag);
X509_print_ex(bio_out, x509, nmflag, reqflag);
BIO_flush(bio_out);
BIO_free(bio_out);
BIO_flush(bio_out);
BIO_free(bio_out);
}
else
{
{
gen_ok = false;
}
}
if (gen_ok)
{
/* Save cert to file */
// open the file.
FILE *out = NULL;
if (NULL == (out = RsDirUtil::rs_fopen(cert_name.c_str(), "w")))
{
fprintf(stderr,"RsGenerateCert() Couldn't create Cert File");
fprintf(stderr," : %s\n", cert_name.c_str());
// open the file.
FILE *out = NULL;
if (NULL == (out = RsDirUtil::rs_fopen(cert_name.c_str(), "w")))
{
fprintf(stderr,"RsGenerateCert() Couldn't create Cert File");
fprintf(stderr," : %s\n", cert_name.c_str());
gen_ok = false;
}
if (!PEM_write_X509(out,x509))
{
fprintf(stderr,"RsGenerateCert() Couldn't Save Cert");
fprintf(stderr," : %s\n", cert_name.c_str());
}
if (!PEM_write_X509(out,x509))
{
fprintf(stderr,"RsGenerateCert() Couldn't Save Cert");
fprintf(stderr," : %s\n", cert_name.c_str());
gen_ok = false;
}
}
fclose(out);
X509_free(x509);
@ -1312,14 +1313,14 @@ bool RsInit::GenerateSSLCertificate(std::string gpg_id, std::string org, std
/* try to load it, and get Id */
std::string location;
std::string gpgid;
if (LoadCheckX509(cert_name.c_str(), gpgid, location, sslId) == 0) {
std::cerr << "RsInit::GenerateSSLCertificate() Cannot check own signature, maybe the files are corrupted." << std::endl;
return false;
}
std::string location;
std::string gpgid;
if (LoadCheckX509(cert_name.c_str(), gpgid, location, sslId) == 0) {
std::cerr << "RsInit::GenerateSSLCertificate() Cannot check own signature, maybe the files are corrupted." << std::endl;
return false;
}
/* Move directory to correct id */
/* Move directory to correct id */
std::string finalbase = RsInitConfig::basedir + "/" + sslId + "/";
/* Rename Directory */
@ -1347,7 +1348,7 @@ bool RsInit::GenerateSSLCertificate(std::string gpg_id, std::string org, std
/******************* PRIVATE FNS TO HELP with GEN **************/
bool RsInit::setupAccount(std::string accountdir)
bool RsInit::setupAccount(const std::string& accountdir)
{
/* actual config directory isd */
@ -1407,7 +1408,7 @@ bool RsInit::setupAccount(std::string accountdir)
/***************************** FINAL LOADING OF SETUP *************************/
/* Login SSL */
bool RsInit::LoadPassword(std::string id, std::string inPwd)
bool RsInit::LoadPassword(const std::string& id, const std::string& inPwd)
{
/* select configDir */
@ -1441,7 +1442,7 @@ bool RsInit::LoadPassword(std::string id, std::string inPwd)
*/
int RsInit::LockAndLoadCertificates(bool autoLoginNT, std::string& lockFilePath)
{
int retVal = LockConfigDirectory(RsInitConfig::configDir, lockFilePath);
int retVal = LockConfigDirectory(RsInitConfig::configDir, lockFilePath);
if(retVal != 0)
return retVal;
@ -1466,7 +1467,6 @@ int RsInit::LockAndLoadCertificates(bool autoLoginNT, std::string& lockFilePath
*/
int RsInit::LoadCertificates(bool autoLoginNT)
{
if (RsInitConfig::load_cert == "")
{
std::cerr << "RetroShare needs a certificate" << std::endl;
@ -1516,11 +1516,13 @@ int RsInit::LoadCertificates(bool autoLoginNT)
return 1;
}
bool RsInit::RsClearAutoLogin()
{
return RsLoginHandler::clearAutoLogin(RsInitConfig::preferedId);
}
bool RsInit::get_configinit(std::string dir, std::string &id)
bool RsInit::get_configinit(const std::string& dir, std::string &id)
{
// have a config directories.
@ -1551,8 +1553,7 @@ bool RsInit::get_configinit(std::string dir, std::string &id)
return false;
}
bool RsInit::create_configinit(std::string dir, std::string id)
bool RsInit::create_configinit(const std::string& dir, const std::string& id)
{
// Check for config file.
std::string initfile = dir + "/";