2009-05-23 13:40:35 -04:00
|
|
|
/*
|
2010-01-13 15:58:58 -05:00
|
|
|
* libretroshare/src AuthGPG.cc
|
2009-05-23 13:40:35 -04:00
|
|
|
*
|
|
|
|
* GnuPG/GPGme interface for RetroShare.
|
|
|
|
*
|
|
|
|
* Copyright 2008-2009 by Robert Fernie, Retroshare Team.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the termsf the GNU Library General Public
|
|
|
|
* License Version 2 as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
* USA.
|
|
|
|
*
|
|
|
|
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "authgpg.h"
|
2011-08-07 17:11:00 -04:00
|
|
|
#include "retroshare/rsiface.h" // For rsicontrol.
|
|
|
|
#include "retroshare/rspeers.h" // For RsPeerDetails.
|
2011-08-07 18:23:53 -04:00
|
|
|
#ifdef WINDOWS_SYS
|
|
|
|
#include "retroshare/rsinit.h"
|
|
|
|
#endif
|
2011-08-21 18:28:19 -04:00
|
|
|
#include "pqi/pqinotify.h"
|
2012-04-08 10:52:01 -04:00
|
|
|
#include "pgp/pgphandler.h"
|
2011-08-07 17:11:00 -04:00
|
|
|
|
2010-04-30 10:34:48 -04:00
|
|
|
#include <util/rsdir.h>
|
2012-01-23 15:55:08 -05:00
|
|
|
#include <util/pgpkey.h>
|
2009-05-23 13:40:35 -04:00
|
|
|
#include <iostream>
|
2012-04-08 10:52:01 -04:00
|
|
|
#include <stdexcept>
|
2009-05-23 13:40:35 -04:00
|
|
|
#include <sstream>
|
2010-01-13 15:52:31 -05:00
|
|
|
#include <algorithm>
|
2010-01-13 16:26:30 -05:00
|
|
|
#include "serialiser/rsconfigitems.h"
|
2010-01-19 16:44:59 -05:00
|
|
|
#include "cleanupxpgp.h"
|
2010-01-13 16:14:49 -05:00
|
|
|
|
2012-04-09 13:03:47 -04:00
|
|
|
#define LIMIT_CERTIFICATE_SIZE 1
|
|
|
|
#define MAX_CERTIFICATE_SIZE 10000
|
|
|
|
|
2010-09-30 15:05:43 -04:00
|
|
|
const time_t STORE_KEY_TIMEOUT = 1 * 60 * 60; //store key is call around every hour
|
|
|
|
|
2012-04-08 10:52:01 -04:00
|
|
|
AuthGPG *AuthGPG::_instance = NULL ;
|
|
|
|
|
2011-01-23 06:57:09 -05:00
|
|
|
void cleanupZombies(int numkill); // function to cleanup zombies under OSX.
|
|
|
|
|
2010-01-21 18:01:48 -05:00
|
|
|
//#define GPG_DEBUG 1
|
2009-07-30 17:27:47 -04:00
|
|
|
|
2009-05-23 13:40:35 -04:00
|
|
|
/* Turn a set of parameters into a string */
|
2010-01-18 07:30:54 -05:00
|
|
|
static std::string setKeyPairParams(bool useRsa, unsigned int blen,
|
|
|
|
std::string name, std::string comment, std::string email,
|
|
|
|
std::string inPassphrase);
|
2009-05-23 13:40:35 -04:00
|
|
|
|
2012-04-08 10:52:01 -04:00
|
|
|
// static gpg_error_t keySignCallback(void *, gpgme_status_code_t, const char *, int);
|
|
|
|
// static gpg_error_t trustCallback(void *, gpgme_status_code_t, const char *, int);
|
|
|
|
// static std::string ProcessPGPmeError(gpgme_error_t ERR);
|
2009-05-23 13:40:35 -04:00
|
|
|
|
2012-04-09 13:03:47 -04:00
|
|
|
/* Function to sign X509_REQ via GPGme. */
|
2009-05-23 13:40:35 -04:00
|
|
|
|
2012-04-08 10:52:01 -04:00
|
|
|
bool AuthGPG::decryptTextFromFile(std::string& text,const std::string& inputfile)
|
2009-05-25 07:38:47 -04:00
|
|
|
{
|
2012-04-08 10:52:01 -04:00
|
|
|
return PGPHandler::decryptTextFromFile(mOwnGpgId,text,inputfile) ;
|
|
|
|
}
|
2012-04-09 13:03:47 -04:00
|
|
|
|
2012-04-08 10:52:01 -04:00
|
|
|
bool AuthGPG::encryptTextToFile(const std::string& text,const std::string& outfile)
|
|
|
|
{
|
|
|
|
return PGPHandler::encryptTextToFile(mOwnGpgId,text,outfile) ;
|
2009-05-25 07:38:47 -04:00
|
|
|
}
|
2009-05-24 06:33:08 -04:00
|
|
|
|
2012-04-09 13:03:47 -04:00
|
|
|
std::string pgp_pwd_callback(void * /*hook*/, const char *uid_hint, const char * /*passphrase_info*/, int prev_was_bad)
|
2010-02-09 14:10:15 -05:00
|
|
|
{
|
2012-04-08 10:52:01 -04:00
|
|
|
#define GPG_DEBUG2
|
2010-04-20 08:08:25 -04:00
|
|
|
#ifdef GPG_DEBUG2
|
|
|
|
fprintf(stderr, "pgp_pwd_callback() called.\n");
|
|
|
|
#endif
|
2011-08-05 16:45:09 -04:00
|
|
|
std::string password;
|
2012-04-08 10:52:01 -04:00
|
|
|
rsicontrol->getNotify().askForPassword(uid_hint, prev_was_bad, password) ;
|
|
|
|
|
|
|
|
return password ;
|
|
|
|
}
|
|
|
|
|
2012-06-12 16:31:13 -04:00
|
|
|
void AuthGPG::init(const std::string& path_to_public_keyring,const std::string& path_to_secret_keyring,const std::string& pgp_lock_file)
|
2009-05-23 13:40:35 -04:00
|
|
|
{
|
2012-04-08 10:52:01 -04:00
|
|
|
if(_instance != NULL)
|
2012-06-09 17:01:22 -04:00
|
|
|
{
|
2012-06-09 20:29:46 -04:00
|
|
|
exit();
|
2012-06-09 17:01:22 -04:00
|
|
|
std::cerr << "AuthGPG::init() called twice!" << std::endl ;
|
|
|
|
}
|
2010-04-08 15:07:40 -04:00
|
|
|
|
2012-05-01 04:53:32 -04:00
|
|
|
PGPHandler::setPassphraseCallback(pgp_pwd_callback) ;
|
2012-06-12 16:31:13 -04:00
|
|
|
_instance = new AuthGPG(path_to_public_keyring,path_to_secret_keyring,pgp_lock_file) ;
|
2010-04-30 10:34:48 -04:00
|
|
|
}
|
2010-04-08 15:07:40 -04:00
|
|
|
|
2012-06-09 20:29:46 -04:00
|
|
|
void AuthGPG::exit()
|
|
|
|
{
|
|
|
|
if(_instance != NULL)
|
|
|
|
{
|
|
|
|
_instance->join();
|
|
|
|
delete _instance ;
|
|
|
|
_instance = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-12 16:31:13 -04:00
|
|
|
AuthGPG::AuthGPG(const std::string& path_to_public_keyring,const std::string& path_to_secret_keyring,const std::string& pgp_lock_file)
|
2012-04-08 10:52:01 -04:00
|
|
|
:p3Config(CONFIG_TYPE_AUTHGPG),
|
2012-06-12 16:31:13 -04:00
|
|
|
PGPHandler(path_to_public_keyring,path_to_secret_keyring,pgp_lock_file),
|
2012-04-08 10:52:01 -04:00
|
|
|
gpgMtxEngine("AuthGPG-engine"),
|
|
|
|
gpgMtxData("AuthGPG-data"),
|
|
|
|
gpgKeySelected(false),
|
|
|
|
gpgMtxService("AuthGPG-service")
|
2010-04-30 10:34:48 -04:00
|
|
|
{
|
2012-04-08 10:52:01 -04:00
|
|
|
start();
|
2009-10-27 16:50:30 -04:00
|
|
|
}
|
|
|
|
|
2009-05-23 13:40:35 -04:00
|
|
|
/* This function is called when retroshare is first started
|
|
|
|
* to get the list of available GPG certificates.
|
|
|
|
* This function should only return certs for which
|
|
|
|
* the private(secret) keys are available.
|
|
|
|
*
|
|
|
|
* returns false if GnuPG is not available.
|
|
|
|
*/
|
2012-04-08 10:52:01 -04:00
|
|
|
bool AuthGPG::availableGPGCertificatesWithPrivateKeys(std::list<std::string> &ids)
|
2009-05-23 13:40:35 -04:00
|
|
|
{
|
2012-04-08 10:52:01 -04:00
|
|
|
std::list<PGPIdType> pids ;
|
2009-05-23 13:40:35 -04:00
|
|
|
|
2012-04-08 10:52:01 -04:00
|
|
|
PGPHandler::availableGPGCertificatesWithPrivateKeys(pids) ;
|
2009-05-23 13:40:35 -04:00
|
|
|
|
2012-04-08 10:52:01 -04:00
|
|
|
for(std::list<PGPIdType>::const_iterator it(pids.begin());it!=pids.end();++it)
|
|
|
|
ids.push_back( (*it).toStdString() ) ;
|
2009-05-23 13:40:35 -04:00
|
|
|
|
|
|
|
/* return false if there are no private keys */
|
2012-04-08 10:52:01 -04:00
|
|
|
return !ids.empty();
|
2009-05-23 13:40:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* You can initialise Retroshare with
|
|
|
|
* (a) load existing certificate.
|
|
|
|
* (b) a new certificate.
|
|
|
|
*
|
|
|
|
* This function must be called successfully (return == 1)
|
|
|
|
* before anything else can be done. (except above fn).
|
|
|
|
*/
|
2012-04-08 10:52:01 -04:00
|
|
|
int AuthGPG::GPGInit(const std::string &ownId)
|
2009-05-23 13:40:35 -04:00
|
|
|
{
|
2012-04-08 10:52:01 -04:00
|
|
|
std::cerr << "AuthGPG::GPGInit() called with own gpg id : " << ownId << std::endl;
|
2010-02-09 14:10:15 -05:00
|
|
|
|
2012-06-09 14:45:35 -04:00
|
|
|
mOwnGpgId = PGPIdType(ownId);
|
2010-02-05 16:00:36 -05:00
|
|
|
|
2012-04-08 10:52:01 -04:00
|
|
|
//force the validity of the private key. When set to unknown, it caused signature and text encryptions bugs
|
|
|
|
privateTrustCertificate(ownId, 5);
|
2010-04-20 08:08:25 -04:00
|
|
|
|
2012-04-08 10:52:01 -04:00
|
|
|
std::cerr << "AuthGPG::GPGInit finished." << std::endl;
|
2010-04-08 15:07:40 -04:00
|
|
|
|
2012-04-08 10:52:01 -04:00
|
|
|
return 1;
|
2009-05-23 13:40:35 -04:00
|
|
|
}
|
|
|
|
|
2012-04-08 10:52:01 -04:00
|
|
|
AuthGPG::~AuthGPG()
|
2009-05-23 13:40:35 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-04-08 10:52:01 -04:00
|
|
|
void AuthGPG::run()
|
2010-09-30 15:05:43 -04:00
|
|
|
{
|
|
|
|
int count = 0;
|
|
|
|
|
2011-03-03 18:30:08 -05:00
|
|
|
while (isRunning())
|
2010-09-30 15:05:43 -04:00
|
|
|
{
|
|
|
|
#ifdef WIN32
|
2011-01-09 07:31:41 -05:00
|
|
|
Sleep(100);
|
2010-09-30 15:05:43 -04:00
|
|
|
#else
|
2011-01-09 07:31:41 -05:00
|
|
|
usleep(100000);
|
2010-09-30 15:05:43 -04:00
|
|
|
#endif
|
|
|
|
|
2011-01-09 07:31:41 -05:00
|
|
|
/* every 100 milliseconds */
|
2010-10-13 12:15:26 -04:00
|
|
|
processServices();
|
2012-04-08 10:52:01 -04:00
|
|
|
#ifdef SUSPENDED
|
2010-09-30 15:05:43 -04:00
|
|
|
/* every minute */
|
2011-01-09 07:31:41 -05:00
|
|
|
if (++count >= 600) {
|
2010-09-30 15:05:43 -04:00
|
|
|
storeAllKeys_tick();
|
|
|
|
count = 0;
|
|
|
|
}
|
2012-04-08 10:52:01 -04:00
|
|
|
#endif
|
2010-09-30 15:05:43 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-08 10:52:01 -04:00
|
|
|
void AuthGPG::processServices()
|
2010-10-13 12:15:26 -04:00
|
|
|
{
|
|
|
|
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);
|
2012-04-09 13:03:47 -04:00
|
|
|
if (loadOrSave)
|
|
|
|
{
|
|
|
|
if (loadOrSave->m_load)
|
|
|
|
{
|
|
|
|
/* process load operation */
|
2010-10-13 12:15:26 -04:00
|
|
|
|
2012-02-15 11:44:45 -05:00
|
|
|
|
2012-04-09 13:03:47 -04:00
|
|
|
/* load the certificate */
|
2012-02-15 11:44:45 -05:00
|
|
|
|
|
|
|
|
2012-04-09 13:03:47 -04:00
|
|
|
/* don't bother loading - if we already have the certificate */
|
|
|
|
if (isGPGId(loadOrSave->m_certGpgId))
|
|
|
|
{
|
2012-02-17 15:28:59 -05:00
|
|
|
#ifdef GPG_DEBUG
|
2012-04-09 13:03:47 -04:00
|
|
|
std::cerr << "AuthGPGimpl::processServices() Skipping load - already have it" << std::endl;
|
2012-02-17 15:28:59 -05:00
|
|
|
#endif
|
2012-04-09 13:03:47 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-10-13 12:15:26 -04:00
|
|
|
#ifdef GPG_DEBUG
|
2012-04-09 13:03:47 -04:00
|
|
|
std::cerr << "AuthGPGimpl::processServices() Process load operation" << std::endl;
|
2010-10-13 12:15:26 -04:00
|
|
|
#endif
|
2012-04-09 13:03:47 -04:00
|
|
|
std::string error_string ;
|
|
|
|
LoadCertificateFromString(loadOrSave->m_certGpg, loadOrSave->m_certGpgId,error_string);
|
|
|
|
}
|
2012-02-15 11:44:45 -05:00
|
|
|
|
|
|
|
|
2010-10-13 12:15:26 -04:00
|
|
|
|
2012-04-09 13:03:47 -04:00
|
|
|
} else {
|
|
|
|
/* process save operation */
|
2010-10-13 12:15:26 -04:00
|
|
|
|
|
|
|
#ifdef GPG_DEBUG
|
2012-04-09 13:03:47 -04:00
|
|
|
std::cerr << "AuthGPGimpl::processServices() Process save operation" << std::endl;
|
2010-10-13 12:15:26 -04:00
|
|
|
#endif
|
|
|
|
|
2012-04-09 13:03:47 -04:00
|
|
|
/* save the certificate to string */
|
|
|
|
/*****
|
|
|
|
* #define DISABLE_CERTIFICATE_SEND 1
|
|
|
|
****/
|
2012-01-20 09:41:45 -05:00
|
|
|
|
2012-04-09 13:03:47 -04:00
|
|
|
loadOrSave->m_certGpg = SaveCertificateToString(loadOrSave->m_certGpgId,true);
|
2012-01-20 09:41:45 -05:00
|
|
|
|
2012-02-17 15:28:59 -05:00
|
|
|
#ifdef GPG_DEBUG
|
2012-04-09 13:03:47 -04:00
|
|
|
std::cerr << "Certificate for: " << loadOrSave->m_certGpgId << " is: ";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
std::cerr << loadOrSave->m_certGpg;
|
|
|
|
std::cerr << std::endl;
|
2012-01-19 20:05:46 -05:00
|
|
|
#endif
|
2012-02-17 15:28:59 -05:00
|
|
|
|
2012-04-09 13:03:47 -04:00
|
|
|
}
|
2010-10-13 12:15:26 -04:00
|
|
|
|
2012-04-09 13:03:47 -04:00
|
|
|
service->setGPGOperation(loadOrSave);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-10-13 12:15:26 -04:00
|
|
|
#ifdef GPG_DEBUG
|
|
|
|
std::cerr << "AuthGPGimpl::processServices() Unknown operation" << std::endl;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
delete operation;
|
|
|
|
}
|
|
|
|
|
2012-04-08 10:52:01 -04:00
|
|
|
#ifdef TO_REMOVE
|
2009-05-23 13:40:35 -04:00
|
|
|
// store all keys in map mKeyList to avoid callin gpgme exe repeatedly
|
2012-04-08 10:52:01 -04:00
|
|
|
bool AuthGPG::storeAllKeys()
|
2009-05-23 13:40:35 -04:00
|
|
|
{
|
2010-01-21 18:01:48 -05:00
|
|
|
#ifdef GPG_DEBUG
|
2012-04-08 10:52:01 -04:00
|
|
|
std::cerr << "AuthGPG::storeAllKeys()" << std::endl;
|
2010-01-21 18:01:48 -05:00
|
|
|
#endif
|
2009-05-23 13:40:35 -04:00
|
|
|
|
2010-09-28 18:30:57 -04:00
|
|
|
std::string ownGpgId;
|
|
|
|
|
|
|
|
/* store member variables locally */
|
2009-05-23 13:40:35 -04:00
|
|
|
{
|
2010-09-30 15:05:43 -04:00
|
|
|
RsStackMutex stack(gpgMtxData);
|
2010-04-25 15:26:37 -04:00
|
|
|
|
|
|
|
if (!gpgmeInit)
|
|
|
|
{
|
2012-04-08 10:52:01 -04:00
|
|
|
std::cerr << "AuthGPG::storeAllKeys() Error since GPG is not initialised" << std::endl;
|
2010-04-25 15:26:37 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-09-28 18:30:57 -04:00
|
|
|
mStoreKeyTime = time(NULL);
|
|
|
|
ownGpgId = mOwnGpgId;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* read keys from gpg to local list */
|
|
|
|
std::list<gpgcert> keyList;
|
|
|
|
|
|
|
|
{
|
2010-01-21 18:01:48 -05:00
|
|
|
#ifdef GPG_DEBUG
|
2012-04-08 10:52:01 -04:00
|
|
|
std::cerr << "AuthGPG::storeAllKeys() clearing existing ones" << std::endl;
|
2010-01-21 18:01:48 -05:00
|
|
|
#endif
|
2009-05-23 13:40:35 -04:00
|
|
|
|
2010-09-28 18:30:57 -04:00
|
|
|
gpg_error_t ERR;
|
|
|
|
|
|
|
|
RsStackMutex stack(gpgMtxEngine); /******* LOCKED ******/
|
|
|
|
|
2010-04-25 15:26:37 -04:00
|
|
|
/* enable SIG mode */
|
|
|
|
gpgme_keylist_mode_t origmode = gpgme_get_keylist_mode(CTX);
|
|
|
|
gpgme_keylist_mode_t mode = origmode | GPGME_KEYLIST_MODE_SIGS;
|
2009-05-23 13:40:35 -04:00
|
|
|
|
2010-04-25 15:26:37 -04:00
|
|
|
gpgme_set_keylist_mode(CTX, mode);
|
2009-05-23 13:40:35 -04:00
|
|
|
|
2010-04-25 15:26:37 -04:00
|
|
|
/* store keys */
|
|
|
|
gpgme_key_t KEY = NULL;
|
2009-05-23 13:40:35 -04:00
|
|
|
|
2010-04-25 15:26:37 -04:00
|
|
|
/* Initiates a key listing 0 = All Keys */
|
|
|
|
if (GPG_ERR_NO_ERROR != gpgme_op_keylist_start (CTX, "", 0))
|
|
|
|
{
|
2012-04-08 10:52:01 -04:00
|
|
|
std::cerr << "AuthGPG::storeAllKeys() Error iterating through KeyList" << std::endl;
|
2010-04-25 15:26:37 -04:00
|
|
|
// if (rsicontrol != NULL) {
|
|
|
|
// rsicontrol->getNotify().notifyErrorMsg(0,0,"Error reading gpg keyring, cannot acess key list.");
|
|
|
|
// }
|
|
|
|
gpgme_set_keylist_mode(CTX, origmode);
|
|
|
|
return false;
|
|
|
|
}
|
2009-05-23 13:40:35 -04:00
|
|
|
|
2010-04-25 15:26:37 -04:00
|
|
|
/* Loop until end of key */
|
|
|
|
ERR = gpgme_op_keylist_next (CTX, &KEY);
|
|
|
|
if (GPG_ERR_NO_ERROR != ERR) {
|
2012-04-08 10:52:01 -04:00
|
|
|
std::cerr << "AuthGPG::storeAllKeys() didn't find any gpg key in the keyring" << std::endl;
|
2010-04-25 15:26:37 -04:00
|
|
|
// if (rsicontrol != NULL) {
|
|
|
|
// rsicontrol->getNotify().notifyErrorMsg(0,0,"Error reading gpg keyring, cannot find any key in the list.");
|
|
|
|
// }
|
2010-06-25 10:38:38 -04:00
|
|
|
gpgme_set_keylist_mode(CTX, origmode);
|
2010-04-25 15:26:37 -04:00
|
|
|
return false;
|
|
|
|
}
|
2010-04-25 13:06:48 -04:00
|
|
|
|
2010-04-25 15:26:37 -04:00
|
|
|
for(int i = 0;GPG_ERR_NO_ERROR == ERR; i++)
|
|
|
|
{
|
|
|
|
/* store in pqiAuthDetails */
|
|
|
|
gpgcert nu;
|
2009-05-23 13:40:35 -04:00
|
|
|
|
2010-04-25 15:26:37 -04:00
|
|
|
/* NB subkeys is a linked list and can contain multiple keys.
|
|
|
|
* first key is primary.
|
|
|
|
*/
|
2009-05-23 13:40:35 -04:00
|
|
|
|
2010-04-25 15:26:37 -04:00
|
|
|
if ((!KEY->subkeys) || (!KEY->uids))
|
|
|
|
{
|
2012-04-08 10:52:01 -04:00
|
|
|
std::cerr << "AuthGPG::storeAllKeys() Invalid Key in List... skipping" << std::endl;
|
2010-04-25 15:26:37 -04:00
|
|
|
continue;
|
|
|
|
}
|
2009-05-23 13:40:35 -04:00
|
|
|
|
2010-04-25 15:26:37 -04:00
|
|
|
/* In general MainSubKey is used to sign all others!
|
|
|
|
* Don't really need to worry about other ids either.
|
|
|
|
*/
|
|
|
|
gpgme_subkey_t mainsubkey = KEY->subkeys;
|
|
|
|
nu.id = mainsubkey->keyid;
|
|
|
|
nu.fpr = mainsubkey->fpr;
|
2009-05-23 13:40:35 -04:00
|
|
|
|
2010-01-21 18:01:48 -05:00
|
|
|
#ifdef GPG_DEBUG
|
2010-04-25 15:26:37 -04:00
|
|
|
std::cerr << "MAIN KEYID: " << nu.id << " FPR: " << nu.fpr << std::endl;
|
2009-05-23 13:40:35 -04:00
|
|
|
|
2010-04-25 15:26:37 -04:00
|
|
|
gpgme_subkey_t subkeylist = KEY->subkeys;
|
|
|
|
while(subkeylist != NULL)
|
|
|
|
{
|
|
|
|
std::cerr << "\tKEYID: " << subkeylist->keyid << " FPR: " << subkeylist->fpr << std::endl;
|
2009-05-23 13:40:35 -04:00
|
|
|
|
2010-04-25 15:26:37 -04:00
|
|
|
subkeylist = subkeylist->next;
|
|
|
|
}
|
2010-01-21 18:01:48 -05:00
|
|
|
#endif
|
2009-05-23 13:40:35 -04:00
|
|
|
|
|
|
|
|
2010-04-25 15:26:37 -04:00
|
|
|
/* NB uids is a linked list and can contain multiple ids.
|
|
|
|
* first id is primary.
|
|
|
|
*/
|
|
|
|
gpgme_user_id_t mainuid = KEY->uids;
|
|
|
|
nu.name = mainuid->name;
|
|
|
|
nu.email = mainuid->email;
|
|
|
|
gpgme_key_sig_t mainsiglist = mainuid->signatures;
|
2010-09-28 18:30:57 -04:00
|
|
|
|
2010-04-25 15:26:37 -04:00
|
|
|
nu.ownsign = false;
|
|
|
|
while(mainsiglist != NULL)
|
2009-05-23 13:40:35 -04:00
|
|
|
{
|
2010-04-25 15:26:37 -04:00
|
|
|
if (mainsiglist->status == GPG_ERR_NO_ERROR)
|
2009-05-23 13:40:35 -04:00
|
|
|
{
|
2010-04-25 15:26:37 -04:00
|
|
|
/* add as a signature ... even if the
|
|
|
|
* we haven't go the peer yet.
|
|
|
|
* (might be yet to come).
|
|
|
|
*/
|
|
|
|
std::string keyid = mainsiglist->keyid;
|
|
|
|
if (nu.signers.end() == std::find(
|
|
|
|
nu.signers.begin(),
|
|
|
|
nu.signers.end(),keyid))
|
|
|
|
{
|
|
|
|
nu.signers.push_back(keyid);
|
|
|
|
}
|
2010-09-28 18:30:57 -04:00
|
|
|
if (keyid == ownGpgId) {
|
2010-04-25 15:26:37 -04:00
|
|
|
nu.ownsign = true;
|
|
|
|
}
|
2009-05-23 13:40:35 -04:00
|
|
|
}
|
2010-04-25 15:26:37 -04:00
|
|
|
mainsiglist = mainsiglist->next;
|
2009-05-23 13:40:35 -04:00
|
|
|
}
|
|
|
|
|
2010-01-21 18:01:48 -05:00
|
|
|
#ifdef GPG_DEBUG
|
2010-04-25 15:26:37 -04:00
|
|
|
gpgme_user_id_t uidlist = KEY->uids;
|
|
|
|
while(uidlist != NULL)
|
2009-05-23 13:40:35 -04:00
|
|
|
{
|
2010-04-25 15:26:37 -04:00
|
|
|
std::cerr << "\tUID: " << uidlist->uid;
|
|
|
|
std::cerr << " NAME: " << uidlist->name;
|
|
|
|
std::cerr << " EMAIL: " << uidlist->email;
|
|
|
|
std::cerr << " VALIDITY: " << uidlist->validity;
|
2009-05-23 13:40:35 -04:00
|
|
|
std::cerr << std::endl;
|
2010-04-25 15:26:37 -04:00
|
|
|
gpgme_key_sig_t usiglist = uidlist->signatures;
|
|
|
|
while(usiglist != NULL)
|
|
|
|
{
|
|
|
|
std::cerr << "\t\tSIG KEYID: " << usiglist->keyid;
|
|
|
|
std::cerr << " UID: " << usiglist->uid;
|
|
|
|
std::cerr << " NAME: " << usiglist->name;
|
|
|
|
std::cerr << " EMAIL: " << usiglist->email;
|
|
|
|
std::cerr << " VALIDITY: " << (usiglist->status == GPG_ERR_NO_ERROR);
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
|
|
|
usiglist = usiglist->next;
|
|
|
|
}
|
2009-05-23 13:40:35 -04:00
|
|
|
|
2010-04-25 15:26:37 -04:00
|
|
|
uidlist = uidlist->next;
|
2009-05-23 13:40:35 -04:00
|
|
|
}
|
2010-04-25 15:26:37 -04:00
|
|
|
#endif
|
2009-05-23 13:40:35 -04:00
|
|
|
|
2010-04-25 15:26:37 -04:00
|
|
|
/* signatures are attached to uids... but only supplied
|
|
|
|
* if GPGME_KEYLIST_MODE_SIGS is on.
|
|
|
|
* signature notation supplied is GPGME_KEYLIST_MODE_SIG_NOTATION is on
|
|
|
|
*/
|
|
|
|
nu.trustLvl = KEY->owner_trust;
|
|
|
|
nu.validLvl = mainuid->validity;
|
|
|
|
|
|
|
|
/* grab a reference, so the key remains */
|
|
|
|
gpgme_key_ref(KEY);
|
|
|
|
nu.key = KEY;
|
|
|
|
|
|
|
|
/* store in map */
|
2010-09-28 18:30:57 -04:00
|
|
|
keyList.push_back(nu);
|
2010-04-25 15:26:37 -04:00
|
|
|
#ifdef GPG_DEBUG
|
|
|
|
std::cerr << "nu.name" << nu.name << std::endl;
|
|
|
|
std::cerr << "nu.trustLvl" << nu.trustLvl << std::endl;
|
|
|
|
std::cerr << "nu.accept_connection" << nu.accept_connection << std::endl;
|
2010-01-21 18:01:48 -05:00
|
|
|
#endif
|
2010-01-13 16:12:56 -05:00
|
|
|
|
2010-04-25 15:26:37 -04:00
|
|
|
ERR = gpgme_op_keylist_next (CTX, &KEY);
|
|
|
|
}
|
2010-03-02 17:35:49 -05:00
|
|
|
|
2010-04-25 15:26:37 -04:00
|
|
|
if (GPG_ERR_NO_ERROR != gpgme_op_keylist_end(CTX))
|
|
|
|
{
|
|
|
|
std::cerr << "Error ending KeyList" << std::endl;
|
|
|
|
gpgme_set_keylist_mode(CTX, origmode);
|
|
|
|
return false;
|
|
|
|
}
|
2009-05-23 13:40:35 -04:00
|
|
|
|
|
|
|
gpgme_set_keylist_mode(CTX, origmode);
|
2010-04-25 15:26:37 -04:00
|
|
|
}
|
2010-04-25 13:06:48 -04:00
|
|
|
|
2010-09-28 18:30:57 -04:00
|
|
|
/* process read gpg keys and store it in member */
|
|
|
|
std::list<std::string> gpg_change_trust_list;
|
|
|
|
|
|
|
|
{
|
2010-09-30 15:05:43 -04:00
|
|
|
RsStackMutex stack(gpgMtxData);
|
2010-09-28 18:30:57 -04:00
|
|
|
|
|
|
|
//let's start a new list
|
|
|
|
mKeyList.clear();
|
|
|
|
|
|
|
|
for (std::list<gpgcert>::iterator it = keyList.begin(); it != keyList.end(); it++) {
|
|
|
|
gpgcert &nu = *it;
|
|
|
|
|
|
|
|
std::map<std::string, bool>::iterator itAccept;
|
|
|
|
if (mAcceptToConnectMap.end() != (itAccept = mAcceptToConnectMap.find(nu.id))) {
|
|
|
|
nu.accept_connection = itAccept->second;
|
|
|
|
} else {
|
|
|
|
nu.accept_connection = false;
|
|
|
|
mAcceptToConnectMap[nu.id] = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nu.trustLvl < 2 && nu.accept_connection) {
|
|
|
|
//add it to the list of key that we will force the trust to 2
|
|
|
|
gpg_change_trust_list.push_back(nu.id);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* grab a reference, so the key remains */
|
|
|
|
gpgme_key_ref(nu.key);
|
|
|
|
|
|
|
|
mKeyList[nu.id] = nu;
|
|
|
|
|
|
|
|
//store own key
|
|
|
|
if (nu.id == mOwnGpgId) {
|
|
|
|
/* grab a reference, so the key remains */
|
|
|
|
gpgme_key_ref(nu.key);
|
|
|
|
|
|
|
|
gpgme_key_unref(mOwnGpgCert.key);
|
|
|
|
mOwnGpgCert = nu;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-25 15:26:37 -04:00
|
|
|
std::list<std::string>::iterator it;
|
|
|
|
for(it = gpg_change_trust_list.begin(); it != gpg_change_trust_list.end(); it++)
|
|
|
|
{
|
|
|
|
privateTrustCertificate(*it, 3);
|
|
|
|
}
|
2010-04-25 13:06:48 -04:00
|
|
|
|
2009-05-23 13:40:35 -04:00
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
2011-03-15 19:15:46 -04:00
|
|
|
std::string ProcessPGPmeError(gpgme_error_t ERR)
|
2009-05-23 13:40:35 -04:00
|
|
|
{
|
|
|
|
gpgme_err_code_t code = gpgme_err_code(ERR);
|
|
|
|
gpgme_err_source_t src = gpgme_err_source(ERR);
|
|
|
|
|
2011-03-15 19:15:46 -04:00
|
|
|
std::ostringstream ss ;
|
|
|
|
|
2010-01-21 18:01:48 -05:00
|
|
|
if(code > 0)
|
|
|
|
{
|
2011-03-15 19:15:46 -04:00
|
|
|
ss << "GPGme ERROR: Code: " << code << " Source: " << src << std::endl;
|
|
|
|
ss << "GPGme ERROR: " << gpgme_strerror(ERR) << std::endl;
|
2010-01-21 18:01:48 -05:00
|
|
|
}
|
2011-03-15 19:15:46 -04:00
|
|
|
else
|
|
|
|
return std::string("Unknown error") ;
|
|
|
|
|
|
|
|
return ss.str() ;
|
2009-05-23 13:40:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void print_pgpme_verify_summary(unsigned int summary)
|
|
|
|
{
|
|
|
|
std::cerr << "\tFLAGS:";
|
|
|
|
if (summary & GPGME_SIGSUM_VALID)
|
|
|
|
std::cerr << " VALID ";
|
|
|
|
if (summary & GPGME_SIGSUM_GREEN)
|
|
|
|
std::cerr << " GREEN ";
|
|
|
|
if (summary & GPGME_SIGSUM_RED)
|
|
|
|
std::cerr << " RED ";
|
|
|
|
if (summary & GPGME_SIGSUM_KEY_REVOKED)
|
|
|
|
std::cerr << " KEY_REVOKED ";
|
|
|
|
if (summary & GPGME_SIGSUM_KEY_EXPIRED)
|
|
|
|
std::cerr << " KEY_EXPIRED ";
|
2010-01-13 19:36:02 -05:00
|
|
|
if (summary & GPGME_SIGSUM_SIG_EXPIRED)
|
|
|
|
std::cerr << " SIG_EXPIRED ";
|
|
|
|
if (summary & GPGME_SIGSUM_KEY_MISSING)
|
2009-05-23 13:40:35 -04:00
|
|
|
std::cerr << " KEY_MISSING ";
|
|
|
|
if (summary & GPGME_SIGSUM_CRL_MISSING)
|
|
|
|
std::cerr << " CRL_MISSING ";
|
|
|
|
if (summary & GPGME_SIGSUM_CRL_TOO_OLD)
|
|
|
|
std::cerr << " CRL_TOO_OLD ";
|
|
|
|
if (summary & GPGME_SIGSUM_BAD_POLICY)
|
|
|
|
std::cerr << " BAD_POLICY ";
|
|
|
|
if (summary & GPGME_SIGSUM_SYS_ERROR)
|
|
|
|
std::cerr << " SYS_ERROR ";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
}
|
2010-01-21 18:01:48 -05:00
|
|
|
#endif
|
2010-01-18 17:44:18 -05:00
|
|
|
|
2012-04-08 10:52:01 -04:00
|
|
|
bool AuthGPG::DoOwnSignature(const void *data, unsigned int datalen, void *buf_sigout, unsigned int *outl)
|
|
|
|
{
|
|
|
|
return PGPHandler::SignDataBin(mOwnGpgId,data,datalen,(unsigned char *)buf_sigout,outl) ;
|
2009-05-23 13:40:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* import to GnuPG and other Certificates */
|
2012-04-08 10:52:01 -04:00
|
|
|
bool AuthGPG::VerifySignature(const void *data, int datalen, const void *sig, unsigned int siglen, const std::string &withfingerprint)
|
2009-05-23 13:40:35 -04:00
|
|
|
{
|
2012-04-26 17:39:45 -04:00
|
|
|
if(withfingerprint.length() != 40)
|
|
|
|
{
|
|
|
|
std::cerr << "WARNING: Still need to implement signature verification from complete keyring." << std::endl;
|
|
|
|
return false ;
|
|
|
|
}
|
|
|
|
|
2012-06-09 14:45:35 -04:00
|
|
|
return PGPHandler::VerifySignBin((unsigned char*)data,datalen,(unsigned char*)sig,siglen,PGPFingerprintType(withfingerprint)) ;
|
2009-05-23 13:40:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-04-08 10:52:01 -04:00
|
|
|
bool AuthGPG::active()
|
2010-01-21 18:01:48 -05:00
|
|
|
{
|
2010-09-30 15:05:43 -04:00
|
|
|
RsStackMutex stack(gpgMtxData); /******* LOCKED ******/
|
2010-01-21 18:01:48 -05:00
|
|
|
|
2012-04-08 10:52:01 -04:00
|
|
|
return gpgKeySelected;
|
2009-05-23 13:40:35 -04:00
|
|
|
}
|
|
|
|
|
2012-04-08 10:52:01 -04:00
|
|
|
bool AuthGPG::GeneratePGPCertificate(const std::string& name,
|
|
|
|
const std::string& email, const std::string& passwd, std::string &pgpId, std::string& errString)
|
2012-01-27 08:03:59 -05:00
|
|
|
{
|
2012-04-08 10:52:01 -04:00
|
|
|
RsStackMutex stack(gpgMtxEngine); /******* LOCKED ******/
|
2012-01-27 08:03:59 -05:00
|
|
|
|
2012-04-08 10:52:01 -04:00
|
|
|
PGPIdType id ;
|
2009-05-23 13:40:35 -04:00
|
|
|
|
2012-04-08 10:52:01 -04:00
|
|
|
bool res = PGPHandler::GeneratePGPCertificate(name, email, passwd, id, errString) ;
|
|
|
|
|
|
|
|
pgpId = id.toStdString() ;
|
|
|
|
return res ;
|
2009-05-23 13:40:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**** These Two are common */
|
2012-06-09 17:01:22 -04:00
|
|
|
std::string AuthGPG::getGPGName(const std::string &id,bool *success)
|
2009-05-23 13:40:35 -04:00
|
|
|
{
|
2012-04-26 17:39:45 -04:00
|
|
|
if(id.length() != 16)
|
|
|
|
{
|
|
|
|
std::cerr << "Wrong string passed to getGPGDetails: \"" << id << "\"" << std::endl;
|
|
|
|
return std::string() ;
|
|
|
|
}
|
2012-04-09 13:03:47 -04:00
|
|
|
RsStackMutex stack(gpgMtxData); /******* LOCKED ******/
|
2009-05-25 07:38:47 -04:00
|
|
|
|
2012-06-09 14:45:35 -04:00
|
|
|
const PGPCertificateInfo *info = PGPHandler::getCertificateInfo(PGPIdType(id)) ;
|
2009-11-14 15:20:33 -05:00
|
|
|
|
2012-04-09 13:03:47 -04:00
|
|
|
if(info != NULL)
|
2012-06-09 17:01:22 -04:00
|
|
|
{
|
|
|
|
if(success != NULL) *success = true ;
|
2012-04-09 13:03:47 -04:00
|
|
|
return info->_name ;
|
2012-06-09 17:01:22 -04:00
|
|
|
}
|
2012-04-09 13:03:47 -04:00
|
|
|
else
|
2012-06-09 17:01:22 -04:00
|
|
|
{
|
|
|
|
if(success != NULL) *success = false ;
|
2012-04-09 13:03:47 -04:00
|
|
|
return "[Unknown PGP Cert name]" ;
|
2012-06-09 17:01:22 -04:00
|
|
|
}
|
2009-05-23 13:40:35 -04:00
|
|
|
}
|
|
|
|
|
2010-01-13 15:56:55 -05:00
|
|
|
/**** These Two are common */
|
2012-06-09 17:01:22 -04:00
|
|
|
std::string AuthGPG::getGPGEmail(const std::string &id,bool *success)
|
2009-05-23 13:40:35 -04:00
|
|
|
{
|
2012-04-09 13:03:47 -04:00
|
|
|
RsStackMutex stack(gpgMtxData); /******* LOCKED ******/
|
2012-06-09 14:45:35 -04:00
|
|
|
const PGPCertificateInfo *info = PGPHandler::getCertificateInfo(PGPIdType(id)) ;
|
2010-01-13 15:56:55 -05:00
|
|
|
|
2012-04-09 13:03:47 -04:00
|
|
|
if(info != NULL)
|
2012-06-09 17:01:22 -04:00
|
|
|
{
|
|
|
|
if(success != NULL) *success = true ;
|
2012-04-09 13:03:47 -04:00
|
|
|
return info->_email ;
|
2012-06-09 17:01:22 -04:00
|
|
|
}
|
2012-04-09 13:03:47 -04:00
|
|
|
else
|
2012-06-09 17:01:22 -04:00
|
|
|
{
|
|
|
|
if(success != NULL) *success = false ;
|
2012-04-09 13:03:47 -04:00
|
|
|
return "[Unknown PGP Cert email]" ;
|
2012-06-09 17:01:22 -04:00
|
|
|
}
|
2010-01-13 15:56:55 -05:00
|
|
|
}
|
2009-05-23 13:40:35 -04:00
|
|
|
|
|
|
|
/**** GPG versions ***/
|
|
|
|
|
2012-04-08 10:52:01 -04:00
|
|
|
std::string AuthGPG::getGPGOwnId()
|
2009-05-23 13:40:35 -04:00
|
|
|
{
|
2012-04-09 13:03:47 -04:00
|
|
|
RsStackMutex stack(gpgMtxData); /******* LOCKED ******/
|
|
|
|
return mOwnGpgId.toStdString();
|
2009-05-23 13:40:35 -04:00
|
|
|
}
|
|
|
|
|
2012-04-08 10:52:01 -04:00
|
|
|
std::string AuthGPG::getGPGOwnName()
|
2010-01-13 16:22:52 -05:00
|
|
|
{
|
2012-04-09 13:03:47 -04:00
|
|
|
return getGPGName(mOwnGpgId.toStdString()) ;
|
2010-01-13 16:22:52 -05:00
|
|
|
}
|
|
|
|
|
2012-04-08 10:52:01 -04:00
|
|
|
bool AuthGPG::getGPGAllList(std::list<std::string> &ids)
|
2009-05-23 13:40:35 -04:00
|
|
|
{
|
2012-04-09 13:03:47 -04:00
|
|
|
RsStackMutex stack(gpgMtxData); /******* LOCKED ******/
|
2010-01-21 17:04:20 -05:00
|
|
|
|
2012-04-09 13:03:47 -04:00
|
|
|
std::list<PGPIdType> list ;
|
|
|
|
PGPHandler::getGPGFilteredList(list) ;
|
2010-01-13 16:08:46 -05:00
|
|
|
|
2012-04-09 13:03:47 -04:00
|
|
|
for(std::list<PGPIdType>::const_iterator it(list.begin());it!=list.end();++it)
|
|
|
|
ids.push_back( (*it).toStdString() ) ;
|
2010-01-13 16:12:56 -05:00
|
|
|
|
2012-04-09 13:03:47 -04:00
|
|
|
return true;
|
2010-01-13 16:08:46 -05:00
|
|
|
}
|
|
|
|
|
2012-04-08 10:52:01 -04:00
|
|
|
#ifdef TO_REMOVE
|
|
|
|
bool AuthGPG::decryptText(gpgme_data_t CIPHER, gpgme_data_t PLAIN)
|
2011-08-12 16:02:00 -04:00
|
|
|
{
|
|
|
|
RsStackMutex stack(gpgMtxEngine); /******* LOCKED ******/
|
|
|
|
gpgme_set_armor (CTX, 1);
|
2009-10-27 16:48:11 -04:00
|
|
|
gpg_error_t ERR;
|
2011-01-23 06:57:09 -05:00
|
|
|
|
|
|
|
cleanupZombies(2); // cleanup zombies under OSX. (Called before gpgme operation)
|
|
|
|
|
2009-10-27 16:48:11 -04:00
|
|
|
if (GPG_ERR_NO_ERROR != (ERR = gpgme_op_decrypt (CTX, CIPHER, PLAIN)))
|
2009-08-18 08:43:19 -04:00
|
|
|
{
|
2012-04-08 10:52:01 -04:00
|
|
|
std::cerr << "AuthGPG::decryptText() Error decrypting text" << std::endl;
|
2011-08-12 16:02:00 -04:00
|
|
|
std::cerr << ProcessPGPmeError(ERR) << std::endl;
|
2009-08-18 08:43:19 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-04-08 10:52:01 -04:00
|
|
|
bool AuthGPG::encryptText(gpgme_data_t PLAIN, gpgme_data_t CIPHER)
|
2011-08-12 16:02:00 -04:00
|
|
|
{
|
|
|
|
RsStackMutex stack(gpgMtxEngine); /******* LOCKED ******/
|
2009-08-18 08:43:19 -04:00
|
|
|
gpgme_encrypt_flags_t* flags = new gpgme_encrypt_flags_t();
|
2009-10-27 16:48:11 -04:00
|
|
|
gpgme_key_t keys[2] = {mOwnGpgCert.key, NULL};
|
2011-08-12 16:02:00 -04:00
|
|
|
gpgme_set_armor (CTX, 1);
|
2009-10-27 16:48:11 -04:00
|
|
|
gpg_error_t ERR;
|
2011-01-23 06:57:09 -05:00
|
|
|
|
|
|
|
cleanupZombies(2); // cleanup zombies under OSX. (Called before gpgme operation)
|
|
|
|
|
2009-10-27 16:48:11 -04:00
|
|
|
if (GPG_ERR_NO_ERROR != (ERR = gpgme_op_encrypt(CTX, keys, *flags, PLAIN, CIPHER)))
|
2009-08-18 08:43:19 -04:00
|
|
|
{
|
2012-04-08 10:52:01 -04:00
|
|
|
std::cerr << "AuthGPG::encryptText() Error encrypting text" << std::endl;
|
2011-08-12 16:02:00 -04:00
|
|
|
std::cerr << ProcessPGPmeError(ERR) << std::endl;
|
2009-08-18 08:43:19 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2012-04-08 10:52:01 -04:00
|
|
|
#endif
|
2009-08-18 08:43:19 -04:00
|
|
|
|
2012-06-14 16:13:31 -04:00
|
|
|
bool AuthGPG::isKeySupported(const std::string& id) const
|
|
|
|
{
|
|
|
|
const PGPCertificateInfo *pc = PGPHandler::getCertificateInfo(PGPIdType(id)) ;
|
|
|
|
|
|
|
|
if(pc == NULL)
|
|
|
|
return false ;
|
|
|
|
|
|
|
|
return !(pc->_flags & PGPCertificateInfo::PGP_CERTIFICATE_FLAG_UNSUPPORTED_ALGORITHM) ;
|
|
|
|
}
|
|
|
|
|
2012-04-09 13:03:47 -04:00
|
|
|
bool AuthGPG::getGPGDetails(const std::string& id, RsPeerDetails &d)
|
2010-01-13 16:16:18 -05:00
|
|
|
{
|
2012-04-09 13:03:47 -04:00
|
|
|
RsStackMutex stack(gpgMtxData); /******* LOCKED ******/
|
2010-01-13 16:16:18 -05:00
|
|
|
|
2012-04-26 17:39:45 -04:00
|
|
|
if(id.length() != 16)
|
|
|
|
{
|
|
|
|
std::cerr << "Wrong string passed to getGPGDetails: \"" << id << "\"" << std::endl;
|
|
|
|
return false ;
|
|
|
|
}
|
|
|
|
|
2012-06-09 14:45:35 -04:00
|
|
|
const PGPCertificateInfo *pc = PGPHandler::getCertificateInfo(PGPIdType(id)) ;
|
2012-04-09 13:03:47 -04:00
|
|
|
|
|
|
|
if(pc == NULL)
|
|
|
|
return false ;
|
|
|
|
|
|
|
|
const PGPCertificateInfo& cert(*pc) ;
|
|
|
|
|
|
|
|
d.id = id ;
|
|
|
|
d.gpg_id = id ;
|
|
|
|
d.name = cert._name;
|
|
|
|
d.email = cert._email;
|
|
|
|
d.trustLvl = cert._trustLvl;
|
|
|
|
d.validLvl = cert._validLvl;
|
|
|
|
d.ownsign = cert._flags & PGPCertificateInfo::PGP_CERTIFICATE_FLAG_HAS_OWN_SIGNATURE;
|
|
|
|
d.gpgSigners.clear() ;
|
|
|
|
for(std::set<std::string>::const_iterator it(cert.signers.begin());it!=cert.signers.end();++it)
|
|
|
|
d.gpgSigners.push_back( *it ) ;
|
|
|
|
|
|
|
|
d.fpr = cert._fpr.toStdString();
|
|
|
|
|
|
|
|
d.accept_connection = cert._flags & PGPCertificateInfo::PGP_CERTIFICATE_FLAG_ACCEPT_CONNEXION;
|
|
|
|
d.hasSignedMe = cert._flags & PGPCertificateInfo::PGP_CERTIFICATE_FLAG_HAS_SIGNED_ME;
|
2009-05-25 07:38:47 -04:00
|
|
|
|
2009-05-23 13:40:35 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-04-09 13:03:47 -04:00
|
|
|
bool AuthGPG::getGPGFilteredList(std::list<std::string>& list,bool (*filter)(const PGPCertificateInfo&))
|
2009-05-23 13:40:35 -04:00
|
|
|
{
|
2012-04-09 13:03:47 -04:00
|
|
|
RsStackMutex stack(gpgMtxData); /******* LOCKED ******/
|
|
|
|
std::list<PGPIdType> ids ;
|
2010-01-13 16:05:38 -05:00
|
|
|
|
2012-04-09 13:03:47 -04:00
|
|
|
PGPHandler::getGPGFilteredList(ids,filter) ;
|
2009-05-23 13:40:35 -04:00
|
|
|
|
2012-04-09 13:03:47 -04:00
|
|
|
for(std::list<PGPIdType>::const_iterator it(ids.begin());it!=ids.end();++it)
|
|
|
|
list.push_back( (*it).toStdString() ) ;
|
2012-05-01 04:53:32 -04:00
|
|
|
|
|
|
|
return true ;
|
2010-01-13 16:25:18 -05:00
|
|
|
}
|
|
|
|
|
2012-04-09 13:03:47 -04:00
|
|
|
static bool filter_Validity(const PGPCertificateInfo& info) { return true ; } //{ return info._validLvl >= PGPCertificateInfo::GPGME_VALIDITY_MARGINAL ; }
|
|
|
|
static bool filter_Accepted(const PGPCertificateInfo& info) { return info._flags & PGPCertificateInfo::PGP_CERTIFICATE_FLAG_ACCEPT_CONNEXION ; }
|
|
|
|
static bool filter_OwnSigned(const PGPCertificateInfo& info) { return info._flags & PGPCertificateInfo::PGP_CERTIFICATE_FLAG_HAS_OWN_SIGNATURE ; }
|
2009-05-23 13:40:35 -04:00
|
|
|
|
2012-04-09 13:03:47 -04:00
|
|
|
bool AuthGPG::getGPGValidList(std::list<std::string> &ids)
|
2009-05-23 13:40:35 -04:00
|
|
|
{
|
2012-04-09 13:03:47 -04:00
|
|
|
return getGPGFilteredList(ids,&filter_Validity);
|
2009-05-23 13:40:35 -04:00
|
|
|
}
|
|
|
|
|
2012-04-09 13:03:47 -04:00
|
|
|
bool AuthGPG::getGPGAcceptedList(std::list<std::string> &ids)
|
2010-01-13 16:22:52 -05:00
|
|
|
{
|
2012-04-09 13:03:47 -04:00
|
|
|
return getGPGFilteredList(ids,&filter_Accepted);
|
2010-01-13 16:22:52 -05:00
|
|
|
}
|
|
|
|
|
2012-04-09 13:03:47 -04:00
|
|
|
bool AuthGPG::getGPGSignedList(std::list<std::string> &ids)
|
2012-02-15 11:44:45 -05:00
|
|
|
{
|
2012-04-09 13:03:47 -04:00
|
|
|
return getGPGFilteredList(ids,&filter_OwnSigned);
|
2012-02-15 11:44:45 -05:00
|
|
|
}
|
|
|
|
|
2012-04-08 10:52:01 -04:00
|
|
|
bool AuthGPG::getCachedGPGCertificate(const std::string &id, std::string &certificate)
|
2012-02-15 11:44:45 -05:00
|
|
|
{
|
2012-04-09 13:03:47 -04:00
|
|
|
RsStackMutex stack(gpgMtxData); /******* LOCKED ******/
|
2012-06-09 14:45:35 -04:00
|
|
|
certificate = PGPHandler::SaveCertificateToString(PGPIdType(id),false) ;
|
2012-02-15 11:44:45 -05:00
|
|
|
|
2012-04-09 13:03:47 -04:00
|
|
|
#ifdef LIMIT_CERTIFICATE_SIZE
|
|
|
|
std::string cleaned_key ;
|
|
|
|
if(PGPKeyManagement::createMinimalKey(certificate,cleaned_key))
|
|
|
|
certificate = cleaned_key ;
|
2012-02-17 15:28:59 -05:00
|
|
|
#endif
|
2012-02-15 11:44:45 -05:00
|
|
|
|
2012-04-09 13:03:47 -04:00
|
|
|
return certificate.length() > 0 ;
|
2012-02-15 11:44:45 -05:00
|
|
|
}
|
|
|
|
|
2009-05-23 13:40:35 -04:00
|
|
|
/*****************************************************************
|
|
|
|
* Loading and Saving Certificates - this has to
|
|
|
|
* be able to handle both openpgp and X509 certificates.
|
|
|
|
*
|
|
|
|
* X509 are passed onto AuthSSL, OpenPGP are passed to gpgme.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/* SKTAN : do not know how to use std::string id */
|
2012-04-08 10:52:01 -04:00
|
|
|
std::string AuthGPG::SaveCertificateToString(const std::string &id,bool include_signatures)
|
2009-05-23 13:40:35 -04:00
|
|
|
{
|
2009-05-25 07:38:47 -04:00
|
|
|
|
2012-01-23 15:55:08 -05:00
|
|
|
if (!isGPGId(id)) {
|
2012-04-08 10:52:01 -04:00
|
|
|
std::cerr << "AuthGPG::SaveCertificateToString() unknown ID" << std::endl;
|
2012-01-23 15:55:08 -05:00
|
|
|
return "";
|
2009-05-23 13:40:35 -04:00
|
|
|
}
|
|
|
|
|
2012-01-23 15:55:08 -05:00
|
|
|
RsStackMutex stack(gpgMtxEngine); /******* LOCKED ******/
|
2009-05-25 07:38:47 -04:00
|
|
|
|
2012-06-09 14:45:35 -04:00
|
|
|
std::string tmp = PGPHandler::SaveCertificateToString(PGPIdType(id),include_signatures) ;
|
2009-05-23 13:40:35 -04:00
|
|
|
|
2012-01-23 15:55:08 -05:00
|
|
|
// Try to remove signatures manually.
|
|
|
|
//
|
|
|
|
std::string cleaned_key ;
|
|
|
|
|
|
|
|
if( (!include_signatures) && PGPKeyManagement::createMinimalKey(tmp,cleaned_key))
|
|
|
|
return cleaned_key ;
|
|
|
|
else
|
|
|
|
return tmp;
|
2009-05-23 13:40:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* import to GnuPG and other Certificates */
|
2012-04-08 10:52:01 -04:00
|
|
|
bool AuthGPG::LoadCertificateFromString(const std::string &str, std::string &gpg_id,std::string& error_string)
|
2009-05-23 13:40:35 -04:00
|
|
|
{
|
2012-04-08 10:52:01 -04:00
|
|
|
RsStackMutex stack(gpgMtxEngine); /******* LOCKED ******/
|
2009-05-25 07:38:47 -04:00
|
|
|
|
2012-04-08 10:52:01 -04:00
|
|
|
PGPIdType id ;
|
|
|
|
bool res = PGPHandler::LoadCertificateFromString(str,id,error_string) ;
|
2009-05-23 13:40:35 -04:00
|
|
|
|
2012-04-08 10:52:01 -04:00
|
|
|
gpg_id = id.toStdString();
|
2009-05-23 13:40:35 -04:00
|
|
|
|
2012-04-08 10:52:01 -04:00
|
|
|
return res ;
|
2009-05-23 13:40:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************
|
|
|
|
* Auth...? Signing, Revoke, Trust are all done at
|
|
|
|
* the PGP level....
|
|
|
|
*
|
|
|
|
* Only Signing of SSL is done at setup.
|
|
|
|
* Auth should be done... ?? not sure
|
|
|
|
* maybe
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************/
|
|
|
|
|
2010-01-13 16:22:52 -05:00
|
|
|
/* These take PGP Ids */
|
2012-04-08 10:52:01 -04:00
|
|
|
bool AuthGPG::AllowConnection(const std::string &gpg_id, bool accept)
|
2010-01-13 16:22:52 -05:00
|
|
|
{
|
2010-01-21 18:01:48 -05:00
|
|
|
#ifdef GPG_DEBUG
|
2012-04-08 10:52:01 -04:00
|
|
|
std::cerr << "AuthGPG::AllowConnection(" << gpg_id << ")" << std::endl;
|
2010-01-21 18:01:48 -05:00
|
|
|
#endif
|
2010-01-13 16:22:52 -05:00
|
|
|
|
2011-08-07 17:11:00 -04:00
|
|
|
/* Was a "Reload Certificates" here -> be shouldn't be needed -> and very expensive, try without. */
|
|
|
|
{
|
|
|
|
RsStackMutex stack(gpgMtxData);
|
2012-06-09 14:45:35 -04:00
|
|
|
PGPHandler::setAcceptConnexion(PGPIdType(gpg_id),accept) ;
|
2011-08-07 17:11:00 -04:00
|
|
|
}
|
2010-04-25 13:06:48 -04:00
|
|
|
|
2011-08-21 18:28:19 -04:00
|
|
|
IndicateConfigChanged();
|
2010-01-13 16:26:30 -05:00
|
|
|
|
2011-08-21 18:28:19 -04:00
|
|
|
rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_FRIENDS, accept ? NOTIFY_TYPE_ADD : NOTIFY_TYPE_DEL);
|
|
|
|
|
|
|
|
return true;
|
2010-01-13 16:22:52 -05:00
|
|
|
}
|
|
|
|
|
2009-05-23 13:40:35 -04:00
|
|
|
/* These take PGP Ids */
|
2012-04-08 10:52:01 -04:00
|
|
|
bool AuthGPG::SignCertificateLevel0(const std::string &id)
|
2009-05-23 13:40:35 -04:00
|
|
|
{
|
2011-08-12 09:42:30 -04:00
|
|
|
/* remove unused parameter warnings */
|
|
|
|
(void) id;
|
2009-05-25 07:38:47 -04:00
|
|
|
|
2010-01-21 18:01:48 -05:00
|
|
|
#ifdef GPG_DEBUG
|
2012-04-08 10:52:01 -04:00
|
|
|
std::cerr << "AuthGPG::SignCertificat(" << id << ")" << std::endl;
|
2010-01-21 18:01:48 -05:00
|
|
|
#endif
|
2009-05-23 13:40:35 -04:00
|
|
|
|
2011-08-12 09:42:30 -04:00
|
|
|
if (1 != privateSignCertificate(id))
|
2009-05-25 07:38:47 -04:00
|
|
|
{
|
2012-04-08 10:52:01 -04:00
|
|
|
// storeAllKeys();
|
2009-05-25 07:38:47 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-08-12 09:42:30 -04:00
|
|
|
/* reload stuff now ... */
|
2012-04-08 10:52:01 -04:00
|
|
|
// storeAllKeys();
|
2009-05-25 07:38:47 -04:00
|
|
|
return true;
|
2009-05-23 13:40:35 -04:00
|
|
|
}
|
|
|
|
|
2012-04-08 10:52:01 -04:00
|
|
|
bool AuthGPG::RevokeCertificate(const std::string &id)
|
2009-05-23 13:40:35 -04:00
|
|
|
{
|
2011-08-12 09:42:30 -04:00
|
|
|
//RsStackMutex stack(gpgMtx); /******* LOCKED ******/
|
|
|
|
|
|
|
|
/* remove unused parameter warnings */
|
|
|
|
(void) id;
|
2009-05-25 07:38:47 -04:00
|
|
|
|
2010-01-21 18:01:48 -05:00
|
|
|
#ifdef GPG_DEBUG
|
2012-04-08 10:52:01 -04:00
|
|
|
std::cerr << "AuthGPG::RevokeCertificate(" << id << ") not implemented yet" << std::endl;
|
2010-01-21 18:01:48 -05:00
|
|
|
#endif
|
2009-05-23 13:40:35 -04:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-04-08 10:52:01 -04:00
|
|
|
bool AuthGPG::TrustCertificate(const std::string &id, int trustlvl)
|
2010-01-13 16:14:49 -05:00
|
|
|
{
|
2010-01-21 18:01:48 -05:00
|
|
|
#ifdef GPG_DEBUG
|
2012-04-08 10:52:01 -04:00
|
|
|
std::cerr << "AuthGPG::TrustCertificate(" << id << ", " << trustlvl << ")" << std::endl;
|
2010-01-21 18:01:48 -05:00
|
|
|
#endif
|
2010-04-08 15:07:40 -04:00
|
|
|
if (1 != privateTrustCertificate(id, trustlvl))
|
|
|
|
{
|
2012-04-08 10:52:01 -04:00
|
|
|
// storeAllKeys();
|
2010-04-08 15:07:40 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-09-30 15:05:43 -04:00
|
|
|
/* Keys are reloaded by privateTrustCertificate */
|
2010-04-08 15:07:40 -04:00
|
|
|
return true;
|
2010-01-13 16:14:49 -05:00
|
|
|
}
|
|
|
|
|
2010-06-25 17:50:46 -04:00
|
|
|
#if 0
|
|
|
|
/* remove otherwise will cause bugs */
|
2012-04-08 10:52:01 -04:00
|
|
|
bool AuthGPG::SignData(std::string input, std::string &sign)
|
2009-05-23 13:40:35 -04:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-04-08 10:52:01 -04:00
|
|
|
bool AuthGPG::SignData(const void *data, const uint32_t len, std::string &sign)
|
2009-05-23 13:40:35 -04:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-08 10:52:01 -04:00
|
|
|
bool AuthGPG::SignDataBin(std::string input, unsigned char *sign, unsigned int *signlen)
|
2009-05-23 13:40:35 -04:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2010-06-25 17:50:46 -04:00
|
|
|
#endif
|
2009-05-23 13:40:35 -04:00
|
|
|
|
2012-04-08 10:52:01 -04:00
|
|
|
bool AuthGPG::SignDataBin(const void *data, unsigned int datalen, unsigned char *sign, unsigned int *signlen) {
|
2010-06-25 17:50:46 -04:00
|
|
|
return DoOwnSignature(data, datalen,
|
2010-01-13 15:52:31 -05:00
|
|
|
sign, signlen);
|
2009-05-23 13:40:35 -04:00
|
|
|
}
|
|
|
|
|
2012-04-08 10:52:01 -04:00
|
|
|
bool AuthGPG::VerifySignBin(const void *data, uint32_t datalen, unsigned char *sign, unsigned int signlen, const std::string &withfingerprint) {
|
2010-06-25 17:50:46 -04:00
|
|
|
return VerifySignature(data, datalen,
|
2010-01-13 16:22:52 -05:00
|
|
|
sign, signlen, withfingerprint);
|
2009-05-23 13:40:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Sign/Trust stuff */
|
|
|
|
|
2012-04-08 10:52:01 -04:00
|
|
|
int AuthGPG::privateSignCertificate(const std::string &id)
|
2009-05-23 13:40:35 -04:00
|
|
|
{
|
2012-04-08 10:52:01 -04:00
|
|
|
std::cerr << __PRETTY_FUNCTION__ << ": To be implemented." << std::endl;
|
2010-09-28 18:30:57 -04:00
|
|
|
|
2012-04-08 10:52:01 -04:00
|
|
|
// /* The key should be in Others list and not in Peers list ??
|
|
|
|
// * Once the key is signed, it moves from Others to Peers list ???
|
|
|
|
// */
|
|
|
|
//
|
|
|
|
// gpgcert signKey;
|
|
|
|
// gpgcert ownKey;
|
|
|
|
//
|
|
|
|
// {
|
|
|
|
// RsStackMutex stack(gpgMtxData); /******* LOCKED ******/
|
|
|
|
// certmap::iterator it;
|
|
|
|
//
|
|
|
|
// if (mKeyList.end() == (it = mKeyList.find(id)))
|
|
|
|
// {
|
|
|
|
// return false;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// /* grab a reference, so the key remains */
|
|
|
|
// gpgme_key_ref(it->second.key);
|
|
|
|
//
|
|
|
|
// signKey = it->second;
|
|
|
|
//
|
|
|
|
// /* grab a reference, so the key remains */
|
|
|
|
// gpgme_key_ref(mOwnGpgCert.key);
|
|
|
|
//
|
|
|
|
// ownKey = mOwnGpgCert;
|
|
|
|
// } /******* UNLOCKED ******/
|
|
|
|
//
|
|
|
|
// RsStackMutex stack(gpgMtxEngine); /******* LOCKED ******/
|
|
|
|
//
|
|
|
|
// class SignParams sparams("0");
|
|
|
|
// class EditParams params(SIGN_START, &sparams);
|
|
|
|
// gpgme_data_t out;
|
|
|
|
// gpg_error_t ERR;
|
|
|
|
//
|
|
|
|
// if(GPG_ERR_NO_ERROR != (ERR = gpgme_data_new(&out))) {
|
|
|
|
// return 0;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// gpgme_signers_clear(CTX);
|
|
|
|
// if(GPG_ERR_NO_ERROR != (ERR = gpgme_signers_add(CTX, ownKey.key))) {
|
|
|
|
// gpgme_data_release(out);
|
|
|
|
// return 0;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if(GPG_ERR_NO_ERROR != (ERR = gpgme_op_edit(CTX, signKey.key, keySignCallback, ¶ms, out))) {
|
|
|
|
// gpgme_data_release(out);
|
|
|
|
// gpgme_signers_clear(CTX);
|
|
|
|
// return 0;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// gpgme_data_release(out);
|
|
|
|
// gpgme_signers_clear(CTX);
|
2010-06-18 18:58:27 -04:00
|
|
|
|
2009-05-23 13:40:35 -04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* revoke the signature on Certificate */
|
2012-04-08 10:52:01 -04:00
|
|
|
int AuthGPG::privateRevokeCertificate(const std::string &/*id*/)
|
2009-05-23 13:40:35 -04:00
|
|
|
{
|
2011-08-12 09:42:30 -04:00
|
|
|
//RsStackMutex stack(gpgMtx); /******* LOCKED ******/
|
2009-05-25 07:38:47 -04:00
|
|
|
|
2009-05-23 13:40:35 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-04-08 10:52:01 -04:00
|
|
|
int AuthGPG::privateTrustCertificate(const std::string &id, int trustlvl)
|
2009-05-23 13:40:35 -04:00
|
|
|
{
|
2010-01-13 16:34:47 -05:00
|
|
|
/* The certificate should be in Peers list ??? */
|
2010-12-21 16:13:08 -05:00
|
|
|
if(!isGPGAccepted(id)) {
|
2009-05-23 13:40:35 -04:00
|
|
|
std::cerr << "Invalid Certificate" << std::endl;
|
|
|
|
return 0;
|
|
|
|
}
|
2010-04-25 13:06:48 -04:00
|
|
|
|
2012-04-08 10:52:01 -04:00
|
|
|
std::cerr << __PRETTY_FUNCTION__ << ": to be implemented!" << std::endl;
|
|
|
|
|
|
|
|
// {
|
|
|
|
// gpgcert trustCert;
|
|
|
|
// {
|
|
|
|
// RsStackMutex stack(gpgMtxData);
|
|
|
|
//
|
|
|
|
// trustCert = mKeyList.find(id)->second;
|
|
|
|
// } /******* UNLOCKED ******/
|
|
|
|
//
|
|
|
|
// RsStackMutex stack(gpgMtxEngine); /******* LOCKED ******/
|
|
|
|
//
|
|
|
|
// gpgme_key_t trustKey = trustCert.key;
|
|
|
|
// std::string trustString;
|
|
|
|
// std::ostringstream trustStrOut;
|
|
|
|
// trustStrOut << trustlvl;
|
|
|
|
// class TrustParams sparams(trustStrOut.str());
|
|
|
|
// class EditParams params(TRUST_START, &sparams);
|
|
|
|
// gpgme_data_t out;
|
|
|
|
// gpg_error_t ERR;
|
|
|
|
//
|
|
|
|
// if(GPG_ERR_NO_ERROR != (ERR = gpgme_data_new(&out))) {
|
|
|
|
// return 0;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if(GPG_ERR_NO_ERROR != (ERR = gpgme_op_edit(CTX, trustKey, trustCallback, ¶ms, out))) {
|
|
|
|
// gpgme_data_release(out);
|
|
|
|
// return 0;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// gpgme_data_release(out);
|
|
|
|
//
|
|
|
|
// //the key ref has changed, we got to get rid of the old reference.
|
|
|
|
// trustCert.key = NULL;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// storeAllKeys();
|
2009-05-23 13:40:35 -04:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2010-01-18 07:30:54 -05:00
|
|
|
static std::string setKeyPairParams(bool useRsa, unsigned int blen,
|
|
|
|
std::string name, std::string comment, std::string email,
|
|
|
|
std::string inPassphrase)
|
|
|
|
{
|
|
|
|
std::ostringstream params;
|
|
|
|
params << "<GnupgKeyParms format=\"internal\">"<< std::endl;
|
|
|
|
if (useRsa)
|
|
|
|
{
|
|
|
|
params << "Key-Type: RSA"<< std::endl;
|
|
|
|
if (blen < 1024)
|
|
|
|
{
|
2010-01-21 18:01:48 -05:00
|
|
|
#ifdef GPG_DEBUG
|
2010-01-18 07:30:54 -05:00
|
|
|
std::cerr << "Weak Key... strengthing..."<< std::endl;
|
2010-01-21 18:01:48 -05:00
|
|
|
#endif
|
2010-01-18 07:30:54 -05:00
|
|
|
blen = 1024;
|
|
|
|
}
|
|
|
|
blen = ((blen / 512) * 512); /* make multiple of 512 */
|
|
|
|
params << "Key-Length: "<< blen << std::endl;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
params << "Key-Type: DSA"<< std::endl;
|
|
|
|
params << "Key-Length: 1024"<< std::endl;
|
|
|
|
params << "Subkey-Type: ELG-E"<< std::endl;
|
|
|
|
params << "Subkey-Length: 1024"<< std::endl;
|
|
|
|
}
|
|
|
|
params << "Name-Real: "<< name << std::endl;
|
|
|
|
params << "Name-Comment: "<< comment << std::endl;
|
|
|
|
params << "Name-Email: "<< email << std::endl;
|
|
|
|
params << "Expire-Date: 0"<< std::endl;
|
|
|
|
params << "Passphrase: "<< inPassphrase << std::endl;
|
|
|
|
params << "</GnupgKeyParms>"<< std::endl;
|
|
|
|
|
|
|
|
return params.str();
|
|
|
|
}
|
2009-05-23 13:40:35 -04:00
|
|
|
|
|
|
|
|
|
|
|
/* Author: Shiva
|
|
|
|
* This function returns the key macthing the user parameters
|
|
|
|
* from the keyring
|
|
|
|
*/
|
|
|
|
|
2010-04-25 15:26:37 -04:00
|
|
|
#ifdef UNUSED_CODE
|
2009-05-23 13:40:35 -04:00
|
|
|
static gpgme_key_t getKey(gpgme_ctx_t CTX, std::string name, std::string comment, std::string email) {
|
|
|
|
|
|
|
|
gpgme_key_t key;
|
|
|
|
gpgme_user_id_t user;
|
|
|
|
|
|
|
|
/* Initiates a key listing */
|
|
|
|
if (GPG_ERR_NO_ERROR != gpgme_op_keylist_start (CTX, "", 0))
|
|
|
|
{
|
|
|
|
std::cerr << "Error iterating through KeyList";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Loop until end of key */
|
|
|
|
for(int i = 0;(GPG_ERR_NO_ERROR == gpgme_op_keylist_next (CTX, &key)); i++)
|
|
|
|
{
|
|
|
|
user = key->uids;
|
|
|
|
|
|
|
|
while(user != NULL) {
|
|
|
|
if((name.size() && name == user->name) && (comment.size() && comment == user->comment) && \
|
2009-05-25 07:38:47 -04:00
|
|
|
(email.size() && email == user->email))
|
|
|
|
{
|
|
|
|
/* grab a reference to the key */
|
|
|
|
gpgme_op_keylist_end(CTX);
|
|
|
|
if (GPG_ERR_NO_ERROR != gpgme_op_keylist_end(CTX))
|
|
|
|
{
|
|
|
|
std::cerr << "Error ending KeyList";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
}
|
|
|
|
gpgme_key_ref(key);
|
2009-05-23 13:40:35 -04:00
|
|
|
return key;
|
|
|
|
}
|
|
|
|
user = user->next;
|
|
|
|
}
|
|
|
|
}
|
2009-05-25 07:38:47 -04:00
|
|
|
|
|
|
|
if (GPG_ERR_NO_ERROR != gpgme_op_keylist_end(CTX))
|
|
|
|
{
|
2010-02-07 16:28:40 -05:00
|
|
|
std::cerr << "Error ending KeyList" << std::endl;
|
2009-05-25 07:38:47 -04:00
|
|
|
}
|
2009-05-23 13:40:35 -04:00
|
|
|
return NULL;
|
|
|
|
}
|
2010-04-25 15:26:37 -04:00
|
|
|
#endif
|
2009-05-23 13:40:35 -04:00
|
|
|
|
2012-04-08 10:52:01 -04:00
|
|
|
#ifdef TO_REMOVE
|
2009-05-23 13:40:35 -04:00
|
|
|
/* Callback function for key signing */
|
|
|
|
|
|
|
|
static gpg_error_t keySignCallback(void *opaque, gpgme_status_code_t status, \
|
|
|
|
const char *args, int fd) {
|
|
|
|
|
|
|
|
class EditParams *params = (class EditParams *)opaque;
|
|
|
|
class SignParams *sparams = (class SignParams *)params->oParams;
|
|
|
|
const char *result = NULL;
|
2010-04-25 15:26:37 -04:00
|
|
|
#ifdef GPG_DEBUG
|
2010-01-13 16:08:46 -05:00
|
|
|
fprintf(stderr,"keySignCallback status: %d args: %s, params->state: %d\n", status, args, params->state);
|
2009-05-25 07:38:47 -04:00
|
|
|
|
|
|
|
/* printf stuff out */
|
|
|
|
if (status == GPGME_STATUS_EOF)
|
|
|
|
fprintf(stderr,"keySignCallback GPGME_STATUS_EOF\n");
|
|
|
|
if (status == GPGME_STATUS_GOT_IT)
|
|
|
|
fprintf(stderr,"keySignCallback GPGME_STATUS_GOT_IT\n");
|
|
|
|
if (status == GPGME_STATUS_USERID_HINT)
|
|
|
|
fprintf(stderr,"keySignCallback GPGME_STATUS_USERID_HINT\n");
|
|
|
|
if (status == GPGME_STATUS_NEED_PASSPHRASE)
|
|
|
|
fprintf(stderr,"keySignCallback GPGME_STATUS_NEED_PASSPHRASE\n");
|
|
|
|
if (status == GPGME_STATUS_GOOD_PASSPHRASE)
|
|
|
|
fprintf(stderr,"keySignCallback GPGME_STATUS_GOOD_PASSPHRASE\n");
|
|
|
|
if (status == GPGME_STATUS_BAD_PASSPHRASE)
|
|
|
|
fprintf(stderr,"keySignCallback GPGME_STATUS_BAD_PASSPHRASE\n");
|
|
|
|
if (status == GPGME_STATUS_GET_LINE)
|
|
|
|
fprintf(stderr,"keySignCallback GPGME_STATUS_GET_LINE\n");
|
|
|
|
if (status == GPGME_STATUS_GET_BOOL)
|
|
|
|
fprintf(stderr,"keySignCallback GPGME_STATUS_GET_BOOL\n");
|
|
|
|
if (status == GPGME_STATUS_ALREADY_SIGNED)
|
|
|
|
fprintf(stderr,"keySignCallback GPGME_STATUS_ALREADY_SIGNED\n");
|
|
|
|
|
2010-01-13 16:08:46 -05:00
|
|
|
/* printf stuff out */
|
|
|
|
if (params->state == SIGN_START)
|
|
|
|
fprintf(stderr,"keySignCallback params->state SIGN_START\n");
|
|
|
|
if (params->state == SIGN_COMMAND)
|
|
|
|
fprintf(stderr,"keySignCallback params->state SIGN_COMMAND\n");
|
|
|
|
if (params->state == SIGN_UIDS)
|
|
|
|
fprintf(stderr,"keySignCallback params->state SIGN_UIDS\n");
|
|
|
|
if (params->state == SIGN_SET_EXPIRE)
|
|
|
|
fprintf(stderr,"keySignCallback params->state SIGN_SET_EXPIRE\n");
|
|
|
|
if (params->state == SIGN_SET_CHECK_LEVEL)
|
|
|
|
fprintf(stderr,"keySignCallback params->state SIGN_SET_CHECK_LEVEL\n");
|
|
|
|
if (params->state == SIGN_CONFIRM)
|
|
|
|
fprintf(stderr,"keySignCallback params->state SIGN_CONFIRM\n");
|
|
|
|
if (params->state == SIGN_QUIT)
|
|
|
|
fprintf(stderr,"keySignCallback params->state SIGN_QUIT\n");
|
|
|
|
if (params->state == SIGN_ENTER_PASSPHRASE)
|
|
|
|
fprintf(stderr,"keySignCallback params->state SIGN_ENTER_PASSPHRASE\n");
|
|
|
|
if (params->state == SIGN_ERROR)
|
|
|
|
fprintf(stderr,"keySignCallback params->state SIGN_ERROR");
|
2010-04-25 15:26:37 -04:00
|
|
|
#endif
|
2010-01-13 16:08:46 -05:00
|
|
|
|
2009-05-25 07:38:47 -04:00
|
|
|
|
2009-05-23 13:40:35 -04:00
|
|
|
if(status == GPGME_STATUS_EOF ||
|
|
|
|
status == GPGME_STATUS_GOT_IT ||
|
|
|
|
status == GPGME_STATUS_USERID_HINT ||
|
|
|
|
status == GPGME_STATUS_NEED_PASSPHRASE ||
|
2009-05-25 07:38:47 -04:00
|
|
|
// status == GPGME_STATUS_GOOD_PASSPHRASE ||
|
2009-05-23 13:40:35 -04:00
|
|
|
status == GPGME_STATUS_BAD_PASSPHRASE) {
|
2009-05-25 07:38:47 -04:00
|
|
|
|
|
|
|
|
|
|
|
fprintf(stderr,"keySignCallback Error status\n");
|
2011-08-12 16:02:00 -04:00
|
|
|
std::cerr << ProcessPGPmeError(params->err) << std::endl;
|
2009-05-25 07:38:47 -04:00
|
|
|
|
2009-05-23 13:40:35 -04:00
|
|
|
return params->err;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (params->state)
|
|
|
|
{
|
|
|
|
case SIGN_START:
|
2010-04-25 15:26:37 -04:00
|
|
|
#ifdef GPG_DEBUG
|
2009-05-25 07:38:47 -04:00
|
|
|
fprintf(stderr,"keySignCallback SIGN_START\n");
|
2010-04-25 15:26:37 -04:00
|
|
|
#endif
|
2009-05-25 07:38:47 -04:00
|
|
|
|
2009-05-23 13:40:35 -04:00
|
|
|
if (status == GPGME_STATUS_GET_LINE &&
|
|
|
|
(!std::string("keyedit.prompt").compare(args)))
|
|
|
|
{
|
|
|
|
params->state = SIGN_COMMAND;
|
|
|
|
result = "sign";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
params->state = SIGN_ERROR;
|
|
|
|
params->err = gpg_error (GPG_ERR_GENERAL);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SIGN_COMMAND:
|
2010-04-25 15:26:37 -04:00
|
|
|
#ifdef GPG_DEBUG
|
2009-05-25 07:38:47 -04:00
|
|
|
fprintf(stderr,"keySignCallback SIGN_COMMAND\n");
|
2010-04-25 15:26:37 -04:00
|
|
|
#endif
|
2009-05-25 07:38:47 -04:00
|
|
|
|
2009-05-23 13:40:35 -04:00
|
|
|
if (status == GPGME_STATUS_GET_BOOL &&
|
|
|
|
(!std::string("keyedit.sign_all.okay").compare(args)))
|
|
|
|
{
|
|
|
|
params->state = SIGN_UIDS;
|
|
|
|
result = "Y";
|
|
|
|
}
|
|
|
|
else if (status == GPGME_STATUS_GET_BOOL &&
|
|
|
|
(!std::string("sign_uid.okay").compare(args)))
|
|
|
|
{
|
|
|
|
params->state = SIGN_ENTER_PASSPHRASE;
|
|
|
|
result = "Y";
|
|
|
|
}
|
|
|
|
else if (status == GPGME_STATUS_GET_LINE &&
|
|
|
|
(!std::string("sign_uid.expire").compare(args)))
|
|
|
|
{
|
|
|
|
params->state = SIGN_SET_EXPIRE;
|
|
|
|
result = "Y";
|
|
|
|
}
|
|
|
|
else if (status == GPGME_STATUS_GET_LINE &&
|
|
|
|
(!std::string("sign_uid.class").compare(args)))
|
|
|
|
{
|
|
|
|
params->state = SIGN_SET_CHECK_LEVEL;
|
|
|
|
result = sparams->checkLvl.c_str();
|
|
|
|
}
|
|
|
|
else if (status == GPGME_STATUS_ALREADY_SIGNED)
|
|
|
|
{
|
|
|
|
/* The key has already been signed with this key */
|
2010-01-13 16:25:18 -05:00
|
|
|
params->state = SIGN_QUIT;
|
|
|
|
result = "quit";
|
2009-05-23 13:40:35 -04:00
|
|
|
}
|
|
|
|
else if (status == GPGME_STATUS_GET_LINE &&
|
|
|
|
(!std::string("keyedit.prompt").compare(args)))
|
|
|
|
{
|
|
|
|
/* Failed sign: expired key */
|
|
|
|
params->state = SIGN_ERROR;
|
|
|
|
params->err = gpg_error (GPG_ERR_UNUSABLE_PUBKEY);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
params->state = SIGN_ERROR;
|
|
|
|
params->err = gpg_error (GPG_ERR_GENERAL);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SIGN_UIDS:
|
2010-04-25 15:26:37 -04:00
|
|
|
#ifdef GPG_DEBUG
|
2009-05-25 07:38:47 -04:00
|
|
|
fprintf(stderr,"keySignCallback SIGN_UIDS\n");
|
2010-04-25 15:26:37 -04:00
|
|
|
#endif
|
2009-05-25 07:38:47 -04:00
|
|
|
|
2009-05-23 13:40:35 -04:00
|
|
|
if (status == GPGME_STATUS_GET_LINE &&
|
|
|
|
(!std::string("sign_uid.expire").compare(args)))
|
|
|
|
{
|
|
|
|
params->state = SIGN_SET_EXPIRE;
|
|
|
|
result = "Y";
|
|
|
|
}
|
|
|
|
else if (status == GPGME_STATUS_GET_LINE &&
|
|
|
|
(!std::string("sign_uid.class").compare(args)))
|
|
|
|
{
|
|
|
|
params->state = SIGN_SET_CHECK_LEVEL;
|
|
|
|
result = sparams->checkLvl.c_str();
|
|
|
|
}
|
|
|
|
else if (status == GPGME_STATUS_GET_BOOL &&
|
|
|
|
(!std::string("sign_uid.okay").compare(args)))
|
|
|
|
{
|
|
|
|
params->state = SIGN_ENTER_PASSPHRASE;
|
|
|
|
result = "Y";
|
|
|
|
}
|
|
|
|
else if (status == GPGME_STATUS_GET_LINE &&
|
|
|
|
(!std::string("keyedit.prompt").compare(args)))
|
|
|
|
{
|
|
|
|
/* Failed sign: expired key */
|
|
|
|
params->state = SIGN_ERROR;
|
|
|
|
params->err = gpg_error (GPG_ERR_UNUSABLE_PUBKEY);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
params->state = SIGN_ERROR;
|
|
|
|
params->err = gpg_error (GPG_ERR_GENERAL);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SIGN_SET_EXPIRE:
|
2010-04-25 15:26:37 -04:00
|
|
|
#ifdef GPG_DEBUG
|
2009-05-25 07:38:47 -04:00
|
|
|
fprintf(stderr,"keySignCallback SIGN_SET_EXPIRE\n");
|
2010-04-25 15:26:37 -04:00
|
|
|
#endif
|
2009-05-25 07:38:47 -04:00
|
|
|
|
2009-05-23 13:40:35 -04:00
|
|
|
if (status == GPGME_STATUS_GET_LINE &&
|
|
|
|
(!std::string("sign_uid.class").compare(args)))
|
|
|
|
{
|
|
|
|
params->state = SIGN_SET_CHECK_LEVEL;
|
|
|
|
result = sparams->checkLvl.c_str();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
params->state = SIGN_ERROR;
|
|
|
|
params->err = gpg_error (GPG_ERR_GENERAL);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SIGN_SET_CHECK_LEVEL:
|
2010-04-25 15:26:37 -04:00
|
|
|
#ifdef GPG_DEBUG
|
2009-05-25 07:38:47 -04:00
|
|
|
fprintf(stderr,"keySignCallback SIGN_SET_CHECK_LEVEL\n");
|
2010-04-25 15:26:37 -04:00
|
|
|
#endif
|
2009-05-25 07:38:47 -04:00
|
|
|
|
2009-05-23 13:40:35 -04:00
|
|
|
if (status == GPGME_STATUS_GET_BOOL &&
|
|
|
|
(!std::string("sign_uid.okay").compare(args)))
|
|
|
|
{
|
|
|
|
params->state = SIGN_ENTER_PASSPHRASE;
|
|
|
|
result = "Y";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
params->state = SIGN_ERROR;
|
|
|
|
params->err = gpg_error (GPG_ERR_GENERAL);
|
|
|
|
}
|
|
|
|
break;
|
2010-01-13 16:08:46 -05:00
|
|
|
case SIGN_ENTER_PASSPHRASE:
|
2010-04-25 15:26:37 -04:00
|
|
|
#ifdef GPG_DEBUG
|
2010-01-13 16:08:46 -05:00
|
|
|
fprintf(stderr,"keySignCallback SIGN_ENTER_PASSPHRASE\n");
|
2010-04-25 15:26:37 -04:00
|
|
|
#endif
|
2010-01-13 16:08:46 -05:00
|
|
|
|
|
|
|
if (status == GPGME_STATUS_GOOD_PASSPHRASE)
|
|
|
|
{
|
|
|
|
params->state = SIGN_CONFIRM;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
params->state = SIGN_ERROR;
|
|
|
|
params->err = gpg_error (GPG_ERR_GENERAL);
|
|
|
|
}
|
|
|
|
break;
|
2009-05-23 13:40:35 -04:00
|
|
|
case SIGN_CONFIRM:
|
2010-04-25 15:26:37 -04:00
|
|
|
#ifdef GPG_DEBUG
|
2009-05-25 07:38:47 -04:00
|
|
|
fprintf(stderr,"keySignCallback SIGN_CONFIRM\n");
|
2010-04-25 15:26:37 -04:00
|
|
|
#endif
|
2009-05-25 07:38:47 -04:00
|
|
|
|
2009-05-23 13:40:35 -04:00
|
|
|
if (status == GPGME_STATUS_GET_LINE &&
|
|
|
|
(!std::string("keyedit.prompt").compare(args)))
|
|
|
|
{
|
|
|
|
params->state = SIGN_QUIT;
|
|
|
|
result = "quit";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
params->state = SIGN_ERROR;
|
|
|
|
params->err = gpg_error (GPG_ERR_GENERAL);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SIGN_QUIT:
|
2010-04-25 15:26:37 -04:00
|
|
|
#ifdef GPG_DEBUG
|
2009-05-25 07:38:47 -04:00
|
|
|
fprintf(stderr,"keySignCallback SIGN_QUIT\n");
|
2010-04-25 15:26:37 -04:00
|
|
|
#endif
|
2009-05-25 07:38:47 -04:00
|
|
|
|
2009-05-23 13:40:35 -04:00
|
|
|
if (status == GPGME_STATUS_GET_BOOL &&
|
|
|
|
(!std::string("keyedit.save.okay").compare(args)))
|
|
|
|
{
|
|
|
|
params->state = SIGN_SAVE;
|
|
|
|
result = "Y";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
params->state = SIGN_ERROR;
|
|
|
|
params->err = gpg_error (GPG_ERR_GENERAL);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SIGN_ERROR:
|
2010-04-25 15:26:37 -04:00
|
|
|
#ifdef GPG_DEBUG
|
2009-05-25 07:38:47 -04:00
|
|
|
fprintf(stderr,"keySignCallback SIGN_ERROR\n");
|
2010-04-25 15:26:37 -04:00
|
|
|
#endif
|
2009-05-25 07:38:47 -04:00
|
|
|
|
2009-05-23 13:40:35 -04:00
|
|
|
if (status == GPGME_STATUS_GET_LINE &&
|
|
|
|
(!std::string("keyedit.prompt").compare(args)))
|
|
|
|
{
|
|
|
|
/* Go to quit operation state */
|
|
|
|
params->state = SIGN_QUIT;
|
|
|
|
result = "quit";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
params->state = SIGN_ERROR;
|
|
|
|
params->err = gpg_error (GPG_ERR_GENERAL);
|
|
|
|
}
|
|
|
|
break;
|
2009-05-25 07:38:47 -04:00
|
|
|
default:
|
|
|
|
fprintf(stderr,"keySignCallback UNKNOWN state\n");
|
|
|
|
break;
|
2009-05-23 13:40:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (result)
|
2010-01-24 08:59:22 -05:00
|
|
|
{
|
2010-04-25 15:26:37 -04:00
|
|
|
#ifdef GPG_DEBUG
|
2009-05-25 07:38:47 -04:00
|
|
|
fprintf(stderr,"keySignCallback result:%s\n", result);
|
2010-04-25 15:26:37 -04:00
|
|
|
#endif
|
2009-07-30 10:36:42 -04:00
|
|
|
#ifndef WINDOWS_SYS
|
2009-05-23 13:40:35 -04:00
|
|
|
if (*result)
|
2010-01-24 08:59:22 -05:00
|
|
|
{
|
2009-05-23 13:40:35 -04:00
|
|
|
write (fd, result, strlen (result));
|
2010-01-24 08:59:22 -05:00
|
|
|
write (fd, "\n", 1);
|
|
|
|
}
|
2009-07-30 10:36:42 -04:00
|
|
|
#else
|
|
|
|
DWORD written = 0;
|
|
|
|
HANDLE winFd = (HANDLE) fd;
|
|
|
|
if (*result)
|
2010-01-24 08:59:22 -05:00
|
|
|
{
|
2009-07-30 10:36:42 -04:00
|
|
|
WriteFile(winFd, result, strlen(result), &written, NULL);
|
2010-01-24 08:59:22 -05:00
|
|
|
WriteFile(winFd, "\n", 1, &written, NULL);
|
|
|
|
}
|
2009-07-30 10:36:42 -04:00
|
|
|
#endif
|
|
|
|
|
2010-01-24 08:59:22 -05:00
|
|
|
}
|
2009-05-23 13:40:35 -04:00
|
|
|
|
2009-05-25 07:38:47 -04:00
|
|
|
fprintf(stderr,"keySignCallback Error status\n");
|
2011-08-12 16:02:00 -04:00
|
|
|
std::cerr << ProcessPGPmeError(params->err) << std::endl;
|
2009-05-25 07:38:47 -04:00
|
|
|
|
2009-05-23 13:40:35 -04:00
|
|
|
return params->err;
|
|
|
|
}
|
2012-04-08 10:52:01 -04:00
|
|
|
#endif
|
2009-05-23 13:40:35 -04:00
|
|
|
|
|
|
|
|
2012-04-08 10:52:01 -04:00
|
|
|
#ifdef TO_REMOVE
|
2009-05-23 13:40:35 -04:00
|
|
|
/* Callback function for assigning trust level */
|
|
|
|
|
|
|
|
static gpgme_error_t trustCallback(void *opaque, gpgme_status_code_t status, \
|
|
|
|
const char *args, int fd) {
|
|
|
|
|
2010-01-13 16:14:49 -05:00
|
|
|
class EditParams *params = (class EditParams *)opaque;
|
|
|
|
class TrustParams *tparams = (class TrustParams *)params->oParams;
|
|
|
|
const char *result = NULL;
|
|
|
|
|
|
|
|
/* printf stuff out */
|
2010-04-25 15:26:37 -04:00
|
|
|
#ifdef GPG_DEBUG
|
2010-01-13 16:14:49 -05:00
|
|
|
if (status == GPGME_STATUS_EOF)
|
|
|
|
fprintf(stderr,"keySignCallback GPGME_STATUS_EOF\n");
|
|
|
|
if (status == GPGME_STATUS_GOT_IT)
|
|
|
|
fprintf(stderr,"keySignCallback GPGME_STATUS_GOT_IT\n");
|
|
|
|
if (status == GPGME_STATUS_USERID_HINT)
|
|
|
|
fprintf(stderr,"keySignCallback GPGME_STATUS_USERID_HINT\n");
|
|
|
|
if (status == GPGME_STATUS_NEED_PASSPHRASE)
|
|
|
|
fprintf(stderr,"keySignCallback GPGME_STATUS_NEED_PASSPHRASE\n");
|
|
|
|
if (status == GPGME_STATUS_GOOD_PASSPHRASE)
|
|
|
|
fprintf(stderr,"keySignCallback GPGME_STATUS_GOOD_PASSPHRASE\n");
|
|
|
|
if (status == GPGME_STATUS_BAD_PASSPHRASE)
|
|
|
|
fprintf(stderr,"keySignCallback GPGME_STATUS_BAD_PASSPHRASE\n");
|
|
|
|
if (status == GPGME_STATUS_GET_LINE)
|
|
|
|
fprintf(stderr,"keySignCallback GPGME_STATUS_GET_LINE\n");
|
|
|
|
if (status == GPGME_STATUS_GET_BOOL)
|
|
|
|
fprintf(stderr,"keySignCallback GPGME_STATUS_GET_BOOL \n");
|
|
|
|
if (status == GPGME_STATUS_ALREADY_SIGNED)
|
|
|
|
fprintf(stderr,"keySignCallback GPGME_STATUS_ALREADY_SIGNED\n");
|
|
|
|
|
|
|
|
/* printf stuff out */
|
|
|
|
if (params->state == TRUST_START)
|
|
|
|
fprintf(stderr,"keySignCallback params->state TRUST_START\n");
|
|
|
|
if (params->state == TRUST_COMMAND)
|
|
|
|
fprintf(stderr,"keySignCallback params->state TRUST_COMMAND\n");
|
|
|
|
if (params->state == TRUST_VALUE)
|
|
|
|
fprintf(stderr,"keySignCallback params->state TRUST_VALUE\n");
|
|
|
|
if (params->state == TRUST_REALLY_ULTIMATE)
|
|
|
|
fprintf(stderr,"keySignCallback params->state TRUST_REALLY_ULTIMATE\n");
|
|
|
|
if (params->state == TRUST_QUIT)
|
|
|
|
fprintf(stderr,"keySignCallback params->state TRUST_QUIT\n");
|
|
|
|
if (params->state == TRUST_ERROR)
|
|
|
|
fprintf(stderr,"keySignCallback params->state TRUST_ERROR\n");
|
2010-04-25 15:26:37 -04:00
|
|
|
#endif
|
2010-01-13 16:14:49 -05:00
|
|
|
|
2009-05-23 13:40:35 -04:00
|
|
|
|
|
|
|
if(status == GPGME_STATUS_EOF ||
|
|
|
|
status == GPGME_STATUS_GOT_IT) {
|
|
|
|
return params->err;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
switch (params->state)
|
|
|
|
{
|
|
|
|
case TRUST_START:
|
|
|
|
if (status == GPGME_STATUS_GET_LINE &&
|
|
|
|
(!std::string("keyedit.prompt").compare(args))) {
|
|
|
|
params->state = TRUST_COMMAND;
|
|
|
|
result = "trust";
|
|
|
|
} else {
|
|
|
|
params->state = TRUST_ERROR;
|
|
|
|
params->err = gpg_error (GPG_ERR_GENERAL);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TRUST_COMMAND:
|
|
|
|
if (status == GPGME_STATUS_GET_LINE &&
|
|
|
|
(!std::string("edit_ownertrust.value").compare(args))) {
|
|
|
|
params->state = TRUST_VALUE;
|
2010-01-13 16:14:49 -05:00
|
|
|
result = tparams->trustLvl.c_str();;
|
2009-05-23 13:40:35 -04:00
|
|
|
} else {
|
|
|
|
params->state = TRUST_ERROR;
|
|
|
|
params->err = gpg_error (GPG_ERR_GENERAL);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TRUST_VALUE:
|
|
|
|
if (status == GPGME_STATUS_GET_LINE &&
|
|
|
|
(!std::string("keyedit.prompt").compare(args))) {
|
|
|
|
params->state = TRUST_QUIT;
|
|
|
|
result = "quit";
|
|
|
|
}
|
|
|
|
else if (status == GPGME_STATUS_GET_BOOL &&
|
|
|
|
(!std::string("edit_ownertrust.set_ultimate.okay").compare(args))) {
|
|
|
|
params->state = TRUST_REALLY_ULTIMATE;
|
|
|
|
result = "Y";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
params->state = TRUST_ERROR;
|
|
|
|
params->err = gpg_error (GPG_ERR_GENERAL);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TRUST_REALLY_ULTIMATE:
|
|
|
|
if (status == GPGME_STATUS_GET_LINE &&
|
|
|
|
(!std::string("keyedit.prompt").compare(args))) {
|
|
|
|
params->state = TRUST_QUIT;
|
|
|
|
result = "quit";
|
|
|
|
} else {
|
|
|
|
params->state = TRUST_ERROR;
|
|
|
|
params->err = gpg_error (GPG_ERR_GENERAL);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TRUST_QUIT:
|
|
|
|
if (status == GPGME_STATUS_GET_BOOL &&
|
|
|
|
(!std::string("keyedit.save.okay").compare(args))) {
|
|
|
|
params->state = TRUST_SAVE;
|
|
|
|
result = "Y";
|
|
|
|
} else {
|
|
|
|
params->state = TRUST_ERROR;
|
|
|
|
params->err = gpg_error (GPG_ERR_GENERAL);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TRUST_ERROR:
|
|
|
|
if (status == GPGME_STATUS_GET_LINE &&
|
|
|
|
(!std::string("keyedit.prompt").compare(args))) {
|
|
|
|
/* Go to quit operation state */
|
|
|
|
params->state = TRUST_QUIT;
|
|
|
|
result = "quit";
|
|
|
|
} else {
|
|
|
|
params->state = TRUST_ERROR;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result)
|
|
|
|
{
|
2009-07-30 10:36:42 -04:00
|
|
|
#ifndef WINDOWS_SYS
|
2009-05-23 13:40:35 -04:00
|
|
|
if (*result)
|
|
|
|
write (fd, result, strlen (result));
|
|
|
|
write (fd, "\n", 1);
|
2009-07-30 10:36:42 -04:00
|
|
|
#else
|
|
|
|
DWORD written = 0;
|
|
|
|
HANDLE winFd = (HANDLE) fd;
|
|
|
|
if (*result)
|
|
|
|
WriteFile(winFd, result, strlen (result), &written, NULL);
|
|
|
|
WriteFile(winFd, "\n", 1, &written, NULL);
|
|
|
|
#endif
|
2010-01-21 18:01:48 -05:00
|
|
|
#ifdef GPG_DEBUG
|
2010-01-13 16:14:49 -05:00
|
|
|
std::cerr << "trustCallback() result : " << result << std::endl;
|
2010-01-21 18:01:48 -05:00
|
|
|
#endif
|
2009-05-23 13:40:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return params->err;
|
|
|
|
}
|
2012-04-08 10:52:01 -04:00
|
|
|
#endif
|
2010-01-13 16:26:30 -05:00
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------------//
|
|
|
|
// -------------------------------- Config functions ------------------------------ //
|
|
|
|
// -----------------------------------------------------------------------------------//
|
|
|
|
//
|
2012-04-08 10:52:01 -04:00
|
|
|
RsSerialiser *AuthGPG::setupSerialiser()
|
2010-01-13 16:26:30 -05:00
|
|
|
{
|
|
|
|
RsSerialiser *rss = new RsSerialiser ;
|
|
|
|
rss->addSerialType(new RsGeneralConfigSerialiser());
|
|
|
|
return rss ;
|
|
|
|
}
|
|
|
|
|
2012-04-08 10:52:01 -04:00
|
|
|
bool AuthGPG::saveList(bool& cleanup, std::list<RsItem*>& lst)
|
2010-01-13 16:26:30 -05:00
|
|
|
{
|
2012-04-08 10:52:01 -04:00
|
|
|
#ifdef GPG_DEBUG
|
|
|
|
std::cerr << "AuthGPG::saveList() called" << std::endl ;
|
|
|
|
#endif
|
2012-06-12 17:19:38 -04:00
|
|
|
std::list<std::string> ids ;
|
|
|
|
getGPGAcceptedList(ids) ; // needs to be done before the lock
|
2010-01-21 17:04:20 -05:00
|
|
|
|
2012-04-08 10:52:01 -04:00
|
|
|
RsStackMutex stack(gpgMtxData); /******* LOCKED ******/
|
2010-01-21 17:04:20 -05:00
|
|
|
|
2012-04-08 10:52:01 -04:00
|
|
|
cleanup = true ;
|
2010-01-21 17:04:20 -05:00
|
|
|
|
2012-04-08 10:52:01 -04:00
|
|
|
// Now save config for network digging strategies
|
|
|
|
RsConfigKeyValueSet *vitem = new RsConfigKeyValueSet ;
|
2012-04-09 13:03:47 -04:00
|
|
|
|
|
|
|
for (std::list<std::string>::const_iterator it(ids.begin()); it != ids.end(); ++it)
|
|
|
|
if((*it) != mOwnGpgId.toStdString()) // skip our own id.
|
2011-08-07 17:11:00 -04:00
|
|
|
{
|
2012-04-09 13:03:47 -04:00
|
|
|
RsTlvKeyValue kv;
|
2012-06-12 17:19:38 -04:00
|
|
|
kv.key = *it ;
|
2011-08-07 17:11:00 -04:00
|
|
|
#ifdef GPG_DEBUG
|
2012-06-12 17:19:38 -04:00
|
|
|
std::cerr << "AuthGPG::saveList() called (it->second) : " << (it->second) << std::endl ;
|
2011-08-07 17:11:00 -04:00
|
|
|
#endif
|
2012-04-09 13:03:47 -04:00
|
|
|
kv.value = "TRUE";
|
|
|
|
vitem->tlvkvs.pairs.push_back(kv) ;
|
|
|
|
}
|
2012-04-08 10:52:01 -04:00
|
|
|
lst.push_back(vitem);
|
2010-01-13 16:26:30 -05:00
|
|
|
|
2012-04-08 10:52:01 -04:00
|
|
|
return true;
|
2010-01-13 16:26:30 -05:00
|
|
|
}
|
|
|
|
|
2012-04-08 10:52:01 -04:00
|
|
|
bool AuthGPG::loadList(std::list<RsItem*>& load)
|
2010-01-13 16:26:30 -05:00
|
|
|
{
|
2012-04-09 13:03:47 -04:00
|
|
|
#ifdef GPG_DEBUG
|
|
|
|
std::cerr << "AuthGPG::loadList() Item Count: " << load.size() << std::endl;
|
|
|
|
#endif
|
2010-01-13 16:26:30 -05:00
|
|
|
|
2012-04-09 13:03:47 -04:00
|
|
|
RsStackMutex stack(gpgMtxData); /******* LOCKED ******/
|
|
|
|
/* load the list of accepted gpg keys */
|
|
|
|
std::list<RsItem *>::iterator it;
|
|
|
|
for(it = load.begin(); it != load.end(); it++)
|
2011-08-07 17:11:00 -04:00
|
|
|
{
|
|
|
|
RsConfigKeyValueSet *vitem = dynamic_cast<RsConfigKeyValueSet *>(*it);
|
|
|
|
if(vitem)
|
|
|
|
{
|
|
|
|
#ifdef GPG_DEBUG
|
2012-04-08 10:52:01 -04:00
|
|
|
std::cerr << "AuthGPG::loadList() General Variable Config Item:" << std::endl;
|
2011-08-07 17:11:00 -04:00
|
|
|
vitem->print(std::cerr, 10);
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
std::list<RsTlvKeyValue>::iterator kit;
|
|
|
|
for(kit = vitem->tlvkvs.pairs.begin(); kit != vitem->tlvkvs.pairs.end(); kit++)
|
2012-04-09 13:03:47 -04:00
|
|
|
if (kit->key != mOwnGpgId.toStdString())
|
2012-06-09 14:45:35 -04:00
|
|
|
PGPHandler::setAcceptConnexion(PGPIdType(kit->key), (kit->value == "TRUE"));
|
2012-04-09 13:03:47 -04:00
|
|
|
}
|
|
|
|
delete (*it);
|
|
|
|
}
|
|
|
|
return true;
|
2010-01-13 16:26:30 -05:00
|
|
|
}
|
2010-04-08 15:08:41 -04:00
|
|
|
|
2012-04-08 10:52:01 -04:00
|
|
|
bool AuthGPG::addService(AuthGPGService *service)
|
2010-10-13 12:15:26 -04:00
|
|
|
{
|
2012-04-09 13:03:47 -04:00
|
|
|
RsStackMutex stack(gpgMtxService); /********* LOCKED *********/
|
2010-10-13 12:15:26 -04:00
|
|
|
|
2012-04-09 13:03:47 -04:00
|
|
|
if (std::find(services.begin(), services.end(), service) != services.end()) {
|
|
|
|
/* it exists already! */
|
|
|
|
return false;
|
|
|
|
}
|
2010-10-13 12:15:26 -04:00
|
|
|
|
2012-04-09 13:03:47 -04:00
|
|
|
services.push_back(service);
|
|
|
|
return true;
|
2010-10-13 12:15:26 -04:00
|
|
|
}
|
2011-01-23 06:57:09 -05:00
|
|
|
|
2012-04-09 13:03:47 -04:00
|
|
|
#ifdef TO_REMOVE
|
2011-01-23 06:57:09 -05:00
|
|
|
|
|
|
|
/***************************** HACK to Cleanup OSX Zombies *****************************/
|
|
|
|
|
|
|
|
|
2011-01-23 07:37:42 -05:00
|
|
|
#ifdef __APPLE__
|
2011-01-23 06:57:09 -05:00
|
|
|
#include <sys/wait.h>
|
2011-01-23 07:37:42 -05:00
|
|
|
#endif
|
2011-01-23 06:57:09 -05:00
|
|
|
|
|
|
|
void cleanupZombies(int numkill)
|
|
|
|
{
|
|
|
|
|
|
|
|
#ifdef __APPLE__
|
|
|
|
|
|
|
|
pid_t wpid = -1; // any child.
|
|
|
|
int stat_loc = 0;
|
|
|
|
int options = WNOHANG ;
|
|
|
|
|
|
|
|
//std::cerr << "cleanupZombies() checking for dead children";
|
|
|
|
//std::cerr << std::endl;
|
|
|
|
|
|
|
|
int i;
|
|
|
|
for(i = 0; i < numkill; i++)
|
|
|
|
{
|
|
|
|
pid_t childpid = waitpid(wpid, &stat_loc, options);
|
|
|
|
|
|
|
|
if (childpid > 0)
|
|
|
|
{
|
|
|
|
std::cerr << "cleanupZombies() Found stopped child with pid: " << childpid;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//std::cerr << "cleanupZombies() No Zombies around!";
|
|
|
|
//std::cerr << std::endl;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-29 13:08:39 -04:00
|
|
|
//std::cerr << "cleanupZombies() Killed " << i << " zombies";
|
|
|
|
//std::cerr << std::endl;
|
2011-08-12 09:42:30 -04:00
|
|
|
#else
|
|
|
|
/* remove unused parameter warnings */
|
|
|
|
(void) numkill;
|
2011-01-23 06:57:09 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2012-04-08 10:52:01 -04:00
|
|
|
#endif
|