fixed adding self signature at certificate generation

git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-OpenPGP@5271 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2012-07-02 20:46:14 +00:00
parent b3b7fc3475
commit 53416b85c3
3 changed files with 38 additions and 30 deletions

View File

@ -200,7 +200,7 @@ void PGPHandler::initCertificateInfo(PGPCertificateInfo& cert,const ops_keydata_
cert._flags |= PGPCertificateInfo::PGP_CERTIFICATE_FLAG_UNSUPPORTED_ALGORITHM ;
}
void PGPHandler::validateAndUpdateSignatures(PGPCertificateInfo& cert,const ops_keydata_t *keydata)
bool PGPHandler::validateAndUpdateSignatures(PGPCertificateInfo& cert,const ops_keydata_t *keydata)
{
ops_validate_result_t* result=(ops_validate_result_t*)ops_mallocz(sizeof *result);
ops_boolean_t res = ops_validate_key_signatures(result,keydata,_pubring,cb_get_passphrase) ;
@ -208,14 +208,26 @@ void PGPHandler::validateAndUpdateSignatures(PGPCertificateInfo& cert,const ops_
if(res == ops_false)
std::cerr << "(EE) Error in PGPHandler::validateAndUpdateSignatures(). Validation failed for at least some signatures." << std::endl;
bool ret = false ;
// Parse signers.
//
if(result != NULL)
for(size_t i=0;i<result->valid_count;++i)
cert.signers.insert(PGPIdType(result->valid_sigs[i].signer_id).toStdString()) ;
{
std::string signer_str = PGPIdType(result->valid_sigs[i].signer_id).toStdString() ;
if(cert.signers.find(signer_str) == cert.signers.end())
{
cert.signers.insert(signer_str) ;
ret = true ;
}
}
ops_validate_result_free(result) ;
return ret ;
}
PGPHandler::~PGPHandler()
@ -369,43 +381,32 @@ bool PGPHandler::GeneratePGPCertificate(const std::string& name, const std::stri
}
ops_teardown_file_write(cinfo,fd) ;
// 6 - copy the public key to the public keyring
// 6 - copy the public key to the public keyring on disk
ops_memory_t *buf2 = NULL ;
ops_setup_memory_write(&cinfo, &buf2, 0);
cinfo = NULL ;
fd=ops_setup_file_append(&cinfo, _pubring_path.c_str());
if(!ops_write_transferable_public_key(key, ops_false, cinfo))
{
std::cerr << "(EE) Cannot encode secret key to memory!!" << std::endl;
return false ;
}
ops_keyring_t *tmp_pubring = allocateOPSKeyring() ;
if(! ops_keyring_read_from_mem(tmp_pubring, ops_false, buf2))
{
std::cerr << "(EE) Cannot re-read key from memory!!" << std::endl;
return false ;
}
ops_teardown_memory_write(cinfo,buf2); // cleanup memory
if(!addOrMergeKey(_pubring,_public_keyring_map,&tmp_pubring->keys[0]))
{
std::cerr << "(EE) Cannot add new key to keyring. Conflict in GPG ids?" << std::endl;
return false ;
}
ops_keyring_free(tmp_pubring) ;
free(tmp_pubring) ;
#ifdef DEBUG_PGPHANDLER
std::cerr << "Added new public key with id " << pgpId.toStdString() << " to public keyring." << std::endl;
#endif
ops_teardown_file_write(cinfo,fd) ;
// 7 - clean
ops_keydata_free(key) ;
// 8 - Update some flags.
// 8 - re-read the key from the public keyring, and add it to memory.
_pubring_last_update_time = 0 ; // force update pubring from disk.
locked_syncPublicKeyring() ;
#ifdef DEBUG_PGPHANDLER
std::cerr << "Added new public key with id " << pgpId.toStdString() << " to public keyring." << std::endl;
#endif
// 9 - Update some flags.
_pubring_changed = true ;
privateTrustCertificate(pgpId,PGPCertificateInfo::PGP_CERTIFICATE_TRUST_ULTIMATE) ;
return true ;

View File

@ -120,7 +120,10 @@ class PGPHandler
private:
void initCertificateInfo(PGPCertificateInfo& cert,const ops_keydata_t *keydata,uint32_t i) ;
void validateAndUpdateSignatures(PGPCertificateInfo& cert,const ops_keydata_t *keydata) ;
// Returns true if the signatures have been updated
//
bool validateAndUpdateSignatures(PGPCertificateInfo& cert,const ops_keydata_t *keydata) ;
const ops_keydata_t *getPublicKey(const PGPIdType&) const ;
const ops_keydata_t *getSecretKey(const PGPIdType&) const ;
@ -130,7 +133,6 @@ class PGPHandler
bool locked_syncPublicKeyring() ;
bool locked_syncTrustDatabase() ;
//bool locked_syncSecretKeyring() ;
void mergeKeyringFromDisk(ops_keyring_t *keyring, std::map<std::string,PGPCertificateInfo>& kmap, const std::string& keyring_file) ;
bool addOrMergeKey(ops_keyring_t *keyring,std::map<std::string,PGPCertificateInfo>& kmap,const ops_keydata_t *keydata) ;
@ -152,7 +154,6 @@ class PGPHandler
bool _pubring_changed ;
bool _trustdb_changed ;
//bool _secring_changed ;
time_t _pubring_last_update_time ;
time_t _secring_last_update_time ;

View File

@ -40,7 +40,13 @@ int main(int argc,char *argv[])
throw std::runtime_error("PGPHandler::readKeyRing(): cannot read key file. File corrupted, or missing/superfluous armour parameter.") ;
for(int i=0;i<kr->nkeys;++i)
{
ops_print_public_keydata(&kr->keys[i]) ;
ops_print_public_keydata_verbose(&kr->keys[i]) ;
ops_print_public_key(&kr->keys[i].key.pkey) ;
}
ops_list_packets(const_cast<char *>(keyfile.c_str()),armoured,kr,NULL) ;
return 0 ;
}