Changeset 139
- Timestamp:
- 05/20/05 18:17:11
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
openpgpsdk/trunk/examples/create-signed-key.c
r138 r139 2 2 #include "util.h" 3 3 #include "signature.h" 4 #include "packet-parse.h" 4 5 #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 15 static ops_secret_key_t skey; 16 static ops_boolean_t skey_found; 17 18 static ops_parse_callback_return_t 19 callback(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 31 static 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 } 5 48 6 49 int main(int argc,char **argv) … … 8 51 ops_writer_fd_arg_t arg; 9 52 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;17 53 ops_create_signature_t sig; 18 54 ops_user_id_t id; 19 55 unsigned char keyid[OPS_KEY_ID_SIZE]; 56 char *user_id; 20 57 21 if(argc != 2)58 if(argc != 3) 22 59 { 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]); 24 61 exit(1); 25 62 } 26 27 nstr=argv[1];28 estr=argv[2];29 user_id=argv[3];30 63 31 BN_hex2bn(&n,nstr);32 BN_hex2bn(&e,estr);64 get_key(argv[1]); 65 user_id=argv[2]; 33 66 34 67 arg.fd=1; … … 36 69 opt.arg=&arg; 37 70 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); 40 72 41 73 ops_fast_create_user_id(&id,user_id); 42 74 ops_write_struct_user_id(&id,&opt); 43 75 44 ops_signature_start(&sig,& key,&id);76 ops_signature_start(&sig,&skey.public_key,&id); 45 77 ops_signature_add_creation_time(&sig,time(NULL)); 46 78 47 ops_keyid(keyid,& key);79 ops_keyid(keyid,&skey.public_key); 48 80 ops_signature_add_issuer_key_id(&sig,keyid); 49 81 … … 52 84 ops_signature_hashed_subpackets_end(&sig); 53 85 54 ops_signature_end(&sig,& key,&skey);86 ops_signature_end(&sig,&skey.public_key,&skey); 55 87 56 88 return 0;
