- added profile import/creation
- fixed leaking file descriptors
- added upload handler for small files
- fixed terminal thread
- removed some unused parameter warnings

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@8485 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
electron128 2015-06-16 12:35:07 +00:00
parent 3ed1be74a6
commit 8fc3917c4b
21 changed files with 1343 additions and 121 deletions

View file

@ -783,8 +783,39 @@ bool PGPHandler::importGPGKeyPair(const std::string& filename,RsPgpId& imported_
if(ops_false == ops_keyring_read_from_file(tmp_keyring, ops_true, filename.c_str()))
{
import_error = "PGPHandler::readKeyRing(): cannot read key file. File corrupted?" ;
free(tmp_keyring);
return false ;
}
return checkAndImportKeyPair(tmp_keyring, imported_key_id, import_error);
}
bool PGPHandler::importGPGKeyPairFromString(const std::string &data, RsPgpId &imported_key_id, std::string &import_error)
{
import_error = "" ;
ops_memory_t* mem = ops_memory_new();
ops_memory_add(mem, (unsigned char*)data.data(), data.length());
ops_keyring_t *tmp_keyring = allocateOPSKeyring();
if(ops_false == ops_keyring_read_from_mem(tmp_keyring, ops_true, mem))
{
import_error = "PGPHandler::importGPGKeyPairFromString(): cannot parse key data" ;
free(tmp_keyring);
return false ;
}
return checkAndImportKeyPair(tmp_keyring, imported_key_id, import_error);
}
bool PGPHandler::checkAndImportKeyPair(ops_keyring_t *tmp_keyring, RsPgpId &imported_key_id, std::string &import_error)
{
if(tmp_keyring == 0)
{
import_error = "PGPHandler::checkAndImportKey(): keyring is null" ;
return false;
}
if(tmp_keyring->nkeys != 2)
{
import_error = "PGPHandler::importKeyPair(): file does not contain a valid keypair." ;
@ -923,6 +954,7 @@ bool PGPHandler::importGPGKeyPair(const std::string& filename,RsPgpId& imported_
// 6 - clean
//
ops_keyring_free(tmp_keyring) ;
free(tmp_keyring);
// write public key to disk
syncDatabase();

View file

@ -74,6 +74,7 @@ class PGPHandler
bool haveSecretKey(const RsPgpId& id) const ;
bool importGPGKeyPair(const std::string& filename,RsPgpId& imported_id,std::string& import_error) ;
bool importGPGKeyPairFromString(const std::string& data,RsPgpId& imported_id,std::string& import_error) ;
bool exportGPGKeyPair(const std::string& filename,const RsPgpId& exported_id) const ;
bool availableGPGCertificatesWithPrivateKeys(std::list<RsPgpId>& ids);
@ -152,6 +153,14 @@ class PGPHandler
//
bool validateAndUpdateSignatures(PGPCertificateInfo& cert,const ops_keydata_t *keydata) ;
/** Check public/private key and import them into the keyring
* @param keyring keyring with the new public/private key pair. Will be freed by the function.
* @param imported_key_id PGP id of the imported key
* @param import_error human readbale error message
* @returns true on success
* */
bool checkAndImportKeyPair(ops_keyring_t *keyring, RsPgpId& imported_key_id,std::string& import_error);
const ops_keydata_t *locked_getPublicKey(const RsPgpId&,bool stamp_the_key) const;
const ops_keydata_t *locked_getSecretKey(const RsPgpId&) const ;

View file

@ -318,6 +318,11 @@ bool AuthGPG::importProfile(const std::string& fname,RsPgpId& imported_id,std::s
return PGPHandler::importGPGKeyPair(fname,imported_id,import_error) ;
}
bool AuthGPG::importProfileFromString(const std::string &data, RsPgpId &gpg_id, std::string &import_error)
{
return PGPHandler::importGPGKeyPairFromString(data, gpg_id, import_error);
}
bool AuthGPG::active()
{

View file

@ -164,6 +164,7 @@ class AuthGPG: public p3Config, public RsTickingThread, public PGPHandler
virtual bool getGPGAcceptedList(std::list<RsPgpId> &ids);
virtual bool getGPGSignedList(std::list<RsPgpId> &ids);
virtual bool importProfile(const std::string& filename,RsPgpId& gpg_id,std::string& import_error) ;
virtual bool importProfileFromString(const std::string& data,RsPgpId& gpg_id,std::string& import_error) ;
virtual bool exportProfile(const std::string& filename,const RsPgpId& gpg_id) ;
virtual bool removeKeysFromPGPKeyring(const std::set<RsPgpId> &pgp_ids,std::string& backup_file,uint32_t& error_code) ;

View file

@ -144,6 +144,7 @@ namespace RsAccounts
// PGP Support Functions.
bool ExportIdentity(const std::string& fname,const RsPgpId& pgp_id) ;
bool ImportIdentity(const std::string& fname,RsPgpId& imported_pgp_id,std::string& import_error) ;
bool ImportIdentityFromString(const std::string& data,RsPgpId& imported_pgp_id,std::string& import_error) ;
void GetUnsupportedKeys(std::map<std::string,std::vector<std::string> > &unsupported_keys);
bool CopyGnuPGKeyrings() ;

View file

@ -904,6 +904,11 @@ bool RsAccountsDetail::importIdentity(const std::string& fname,RsPgpId& id,std::
return AuthGPG::getAuthGPG()->importProfile(fname,id,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);
}
bool RsAccountsDetail::copyGnuPGKeyrings()
{
std::string pgp_dir = PathPGPDirectory() ;
@ -1284,6 +1289,11 @@ bool RsAccounts::ImportIdentity(const std::string& fname,RsPgpId& imported_pg
return rsAccounts->importIdentity(fname,imported_pgp_id,import_error);
}
bool RsAccounts::ImportIdentityFromString(const std::string& data,RsPgpId& imported_pgp_id,std::string& import_error)
{
return rsAccounts->importIdentityFromString(data,imported_pgp_id,import_error);
}
void RsAccounts::GetUnsupportedKeys(std::map<std::string,std::vector<std::string> > &unsupported_keys)
{
return rsAccounts->getUnsupportedKeys(unsupported_keys);

View file

@ -98,6 +98,7 @@ class RsAccountsDetail
// PGP Support Functions.
bool exportIdentity(const std::string& fname,const RsPgpId& pgp_id) ;
bool importIdentity(const std::string& fname,RsPgpId& imported_pgp_id,std::string& import_error) ;
bool importIdentityFromString(const std::string& data,RsPgpId& imported_pgp_id,std::string& import_error) ;
void getUnsupportedKeys(std::map<std::string,std::vector<std::string> > &unsupported_keys);
bool copyGnuPGKeyrings() ;