Changeset 139

Show
Ignore:
Timestamp:
05/20/05 18:17:11
Author:
ben
Message:

A step closer to signing, still not there yet.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • openpgpsdk/trunk/examples/create-signed-key.c

    r138 r139  
    22#include "util.h" 
    33#include "signature.h" 
     4#include "packet-parse.h" 
    45#include <stdio.h> 
     6#include <fcntl.h> 
     7#include <assert.h> 
     8 
     9/* 
     10 * Slightly strange beast that might get replaced later - it needs 
     11 * some other OpenPGP package to generate a key for it to use - this 
     12 * is because we don't have a way to generate our own (yet). 
     13 */ 
     14 
     15static ops_secret_key_t skey; 
     16static ops_boolean_t skey_found; 
     17 
     18static ops_parse_callback_return_t 
     19callback(const ops_parser_content_t *content,void *arg_) 
     20    { 
     21    if(content->tag == OPS_PTAG_CT_SECRET_KEY) 
     22        { 
     23        memcpy(&skey,&content->content.secret_key,sizeof skey); 
     24        skey_found=ops_true; 
     25        return OPS_KEEP_MEMORY; 
     26        } 
     27 
     28    return OPS_RELEASE_MEMORY; 
     29    } 
     30     
     31static void get_key(const char *keyfile) 
     32    { 
     33    ops_reader_fd_arg_t arg; 
     34    ops_parse_options_t opt; 
     35 
     36    ops_parse_options_init(&opt); 
     37    opt.cb=callback; 
     38 
     39    arg.fd=open(keyfile,O_RDONLY); 
     40    assert(arg.fd >= 0); 
     41    opt.reader_arg=&arg; 
     42    opt.reader=ops_reader_fd; 
     43 
     44    ops_parse(&opt); 
     45 
     46    assert(skey_found); 
     47    } 
    548 
    649int main(int argc,char **argv) 
     
    851    ops_writer_fd_arg_t arg; 
    952    ops_create_options_t opt; 
    10     char *user_id; 
    11     const char *nstr; 
    12     const char *estr; 
    13     BIGNUM *n=NULL; 
    14     BIGNUM *e=NULL; 
    15     ops_public_key_t key; 
    16     ops_secret_key_t skey; 
    1753    ops_create_signature_t sig; 
    1854    ops_user_id_t id; 
    1955    unsigned char keyid[OPS_KEY_ID_SIZE]; 
     56    char *user_id; 
    2057 
    21     if(argc != 2
     58    if(argc != 3
    2259        { 
    23         fprintf(stderr,"%s <public key file> <secret key file>\n",argv[0]); 
     60        fprintf(stderr,"%s <secret key file> <user_id>\n",argv[0]); 
    2461        exit(1); 
    2562        } 
    26      
    27     nstr=argv[1]; 
    28     estr=argv[2]; 
    29     user_id=argv[3]; 
    3063 
    31     BN_hex2bn(&n,nstr); 
    32     BN_hex2bn(&e,estr)
     64    get_key(argv[1]); 
     65    user_id=argv[2]
    3366 
    3467    arg.fd=1; 
     
    3669    opt.arg=&arg; 
    3770 
    38     ops_fast_create_rsa_public_key(&key,time(NULL),n,e); 
    39     ops_write_struct_public_key(&key,&opt); 
     71    ops_write_struct_public_key(&skey.public_key,&opt); 
    4072 
    4173    ops_fast_create_user_id(&id,user_id); 
    4274    ops_write_struct_user_id(&id,&opt); 
    4375 
    44     ops_signature_start(&sig,&key,&id); 
     76    ops_signature_start(&sig,&skey.public_key,&id); 
    4577    ops_signature_add_creation_time(&sig,time(NULL)); 
    4678 
    47     ops_keyid(keyid,&key); 
     79    ops_keyid(keyid,&skey.public_key); 
    4880    ops_signature_add_issuer_key_id(&sig,keyid); 
    4981 
     
    5284    ops_signature_hashed_subpackets_end(&sig); 
    5385 
    54     ops_signature_end(&sig,&key,&skey); 
     86    ops_signature_end(&sig,&skey.public_key,&skey); 
    5587 
    5688    return 0;