mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-19 14:30:43 -04:00
added lock when generating new cert
git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-OpenPGP@5266 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
9a07328ac2
commit
419c8eafb5
1 changed files with 17 additions and 61 deletions
|
@ -81,7 +81,6 @@ PGPHandler::PGPHandler(const std::string& pubring, const std::string& secring,co
|
||||||
{
|
{
|
||||||
_pubring_changed = false ;
|
_pubring_changed = false ;
|
||||||
_trustdb_changed = false ;
|
_trustdb_changed = false ;
|
||||||
//_secring_changed = false ;
|
|
||||||
|
|
||||||
RsStackFileLock flck(_pgp_lock_filename) ; // lock access to PGP directory.
|
RsStackFileLock flck(_pgp_lock_filename) ; // lock access to PGP directory.
|
||||||
|
|
||||||
|
@ -356,7 +355,10 @@ bool PGPHandler::GeneratePGPCertificate(const std::string& name, const std::stri
|
||||||
ops_keyring_free(tmp_secring) ;
|
ops_keyring_free(tmp_secring) ;
|
||||||
free(tmp_secring) ;
|
free(tmp_secring) ;
|
||||||
|
|
||||||
// 3 - add key to secret keyring on disk.
|
// 5 - add key to secret keyring on disk.
|
||||||
|
|
||||||
|
{
|
||||||
|
RsStackFileLock flck(_pgp_lock_filename) ; // lock access to PGP directory.
|
||||||
|
|
||||||
cinfo = NULL ;
|
cinfo = NULL ;
|
||||||
int fd=ops_setup_file_append(&cinfo, _secring_path.c_str());
|
int fd=ops_setup_file_append(&cinfo, _secring_path.c_str());
|
||||||
|
@ -367,8 +369,9 @@ bool PGPHandler::GeneratePGPCertificate(const std::string& name, const std::stri
|
||||||
return false ;
|
return false ;
|
||||||
}
|
}
|
||||||
ops_teardown_file_write(cinfo,fd) ;
|
ops_teardown_file_write(cinfo,fd) ;
|
||||||
|
}
|
||||||
|
|
||||||
// 5 - copy the public key to the public keyring
|
// 6 - copy the public key to the public keyring
|
||||||
|
|
||||||
ops_memory_t *buf2 = NULL ;
|
ops_memory_t *buf2 = NULL ;
|
||||||
ops_setup_memory_write(&cinfo, &buf2, 0);
|
ops_setup_memory_write(&cinfo, &buf2, 0);
|
||||||
|
@ -396,13 +399,13 @@ bool PGPHandler::GeneratePGPCertificate(const std::string& name, const std::stri
|
||||||
std::cerr << "Added new public key with id " << pgpId.toStdString() << " to public keyring." << std::endl;
|
std::cerr << "Added new public key with id " << pgpId.toStdString() << " to public keyring." << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// 6 - clean
|
// 7 - clean
|
||||||
ops_keydata_free(key) ;
|
ops_keydata_free(key) ;
|
||||||
|
|
||||||
// 7 - Update flags.
|
// 8 - Update flags.
|
||||||
|
|
||||||
_pubring_changed = true ;
|
_pubring_changed = true ;
|
||||||
//_secring_changed = true ;
|
privateTrustCertificate(pgpId,PGPCertificateInfo::PGP_CERTIFICATE_TRUST_ULTIMATE) ;
|
||||||
|
|
||||||
return true ;
|
return true ;
|
||||||
}
|
}
|
||||||
|
@ -977,53 +980,6 @@ bool PGPHandler::locked_syncPublicKeyring()
|
||||||
return true ;
|
return true ;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef TO_BE_REMOVED
|
|
||||||
bool PGPHandler::locked_syncSecretKeyring()
|
|
||||||
{
|
|
||||||
struct stat64 buf ;
|
|
||||||
#ifdef WINDOWS_SYS
|
|
||||||
std::wstring wfullname;
|
|
||||||
librs::util::ConvertUtf8ToUtf16(_secring_path, wfullname);
|
|
||||||
if(-1 == _wstati64(wfullname.c_str(), &buf))
|
|
||||||
#else
|
|
||||||
if(-1 == stat64(_secring_path.c_str(), &buf))
|
|
||||||
#endif
|
|
||||||
std::cerr << "PGPHandler::syncDatabase(): can't stat file " << _secring_path << ". Can't sync secret keyring." << std::endl;
|
|
||||||
|
|
||||||
#ifdef TODO
|
|
||||||
if(_secring_last_update_time < buf.st_mtime)
|
|
||||||
{
|
|
||||||
std::cerr << "Detected change on disk of secret keyring. " << std::endl ;
|
|
||||||
secring_changed_on_disk = true ;
|
|
||||||
|
|
||||||
mergeKeyringFromDisk(_secring,_secret_keyring_map,_secring_path) ;
|
|
||||||
_secring_last_update_time = buf.st_mtime ;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
if(_secring_changed)
|
|
||||||
{
|
|
||||||
std::cerr << "Local changes in secret keyring. Writing to disk..." << std::endl;
|
|
||||||
|
|
||||||
fd=ops_setup_file_append(&cinfo, secring_name);
|
|
||||||
ops_write_transferable_secret_key(keydata, passphrase, pplen, ARMOUR_NO, cinfo);
|
|
||||||
ops_teardown_file_write(cinfo,fd)
|
|
||||||
|
|
||||||
if(!ops_write_keyring_to_file(_secring,ops_false,_secring_path.c_str()))
|
|
||||||
{
|
|
||||||
std::cerr << "Cannot write secret keyring. Disk full? Disk quota exceeded?" << std::endl;
|
|
||||||
return false ;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
std::cerr << "Done." << std::endl;
|
|
||||||
_secring_last_update_time = time(NULL) ; // should we get this value from the disk instead??
|
|
||||||
_secring_changed = false ;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true ;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
bool PGPHandler::locked_syncTrustDatabase()
|
bool PGPHandler::locked_syncTrustDatabase()
|
||||||
{
|
{
|
||||||
struct stat64 buf ;
|
struct stat64 buf ;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue