debugging of pgpkey parser and radix output form openpgpsdk

git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-OpenPGP@5061 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2012-03-29 21:51:37 +00:00
parent 51fa97ac59
commit 648555711c
5 changed files with 67 additions and 32 deletions

View file

@ -160,7 +160,7 @@ bool PGPHandler::GeneratePGPCertificate(const std::string& name, const std::stri
ops_user_id_t uid ;
const char *s = strdup((name + " " + email + " (Generated by RetroShare)").c_str()) ;
uid.user_id = (unsigned char *)s ;
unsigned long int e = 44497 ; // some prime number
unsigned long int e = 17 ; // some prime number
ops_keydata_t *key = ops_rsa_create_selfsigned_keypair(KEY_NUMBITS,e,&uid) ;
@ -171,25 +171,44 @@ bool PGPHandler::GeneratePGPCertificate(const std::string& name, const std::stri
// Now output the pubkey to a string.
//
std::string akey = makeRadixEncodedPGPKey(key) ;
std::cerr << "key: " << std::endl;
std::cerr << akey << std::endl;
ops_keydata_free(key) ;
return true ;
}
std::string PGPHandler::makeRadixEncodedPGPKey(const ops_keydata_t *key)
{
ops_boolean_t armoured=ops_true;
ops_boolean_t overwrite=ops_true;
ops_create_info_t* cinfo;
ops_memory_t *buf = NULL ;//(ops_memory_t*)ops_mallocz(1000) ;
ops_setup_memory_write(&cinfo, &buf, 0);
ops_writer_push_armoured(cinfo,OPS_PGP_PUBLIC_KEY_BLOCK) ;
//ops_writer_push_armoured(cinfo,OPS_PGP_SIGNATURE) ;
ops_write_transferable_public_key(key,armoured,cinfo);
//ops_writer_close(cinfo) ;
ops_writer_close(cinfo) ;
std::cerr << "Memory written: size = " << ops_memory_get_length(buf) << std::endl;
std::cerr << "String of key: " << std::endl;
std::cerr << std::string((char *)ops_memory_get_data(buf),ops_memory_get_length(buf)) << std::endl;
std::string akey((char *)ops_memory_get_data(buf),ops_memory_get_length(buf)) ;
//ops_teardown_memory_write(cinfo,buf);
ops_teardown_memory_write(cinfo,buf);
ops_keydata_free(key) ;
return true ;
return akey ;
}
std::string PGPHandler::SaveCertificateToString(const PGPIdType& id,bool include_signatures)
{
const ops_keydata_t *key = ops_keyring_find_key_by_id(_pubring,id.toByteArray());
if(key == NULL)
{
std::cerr << "Cannot output key " << id.toStdString() << ": not found in keyring." << std::endl;
return "" ;
}
return makeRadixEncodedPGPKey(key) ;
}

View file

@ -22,6 +22,7 @@ class PGPIdType
std::string toStdString() const ;
uint64_t toUInt64() const ;
const unsigned char *toByteArray() const { return &bytes[0] ; }
private:
unsigned char bytes[KEY_ID_SIZE] ;
@ -53,6 +54,8 @@ class PGPHandler
virtual void printKeys() const ;
private:
static std::string makeRadixEncodedPGPKey(const ops_keydata_t *key) ;
RsMutex pgphandlerMtx ;
ops_keyring_t *_pubring ;

View file

@ -50,6 +50,11 @@ int main(int argc,char *argv[])
else
std::cerr << "Certificate generation success. New id = " << newid.toStdString() << std::endl;
PGPIdType id2(std::string("EFD19E9DC737CA98")) ;
std::cerr << "Now extracting key " << id2.toStdString() << " from keyring:" << std::endl ;
std::string cert = pgph.SaveCertificateToString(id2,false) ;
std::cerr << cert << std::endl;
return 0 ;
}