removed getAuthGPG and replaced AuthGPG with a class with static members

This commit is contained in:
csoler 2021-08-14 14:56:28 +02:00
parent b8f4e64393
commit b084b20280
14 changed files with 266 additions and 218 deletions

View File

@ -107,7 +107,7 @@ p3discovery2::p3discovery2(
addSerialType(new RsDiscSerialiser()); addSerialType(new RsDiscSerialiser());
// Add self into PGP FriendList. // Add self into PGP FriendList.
mFriendList[AuthGPG::getAuthGPG()->getGPGOwnId()] = DiscPgpInfo(); mFriendList[AuthGPG::getGPGOwnId()] = DiscPgpInfo();
} }
@ -219,7 +219,7 @@ void p3discovery2::removeFriend(const RsPeerId &sslId)
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
/* pgp peer without any ssl entries -> check if they are still a real friend */ /* pgp peer without any ssl entries -> check if they are still a real friend */
if (!(AuthGPG::getAuthGPG()->isGPGAccepted(pgpId))) if (!(AuthGPG::isGPGAccepted(pgpId)))
{ {
#ifdef P3DISC_DEBUG #ifdef P3DISC_DEBUG
std::cerr << "p3discovery2::addFriend() pgpId is no longer a friend, removing"; std::cerr << "p3discovery2::addFriend() pgpId is no longer a friend, removing";
@ -604,8 +604,8 @@ void p3discovery2::updatePgpFriendList()
std::list<RsPgpId>::iterator lit; std::list<RsPgpId>::iterator lit;
std::map<RsPgpId, DiscPgpInfo>::iterator it; std::map<RsPgpId, DiscPgpInfo>::iterator it;
RsPgpId ownPgpId = AuthGPG::getAuthGPG()->getGPGOwnId(); RsPgpId ownPgpId = AuthGPG::getGPGOwnId();
AuthGPG::getAuthGPG()->getGPGAcceptedList(pgpList); AuthGPG::getGPGAcceptedList(pgpList);
pgpList.push_back(ownPgpId); pgpList.push_back(ownPgpId);
// convert to set for ordering. // convert to set for ordering.
@ -723,7 +723,7 @@ void p3discovery2::processPGPList(const RsPeerId &fromId, const RsDiscPgpListIte
std::set<RsPgpId>::const_iterator fit; std::set<RsPgpId>::const_iterator fit;
for(fit = item->pgpIdSet.ids.begin(); fit != item->pgpIdSet.ids.end(); ++fit) for(fit = item->pgpIdSet.ids.begin(); fit != item->pgpIdSet.ids.end(); ++fit)
{ {
if (!AuthGPG::getAuthGPG()->isGPGId(*fit)) if (!AuthGPG::isPGPId(*fit))
{ {
#ifdef P3DISC_DEBUG #ifdef P3DISC_DEBUG
std::cerr << "p3discovery2::processPGPList() requesting certificate for PgpId: " << *fit; std::cerr << "p3discovery2::processPGPList() requesting certificate for PgpId: " << *fit;
@ -1058,11 +1058,11 @@ void p3discovery2::recvPGPCertificateRequest( const RsPeerId& fromId, const RsDi
return; return;
} }
RsPgpId ownPgpId = AuthGPG::getAuthGPG()->getGPGOwnId(); RsPgpId ownPgpId = AuthGPG::getGPGOwnId();
for(const RsPgpId& pgpId : item->pgpIdSet.ids) for(const RsPgpId& pgpId : item->pgpIdSet.ids)
if (pgpId == ownPgpId) if (pgpId == ownPgpId)
sendPGPCertificate(pgpId, fromId); sendPGPCertificate(pgpId, fromId);
else if(ps.vs_disc != RS_VS_DISC_OFF && AuthGPG::getAuthGPG()->isGPGAccepted(pgpId)) else if(ps.vs_disc != RS_VS_DISC_OFF && AuthGPG::isGPGAccepted(pgpId))
sendPGPCertificate(pgpId, fromId); sendPGPCertificate(pgpId, fromId);
else else
std::cerr << "(WW) not sending certificate " << pgpId << " asked by friend " << fromId << " because this either this cert is not a friend, or discovery is off" << std::endl; std::cerr << "(WW) not sending certificate " << pgpId << " asked by friend " << fromId << " because this either this cert is not a friend, or discovery is off" << std::endl;
@ -1078,7 +1078,7 @@ void p3discovery2::sendPGPCertificate(const RsPgpId &aboutId, const RsPeerId &to
unsigned char *bin_data; unsigned char *bin_data;
size_t bin_len; size_t bin_len;
if(!AuthGPG::getAuthGPG()->exportPublicKey(aboutId,bin_data,bin_len,false,true)) if(!AuthGPG::exportPublicKey(aboutId,bin_data,bin_len,false,true))
{ {
std::cerr << "(EE) cannot export public key " << aboutId << " requested by peer " << toId << std::endl; std::cerr << "(EE) cannot export public key " << aboutId << " requested by peer " << toId << std::endl;
return ; return ;
@ -1098,7 +1098,7 @@ void p3discovery2::recvPGPCertificate(const RsPeerId& fromId, RsDiscPgpKeyItem*
std::string cert_name; std::string cert_name;
std::list<RsPgpId> cert_signers; std::list<RsPgpId> cert_signers;
if(!AuthGPG::getAuthGPG()->getGPGDetailsFromBinaryBlock( (unsigned char*)item->bin_data,item->bin_len, cert_pgp_id, cert_name, cert_signers )) if(!AuthGPG::getGPGDetailsFromBinaryBlock( (unsigned char*)item->bin_data,item->bin_len, cert_pgp_id, cert_name, cert_signers ))
{ {
std::cerr << "(EE) cannot parse own PGP key sent by " << fromId << std::endl; std::cerr << "(EE) cannot parse own PGP key sent by " << fromId << std::endl;
return; return;
@ -1147,7 +1147,7 @@ void p3discovery2::recvPGPCertificate(const RsPeerId& fromId, RsDiscPgpKeyItem*
// otherwise the connection should already be accepted. This only happens when the short invite peer sends its own PGP key. // otherwise the connection should already be accepted. This only happens when the short invite peer sends its own PGP key.
if(det.skip_pgp_signature_validation) if(det.skip_pgp_signature_validation)
AuthGPG::getAuthGPG()->AllowConnection(det.gpg_id,true); AuthGPG::AllowConnection(det.gpg_id,true);
} }
/************* from pqiServiceMonitor *******************/ /************* from pqiServiceMonitor *******************/

View File

@ -34,7 +34,7 @@ PgpAuxUtilsImpl::PgpAuxUtilsImpl()
const RsPgpId& PgpAuxUtilsImpl::getPGPOwnId() const RsPgpId& PgpAuxUtilsImpl::getPGPOwnId()
{ {
return AuthGPG::getAuthGPG()->getGPGOwnId(); return AuthGPG::getGPGOwnId();
} }
RsPgpId PgpAuxUtilsImpl::getPGPId(const RsPeerId& sslid) RsPgpId PgpAuxUtilsImpl::getPGPId(const RsPeerId& sslid)
@ -44,7 +44,7 @@ RsPgpId PgpAuxUtilsImpl::getPGPId(const RsPeerId& sslid)
bool PgpAuxUtilsImpl::getKeyFingerprint(const RsPgpId& id,PGPFingerprintType& fp) const bool PgpAuxUtilsImpl::getKeyFingerprint(const RsPgpId& id,PGPFingerprintType& fp) const
{ {
return AuthGPG::getAuthGPG()->getKeyFingerprint(id, fp); return AuthGPG::getKeyFingerprint(id, fp);
} }
bool PgpAuxUtilsImpl::VerifySignBin(const void *data, bool PgpAuxUtilsImpl::VerifySignBin(const void *data,
@ -54,17 +54,17 @@ bool PgpAuxUtilsImpl::VerifySignBin(const void *data,
const PGPFingerprintType& withfingerprint) const PGPFingerprintType& withfingerprint)
{ {
return AuthGPG::getAuthGPG()->VerifySignBin(data, len, sign, signlen, withfingerprint); return AuthGPG::VerifySignBin(data, len, sign, signlen, withfingerprint);
} }
bool PgpAuxUtilsImpl::getGPGAllList(std::list<RsPgpId> &ids) bool PgpAuxUtilsImpl::getGPGAllList(std::list<RsPgpId> &ids)
{ {
return AuthGPG::getAuthGPG()->getGPGAllList(ids); return AuthGPG::getGPGAllList(ids);
} }
bool PgpAuxUtilsImpl::parseSignature(unsigned char *sign, unsigned int signlen, RsPgpId& issuer) const bool PgpAuxUtilsImpl::parseSignature(unsigned char *sign, unsigned int signlen, RsPgpId& issuer) const
{ {
return AuthGPG::getAuthGPG()->parseSignature(sign,signlen,issuer); return AuthGPG::parseSignature(sign,signlen,issuer);
} }

View File

@ -54,9 +54,21 @@ void cleanupZombies(int numkill); // function to cleanup zombies under OSX.
/* Function to sign X509_REQ via GPGme. */ /* Function to sign X509_REQ via GPGme. */
int AuthGPG::availableGPGCertificatesWithPrivateKeys(std::list<RsPgpId>& pgpIds)
{
return instance()->mPgpHandler->availableGPGCertificatesWithPrivateKeys(pgpIds);
}
bool AuthGPG::getGPGDetailsFromBinaryBlock(const unsigned char *mem,size_t mem_size,RsPgpId& key_id, std::string& name, std::list<RsPgpId>& signers)
{
return instance()->mPgpHandler->getGPGDetailsFromBinaryBlock(mem,mem_size,key_id,name,signers);
}
void AuthGPG::registerToConfigMgr(const std::string& fname,p3ConfigMgr *CfgMgr)
{
CfgMgr->addConfiguration(fname, instance());
}
bool AuthGPG::decryptTextFromFile(std::string& text,const std::string& inputfile) bool AuthGPG::decryptTextFromFile(std::string& text,const std::string& inputfile)
{ {
return PGPHandler::decryptTextFromFile(mOwnGpgId,text,inputfile) ; return instance()->mPgpHandler->decryptTextFromFile(instance()->mOwnGpgId,text,inputfile) ;
} }
bool AuthGPG::removeKeysFromPGPKeyring(const std::set<RsPgpId>& pgp_ids,std::string& backup_file,uint32_t& error_code) bool AuthGPG::removeKeysFromPGPKeyring(const std::set<RsPgpId>& pgp_ids,std::string& backup_file,uint32_t& error_code)
@ -66,22 +78,22 @@ bool AuthGPG::removeKeysFromPGPKeyring(const std::set<RsPgpId>& pgp_ids,std::str
// for(std::list<RsPgpId>::const_iterator it(pgp_ids.begin());it!=pgp_ids.end();++it) // for(std::list<RsPgpId>::const_iterator it(pgp_ids.begin());it!=pgp_ids.end();++it)
// pids.push_back(RsPgpId(*it)) ; // pids.push_back(RsPgpId(*it)) ;
return PGPHandler::removeKeysFromPGPKeyring(pgp_ids,backup_file,error_code) ; return instance()->mPgpHandler->removeKeysFromPGPKeyring(pgp_ids,backup_file,error_code) ;
} }
// bool AuthGPG::decryptTextFromString(std::string& encrypted_text,std::string& output) // bool AuthGPG::decryptTextFromString(std::string& encrypted_text,std::string& output)
// { // {
// return PGPHandler::decryptTextFromString(mOwnGpgId,encrypted_text,output) ; // return instance()->mPgpHandler->decryptTextFromString(mOwnGpgId,encrypted_text,output) ;
// } // }
bool AuthGPG::encryptTextToFile(const std::string& text,const std::string& outfile) bool AuthGPG::encryptTextToFile(const std::string& text,const std::string& outfile)
{ {
return PGPHandler::encryptTextToFile(mOwnGpgId,text,outfile) ; return instance()->mPgpHandler->encryptTextToFile(instance()->mOwnGpgId,text,outfile) ;
} }
// bool AuthGPG::encryptTextToString(const std::string& pgp_id,const std::string& text,std::string& outstr) // bool AuthGPG::encryptTextToString(const std::string& pgp_id,const std::string& text,std::string& outstr)
// { // {
// return PGPHandler::encryptTextToString(RsPgpId(pgp_id),text,outstr) ; // return instance()->mPgpHandler->encryptTextToString(RsPgpId(pgp_id),text,outstr) ;
// } // }
std::string pgp_pwd_callback(void * /*hook*/, const char *uid_title, const char *uid_hint, const char * /*passphrase_info*/, int prev_was_bad,bool *cancelled) std::string pgp_pwd_callback(void * /*hook*/, const char *uid_title, const char *uid_hint, const char * /*passphrase_info*/, int prev_was_bad,bool *cancelled)
@ -107,8 +119,8 @@ void AuthGPG::init(
std::cerr << "AuthGPG::init() called twice!" << std::endl ; std::cerr << "AuthGPG::init() called twice!" << std::endl ;
} }
// if(cb) PGPHandler::setPassphraseCallback(cb);else // if(cb) instance()->mPgpHandler->setPassphraseCallback(cb);else
PGPHandler::setPassphraseCallback(pgp_pwd_callback); instance()->mPgpHandler->setPassphraseCallback(pgp_pwd_callback);
_instance = new AuthGPG( path_to_public_keyring, _instance = new AuthGPG( path_to_public_keyring,
path_to_secret_keyring, path_to_secret_keyring,
path_to_trustdb, pgp_lock_file ); path_to_trustdb, pgp_lock_file );
@ -126,7 +138,6 @@ void AuthGPG::exit()
AuthGPG::AuthGPG(const std::string& path_to_public_keyring,const std::string& path_to_secret_keyring,const std::string& path_to_trustdb,const std::string& pgp_lock_file) AuthGPG::AuthGPG(const std::string& path_to_public_keyring,const std::string& path_to_secret_keyring,const std::string& path_to_trustdb,const std::string& pgp_lock_file)
:p3Config(), :p3Config(),
OpenPGPSDKHandler(path_to_public_keyring,path_to_secret_keyring,path_to_trustdb,pgp_lock_file),
gpgMtxService("AuthGPG-service"), gpgMtxService("AuthGPG-service"),
gpgMtxEngine("AuthGPG-engine"), gpgMtxEngine("AuthGPG-engine"),
gpgMtxData("AuthGPG-data"), gpgMtxData("AuthGPG-data"),
@ -135,7 +146,9 @@ AuthGPG::AuthGPG(const std::string& path_to_public_keyring,const std::string& pa
_force_sync_database(false), _force_sync_database(false),
mCount(0) mCount(0)
{ {
start("AuthGPG"); mPgpHandler = new OpenPGPSDKHandler(path_to_public_keyring,path_to_secret_keyring,path_to_trustdb,pgp_lock_file);
start("AuthGPG");
} }
/* This function is called when retroshare is first started /* This function is called when retroshare is first started
@ -149,7 +162,7 @@ AuthGPG::AuthGPG(const std::string& path_to_public_keyring,const std::string& pa
//{ //{
// std::list<RsPgpId> pids ; // std::list<RsPgpId> pids ;
// //
// PGPHandler::availableGPGCertificatesWithPrivateKeys(pids) ; // mPgpHandler->availableGPGCertificatesWithPrivateKeys(pids) ;
// //
// for(std::list<RsPgpId>::const_iterator it(pids.begin());it!=pids.end();++it) // for(std::list<RsPgpId>::const_iterator it(pids.begin());it!=pids.end();++it)
// ids.push_back( (*it).toStdString() ) ; // ids.push_back( (*it).toStdString() ) ;
@ -171,11 +184,11 @@ int AuthGPG::GPGInit(const RsPgpId &ownId)
std::cerr << "AuthGPG::GPGInit() called with own gpg id : " << ownId.toStdString() << std::endl; std::cerr << "AuthGPG::GPGInit() called with own gpg id : " << ownId.toStdString() << std::endl;
#endif #endif
mOwnGpgId = RsPgpId(ownId); instance()->mOwnGpgId = ownId;
//force the validity of the private key. When set to unknown, it caused signature and text encryptions bugs //force the validity of the private key. When set to unknown, it caused signature and text encryptions bugs
privateTrustCertificate(ownId, 5); instance()->privateTrustCertificate(ownId, 5);
updateOwnSignatureFlag(mOwnGpgId) ; instance()->mPgpHandler->updateOwnSignatureFlag(ownId) ;
#ifdef DEBUG_AUTHGPG #ifdef DEBUG_AUTHGPG
std::cerr << "AuthGPG::GPGInit finished." << std::endl; std::cerr << "AuthGPG::GPGInit finished." << std::endl;
@ -204,7 +217,7 @@ void AuthGPG::threadTick()
/// - checks whether the keyring has changed on disk. /// - checks whether the keyring has changed on disk.
/// - merges/updates according to status. /// - merges/updates according to status.
/// ///
PGPHandler::syncDatabase() ; mPgpHandler->syncDatabase() ;
mCount = 0; mCount = 0;
_force_sync_database = false ; _force_sync_database = false ;
}//if (++count >= 100 || _force_sync_database) }//if (++count >= 100 || _force_sync_database)
@ -251,7 +264,7 @@ void AuthGPG::processServices()
/* don't bother loading - if we already have the certificate */ /* don't bother loading - if we already have the certificate */
if (isGPGId(loadOrSave->m_certGpgId)) if (mPgpHandler->isGPGId(loadOrSave->m_certGpgId))
{ {
#ifdef GPG_DEBUG #ifdef GPG_DEBUG
std::cerr << "AuthGPGimpl::processServices() Skipping load - already have it" << std::endl; std::cerr << "AuthGPGimpl::processServices() Skipping load - already have it" << std::endl;
@ -307,64 +320,64 @@ void AuthGPG::processServices()
bool AuthGPG::DoOwnSignature(const void *data, unsigned int datalen, void *buf_sigout, unsigned int *outl, std::string reason /* = "" */) bool AuthGPG::DoOwnSignature(const void *data, unsigned int datalen, void *buf_sigout, unsigned int *outl, std::string reason /* = "" */)
{ {
return PGPHandler::SignDataBin(mOwnGpgId,data,datalen,(unsigned char *)buf_sigout,outl,false,reason) ; return instance()->mPgpHandler->SignDataBin(mOwnGpgId,data,datalen,(unsigned char *)buf_sigout,outl,false,reason) ;
} }
/* import to GnuPG and other Certificates */ /* import to GnuPG and other Certificates */
bool AuthGPG::VerifySignature(const void *data, int datalen, const void *sig, unsigned int siglen, const PGPFingerprintType& withfingerprint) bool AuthGPG::VerifySignature(const void *data, int datalen, const void *sig, unsigned int siglen, const PGPFingerprintType& withfingerprint)
{ {
return PGPHandler::VerifySignBin((unsigned char*)data,datalen,(unsigned char*)sig,siglen,withfingerprint) ; return instance()->mPgpHandler->VerifySignBin((unsigned char*)data,datalen,(unsigned char*)sig,siglen,withfingerprint) ;
} }
bool AuthGPG::parseSignature(const void *sig, unsigned int siglen, RsPgpId& issuer_id) bool AuthGPG::parseSignature(const void *sig, unsigned int siglen, RsPgpId& issuer_id)
{ {
return PGPHandler::parseSignature((unsigned char*)sig,siglen,issuer_id) ; return instance()->mPgpHandler->parseSignature((unsigned char*)sig,siglen,issuer_id) ;
} }
bool AuthGPG::exportProfile(const std::string& fname,const RsPgpId& exported_id) bool AuthGPG::exportProfile(const std::string& fname,const RsPgpId& exported_id)
{ {
return PGPHandler::exportGPGKeyPair(fname,exported_id) ; return instance()->mPgpHandler->exportGPGKeyPair(fname,exported_id) ;
} }
bool AuthGPG::exportIdentityToString( bool AuthGPG::exportIdentityToString(
std::string& data, const RsPgpId& pgpId, bool includeSignatures, std::string& data, const RsPgpId& pgpId, bool includeSignatures,
std::string& errorMsg ) std::string& errorMsg )
{ {
return PGPHandler::exportGPGKeyPairToString( return instance()->mPgpHandler->exportGPGKeyPairToString(
data, pgpId, includeSignatures, errorMsg); data, pgpId, includeSignatures, errorMsg);
} }
bool AuthGPG::importProfile(const std::string& fname,RsPgpId& imported_id,std::string& import_error) bool AuthGPG::importProfile(const std::string& fname,RsPgpId& imported_id,std::string& import_error)
{ {
return PGPHandler::importGPGKeyPair(fname,imported_id,import_error) ; return instance()->mPgpHandler->importGPGKeyPair(fname,imported_id,import_error) ;
} }
bool AuthGPG::importProfileFromString(const std::string &data, RsPgpId &gpg_id, std::string &import_error) bool AuthGPG::importProfileFromString(const std::string &data, RsPgpId &gpg_id, std::string &import_error)
{ {
return PGPHandler::importGPGKeyPairFromString(data, gpg_id, import_error); return instance()->mPgpHandler->importGPGKeyPairFromString(data, gpg_id, import_error);
} }
bool AuthGPG::active() bool AuthGPG::active()
{ {
RsStackMutex stack(gpgMtxData); /******* LOCKED ******/ RsStackMutex stack(instance()->gpgMtxData); /******* LOCKED ******/
return gpgKeySelected; return instance()->gpgKeySelected;
} }
bool AuthGPG::GeneratePGPCertificate(const std::string& name, const std::string& email, const std::string& passwd, RsPgpId& pgpId, const int keynumbits, std::string& errString) bool AuthGPG::GeneratePGPCertificate(const std::string& name, const std::string& email, const std::string& passwd, RsPgpId& pgpId, const int keynumbits, std::string& errString)
{ {
RsStackMutex stack(gpgMtxEngine); /******* LOCKED ******/ RsStackMutex stack(instance()->gpgMtxEngine); /******* LOCKED ******/
return PGPHandler::GeneratePGPCertificate(name, email, passwd, pgpId, keynumbits, errString) ; return instance()->mPgpHandler->GeneratePGPCertificate(name, email, passwd, pgpId, keynumbits, errString) ;
} }
/**** These Two are common */ /**** These Two are common */
std::string AuthGPG::getGPGName(const RsPgpId& id,bool *success) std::string AuthGPG::getGPGName(const RsPgpId& id,bool *success)
{ {
RsStackMutex stack(gpgMtxData); /******* LOCKED ******/ RsStackMutex stack(instance()->gpgMtxData); /******* LOCKED ******/
const PGPCertificateInfo *info = getCertificateInfo(id) ; const PGPCertificateInfo *info = instance()->mPgpHandler->getCertificateInfo(id) ;
if(info != NULL) if(info != NULL)
{ {
@ -378,11 +391,29 @@ std::string AuthGPG::getGPGName(const RsPgpId& id,bool *success)
} }
} }
AuthGPG *AuthGPG::instance()
{
if(!_instance)
{
RsFatal() << "AuthGPG::instance() called before AuthGPG::init()! This should not happen." << std::endl;
return nullptr;
}
return _instance;
}
bool AuthGPG::isPGPId(const RsPgpId& id)
{
return instance()->mPgpHandler->isGPGId(id);
}
bool AuthGPG::isPGPAccepted(const RsPgpId& id)
{
return instance()->mPgpHandler->isGPGAccepted(id);
}
/**** These Two are common */ /**** These Two are common */
std::string AuthGPG::getGPGEmail(const RsPgpId& id,bool *success) std::string AuthGPG::getGPGEmail(const RsPgpId& id,bool *success)
{ {
RsStackMutex stack(gpgMtxData); /******* LOCKED ******/ RsStackMutex stack(instance()->gpgMtxData); /******* LOCKED ******/
const PGPCertificateInfo *info = getCertificateInfo(id) ; const PGPCertificateInfo *info = instance()->mPgpHandler->getCertificateInfo(id) ;
if(info != NULL) if(info != NULL)
{ {
@ -400,20 +431,20 @@ std::string AuthGPG::getGPGEmail(const RsPgpId& id,bool *success)
const RsPgpId& AuthGPG::getGPGOwnId() const RsPgpId& AuthGPG::getGPGOwnId()
{ {
RsStackMutex stack(gpgMtxData); /******* LOCKED ******/ RsStackMutex stack(instance()->gpgMtxData); /******* LOCKED ******/
return mOwnGpgId ; return instance()->mOwnGpgId ;
} }
std::string AuthGPG::getGPGOwnName() std::string AuthGPG::getGPGOwnName()
{ {
return getGPGName(mOwnGpgId) ; return getGPGName(instance()->mOwnGpgId) ;
} }
bool AuthGPG::getGPGAllList(std::list<RsPgpId> &ids) bool AuthGPG::getGPGAllList(std::list<RsPgpId> &ids)
{ {
RsStackMutex stack(gpgMtxData); /******* LOCKED ******/ RsStackMutex stack(instance()->gpgMtxData); /******* LOCKED ******/
PGPHandler::getGPGFilteredList(ids) ; instance()->mPgpHandler->getGPGFilteredList(ids) ;
return true; return true;
} }
@ -421,7 +452,7 @@ const PGPCertificateInfo *AuthGPG::getCertInfoFromStdString(const std::string& p
{ {
try try
{ {
return PGPHandler::getCertificateInfo(RsPgpId(pgp_id)) ; return instance()->mPgpHandler->getCertificateInfo(RsPgpId(pgp_id)) ;
} }
catch(std::exception& e) catch(std::exception& e)
{ {
@ -429,13 +460,13 @@ const PGPCertificateInfo *AuthGPG::getCertInfoFromStdString(const std::string& p
return NULL ; return NULL ;
} }
} }
bool AuthGPG::haveSecretKey(const RsPgpId& id) const bool AuthGPG::haveSecretKey(const RsPgpId& id)
{ {
return PGPHandler::haveSecretKey(id) ; return instance()->mPgpHandler->haveSecretKey(id) ;
} }
bool AuthGPG::isKeySupported(const RsPgpId& id) const bool AuthGPG::isKeySupported(const RsPgpId& id)
{ {
const PGPCertificateInfo *pc = getCertificateInfo(id) ; const PGPCertificateInfo *pc = instance()->mPgpHandler->getCertificateInfo(id) ;
if(pc == NULL) if(pc == NULL)
return false ; return false ;
@ -445,9 +476,9 @@ bool AuthGPG::isKeySupported(const RsPgpId& id) const
bool AuthGPG::getGPGDetails(const RsPgpId& pgp_id, RsPeerDetails &d) bool AuthGPG::getGPGDetails(const RsPgpId& pgp_id, RsPeerDetails &d)
{ {
RsStackMutex stack(gpgMtxData); /******* LOCKED ******/ RsStackMutex stack(instance()->gpgMtxData); /******* LOCKED ******/
const PGPCertificateInfo *pc = PGPHandler::getCertificateInfo(pgp_id) ; const PGPCertificateInfo *pc = instance()->mPgpHandler->getCertificateInfo(pgp_id) ;
if(pc == NULL) if(pc == NULL)
return false ; return false ;
@ -476,9 +507,7 @@ bool AuthGPG::getGPGDetails(const RsPgpId& pgp_id, RsPeerDetails &d)
bool AuthGPG::getGPGFilteredList(std::list<RsPgpId>& list,bool (*filter)(const PGPCertificateInfo&)) bool AuthGPG::getGPGFilteredList(std::list<RsPgpId>& list,bool (*filter)(const PGPCertificateInfo&))
{ {
RsStackMutex stack(gpgMtxData); /******* LOCKED ******/ return instance()->mPgpHandler->getGPGFilteredList(list,filter) ;
return PGPHandler::getGPGFilteredList(list,filter) ;
} }
static bool filter_Validity(const PGPCertificateInfo& /*info*/) { return true ; } //{ return info._validLvl >= PGPCertificateInfo::GPGME_VALIDITY_MARGINAL ; } static bool filter_Validity(const PGPCertificateInfo& /*info*/) { return true ; } //{ return info._validLvl >= PGPCertificateInfo::GPGME_VALIDITY_MARGINAL ; }
@ -504,9 +533,9 @@ bool AuthGPG::getGPGSignedList(std::list<RsPgpId> &ids)
// { // {
// RsStackMutex stack(gpgMtxData); /******* LOCKED ******/ // RsStackMutex stack(gpgMtxData); /******* LOCKED ******/
// #ifdef LIMIT_CERTIFICATE_SIZE // #ifdef LIMIT_CERTIFICATE_SIZE
// certificate = PGPHandler::SaveCertificateToString(RsPgpId(id),false) ; // certificate = instance()->mPgpHandler->SaveCertificateToString(RsPgpId(id),false) ;
// #else // #else
// certificate = PGPHandler::SaveCertificateToString(RsPgpId(id),true) ; // certificate = instance()->mPgpHandler->SaveCertificateToString(RsPgpId(id),true) ;
// #endif // #endif
// //
// // #ifdef LIMIT_CERTIFICATE_SIZE // // #ifdef LIMIT_CERTIFICATE_SIZE
@ -530,18 +559,18 @@ bool AuthGPG::getGPGSignedList(std::list<RsPgpId> &ids)
/* SKTAN : do not know how to use std::string id */ /* SKTAN : do not know how to use std::string id */
std::string AuthGPG::SaveCertificateToString(const RsPgpId &id,bool include_signatures) std::string AuthGPG::SaveCertificateToString(const RsPgpId &id,bool include_signatures)
{ {
RsStackMutex stack(gpgMtxEngine); /******* LOCKED ******/ RsStackMutex stack(instance()->gpgMtxEngine); /******* LOCKED ******/
return PGPHandler::SaveCertificateToString(id,include_signatures) ; return instance()->mPgpHandler->SaveCertificateToString(id,include_signatures) ;
} }
/* import to GnuPG and other Certificates */ /* import to GnuPG and other Certificates */
bool AuthGPG::LoadPGPKeyFromBinaryData(const unsigned char *data,uint32_t data_len, RsPgpId& gpg_id,std::string& error_string) bool AuthGPG::LoadPGPKeyFromBinaryData(const unsigned char *data,uint32_t data_len, RsPgpId& gpg_id,std::string& error_string)
{ {
RsStackMutex stack(gpgMtxEngine); /******* LOCKED ******/ RsStackMutex stack(instance()->gpgMtxEngine); /******* LOCKED ******/
if(PGPHandler::LoadCertificateFromBinaryData(data,data_len,gpg_id,error_string)) if(instance()->mPgpHandler->LoadCertificateFromBinaryData(data,data_len,gpg_id,error_string))
{ {
updateOwnSignatureFlag(gpg_id,mOwnGpgId) ; instance()->mPgpHandler->updateOwnSignatureFlag(gpg_id,instance()->mOwnGpgId) ;
return true ; return true ;
} }
@ -551,11 +580,11 @@ bool AuthGPG::LoadPGPKeyFromBinaryData(const unsigned char *data,uint32_t data_l
/* import to GnuPG and other Certificates */ /* import to GnuPG and other Certificates */
bool AuthGPG::LoadCertificateFromString(const std::string &str, RsPgpId& gpg_id,std::string& error_string) bool AuthGPG::LoadCertificateFromString(const std::string &str, RsPgpId& gpg_id,std::string& error_string)
{ {
RsStackMutex stack(gpgMtxEngine); /******* LOCKED ******/ RsStackMutex stack(instance()->gpgMtxEngine); /******* LOCKED ******/
if(PGPHandler::LoadCertificateFromString(str,gpg_id,error_string)) if(instance()->mPgpHandler->LoadCertificateFromString(str,gpg_id,error_string))
{ {
updateOwnSignatureFlag(gpg_id,mOwnGpgId) ; instance()->mPgpHandler->updateOwnSignatureFlag(gpg_id,instance()->mOwnGpgId) ;
return true ; return true ;
} }
@ -584,11 +613,11 @@ bool AuthGPG::AllowConnection(const RsPgpId& gpg_id, bool accept)
/* Was a "Reload Certificates" here -> be shouldn't be needed -> and very expensive, try without. */ /* Was a "Reload Certificates" here -> be shouldn't be needed -> and very expensive, try without. */
{ {
RsStackMutex stack(gpgMtxData); RsStackMutex stack(instance()->gpgMtxData);
PGPHandler::setAcceptConnexion(gpg_id,accept) ; instance()->mPgpHandler->setAcceptConnexion(gpg_id,accept) ;
} }
IndicateConfigChanged(); instance()->IndicateConfigChanged();
RsServer::notify()->notifyListChange(NOTIFY_LIST_FRIENDS, accept ? NOTIFY_TYPE_ADD : NOTIFY_TYPE_DEL); RsServer::notify()->notifyListChange(NOTIFY_LIST_FRIENDS, accept ? NOTIFY_TYPE_ADD : NOTIFY_TYPE_DEL);
@ -602,7 +631,7 @@ bool AuthGPG::SignCertificateLevel0(const RsPgpId &id)
std::cerr << "AuthGPG::SignCertificat(" << id << ")" << std::endl; std::cerr << "AuthGPG::SignCertificat(" << id << ")" << std::endl;
#endif #endif
return privateSignCertificate(id) ; return instance()->privateSignCertificate(id) ;
} }
bool AuthGPG::RevokeCertificate(const RsPgpId &id) bool AuthGPG::RevokeCertificate(const RsPgpId &id)
@ -622,26 +651,39 @@ bool AuthGPG::TrustCertificate(const RsPgpId& id, int trustlvl)
#ifdef GPG_DEBUG #ifdef GPG_DEBUG
std::cerr << "AuthGPG::TrustCertificate(" << id << ", " << trustlvl << ")" << std::endl; std::cerr << "AuthGPG::TrustCertificate(" << id << ", " << trustlvl << ")" << std::endl;
#endif #endif
return privateTrustCertificate(id, trustlvl) ; return instance()->privateTrustCertificate(id, trustlvl) ;
} }
bool AuthGPG::encryptDataBin(const RsPgpId& pgp_id,const void *data, unsigned int datalen, unsigned char *sign, unsigned int *signlen) bool AuthGPG::encryptDataBin(const RsPgpId& pgp_id,const void *data, unsigned int datalen, unsigned char *sign, unsigned int *signlen)
{ {
return PGPHandler::encryptDataBin(RsPgpId(pgp_id),data,datalen,sign,signlen) ; return instance()->mPgpHandler->encryptDataBin(RsPgpId(pgp_id),data,datalen,sign,signlen) ;
} }
bool AuthGPG::decryptDataBin(const void *data, unsigned int datalen, unsigned char *sign, unsigned int *signlen) bool AuthGPG::decryptDataBin(const void *data, unsigned int datalen, unsigned char *sign, unsigned int *signlen)
{ {
return PGPHandler::decryptDataBin(mOwnGpgId,data,datalen,sign,signlen) ; return instance()->mPgpHandler->decryptDataBin(instance()->mOwnGpgId,data,datalen,sign,signlen) ;
} }
bool AuthGPG::SignDataBin(const void *data, unsigned int datalen, unsigned char *sign, unsigned int *signlen, std::string reason /*= ""*/) bool AuthGPG::SignDataBin(const void *data, unsigned int datalen, unsigned char *sign, unsigned int *signlen, std::string reason /*= ""*/)
{ {
return DoOwnSignature(data, datalen, sign, signlen, reason); return instance()->DoOwnSignature(data, datalen, sign, signlen, reason);
} }
bool AuthGPG::exportPublicKey( const RsPgpId& id, unsigned char*& mem_block, size_t& mem_size, bool armoured, bool include_signatures )
{
return instance()->mPgpHandler->exportPublicKey(id,mem_block,mem_size,armoured,include_signatures);
}
bool AuthGPG::isPgpPubKeyAvailable(const RsPgpId& pgp_id)
{
return instance()->mPgpHandler->isPgpPubKeyAvailable(pgp_id);
}
bool AuthGPG::getKeyFingerprint(const RsPgpId& id,PGPFingerprintType& fp)
{
return instance()->mPgpHandler->getKeyFingerprint(id,fp);
}
bool AuthGPG::VerifySignBin(const void *data, uint32_t datalen, unsigned char *sign, unsigned int signlen, const PGPFingerprintType& withfingerprint) bool AuthGPG::VerifySignBin(const void *data, uint32_t datalen, unsigned char *sign, unsigned int signlen, const PGPFingerprintType& withfingerprint)
{ {
return VerifySignature(data, datalen, sign, signlen, withfingerprint); return instance()->VerifySignature(data, datalen, sign, signlen, withfingerprint);
} }
/* Sign/Trust stuff */ /* Sign/Trust stuff */
@ -650,7 +692,7 @@ int AuthGPG::privateSignCertificate(const RsPgpId &id)
{ {
RsStackMutex stack(gpgMtxData); /******* LOCKED ******/ RsStackMutex stack(gpgMtxData); /******* LOCKED ******/
int ret = PGPHandler::privateSignCertificate(mOwnGpgId,id) ; int ret = mPgpHandler->privateSignCertificate(mOwnGpgId,id) ;
_force_sync_database = true ; _force_sync_database = true ;
return ret ; return ret ;
} }
@ -675,7 +717,7 @@ int AuthGPG::privateTrustCertificate(const RsPgpId& id, int trustlvl)
if(!isGPGAccepted(id)) if(!isGPGAccepted(id))
return 0; return 0;
int res = PGPHandler::privateTrustCertificate(id,trustlvl) ; int res = instance()->mPgpHandler->privateTrustCertificate(id,trustlvl) ;
_force_sync_database = true ; _force_sync_database = true ;
return res ; return res ;
} }
@ -690,6 +732,10 @@ RsSerialiser *AuthGPG::setupSerialiser()
rss->addSerialType(new RsGeneralConfigSerialiser()); rss->addSerialType(new RsGeneralConfigSerialiser());
return rss ; return rss ;
} }
bool AuthGPG::isGPGAccepted(const RsPgpId& id)
{
return instance()->mPgpHandler->isGPGAccepted(id);
}
bool AuthGPG::saveList(bool& cleanup, std::list<RsItem*>& lst) bool AuthGPG::saveList(bool& cleanup, std::list<RsItem*>& lst)
{ {
@ -745,7 +791,7 @@ bool AuthGPG::loadList(std::list<RsItem*>& load)
std::list<RsTlvKeyValue>::iterator kit; std::list<RsTlvKeyValue>::iterator kit;
for(kit = vitem->tlvkvs.pairs.begin(); kit != vitem->tlvkvs.pairs.end(); ++kit) for(kit = vitem->tlvkvs.pairs.begin(); kit != vitem->tlvkvs.pairs.end(); ++kit)
if (kit->key != mOwnGpgId.toStdString()) if (kit->key != mOwnGpgId.toStdString())
PGPHandler::setAcceptConnexion(RsPgpId(kit->key), (kit->value == "TRUE")); instance()->mPgpHandler->setAcceptConnexion(RsPgpId(kit->key), (kit->value == "TRUE"));
} }
delete (*it); delete (*it);
} }
@ -755,14 +801,14 @@ bool AuthGPG::loadList(std::list<RsItem*>& load)
bool AuthGPG::addService(AuthGPGService *service) bool AuthGPG::addService(AuthGPGService *service)
{ {
RsStackMutex stack(gpgMtxService); /********* LOCKED *********/ RsStackMutex stack(instance()->gpgMtxService); /********* LOCKED *********/
if (std::find(services.begin(), services.end(), service) != services.end()) { if (std::find(instance()->services.begin(), instance()->services.end(), service) != instance()->services.end()) {
/* it exists already! */ /* it exists already! */
return false; return false;
} }
services.push_back(service); instance()->services.push_back(service);
return true; return true;
} }

View File

@ -89,18 +89,19 @@ public:
virtual void setGPGOperation(AuthGPGOperation *operation) = 0; virtual void setGPGOperation(AuthGPGOperation *operation) = 0;
}; };
// Note: replace OpenPGPSDKHandler with your own PGP handler class when needed. class AuthGPG: public p3Config, public RsTickingThread
class AuthGPG: public p3Config, public RsTickingThread, public OpenPGPSDKHandler
{ {
public: public:
static void init(const std::string& path_to_pubring, static void init(const std::string& path_to_pubring,
const std::string& path_to_secring, const std::string& path_to_secring,
const std::string& path_to_trustdb, const std::string& path_to_trustdb,
const std::string& pgp_lock_file); const std::string& pgp_lock_file);
static void exit(); static void registerToConfigMgr(const std::string& fname,p3ConfigMgr *CfgMgr);
static AuthGPG *getAuthGPG() { return _instance ; } static void exit();
static bool isPGPId(const RsPgpId& id) ;
static bool isPGPAccepted(const RsPgpId& id) ;
/** /**
* @param ids list of gpg certificate ids (note, not the actual certificates) * @param ids list of gpg certificate ids (note, not the actual certificates)
@ -120,7 +121,7 @@ public:
* (see storage at the end of the class) * (see storage at the end of the class)
* *
****/ ****/
virtual bool active(); static bool active();
// /* Initialize */ // /* Initialize */
// virtual bool InitAuth (); // virtual bool InitAuth ();
@ -128,10 +129,13 @@ public:
/* Init by generating new Own PGP Cert, or selecting existing PGP Cert */ /* Init by generating new Own PGP Cert, or selecting existing PGP Cert */
virtual int GPGInit(const RsPgpId &ownId); static int GPGInit(const RsPgpId &ownId);
virtual bool GeneratePGPCertificate(const std::string& name, const std::string& email, const std::string& passwd, RsPgpId &pgpId, const int keynumbits, std::string &errString); static bool GeneratePGPCertificate(const std::string& name, const std::string& email, const std::string& passwd, RsPgpId &pgpId, const int keynumbits, std::string &errString);
/*********************************************************************************/ static bool getGPGDetailsFromBinaryBlock(const unsigned char *mem,size_t mem_size,RsPgpId& key_id, std::string& name, std::list<RsPgpId>& signers) ;
static int availableGPGCertificatesWithPrivateKeys(std::list<RsPgpId>& pgpIds);
/*********************************************************************************/
/************************* STAGE 3 ***********************************************/ /************************* STAGE 3 ***********************************************/
/*********************************************************************************/ /*********************************************************************************/
/***** /*****
@ -142,29 +146,35 @@ public:
* provide access to details in cache list. * provide access to details in cache list.
* *
****/ ****/
virtual std::string getGPGName(const RsPgpId &pgp_id,bool *success = NULL); static std::string getGPGName(const RsPgpId &pgp_id,bool *success = NULL);
virtual std::string getGPGEmail(const RsPgpId &pgp_id,bool *success = NULL); static std::string getGPGEmail(const RsPgpId &pgp_id,bool *success = NULL);
/* PGP web of trust management */ static bool exportPublicKey( const RsPgpId& id, unsigned char*& mem_block, size_t& mem_size, bool armoured, bool include_signatures );
virtual const RsPgpId& getGPGOwnId();
virtual std::string getGPGOwnName();
//virtual std::string getGPGOwnEmail(); /* PGP web of trust management */
virtual bool isKeySupported(const RsPgpId &id) const ; static const RsPgpId& getGPGOwnId();
virtual bool haveSecretKey(const RsPgpId &id) const ; static std::string getGPGOwnName();
virtual bool getGPGDetails(const RsPgpId& id, RsPeerDetails &d);
virtual bool getGPGAllList(std::list<RsPgpId> &ids); static bool isGPGAccepted(const RsPgpId& id);
virtual bool getGPGValidList(std::list<RsPgpId> &ids);
virtual bool getGPGAcceptedList(std::list<RsPgpId> &ids); //virtual std::string getGPGOwnEmail();
virtual bool getGPGSignedList(std::list<RsPgpId> &ids); static bool getKeyFingerprint(const RsPgpId& id,PGPFingerprintType& fp) ;
virtual bool importProfile(const std::string& filename,RsPgpId& gpg_id,std::string& import_error) ; static bool isKeySupported(const RsPgpId &id) ;
virtual bool importProfileFromString(const std::string& data,RsPgpId& gpg_id,std::string& import_error) ; static bool isPgpPubKeyAvailable(const RsPgpId& pgp_id);
virtual bool exportProfile(const std::string& filename,const RsPgpId& gpg_id) ; static bool haveSecretKey(const RsPgpId &id) ;
virtual bool exportIdentityToString( static bool getGPGDetails(const RsPgpId& id, RsPeerDetails &d);
static bool getGPGAllList(std::list<RsPgpId> &ids);
static bool getGPGValidList(std::list<RsPgpId> &ids);
static bool getGPGAcceptedList(std::list<RsPgpId> &ids);
static bool getGPGSignedList(std::list<RsPgpId> &ids);
static bool importProfile(const std::string& filename,RsPgpId& gpg_id,std::string& import_error) ;
static bool importProfileFromString(const std::string& data,RsPgpId& gpg_id,std::string& import_error) ;
static bool exportProfile(const std::string& filename,const RsPgpId& gpg_id) ;
static bool exportIdentityToString(
std::string& data, const RsPgpId& pgpId, bool includeSignatures, std::string& data, const RsPgpId& pgpId, bool includeSignatures,
std::string& errorMsg ); std::string& errorMsg );
virtual bool removeKeysFromPGPKeyring(const std::set<RsPgpId> &pgp_ids,std::string& backup_file,uint32_t& error_code) ; static bool removeKeysFromPGPKeyring(const std::set<RsPgpId> &pgp_ids,std::string& backup_file,uint32_t& error_code) ;
/*********************************************************************************/ /*********************************************************************************/
/************************* STAGE 4 ***********************************************/ /************************* STAGE 4 ***********************************************/
@ -173,9 +183,9 @@ public:
* STAGE 4: Loading and Saving Certificates. (Strings and Files) * STAGE 4: Loading and Saving Certificates. (Strings and Files)
* *
****/ ****/
virtual bool LoadCertificateFromString(const std::string &pem, RsPgpId& gpg_id,std::string& error_string); static bool LoadCertificateFromString(const std::string &pem, RsPgpId& gpg_id,std::string& error_string);
virtual bool LoadPGPKeyFromBinaryData(const unsigned char *data,uint32_t data_len, RsPgpId& gpg_id,std::string& error_string); static bool LoadPGPKeyFromBinaryData(const unsigned char *data,uint32_t data_len, RsPgpId& gpg_id,std::string& error_string);
virtual std::string SaveCertificateToString(const RsPgpId &id,bool include_signatures) ; static std::string SaveCertificateToString(const RsPgpId &id,bool include_signatures) ;
// Cached certificates. // Cached certificates.
//bool getCachedGPGCertificate(const RsPgpId &id, std::string &certificate); //bool getCachedGPGCertificate(const RsPgpId &id, std::string &certificate);
@ -190,12 +200,12 @@ public:
* done in gpgroot already. * done in gpgroot already.
* *
****/ ****/
virtual bool AllowConnection(const RsPgpId &gpg_id, bool accept); static bool AllowConnection(const RsPgpId &gpg_id, bool accept);
virtual bool SignCertificateLevel0(const RsPgpId &id); static bool SignCertificateLevel0(const RsPgpId &id);
virtual bool RevokeCertificate(const RsPgpId &id); /* Particularly hard - leave for later */ static bool RevokeCertificate(const RsPgpId &id); /* Particularly hard - leave for later */
virtual bool TrustCertificate(const RsPgpId& id, int trustlvl); //trustlvl is 2 for none, 3 for marginal and 4 for full trust static bool TrustCertificate(const RsPgpId& id, int trustlvl); //trustlvl is 2 for none, 3 for marginal and 4 for full trust
/*********************************************************************************/ /*********************************************************************************/
/************************* STAGE 7 ***********************************************/ /************************* STAGE 7 ***********************************************/
@ -206,25 +216,25 @@ public:
* There should also be Encryption Functions... (do later). * There should also be Encryption Functions... (do later).
* *
****/ ****/
virtual bool SignDataBin(const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen, std::string reason = ""); static bool SignDataBin(const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen, std::string reason = "");
virtual bool VerifySignBin(const void*, uint32_t, unsigned char*, unsigned int, const PGPFingerprintType& withfingerprint); static bool VerifySignBin(const void*, uint32_t, unsigned char*, unsigned int, const PGPFingerprintType& withfingerprint);
virtual bool parseSignature(const void *sig, unsigned int siglen, RsPgpId& issuer_id); static bool parseSignature(const void *sig, unsigned int siglen, RsPgpId& issuer_id);
virtual bool encryptDataBin(const RsPgpId& pgp_id,const void *data, const uint32_t len, unsigned char *encr, unsigned int *encrlen); static bool encryptDataBin(const RsPgpId& pgp_id,const void *data, const uint32_t len, unsigned char *encr, unsigned int *encrlen);
virtual bool decryptDataBin(const void *data, const uint32_t len, unsigned char *decr, unsigned int *decrlen); static bool decryptDataBin(const void *data, const uint32_t len, unsigned char *decr, unsigned int *decrlen);
virtual bool decryptTextFromFile( std::string& text,const std::string& filename); static bool decryptTextFromFile( std::string& text,const std::string& filename);
virtual bool encryptTextToFile (const std::string& text,const std::string& filename); static bool encryptTextToFile (const std::string& text,const std::string& filename);
// virtual bool decryptTextFromString( std::string& encrypted_text,std::string& clear_string); // virtual bool decryptTextFromString( std::string& encrypted_text,std::string& clear_string);
// virtual bool encryptTextToString (const std::string& pgp_id,const std::string& clear_text,std::string& encrypted_string); // virtual bool encryptTextToString (const std::string& pgp_id,const std::string& clear_text,std::string& encrypted_string);
bool getGPGFilteredList(std::list<RsPgpId>& list,bool (*filter)(const PGPCertificateInfo&) = NULL) ; static bool getGPGFilteredList(std::list<RsPgpId>& list,bool (*filter)(const PGPCertificateInfo&) = NULL) ;
//END of PGP public functions //END of PGP public functions
/* GPG service */ /* GPG service */
virtual bool addService(AuthGPGService *service) ; static bool addService(AuthGPGService *service) ;
// This is for debug purpose only. Don't use it !! // This is for debug purpose only. Don't use it !!
static void setAuthGPG_debug(AuthGPG *auth_gpg) { _instance = auth_gpg ; } static void setAuthGPG_debug(AuthGPG *auth_gpg) { _instance = auth_gpg ; }
@ -236,9 +246,9 @@ public:
/*****************************************************************/ /*****************************************************************/
/*********************** p3config ******************************/ /*********************** p3config ******************************/
/* Key Functions to be overloaded for Full Configuration */ /* Key Functions to be overloaded for Full Configuration */
virtual RsSerialiser *setupSerialiser(); virtual RsSerialiser *setupSerialiser() override;
virtual bool saveList(bool &cleanup, std::list<RsItem *>&); virtual bool saveList(bool &cleanup, std::list<RsItem *>&) override;
virtual bool loadList(std::list<RsItem *>& load); virtual bool loadList(std::list<RsItem *>& load) override;
/*****************************************************************/ /*****************************************************************/
private: private:
@ -276,8 +286,7 @@ private:
void threadTick() override; /// @see RsTickingThread void threadTick() override; /// @see RsTickingThread
private: private:
static AuthGPG *instance();
static AuthGPG *instance_gpg; // pointeur vers le singleton
RsMutex gpgMtxService; RsMutex gpgMtxService;
RsMutex gpgMtxEngine; RsMutex gpgMtxEngine;
@ -292,6 +301,8 @@ private:
rstime_t mStoreKeyTime; rstime_t mStoreKeyTime;
PGPHandler *mPgpHandler;
RsPgpId mOwnGpgId; RsPgpId mOwnGpgId;
bool gpgKeySelected; bool gpgKeySelected;
bool _force_sync_database ; bool _force_sync_database ;

View File

@ -759,8 +759,7 @@ X509 *AuthSSLimpl::SignX509ReqWithGPG(X509_REQ *req, long /*days*/)
//long version = 0x00; //long version = 0x00;
unsigned long chtype = MBSTRING_UTF8; unsigned long chtype = MBSTRING_UTF8;
X509_NAME *issuer_name = X509_NAME_new(); X509_NAME *issuer_name = X509_NAME_new();
X509_NAME_add_entry_by_txt(issuer_name, "CN", chtype, X509_NAME_add_entry_by_txt(issuer_name, "CN", chtype, (unsigned char *) AuthGPG::getGPGOwnId().toStdString().c_str(), -1, -1, 0);
(unsigned char *) AuthGPG::getAuthGPG()->getGPGOwnId().toStdString().c_str(), -1, -1, 0);
/**** /****
X509_NAME_add_entry_by_NID(issuer_name, 48, 0, X509_NAME_add_entry_by_NID(issuer_name, 48, 0,
(unsigned char *) "email@email.com", -1, -1, 0); (unsigned char *) "email@email.com", -1, -1, 0);
@ -770,7 +769,7 @@ X509 *AuthSSLimpl::SignX509ReqWithGPG(X509_REQ *req, long /*days*/)
(unsigned char *) "loc", -1, -1, 0); (unsigned char *) "loc", -1, -1, 0);
****/ ****/
std::cerr << "AuthSSLimpl::SignX509Req() Issuer name: " << AuthGPG::getAuthGPG()->getGPGOwnId().toStdString() << std::endl; std::cerr << "AuthSSLimpl::SignX509Req() Issuer name: " << AuthGPG::getGPGOwnId().toStdString() << std::endl;
#ifdef V07_NON_BACKWARD_COMPATIBLE_CHANGE_002 #ifdef V07_NON_BACKWARD_COMPATIBLE_CHANGE_002
static const uint64_t CERTIFICATE_SERIAL_NUMBER = RS_CERTIFICATE_VERSION_NUMBER_07_0001 ; static const uint64_t CERTIFICATE_SERIAL_NUMBER = RS_CERTIFICATE_VERSION_NUMBER_07_0001 ;
@ -945,7 +944,7 @@ X509 *AuthSSLimpl::SignX509ReqWithGPG(X509_REQ *req, long /*days*/)
std::cerr << "Buffers Allocated" << std::endl; std::cerr << "Buffers Allocated" << std::endl;
/* NOW Sign via GPG Functions */ /* NOW Sign via GPG Functions */
if (!AuthGPG::getAuthGPG()->SignDataBin(buf_in, inl, buf_sigout, (unsigned int *) &sigoutl,"AuthSSLimpl::SignX509ReqWithGPG()")) if (!AuthGPG::SignDataBin(buf_in, inl, buf_sigout, (unsigned int *) &sigoutl,"AuthSSLimpl::SignX509ReqWithGPG()"))
{ {
sigoutl = 0; sigoutl = 0;
goto err; goto err;
@ -1040,7 +1039,7 @@ bool AuthSSLimpl::AuthX509WithGPG(X509 *x509,bool verbose, uint32_t& diagnostic)
{ {
RsPgpId issuer = RsX509Cert::getCertIssuer(*x509); RsPgpId issuer = RsX509Cert::getCertIssuer(*x509);
RsPeerDetails pd; RsPeerDetails pd;
if (!AuthGPG::getAuthGPG()->getGPGDetails(issuer, pd)) if (!AuthGPG::getGPGDetails(issuer, pd))
{ {
RsInfo() << __PRETTY_FUNCTION__ << " X509 NOT authenticated : " RsInfo() << __PRETTY_FUNCTION__ << " X509 NOT authenticated : "
<< "AuthGPG::getAuthGPG()->getGPGDetails(" << issuer << "AuthGPG::getAuthGPG()->getGPGDetails(" << issuer
@ -1185,9 +1184,7 @@ bool AuthSSLimpl::AuthX509WithGPG(X509 *x509,bool verbose, uint32_t& diagnostic)
// passed, verify the signature itself // passed, verify the signature itself
if (!AuthGPG::getAuthGPG()->VerifySignBin( if (!AuthGPG::VerifySignBin( signed_data, signed_data_length, signature->data, static_cast<unsigned int>(signature->length), pd.fpr ))
signed_data, signed_data_length, signature->data,
static_cast<unsigned int>(signature->length), pd.fpr ))
{ {
diagnostic = RS_SSL_HANDSHAKE_DIAGNOSTIC_WRONG_SIGNATURE; diagnostic = RS_SSL_HANDSHAKE_DIAGNOSTIC_WRONG_SIGNATURE;
goto err; goto err;
@ -1383,7 +1380,7 @@ int AuthSSLimpl::VerifyX509Callback(int /*preverify_ok*/, X509_STORE_CTX* ctx)
std::cerr << "******* VerifyX509Callback cert: " << std::hex << ctx->cert <<std::dec << std::endl; std::cerr << "******* VerifyX509Callback cert: " << std::hex << ctx->cert <<std::dec << std::endl;
#endif #endif
if ( !isSslOnlyFriend && pgpId != AuthGPG::getAuthGPG()->getGPGOwnId() && !AuthGPG::getAuthGPG()->isGPGAccepted(pgpId) ) if ( !isSslOnlyFriend && pgpId != AuthGPG::getGPGOwnId() && !AuthGPG::isGPGAccepted(pgpId) )
{ {
std::string errMsg = "Connection attempt signed by PGP key id: " + std::string errMsg = "Connection attempt signed by PGP key id: " +
pgpId.toStdString() + " not accepted because it is not" pgpId.toStdString() + " not accepted because it is not"

View File

@ -812,11 +812,11 @@ int p3PeerMgrIMPL::getFriendCount(bool ssl, bool online)
// count all gpg id's // count all gpg id's
std::list<RsPgpId> gpgIds; std::list<RsPgpId> gpgIds;
AuthGPG::getAuthGPG()->getGPGAcceptedList(gpgIds); AuthGPG::getGPGAcceptedList(gpgIds);
// add own gpg id, if we have more than one location // add own gpg id, if we have more than one location
std::list<RsPeerId> ownSslIds; std::list<RsPeerId> ownSslIds;
getAssociatedPeers(AuthGPG::getAuthGPG()->getGPGOwnId(), ownSslIds); getAssociatedPeers(AuthGPG::getGPGOwnId(), ownSslIds);
return gpgIds.size() + ((ownSslIds.size() > 0) ? 1 : 0); return gpgIds.size() + ((ownSslIds.size() > 0) ? 1 : 0);
} }
@ -962,7 +962,7 @@ bool p3PeerMgrIMPL::addFriend(const RsPeerId& input_id, const RsPgpId& input_gpg
// check that the PGP key is known // check that the PGP key is known
if(!AuthGPG::getAuthGPG()->isGPGId(gpg_id)) if(!AuthGPG::isPGPId(gpg_id))
{ {
RsErr() << "Trying to add SSL id (" << id << ") to be validated with unknown PGP key (" << gpg_id << ". This is a bug!" << std::endl; RsErr() << "Trying to add SSL id (" << id << ") to be validated with unknown PGP key (" << gpg_id << ". This is a bug!" << std::endl;
return false; return false;
@ -970,7 +970,7 @@ bool p3PeerMgrIMPL::addFriend(const RsPeerId& input_id, const RsPgpId& input_gpg
//Authentication is now tested at connection time, we don't store the ssl cert anymore //Authentication is now tested at connection time, we don't store the ssl cert anymore
// //
if (!AuthGPG::getAuthGPG()->isGPGAccepted(gpg_id) && gpg_id != AuthGPG::getAuthGPG()->getGPGOwnId()) if (!AuthGPG::isGPGAccepted(gpg_id) && gpg_id != AuthGPG::getGPGOwnId())
{ {
#ifdef PEER_DEBUG #ifdef PEER_DEBUG
std::cerr << "p3PeerMgrIMPL::addFriend() gpg is not accepted" << std::endl; std::cerr << "p3PeerMgrIMPL::addFriend() gpg is not accepted" << std::endl;
@ -1024,7 +1024,7 @@ bool p3PeerMgrIMPL::addFriend(const RsPeerId& input_id, const RsPgpId& input_gpg
pstate.id = id; pstate.id = id;
pstate.gpg_id = gpg_id; pstate.gpg_id = gpg_id;
pstate.name = AuthGPG::getAuthGPG()->getGPGName(gpg_id); pstate.name = AuthGPG::getGPGName(gpg_id);
pstate.vs_disc = vs_disc; pstate.vs_disc = vs_disc;
pstate.vs_dht = vs_dht; pstate.vs_dht = vs_dht;
@ -1126,8 +1126,8 @@ bool p3PeerMgrIMPL::addSslOnlyFriend( const RsPeerId& sslId, const RsPgpId& pgp_
* superficially set to true the PGP signature verification would have been * superficially set to true the PGP signature verification would have been
* skipped and the attacker connection would be accepted. * skipped and the attacker connection would be accepted.
* If the PGP key is available add it as full friend. */ * If the PGP key is available add it as full friend. */
if(AuthGPG::getAuthGPG()->isPgpPubKeyAvailable(pgp_id)) if(AuthGPG::isPgpPubKeyAvailable(pgp_id))
AuthGPG::getAuthGPG()->AllowConnection(pgp_id, true); AuthGPG::AllowConnection(pgp_id, true);
else else
pstate.skip_pgp_signature_validation = true; pstate.skip_pgp_signature_validation = true;
@ -2470,7 +2470,7 @@ bool p3PeerMgrIMPL::loadList(std::list<RsItem *>& load)
setOwnNetworkMode(pitem->netMode); setOwnNetworkMode(pitem->netMode);
setOwnVisState(pitem->vs_disc, pitem->vs_dht); setOwnVisState(pitem->vs_disc, pitem->vs_dht);
mOwnState.gpg_id = AuthGPG::getAuthGPG()->getGPGOwnId(); mOwnState.gpg_id = AuthGPG::getGPGOwnId();
mOwnState.location = AuthSSL::getAuthSSL()->getOwnLocation(); mOwnState.location = AuthSSL::getAuthSSL()->getOwnLocation();
} }
else else
@ -2642,7 +2642,7 @@ bool p3PeerMgrIMPL::loadList(std::list<RsItem *>& load)
#endif #endif
for(uint32_t i=0;i<sitem->pgp_ids.size();++i) for(uint32_t i=0;i<sitem->pgp_ids.size();++i)
if(AuthGPG::getAuthGPG()->isGPGAccepted(sitem->pgp_ids[i]) || sitem->pgp_ids[i] == AuthGPG::getAuthGPG()->getGPGOwnId()) if(AuthGPG::isGPGAccepted(sitem->pgp_ids[i]) || sitem->pgp_ids[i] == AuthGPG::getGPGOwnId())
{ {
mFriendsPermissionFlags[sitem->pgp_ids[i]] = sitem->service_flags[i] ; mFriendsPermissionFlags[sitem->pgp_ids[i]] = sitem->service_flags[i] ;
#ifdef PEER_DEBUG #ifdef PEER_DEBUG
@ -2684,7 +2684,7 @@ bool p3PeerMgrIMPL::loadList(std::list<RsItem *>& load)
for(auto group_pair:groupList) for(auto group_pair:groupList)
{ {
for(auto profileIdIt(group_pair.second.peerIds.begin());profileIdIt!=group_pair.second.peerIds.end();) for(auto profileIdIt(group_pair.second.peerIds.begin());profileIdIt!=group_pair.second.peerIds.end();)
if(AuthGPG::getAuthGPG()->isGPGAccepted(*profileIdIt) || *profileIdIt == AuthGPG::getAuthGPG()->getGPGOwnId()) if(AuthGPG::isGPGAccepted(*profileIdIt) || *profileIdIt == AuthGPG::getGPGOwnId())
++profileIdIt; ++profileIdIt;
else else
{ {

View File

@ -1213,8 +1213,7 @@ int pqissl::Authorise_SSL_Connection()
} }
RsPgpId pgpId = RsX509Cert::getCertIssuer(*peercert); RsPgpId pgpId = RsX509Cert::getCertIssuer(*peercert);
if( !isSslOnlyFriend && pgpId != AuthGPG::getAuthGPG()->getGPGOwnId() && if( !isSslOnlyFriend && pgpId != AuthGPG::getGPGOwnId() && !AuthGPG::isGPGAccepted(pgpId) )
!AuthGPG::getAuthGPG()->isGPGAccepted(pgpId) )
{ {
RsFatal() << __PRETTY_FUNCTION__ << " pgpId: " << pgpId RsFatal() << __PRETTY_FUNCTION__ << " pgpId: " << pgpId
<< " is not friend. It is very unlikely to happen at this " << " is not friend. It is very unlikely to happen at this "

View File

@ -797,8 +797,7 @@ int pqissllistener::completeConnection(int fd, IncomingSSLInfo& info)
exit(failure); exit(failure);
} }
if( !isSslOnlyFriend && pgpId != AuthGPG::getAuthGPG()->getGPGOwnId() && if( !isSslOnlyFriend && pgpId != AuthGPG::getGPGOwnId() && !AuthGPG::isGPGAccepted(pgpId) )
!AuthGPG::getAuthGPG()->isGPGAccepted(pgpId) )
{ {
RsFatal() << __PRETTY_FUNCTION__ << " pgpId: " << pgpId RsFatal() << __PRETTY_FUNCTION__ << " pgpId: " << pgpId
<< " is not friend. It is very unlikely to happen at this " << " is not friend. It is very unlikely to happen at this "

View File

@ -254,7 +254,7 @@ bool p3Peers::setPeerMaximumRates(const RsPgpId& pid,uint32_t maxUploadRate,uint
bool p3Peers::haveSecretKey(const RsPgpId& id) bool p3Peers::haveSecretKey(const RsPgpId& id)
{ {
return AuthGPG::getAuthGPG()->haveSecretKey(id); return AuthGPG::haveSecretKey(id);
} }
/* There are too many dependancies of this function /* There are too many dependancies of this function
@ -273,7 +273,7 @@ bool p3Peers::getPeerDetails(const RsPeerId& id, RsPeerDetails &d)
if (id == sOwnId) if (id == sOwnId)
{ {
mPeerMgr->getOwnNetStatus(ps); mPeerMgr->getOwnNetStatus(ps);
ps.gpg_id = AuthGPG::getAuthGPG()->getGPGOwnId(); ps.gpg_id = AuthGPG::getGPGOwnId();
} }
else if (!mPeerMgr->getFriendNetStatus(id, ps)) else if (!mPeerMgr->getFriendNetStatus(id, ps))
{ {
@ -559,17 +559,17 @@ bool p3Peers::isProxyAddress(const uint32_t type, const sockaddr_storage& addr)
bool p3Peers::isKeySupported(const RsPgpId& id) bool p3Peers::isKeySupported(const RsPgpId& id)
{ {
return AuthGPG::getAuthGPG()->isKeySupported(id); return AuthGPG::isKeySupported(id);
} }
std::string p3Peers::getGPGName(const RsPgpId &gpg_id) std::string p3Peers::getGPGName(const RsPgpId &gpg_id)
{ {
/* get from mAuthMgr as it should have more peers? */ /* get from mAuthMgr as it should have more peers? */
return AuthGPG::getAuthGPG()->getGPGName(gpg_id); return AuthGPG::getGPGName(gpg_id);
} }
bool p3Peers::isPgpFriend(const RsPgpId& pgpId) bool p3Peers::isPgpFriend(const RsPgpId& pgpId)
{ return AuthGPG::getAuthGPG()->isGPGAccepted(pgpId); } { return AuthGPG::isGPGAccepted(pgpId); }
bool p3Peers::isSslOnlyFriend(const RsPeerId& sslId) bool p3Peers::isSslOnlyFriend(const RsPeerId& sslId)
{ {
@ -597,7 +597,7 @@ std::string p3Peers::getPeerName(const RsPeerId& ssl)
#endif #endif
std::string name; std::string name;
if (ssl == AuthSSL::getAuthSSL()->OwnId()) if (ssl == AuthSSL::getAuthSSL()->OwnId())
return AuthGPG::getAuthGPG()->getGPGOwnName(); return AuthGPG::getGPGOwnName();
if (mPeerMgr->getPeerName(ssl, name)) if (mPeerMgr->getPeerName(ssl, name))
{ {
@ -617,7 +617,7 @@ bool p3Peers::getGPGAllList(std::list<RsPgpId> &ids)
#endif #endif
/* get from mAuthMgr */ /* get from mAuthMgr */
AuthGPG::getAuthGPG()->getGPGAllList(ids); AuthGPG::getGPGAllList(ids);
return true; return true;
} }
@ -628,7 +628,7 @@ bool p3Peers::getGPGValidList(std::list<RsPgpId> &ids)
#endif #endif
/* get from mAuthMgr */ /* get from mAuthMgr */
AuthGPG::getAuthGPG()->getGPGValidList(ids); AuthGPG::getGPGValidList(ids);
return true; return true;
} }
@ -639,14 +639,14 @@ bool p3Peers::getGPGSignedList(std::list<RsPgpId> &ids)
#endif #endif
/* get from mAuthMgr */ /* get from mAuthMgr */
AuthGPG::getAuthGPG()->getGPGSignedList(ids); AuthGPG::getGPGSignedList(ids);
return true; return true;
} }
bool p3Peers::getPgpFriendList(std::vector<RsPgpId>& pgpIds) bool p3Peers::getPgpFriendList(std::vector<RsPgpId>& pgpIds)
{ {
std::list<RsPgpId> ids; std::list<RsPgpId> ids;
if(AuthGPG::getAuthGPG()->getGPGAcceptedList(ids)) if(AuthGPG::getGPGAcceptedList(ids))
{ {
pgpIds.clear(); pgpIds.clear();
std::copy(ids.begin(), ids.end(), std::back_inserter(pgpIds)); std::copy(ids.begin(), ids.end(), std::back_inserter(pgpIds));
@ -660,7 +660,7 @@ bool p3Peers::getGPGAcceptedList(std::list<RsPgpId> &ids)
#ifdef P3PEERS_DEBUG #ifdef P3PEERS_DEBUG
std::cerr << "p3Peers::getGPGAcceptedList()" << std::endl; std::cerr << "p3Peers::getGPGAcceptedList()" << std::endl;
#endif #endif
AuthGPG::getAuthGPG()->getGPGAcceptedList(ids); AuthGPG::getGPGAcceptedList(ids);
return true; return true;
} }
@ -676,7 +676,7 @@ bool p3Peers::getAssociatedSSLIds(const RsPgpId &gpg_id, std::list<RsPeerId> &id
bool p3Peers::gpgSignData(const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen, std::string reason /* = "" */) bool p3Peers::gpgSignData(const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen, std::string reason /* = "" */)
{ {
return AuthGPG::getAuthGPG()->SignDataBin(data,len,sign,signlen, reason); return AuthGPG::SignDataBin(data,len,sign,signlen, reason);
} }
RsPgpId p3Peers::pgpIdFromFingerprint(const RsPgpFingerprint& fpr) RsPgpId p3Peers::pgpIdFromFingerprint(const RsPgpFingerprint& fpr)
@ -691,7 +691,7 @@ bool p3Peers::getGPGDetails(const RsPgpId &pgp_id, RsPeerDetails &d)
#endif #endif
/* get from mAuthMgr */ /* get from mAuthMgr */
bool res = AuthGPG::getAuthGPG()->getGPGDetails(pgp_id, d); bool res = AuthGPG::getGPGDetails(pgp_id, d);
d.isOnlyGPGdetail = true ; d.isOnlyGPGdetail = true ;
d.service_perm_flags = mPeerMgr->servicePermissionFlags(pgp_id) ; d.service_perm_flags = mPeerMgr->servicePermissionFlags(pgp_id) ;
@ -706,7 +706,7 @@ const RsPgpId& p3Peers::getGPGOwnId()
#endif #endif
/* get from mAuthMgr */ /* get from mAuthMgr */
return AuthGPG::getAuthGPG()->getGPGOwnId(); return AuthGPG::getGPGOwnId();
} }
RsPgpId p3Peers::getGPGId(const RsPeerId& sslid) RsPgpId p3Peers::getGPGId(const RsPeerId& sslid)
@ -718,7 +718,7 @@ RsPgpId p3Peers::getGPGId(const RsPeerId& sslid)
/* get from mAuthMgr */ /* get from mAuthMgr */
if (sslid == AuthSSL::getAuthSSL()->OwnId()) if (sslid == AuthSSL::getAuthSSL()->OwnId())
{ {
return AuthGPG::getAuthGPG()->getGPGOwnId(); return AuthGPG::getGPGOwnId();
} }
peerState pcs; peerState pcs;
if (mPeerMgr->getFriendNetStatus(sslid, pcs)) if (mPeerMgr->getFriendNetStatus(sslid, pcs))
@ -739,12 +739,12 @@ bool p3Peers::addFriend(const RsPeerId &ssl_id, const RsPgpId &gpg_id,ServicePe
#ifdef P3PEERS_DEBUG #ifdef P3PEERS_DEBUG
std::cerr << "p3Peers::addFriend() with : id : " << id << "; gpg_id : " << gpg_id << std::endl; std::cerr << "p3Peers::addFriend() with : id : " << id << "; gpg_id : " << gpg_id << std::endl;
#endif #endif
if(AuthGPG::getAuthGPG()->isGPGId(gpg_id)) if(AuthGPG::isPGPId(gpg_id))
{ {
#ifdef P3PEERS_DEBUG #ifdef P3PEERS_DEBUG
std::cerr << "p3Peers::addFriend() Authorising GPG Id: " << gpg_id << std::endl; std::cerr << "p3Peers::addFriend() Authorising GPG Id: " << gpg_id << std::endl;
#endif #endif
if (AuthGPG::getAuthGPG()->AllowConnection(gpg_id, true)) if (AuthGPG::AllowConnection(gpg_id, true))
{ {
#ifdef P3PEERS_DEBUG #ifdef P3PEERS_DEBUG
std::cerr << "p3Peers::addFriend() Authorization OK." << std::endl; std::cerr << "p3Peers::addFriend() Authorization OK." << std::endl;
@ -797,7 +797,7 @@ bool p3Peers::addSslOnlyFriend( const RsPeerId& sslId, const RsPgpId& pgp_id,con
bool p3Peers::removeKeysFromPGPKeyring(const std::set<RsPgpId>& pgp_ids,std::string& backup_file,uint32_t& error_code) bool p3Peers::removeKeysFromPGPKeyring(const std::set<RsPgpId>& pgp_ids,std::string& backup_file,uint32_t& error_code)
{ {
return AuthGPG::getAuthGPG()->removeKeysFromPGPKeyring(pgp_ids,backup_file,error_code) ; return AuthGPG::removeKeysFromPGPKeyring(pgp_ids,backup_file,error_code) ;
} }
bool p3Peers::removeFriendLocation(const RsPeerId &sslId) bool p3Peers::removeFriendLocation(const RsPeerId &sslId)
@ -817,7 +817,7 @@ bool p3Peers::removeFriend(const RsPgpId& gpgId)
#ifdef P3PEERS_DEBUG #ifdef P3PEERS_DEBUG
std::cerr << "p3Peers::removeFriend() " << gpgId << std::endl; std::cerr << "p3Peers::removeFriend() " << gpgId << std::endl;
#endif #endif
if (gpgId == AuthGPG::getAuthGPG()->getGPGOwnId()) { if (gpgId == AuthGPG::getGPGOwnId()) {
std::cerr << "p3Peers::removeFriend() ERROR we're not going to remove our own GPG id." << std::endl; std::cerr << "p3Peers::removeFriend() ERROR we're not going to remove our own GPG id." << std::endl;
return false; return false;
} }
@ -825,7 +825,7 @@ bool p3Peers::removeFriend(const RsPgpId& gpgId)
#ifdef P3PEERS_DEBUG #ifdef P3PEERS_DEBUG
std::cerr << "p3Peers::removeFriend() Removing GPG Id: " << gpgId << std::endl; std::cerr << "p3Peers::removeFriend() Removing GPG Id: " << gpgId << std::endl;
#endif #endif
if (AuthGPG::getAuthGPG()->AllowConnection(gpgId, false)) if (AuthGPG::AllowConnection(gpgId, false))
{ {
#ifdef P3PEERS_DEBUG #ifdef P3PEERS_DEBUG
std::cerr << "p3Peers::removeFriend() OK." << std::endl; std::cerr << "p3Peers::removeFriend() OK." << std::endl;
@ -1107,9 +1107,7 @@ std::string p3Peers::getPGPKey(const RsPgpId& pgp_id,bool include_signatures)
rs_owner_ptr<unsigned char> mem_block = nullptr; rs_owner_ptr<unsigned char> mem_block = nullptr;
size_t mem_block_size = 0; size_t mem_block_size = 0;
if( !AuthGPG::getAuthGPG()->exportPublicKey( if( !AuthGPG::exportPublicKey( RsPgpId(pgp_id), mem_block, mem_block_size, false, include_signatures ) )
RsPgpId(pgp_id), mem_block, mem_block_size,
false, include_signatures ) )
{ {
RsErr() << __PRETTY_FUNCTION__ RsErr() << __PRETTY_FUNCTION__
<< " Failure retriving certificate for id " << pgp_id << " Failure retriving certificate for id " << pgp_id
@ -1140,8 +1138,7 @@ bool p3Peers::GetPGPBase64StringAndCheckSum(
rs_owner_ptr<unsigned char> mem_block = nullptr; rs_owner_ptr<unsigned char> mem_block = nullptr;
size_t mem_block_size = 0; size_t mem_block_size = 0;
if(!AuthGPG::getAuthGPG()->exportPublicKey( if(!AuthGPG::exportPublicKey( gpg_id,mem_block,mem_block_size,false,false ))
gpg_id,mem_block,mem_block_size,false,false ))
return false; return false;
RsBase64::encode(mem_block, mem_block_size, gpg_base64_string, true, false); RsBase64::encode(mem_block, mem_block_size, gpg_base64_string, true, false);
@ -1601,7 +1598,7 @@ std::string p3Peers::GetRetroshareInvite( const RsPeerId& sslId, RetroshareInvit
unsigned char *mem_block = nullptr; unsigned char *mem_block = nullptr;
size_t mem_block_size = 0; size_t mem_block_size = 0;
if(!AuthGPG::getAuthGPG()->exportPublicKey( RsPgpId(detail.gpg_id), mem_block, mem_block_size, false, !!(invite_flags & RetroshareInviteFlags::PGP_SIGNATURES) )) if(!AuthGPG::exportPublicKey( RsPgpId(detail.gpg_id), mem_block, mem_block_size, false, !!(invite_flags & RetroshareInviteFlags::PGP_SIGNATURES) ))
{ {
std::cerr << "Cannot output certificate for id \"" << detail.gpg_id std::cerr << "Cannot output certificate for id \"" << detail.gpg_id
<< "\". Sorry." << std::endl; << "\". Sorry." << std::endl;
@ -1637,7 +1634,7 @@ bool p3Peers::loadCertificateFromString(
} }
RsPgpId gpgid; RsPgpId gpgid;
bool res = AuthGPG::getAuthGPG()->LoadCertificateFromString( crt->armouredPGPKey(), gpgid, error_string ); bool res = AuthGPG::LoadCertificateFromString( crt->armouredPGPKey(), gpgid, error_string );
gpg_id = gpgid; gpg_id = gpgid;
ssl_id = crt->sslid(); ssl_id = crt->sslid();
@ -1654,7 +1651,7 @@ bool p3Peers::loadCertificateFromString(
} }
bool p3Peers::loadPgpKeyFromBinaryData( const unsigned char *bin_key_data,uint32_t bin_key_len, RsPgpId& gpg_id, std::string& error_string ) bool p3Peers::loadPgpKeyFromBinaryData( const unsigned char *bin_key_data,uint32_t bin_key_len, RsPgpId& gpg_id, std::string& error_string )
{ {
bool res = AuthGPG::getAuthGPG()->LoadPGPKeyFromBinaryData( bin_key_data,bin_key_len, gpg_id, error_string ); bool res = AuthGPG::LoadPGPKeyFromBinaryData( bin_key_data,bin_key_len, gpg_id, error_string );
if(res) if(res)
mPeerMgr->notifyPgpKeyReceived(gpg_id); mPeerMgr->notifyPgpKeyReceived(gpg_id);
@ -1673,9 +1670,7 @@ bool p3Peers::loadDetailsFromStringCert( const std::string &certstr,
RsCertificate& cert = *certPtr; RsCertificate& cert = *certPtr;
if(!AuthGPG::getAuthGPG()->getGPGDetailsFromBinaryBlock( if(!AuthGPG::getGPGDetailsFromBinaryBlock( cert.pgp_key(), cert.pgp_key_size(), pd.gpg_id, pd.name, pd.gpgSigners ))
cert.pgp_key(), cert.pgp_key_size(),
pd.gpg_id, pd.name, pd.gpgSigners ))
return false; return false;
Dbg4() << __PRETTY_FUNCTION__ << " Parsing cert for sslid, location, ext " Dbg4() << __PRETTY_FUNCTION__ << " Parsing cert for sslid, location, ext "
@ -1753,7 +1748,7 @@ bool p3Peers::signGPGCertificate(const RsPgpId &id, const std::string &gpg_pass
rsNotify->cachePgpPassphrase(gpg_passphrase); rsNotify->cachePgpPassphrase(gpg_passphrase);
rsNotify->setDisableAskPassword(true); rsNotify->setDisableAskPassword(true);
bool res = AuthGPG::getAuthGPG()->SignCertificateLevel0(id); bool res = AuthGPG::SignCertificateLevel0(id);
rsNotify->clearPgpPassphrase(); rsNotify->clearPgpPassphrase();
rsNotify->setDisableAskPassword(false); rsNotify->setDisableAskPassword(false);
@ -1767,7 +1762,7 @@ bool p3Peers::trustGPGCertificate(const RsPgpId &id, uint32_t trustlvl)
std::cerr << "p3Peers::TrustCertificate() " << id; std::cerr << "p3Peers::TrustCertificate() " << id;
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
return AuthGPG::getAuthGPG()->TrustCertificate(id, trustlvl); return AuthGPG::TrustCertificate(id, trustlvl);
} }
/* Group Stuff */ /* Group Stuff */

View File

@ -140,7 +140,7 @@ bool p3ServerConfig::setConfigurationOption(uint32_t key, const std::string &opt
int p3ServerConfig::getConfigNetStatus(RsConfigNetStatus &status) int p3ServerConfig::getConfigNetStatus(RsConfigNetStatus &status)
{ {
status.ownId = AuthSSL::getAuthSSL()->OwnId(); status.ownId = AuthSSL::getAuthSSL()->OwnId();
status.ownName = AuthGPG::getAuthGPG()->getGPGOwnName(); status.ownName = AuthGPG::getGPGOwnName();
// Details from PeerMgr. // Details from PeerMgr.
peerState pstate; peerState pstate;

View File

@ -701,10 +701,10 @@ static bool checkAccount(const std::string &accountdir, AccountDetails &account,
if(! RsAccounts::GetPGPLoginDetails(account.mPgpId, account.mPgpName, account.mPgpEmail)) if(! RsAccounts::GetPGPLoginDetails(account.mPgpId, account.mPgpName, account.mPgpEmail))
return false ; return false ;
if(!AuthGPG::getAuthGPG()->haveSecretKey(account.mPgpId)) if(!AuthGPG::haveSecretKey(account.mPgpId))
return false ; return false ;
if(!AuthGPG::getAuthGPG()->isKeySupported(account.mPgpId)) if(!AuthGPG::isKeySupported(account.mPgpId))
{ {
std::string keystring = account.mPgpId.toStdString() + " " + account.mPgpName + "&#60;" + account.mPgpEmail ; std::string keystring = account.mPgpId.toStdString() + " " + account.mPgpName + "&#60;" + account.mPgpEmail ;
unsupported_keys[keystring].push_back("Location: " + account.mLocation + "&nbsp;&nbsp;(" + account.mSslId.toStdString() + ")") ; unsupported_keys[keystring].push_back("Location: " + account.mLocation + "&nbsp;&nbsp;(" + account.mSslId.toStdString() + ")") ;
@ -851,9 +851,10 @@ static bool checkAccount(const std::string &accountdir, AccountDetails &account,
/* Generating GPGme Account */ /* Generating GPGme Account */
int RsAccountsDetail::GetPGPLogins(std::list<RsPgpId> &pgpIds) { int RsAccountsDetail::GetPGPLogins(std::list<RsPgpId>& pgpIds)
AuthGPG::getAuthGPG()->availableGPGCertificatesWithPrivateKeys(pgpIds); {
return 1; AuthGPG::availableGPGCertificatesWithPrivateKeys(pgpIds);
return 1;
} }
int RsAccountsDetail::GetPGPLoginDetails(const RsPgpId& id, std::string &name, std::string &email) int RsAccountsDetail::GetPGPLoginDetails(const RsPgpId& id, std::string &name, std::string &email)
@ -863,10 +864,10 @@ int RsAccountsDetail::GetPGPLoginDetails(const RsPgpId& id, std::string &na
#endif #endif
bool ok = true ; bool ok = true ;
name = AuthGPG::getAuthGPG()->getGPGName(id,&ok); name = AuthGPG::getGPGName(id,&ok);
if(!ok) if(!ok)
return 0 ; return 0 ;
email = AuthGPG::getAuthGPG()->getGPGEmail(id,&ok); email = AuthGPG::getGPGEmail(id,&ok);
if(!ok) if(!ok)
return 0 ; return 0 ;
@ -886,7 +887,7 @@ bool RsAccountsDetail::SelectPGPAccount(const RsPgpId& pgpId)
{ {
bool retVal = false; bool retVal = false;
if (0 < AuthGPG::getAuthGPG() -> GPGInit(pgpId)) if (0 < AuthGPG::GPGInit(pgpId))
{ {
retVal = true; retVal = true;
#ifdef DEBUG_ACCOUNTS #ifdef DEBUG_ACCOUNTS
@ -906,7 +907,7 @@ bool RsAccountsDetail::SelectPGPAccount(const RsPgpId& pgpId)
bool RsAccountsDetail::GeneratePGPCertificate(const std::string& name, const std::string& email, const std::string& passwd, RsPgpId &pgpId, const int keynumbits, std::string &errString) bool RsAccountsDetail::GeneratePGPCertificate(const std::string& name, const std::string& email, const std::string& passwd, RsPgpId &pgpId, const int keynumbits, std::string &errString)
{ {
return AuthGPG::getAuthGPG()->GeneratePGPCertificate(name, email, passwd, pgpId, keynumbits, errString); return AuthGPG::GeneratePGPCertificate(name, email, passwd, pgpId, keynumbits, errString);
} }
// PGP Support Functions. // PGP Support Functions.
@ -918,24 +919,24 @@ void RsAccountsDetail::getUnsupportedKeys(std::map<std::string,std::vector<std::
bool RsAccountsDetail::exportIdentity(const std::string& fname,const RsPgpId& id) bool RsAccountsDetail::exportIdentity(const std::string& fname,const RsPgpId& id)
{ {
return AuthGPG::getAuthGPG()->exportProfile(fname,id); return AuthGPG::exportProfile(fname,id);
} }
bool RsAccountsDetail::importIdentity(const std::string& fname,RsPgpId& id,std::string& import_error) bool RsAccountsDetail::importIdentity(const std::string& fname,RsPgpId& id,std::string& import_error)
{ {
return AuthGPG::getAuthGPG()->importProfile(fname,id,import_error); return AuthGPG::importProfile(fname,id,import_error);
} }
bool RsAccountsDetail::importIdentityFromString(const std::string &data, RsPgpId &imported_pgp_id, std::string &import_error) bool RsAccountsDetail::importIdentityFromString(const std::string &data, RsPgpId &imported_pgp_id, std::string &import_error)
{ {
return AuthGPG::getAuthGPG()->importProfileFromString(data, imported_pgp_id, import_error); return AuthGPG::importProfileFromString(data, imported_pgp_id, import_error);
} }
bool RsAccountsDetail::exportIdentityToString( bool RsAccountsDetail::exportIdentityToString(
std::string& data, const RsPgpId& pgpId, bool includeSignatures, std::string& data, const RsPgpId& pgpId, bool includeSignatures,
std::string& errorMsg ) std::string& errorMsg )
{ {
return AuthGPG::getAuthGPG()->exportIdentityToString( return AuthGPG::exportIdentityToString(
data, pgpId, includeSignatures, errorMsg ); data, pgpId, includeSignatures, errorMsg );
} }
@ -1020,7 +1021,7 @@ bool RsAccountsDetail::GenerateSSLCertificate(const RsPgpId& pgp_id, const s
int nbits = 4096; int nbits = 4096;
//std::string pgp_name = AuthGPG::getAuthGPG()->getGPGName(pgp_id); //std::string pgp_name = AuthGPG::getGPGName(pgp_id);
// Create the filename ..... // Create the filename .....
// Temporary Directory for creating files.... // Temporary Directory for creating files....

View File

@ -510,7 +510,7 @@ RsInit::LoadCertificateStatus RsInit::LockAndLoadCertificates(
if(!RsAccounts::GetAccountDetails(accountId, pgpId, pgpName, pgpEmail, location)) if(!RsAccounts::GetAccountDetails(accountId, pgpId, pgpName, pgpEmail, location))
throw RsInit::ERR_UNKNOWN; // invalid PreferredAccount; throw RsInit::ERR_UNKNOWN; // invalid PreferredAccount;
if(0 == AuthGPG::getAuthGPG() -> GPGInit(pgpId)) if(0 == AuthGPG::GPGInit(pgpId))
throw RsInit::ERR_UNKNOWN; // PGP Error. throw RsInit::ERR_UNKNOWN; // PGP Error.
LoadCertificateStatus retVal = LoadCertificateStatus retVal =
@ -910,8 +910,8 @@ int RsServer::StartupRetroShare()
/* History Manager */ /* History Manager */
mHistoryMgr = new p3HistoryMgr(); mHistoryMgr = new p3HistoryMgr();
mPeerMgr = new p3PeerMgrIMPL( AuthSSL::getAuthSSL()->OwnId(), mPeerMgr = new p3PeerMgrIMPL( AuthSSL::getAuthSSL()->OwnId(),
AuthGPG::getAuthGPG()->getGPGOwnId(), AuthGPG::getGPGOwnId(),
AuthGPG::getAuthGPG()->getGPGOwnName(), AuthGPG::getGPGOwnName(),
AuthSSL::getAuthSSL()->getOwnLocation()); AuthSSL::getAuthSSL()->getOwnLocation());
mNetMgr = new p3NetMgrIMPL(); mNetMgr = new p3NetMgrIMPL();
mLinkMgr = new p3LinkMgrIMPL(mPeerMgr, mNetMgr); mLinkMgr = new p3LinkMgrIMPL(mPeerMgr, mNetMgr);
@ -1604,7 +1604,8 @@ int RsServer::StartupRetroShare()
//mConfigMgr->addConfiguration("ftserver.cfg", ftserver); //mConfigMgr->addConfiguration("ftserver.cfg", ftserver);
// //
mConfigMgr->addConfiguration("gpg_prefs.cfg" , AuthGPG::getAuthGPG()); AuthGPG::registerToConfigMgr(std::string("gpg_prefs.cfg"),mConfigMgr);
mConfigMgr->addConfiguration("gxsnettunnel.cfg", mGxsNetTunnel); mConfigMgr->addConfiguration("gxsnettunnel.cfg", mGxsNetTunnel);
mConfigMgr->addConfiguration("peers.cfg" , mPeerMgr); mConfigMgr->addConfiguration("peers.cfg" , mPeerMgr);
mConfigMgr->addConfiguration("general.cfg" , mGeneralConfig); mConfigMgr->addConfiguration("general.cfg" , mGeneralConfig);
@ -1792,7 +1793,7 @@ int RsServer::StartupRetroShare()
/* Add AuthGPG services */ /* Add AuthGPG services */
/**************************************************************************/ /**************************************************************************/
//AuthGPG::getAuthGPG()->addService(mDisc); //AuthGPG::addService(mDisc);
/**************************************************************************/ /**************************************************************************/
/* Force Any Last Configuration Options */ /* Force Any Last Configuration Options */

View File

@ -60,8 +60,7 @@ bool RsLoginHandler::checkAndStoreSSLPasswdIntoGPGFile(
return true ; return true ;
} }
bool ok = AuthGPG::getAuthGPG()->encryptTextToFile( bool ok = AuthGPG::encryptTextToFile( ssl_passwd, getSSLPasswdFileName(ssl_id));
ssl_passwd, getSSLPasswdFileName(ssl_id));
if (!ok) std::cerr << "Encrypting went wrong !" << std::endl; if (!ok) std::cerr << "Encrypting went wrong !" << std::endl;
@ -90,7 +89,7 @@ bool RsLoginHandler::getSSLPasswdFromGPGFile(const RsPeerId& ssl_id,std::string&
#endif #endif
std::string plain; std::string plain;
if ( AuthGPG::getAuthGPG()->decryptTextFromFile( plain, getSSLPasswdFileName(ssl_id)) ) if ( AuthGPG::decryptTextFromFile( plain, getSSLPasswdFileName(ssl_id)) )
{ {
sslPassword = plain; sslPassword = plain;
#ifdef DEBUG_RSLOGINHANDLER #ifdef DEBUG_RSLOGINHANDLER

View File

@ -1066,7 +1066,7 @@ bool p3IdService::createIdentity(uint32_t& token, RsIdentityParameters &params)
if(params.isPgpLinked) if(params.isPgpLinked)
{ {
ssdata.pgp.pgpId = AuthGPG::getAuthGPG()->getGPGOwnId(); ssdata.pgp.pgpId = AuthGPG::getGPGOwnId();
ssdata.pgp.lastCheckTs = time(nullptr); ssdata.pgp.lastCheckTs = time(nullptr);
} }
@ -3618,7 +3618,7 @@ RsGenExchange::ServiceCreate_Return p3IdService::service_CreateGroup(
unsigned int sign_size = MAX_SIGN_SIZE; unsigned int sign_size = MAX_SIGN_SIZE;
memset(signarray,0,MAX_SIGN_SIZE) ; // just in case. memset(signarray,0,MAX_SIGN_SIZE) ; // just in case.
int result = AuthGPG::getAuthGPG()->SignDataBin( int result = AuthGPG::SignDataBin(
static_cast<const void*>(hash.toByteArray()), static_cast<const void*>(hash.toByteArray()),
hash.SIZE_IN_BYTES, signarray, &sign_size, hash.SIZE_IN_BYTES, signarray, &sign_size,
__PRETTY_FUNCTION__ ) __PRETTY_FUNCTION__ )