proper save of keys with all signatures

git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-OpenPGP@5272 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2012-07-02 21:45:43 +00:00
parent 53416b85c3
commit da1c8a6aa3
4 changed files with 65 additions and 39 deletions

View file

@ -420,7 +420,7 @@ std::string PGPHandler::makeRadixEncodedPGPKey(const ops_keydata_t *key)
ops_memory_t *buf = NULL ; ops_memory_t *buf = NULL ;
ops_setup_memory_write(&cinfo, &buf, 0); ops_setup_memory_write(&cinfo, &buf, 0);
if(ops_write_transferable_public_key(key,armoured,cinfo) != ops_true) if(ops_write_transferable_public_key_from_packet_data(key,armoured,cinfo) != ops_true)
return "ERROR: This key cannot be processed by RetroShare because\nDSA certificates are not yet handled." ; return "ERROR: This key cannot be processed by RetroShare because\nDSA certificates are not yet handled." ;
ops_writer_close(cinfo) ; ops_writer_close(cinfo) ;

View file

@ -8,6 +8,7 @@
/****************************/ /****************************/
/* #define DEBUG_PGPUTIL 1 */ /* #define DEBUG_PGPUTIL 1 */
/****************************/ /****************************/
#define DEBUG_PGPUTIL 1
#define PGP_CRC24_INIT 0xB704CEL #define PGP_CRC24_INIT 0xB704CEL
#define PGP_CRC24_POLY 0x1864CFBL #define PGP_CRC24_POLY 0x1864CFBL

View file

@ -441,55 +441,78 @@ static ops_boolean_t write_secret_key_body(const ops_secret_key_t *key,
ops_boolean_t ops_write_transferable_public_key(const ops_keydata_t *keydata, ops_boolean_t ops_write_transferable_public_key(const ops_keydata_t *keydata,
ops_boolean_t armoured, ops_boolean_t armoured,
ops_create_info_t *info) ops_create_info_t *info)
{ {
ops_boolean_t rtn; ops_boolean_t rtn;
unsigned int i=0,j=0; unsigned int i=0,j=0;
if (armoured) if (armoured)
{ ops_writer_push_armoured(info, OPS_PGP_PUBLIC_KEY_BLOCK); } { ops_writer_push_armoured(info, OPS_PGP_PUBLIC_KEY_BLOCK); }
// public key // public key
rtn=ops_write_struct_public_key(&keydata->key.skey.public_key,info); rtn=ops_write_struct_public_key(&keydata->key.skey.public_key,info);
if (rtn!=ops_true) if (rtn!=ops_true)
return rtn; return rtn;
// TODO: revocation signatures go here // TODO: revocation signatures go here
// user ids and corresponding signatures // user ids and corresponding signatures
for (i=0; i<keydata->nuids; i++) for (i=0; i<keydata->nuids; i++)
{ {
ops_user_id_t* uid=&keydata->uids[i]; ops_user_id_t* uid=&keydata->uids[i];
rtn=ops_write_struct_user_id(uid, info); rtn=ops_write_struct_user_id(uid, info);
if (!rtn) if (!rtn)
return rtn; return rtn;
// find signature for this packet if it exists // find signature for this packet if it exists
for (j=0; j<keydata->nsigs; j++) for (j=0; j<keydata->nsigs; j++)
{ {
sigpacket_t* sig=&keydata->sigs[i]; sigpacket_t* sig=&keydata->sigs[i];
if (!strcmp((char *)sig->userid->user_id, (char *)uid->user_id)) if (!strcmp((char *)sig->userid->user_id, (char *)uid->user_id))
{ {
rtn=ops_write(sig->packet->raw, sig->packet->length, info); rtn=ops_write(sig->packet->raw, sig->packet->length, info);
if (!rtn) if (!rtn)
return !rtn; return !rtn;
} }
} }
} }
// TODO: user attributes and corresponding signatures // TODO: user attributes and corresponding signatures
// subkey packets and corresponding signatures and optional revocation // subkey packets and corresponding signatures and optional revocation
if (armoured) if (armoured)
{ {
writer_info_finalise(&info->errors, &info->winfo); writer_info_finalise(&info->errors, &info->winfo);
ops_writer_pop(info); ops_writer_pop(info);
} }
return rtn; return rtn;
} }
ops_boolean_t ops_write_transferable_public_key_from_packet_data(const ops_keydata_t *keydata,
ops_boolean_t armoured,
ops_create_info_t *info)
{
ops_boolean_t rtn = ops_true;
unsigned int i=0,j=0;
if (armoured)
{ ops_writer_push_armoured(info, OPS_PGP_PUBLIC_KEY_BLOCK); }
for(i=0;i<keydata->npackets;++i)
if(!ops_write(keydata->packets[i].raw, keydata->packets[i].length, info))
return ops_false ;
if (armoured)
{
writer_info_finalise(&info->errors, &info->winfo);
ops_writer_pop(info);
}
return rtn;
}
/** /**
\ingroup HighLevel_KeyWrite \ingroup HighLevel_KeyWrite

View file

@ -78,6 +78,8 @@ ops_boolean_t ops_write_pk_session_key(ops_create_info_t *info,
ops_pk_session_key_t *pksk); ops_pk_session_key_t *pksk);
ops_boolean_t ops_write_transferable_public_key(const ops_keydata_t *key, ops_boolean_t armoured, ops_create_info_t *info); ops_boolean_t ops_write_transferable_public_key(const ops_keydata_t *key, ops_boolean_t armoured, ops_create_info_t *info);
ops_boolean_t ops_write_transferable_secret_key(const ops_keydata_t *key, const unsigned char* passphrase, const size_t pplen, ops_boolean_t armoured, ops_create_info_t *info); ops_boolean_t ops_write_transferable_secret_key(const ops_keydata_t *key, const unsigned char* passphrase, const size_t pplen, ops_boolean_t armoured, ops_create_info_t *info);
ops_boolean_t ops_write_transferable_public_key_from_packet_data(const ops_keydata_t *keydata, ops_boolean_t armoured, ops_create_info_t *info);
#endif /*OPS_CREATE_H*/ #endif /*OPS_CREATE_H*/