From 0a6c60d2df6d8d4b43bf05156e99220505169c99 Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 8 Jul 2012 21:06:41 +0000 Subject: [PATCH] added filtering of private key for login window, and fixed uid at cert creation time git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-OpenPGP@5282 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/pgp/pgphandler.cc | 10 +++++++++- libretroshare/src/pgp/pgphandler.h | 1 + libretroshare/src/pqi/authgpg.cc | 5 ++++- libretroshare/src/pqi/authgpg.h | 1 + libretroshare/src/pqi/authssl.cc | 1 + libretroshare/src/rsserver/rsinit.cc | 3 +++ 6 files changed, 19 insertions(+), 2 deletions(-) diff --git a/libretroshare/src/pgp/pgphandler.cc b/libretroshare/src/pgp/pgphandler.cc index f9f6b04af..0e175ee42 100644 --- a/libretroshare/src/pgp/pgphandler.cc +++ b/libretroshare/src/pgp/pgphandler.cc @@ -157,6 +157,7 @@ PGPHandler::PGPHandler(const std::string& pubring, const std::string& secring,co std::cerr << "Secring read successfully." << std::endl; locked_readPrivateTrustDatabase() ; + _trustdb_last_update_time = time(NULL) ; } void PGPHandler::initCertificateInfo(PGPCertificateInfo& cert,const ops_keydata_t *keydata,uint32_t index) @@ -285,6 +286,13 @@ bool PGPHandler::printKeys() const return true ; } +bool PGPHandler::haveSecretKey(const PGPIdType& id) const +{ + RsStackMutex mtx(pgphandlerMtx) ; // lock access to PGP memory structures. + + return getSecretKey(id) != NULL ; +} + const PGPCertificateInfo *PGPHandler::getCertificateInfo(const PGPIdType& id) const { RsStackMutex mtx(pgphandlerMtx) ; // lock access to PGP memory structures. @@ -330,7 +338,7 @@ bool PGPHandler::GeneratePGPCertificate(const std::string& name, const std::stri // 1 - generate keypair - RSA-2048 // ops_user_id_t uid ; - char *s = strdup((name + " " + email + " (Generated by RetroShare)").c_str()) ; + char *s = strdup((name + " (Generated by RetroShare) <" + email + ">" ).c_str()) ; uid.user_id = (unsigned char *)s ; unsigned long int e = 65537 ; // some prime number diff --git a/libretroshare/src/pgp/pgphandler.h b/libretroshare/src/pgp/pgphandler.h index a08fc89f3..ef9e0e408 100644 --- a/libretroshare/src/pgp/pgphandler.h +++ b/libretroshare/src/pgp/pgphandler.h @@ -70,6 +70,7 @@ class PGPHandler * @param ids list of gpg certificate ids (note, not the actual certificates) */ bool getGPGFilteredList(std::list& list,bool (*filter)(const PGPCertificateInfo&) = NULL) const ; + bool haveSecretKey(const PGPIdType& id) const ; bool availableGPGCertificatesWithPrivateKeys(std::list& ids); bool GeneratePGPCertificate(const std::string& name, const std::string& email, const std::string& passwd, PGPIdType& pgpId, std::string& errString) ; diff --git a/libretroshare/src/pqi/authgpg.cc b/libretroshare/src/pqi/authgpg.cc index 4c60de07e..5bd0e0e4e 100644 --- a/libretroshare/src/pqi/authgpg.cc +++ b/libretroshare/src/pqi/authgpg.cc @@ -389,7 +389,10 @@ bool AuthGPG::getGPGAllList(std::list &ids) return true; } - +bool AuthGPG::haveSecretKey(const std::string& id) const +{ + return PGPHandler::haveSecretKey(PGPIdType(id)) ; +} bool AuthGPG::isKeySupported(const std::string& id) const { const PGPCertificateInfo *pc = PGPHandler::getCertificateInfo(PGPIdType(id)) ; diff --git a/libretroshare/src/pqi/authgpg.h b/libretroshare/src/pqi/authgpg.h index 017fd501c..39d353509 100644 --- a/libretroshare/src/pqi/authgpg.h +++ b/libretroshare/src/pqi/authgpg.h @@ -166,6 +166,7 @@ class AuthGPG: public p3Config, public RsThread, public PGPHandler //virtual std::string getGPGOwnEmail(); virtual bool isKeySupported(const std::string &id) const ; + virtual bool haveSecretKey(const std::string &id) const ; virtual bool getGPGDetails(const std::string &id, RsPeerDetails &d); virtual bool getGPGAllList(std::list &ids); virtual bool getGPGValidList(std::list &ids); diff --git a/libretroshare/src/pqi/authssl.cc b/libretroshare/src/pqi/authssl.cc index 25975f211..bb95a219b 100644 --- a/libretroshare/src/pqi/authssl.cc +++ b/libretroshare/src/pqi/authssl.cc @@ -54,6 +54,7 @@ /**** * #define AUTHSSL_DEBUG 1 ***/ + #define AUTHSSL_DEBUG 1 // initialisation du pointeur de singleton static AuthSSL *instance_ssl = NULL; diff --git a/libretroshare/src/rsserver/rsinit.cc b/libretroshare/src/rsserver/rsinit.cc index ec326b393..ae07170e5 100644 --- a/libretroshare/src/rsserver/rsinit.cc +++ b/libretroshare/src/rsserver/rsinit.cc @@ -1112,6 +1112,9 @@ static bool checkAccount(std::string accountdir, accountId &id) if(!AuthGPG::getAuthGPG()->isKeySupported(id.pgpId)) return false ; + if(!AuthGPG::getAuthGPG()->haveSecretKey(id.pgpId)) + return false ; + #ifdef GPG_DEBUG std::cerr << "PGPLoginDetails: " << id.pgpId << " name: " << id.pgpName; std::cerr << " email: " << id.pgpEmail << std::endl;