2012-03-26 17:17:04 -04:00
|
|
|
// This class implements an abstract pgp handler to be used in RetroShare.
|
|
|
|
//
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <string>
|
|
|
|
#include <list>
|
|
|
|
#include <util/rsthreads.h>
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
#include <openpgpsdk/types.h>
|
|
|
|
#include <openpgpsdk/keyring.h>
|
2012-03-27 16:48:21 -04:00
|
|
|
#include <openpgpsdk/keyring_local.h>
|
2012-03-26 17:17:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
class PGPIdType
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static const int KEY_ID_SIZE = 8 ;
|
|
|
|
|
2012-03-27 16:48:21 -04:00
|
|
|
PGPIdType() {}
|
2012-03-26 17:17:04 -04:00
|
|
|
PGPIdType(const std::string& hex_string) ;
|
|
|
|
PGPIdType(const unsigned char bytes[]) ;
|
|
|
|
|
|
|
|
std::string toStdString() const ;
|
|
|
|
uint64_t toUInt64() const ;
|
2012-03-29 17:51:37 -04:00
|
|
|
const unsigned char *toByteArray() const { return &bytes[0] ; }
|
2012-03-26 17:17:04 -04:00
|
|
|
|
|
|
|
private:
|
|
|
|
unsigned char bytes[KEY_ID_SIZE] ;
|
|
|
|
};
|
|
|
|
|
|
|
|
class PGPHandler
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PGPHandler(const std::string& path_to_public_keyring, const std::string& path_to_secret_keyring) ;
|
|
|
|
|
|
|
|
virtual ~PGPHandler() ;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param ids list of gpg certificate ids (note, not the actual certificates)
|
|
|
|
*/
|
|
|
|
|
|
|
|
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) ;
|
|
|
|
|
|
|
|
bool LoadCertificateFromString(const std::string& pem, PGPIdType& gpg_id, std::string& error_string);
|
|
|
|
std::string SaveCertificateToString(const PGPIdType& id,bool include_signatures) ;
|
|
|
|
|
|
|
|
bool TrustCertificate(const PGPIdType& id, int trustlvl);
|
|
|
|
|
|
|
|
virtual bool SignDataBin(const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen) { return false ; }
|
|
|
|
virtual bool VerifySignBin(const void*, uint32_t, unsigned char*, unsigned int, const std::string &withfingerprint) { return false ; }
|
|
|
|
|
|
|
|
// Debug stuff.
|
2012-03-27 16:48:21 -04:00
|
|
|
virtual void printKeys() const ;
|
2012-03-26 17:17:04 -04:00
|
|
|
|
|
|
|
private:
|
2012-03-29 17:51:37 -04:00
|
|
|
static std::string makeRadixEncodedPGPKey(const ops_keydata_t *key) ;
|
|
|
|
|
2012-03-26 17:17:04 -04:00
|
|
|
RsMutex pgphandlerMtx ;
|
|
|
|
|
|
|
|
ops_keyring_t *_pubring ;
|
|
|
|
ops_keyring_t *_secring ;
|
|
|
|
|
|
|
|
const std::string _pubring_path ;
|
|
|
|
const std::string _secring_path ;
|
|
|
|
};
|