encrypt and decrypt ssl password

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1550 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
joss17 2009-08-18 12:43:19 +00:00
parent 128aa9ceda
commit 0a28f35eea
4 changed files with 94 additions and 11 deletions

View file

@ -1343,6 +1343,36 @@ bool GPGAuthMgr::getPGPAllList(std::list<std::string> &ids)
return true;
}
bool GPGAuthMgr::decryptText(gpgme_data_t CIPHER, gpgme_data_t PLAIN) {
RsStackMutex stack(pgpMtx); /******* LOCKED ******/
if (GPG_ERR_NO_ERROR != gpgme_op_decrypt (CTX, CIPHER, PLAIN))
{
std::cerr << "Error decrypting text";
std::cerr << std::endl;
return false;
}
return true;
}
bool GPGAuthMgr::encryptText(gpgme_data_t PLAIN, gpgme_data_t CIPHER) {
RsStackMutex stack(pgpMtx); /******* LOCKED ******/
gpgme_encrypt_flags_t* flags = new gpgme_encrypt_flags_t();
if (GPG_ERR_NO_ERROR != gpgme_op_encrypt(CTX, NULL, *flags, PLAIN, CIPHER))
{
std::cerr << "Error encrypting text";
std::cerr << std::endl;
return false;
}
return true;
}
bool GPGAuthMgr::getPGPAuthenticatedList(std::list<std::string> &ids)
{
RsStackMutex stack(pgpMtx); /******* LOCKED ******/

View file

@ -176,6 +176,8 @@ class GPGAuthMgr: public AuthSSL
bool isPGPValid(std::string id);
bool isPGPAuthenticated(std::string id);
bool getPGPDetails(std::string id, pqiAuthDetails &details);
bool decryptText(gpgme_data_t CIPHER, gpgme_data_t PLAIN);
bool encryptText(gpgme_data_t PLAIN, gpgme_data_t CIPHER);
/*********************************************************************************/
/************************* STAGE 4 ***********************************************/

View file

@ -29,6 +29,7 @@
#include <list>
#include <map>
#include <string>
#include <gpgme.h>
/************** GENERIC AUTHENTICATION MANAGER ***********
* Provides a common interface for certificates.
@ -111,8 +112,9 @@ virtual void addTrustingPeer(std::string id) = 0;
/* Extra Fns for PGP, call std versions if not overloaded */
virtual std::string PGPOwnId() { return OwnId(); }
virtual bool getPGPAllList(std::list<std::string> &ids) { return getAllList(ids); };
virtual bool getPGPAllList(std::list<std::string> &ids) { return getAllList(ids); }
virtual bool encryptText(gpgme_data_t PLAIN, gpgme_data_t CIPHER) { return 0; }
virtual bool decryptText(gpgme_data_t CIPHER, gpgme_data_t PLAIN) { return 0; }
/* Load/Save certificates */
virtual bool LoadCertificateFromString(std::string pem, std::string &id) = 0;