mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-02 14:16:16 -04:00
Added service functionality to AuthGPG for load and save of certificates in the background (prepared for more when needed).
Added p3disc as service and process the certificats of RsDiscReply with AuthGPG service. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3669 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
923e76bde2
commit
3a60e8cecb
5 changed files with 301 additions and 109 deletions
|
@ -357,6 +357,9 @@ void AuthGPGimpl::run()
|
|||
sleep(1);
|
||||
#endif
|
||||
|
||||
/* every second */
|
||||
processServices();
|
||||
|
||||
/* every minute */
|
||||
if (++count >= 60) {
|
||||
storeAllKeys_tick();
|
||||
|
@ -365,6 +368,67 @@ void AuthGPGimpl::run()
|
|||
}
|
||||
}
|
||||
|
||||
void AuthGPGimpl::processServices()
|
||||
{
|
||||
AuthGPGOperation *operation = NULL;
|
||||
AuthGPGService *service = NULL;
|
||||
|
||||
{
|
||||
RsStackMutex stack(gpgMtxService); /******* LOCKED ******/
|
||||
|
||||
std::list<AuthGPGService*>::iterator serviceIt;
|
||||
for (serviceIt = services.begin(); serviceIt != services.end(); serviceIt++) {
|
||||
operation = (*serviceIt)->getGPGOperation();
|
||||
if (operation) {
|
||||
service = *serviceIt;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} /******* UNLOCKED ******/
|
||||
|
||||
if (operation == NULL) {
|
||||
/* nothing to do */
|
||||
return;
|
||||
}
|
||||
|
||||
if (service == NULL) {
|
||||
/* huh ? */
|
||||
delete operation;
|
||||
return;
|
||||
}
|
||||
|
||||
AuthGPGOperationLoadOrSave *loadOrSave = dynamic_cast<AuthGPGOperationLoadOrSave*>(operation);
|
||||
if (loadOrSave) {
|
||||
if (loadOrSave->m_load) {
|
||||
/* process load operation */
|
||||
|
||||
#ifdef GPG_DEBUG
|
||||
std::cerr << "AuthGPGimpl::processServices() Process load operation" << std::endl;
|
||||
#endif
|
||||
|
||||
/* load the certificate */
|
||||
LoadCertificateFromString(loadOrSave->m_certGpg, loadOrSave->m_certGpgId);
|
||||
} else {
|
||||
/* process save operation */
|
||||
|
||||
#ifdef GPG_DEBUG
|
||||
std::cerr << "AuthGPGimpl::processServices() Process save operation" << std::endl;
|
||||
#endif
|
||||
|
||||
/* save the certificate to string */
|
||||
loadOrSave->m_certGpg = SaveCertificateToString(loadOrSave->m_certGpgId);
|
||||
}
|
||||
|
||||
service->setGPGOperation(loadOrSave);
|
||||
} else {
|
||||
#ifdef GPG_DEBUG
|
||||
std::cerr << "AuthGPGimpl::processServices() Unknown operation" << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
delete operation;
|
||||
}
|
||||
|
||||
bool AuthGPGimpl::storeAllKeys_tick() {
|
||||
#ifdef GPG_DEBUG
|
||||
std::cerr << "AuthGPGimpl::storeAllKeys_tick() called." << std::endl;
|
||||
|
@ -892,7 +956,7 @@ bool AuthGPGimpl::DoOwnSignature(const void *data, unsigned int datalen, void *b
|
|||
|
||||
|
||||
/* import to GnuPG and other Certificates */
|
||||
bool AuthGPGimpl::VerifySignature(const void *data, int datalen, const void *sig, unsigned int siglen, std::string withfingerprint)
|
||||
bool AuthGPGimpl::VerifySignature(const void *data, int datalen, const void *sig, unsigned int siglen, const std::string &withfingerprint)
|
||||
{
|
||||
gpgme_data_t gpgmeSig;
|
||||
gpgme_data_t gpgmeData;
|
||||
|
@ -1504,7 +1568,7 @@ bool AuthGPGimpl::SignDataBin(const void *data, unsigned int datalen, unsigned c
|
|||
sign, signlen);
|
||||
}
|
||||
|
||||
bool AuthGPGimpl::VerifySignBin(const void *data, uint32_t datalen, unsigned char *sign, unsigned int signlen, std::string withfingerprint) {
|
||||
bool AuthGPGimpl::VerifySignBin(const void *data, uint32_t datalen, unsigned char *sign, unsigned int signlen, const std::string &withfingerprint) {
|
||||
return VerifySignature(data, datalen,
|
||||
sign, signlen, withfingerprint);
|
||||
}
|
||||
|
@ -2314,3 +2378,15 @@ bool AuthGPGimpl::loadList(std::list<RsItem*> load)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool AuthGPGimpl::addService(AuthGPGService *service)
|
||||
{
|
||||
RsStackMutex stack(gpgMtxService); /********* LOCKED *********/
|
||||
|
||||
if (std::find(services.begin(), services.end(), service) != services.end()) {
|
||||
/* it exists already! */
|
||||
return false;
|
||||
}
|
||||
|
||||
services.push_back(service);
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -84,6 +84,48 @@ class gpgcert
|
|||
gpgme_key_t key;
|
||||
};
|
||||
|
||||
class AuthGPGOperation
|
||||
{
|
||||
public:
|
||||
AuthGPGOperation(void *userdata)
|
||||
{
|
||||
m_userdata = userdata;
|
||||
}
|
||||
virtual ~AuthGPGOperation() {}
|
||||
|
||||
public:
|
||||
void *m_userdata;
|
||||
};
|
||||
|
||||
class AuthGPGOperationLoadOrSave : public AuthGPGOperation
|
||||
{
|
||||
public:
|
||||
AuthGPGOperationLoadOrSave(bool load, const std::string &certGpgOrId, void *userdata) : AuthGPGOperation(userdata)
|
||||
{
|
||||
m_load = load;
|
||||
if (m_load) {
|
||||
m_certGpg = certGpgOrId;
|
||||
} else {
|
||||
m_certGpgId = certGpgOrId;
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
bool m_load;
|
||||
std::string m_certGpgId; // set for save
|
||||
std::string m_certGpg; // set for load
|
||||
};
|
||||
|
||||
class AuthGPGService
|
||||
{
|
||||
public:
|
||||
AuthGPGService() {};
|
||||
~AuthGPGService() {};
|
||||
|
||||
virtual AuthGPGOperation *getGPGOperation() = 0;
|
||||
virtual void setGPGOperation(AuthGPGOperation *operation) = 0;
|
||||
};
|
||||
|
||||
/*!
|
||||
* The certificate map type
|
||||
*/
|
||||
|
@ -135,7 +177,7 @@ virtual bool InitAuth () = 0;
|
|||
virtual int GPGInit(std::string ownId) = 0;
|
||||
virtual bool CloseAuth() = 0;
|
||||
virtual bool GeneratePGPCertificate(std::string name, std::string email, std::string passwd, std::string &pgpId, std::string &errString) = 0;
|
||||
|
||||
|
||||
/*********************************************************************************/
|
||||
/************************* STAGE 3 ***********************************************/
|
||||
/*********************************************************************************/
|
||||
|
@ -206,11 +248,13 @@ virtual bool TrustCertificate(std::string id, int trustlvl) = 0; //trustlvl is
|
|||
//virtual bool SignData(const void *data, const uint32_t len, std::string &sign) = 0;
|
||||
//virtual bool SignDataBin(std::string input, unsigned char *sign, unsigned int *signlen) = 0;
|
||||
virtual bool SignDataBin(const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen) = 0;
|
||||
virtual bool VerifySignBin(const void*, uint32_t, unsigned char*, unsigned int, std::string withfingerprint) = 0;
|
||||
virtual bool VerifySignBin(const void*, uint32_t, unsigned char*, unsigned int, const std::string &withfingerprint) = 0;
|
||||
virtual bool decryptText(gpgme_data_t CIPHER, gpgme_data_t PLAIN) = 0;
|
||||
virtual bool encryptText(gpgme_data_t PLAIN, gpgme_data_t CIPHER) = 0;
|
||||
//END of PGP public functions
|
||||
|
||||
/* GPG service */
|
||||
virtual bool addService(AuthGPGService *service) = 0;
|
||||
|
||||
};
|
||||
|
||||
|
@ -253,7 +297,7 @@ virtual bool InitAuth ();
|
|||
virtual int GPGInit(std::string ownId);
|
||||
virtual bool CloseAuth();
|
||||
virtual bool GeneratePGPCertificate(std::string name, std::string email, std::string passwd, std::string &pgpId, std::string &errString);
|
||||
|
||||
|
||||
/*********************************************************************************/
|
||||
/************************* STAGE 3 ***********************************************/
|
||||
/*********************************************************************************/
|
||||
|
@ -325,11 +369,14 @@ virtual bool TrustCertificate(std::string id, int trustlvl); //trustlvl is 2 fo
|
|||
//virtual bool SignData(const void *data, const uint32_t len, std::string &sign);
|
||||
//virtual bool SignDataBin(std::string input, unsigned char *sign, unsigned int *signlen);
|
||||
virtual bool SignDataBin(const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen);
|
||||
virtual bool VerifySignBin(const void*, uint32_t, unsigned char*, unsigned int, std::string withfingerprint);
|
||||
virtual bool VerifySignBin(const void*, uint32_t, unsigned char*, unsigned int, const std::string &withfingerprint);
|
||||
virtual bool decryptText(gpgme_data_t CIPHER, gpgme_data_t PLAIN);
|
||||
virtual bool encryptText(gpgme_data_t PLAIN, gpgme_data_t CIPHER);
|
||||
//END of PGP public functions
|
||||
|
||||
/* GPG service */
|
||||
virtual bool addService(AuthGPGService *service);
|
||||
|
||||
protected:
|
||||
/*****************************************************************/
|
||||
/*********************** p3config ******************************/
|
||||
|
@ -348,7 +395,7 @@ virtual bool encryptText(gpgme_data_t PLAIN, gpgme_data_t CIPHER);
|
|||
|
||||
/* Internal functions */
|
||||
bool DoOwnSignature(const void *, unsigned int, void *, unsigned int *);
|
||||
bool VerifySignature(const void *data, int datalen, const void *sig, unsigned int siglen, std::string withfingerprint);
|
||||
bool VerifySignature(const void *data, int datalen, const void *sig, unsigned int siglen, const std::string &withfingerprint);
|
||||
|
||||
/* Sign/Trust stuff */
|
||||
int privateSignCertificate(GPG_id id);
|
||||
|
@ -362,6 +409,9 @@ virtual bool encryptText(gpgme_data_t PLAIN, gpgme_data_t CIPHER);
|
|||
// Not used anymore
|
||||
// bool updateTrustAllKeys_locked();
|
||||
|
||||
/* GPG service */
|
||||
void processServices();
|
||||
|
||||
bool printAllKeys_locked();
|
||||
bool printOwnKeys_locked();
|
||||
|
||||
|
@ -393,6 +443,10 @@ private:
|
|||
|
||||
std::map<std::string, bool> mAcceptToConnectMap;
|
||||
|
||||
RsMutex gpgMtxService;
|
||||
/* Below is protected via the mutex */
|
||||
|
||||
std::list<AuthGPGService*> services;
|
||||
};
|
||||
|
||||
/*!
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue