implemented export of identity (to create additional locations easily). Import still to do...

git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-OpenPGP@5285 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2012-07-10 21:40:53 +00:00
parent 2ca0bf71d0
commit c9eb267165
11 changed files with 263 additions and 88 deletions

View file

@ -434,9 +434,23 @@ std::string PGPHandler::makeRadixEncodedPGPKey(const ops_keydata_t *key)
ops_memory_t *buf = NULL ;
ops_setup_memory_write(&cinfo, &buf, 0);
const unsigned char *passphrase = NULL ;
if(ops_write_transferable_public_key_from_packet_data(key,armoured,cinfo) != ops_true)
return "ERROR: This key cannot be processed by RetroShare because\nDSA certificates are not yet handled." ;
if(key->type == OPS_PTAG_CT_PUBLIC_KEY)
{
if(ops_write_transferable_public_key_from_packet_data(key,armoured,cinfo) != ops_true)
return "ERROR: This key cannot be processed by RetroShare because\nDSA certificates are not yet handled." ;
}
else if(key->type == OPS_PTAG_CT_ENCRYPTED_SECRET_KEY)
{
if(ops_write_transferable_secret_key_from_packet_data(key,armoured,cinfo) != ops_true)
return "ERROR: This key cannot be processed by RetroShare because\nDSA certificates are not yet handled." ;
}
else
{
std::cerr << "Unhandled key type " << key->type << std::endl;
return "ERROR: Cannot write key. Unhandled key type. " ;
}
ops_writer_close(cinfo) ;
@ -480,6 +494,45 @@ std::string PGPHandler::SaveCertificateToString(const PGPIdType& id,bool include
return makeRadixEncodedPGPKey(key) ;
}
bool PGPHandler::exportGPGKeyPair(const std::string& filename,const PGPIdType& exported_key_id) const
{
RsStackMutex mtx(pgphandlerMtx) ; // lock access to PGP memory structures.
const ops_keydata_t *pubkey = getPublicKey(exported_key_id) ;
if(pubkey == NULL)
{
std::cerr << "Cannot output key " << exported_key_id.toStdString() << ": not found in public keyring." << std::endl;
return false ;
}
const ops_keydata_t *seckey = getSecretKey(exported_key_id) ;
if(seckey == NULL)
{
std::cerr << "Cannot output key " << exported_key_id.toStdString() << ": not found in secret keyring." << std::endl;
return false ;
}
FILE *f = fopen(filename.c_str(),"w") ;
if(f == NULL)
{
std::cerr << "Cannot output key " << exported_key_id.toStdString() << ": file " << filename << " cannot be written. Please check for permissions, quotas, disk space." << std::endl;
return false ;
}
fprintf(f,"%s\n", makeRadixEncodedPGPKey(pubkey).c_str()) ;
fprintf(f,"%s\n", makeRadixEncodedPGPKey(seckey).c_str()) ;
fclose(f) ;
return true ;
}
bool PGPHandler::importGPGKeyPair(const std::string& filename,PGPIdType& imported_key_id)
{
std::cerr << "Import key not yet implemented!!" << std::endl;
return false ;
}
void PGPHandler::addNewKeyToOPSKeyring(ops_keyring_t *kr,const ops_keydata_t& key)
{
kr->keys = (ops_keydata_t*)realloc(kr->keys,(kr->nkeys+1)*sizeof(ops_keydata_t)) ;

View file

@ -72,6 +72,9 @@ class PGPHandler
bool getGPGFilteredList(std::list<PGPIdType>& list,bool (*filter)(const PGPCertificateInfo&) = NULL) const ;
bool haveSecretKey(const PGPIdType& id) const ;
bool importGPGKeyPair(const std::string& filename,PGPIdType& imported_id) ;
bool exportGPGKeyPair(const std::string& filename,const PGPIdType& exported_id) 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) ;

View file

@ -292,14 +292,30 @@ bool AuthGPG::VerifySignature(const void *data, int datalen, const void *sig, un
{
if(withfingerprint.length() != 40)
{
std::cerr << "WARNING: Still need to implement signature verification from complete keyring." << std::endl;
std::cerr << "AuthGPG::VerifySignature(): no (or dammaged) fingerprint. Nor verifying signature. This is likely to be an unknown peer. fingerprint=\"" << withfingerprint << "\"." << std::endl;
return false ;
}
return PGPHandler::VerifySignBin((unsigned char*)data,datalen,(unsigned char*)sig,siglen,PGPFingerprintType(withfingerprint)) ;
}
bool AuthGPG::exportProfile(const std::string& fname,const std::string& exported_id)
{
return PGPHandler::exportGPGKeyPair(fname,PGPIdType(exported_id)) ;
}
bool AuthGPG::importProfile(const std::string& fname,std::string& imported_id)
{
PGPIdType id ;
if(PGPHandler::importGPGKeyPair(fname,id))
{
imported_id = id.toStdString() ;
return true ;
}
else
return false ;
}
bool AuthGPG::active()

View file

@ -172,6 +172,8 @@ class AuthGPG: public p3Config, public RsThread, public PGPHandler
virtual bool getGPGValidList(std::list<std::string> &ids);
virtual bool getGPGAcceptedList(std::list<std::string> &ids);
virtual bool getGPGSignedList(std::list<std::string> &ids);
virtual bool importProfile(const std::string& filename,std::string& gpg_id) ;
virtual bool exportProfile(const std::string& filename,const std::string& gpg_id) ;
/*********************************************************************************/
/************************* STAGE 4 ***********************************************/

View file

@ -80,6 +80,8 @@ class RsInit
static bool ValidateCertificate(std::string &userName) ;
static bool exportIdentity(const std::string& fname,const std::string& pgp_id) ;
static bool importIdentity(const std::string& fname,std::string& imported_pgp_id) ;
/*!
* Generating GPGme Account

View file

@ -708,6 +708,16 @@ int RsInit::InitRetroShare(int argcIgnored, char **argvIgnored, bool strictCheck
/**************************** Access Functions for Init Data **************************/
bool RsInit::exportIdentity(const std::string& fname,const std::string& id)
{
return AuthGPG::getAuthGPG()->exportProfile(fname,id);
}
bool RsInit::importIdentity(const std::string& fname,std::string& id)
{
return AuthGPG::getAuthGPG()->importProfile(fname,id);
}
bool RsInit::copyGnuPGKeyrings()
{
std::string pgp_dir = RsInitConfig::basedir + "/pgp" ;