mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-02 06:06:10 -04:00
- added key copy methods to OpenPGP-SDK
- added encrypted key storage and retrieval to own keyring after generation - improved test program git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-OpenPGP@5070 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
648555711c
commit
1888b21998
14 changed files with 406 additions and 85 deletions
|
@ -26,7 +26,7 @@
|
|||
#include <openpgpsdk/packet-parse.h>
|
||||
#include <openpgpsdk/util.h>
|
||||
#include <openpgpsdk/accumulate.h>
|
||||
#include "keyring_local.h"
|
||||
#include <openpgpsdk/keyring_local.h>
|
||||
#include "parse_local.h"
|
||||
#include <openpgpsdk/signature.h>
|
||||
#include <assert.h>
|
||||
|
|
|
@ -127,6 +127,7 @@ static unsigned public_key_length(const ops_public_key_t *key)
|
|||
return mpi_length(key->key.rsa.n)+mpi_length(key->key.rsa.e);
|
||||
|
||||
default:
|
||||
fprintf(stderr,"Bad algorithm type in key: %d\n",key->algorithm) ;
|
||||
assert(!"unknown key algorithm");
|
||||
}
|
||||
/* not reached */
|
||||
|
|
|
@ -94,6 +94,98 @@ void ops_keydata_free(ops_keydata_t *keydata)
|
|||
free(keydata);
|
||||
}
|
||||
|
||||
// \todo check where userid pointers are copied
|
||||
/**
|
||||
\ingroup Core_Keys
|
||||
\brief Copy user id, including contents
|
||||
\param dst Destination User ID
|
||||
\param src Source User ID
|
||||
\note If dst already has a user_id, it will be freed.
|
||||
*/
|
||||
void ops_copy_userid(ops_user_id_t* dst, const ops_user_id_t* src)
|
||||
{
|
||||
int len=strlen((char *)src->user_id);
|
||||
if (dst->user_id)
|
||||
free(dst->user_id);
|
||||
dst->user_id=ops_mallocz(len+1);
|
||||
|
||||
memcpy(dst->user_id, src->user_id, len);
|
||||
}
|
||||
// \todo check where pkt pointers are copied
|
||||
/**
|
||||
\ingroup Core_Keys
|
||||
\brief Copy packet, including contents
|
||||
\param dst Destination packet
|
||||
\param src Source packet
|
||||
\note If dst already has a packet, it will be freed.
|
||||
*/
|
||||
void ops_copy_packet(ops_packet_t* dst, const ops_packet_t* src)
|
||||
{
|
||||
if (dst->raw)
|
||||
free(dst->raw);
|
||||
dst->raw=ops_mallocz(src->length);
|
||||
|
||||
dst->length=src->length;
|
||||
memcpy(dst->raw, src->raw, src->length);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
\ingroup Core_Keys
|
||||
\brief Copies entire key data
|
||||
\param dst Destination key where to copy
|
||||
\param src Source key to copy
|
||||
*/
|
||||
void ops_keydata_copy(ops_keydata_t *dst,const ops_keydata_t *src)
|
||||
{
|
||||
unsigned n;
|
||||
|
||||
memset(dst,0,sizeof(ops_keydata_t)) ;
|
||||
|
||||
dst->uids = (ops_user_id_t*)ops_mallocz(src->nuids * sizeof(ops_user_id_t)) ;
|
||||
dst->nuids = src->nuids ;
|
||||
|
||||
for(n=0 ; n < src->nuids ; ++n)
|
||||
ops_copy_userid(&dst->uids[n],&src->uids[n]) ;
|
||||
|
||||
dst->packets = (ops_packet_t*)ops_mallocz(src->npackets * sizeof(ops_packet_t)) ;
|
||||
dst->npackets = src->npackets ;
|
||||
|
||||
for(n=0 ; n < src->npackets ; ++n)
|
||||
ops_copy_packet(&(dst->packets[n]),&(src->packets[n]));
|
||||
|
||||
dst->nsigs = src->nsigs ;
|
||||
dst->sigs = (sigpacket_t*)ops_mallocz(src->nsigs * sizeof(sigpacket_t)) ;
|
||||
|
||||
for(n=0 ; n < src->nsigs ; ++n)
|
||||
{
|
||||
dst->sigs[n].userid = (ops_user_id_t*)ops_mallocz(sizeof(ops_user_id_t)) ;
|
||||
dst->sigs[n].packet = (ops_packet_t*)ops_mallocz(sizeof(ops_packet_t)) ;
|
||||
|
||||
ops_copy_userid(dst->sigs[n].userid,src->sigs[n].userid) ;
|
||||
ops_copy_packet(dst->sigs[n].packet,src->sigs[n].packet) ;
|
||||
}
|
||||
|
||||
dst->key_id[0] = src->key_id[0] ;
|
||||
dst->key_id[1] = src->key_id[1] ;
|
||||
dst->key_id[2] = src->key_id[2] ;
|
||||
dst->key_id[3] = src->key_id[3] ;
|
||||
dst->key_id[4] = src->key_id[4] ;
|
||||
dst->key_id[5] = src->key_id[5] ;
|
||||
dst->key_id[6] = src->key_id[6] ;
|
||||
dst->key_id[7] = src->key_id[7] ;
|
||||
dst->type = src->type ;
|
||||
dst->key = src->key ;
|
||||
dst->fingerprint = src->fingerprint ;
|
||||
|
||||
if(src->type == OPS_PTAG_CT_PUBLIC_KEY)
|
||||
ops_public_key_copy(&dst->key.pkey,&src->key.pkey);
|
||||
else
|
||||
ops_secret_key_copy(&dst->key.skey,&src->key.skey);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
\ingroup HighLevel_KeyGeneral
|
||||
|
||||
|
@ -361,42 +453,6 @@ const ops_keydata_t* ops_keyring_get_key_by_index(const ops_keyring_t *keyring,
|
|||
return &keyring->keys[index];
|
||||
}
|
||||
|
||||
// \todo check where userid pointers are copied
|
||||
/**
|
||||
\ingroup Core_Keys
|
||||
\brief Copy user id, including contents
|
||||
\param dst Destination User ID
|
||||
\param src Source User ID
|
||||
\note If dst already has a user_id, it will be freed.
|
||||
*/
|
||||
void ops_copy_userid(ops_user_id_t* dst, const ops_user_id_t* src)
|
||||
{
|
||||
int len=strlen((char *)src->user_id);
|
||||
if (dst->user_id)
|
||||
free(dst->user_id);
|
||||
dst->user_id=ops_mallocz(len+1);
|
||||
|
||||
memcpy(dst->user_id, src->user_id, len);
|
||||
}
|
||||
|
||||
// \todo check where pkt pointers are copied
|
||||
/**
|
||||
\ingroup Core_Keys
|
||||
\brief Copy packet, including contents
|
||||
\param dst Destination packet
|
||||
\param src Source packet
|
||||
\note If dst already has a packet, it will be freed.
|
||||
*/
|
||||
void ops_copy_packet(ops_packet_t* dst, const ops_packet_t* src)
|
||||
{
|
||||
if (dst->raw)
|
||||
free(dst->raw);
|
||||
dst->raw=ops_mallocz(src->length);
|
||||
|
||||
dst->length=src->length;
|
||||
memcpy(dst->raw, src->raw, src->length);
|
||||
}
|
||||
|
||||
/**
|
||||
\ingroup Core_Keys
|
||||
\brief Add User ID to keydata
|
||||
|
|
|
@ -999,6 +999,41 @@ void ops_public_key_free(ops_public_key_t *p)
|
|||
}
|
||||
}
|
||||
|
||||
void ops_public_key_copy(ops_public_key_t *dst,const ops_public_key_t *src)
|
||||
{
|
||||
*dst = *src ;
|
||||
|
||||
switch(src->algorithm)
|
||||
{
|
||||
case OPS_PKA_RSA:
|
||||
case OPS_PKA_RSA_ENCRYPT_ONLY:
|
||||
case OPS_PKA_RSA_SIGN_ONLY:
|
||||
dst->key.rsa.n = BN_dup(src->key.rsa.n);
|
||||
dst->key.rsa.e = BN_dup(src->key.rsa.e);
|
||||
break;
|
||||
|
||||
case OPS_PKA_DSA:
|
||||
dst->key.dsa.p = BN_dup(src->key.dsa.p);
|
||||
dst->key.dsa.q = BN_dup(src->key.dsa.q);
|
||||
dst->key.dsa.g = BN_dup(src->key.dsa.g);
|
||||
dst->key.dsa.y = BN_dup(src->key.dsa.y);
|
||||
break;
|
||||
|
||||
case OPS_PKA_ELGAMAL:
|
||||
case OPS_PKA_ELGAMAL_ENCRYPT_OR_SIGN:
|
||||
dst->key.elgamal.p = BN_dup(src->key.elgamal.p);
|
||||
dst->key.elgamal.g = BN_dup(src->key.elgamal.g);
|
||||
dst->key.elgamal.y = BN_dup(src->key.elgamal.y);
|
||||
break;
|
||||
|
||||
//case 0:
|
||||
// nothing to free
|
||||
// break;
|
||||
|
||||
default:
|
||||
assert(0);
|
||||
}
|
||||
}
|
||||
/**
|
||||
\ingroup Core_ReadPackets
|
||||
*/
|
||||
|
@ -1573,9 +1608,9 @@ static int parse_one_signature_subpacket(ops_signature_t *sig,
|
|||
|
||||
case OPS_PTAG_SS_REVOCATION_KEY:
|
||||
/* octet 0 = class. Bit 0x80 must be set */
|
||||
if(!limited_read (&C.ss_revocation_key.class,1,&subregion,pinfo))
|
||||
if(!limited_read (&C.ss_revocation_key.cclass,1,&subregion,pinfo))
|
||||
return 0;
|
||||
if(!(C.ss_revocation_key.class&0x80))
|
||||
if(!(C.ss_revocation_key.cclass&0x80))
|
||||
{
|
||||
printf("Warning: OPS_PTAG_SS_REVOCATION_KEY class: "
|
||||
"Bit 0x80 should be set\n");
|
||||
|
@ -2124,6 +2159,31 @@ void ops_secret_key_free(ops_secret_key_t *key)
|
|||
ops_public_key_free(&key->public_key);
|
||||
}
|
||||
|
||||
void ops_secret_key_copy(ops_secret_key_t *dst,const ops_secret_key_t *src)
|
||||
{
|
||||
*dst = *src ;
|
||||
ops_public_key_copy(&dst->public_key,&src->public_key);
|
||||
|
||||
switch(src->public_key.algorithm)
|
||||
{
|
||||
case OPS_PKA_RSA:
|
||||
case OPS_PKA_RSA_ENCRYPT_ONLY:
|
||||
case OPS_PKA_RSA_SIGN_ONLY:
|
||||
dst->key.rsa.d = BN_dup(src->key.rsa.d) ;
|
||||
dst->key.rsa.p = BN_dup(src->key.rsa.p) ;
|
||||
dst->key.rsa.q = BN_dup(src->key.rsa.q) ;
|
||||
dst->key.rsa.u = BN_dup(src->key.rsa.u) ;
|
||||
break;
|
||||
|
||||
case OPS_PKA_DSA:
|
||||
dst->key.dsa.x = BN_dup(src->key.dsa.x) ;
|
||||
break;
|
||||
|
||||
default:
|
||||
fprintf(stderr,"ops_secret_key_copy: Unknown algorithm: %d (%s)\n",src->public_key.algorithm, ops_show_pka(src->public_key.algorithm));
|
||||
//assert(0);
|
||||
}
|
||||
}
|
||||
static int consume_packet(ops_region_t *region,ops_parse_info_t *pinfo,
|
||||
ops_boolean_t warn)
|
||||
{
|
||||
|
|
|
@ -849,8 +849,8 @@ int ops_print_packet(const ops_parser_content_t *content_)
|
|||
start_subpacket(content_->tag);
|
||||
/* not yet tested */
|
||||
printf (" revocation key: class=0x%x",
|
||||
content->ss_revocation_key.class);
|
||||
if (content->ss_revocation_key.class&0x40)
|
||||
content->ss_revocation_key.cclass);
|
||||
if (content->ss_revocation_key.cclass&0x40)
|
||||
printf (" (sensitive)");
|
||||
printf (", algid=0x%x",
|
||||
content->ss_revocation_key.algid);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
TEMPLATE = lib
|
||||
CONFIG = staticlib
|
||||
CONFIG = staticlib debug
|
||||
|
||||
DEFINES *= OPENSSL_NO_IDEA
|
||||
|
||||
|
|
|
@ -261,7 +261,7 @@ typedef struct
|
|||
unsigned pos;
|
||||
} linebreak_arg_t;
|
||||
|
||||
#define BREAKPOS 76
|
||||
#define BREAKPOS 64
|
||||
|
||||
static ops_boolean_t linebreak_writer(const unsigned char *src,
|
||||
unsigned length,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue