mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-29 09:26:18 -05:00
added keyring output
git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-OpenPGP@5131 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
60fcd981c1
commit
fcb202f666
@ -249,6 +249,16 @@ void PGPHandler::initCertificateInfo(PGPCertificateInfo& cert,const ops_keydata_
|
||||
ops_fingerprint(&f,&keydata->key.pkey) ;
|
||||
|
||||
cert._fpr = PGPFingerprintType(f.fingerprint) ;
|
||||
|
||||
// Parse signers.
|
||||
//
|
||||
|
||||
for(size_t i=0;i<keydata->nsigs;++i)
|
||||
{
|
||||
cert.signers.insert(std::string((const char *)keydata->sigs[i].userid->user_id)) ;
|
||||
|
||||
std::cerr << "Signature data packet size = " << keydata->sigs[i].packet->length << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
PGPHandler::~PGPHandler()
|
||||
@ -279,6 +289,7 @@ bool PGPHandler::printKeys() const
|
||||
std::cerr << "\ttrustLvl : " << it->second._trustLvl << std::endl;
|
||||
std::cerr << "\tvalidLvl : " << it->second._validLvl << std::endl;
|
||||
std::cerr << "\tfingerprint : " << it->second._fpr.toStdString() << std::endl;
|
||||
std::cerr << "\tSigners : " << it->second.signers.size() << std::endl;
|
||||
|
||||
std::set<std::string>::const_iterator sit;
|
||||
for(sit = it->second.signers.begin(); sit != it->second.signers.end(); sit++)
|
||||
@ -292,6 +303,9 @@ bool PGPHandler::printKeys() const
|
||||
std::cerr << std::endl ;
|
||||
}
|
||||
}
|
||||
std::cerr << "Public keyring list from OPS:" << std::endl;
|
||||
ops_keyring_list(_pubring) ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
@ -522,10 +536,13 @@ bool PGPHandler::LoadCertificateFromString(const std::string& pgp_cert,PGPIdType
|
||||
return true ;
|
||||
}
|
||||
|
||||
bool PGPHandler::writePublicKeyring(const std::string& outfilename) const
|
||||
{
|
||||
return ops_write_keyring_to_file(_pubring,ops_false,outfilename.c_str()) ;
|
||||
}
|
||||
|
||||
bool PGPHandler::encryptTextToFile(const PGPIdType& key_id,const std::string& text,const std::string& outfile)
|
||||
{
|
||||
const char* filename = "armour_nocompress_sign.asc";
|
||||
|
||||
ops_create_info_t *info;
|
||||
int fd = ops_setup_file_write(&info, outfile.c_str(), ops_true);
|
||||
|
||||
@ -538,7 +555,7 @@ bool PGPHandler::encryptTextToFile(const PGPIdType& key_id,const std::string& te
|
||||
}
|
||||
if (fd < 0)
|
||||
{
|
||||
fprintf(stderr, "Cannot write to %s\n", filename);
|
||||
std::cerr << "PGPHandler::encryptTextToFile(): ERROR: Cannot write to " << outfile << std::endl;
|
||||
return false ;
|
||||
}
|
||||
ops_encrypt_stream(info, public_key, NULL, ops_false, ops_true);
|
||||
@ -549,72 +566,6 @@ bool PGPHandler::encryptTextToFile(const PGPIdType& key_id,const std::string& te
|
||||
return true ;
|
||||
}
|
||||
|
||||
// ops_parse_cb_return_t pgphandler_callback_write_parsed(const ops_parser_content_t *content_, ops_parse_cb_info_t *cbinfo)
|
||||
// {
|
||||
// ops_parser_content_union_t* content =(ops_parser_content_union_t *)&content_->content;
|
||||
// static ops_boolean_t skipping;
|
||||
//
|
||||
// if(content_->tag != OPS_PTAG_CT_UNARMOURED_TEXT && skipping)
|
||||
// {
|
||||
// puts("...end of skip");
|
||||
// skipping=ops_false;
|
||||
// }
|
||||
//
|
||||
// switch(content_->tag)
|
||||
// {
|
||||
// case OPS_PTAG_CT_UNARMOURED_TEXT:
|
||||
// printf("OPS_PTAG_CT_UNARMOURED_TEXT\n");
|
||||
// if(!skipping)
|
||||
// {
|
||||
// puts("Skipping...");
|
||||
// skipping=ops_true;
|
||||
// }
|
||||
// fwrite(content->unarmoured_text.data, 1, content->unarmoured_text.length, stdout);
|
||||
// break;
|
||||
//
|
||||
// case OPS_PTAG_CT_PK_SESSION_KEY:
|
||||
// return callback_pk_session_key(content_, cbinfo);
|
||||
// break;
|
||||
//
|
||||
// case OPS_PARSER_CMD_GET_SECRET_KEY:
|
||||
// return callback_cmd_get_secret_key(content_, cbinfo);
|
||||
// break;
|
||||
//
|
||||
// case OPS_PARSER_CMD_GET_SK_PASSPHRASE:
|
||||
// // return callback_cmd_get_secret_key_passphrase(content_,cbinfo);
|
||||
// return cbinfo->cryptinfo.cb_get_passphrase(content_, cbinfo);
|
||||
// break;
|
||||
//
|
||||
// case OPS_PTAG_CT_LITERAL_DATA_BODY:
|
||||
// return callback_literal_data(content_, cbinfo);
|
||||
// break;
|
||||
//
|
||||
// case OPS_PTAG_CT_ARMOUR_HEADER:
|
||||
// case OPS_PTAG_CT_ARMOUR_TRAILER:
|
||||
// case OPS_PTAG_CT_ENCRYPTED_PK_SESSION_KEY:
|
||||
// case OPS_PTAG_CT_COMPRESSED:
|
||||
// case OPS_PTAG_CT_LITERAL_DATA_HEADER:
|
||||
// case OPS_PTAG_CT_SE_IP_DATA_BODY:
|
||||
// case OPS_PTAG_CT_SE_IP_DATA_HEADER:
|
||||
// case OPS_PTAG_CT_SE_DATA_BODY:
|
||||
// case OPS_PTAG_CT_SE_DATA_HEADER:
|
||||
//
|
||||
// // Ignore these packets
|
||||
// // They're handled in ops_parse_one_packet()
|
||||
// // and nothing else needs to be done
|
||||
// break;
|
||||
//
|
||||
// default:
|
||||
// // return callback_general(content_,cbinfo);
|
||||
// break;
|
||||
// // fprintf(stderr,"Unexpected packet tag=%d (0x%x)\n",content_->tag,
|
||||
// // content_->tag);
|
||||
// // assert(0);
|
||||
// }
|
||||
//
|
||||
// return OPS_RELEASE_MEMORY;
|
||||
// }
|
||||
|
||||
bool PGPHandler::decryptTextFromFile(const PGPIdType& key_id,std::string& text,const std::string& inputfile)
|
||||
{
|
||||
unsigned char *out_buf = NULL ;
|
||||
|
@ -117,9 +117,11 @@ class PGPHandler
|
||||
bool decryptTextFromFile(const PGPIdType& key_id,std::string& text,const std::string& inputfile) ;
|
||||
|
||||
bool getKeyFingerprint(const PGPIdType& id,PGPFingerprintType& fp) const ;
|
||||
|
||||
void setAcceptConnexion(const PGPIdType&,bool) ;
|
||||
|
||||
// Write keyring
|
||||
bool writePublicKeyring(const std::string& filename) const ;
|
||||
|
||||
// Debug stuff.
|
||||
virtual bool printKeys() const ;
|
||||
|
||||
@ -130,18 +132,15 @@ class PGPHandler
|
||||
bool isGPGAccepted(const std::string &id);
|
||||
|
||||
static void setPassphraseCallback(PassphraseCallback cb) ;
|
||||
|
||||
static PassphraseCallback passphraseCallback() { return _passphrase_callback ; }
|
||||
private:
|
||||
static std::string makeRadixEncodedPGPKey(const ops_keydata_t *key) ;
|
||||
static ops_keyring_t *allocateOPSKeyring() ;
|
||||
static void addNewKeyToOPSKeyring(ops_keyring_t*, const ops_keydata_t&) ;
|
||||
|
||||
void initCertificateInfo(PGPCertificateInfo& cert,const ops_keydata_t *keydata,uint32_t i) ;
|
||||
|
||||
const ops_keydata_t *getPublicKey(const PGPIdType&) const ;
|
||||
const ops_keydata_t *getSecretKey(const PGPIdType&) const ;
|
||||
|
||||
// Members.
|
||||
//
|
||||
RsMutex pgphandlerMtx ;
|
||||
|
||||
ops_keyring_t *_pubring ;
|
||||
@ -153,6 +152,11 @@ class PGPHandler
|
||||
const std::string _pubring_path ;
|
||||
const std::string _secring_path ;
|
||||
|
||||
// Helper functions.
|
||||
//
|
||||
static std::string makeRadixEncodedPGPKey(const ops_keydata_t *key) ;
|
||||
static ops_keyring_t *allocateOPSKeyring() ;
|
||||
static void addNewKeyToOPSKeyring(ops_keyring_t*, const ops_keydata_t&) ;
|
||||
static PassphraseCallback _passphrase_callback ;
|
||||
};
|
||||
|
||||
|
@ -43,6 +43,9 @@ int main(int argc,char *argv[])
|
||||
PGPHandler::setPassphraseCallback(&passphrase_callback) ;
|
||||
PGPHandler pgph(pubring,secring) ;
|
||||
|
||||
std::cerr << "Writing public keyring to file tmp_keyring.asc" << std::endl;
|
||||
pgph.writePublicKeyring("tmp_keyring.asc") ;
|
||||
|
||||
pgph.printKeys() ;
|
||||
|
||||
std::cerr << std::endl ;
|
||||
|
@ -63,6 +63,7 @@ ops_secret_key_t *ops_decrypt_secret_key_from_data(const ops_keydata_t *key,
|
||||
|
||||
ops_boolean_t ops_keyring_read_from_file(ops_keyring_t *keyring, const ops_boolean_t armour, const char *filename);
|
||||
ops_boolean_t ops_keyring_read_from_mem(ops_keyring_t *keyring, const ops_boolean_t armour, ops_memory_t *mem);
|
||||
ops_boolean_t ops_write_keyring_to_file(const ops_keyring_t *keyring,ops_boolean_t armoured,const char *filename);
|
||||
|
||||
char *ops_malloc_passphrase(char *passphrase);
|
||||
char *ops_get_passphrase(void);
|
||||
|
@ -956,26 +956,53 @@ ops_keyring_list(const ops_keyring_t* keyring)
|
||||
static ops_parse_cb_return_t
|
||||
cb_keyring_read(const ops_parser_content_t *content_,
|
||||
ops_parse_cb_info_t *cbinfo)
|
||||
{
|
||||
OPS_USED(cbinfo);
|
||||
{
|
||||
OPS_USED(cbinfo);
|
||||
|
||||
switch(content_->tag)
|
||||
{
|
||||
case OPS_PARSER_PTAG:
|
||||
case OPS_PTAG_CT_ENCRYPTED_SECRET_KEY: // we get these because we didn't prompt
|
||||
case OPS_PTAG_CT_SIGNATURE_HEADER:
|
||||
case OPS_PTAG_CT_SIGNATURE_FOOTER:
|
||||
case OPS_PTAG_CT_SIGNATURE:
|
||||
case OPS_PTAG_CT_TRUST:
|
||||
case OPS_PARSER_ERRCODE:
|
||||
break;
|
||||
switch(content_->tag)
|
||||
{
|
||||
case OPS_PARSER_PTAG:
|
||||
case OPS_PTAG_CT_ENCRYPTED_SECRET_KEY: // we get these because we didn't prompt
|
||||
case OPS_PTAG_CT_SIGNATURE_HEADER:
|
||||
case OPS_PTAG_CT_SIGNATURE_FOOTER:
|
||||
case OPS_PTAG_CT_SIGNATURE:
|
||||
case OPS_PTAG_CT_TRUST:
|
||||
case OPS_PARSER_ERRCODE:
|
||||
break;
|
||||
|
||||
default:
|
||||
;
|
||||
default:
|
||||
;
|
||||
}
|
||||
|
||||
return OPS_RELEASE_MEMORY;
|
||||
}
|
||||
return OPS_RELEASE_MEMORY;
|
||||
}
|
||||
|
||||
ops_boolean_t ops_write_keyring_to_file(const ops_keyring_t *keyring,ops_boolean_t armoured,const char *filename)
|
||||
{
|
||||
ops_create_info_t *info;
|
||||
int fd = ops_setup_file_write(&info, filename, ops_true);
|
||||
|
||||
if (fd < 0)
|
||||
{
|
||||
fprintf(stderr,"ops_write_keyring(): ERROR: Cannot write to %s\n",filename ) ;
|
||||
return ops_false ;
|
||||
}
|
||||
|
||||
int i;
|
||||
for(i=0;i<keyring->nkeys;++i)
|
||||
if(keyring->keys[i].key.pkey.algorithm == OPS_PKA_RSA)
|
||||
ops_write_transferable_public_key(&keyring->keys[i],armoured,info) ;
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "ops_write_keyring: not writing key. Algorithm not handled: ") ;
|
||||
ops_print_public_keydata(&keyring->keys[i]);
|
||||
}
|
||||
|
||||
ops_writer_close(info);
|
||||
ops_create_info_delete(info);
|
||||
|
||||
return ops_true ;
|
||||
}
|
||||
|
||||
/*\@}*/
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user