added caching of GPG information to PGPHandler

git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-OpenPGP@5086 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2012-04-09 17:03:47 +00:00
parent b43fb7e8b3
commit fa429ad8d4
5 changed files with 316 additions and 479 deletions

View file

@ -6,6 +6,7 @@
#include <string>
#include <list>
#include <map>
#include <set>
#include <util/rsthreads.h>
extern "C" {
@ -33,6 +34,7 @@ class PGPIdType
private:
unsigned char bytes[KEY_ID_SIZE] ;
std::string _string_id ;
};
class PGPFingerprintType
{
@ -60,6 +62,32 @@ class PGPFingerprintType
PGPFingerprintType() {}
private:
unsigned char bytes[KEY_FINGERPRINT_SIZE] ;
std::string _string_id ;
};
class PGPCertificateInfo
{
public:
PGPCertificateInfo() {}
std::string _name;
std::string _email;
std::string _comment;
std::set<std::string> signers;
uint32_t _trustLvl;
uint32_t _validLvl;
uint32_t _flags ;
PGPFingerprintType _fpr; /* fingerprint */
PGPIdType _key_id ;
uint32_t _key_index ; // index to array of keys in the public keyring
static const uint32_t PGP_CERTIFICATE_FLAG_ACCEPT_CONNEXION = 0x0001 ;
static const uint32_t PGP_CERTIFICATE_FLAG_HAS_OWN_SIGNATURE = 0x0002 ;
static const uint32_t PGP_CERTIFICATE_FLAG_HAS_SIGNED_ME = 0x0004 ;
};
class PGPHandler
@ -72,6 +100,7 @@ class PGPHandler
/**
* @param ids list of gpg certificate ids (note, not the actual certificates)
*/
bool getGPGFilteredList(std::list<PGPIdType>& list,bool (*filter)(const PGPCertificateInfo&) = NULL) const ;
bool availableGPGCertificatesWithPrivateKeys(std::list<PGPIdType>& ids);
bool GeneratePGPCertificate(const std::string& name, const std::string& email, const std::string& passwd, PGPIdType& pgpId, std::string& errString) ;
@ -89,14 +118,24 @@ class PGPHandler
bool getKeyFingerprint(const PGPIdType& id,PGPFingerprintType& fp) const ;
void setAcceptConnexion(const PGPIdType&,bool) ;
// Debug stuff.
virtual void printKeys() const ;
virtual bool printKeys() const ;
const PGPCertificateInfo *getCertificateInfo(const PGPIdType& id) const ;
bool isGPGId(const std::string &id);
bool isGPGSigned(const std::string &id);
bool isGPGAccepted(const std::string &id);
private:
static std::string makeRadixEncodedPGPKey(const ops_keydata_t *key) ;
static ops_keyring_t *allocateOPSKeyring() ;
static void addNewKeyToOPSKeyring(ops_keyring_t*, const ops_keydata_t&) ;
void initCertificateInfo(PGPCertificateInfo& cert,const ops_keydata_t *keydata,uint32_t i) ;
const ops_keydata_t *getPublicKey(const PGPIdType&) const ;
const ops_keydata_t *getSecretKey(const PGPIdType&) const ;
@ -105,8 +144,8 @@ class PGPHandler
ops_keyring_t *_pubring ;
ops_keyring_t *_secring ;
std::map<uint64_t,uint32_t> _public_keyring_map ; // used for fast access to keys. Gives the index in the keyring.
std::map<uint64_t,uint32_t> _secret_keyring_map ;
std::map<std::string,PGPCertificateInfo> _public_keyring_map ; // used for fast access to keys. Gives the index in the keyring.
std::map<std::string,PGPCertificateInfo> _secret_keyring_map ;
const std::string _pubring_path ;
const std::string _secring_path ;