Changeset 574
- Timestamp:
- 08/13/08 14:30:27
- Files:
-
- openpgpsdk/trunk/Makefile (modified) (1 diff)
- openpgpsdk/trunk/include/openpgpsdk/armour.h (modified) (2 diffs)
- openpgpsdk/trunk/include/openpgpsdk/callback.h (added)
- openpgpsdk/trunk/include/openpgpsdk/create.h (modified) (1 diff)
- openpgpsdk/trunk/include/openpgpsdk/crypto.h (modified) (1 diff)
- openpgpsdk/trunk/include/openpgpsdk/hash.h (added)
- openpgpsdk/trunk/include/openpgpsdk/readerwriter.h (modified) (1 diff)
- openpgpsdk/trunk/include/openpgpsdk/std_print.h (modified) (1 diff)
- openpgpsdk/trunk/include/openpgpsdk/writer.h (added)
- openpgpsdk/trunk/include/openpgpsdk/writer_armoured.h (added)
- openpgpsdk/trunk/src/app/openpgp.c (modified) (8 diffs)
- openpgpsdk/trunk/src/lib/Makefile.template (modified) (1 diff)
- openpgpsdk/trunk/src/lib/accumulate.c (moved) (moved from openpgpsdk/trunk/src/lib/adv_accumulate.c)
- openpgpsdk/trunk/src/lib/adv_armour.c (deleted)
- openpgpsdk/trunk/src/lib/compress.c (moved) (moved from openpgpsdk/trunk/src/lib/adv_compress.c) (7 diffs)
- openpgpsdk/trunk/src/lib/create.c (moved) (moved from openpgpsdk/trunk/src/lib/adv_create.c) (6 diffs)
- openpgpsdk/trunk/src/lib/crypto.c (moved) (moved from openpgpsdk/trunk/src/lib/adv_crypto.c) (2 diffs)
- openpgpsdk/trunk/src/lib/errors.c (moved) (moved from openpgpsdk/trunk/src/lib/adv_errors.c) (2 diffs)
- openpgpsdk/trunk/src/lib/fingerprint.c (moved) (moved from openpgpsdk/trunk/src/lib/adv_fingerprint.c) (1 diff)
- openpgpsdk/trunk/src/lib/hash.c (moved) (moved from openpgpsdk/trunk/src/lib/adv_hash.c) (1 diff)
- openpgpsdk/trunk/src/lib/keyring.c (moved) (moved from openpgpsdk/trunk/src/lib/adv_keyring.c) (3 diffs)
- openpgpsdk/trunk/src/lib/lists.c (moved) (moved from openpgpsdk/trunk/src/lib/adv_lists.c)
- openpgpsdk/trunk/src/lib/memory.c (moved) (moved from openpgpsdk/trunk/src/lib/adv_memory.c) (2 diffs)
- openpgpsdk/trunk/src/lib/openssl_crypto.c (moved) (moved from openpgpsdk/trunk/src/lib/adv_openssl_crypto.c)
- openpgpsdk/trunk/src/lib/packet-parse.c (moved) (moved from openpgpsdk/trunk/src/lib/adv_packet-parse.c) (4 diffs)
- openpgpsdk/trunk/src/lib/packet-print.c (moved) (moved from openpgpsdk/trunk/src/lib/std_print.c) (2 diffs)
- openpgpsdk/trunk/src/lib/packet-show.c (moved) (moved from openpgpsdk/trunk/src/lib/adv_packet-show.c)
- openpgpsdk/trunk/src/lib/parse_local.h (modified) (2 diffs)
- openpgpsdk/trunk/src/lib/reader.c (added)
- openpgpsdk/trunk/src/lib/reader_armoured.c (added)
- openpgpsdk/trunk/src/lib/reader_encrypted.c (added)
- openpgpsdk/trunk/src/lib/reader_fd.c (added)
- openpgpsdk/trunk/src/lib/reader_hashed.c (added)
- openpgpsdk/trunk/src/lib/reader_mem.c (added)
- openpgpsdk/trunk/src/lib/readerwriter.c (moved) (moved from openpgpsdk/trunk/src/lib/adv_readerwriter.c) (8 diffs)
- openpgpsdk/trunk/src/lib/signature.c (moved) (moved from openpgpsdk/trunk/src/lib/adv_signature.c) (2 diffs)
- openpgpsdk/trunk/src/lib/std_encrypt.c (deleted)
- openpgpsdk/trunk/src/lib/std_keyring.c (deleted)
- openpgpsdk/trunk/src/lib/std_signature.c (deleted)
- openpgpsdk/trunk/src/lib/symmetric.c (moved) (moved from openpgpsdk/trunk/src/lib/adv_symmetric.c) (3 diffs)
- openpgpsdk/trunk/src/lib/util.c (moved) (moved from openpgpsdk/trunk/src/lib/adv_util.c) (1 diff)
- openpgpsdk/trunk/src/lib/validate.c (moved) (moved from openpgpsdk/trunk/src/lib/adv_validate.c)
- openpgpsdk/trunk/src/lib/writer.c (added)
- openpgpsdk/trunk/src/lib/writer_armour.c (added)
- openpgpsdk/trunk/src/lib/writer_encrypt.c (moved) (moved from openpgpsdk/trunk/src/lib/adv_writer_encrypt.c)
- openpgpsdk/trunk/src/lib/writer_encrypt_se_ip.c (moved) (moved from openpgpsdk/trunk/src/lib/adv_writer_encrypt_se_ip.c) (2 diffs)
- openpgpsdk/trunk/src/lib/writer_fd.c (added)
- openpgpsdk/trunk/src/lib/writer_memory.c (added)
- openpgpsdk/trunk/src/lib/writer_skey_checksum.c (added)
- openpgpsdk/trunk/src/lib/writer_stream_encrypt_se_ip.c (moved) (moved from openpgpsdk/trunk/src/lib/adv_writer_stream_encrypt_se_ip.c)
- openpgpsdk/trunk/tests/test_common.c (modified) (1 diff)
- openpgpsdk/trunk/tests/test_packet_types.c (modified) (1 diff)
- openpgpsdk/trunk/tests/test_rsa_decrypt.c (modified) (1 diff)
- openpgpsdk/trunk/tests/test_rsa_signature.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
openpgpsdk/trunk/Makefile
r541 r574 10 10 default: 11 11 @set -e; for d in $(SUBDIRS); do \ 12 (cd $$d; echo "+++ make in $$d"; make ; echo "--- $$d"); \12 (cd $$d; echo "+++ make in $$d"; make -w; echo "** submake returns $$?\n"; echo "--- $$d"); \ 13 13 done 14 14 openpgpsdk/trunk/include/openpgpsdk/armour.h
r573 r574 20 20 */ 21 21 22 #ifndef __OPS_ARMOUR_H__ 23 #define __OPS_ARMOUR_H__ 24 22 25 #include "packet-parse.h" 23 26 #include "signature.h" 27 28 unsigned ops_crc24(unsigned checksum,unsigned char c); 24 29 25 30 void ops_reader_push_dearmour(ops_parse_info_t *parse_info, … … 46 51 void ops_writer_push_armoured(ops_create_info_t *info, ops_armor_type_t type); 47 52 53 #define CRC24_INIT 0xb704ceL 54 55 #endif /* __OPS_ARMOUR_H__ */ 56 48 57 // EOF openpgpsdk/trunk/include/openpgpsdk/create.h
r570 r574 26 26 #define OPS_CREATE_H 27 27 28 #include "types.h" 29 #include "packet.h" 30 #include "crypto.h" 31 #include "memory.h" 32 #include "errors.h" 33 #include "keyring.h" 28 #include <openpgpsdk/types.h> 29 #include <openpgpsdk/packet.h> 30 #include <openpgpsdk/crypto.h> 31 #include <openpgpsdk/memory.h> 32 #include <openpgpsdk/errors.h> 33 #include <openpgpsdk/keyring.h> 34 #include <openpgpsdk/writer.h> 34 35 35 typedef struct ops_writer_info ops_writer_info_t;36 36 /** 37 37 * \ingroup Create 38 * the writer function prototype38 * This struct contains the required information about how to write this stream 39 39 */ 40 typedef ops_boolean_t ops_writer_t(const unsigned char *src, 41 unsigned length, 42 ops_error_t **errors, 43 ops_writer_info_t *winfo); 44 typedef ops_boolean_t ops_writer_finaliser_t(ops_error_t **errors, 45 ops_writer_info_t *winfo); 46 typedef void ops_writer_destroyer_t(ops_writer_info_t *winfo); 40 struct ops_create_info 41 { 42 ops_writer_info_t winfo; 43 ops_error_t *errors; /*!< an error stack */ 44 }; 47 45 48 46 ops_create_info_t *ops_create_info_new(void); 49 47 void ops_create_info_delete(ops_create_info_t *info); 50 void *ops_writer_get_arg(ops_writer_info_t *winfo);51 ops_boolean_t ops_stacked_write(const void *src,unsigned length,52 ops_error_t **errors,53 ops_writer_info_t *winfo);54 48 55 void ops_writer_set(ops_create_info_t *info, 56 ops_writer_t *writer, 57 ops_writer_finaliser_t *finaliser, 58 ops_writer_destroyer_t *destroyer, 59 void *arg); 60 void ops_writer_push(ops_create_info_t *info, 61 ops_writer_t *writer, 62 ops_writer_finaliser_t *finaliser, 63 ops_writer_destroyer_t *destroyer, 64 void *arg); 65 void ops_writer_pop(ops_create_info_t *info); 66 void ops_writer_generic_destroyer(ops_writer_info_t *winfo); 67 ops_boolean_t ops_writer_passthrough(const unsigned char *src, 68 unsigned length, 69 ops_error_t **errors, 70 ops_writer_info_t *winfo); 49 ops_memory_t* ops_write_buf_from_file(const char *filename); 50 int ops_write_file_from_buf(const char *filename, const char* buf, const size_t len, const ops_boolean_t overwrite); 71 51 72 void ops_writer_set_fd(ops_create_info_t *info,int fd); 73 ops_boolean_t ops_writer_close(ops_create_info_t *info); 74 75 ops_boolean_t ops_write(const void *src,unsigned length, 76 ops_create_info_t *opt); 77 ops_boolean_t ops_write_length(unsigned length,ops_create_info_t *opt); 78 ops_boolean_t ops_write_ptag(ops_content_tag_t tag,ops_create_info_t *opt); 79 ops_boolean_t ops_write_scalar(unsigned n,unsigned length, 80 ops_create_info_t *opt); 81 ops_boolean_t ops_write_mpi(const BIGNUM *bn,ops_create_info_t *opt); 82 ops_boolean_t ops_write_encrypted_mpi(const BIGNUM *bn, ops_crypt_t* crypt, ops_create_info_t *info); 83 ops_boolean_t ops_write_ss_header(unsigned length,ops_content_tag_t type, 84 ops_create_info_t *opt); 85 86 void ops_fast_create_rsa_public_key(ops_public_key_t *key,time_t time, 87 BIGNUM *n,BIGNUM *e); 88 void ops_create_rsa_public_key(ops_public_key_t *key,time_t time, 89 const BIGNUM *n,const BIGNUM *e); 52 ops_boolean_t ops_calc_session_key_checksum(ops_pk_session_key_t *session_key, unsigned char *cs); 90 53 void ops_build_public_key(ops_memory_t *out,const ops_public_key_t *key, 91 54 ops_boolean_t make_packet); 55 ops_boolean_t ops_write_struct_user_id(ops_user_id_t *id, 56 ops_create_info_t *info); 92 57 ops_boolean_t ops_write_struct_public_key(const ops_public_key_t *key, 93 ops_create_info_t *opt); 94 ops_boolean_t ops_write_rsa_public_key(time_t time,const BIGNUM *n, 95 const BIGNUM *e, 96 ops_create_info_t *opt); 58 ops_create_info_t *info); 97 59 98 void ops_fast_create_user_id(ops_user_id_t *id,unsigned char *user_id); 99 ops_boolean_t ops_write_struct_user_id(ops_user_id_t *id, 100 ops_create_info_t *opt); 101 ops_boolean_t ops_write_user_id(const unsigned char *user_id,ops_create_info_t *opt); 102 103 void ops_create_rsa_secret_key(ops_secret_key_t *key,const BIGNUM *p, 104 const BIGNUM *q,const BIGNUM *d, 105 const BIGNUM *u,const BIGNUM *n, 106 const BIGNUM *e); 107 void ops_fast_create_rsa_secret_key(ops_secret_key_t *key,time_t time, 108 BIGNUM *p,BIGNUM *q,BIGNUM *d,BIGNUM *u, 109 BIGNUM *n,BIGNUM *e); 60 ops_boolean_t ops_write_ss_header(unsigned length,ops_content_tag_t type, 61 ops_create_info_t *info); 110 62 ops_boolean_t ops_write_struct_secret_key(const ops_secret_key_t *key, 111 63 const unsigned char* passphrase, 112 64 const size_t pplen, 113 65 ops_create_info_t *info); 114 66 ops_boolean_t ops_write_one_pass_sig(const ops_secret_key_t* skey, 67 const ops_hash_algorithm_t hash_alg, 68 const ops_sig_type_t sig_type, 69 ops_create_info_t* info); 70 ops_boolean_t ops_write_literal_data_from_buf(const unsigned char *data, 71 const int maxlen, 72 const ops_literal_data_type_t type, 73 ops_create_info_t *info); 115 74 ops_pk_session_key_t *ops_create_pk_session_key(const ops_keydata_t *key); 116 117 void ops_create_m_buf(ops_pk_session_key_t *session_key, unsigned char *buf);118 119 // RENAMED from ops_boolean_t ops_write_literal_data(const unsigned char *data,120 ops_boolean_t ops_write_literal_data_from_buf(const unsigned char *data,121 const int maxlen,122 const ops_literal_data_type_t type,123 ops_create_info_t *info);124 ops_boolean_t ops_write_literal_data_from_file(const char *filename,125 const ops_literal_data_type_t type,126 ops_create_info_t *info);127 128 ops_memory_t* ops_write_buf_from_file(const char *filename);129 int ops_write_file_from_buf(const char* filename, const char* buf, const size_t len, const ops_boolean_t overwrite);130 131 ops_boolean_t ops_write_symmetrically_encrypted_data(const unsigned char *data,132 const int len,133 ops_create_info_t *info);134 135 ops_boolean_t ops_write_se_ip_data(const unsigned char *data,136 const unsigned int len,137 ops_crypt_t *crypt,138 ops_create_info_t *info);139 75 ops_boolean_t ops_write_pk_session_key(ops_create_info_t *info, 140 76 ops_pk_session_key_t *pksk); 141 ops_boolean_t ops_ calc_session_key_checksum(ops_pk_session_key_t *session_key, unsigned char *cs);142 void ops_calc_mdc_hash(const unsigned char* preamble, const size_t sz_preamble, const unsigned char* data, const unsigned int len, unsigned char *hashed);77 ops_boolean_t ops_write_transferable_public_key(const ops_keydata_t *key, ops_boolean_t armoured, ops_create_info_t *info); 78 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); 143 79 144 ops_boolean_t ops_write_one_pass_sig(const ops_secret_key_t* skey, const ops_hash_algorithm_t hash_alg, const ops_sig_type_t sig_type, ops_create_info_t* info); 80 #endif /*OPS_CREATE_H*/ 145 81 146 ops_boolean_t ops_write_transferable_public_key(const ops_keydata_t *key, ops_boolean_t armoured, ops_create_info_t *info); 147 ops_boolean_t ops_write_transferable_secret_key(const ops_keydata_t *key, const unsigned char* passphrase, size_t pplen, ops_boolean_t armoured, ops_create_info_t *info); 148 149 #endif 82 // eof openpgpsdk/trunk/include/openpgpsdk/crypto.h
r570 r574 160 160 const struct ops_key_data *key); 161 161 162 voidops_encrypt_file(const char* input_filename, const char* output_filename, const ops_keydata_t *pub_key, const ops_boolean_t use_armour, const ops_boolean_t allow_overwrite);163 voidops_decrypt_file(const char* input_filename, const char* output_filename, ops_keyring_t *keyring, const ops_boolean_t use_armour, const ops_boolean_t allow_overwrite,ops_parse_cb_t* cb_get_passphrase);162 ops_boolean_t ops_encrypt_file(const char* input_filename, const char* output_filename, const ops_keydata_t *pub_key, const ops_boolean_t use_armour, const ops_boolean_t allow_overwrite); 163 ops_boolean_t ops_decrypt_file(const char* input_filename, const char* output_filename, ops_keyring_t *keyring, const ops_boolean_t use_armour, const ops_boolean_t allow_overwrite,ops_parse_cb_t* cb_get_passphrase); 164 164 165 165 // Keys openpgpsdk/trunk/include/openpgpsdk/readerwriter.h
r570 r574 25 25 #include <openpgpsdk/memory.h> 26 26 #include <openpgpsdk/create.h> 27 28 /**29 * \ingroup Create30 * This struct contains the required information about one writer31 */32 struct ops_writer_info33 {34 ops_writer_t *writer;35 ops_writer_finaliser_t *finaliser;36 ops_writer_destroyer_t *destroyer;37 void *arg;38 ops_writer_info_t *next;39 };40 41 /**42 * \ingroup Create43 * This struct contains the required information about how to write this stream44 */45 struct ops_create_info46 {47 ops_writer_info_t winfo;48 ops_error_t *errors; /*!< an error stack */49 };50 27 51 28 // openpgpsdk/trunk/include/openpgpsdk/std_print.h
r570 r574 43 43 //void ops_print_secret_key(const ops_content_tag_t type, const ops_secret_key_t* skey); 44 44 int ops_print_packet(const ops_parser_content_t *content_); 45 void ops_list_packets(char *filename, ops_boolean_t armour, ops_keyring_t* pubring, ops_parse_cb_t* cb_get_passphrase); 46 45 47 #endif openpgpsdk/trunk/src/app/openpgp.c
r572 r574 37 37 #include "openpgpsdk/validate.h" 38 38 #include "openpgpsdk/readerwriter.h" 39 #include "openpgpsdk/std_print.h" 39 40 40 41 #define DEFAULT_NUMBITS 1024 … … 52 53 static const char* usage_clearsign="%s --clearsign --userid=<userid> --filename=<filename> [--homedir=<homedir>]\n"; 53 54 static const char* usage_verify="%s --verify --filename=<filename> [--homedir=<homedir>] [--armour]\n"; 55 static const char* usage_list_packets="%s --list-packets --filename=<filename> [--homedir=<homedir>] [--armour]\n"; 54 56 55 57 static const char* pname; … … 68 70 CLEARSIGN, 69 71 VERIFY, 72 LIST_PACKETS, 73 70 74 // options 71 75 KEYRING, … … 93 97 { "clearsign", no_argument, NULL, CLEARSIGN }, 94 98 { "verify", no_argument, NULL, VERIFY }, 99 100 { "list-packets", no_argument, NULL, LIST_PACKETS }, 95 101 96 102 // options … … 228 234 break; 229 235 236 case LIST_PACKETS: 237 cmd=LIST_PACKETS; 238 break; 239 230 240 // option 231 241 … … 428 438 429 439 // write public key 430 #ifdef TMP431 ops_setup_memory_write(&cinfo, &mem, 128);432 ops_write_transferable_public_key(mykeydata, ops_true, cinfo);433 ops_keyring_read_from_mem(pubring, mem);434 ops_teardown_memory_write(cinfo,mem);435 436 // write secret key437 ops_setup_memory_write(&cinfo, &mem, 128);438 ops_write_transferable_secret_key(mykeydata, NULL, 0, ops_true, cinfo);439 ops_keyring_read_from_mem(secring, mem);440 ops_teardown_memory_write(cinfo,mem);441 #else442 440 // append to keyrings 443 441 fd=ops_setup_file_append(&cinfo, pubring_name); … … 461 459 exit(-1); 462 460 } 463 #endif 461 464 462 ops_keydata_free(mykeydata); 465 463 break; … … 576 574 break; 577 575 576 case LIST_PACKETS: 577 if (!got_filename) 578 { 579 print_usage(usage_list_packets, pname); 580 exit(-1); 581 } 582 ops_list_packets(opt_filename, armour, pubring, callback_cmd_get_passphrase_from_cmdline); 583 break; 584 578 585 default: 579 586 print_usage(usage,pname); openpgpsdk/trunk/src/lib/Makefile.template
r546 r574 8 8 all: Makefile headers .depend lib 9 9 10 LIBOBJS = adv_packet-parse.o adv_util.o adv_openssl_crypto.o adv_accumulate.o \ 11 adv_memory.o adv_fingerprint.o adv_hash.o adv_keyring.o \ 12 adv_signature.o adv_compress.o adv_packet-show.o adv_create.o \ 13 adv_validate.o adv_lists.o adv_armour.o adv_errors.o \ 14 adv_writer_encrypt_se_ip.o adv_writer_encrypt.o \ 15 adv_writer_stream_encrypt_se_ip.o \ 16 adv_symmetric.o adv_crypto.o random.o adv_readerwriter.o \ 17 std_encrypt.o std_keyring.o std_print.o std_signature.o 10 LIBOBJS = packet-parse.o packet-print.o packet-show.o \ 11 util.o openssl_crypto.o accumulate.o \ 12 memory.o fingerprint.o hash.o keyring.o \ 13 signature.o compress.o create.o \ 14 validate.o lists.o errors.o \ 15 symmetric.o crypto.o random.o readerwriter.o \ 16 reader.o reader_fd.o reader_mem.o \ 17 reader_armoured.o reader_hashed.o reader_encrypted.o \ 18 writer_fd.o writer_memory.o \ 19 writer.o writer_skey_checksum.o writer_armour.o \ 20 writer_encrypt_se_ip.o writer_encrypt.o \ 21 writer_stream_encrypt_se_ip.o 18 22 19 23 headers: openpgpsdk/trunk/src/lib/compress.c
r571 r574 66 66 } compress_arg_t; 67 67 68 #define ERR(err) do { content.content.error.error=err; content.tag=OPS_PARSER_ERROR; ops_parse_cb(&content,cbinfo); return -1; } while(0)69 70 68 // \todo remove code duplication between this and bzip2_compressed_data_reader 71 69 static int zlib_compressed_data_reader(void *dest,size_t length, … … 77 75 assert(arg->type==OPS_C_ZIP || arg->type==OPS_C_ZLIB); 78 76 79 ops_parser_content_t content;77 //ops_parser_content_t content; 80 78 int saved=length; 81 79 … … 87 85 { 88 86 if(arg->inflate_ret != Z_STREAM_END) 89 ERR("Compressed data didn't end when region ended.");87 OPS_ERROR(cbinfo->errors, OPS_E_P_DECOMPRESSION_ERROR,"Compressed data didn't end when region ended."); 90 88 /* 91 89 else … … 133 131 if(!arg->region->indeterminate 134 132 && arg->region->length_read != arg->region->length) 135 ERR("Compressed stream ended before packet end.");133 OPS_ERROR(cbinfo->errors,OPS_E_P_DECOMPRESSION_ERROR,"Compressed stream ended before packet end."); 136 134 } 137 135 else if(ret != Z_OK) 138 136 { 139 137 fprintf(stderr,"ret=%d\n",ret); 140 ERR(arg->zstream.msg);138 OPS_ERROR(cbinfo->errors,OPS_E_P_DECOMPRESSION_ERROR, arg->zstream.msg); 141 139 } 142 140 arg->inflate_ret=ret; … … 163 161 assert(arg->type==OPS_C_BZIP2); 164 162 165 ops_parser_content_t content;163 //ops_parser_content_t content; 166 164 int saved=length; 167 165 … … 173 171 { 174 172 if(arg->inflate_ret != BZ_STREAM_END) 175 ERR("Compressed data didn't end when region ended.");173 OPS_ERROR(cbinfo->errors, OPS_E_P_DECOMPRESSION_ERROR,"Compressed data didn't end when region ended."); 176 174 } 177 175 … … 214 212 if(!arg->region->indeterminate 215 213 && arg->region->length_read != arg->region->length) 216 ERR("Compressed stream ended before packet end.");214 OPS_ERROR(cbinfo->errors,OPS_E_P_DECOMPRESSION_ERROR,"Compressed stream ended before packet end."); 217 215 } 218 216 else if(ret != BZ_OK) 219 217 { 220 fprintf(stderr,"ret=%d\n",ret); 221 // ERR(arg->bzstream.msg); //\todo add error handling 218 OPS_ERROR_1(cbinfo->errors,OPS_E_P_DECOMPRESSION_ERROR,"Invalid return %d from BZ2_bzDecompress", ret); 222 219 } 223 220 arg->inflate_ret=ret; openpgpsdk/trunk/src/lib/create.c
r573 r574 42 42 #endif 43 43 44 #include <openpgpsdk/writer.h> 44 45 #include <openpgpsdk/final.h> 45 46 46 47 static int debug=0; 47 48 static ops_boolean_t writer_info_finalise(ops_error_t **errors,49 ops_writer_info_t *winfo);50 51 /*52 * return true if OK, otherwise false53 */54 static ops_boolean_t base_write(const void *src,unsigned length,55 ops_create_info_t *info)56 {57 return info->winfo.writer(src,length,&info->errors,&info->winfo);58 }59 60 /**61 * \ingroup Create62 *63 * \param src64 * \param length65 * \param info66 * \return 1 if OK, otherwise 067 */68 69 ops_boolean_t ops_write(const void *src,unsigned length,70 ops_create_info_t *info)71 {72 return base_write(src,length,info);73 }74 75 /**76 * \ingroup Create77 * \param n78 * \param length79 * \param info80 * \return ops_true if OK, otherwise ops_false81 */82 83 ops_boolean_t ops_write_scalar(unsigned n,unsigned length,84 ops_create_info_t *info)85 {86 while(length-- > 0)87 {88 unsigned char c[1];89 90 c[0]=n >> (length*8);91 if(!base_write(c,1,info))92 return ops_false;93 }94 return ops_true;95 }96 97 /**98 * \ingroup Create99 * \param bn100 * \param info101 * \return 1 if OK, otherwise 0102 */103 104 ops_boolean_t ops_write_mpi(const BIGNUM *bn,ops_create_info_t *info)105 {106 unsigned char buf[8192];107 int bits=BN_num_bits(bn);108 109 assert(bits <= 65535);110 BN_bn2bin(bn,buf);111 return ops_write_scalar(bits,2,info)112 && ops_write(buf,(bits+7)/8,info);113 }114 115 /**116 * \ingroup Create117 * \param tag118 * \param info119 * \return 1 if OK, otherwise 0120 */121 122 ops_boolean_t ops_write_ptag(ops_content_tag_t tag,ops_create_info_t *info)123 {124 unsigned char c[1];125 126 c[0]=tag|OPS_PTAG_ALWAYS_SET|OPS_PTAG_NEW_FORMAT;127 128 return base_write(c,1,info);129 }130 131 /**132 * \ingroup Create133 * \param length134 * \param info135 * \return 1 if OK, otherwise 0136 */137 138 ops_boolean_t ops_write_length(unsigned length,ops_create_info_t *info)139 {140 unsigned char c[2];141 142 if(length < 192)143 {144 c[0]=length;145 return base_write(c,1,info);146 }147 else if(length < 8384)148 {149 c[0]=((length-192) >> 8)+192;150 c[1]=(length-192)%256;151 return base_write(c,2,info);152 }153 return ops_write_scalar(0xff,1,info) && ops_write_scalar(length,4,info);154 }155 48 156 49 /** … … 321 214 } 322 215 323 typedef struct324 {325 ops_hash_algorithm_t hash_algorithm;326 ops_hash_t hash;327 unsigned char *hashed;328 } skey_checksum_arg_t;329 330 static ops_boolean_t skey_checksum_writer(const unsigned char *src, const unsigned length, ops_error_t **errors, ops_writer_info_t *winfo)331 {332 skey_checksum_arg_t *arg=ops_writer_get_arg(winfo);333 ops_boolean_t rtn=ops_true;334 335 // add contents to hash336 arg->hash.add(&arg->hash, src, length);337 338 // write to next stacked writer339 rtn=ops_stacked_write(src,length,errors,winfo);340 341 // tidy up and return342 return rtn;343 }344 345 static ops_boolean_t skey_checksum_finaliser(ops_error_t **errors __attribute__((unused)), ops_writer_info_t *winfo)346 {347 skey_checksum_arg_t *arg=ops_writer_get_arg(winfo);348 arg->hash.finish(&arg->hash, arg->hashed);349 return ops_true;350 }351 352 static void skey_checksum_destroyer(ops_writer_info_t* winfo)353 {354 skey_checksum_arg_t *arg=ops_writer_get_arg(winfo);355 free(arg);356 }357 358 void ops_push_skey_checksum_writer(ops_create_info_t *cinfo, ops_secret_key_t *skey)359 {360 // OPS_USED(info);361 // XXX: push a SHA-1 checksum writer (and change s2k to 254).362 skey_checksum_arg_t *arg=ops_mallocz(sizeof *arg);363 364 // configure the arg365 arg->hash_algorithm=skey->hash_algorithm;366 arg->hashed=&skey->checkhash[0];367 368 // init the hash369 ops_hash_any(&arg->hash, arg->hash_algorithm);370 arg->hash.init(&arg->hash);371 372 ops_writer_push(cinfo, skey_checksum_writer, skey_checksum_finaliser, skey_checksum_destroyer, arg);373 }374 375 216 /* Note that we support v3 keys here because they're needed for 376 217 * for verification - the writer doesn't allow them, though */ … … 871 712 { return ops_mallocz(sizeof(ops_create_info_t)); } 872 713 873 /* Note that we finalise from the top down, so we don't use writers below874 * that have already been finalised875 */876 static ops_boolean_t writer_info_finalise(ops_error_t **errors,877 ops_writer_info_t *winfo)878 {879 ops_boolean_t ret=ops_true;880 881 if(winfo->finaliser)882 {883 ret=winfo->finaliser(errors,winfo);884 winfo->finaliser=NULL;885 }886 if(winfo->next && !writer_info_finalise(errors,winfo->next))887 {888 winfo->finaliser=NULL;889 return ops_false;890 }891 return ret;892 }893 894 static void writer_info_delete(ops_writer_info_t *winfo)895 {896 // we should have finalised before deleting897 assert(!winfo->finaliser);898 if(winfo->next)899 {900 writer_info_delete(winfo->next);901 free(winfo->next);902 winfo->next=NULL;903 }904 if(winfo->destroyer)905 {906 winfo->destroyer(winfo);907 winfo->destroyer=NULL;908 }909 winfo->writer=NULL;910 }911 912 714 /** 913 715 * \ingroup Create … … 923 725 free(info); 924 726 } 925 926 typedef struct927 {928 int fd;929 } writer_fd_arg_t;930 931 static ops_boolean_t fd_writer(const unsigned char *src,unsigned length,932 ops_error_t **errors,933 ops_writer_info_t *winfo)934 {935 writer_fd_arg_t *arg=ops_writer_get_arg(winfo);936 int n=write(arg->fd,src,length);937 938 if(n == -1)939 {940 OPS_SYSTEM_ERROR_1(errors,OPS_E_W_WRITE_FAILED,"write",941 "file descriptor %d",arg->fd);942 return ops_false;943 }944 945 if((unsigned)n != length)946 {947 OPS_ERROR_1(errors,OPS_E_W_WRITE_TOO_SHORT,948 "file descriptor %d",arg->fd);949 return ops_false;950 }951 952 return ops_true;953 }954 955 static void fd_destroyer(ops_writer_info_t *winfo)956 {957 free(ops_writer_get_arg(winfo));958 }959 960 /**961 * \ingroup Create962 *963 * Set the writer in info to be a stock writer that writes to a file964 * descriptor. If another writer has already been set, then that is965 * first destroyed.966 *967 * \param info The info structure968 * \param fd The file descriptor969 *970 */971 972 void ops_writer_set_fd(ops_create_info_t *info,int fd)973 {974 writer_fd_arg_t *arg=malloc(sizeof *arg);975 976 arg->fd=fd;977 ops_writer_set(info,fd_writer,NULL,fd_destroyer,arg);978 }979 980 /**981 * \ingroup Create982 *983 * Set a writer in info. There should not be another writer set.984 *985 * \param info The info structure986 * \param writer The writer987 * \param destroyer The destroyer988 * \param arg The argument for the writer and destroyer989 */990 void ops_writer_set(ops_create_info_t *info,991 ops_writer_t *writer,992 ops_writer_finaliser_t *finaliser,993 ops_writer_destroyer_t *destroyer,994 void *arg)995 {996 assert(!info->winfo.writer);997 info->winfo.writer=writer;998 info->winfo.finaliser=finaliser;999 info->winfo.destroyer=destroyer;1000 info->winfo.arg=arg;1001 }1002 1003 /**1004 * \ingroup Create1005 *1006 * Push a writer in info. There must already be another writer set.1007 *1008 * \param info The info structure1009 * \param writer The writer1010 * \param destroyer The destroyer1011 * \param arg The argument for the writer and destroyer1012 */1013 void ops_writer_push(ops_create_info_t *info,1014 ops_writer_t *writer,1015 ops_writer_finaliser_t *finaliser,1016 ops_writer_destroyer_t *destroyer,1017 void *arg)1018 {1019 ops_writer_info_t *copy=ops_mallocz(sizeof *copy);1020 1021 assert(info->winfo.writer);1022 *copy=info->winfo;1023 info->winfo.next=copy;1024 1025 info->winfo.writer=writer;1026 info->winfo.finaliser=finaliser;1027 info->winfo.destroyer=destroyer;1028 info->winfo.arg=arg;1029 }1030 1031 void ops_writer_pop(ops_create_info_t *info)1032 {1033 ops_writer_info_t *next;1034 1035 // Make sure the finaliser has been called.1036 assert(!info->winfo.finaliser);1037 // Make sure this is a stacked writer1038 assert(info->winfo.next);1039 if(info->winfo.destroyer)1040 info->winfo.destroyer(&info->winfo);1041 1042 next=info->winfo.next;1043 info->winfo=*next;1044 1045 free(next);1046 }1047 1048 /**1049 * \ingroup Create1050 *1051 * Close the writer currently set in info.1052 *1053 * \param info The info structure1054 */1055 ops_boolean_t ops_writer_close(ops_create_info_t *info)1056 {1057 ops_boolean_t ret=writer_info_finalise(&info->errors,&info->winfo);1058 1059 writer_info_delete(&info->winfo);1060 1061 return ret;1062 }1063 1064 /**1065 * \ingroup Create1066 *1067 * Get the arg supplied to ops_create_info_set_writer().1068 *1069 * \param winfo The writer_info structure1070 * \return The arg1071 */1072 void *ops_writer_get_arg(ops_writer_info_t *winfo)1073 { return winfo->arg; }1074 1075 /**1076 * \ingroup Create1077 *1078 * Write to the next writer down in the stack.1079 *1080 * \param src The data to write.1081 * \param length The length of src.1082 * \param flags The writer flags.1083 * \param errors A place to store errors.1084 * \param info The writer_info structure.1085 * \return Success - if ops_false, then errors should contain the error.1086 */1087 ops_boolean_t ops_stacked_write(const void *src,unsigned length,1088 ops_error_t **errors,ops_writer_info_t *winfo)1089 {1090 return winfo->next->writer(src,length,errors,winfo->next);1091 }1092 1093 /**1094 * \ingroup Create1095 *1096 * Free the arg. Many writers just have a malloc()ed lump of storage, this1097 * function releases it.1098 *1099 * \param winfo the info structure.1100 */1101 void ops_writer_generic_destroyer(ops_writer_info_t *winfo)1102 { free(ops_writer_get_arg(winfo)); }1103 1104 /**1105 * \ingroup Create1106 *1107 * A writer that just writes to the next one down. Useful for when you1108 * want to insert just a finaliser into the stack.1109 */1110 ops_boolean_t ops_writer_passthrough(const unsigned char *src,1111 unsigned length,1112 ops_error_t **errors,1113 ops_writer_info_t *winfo)1114 { return ops_stacked_write(src,length,errors,winfo); }1115 1116 727 1117 728 ops_boolean_t ops_calc_session_key_checksum(ops_pk_session_key_t *session_key, unsigned char *cs) … … 1310 921 } 1311 922 1312 // RENAMED from ops_boolean_t ops_write_literal_data(const unsigned char *data,1313 923 ops_boolean_t ops_write_literal_data_from_buf(const unsigned char *data, 1314 924 const int maxlen, … … 1479 1089 } 1480 1090 1481 1482 1483 1091 // EOF openpgpsdk/trunk/src/lib/crypto.c
r571 r574 22 22 #include <openpgpsdk/crypto.h> 23 23 #include <openpgpsdk/random.h> 24 #include <openpgpsdk/readerwriter.h> 25 #include <openpgpsdk/writer_armoured.h> 26 #include "parse_local.h" 24 27 25 28 #include <assert.h> 26 29 #include <string.h> 30 #include <fcntl.h> 27 31 28 32 #include <openpgpsdk/final.h> … … 130 134 return ops_true; 131 135 } 136 137 #define MAXBUF 1024 138 139 static ops_parse_cb_return_t 140 callback_write_parsed(const ops_parser_content_t *content_,ops_parse_cb_info_t *cbinfo); 141 142 ops_boolean_t ops_encrypt_file(const char* input_filename, const char* output_filename, const ops_keydata_t *pub_key, const ops_boolean_t use_armour, const ops_boolean_t allow_overwrite) 143 { 144 int fd_in=0; 145 int fd_out=0; 146 147 ops_create_info_t *cinfo; 148 149 #ifdef WIN32 150 fd_in=open(input_filename,O_RDONLY | O_BINARY); 151 #else 152 fd_in=open(input_filename,O_RDONLY); 153 #endif 154 if(fd_in < 0) 155 { 156 perror(input_filename); 157 return ops_false; 158 } 159 160 fd_out=ops_setup_file_write(&cinfo, output_filename, allow_overwrite); 161 if (fd_out < 0) 162 return ops_false; 163 164 // set armoured/not armoured here 165 if (use_armour) 166 ops_writer_push_armoured_message(cinfo); 167 168 // Push the encrypted writer 169 ops_writer_push_encrypt_se_ip(cinfo,pub_key); 170 171 // Do the writing 172 173 unsigned char* buf=NULL; 174 size_t bufsz=16; 175 int done=0; 176 for (;;) 177 { 178 buf=realloc(buf,done+bufsz); 179 180 int n=0; 181 182 n=read(fd_in,buf+done,bufsz); 183 if (!n) 184 break; 185 assert(n>=0); 186 done+=n; 187 } 188 189 // This does the writing 190 ops_write(buf,done,cinfo); 191 192 // tidy up 193 close(fd_in); 194 free(buf); 195 ops_teardown_file_write(cinfo,fd_out); 196 197 return ops_true; 198 } 199 200 /* 201 the output filename can either be given explicitly, or if NULL, 202 it will be derived from the input filename following GPG conventions. 203 That is, we assume a binary encrypted file will be called <origfile>.gpg 204 and an armoured file will be called <origfile.asc> 205 If neither is true, then we add a .decrypted suffix. 206 */ 207 208 ops_boolean_t ops_decrypt_file(const char* input_filename, const char* output_filename, ops_keyring_t* keyring, const ops_boolean_t use_armour, const ops_boolean_t allow_overwrite, ops_parse_cb_t* cb_get_passphrase) 209 { 210 int fd_in=0; 211 int fd_out=0; 212 char* myfilename=NULL; 213 214 // 215 ops_parse_info_t *pinfo=NULL; 216 217 // setup for reading from given input file 218 fd_in=ops_setup_file_read(&pinfo, input_filename, 219 NULL, 220 callback_write_parsed, 221 ops_false); 222 if (fd_in < 0) 223 { 224 perror(input_filename); 225 return ops_false; 226 } 227 228 // setup output filename 229 230 if (output_filename) 231 { 232 fd_out=ops_setup_file_write(&pinfo->cbinfo.cinfo, output_filename, allow_overwrite); 233 234 if (fd_out < 0) 235 { 236 perror(output_filename); 237 ops_teardown_file_read(pinfo,fd_in); 238 return ops_false; 239 } 240 } 241 else 242 { 243 int suffixlen=4; 244 char *defaultsuffix=".decrypted"; 245 const char *suffix=input_filename+strlen((char *)input_filename)-suffixlen; 246 if (!strcmp(suffix,".gpg") || !strcmp(suffix,".asc")) 247 { 248 myfilename=ops_mallocz(strlen(input_filename)-suffixlen+1); 249 strncpy(myfilename,input_filename,strlen(input_filename)-suffixlen); 250 } 251 else 252 { 253 myfilename=ops_mallocz(strlen(input_filename)+strlen(defaultsuffix)+1); 254 sprintf(myfilename,"%s%s",input_filename,defaultsuffix); 255 } 256 257 fd_out=ops_setup_file_write(&pinfo->cbinfo.cinfo, myfilename, allow_overwrite); 258 259 if (fd_out < 0) 260 { 261 perror(myfilename); 262 free(myfilename); 263 ops_teardown_file_read(pinfo,fd_in); 264 return ops_false; 265 } 266 267 free (myfilename); 268 } 269 270 // \todo check for suffix matching armour param 271 272 // setup for writing decrypted contents to given output file 273 274 // setup keyring and passphrase callback 275 pinfo->cbinfo.cryptinfo.keyring=keyring; 276 pinfo->cbinfo.cryptinfo.cb_get_passphrase=cb_get_passphrase; 277 278 // Set up armour/passphrase options 279 280 if (use_armour) 281 ops_reader_push_dearmour(pinfo,ops_false,ops_false,ops_false); 282 283 // Do it 284 285 ops_parse_and_print_errors(pinfo); 286 287 // Unsetup 288 289 if (use_armour) 290 ops_reader_pop_dearmour(pinfo); 291 292 ops_teardown_file_write(pinfo->cbinfo.cinfo, fd_out); 293 ops_teardown_file_read(pinfo, fd_in); 294 // \todo cleardown crypt 295 296 return ops_true; 297 } 298 299 static ops_parse_cb_return_t 300 callback_write_parsed(const ops_parser_content_t *content_,ops_parse_cb_info_t *cbinfo) 301 { 302 ops_parser_content_union_t* content=(ops_parser_content_union_t *)&content_->content; 303 static ops_boolean_t skipping; 304 // ops_boolean_t write=ops_true; 305 306 OPS_USED(cbinfo); 307 308 // ops_print_packet(content_); 309 310 if(content_->tag != OPS_PTAG_CT_UNARMOURED_TEXT && skipping) 311 { 312 puts("...end of skip"); 313 skipping=ops_false; 314 } 315 316 switch(content_->tag) 317 { 318 case OPS_PTAG_CT_UNARMOURED_TEXT: 319 printf("OPS_PTAG_CT_UNARMOURED_TEXT\n"); 320 if(!skipping) 321 { 322 puts("Skipping..."); 323 skipping=ops_true; 324 } 325 fwrite(content->unarmoured_text.data,1, 326 content->unarmoured_text.length,stdout); 327 break; 328 329 case OPS_PTAG_CT_PK_SESSION_KEY: 330 return callback_pk_session_key(content_,cbinfo); 331 break; 332 333 case OPS_PARSER_CMD_GET_SECRET_KEY: 334 return callback_cmd_get_secret_key(content_,cbinfo); 335 break; 336 337 case OPS_PARSER_CMD_GET_SK_PASSPHRASE: 338 // return callback_cmd_get_secret_key_passphrase(content_,cbinfo); 339 return cbinfo->cryptinfo.cb_get_passphrase(content_,cbinfo); 340 break; 341 342 case OPS_PTAG_CT_LITERAL_DATA_BODY: 343 return callback_literal_data(content_,cbinfo); 344 break; 345 346 case OPS_PTAG_CT_ARMOUR_HEADER: 347 case OPS_PTAG_CT_ARMOUR_TRAILER: 348 case OPS_PTAG_CT_ENCRYPTED_PK_SESSION_KEY: 349 case OPS_PTAG_CT_COMPRESSED: 350 case OPS_PTAG_CT_LITERAL_DATA_HEADER: 351 case OPS_PTAG_CT_SE_IP_DATA_BODY: 352 case OPS_PTAG_CT_SE_IP_DATA_HEADER: 353 case OPS_PTAG_CT_SE_DATA_BODY: 354 case OPS_PTAG_CT_SE_DATA_HEADER: 355 356 // Ignore these packets 357 // They're handled in ops_parse_one_packet() 358 // and nothing else needs to be done 359 break; 360 361 default: 362 // return callback_general(content_,cbinfo); 363 break; 364 // fprintf(stderr,"Unexpected packet tag=%d (0x%x)\n",content_->tag, 365 // content_->tag); 366 // assert(0); 367 } 368 369 return OPS_RELEASE_MEMORY; 370 } 371 372 // EOF openpgpsdk/trunk/src/lib/errors.c
r571 r574 38 38 #include <openpgpsdk/final.h> 39 39 40 #define ERR (code) { code, #code }40 #define ERRNAME(code) { code, #code } 41 41 42 42 static ops_errcode_name_map_t errcode_name_map[] = 43 43 { 44 { OPS_E_OK, "OPS_E_OK" },45 { OPS_E_FAIL, "OPS_E_FAIL" },46 { OPS_E_SYSTEM_ERROR, "OPS_E_SYSTEM_ERROR" },47 { OPS_E_UNIMPLEMENTED, "OPS_E_UNIMPLEMENTED" },44 ERRNAME(OPS_E_OK), 45 ERRNAME(OPS_E_FAIL), 46 ERRNAME(OPS_E_SYSTEM_ERROR), 47 ERRNAME(OPS_E_UNIMPLEMENTED), 48 48 49 { OPS_E_R, "OPS_E_R" },50 { OPS_E_R_READ_FAILED, "OPS_E_R_READ_FAILED" },51 { OPS_E_R_EARLY_EOF, "OPS_E_R_EARLY_EOF" },52 { OPS_E_R_BAD_FORMAT, "OPS_E_R_BAD_FORMAT" },53 { OPS_E_R_UNCONSUMED_DATA, "OPS_E_R_UNCONSUMED_DATA" },49 ERRNAME(OPS_E_R), 50 ERRNAME(OPS_E_R_READ_FAILED), 51 ERRNAME(OPS_E_R_EARLY_EOF), 52 ERRNAME(OPS_E_R_BAD_FORMAT), 53 ERRNAME(OPS_E_R_UNCONSUMED_DATA), 54 54 55 { OPS_E_W, "OPS_E_W" },56 { OPS_E_W_WRITE_FAILED, "OPS_E_W_WRITE_FAILED" },57 { OPS_E_W_WRITE_TOO_SHORT, "OPS_E_W_WRITE_TOO_SHORT" },55 ERRNAME(OPS_E_W), 56 ERRNAME(OPS_E_W_WRITE_FAILED), 57 ERRNAME(OPS_E_W_WRITE_TOO_SHORT), 58 58 59 { OPS_E_P, "OPS_E_P" },60 { OPS_E_P_NOT_ENOUGH_DATA, "OPS_E_P_NOT_ENOUGH_DATA" },61 { OPS_E_P_UNKNOWN_TAG,"OPS_E_P_UNKNOWN_TAG" },62 { OPS_E_P_PACKET_CONSUMED,"OPS_E_P_PACKET_CONSUMED" },63 ERR (OPS_E_P_MPI_FORMAT_ERROR),59 ERRNAME(OPS_E_P), 60 ERRNAME(OPS_E_P_NOT_ENOUGH_DATA), 61 ERRNAME(OPS_E_P_UNKNOWN_TAG), 62 ERRNAME(OPS_E_P_PACKET_CONSUMED), 63 ERRNAME(OPS_E_P_MPI_FORMAT_ERROR), 64 64 65 { OPS_E_C, "OPS_E_C" },65 ERRNAME(OPS_E_C), 66 66 67 ERR (OPS_E_V),68 ERR (OPS_E_V_BAD_SIGNATURE),69 ERR (OPS_E_V_UNKNOWN_SIGNER),67 ERRNAME(OPS_E_V), 68 ERRNAME(OPS_E_V_BAD_SIGNATURE), 69 ERRNAME(OPS_E_V_UNKNOWN_SIGNER), 70 70 71 ERR (OPS_E_ALG),72 ERR (OPS_E_ALG_UNSUPPORTED_SYMMETRIC_ALG),73 ERR (OPS_E_ALG_UNSUPPORTED_PUBLIC_KEY_ALG),74 ERR (OPS_E_ALG_UNSUPPORTED_SIGNATURE_ALG),75 ERR (OPS_E_ALG_UNSUPPORTED_HASH_ALG),71 ERRNAME(OPS_E_ALG), 72 ERRNAME(OPS_E_ALG_UNSUPPORTED_SYMMETRIC_ALG), 73 ERRNAME(OPS_E_ALG_UNSUPPORTED_PUBLIC_KEY_ALG), 74 ERRNAME(OPS_E_ALG_UNSUPPORTED_SIGNATURE_ALG), 75 ERRNAME(OPS_E_ALG_UNSUPPORTED_HASH_ALG), 76 76 77 ERR(OPS_E_PROTO), 78 ERR(OPS_E_PROTO_BAD_SYMMETRIC_DECRYPT), 79 ERR(OPS_E_PROTO_UNKNOWN_SS), 80 ERR(OPS_E_PROTO_CRITICAL_SS_IGNORED), 81 ERR(OPS_E_PROTO_BAD_PUBLIC_KEY_VRSN), 82 ERR(OPS_E_PROTO_BAD_SIGNATURE_VRSN), 83 ERR(OPS_E_PROTO_BAD_ONE_PASS_SIG_VRSN), 84 ERR(OPS_E_PROTO_BAD_PKSK_VRSN), 85 ERR(OPS_E_PROTO_DECRYPTED_MSG_WRONG_LEN), 86 ERR(OPS_E_PROTO_BAD_SK_CHECKSUM), 87 77 ERRNAME(OPS_E_PROTO), 78 ERRNAME(OPS_E_PROTO_BAD_SYMMETRIC_DECRYPT), 79 ERRNAME(OPS_E_PROTO_UNKNOWN_SS), 80 ERRNAME(OPS_E_PROTO_CRITICAL_SS_IGNORED), 81 ERRNAME(OPS_E_PROTO_BAD_PUBLIC_KEY_VRSN), 82 ERRNAME(OPS_E_PROTO_BAD_SIGNATURE_VRSN), 83 ERRNAME(OPS_E_PROTO_BAD_ONE_PASS_SIG_VRSN), 84 ERRNAME(OPS_E_PROTO_BAD_PKSK_VRSN), 85 ERRNAME(OPS_E_PROTO_DECRYPTED_MSG_WRONG_LEN), 86 ERRNAME(OPS_E_PROTO_BAD_SK_CHECKSUM), 88 87 89 88 { (int) NULL, (char *)NULL }, /* this is the end-of-array marker */ … … 175 174 } 176 175 } 176 177 // EOF openpgpsdk/trunk/src/lib/fingerprint.c
r573 r574 141 141 } 142 142 } 143 144 // EOF openpgpsdk/trunk/src/lib/hash.c
r571 r574 95 95 } 96 96 97 static int hash_reader(void *dest,size_t length,ops_error_t **errors, 98 ops_reader_info_t *rinfo,ops_parse_cb_info_t *cbinfo) 97 void ops_calc_mdc_hash(const unsigned char* preamble, const size_t sz_preamble, const unsigned char* plaintext, const unsigned int sz_plaintext, unsigned char *hashed) 99 98 { 100 ops_hash_t *hash=ops_reader_get_arg(rinfo); 101 int r=ops_stacked_read(dest,length,errors,rinfo,cbinfo); 99 int debug=0; 100 ops_hash_t hash; 101 unsigned char c[1]; 102 102 103 if (r <= 0)104 return r; 105 106 hash->add(hash,dest,r);103 if (debug) 104 { 105 unsigned int i=0; 106 fprintf(stderr,"ops_calc_mdc_hash():\n"); 107 107 108 return r; 108 fprintf(stderr,"\npreamble: "); 109 for (i=0; i<sz_preamble;i++) 110 fprintf(stderr," 0x%02x", preamble[i]); 111 fprintf(stderr,"\n"); 112 113 fprintf(stderr,"\nplaintext (len=%d): ",sz_plaintext); 114 for (i=0; i<sz_plaintext;i++) 115 fprintf(stderr," 0x%02x", plaintext[i]); 116 fprintf(stderr,"\n"); 117 } 118 119 // init 120 ops_hash_any(&hash, OPS_HASH_SHA1); 121 hash.init(&hash); 122 123 // preamble 124 hash.add(&hash,preamble,sz_preamble); 125 // plaintext 126 hash.add(&hash,plaintext,sz_plaintext); 127 // MDC packet tag 128 c[0]=0xD3; 129 hash.add(&hash,&c[0],1); 130 // MDC packet len 131 c[0]=0x14; 132 hash.add(&hash,&c[0],1); 133 134 //finish 135 hash.finish(&hash,hashed); 136 137 if (debug) 138 { 139 unsigned int i=0; 140 fprintf(stderr,"\nhashed (len=%d): ",SHA_DIGEST_LENGTH); 141 for (i=0; i<SHA_DIGEST_LENGTH;i++) 142 fprintf(stderr," 0x%02x", hashed[i]); 143 fprintf(stderr,"\n"); 144 } 109 145 } 110 146 111 void ops_reader_push_hash(ops_parse_info_t *pinfo,ops_hash_t *hash) 112 { 113 hash->init(hash); 114 ops_reader_push(pinfo,hash_reader,NULL,hash); 115 } 116 117 void ops_reader_pop_hash(ops_parse_info_t *pinfo) 118 { ops_reader_pop(pinfo); } 147 // EOF openpgpsdk/trunk/src/lib/keyring.c
r571 r574 23 23 */ 24 24 25 #include <openpgpsdk/armour.h> 26 #include <openpgpsdk/std_print.h> 25 27 #include <openpgpsdk/keyring.h> 26 28 #include <openpgpsdk/packet-parse.h> … … 97 99 } 98 100 99 static void echo_off()100 {101 #ifndef WIN32102 struct termios term;103 int r;104 105 r=tcgetattr(0,&term);106 if(r < 0 && errno == ENOTTY)107 return;108 assert(r >= 0);109 110 term.c_lflag &= ~ECHO;111 112 r=tcsetattr(0,TCSANOW,&term);113 assert(r >= 0);114 #endif115 }116 117 static void echo_on()118 {119 #ifndef WIN32120 struct termios term;121 int r;122 123 r=tcgetattr(0,&term);124 if(r < 0 && errno == ENOTTY)125 return;126 assert(r >= 0);127 128 term.c_lflag |= ECHO;129 130 r=tcsetattr(0,TCSANOW,&term);131 assert(r >= 0);132 #endif133 }134 135 char *ops_malloc_passphrase(char *pp)136 {137 char *passphrase;138 size_t n;139 140 n=strlen(pp);141 passphrase=malloc(n+1);142 strcpy(passphrase,pp);143 144 return passphrase;145 }146 147 char *ops_get_passphrase(void)148 {149 char buffer[1024];150 size_t n;151 152 printf("Passphrase: ");153 154 echo_off();155 fgets(buffer,sizeof buffer,stdin);156 echo_on();157 158 putchar('\n');159 160 n=strlen(buffer);161 if(n && buffer[n-1] == '\n')162 buffer[--n]='\0';163 return ops_malloc_passphrase(buffer);164 }165 166 101 typedef struct 167 102 { … … 449 384 } 450 385 386 /*! \file 387 \brief Standard API keyring functions 388 389 */ 390 391 /** @defgroup StdKeyring Keyring 392 \ingroup StandardAPI 393 394 @defgroup StdKeyringFile Keyring File Operations 395 \ingroup StdKeyring 396 \brief Keyring Open/Read/Write/Close 397 398 Example Usage: 399 \code 400 401 // definition of variables 402 ops_keyring_t keyring; 403 char* filename="~/.gnupg/pubring.gpg"; 404 405 // Read keyring from file 406 ops_keyring_read_from_file(&keyring,filename); 407 408 // do actions using keyring 409 ... 410 411 // Free memory alloc-ed in ops_keyring_read_from_file() 412 ops_keyring_free(); 413 \endcode 414 */ 415 416 /** 417 @defgroup StdKeyringFind Keyfind Find Operations 418 \ingroup StdKeyring 419 Find Key or its info within keyring 420 421 Example Usage: 422 \code 423 424 // definition of variables 425 ops_keyring_t keyring; 426 unsigned char* keyid; 427 ops_key_data_t *key; 428 429 // Read keyring from file 430 ops_keyring_read_from_file(&keyring,"~/.gnupg/pubring.gpg"); 431 432 // Search for keys 433 434 // - get Key ID from given userid 435 keyid=ops_keyring_find_keyid_by_userid (keyring, "user@domain.com") 436 437 // - now get key from Key ID 438 key=ops_keyring_find_key_by_id(keyring, keyid); 439 440 // do something with key 441 ... 442 443 // Free memory alloc-ed in ops_keyring_read_from_file() 444 ops_keyring_free(); 445 \endcode 446 */ 447 448 static ops_parse_cb_return_t 449 cb_keyring_read(const ops_parser_content_t *content_, 450 ops_parse_cb_info_t *cbinfo); 451 452 /** 453 \ingroup StdKeyringFile 454 455 Reads a keyring from a file 456 457 \param keyring Ptr to existing keyring 458 \param file Filename of keyring 459 460 \note Keyring struct must already exist. 461 462 \note Can be used with either a public or secret keyring. 463 464 \note You must call ops_keyring_free() after usage to free alloc-ed memory. 465 466 \note If you call this twice on the same keyring struct, without calling 467 ops_keyring_free() between these calls, you will introduce a memory leak. 468 */ 469 ops_boolean_t ops_keyring_read_from_file(ops_keyring_t *keyring, const ops_boolean_t armour, const char *filename) 470 { 471 ops_parse_info_t *pinfo; 472 int fd; 473 ops_boolean_t res = ops_true; 474 475 //memset(keyring,'\0',sizeof *keyring); 476 477 pinfo=ops_parse_info_new(); 478 479 // add this for the moment, 480 // \todo need to fix the problems with reading signature subpackets later 481 482 // ops_parse_options(pinfo,OPS_PTAG_SS_ALL,OPS_PARSE_RAW); 483 ops_parse_options(pinfo,OPS_PTAG_SS_ALL,OPS_PARSE_PARSED); 484 485 #ifdef WIN32 486 fd=open(filename,O_RDONLY|O_BINARY); 487 #else 488 fd=open(filename,O_RDONLY); 489 #endif 490 if(fd < 0) 491 { 492 ops_parse_info_delete(pinfo); 493 perror(filename); 494 return ops_false; 495 } 496 497 ops_reader_set_fd(pinfo,fd); 498 499 ops_parse_cb_set(pinfo,cb_keyring_read,NULL); 500 501 if (armour) 502 { ops_reader_push_dearmour(pinfo, ops_false, ops_false, ops_false); } 503 504 if ( ops_parse_and_accumulate(keyring,pinfo) == 0 ) { 505 res = ops_false; 506 } 507 else 508 { 509 res = ops_true; 510 } 511 ops_print_errors(ops_parse_info_get_errors(pinfo)); 512 513 close(fd); 514 515 ops_parse_info_delete(pinfo); 516 517 return res; 518 } 519 520 /** 521 \ingroup StdKeyring 522 523 Reads a keyring from memory 524 525 \param keyring Ptr to existing keyring 526 \param mem ptr to memory struct containing keyring info 527 528 \note Keyring struct must already exist. 529 530 \note Can be used with either a public or secret keyring. 531 532 \note You must call ops_keyring_free() after usage to free alloc-ed memory. 533 534 \note If you call this twice on the same keyring struct, without calling 535 ops_keyring_free() between these calls, you will introduce a memory leak. 536 */ 537 ops_boolean_t ops_keyring_read_from_mem(ops_keyring_t *keyring, ops_memory_t* mem) 538 { 539 // \todo currently assuming this is an armoured key. 540 541 ops_parse_info_t *pinfo=NULL; 542 ops_boolean_t res = ops_true; 543 544 // \todo need to free memory first? 545 //memset(keyring,'\0',sizeof *keyring); 546 547 pinfo=ops_parse_info_new(); 548 ops_parse_options(pinfo,OPS_PTAG_SS_ALL,OPS_PARSE_PARSED); 549 550 ops_setup_memory_read(&pinfo, mem, NULL, cb_keyring_read); 551 552 ops_reader_push_dearmour(pinfo,ops_false,ops_false,ops_true); 553 554 if ( ops_parse_and_accumulate(keyring,pinfo) == 0 ) 555 { 556 res = ops_false; 557 } 558 else 559 { 560 res = ops_true; 561 } 562 ops_print_errors(ops_parse_info_get_errors(pinfo)); 563 564 ops_reader_pop_dearmour(pinfo); 565 566 // don't call teardown_memory_read because memory was passed in 567 ops_parse_info_delete(pinfo); 568 569 return res; 570 } 571 572 /** 573 \ingroup StdKeyringFile 574 575 Frees alloc-ed memory 576 577 \param keyring Keyring whose data is to be freed 578 579 \note This does not free keyring itself, just the memory alloc-ed in it. 580 */ 581 void ops_keyring_free(ops_keyring_t *keyring) 582 { 583 free(keyring->keys); 584 keyring->keys=NULL; 585 keyring->nkeys=0; 586 keyring->nkeys_allocated=0; 587 } 588 589 /** 590 \ingroup StdKeyringFind 591 592 Finds key in keyring from its Key ID 593 594 \param keyring Keyring to be searched 595 \param keyid ID of required key 596 597 \return Ptr to key, if found; NULL, if not found 598 */ 599 const ops_keydata_t * 600 ops_keyring_find_key_by_id(const ops_keyring_t *keyring, 601 const unsigned char keyid[OPS_KEY_ID_SIZE]) 602 { 603 int n; 604 605 if (!keyring) 606 return NULL; 607 608 for(n=0 ; n < keyring->nkeys ; ++n) 609 { 610 if(!memcmp(keyring->keys[n].key_id,keyid,OPS_KEY_ID_SIZE)) 611 return &keyring->keys[n]; 612 } 613 614 return NULL; 615 } 616 617 /** 618 \ingroup StdKeyringFind 619 620 Finds key from its User ID 621 622 \param keyring Keyring to be searched 623 \param userid User ID of required key 624 625 \return Ptr to Key, if found; NULL, if not found 626 */ 627 const ops_keydata_t * 628 ops_keyring_find_key_by_userid(const ops_keyring_t *keyring, 629 const char *userid) 630 { 631 int n=0; 632 unsigned int i=0; 633 634 if (!keyring) 635 return NULL; 636 637 for(n=0 ; n < keyring->nkeys ; ++n) 638 { 639 for(i=0; i<keyring->keys[n].nuids; i++) 640 { 641 //printf("[%d][%d] userid %s\n",n,i,keyring->keys[n].uids[i].user_id); 642 if(!strncmp((char *)keyring->keys[n].uids[i].user_id,userid,strlen(userid))) 643 return &keyring->keys[n]; 644 } 645 } 646 647 //printf("end: n=%d,i=%d\n",n,i); 648 return NULL; 649 } 650 651 /** 652 \ingroup StdKeyringList 653 654 List keys in keyring 655 656 \param keyring Keyring to use 657 \param match optional string to match 658 659 */ 660 661 void 662 ops_keyring_list(const ops_keyring_t* keyring, 663 const char* match) 664 { 665 int n; 666 unsigned int i; 667 ops_keydata_t* key; 668 669 printf ("%d keys\n", keyring->nkeys); 670 for(n=0,key=&keyring->keys[n] ; n < keyring->nkeys ; ++n,++key) 671 { 672 for(i=0; i<key->nuids; i++) 673 { 674 if (match) 675 printf ("*** match %s\n", match); 676 // if match, compare 677 // if(!strcmp((char *)keyring->keys[n].uids[i].user_id,userid)) 678 // return &keyring->keys[n].keyid[0]; 679 if (ops_key_is_secret(key)) 680 ops_print_secret_keydata(key); 681 else 682 ops_print_public_keydata(key); 683 } 684 685 } 686 } 687 688 /* Static functions */ 689 690 static ops_parse_cb_return_t 691 cb_keyring_read(const ops_parser_content_t *content_, 692 ops_parse_cb_info_t *cbinfo) 693 { 694 OPS_USED(cbinfo); 695 696 switch(content_->tag) 697 { 698 case OPS_PARSER_PTAG: 699 case OPS_PTAG_CT_ENCRYPTED_SECRET_KEY: // we get these because we didn't prompt 700 case OPS_PTAG_CT_SIGNATURE_HEADER: 701 case OPS_PTAG_CT_SIGNATURE_FOOTER: 702 case OPS_PTAG_CT_SIGNATURE: 703 case OPS_PTAG_CT_TRUST: 704 case OPS_PARSER_ERRCODE: 705 break; 706 707 default: 708 ; 709 } 710 711 return OPS_RELEASE_MEMORY; 712 } 713 714 /*\@}*/ 715 451 716 // eof openpgpsdk/trunk/src/lib/memory.c
r571 r574 96 96 } 97 97 98 static ops_boolean_t memory_writer(const unsigned char *src,unsigned length,99 ops_error_t **errors,100 ops_writer_info_t *winfo)101 {102 ops_memory_t *mem=ops_writer_get_arg(winfo);103 104 OPS_USED(errors);105 ops_memory_add(mem,src,length);106 return ops_true;107 }108 109 /**110 * \ingroup Create111 *112 * Set a memory writer. Note that it is the caller's resposibility to113 * release mem.114 *115 * \param info The info structure116 * \param mem The memory structure */117 118 void ops_writer_set_memory(ops_create_info_t *info,ops_memory_t *mem)119 {120 ops_writer_set(info,memory_writer,NULL,NULL,mem);121 }122 123 98 void ops_memory_make_packet(ops_memory_t *out,ops_content_tag_t tag) 124 99 { … … 170 145 void *ops_memory_get_data(ops_memory_t *mem) 171 146 { return mem->buf; } 147 148 // EOF openpgpsdk/trunk/src/lib/packet-parse.c
r571 r574 26 26 #include <openssl/cast.h> 27 27 28 #include <openpgpsdk/callback.h> 28 29 #include <openpgpsdk/packet.h> 29 30 #include <openpgpsdk/packet-parse.h> … … 35 36 #include <openpgpsdk/packet-show.h> 36 37 #include <openpgpsdk/std_print.h> 38 #include <openpgpsdk/create.h> 39 #include <openpgpsdk/hash.h> 37 40 38 41 #include "parse_local.h" … … 156 159 /*! \todo descr for CB macro */ 157 160 /*! \todo check other callback functions to check they match this usage */ 158 #define CB(cbinfo,t,pc) do { (pc)->tag=(t); if((cbinfo)->cb(pc,(cbinfo)) == OPS_RELEASE_MEMORY) ops_parser_content_free(pc); } while(0)159 #define CBP(info,t,pc) CB(&(info)->cbinfo,t,pc)160 161 /*! macro to save typing */ 161 162 #define C content.content 162 163 164 // \todo replace ERRCODE with OPS_ERROR? 163 165 /*! set error code in content and run CallBack to handle error */ 164 166 #define ERRCODE(cbinfo,err) do { C.errcode.errcode=err; CB(cbinfo,OPS_PARSER_ERRCODE,&content); } while(0) 165 167 #define ERRCODEP(pinfo,err) do { C.errcode.errcode=err; CBP(pinfo,OPS_PARSER_ERRCODE,&content); } while(0) 166 168 /*! set error text in content and run CallBack to handle error, then return */ 167 #define ERR(cbinfo,err) do { C.error.error=err; CB(cbinfo,OPS_PARSER_ERROR,&content); return ops_false; } while(0)168 #define ERRP(info,err) do { C.error.error=err; CBP(info,OPS_PARSER_ERROR,&content); return ops_false; } while(0)169 //#define ERR(cbinfo,err) do { C.error.error=err; CB(cbinfo,OPS_PARSER_ERROR,&content); return ops_false; } while(0) 170 //#define ERRP(info,err) do { C.error.error=err; CBP(info,OPS_PARSER_ERROR,&content); return ops_false; } while(0) 169 171 /*! set error text in content and run CallBack to handle warning, do not return */ 170 172 #define WARN(warn) do { C.error.error=warn; CB(OPS_PARSER_ERROR,&content);; } while(0) … … 3190 3192 { return ops_parse_cb(content,cbinfo->next); } 3191 3193 3192 /**3193 * \brief3194 * \param pinfo3195 * \param reader3196 * \param arg3197 */3198 void ops_reader_set(ops_parse_info_t *pinfo,ops_reader_t *reader,ops_reader_destroyer_t *destroyer,void *arg)3199 {3200 pinfo->rinfo.reader=reader;3201 pinfo->rinfo.destroyer=destroyer;3202 pinfo->rinfo.arg=arg;3203 }3204 3205 /**3206 * \brief3207 * \param pinfo3208 * \param reader3209 * \param arg3210 */3211 void ops_reader_push(ops_parse_info_t *pinfo,ops_reader_t *reader,ops_reader_destroyer_t *destroyer,void *arg)3212 {3213 ops_reader_info_t *rinfo=malloc(sizeof *rinfo);3214 3215 *rinfo=pinfo->rinfo;3216 memset(&pinfo->rinfo,'\0',sizeof pinfo->rinfo);3217 pinfo->rinfo.next=rinfo;3218 pinfo->rinfo.pinfo=pinfo;3219 3220 // should copy accumulate flags from other reader? RW3221 pinfo->rinfo.accumulate=rinfo->accumulate;3222 3223 ops_reader_set(pinfo,reader,destroyer,arg);3224 }3225 3226 /**3227 * \param pinfo3228 */3229 void ops_reader_pop(ops_parse_info_t *pinfo)3230 {3231 ops_reader_info_t *next=pinfo->rinfo.next;3232 3233 pinfo->rinfo=*next;3234 free(next);3235 }3236 3237 void *ops_reader_get_arg(ops_reader_info_t *rinfo)3238 { return rinfo->arg; }3239 3240 void *ops_reader_get_arg_from_pinfo(ops_parse_info_t *pinfo)3241 { return pinfo->rinfo.arg; }3242 3243 3194 ops_error_t *ops_parse_info_get_errors(ops_parse_info_t *pinfo) 3244 3195 { return pinfo->errors; } openpgpsdk/trunk/src/lib/packet-print.c
r573 r574 33 33 #include "openpgpsdk/keyring.h" 34 34 #include "keyring_local.h" 35 #include "parse_local.h" 35 36 #include "openpgpsdk/packet-show.h" 36 37 #include "openpgpsdk/util.h" 37 38 #include "openpgpsdk/std_print.h" 39 #include "openpgpsdk/readerwriter.h" 40 #include "openpgpsdk/armour.h" 38 41 39 42 static int indent=0; … … 1189 1192 return 1; 1190 1193 } 1194 1195 static ops_parse_cb_return_t cb_list_packets(const ops_parser_content_t * content_, ops_parse_cb_info_t *cbinfo) 1196 { 1197 const ops_parser_content_union_t *content=&content_->content; 1198 ops_text_t *text; 1199 const char *str; 1200 // const ops_keydata_t *decrypter; 1201 // const ops_secret_key_t *secret; 1202 static ops_boolean_t unarmoured; 1203 1204 OPS_USED(cbinfo); 1205 1206 if(unarmoured && content_->tag != OPS_PTAG_CT_UNARMOURED_TEXT) 1207 { 1208 unarmoured=ops_false; 1209 puts("UNARMOURED TEXT ends"); 1210 } 1211 1212 switch(content_->tag) 1213 { 1214 case OPS_PARSER_ERROR: 1215 printf("parse error: %s\n",content->error.error); 1216 break; 1217 1218 case OPS_PARSER_ERRCODE: 1219 printf("parse error: %s\n", 1220 ops_errcode(content->errcode.errcode)); 1221 break; 1222 1223 case OPS_PARSER_PACKET_END: 1224 print_packet_hex(&content->packet); 1225 break; 1226 1227 case OPS_PARSER_PTAG: 1228 if(content->ptag.content_tag == OPS_PTAG_CT_PUBLIC_KEY) 1229 { 1230 indent=0; 1231 printf("\n*** NEXT KEY ***\n"); 1232 } 1233 1234 printf("\n"); 1235 print_indent(); 1236 printf("==== ptag new_format=%d content_tag=%d length_type=%d" 1237 " length=0x%x (%d) position=0x%x (%d)\n",content->ptag.new_format, 1238 content->ptag.content_tag,content->ptag.length_type, 1239 content->ptag.length,content->ptag.length, 1240 content->ptag.position,content->ptag.position); 1241 print_tagname(ops_show_packet_tag(content->ptag.content_tag)); 1242 break; 1243 1244 case OPS_PTAG_CT_SE_DATA_HEADER: 1245 print_tagname("SYMMETRIC ENCRYPTED DATA"); 1246 break; 1247 1248 case OPS_PTAG_CT_SE_IP_DATA_HEADER: 1249 print_tagname("SYMMETRIC ENCRYPTED INTEGRITY PROTECTED DATA HEADER"); 1250 printf("Version: %d\n",content->se_ip_data_header.version); 1251 break; 1252 1253 case OPS_PTAG_CT_SE_IP_DATA_BODY: 1254 print_tagname("SYMMETRIC ENCRYPTED INTEGRITY PROTECTED DATA BODY"); 1255 printf(" data body length=%d\n", 1256 content->se_data_body.length); 1257 printf(" data="); 1258 hexdump(content->se_data_body.data, 1259 content->se_data_body.length); 1260 printf("\n"); 1261 break; 1262 1263 case OPS_PTAG_CT_PUBLIC_KEY: 1264 case OPS_PTAG_CT_PUBLIC_SUBKEY: 1265 if (content_->tag == OPS_PTAG_CT_PUBLIC_KEY) 1266 print_tagname("PUBLIC KEY"); 1267 else 1268 print_tagname("PUBLIC SUBKEY"); 1269 1270 ops_print_public_key(&content->public_key); 1271 break; 1272 1273 case OPS_PTAG_CT_TRUST: 1274 print_tagname("TRUST"); 1275 print_data("Trust",&content->trust.data); 1276 break; 1277 1278 case OPS_PTAG_CT_USER_ID: 1279 /* XXX: how do we print UTF-8? */ 1280 print_tagname("USER ID"); 1281 print_utf8_string("user_id",content->user_id.user_id); 1282 break; 1283 1284 case OPS_PTAG_CT_SIGNATURE: 1285 print_tagname("SIGNATURE"); 1286 print_indent(indent); 1287 print_unsigned_int("Signature Version", 1288 content->signature.version); 1289 if (content->signature.creation_time_set) 1290 print_time("Signature Creation Time", 1291 content->signature.creation_time); 1292 1293 print_string_and_value("Signature Type", 1294 ops_show_sig_type(content->signature.type), 1295 content->signature.type); 1296 1297 if(content->signature.signer_id_set) 1298 print_hexdump_data("Signer ID", 1299 content->signature.signer_id, 1300 sizeof content->signature.signer_id); 1301 1302 print_string_and_value("Public Key Algorithm", 1303 ops_show_pka(content->signature.key_algorithm), 1304 content->signature.key_algorithm); 1305 print_string_and_value("Hash Algorithm", 1306 ops_show_hash_algorithm(content->signature.hash_algorithm), 1307 content->signature.hash_algorithm); 1308 1309 print_indent(); 1310 print_hexdump_data("hash2",&content->signature.hash2[0],2); 1311 1312 switch(content->signature.key_algorithm) 1313 { 1314 case OPS_PKA_RSA: 1315 case OPS_PKA_RSA_SIGN_ONLY: 1316 print_bn("sig",content->signature.signature.rsa.sig); 1317 break; 1318 1319 case OPS_PKA_DSA: 1320 print_bn("r",content->signature.signature.dsa.r); 1321 print_bn("s",content->signature.signature.dsa.s); 1322 break; 1323 1324 case OPS_PKA_ELGAMAL_ENCRYPT_OR_SIGN: 1325 print_bn("r",content->signature.signature.elgamal.r); 1326 print_bn("s",content->signature.signature.elgamal.s); 1327 break; 1328 1329 default: 1330 assert(0); 1331 } 1332 1333 if(content->signature.hash) 1334 printf("data hash is set\n"); 1335 1336 break; 1337 1338 case OPS_PTAG_CT_COMPRESSED: 1339 print_tagname("COMPRESSED"); 1340 print_unsigned_int("Compressed Data Type", content->compressed.type); 1341 break; 1342 1343 case OPS_PTAG_CT_ONE_PASS_SIGNATURE: 1344 print_tagname("ONE PASS SIGNATURE"); 1345 1346 print_unsigned_int("Version",content->one_pass_signature.version); 1347 print_string_and_value("Signature Type", 1348 ops_show_sig_type(content->one_pass_signature.sig_type), 1349 content->one_pass_signature.sig_type); 1350 print_string_and_value("Hash Algorithm", 1351 ops_show_hash_algorithm(content->one_pass_signature.hash_algorithm), 1352 content->one_pass_signature.hash_algorithm); 1353 print_string_and_value("Public Key Algorithm", 1354 ops_show_pka(content->one_pass_signature.key_algorithm), 1355 content->one_pass_signature.key_algorithm); 1356 print_hexdump_data("Signer ID", 1357 content->one_pass_signature.keyid, 1358 sizeof content->one_pass_signature.keyid); 1359 1360 print_unsigned_int("Nested", 1361 content->one_pass_signature.nested); 1362 break; 1363 1364 case OPS_PTAG_CT_USER_ATTRIBUTE: 1365 print_tagname("USER ATTRIBUTE"); 1366 print_hexdump("User Attribute", 1367 content->user_attribute.data.contents, 1368 content->user_attribute.data.len); 1369 break; 1370 1371 case OPS_PTAG_RAW_SS: 1372 assert(!content_->critical); 1373 start_subpacket(content_->tag); 1374 print_unsigned_int("Raw Signature Subpacket: tag", 1375 content->ss_raw.tag-OPS_PTAG_SIGNATURE_SUBPACKET_BASE); 1376 print_hexdump("Raw Data", 1377 content->ss_raw.raw, 1378 content->ss_raw.length); 1379 break; 1380 1381 case OPS_PTAG_SS_CREATION_TIME: 1382 start_subpacket(content_->tag); 1383 print_time("Signature Creation Time",content->ss_time.time); 1384 end_subpacket(); 1385 break; 1386 1387 case OPS_PTAG_SS_EXPIRATION_TIME: 1388 start_subpacket(content_->tag); 1389 print_duration("Signature Expiration Time",content->ss_time.time); 1390 end_subpacket(); 1391 break; 1392 1393 case OPS_PTAG_SS_KEY_EXPIRATION_TIME: 1394 start_subpacket(content_->tag); 1395 print_duration("Key Expiration Time", content->ss_time.time); 1396 end_subpacket(); 1397 break; 1398 1399 case OPS_PTAG_SS_TRUST: 1400 start_subpacket(content_->tag); 1401 print_string("Trust Signature",""); 1402 print_unsigned_int("Level", 1403 content->ss_trust.level); 1404 print_unsigned_int("Amount", 1405 content->ss_trust.amount); 1406 end_subpacket(); 1407 break; 1408 1409 case OPS_PTAG_SS_REVOCABLE: 1410 start_subpacket(content_->tag); 1411 print_boolean("Revocable",content->ss_revocable.revocable); 1412 end_subpacket(); 1413 break; 1414 1415 case OPS_PTAG_SS_REVOCATION_KEY: 1416 start_subpacket(content_->tag); 1417 /* not yet tested */ 1418 printf (" revocation key: class=0x%x", 1419 content->ss_revocation_key.class); 1420 if (content->ss_revocation_key.class&0x40) 1421 printf (" (sensitive)"); 1422 printf (", algid=0x%x", 1423 content->ss_revocation_key.algid); 1424 printf(", fingerprint="); 1425 hexdump(content->ss_revocation_key.fingerprint,20); 1426 printf("\n"); 1427 end_subpacket(); 1428 break; 1429 1430 case OPS_PTAG_SS_ISSUER_KEY_ID: 1431 start_subpacket(content_->tag); 1432 print_hexdump("Issuer Key Id", 1433 &content->ss_issuer_key_id.key_id[0], 1434 sizeof content->ss_issuer_key_id.key_id); 1435 end_subpacket(); 1436 break; 1437 1438 case OPS_PTAG_SS_PREFERRED_SKA: 1439 start_subpacket(content_->tag); 1440 print_data( "Preferred Symmetric Algorithms", 1441 &content->ss_preferred_ska.data); 1442 1443 text = ops_showall_ss_preferred_ska(content->ss_preferred_ska); 1444 print_text_breakdown(text); 1445 ops_text_free(text); 1446 1447 end_subpacket(); 1448 break; 1449 1450 case OPS_PTAG_SS_PRIMARY_USER_ID: 1451 start_subpacket(content_->tag); 1452 print_boolean("Primary User ID", 1453 content->ss_primary_user_id.primary_user_id); 1454 end_subpacket(); 1455 break; 1456 1457 case OPS_PTAG_SS_PREFERRED_HASH: 1458 start_subpacket(content_->tag); 1459 print_data("Preferred Hash Algorithms", 1460 &content->ss_preferred_hash.data); 1461 1462 text = ops_showall_ss_preferred_hash(content->ss_preferred_hash); 1463 print_text_breakdown(text); 1464 ops_text_free(text); 1465 end_subpacket(); 1466 break; 1467 1468 case OPS_PTAG_SS_PREFERRED_COMPRESSION: 1469 start_subpacket(content_->tag); 1470 print_data( "Preferred Compression Algorithms", 1471 &content->ss_preferred_compression.data); 1472 1473 text = ops_showall_ss_preferred_compression(content->ss_preferred_compression); 1474 print_text_breakdown(text); 1475 ops_text_free(text); 1476 end_subpacket(); 1477 break; 1478 1479 case OPS_PTAG_SS_KEY_FLAGS: 1480 start_subpacket(content_->tag); 1481 print_data( "Key Flags", &content->ss_key_flags.data); 1482 1483 text = ops_showall_ss_key_flags(content->ss_key_flags); 1484 print_text_breakdown( text); 1485 ops_text_free(text); 1486 1487 end_subpacket(); 1488 break; 1489 1490 case OPS_PTAG_SS_KEY_SERVER_PREFS: 1491 start_subpacket(content_->tag); 1492 print_data( "Key Server Preferences", 1493 &content->ss_key_server_prefs.data); 1494 1495 text = ops_showall_ss_key_server_prefs(content->ss_key_server_prefs); 1496 print_text_breakdown( text); 1497 ops_text_free(text); 1498 1499 end_subpacket(); 1500 break; 1501 1502 case OPS_PTAG_SS_FEATURES: 1503 start_subpacket(content_->tag); 1504 print_data( "Features", 1505 &content->ss_features.data); 1506 1507 text = ops_showall_ss_features(content->ss_features); 1508 print_text_breakdown( text); 1509 ops_text_free(text); 1510 1511 end_subpacket(); 1512 break; 1513 1514 case OPS_PTAG_SS_NOTATION_DATA: 1515 start_subpacket(content_->tag); 1516 print_indent(); 1517 printf("Notation Data:\n"); 1518 1519 indent++; 1520 print_data( "Flags", 1521 &content->ss_notation_data.flags); 1522 text = ops_showall_ss_notation_data_flags(content->ss_notation_data); 1523 print_text_breakdown( text); 1524 ops_text_free(text); 1525 1526 /* xxx - TODO: print out UTF - rachel */ 1527 1528 print_data( "Name", 1529 &content->ss_notation_data.name); 1530 1531 print_data( "Value", 1532 &content->ss_notation_data.value); 1533 1534 indent--; 1535 end_subpacket(); 1536 break; 1537 1538 case OPS_PTAG_SS_REGEXP: 1539 start_subpacket(content_->tag); 1540 print_hexdump("Regular Expression", 1541 (unsigned char *)content->ss_regexp.text, 1542 strlen(content->ss_regexp.text)); 1543 print_string(NULL, 1544 content->ss_regexp.text); 1545 end_subpacket(); 1546 break; 1547 1548 case OPS_PTAG_SS_POLICY_URL: 1549 start_subpacket(content_->tag); 1550 print_string("Policy URL", 1551 content->ss_policy_url.text); 1552 end_subpacket(); 1553 break; 1554 1555 case OPS_PTAG_SS_SIGNERS_USER_ID: 1556 start_subpacket(content_->tag); 1557 print_utf8_string("Signer's User ID",content->ss_signers_user_id.user_id); 1558 end_subpacket(); 1559 break; 1560 1561 case OPS_PTAG_SS_PREFERRED_KEY_SERVER: 1562 start_subpacket(content_->tag); 1563 print_string("Preferred Key Server", 1564 content->ss_preferred_key_server.text); 1565 end_subpacket(); 1566 break; 1567 1568 case OPS_PTAG_SS_USERDEFINED00: 1569 case OPS_PTAG_SS_USERDEFINED01: 1570 case OPS_PTAG_SS_USERDEFINED02: 1571 case OPS_PTAG_SS_USERDEFINED03: 1572 case OPS_PTAG_SS_USERDEFINED04: 1573 case OPS_PTAG_SS_USERDEFINED05: 1574 case OPS_PTAG_SS_USERDEFINED06: 1575 case OPS_PTAG_SS_USERDEFINED07: 1576 case OPS_PTAG_SS_USERDEFINED08: 1577 case OPS_PTAG_SS_USERDEFINED09: 1578 case OPS_PTAG_SS_USERDEFINED10: 1579 start_subpacket(content_->tag); 1580 print_hexdump("Internal or user-defined", 1581 content->ss_userdefined.data.contents, 1582 content->ss_userdefined.data.len); 1583 end_subpacket(); 1584 break; 1585 1586 case OPS_PTAG_SS_RESERVED: 1587 start_subpacket(content_->tag); 1588 print_hexdump("Reserved", 1589 content->ss_userdefined.data.contents, 1590 content->ss_userdefined.data.len); 1591 end_subpacket(); 1592 break; 1593 1594 case OPS_PTAG_SS_REVOCATION_REASON: 1595 start_subpacket(content_->tag); 1596 print_hexdump("Revocation Reason", 1597 &content->ss_revocation_reason.code, 1598 1); 1599 str=ops_show_ss_rr_code(content->ss_revocation_reason.code); 1600 print_string(NULL,str); 1601 /* xxx - todo : output text as UTF-8 string */ 1602 end_subpacket(); 1603 break; 1604 1605 case OPS_PTAG_CT_LITERAL_DATA_HEADER: 1606 print_tagname("LITERAL DATA HEADER"); 1607 printf(" literal data header format=%c filename='%s'\n", 1608 content->literal_data_header.format, 1609 content->literal_data_header.filename); 1610 showtime(" modification time", 1611 content->literal_data_header.modification_time); 1612 printf("\n"); 1613 break; 1614 1615 case OPS_PTAG_CT_LITERAL_DATA_BODY: 1616 print_tagname("LITERAL DATA BODY"); 1617 printf(" literal data body length=%d\n", 1618 content->literal_data_body.length); 1619 printf(" data="); 1620 print_escaped(content->literal_data_body.data, 1621 content->literal_data_body.length); 1622 printf("\n"); 1623 break; 1624 1625 case OPS_PTAG_CT_SIGNATURE_HEADER: 1626 print_tagname("SIGNATURE"); 1627 print_indent(indent); 1628 print_unsigned_int("Signature Version", 1629 content->signature.version); 1630 if(content->signature.creation_time_set) 1631 print_time("Signature Creation Time", content->signature.creation_time); 1632 1633 print_string_and_value("Signature Type", 1634 ops_show_sig_type(content->signature.type), 1635 content->signature.type); 1636 1637 if(content->signature.signer_id_set) 1638 print_hexdump_data("Signer ID", 1639 content->signature.signer_id, 1640 sizeof content->signature.signer_id); 1641 1642 print_string_and_value("Public Key Algorithm", 1643 ops_show_pka(content->signature.key_algorithm), 1644 content->signature.key_algorithm); 1645 print_string_and_value("Hash Algorithm", 1646 ops_show_hash_algorithm(content->signature.hash_algorithm), 1647 content->signature.hash_algorithm); 1648 1649 break; 1650 1651 case OPS_PTAG_CT_SIGNATURE_FOOTER: 1652 print_indent(); 1653 print_hexdump_data("hash2",&content->signature.hash2[0],2); 1654 1655 switch(content->signature.key_algorithm) 1656 { 1657 case OPS_PKA_RSA: 1658 print_bn("sig",content->signature.signature.rsa.sig); 1659 break; 1660 1661 case OPS_PKA_DSA: 1662 print_bn("r",content->signature.signature.dsa.r); 1663 print_bn("s",content->signature.signature.dsa.s); 1664 break; 1665 1666 case OPS_PKA_ELGAMAL_ENCRYPT_OR_SIGN: 1667 print_bn("r",content->signature.signature.elgamal.r); 1668 print_bn("s",content->signature.signature.elgamal.s); 1669 break; 1670 1671 case OPS_PKA_PRIVATE00: 1672 case OPS_PKA_PRIVATE01: 1673 case OPS_PKA_PRIVATE02: 1674 case OPS_PKA_PRIVATE03: 1675 case OPS_PKA_PRIVATE04: 1676 case OPS_PKA_PRIVATE05: 1677 case OPS_PKA_PRIVATE06: 1678 case OPS_PKA_PRIVATE07: 1679 case OPS_PKA_PRIVATE08: 1680 case OPS_PKA_PRIVATE09: 1681 case OPS_PKA_PRIVATE10: 1682 print_data("Private/Experimental", 1683 &content->signature.signature.unknown.data); 1684 break; 1685 1686 default: 1687 assert(0); 1688 } 1689 break; 1690 1691 case OPS_PARSER_CMD_GET_SK_PASSPHRASE: 1692 #ifdef XXX 1693 if(passphrase_prompt) 1694 { 1695 ops_print_secret_key(OPS_PTAG_CT_ENCRYPTED_SECRET_KEY, 1696 content->secret_key_passphrase.secret_key); 1697 *content->secret_key_passphrase.passphrase=ops_get_passphrase(); 1698 if(!**content->secret_key_passphrase.passphrase) 1699 break; 1700 return OPS_KEEP_MEMORY; 1701 } 1702 else 1703 printf(">>> ASKED FOR PASSPHRASE <<<\n"); 1704 #else 1705 if (cbinfo->cryptinfo.cb_get_passphrase) 1706 return cbinfo->cryptinfo.cb_get_passphrase(content_,cbinfo); 1707 #endif /*XXX*/ 1708 break; 1709 1710 case OPS_PTAG_CT_SECRET_KEY: 1711 case OPS_PTAG_CT_ENCRYPTED_SECRET_KEY: 1712 ops_print_secret_key_verbose(content_->tag,&content->secret_key); 1713 break; 1714 1715 case OPS_PTAG_CT_ARMOUR_HEADER: 1716 print_tagname("ARMOUR HEADER"); 1717 print_string("type",content->armour_header.type); 1718 break; 1719 1720 case OPS_PTAG_CT_SIGNED_CLEARTEXT_HEADER: 1721 print_tagname("SIGNED CLEARTEXT HEADER"); 1722 print_headers(&content->signed_cleartext_header.headers); 1723 break; 1724 1725 case OPS_PTAG_CT_SIGNED_CLEARTEXT_BODY: 1726 print_tagname("SIGNED CLEARTEXT BODY"); 1727 print_block("signed cleartext",content->signed_cleartext_body.data, 1728 content->signed_cleartext_body.length); 1729 break; 1730 1731 case OPS_PTAG_CT_SIGNED_CLEARTEXT_TRAILER: 1732 print_tagname("SIGNED CLEARTEXT TRAILER"); 1733 printf("hash algorithm: %d\n", 1734 content->signed_cleartext_trailer.hash->algorithm); 1735 printf("\n"); 1736 break; 1737 1738 case OPS_PTAG_CT_UNARMOURED_TEXT: 1739 if(!unarmoured) 1740 { 1741 print_tagname("UNARMOURED TEXT"); 1742 unarmoured=ops_true; 1743 } 1744 putchar('['); 1745 print_escaped(content->unarmoured_text.data, 1746 content->unarmoured_text.length); 1747 putchar(']'); 1748 break; 1749 1750 case OPS_PTAG_CT_ARMOUR_TRAILER: 1751 print_tagname("ARMOUR TRAILER"); 1752 print_string("type",content->armour_header.type); 1753 break; 1754 1755 case OPS_PTAG_CT_PK_SESSION_KEY: 1756 case OPS_PTAG_CT_ENCRYPTED_PK_SESSION_KEY: 1757 ops_print_pk_session_key(content_->tag,&content->pk_session_key); 1758 break; 1759 1760 case OPS_PARSER_CMD_GET_SECRET_KEY: 1761 ops_print_pk_session_key(OPS_PTAG_CT_ENCRYPTED_PK_SESSION_KEY, 1762 content->get_secret_key.pk_session_key); 1763 1764 #ifdef XXX 1765 decrypter=ops_keyring_find_key_by_id(&keyring, 1766 content->get_secret_key.pk_session_key->key_id); 1767 if(!decrypter || !ops_key_is_secret(decrypter)) 1768 break; 1769 1770 puts("[Decryption key found in keyring]"); 1771 1772 secret=ops_get_secret_key_from_data(decrypter); 1773 while(!secret) 1774 { 1775 /* then it must be encrypted */ 1776 char *phrase=ops_get_passphrase(); 1777 secret=ops_decrypt_secret_key_from_data(decrypter,phrase); 1778 free(phrase); 1779 } 1780 1781 *content->get_secret_key.secret_key=secret; 1782 #else 1783 return callback_cmd_get_secret_key(content_,cbinfo); 1784 #endif /*XXX*/ 1785 break; 1786 1787 default: 1788 print_tagname("UNKNOWN PACKET TYPE"); 1789 fprintf(stderr,"packet-dump: unknown tag=%d (0x%x)\n",content_->tag, 1790 content_->tag); 1791 exit(1); 1792 } 1793 return OPS_RELEASE_MEMORY; 1794 } 1795 1796 void ops_list_packets(char* filename, ops_boolean_t armour, ops_keyring_t* keyring, ops_parse_cb_t* cb_get_passphrase) 1797 { 1798 int fd=0; 1799 ops_parse_info_t *pinfo=NULL; 1800 const ops_boolean_t accumulate=ops_true; 1801 1802 fd=ops_setup_file_read(&pinfo, filename, NULL, cb_list_packets, accumulate); 1803 ops_parse_options(pinfo,OPS_PTAG_SS_ALL,OPS_PARSE_PARSED); 1804 pinfo->cryptinfo.keyring=keyring; 1805 pinfo->cryptinfo.cb_get_passphrase=cb_get_passphrase; 1806 1807 if(armour) 1808 ops_reader_push_dearmour(pinfo,ops_true,ops_true,ops_true); 1809 1810 ops_parse_and_print_errors(pinfo); 1811 1812 ops_teardown_file_read(pinfo,fd); 1813 1814 ops_finish(); 1815 } openpgpsdk/trunk/src/lib/parse_local.h
r570 r574 66 66 67 67 ops_create_info_t *cinfo; /*!< used if writing out parsed info */ 68 ops_crypt_info_t crypt ;68 ops_crypt_info_t cryptinfo; /*!< used when decrypting */ 69 69 }; 70 70 … … 110 110 ops_error_t *errors; 111 111 ops_crypt_t decrypt; 112 ops_crypt_info_t cryptinfo; 112 113 size_t nhashes; 113 114 ops_parse_hash_info_t *hashes; openpgpsdk/trunk/src/lib/readerwriter.c
r571 r574 26 26 #include <direct.h> 27 27 #endif 28 #include <termios.h> 28 29 #include <assert.h> 29 30 #include <string.h> … … 31 32 32 33 #include <openpgpsdk/readerwriter.h> 34 #include <openpgpsdk/callback.h> 35 33 36 #include "parse_local.h" 34 35 /*! \todo descr for CB macro */36 /*! \todo check other callback functions to check they match this usage */37 #define CB(cbinfo,t,pc) do { (pc)->tag=(t); if((cbinfo)->cb(pc,(cbinfo)) == OPS_RELEASE_MEMORY) ops_parser_content_free(pc); } while(0)38 #define CBP(info,t,pc) CB(&(info)->cbinfo,t,pc)39 37 40 38 void ops_setup_memory_write(ops_create_info_t **cinfo, ops_memory_t **mem, size_t bufsz) … … 116 114 void ops_teardown_file_write(ops_create_info_t *cinfo, int fd) 117 115 { 118 ops_writer_close(cinfo); // new116 ops_writer_close(cinfo); 119 117 close(fd); 120 118 ops_create_info_delete(cinfo); … … 239 237 case OPS_PTAG_CT_PK_SESSION_KEY: 240 238 // printf ("OPS_PTAG_CT_PK_SESSION_KEY\n"); 241 assert(cbinfo->crypt .keyring);242 cbinfo->crypt .keydata=ops_keyring_find_key_by_id(cbinfo->crypt.keyring,239 assert(cbinfo->cryptinfo.keyring); 240 cbinfo->cryptinfo.keydata=ops_keyring_find_key_by_id(cbinfo->cryptinfo.keyring, 243 241 content->pk_session_key.key_id); 244 if(!cbinfo->crypt .keydata)242 if(!cbinfo->cryptinfo.keydata) 245 243 break; 246 244 break; … … 268 266 { 269 267 case OPS_PARSER_CMD_GET_SECRET_KEY: 270 cbinfo->crypt .keydata=ops_keyring_find_key_by_id(cbinfo->crypt.keyring,content->get_secret_key.pk_session_key->key_id);271 if (!cbinfo->crypt .keydata || !ops_key_is_secret(cbinfo->crypt.keydata))268 cbinfo->cryptinfo.keydata=ops_keyring_find_key_by_id(cbinfo->cryptinfo.keyring,content->get_secret_key.pk_session_key->key_id); 269 if (!cbinfo->cryptinfo.keydata || !ops_key_is_secret(cbinfo->cryptinfo.keydata)) 272 270 return 0; 273 271 274 272 /* do we need the passphrase and not have it? if so, get it */ 275 if (!cbinfo->crypt .passphrase)273 if (!cbinfo->cryptinfo.passphrase) 276 274 { 277 275 memset(&pc,'\0',sizeof pc); 278 pc.content.secret_key_passphrase.passphrase=&cbinfo->crypt .passphrase;276 pc.content.secret_key_passphrase.passphrase=&cbinfo->cryptinfo.passphrase; 279 277 CB(cbinfo,OPS_PARSER_CMD_GET_SK_PASSPHRASE,&pc); 280 if (!cbinfo->crypt .passphrase)278 if (!cbinfo->cryptinfo.passphrase) 281 279 { 282 280 fprintf(stderr,"can't get passphrase\n"); … … 286 284 287 285 /* now get the key from the data */ 288 secret=ops_get_secret_key_from_data(cbinfo->crypt .keydata);286 secret=ops_get_secret_key_from_data(cbinfo->cryptinfo.keydata); 289 287 while(!secret) 290 288 { 291 if (!cbinfo->crypt .passphrase)289 if (!cbinfo->cryptinfo.passphrase) 292 290 { 293 /* get the passphrase */291 /* get the passphrase again?*/ 294 292 } 295 293 /* then it must be encrypted */ 296 secret=ops_decrypt_secret_key_from_data(cbinfo->crypt .keydata,cbinfo->crypt.passphrase);294 secret=ops_decrypt_secret_key_from_data(cbinfo->cryptinfo.keydata,cbinfo->cryptinfo.passphrase); 297 295 } 298 296 … … 308 306 } 309 307 308 static void echo_off() 309 { 310 #ifndef WIN32 311 struct termios term; 312 int r; 313 314 r=tcgetattr(0,&term); 315 if(r < 0 && errno == ENOTTY) 316 return; 317 assert(r >= 0); 318 319 term.c_lflag &= ~ECHO; 320 321 r=tcsetattr(0,TCSANOW,&term); 322 assert(r >= 0); 323 #endif 324 } 325 326 static void echo_on() 327 { 328 #ifndef WIN32 329 struct termios term; 330 int r; 331 332 r=tcgetattr(0,&term); 333 if(r < 0 && errno == ENOTTY) 334 return; 335 assert(r >= 0); 336 337 term.c_lflag |= ECHO; 338 339 r=tcsetattr(0,TCSANOW,&term); 340 assert(r >= 0); 341 #endif 342 } 343 344 char *ops_get_passphrase(void) 345 { 346 char buffer[1024]; 347 size_t n; 348 349 printf("Passphrase: "); 350 351 echo_off(); 352 fgets(buffer,sizeof buffer,stdin); 353 echo_on(); 354 355 putchar('\n'); 356 357 n=strlen(buffer); 358 if(n && buffer[n-1] == '\n') 359 buffer[--n]='\0'; 360 return ops_malloc_passphrase(buffer); 361 } 362 363 char *ops_malloc_passphrase(char *pp) 364 { 365 char *passphrase; 366 size_t n; 367 368 n=strlen(pp); 369 passphrase=malloc(n+1); 370 strcpy(passphrase,pp); 371 372 return passphrase; 373 } 374 310 375 ops_parse_cb_return_t 311 376 callback_cmd_get_passphrase_from_cmdline(const ops_parser_content_t *content_,ops_parse_cb_info_t *cbinfo) 312 377 { 313 const int max_pp=256;314 char pp[max_pp+1];315 //char *pp=NULL;316 317 378 ops_parser_content_union_t* content=(ops_parser_content_union_t *)&content_->content; 318 379 … … 324 385 { 325 386 case OPS_PARSER_CMD_GET_SK_PASSPHRASE: 326 327 printf("\nEnter passphrase: "); 328 fgets(&pp[0],max_pp, stdin); 329 330 *(content->secret_key_passphrase.passphrase)=ops_malloc_passphrase(pp); 387 *(content->secret_key_passphrase.passphrase)=ops_get_passphrase(); 331 388 return OPS_KEEP_MEMORY; 332 389 break; openpgpsdk/trunk/src/lib/signature.c
r573 r574 27 27 #include <openpgpsdk/crypto.h> 28 28 #include <openpgpsdk/create.h> 29 #include <openpgpsdk/writer_armoured.h> 30 29 31 #include <assert.h> 30 32 #include <string.h> 33 #include <fcntl.h> 34 #include <unistd.h> 31 35 32 36 #include <openpgpsdk/final.h> 33 37 34 38 static int debug=0; 39 #define MAXBUF 1024 35 40 36 41 /** \ingroup Create … … 768 773 { return &sig->hash; } 769 774 775 ops_boolean_t ops_sign_file_as_cleartext(const char* filename, const ops_secret_key_t *skey, const ops_boolean_t overwrite) 776 { 777 // \todo allow choice of hash algorithams 778 // enforce use of SHA1 for now 779 780 unsigned char keyid[OPS_KEY_ID_SIZE]; 781 ops_create_signature_t *sig=NULL; 782 783 char signed_file[MAXBUF+1]; 784 char *suffix= "asc"; 785 int fd_in=0; 786 int fd_out=0; 787 ops_create_info_t *cinfo=NULL; 788 unsigned char buf[MAXBUF]; 789 //int flags=0; 790 ops_boolean_t rtn=ops_false; 791 792 // open file to sign 793 #ifdef WIN32 794 fd_in=open(filename,O_RDONLY | O_BINARY); 795 #else 796 fd_in=open(filename,O_RDONLY); 797 #endif 798 if(fd_in < 0) 799 { 800 return ops_false; 801 } 802 803 // set up output file 804 snprintf(signed_file,sizeof signed_file,"%s.%s",filename,suffix); 805 fd_out=ops_setup_file_write(&cinfo, signed_file, overwrite); 806 if (fd_out < 0) 807 { 808 close (fd_in); 809 return ops_false; 810 } 811 812 // set up signature 813 sig=ops_create_signature_new(); 814 if (!sig) 815 { 816 close (fd_in); 817 ops_teardown_file_write(cinfo,fd_out); 818 return ops_false; 819 } 820 821 // \todo could add more error detection here 822 ops_signature_start_cleartext_signature(sig,skey,OPS_HASH_SHA1,OPS_SIG_BINARY); 823 if (ops_writer_push_clearsigned(cinfo,sig)!=ops_true) 824 { return ops_false; } 825 826 // Do the signing 827 828 for (;;) 829 { 830 int n=0; 831 832 n=read(fd_in,buf,sizeof(buf)); 833 if (!n) 834 break; 835 assert(n>=0); 836 ops_write(buf,n,cinfo); 837 } 838 close(fd_in); 839 840 // add signature with subpackets: 841 // - creation time 842 // - key id 843 rtn = ops_writer_switch_to_armoured_signature(cinfo) 844 && ops_signature_add_creation_time(sig,time(NULL)); 845 if (rtn==ops_false) 846 { 847 ops_teardown_file_write(cinfo,fd_out); 848 return ops_false; 849 } 850 851 ops_keyid(keyid,&skey->public_key); 852 853 rtn = ops_signature_add_issuer_key_id(sig,keyid) 854 && ops_signature_hashed_subpackets_end(sig) 855 && ops_write_signature(sig,&skey->public_key,skey,cinfo); 856 857 ops_teardown_file_write(cinfo,fd_out); 858 859 if (rtn==ops_false) 860 { 861 OPS_ERROR(&cinfo->errors,OPS_E_W,"Cannot sign file as cleartext"); 862 } 863 return rtn; 864 } 865 866 867 /* It is the calling function's responsibility to free signed_cleartext */ 868 /* signed_cleartext should be a NULL pointer when passed in */ 869 ops_boolean_t ops_sign_buf_as_cleartext(const char* cleartext, const size_t len, ops_memory_t** signed_cleartext, const ops_secret_key_t *skey) 870 { 871 ops_boolean_t rtn=ops_false; 872 873 // \todo allow choice of hash algorithams 874 // enforce use of SHA1 for now 875 876 unsigned char keyid[OPS_KEY_ID_SIZE]; 877 ops_create_signature_t *sig=NULL; 878 879 ops_create_info_t *cinfo=NULL; 880 881 assert(*signed_cleartext==NULL); 882 883 // set up signature 884 sig=ops_create_signature_new(); 885 if (!sig) 886 { 887 return ops_false; 888 } 889 890 // \todo could add more error detection here 891 ops_signature_start_cleartext_signature(sig,skey,OPS_HASH_SHA1,OPS_SIG_BINARY); 892 893 // set up output file 894 ops_setup_memory_write(&cinfo, signed_cleartext, len); 895 896 // Do the signing 897 // add signature with subpackets: 898 // - creation time 899 // - key id 900 rtn = ops_writer_push_clearsigned(cinfo,sig) 901 && ops_write(cleartext,len,cinfo) 902 && ops_writer_switch_to_armoured_signature(cinfo) 903 && ops_signature_add_creation_time(sig,time(NULL)); 904 905 if (rtn==ops_false) 906 { 907 return ops_false; 908 } 909 910 ops_keyid(keyid,&skey->public_key); 911 912 rtn = ops_signature_add_issuer_key_id(sig,keyid) 913 && ops_signature_hashed_subpackets_end(sig) 914 && ops_write_signature(sig,&skey->public_key,skey,cinfo) 915 && ops_writer_close(cinfo); 916 917 // Note: the calling function must free signed_cleartext 918 ops_create_info_delete(cinfo); 919 920 return rtn; 921 } 922 923 void ops_sign_file(const char* input_filename, const char* output_filename, const ops_secret_key_t *skey, const ops_boolean_t use_armour, const ops_boolean_t overwrite) 924 { 925 // \todo allow choice of hash algorithams 926 // enforce use of SHA1 for now 927 928 char *myfilename=NULL; 929 unsigned char keyid[OPS_KEY_ID_SIZE]; 930 ops_create_signature_t *sig=NULL; 931 932 int fd_out=0; 933 ops_create_info_t *cinfo=NULL; 934 935 ops_hash_algorithm_t hash_alg=OPS_HASH_SHA1; 936 ops_sig_type_t sig_type=OPS_SIG_BINARY; 937 938 ops_memory_t* mem_buf=NULL; 939 ops_hash_t* hash=NULL; 940 941 // read input file into buf 942 943 mem_buf=ops_write_buf_from_file(input_filename); 944 945 // setup output filename 946 if (!output_filename) 947 { 948 myfilename=ops_mallocz(strlen(input_filename)+4+1); 949 if (use_armour) 950 sprintf(myfilename,"%s.asc",input_filename); 951 else 952 sprintf(myfilename,"%s.gpg",input_filename); 953 fd_out=ops_setup_file_write(&cinfo, myfilename, overwrite); 954 free(myfilename); 955 } 956 else 957 { 958 fd_out=ops_setup_file_write(&cinfo, output_filename, overwrite); 959 } 960 961 // set up signature 962 sig=ops_create_signature_new(); 963 ops_signature_start_message_signature(sig, skey, hash_alg, sig_type); 964 965 // set armoured/not armoured here 966 if (use_armour) 967 ops_writer_push_armoured_message(cinfo); 968 969 if (debug) 970 { fprintf(stderr, "** Writing out one pass sig\n"); } 971 972 // write one_pass_sig 973 ops_write_one_pass_sig(skey, hash_alg, sig_type, cinfo); 974 975 // hash file contents 976 hash=ops_signature_get_hash(sig); 977 hash->add(hash, ops_memory_get_data(mem_buf), ops_memory_get_length(mem_buf)); 978 979 // output file contents as Literal Data packet 980 981 if (debug) 982 { fprintf(stderr,"** Writing out data now\n"); } 983 984 ops_write_literal_data_from_buf(ops_memory_get_data(mem_buf), ops_memory_get_length(mem_buf), OPS_LDT_BINARY, cinfo); 985 986 if (debug) 987 { fprintf(stderr,"** After Writing out data now\n");} 988 989 // add subpackets to signature 990 // - creation time 991 // - key id 992 993 ops_signature_add_creation_time(sig,time(NULL)); 994 995 ops_keyid(keyid,&skey->public_key); 996 ops_signature_add_issuer_key_id(sig,keyid); 997 998 ops_signature_hashed_subpackets_end(sig); 999 1000 // write out sig 1001 ops_write_signature(sig,&skey->public_key,skey,cinfo); 1002 1003 ops_teardown_file_write(cinfo, fd_out); 1004 1005 // tidy up 1006 ops_create_signature_delete(sig); 1007 ops_memory_free(mem_buf); 1008 } 1009 1010 ops_memory_t* ops_sign_mem(const void* input, const int input_len, const ops_sig_type_t sig_type, const ops_secret_key_t *skey, const ops_boolean_t use_armour) 1011 { 1012 // \todo allow choice of hash algorithams 1013 // enforce use of SHA1 for now 1014 1015 unsigned char keyid[OPS_KEY_ID_SIZE]; 1016 ops_create_signature_t *sig=NULL; 1017 1018 ops_create_info_t *cinfo=NULL; 1019 ops_memory_t *mem=ops_memory_new(); 1020 1021 ops_hash_algorithm_t hash_alg=OPS_HASH_SHA1; 1022 // ops_sig_type_t sig_type=OPS_SIG_BINARY; 1023 ops_literal_data_type_t ld_type; 1024 ops_hash_t* hash=NULL; 1025 1026 // setup literal data packet type 1027 if (sig_type==OPS_SIG_BINARY) 1028 ld_type=OPS_LDT_BINARY; 1029 else 1030 ld_type=OPS_LDT_TEXT; 1031 1032 // set up signature 1033 sig=ops_create_signature_new(); 1034 ops_signature_start_message_signature(sig, skey, hash_alg, sig_type); 1035 1036 // setup writer 1037 ops_setup_memory_write(&cinfo, &mem, input_len); 1038 1039 // set armoured/not armoured here 1040 if (use_armour) 1041 ops_writer_push_armoured_message(cinfo); 1042 1043 if (debug) 1044 { fprintf(stderr, "** Writing out one pass sig\n"); } 1045 1046 // write one_pass_sig 1047 ops_write_one_pass_sig(skey, hash_alg, sig_type, cinfo); 1048 1049 // hash file contents 1050 hash=ops_signature_get_hash(sig); 1051 hash->add(hash, input, input_len); 1052 1053 // output file contents as Literal Data packet 1054 1055 if (debug) 1056 { fprintf(stderr,"** Writing out data now\n"); } 1057 1058 ops_write_literal_data_from_buf(input, input_len, ld_type, cinfo); 1059 1060 if (debug) 1061 { fprintf(stderr,"** After Writing out data now\n");} 1062 1063 // add subpackets to signature 1064 // - creation time 1065 // - key id 1066 1067 ops_signature_add_creation_time(sig,time(NULL)); 1068 1069 ops_keyid(keyid,&skey->public_key); 1070 ops_signature_add_issuer_key_id(sig,keyid); 1071 1072 ops_signature_hashed_subpackets_end(sig); 1073 1074 // write out sig 1075 ops_write_signature(sig,&skey->public_key,skey,cinfo); 1076 1077 // tidy up 1078 ops_writer_close(cinfo); 1079 ops_create_signature_delete(sig); 1080 1081 return mem; 1082 } 1083 1084 // EOF openpgpsdk/trunk/src/lib/symmetric.c
r571 r574 34 34 #include <openpgpsdk/final.h> 35 35 36 static int debug=0;36 //static int debug=0; 37 37 38 38 #ifndef ATTRIBUTE_UNUSED … … 45 45 46 46 #endif /* ATTRIBUTE_UNUSED */ 47 48 49 // \todo there's also a encrypted_arg_t in adv_create.c50 // which is used for *encrypting* whereas this is used51 // for *decrypting*52 53 typedef struct54 {55 unsigned char decrypted[1024];56 size_t decrypted_count;57 size_t decrypted_offset;58 ops_crypt_t *decrypt;59 ops_region_t *region;60 ops_boolean_t prev_read_was_plain:1;61 } encrypted_arg_t;62 63 static int encrypted_data_reader(void *dest,size_t length,ops_error_t **errors,64 ops_reader_info_t *rinfo,65 ops_parse_cb_info_t *cbinfo)66 {67 encrypted_arg_t *arg=ops_reader_get_arg(rinfo);68 int saved=length;69 70 // V3 MPIs have the count plain and the cipher is reset after each count71 if(arg->prev_read_was_plain && !rinfo->pinfo->reading_mpi_length)72 {73 assert(rinfo->pinfo->reading_v3_secret);74 arg->decrypt->decrypt_resync(arg->decrypt);75 arg->prev_read_was_plain=ops_false;76 }77 else if(rinfo->pinfo->reading_v3_secret78 && rinfo->pinfo->reading_mpi_length)79 {80 arg->prev_read_was_plain=ops_true;81 }82 83 while(length > 0)84 {85 if(arg->decrypted_count)86 {87 88 unsigned n;89 90 // if we are reading v3 we should never read more than91 // we're asked for92 assert(length >= arg->decrypted_count93 || (!rinfo->pinfo->reading_v3_secret94 && !rinfo->pinfo->exact_read));95 96 if(length > arg->decrypted_count)97 n=arg->decrypted_count;98 else99 n=length;100 101 memcpy(dest,arg->decrypted+arg->decrypted_offset,n);102 arg->decrypted_count-=n;103 arg->decrypted_offset+=n;104 length-=n;105 #ifdef WIN32106 (char*)dest+=n;107 #else108 dest+=n;109 #endif110 }111 else112 {113 unsigned n=arg->region->length;114 unsigned char buffer[1024];115 116 if(!n)117 {118 return -1;119 }120 121 if(!arg->region->indeterminate)122 {123 n-=arg->region->length_read;124 if(n == 0)125 return saved-length;126 if(n > sizeof buffer)127 n=sizeof buffer;128 }129 else130 {131 n=sizeof buffer;132 }133 134 // we can only read as much as we're asked for in v3 keys135 // because they're partially unencrypted!136 if((rinfo->pinfo->reading_v3_secret || rinfo->pinfo->exact_read)137 && n > length)138 n=length;139 140 if(!ops_stacked_limited_read(buffer,n,arg->region,errors,rinfo,141 cbinfo))142 {143 return -1;144 }145 146 if(!rinfo->pinfo->reading_v3_secret147 || !rinfo->pinfo->reading_mpi_length)148 {149 arg->decrypted_count=ops_decrypt_se_ip(arg->decrypt,150 arg->decrypted,151 buffer,n);152 153 if (debug)154 {155 fprintf(stderr,"READING:\nencrypted: ");156 int i=0;157 for (i=0; i<16; i++)158 fprintf(stderr,"%2x ", buffer[i]);159 fprintf(stderr,"\n");160 fprintf(stderr,"decrypted: ");161 for (i=0; i<16; i++)162 fprintf(stderr,"%2x ", arg->decrypted[i]);163 fprintf(stderr,"\n");164 }165 }166 else167 {168 memcpy(arg->decrypted,buffer,n);169 arg->decrypted_count=n;170 }171 172 assert(arg->decrypted_count > 0);173 174 arg->decrypted_offset=0;175 }176 }177 178 return saved;179 }180 181 static void encrypted_data_destroyer(ops_reader_info_t *rinfo)182 { free(ops_reader_get_arg(rinfo)); }183 184 void ops_reader_push_decrypt(ops_parse_info_t *pinfo,ops_crypt_t *decrypt,185 ops_region_t *region)186 {187 encrypted_arg_t *arg=ops_mallocz(sizeof *arg);188 189 arg->decrypt=decrypt;190 arg->region=region;191 192 ops_decrypt_init(arg->decrypt);193 194 ops_reader_push(pinfo,encrypted_data_reader,encrypted_data_destroyer,arg);195 }196 197 void ops_reader_pop_decrypt(ops_parse_info_t *pinfo)198 {199 encrypted_arg_t *arg=ops_reader_get_arg(ops_parse_get_rinfo(pinfo));200 201 arg->decrypt->decrypt_finish(arg->decrypt);202 free(arg);203 204 ops_reader_pop(pinfo);205 }206 47 207 48 static void std_set_iv(ops_crypt_t *crypt,const unsigned char *iv) … … 675 516 return count; 676 517 } 518 519 // EOF openpgpsdk/trunk/src/lib/util.c
r571 r574 106 106 } 107 107 108 /** Arguments for reader_fd109 */110 typedef struct111 {112 int fd; /*!< file descriptor */113 } reader_fd_arg_t;114 115 /**116 * \ingroup Parse117 *118 * ops_reader_fd() attempts to read up to "plength" bytes from the file119 * descriptor in "parse_info" into the buffer starting at "dest" using the120 * rules contained in "flags"121 *122 * \param dest Pointer to previously allocated buffer123 * \param plength Number of bytes to try to read124 * \param flags Rules about reading to use125 * \param parse_info Gets cast to ops_reader_fd_arg_t126 *127 * \return OPS_R_EOF if no bytes were read128 * \return OPS_R_PARTIAL_READ if not enough bytes were read, and OPS_RETURN_LENGTH is set in "flags"129 * \return OPS_R_EARLY_EOF if not enough bytes were read, and OPS_RETURN_LENGTH was not set in "flags"130 * \return OPS_R_OK if expected length was read131 * \return OPS_R_ERROR if cannot read132 *133 * OPS_R_EARLY_EOF and OPS_R_ERROR push errors on the stack134 *135 * \sa enum opt_reader_ret_t136 *137 * \todo change arg_ to typesafe?138 */139 static int fd_reader(void *dest,size_t length,ops_error_t **errors,140 ops_reader_info_t *rinfo,ops_parse_cb_info_t *cbinfo)141 {142 reader_fd_arg_t *arg=ops_reader_get_arg(rinfo);143 int n=read(arg->fd,dest,length);144 145 OPS_USED(cbinfo);146 147 if(n == 0)148 return 0;149 150 if(n < 0)151 {152 OPS_SYSTEM_ERROR_1(errors,OPS_E_R_READ_FAILED,"read",153 "file descriptor %d",arg->fd);154 return -1;155 }156 157 return n;158 }159 160 static void fd_destroyer(ops_reader_info_t *rinfo)161 { free(ops_reader_get_arg(rinfo)); }162 163 void ops_reader_set_fd(ops_parse_info_t *pinfo,int fd)164 {165 reader_fd_arg_t *arg=malloc(sizeof *arg);166 167 arg->fd=fd;168 ops_reader_set(pinfo,fd_reader,fd_destroyer,arg);169 }170 171 108 typedef struct 172 109 { openpgpsdk/trunk/src/lib/writer_encrypt_se_ip.c
r571 r574 35 35 #include <openpgpsdk/compress.h> 36 36 #include <openpgpsdk/create.h> 37 #include <openpgpsdk/hash.h> 37 38 #include <openpgpsdk/keyring.h> 38 39 #include <openpgpsdk/random.h> … … 141 142 free(arg->crypt); 142 143 free(arg); 143 }144 145 void ops_calc_mdc_hash(const unsigned char* preamble, const size_t sz_preamble, const unsigned char* plaintext, const unsigned int sz_plaintext, unsigned char *hashed)146 {147 int debug=0;148 ops_hash_t hash;149 unsigned char c[1];150 151 if (debug)152 {153 unsigned int i=0;154 fprintf(stderr,"ops_calc_mdc_hash():\n");155 156 fprintf(stderr,"\npreamble: ");157 for (i=0; i<sz_preamble;i++)158 fprintf(stderr," 0x%02x", preamble[i]);159 fprintf(stderr,"\n");160 161 fprintf(stderr,"\nplaintext (len=%d): ",sz_plaintext);162 for (i=0; i<sz_plaintext;i++)163 fprintf(stderr," 0x%02x", plaintext[i]);164 fprintf(stderr,"\n");165 }166 167 // init168 ops_hash_any(&hash, OPS_HASH_SHA1);169 hash.init(&hash);170 171 // preamble172 hash.add(&hash,preamble,sz_preamble);173 // plaintext174 hash.add(&hash,plaintext,sz_plaintext);175 // MDC packet tag176 c[0]=0xD3;177 hash.add(&hash,&c[0],1);178 // MDC packet len179 c[0]=0x14;180 hash.add(&hash,&c[0],1);181 182 //finish183 hash.finish(&hash,hashed);184 185 if (debug)186 {187 unsigned int i=0;188 fprintf(stderr,"\nhashed (len=%d): ",SHA_DIGEST_LENGTH);189 for (i=0; i<SHA_DIGEST_LENGTH;i++)190 fprintf(stderr," 0x%02x", hashed[i]);191 fprintf(stderr,"\n");192 }193 144 } 194 145 openpgpsdk/trunk/tests/test_common.c
r572 r574 363 363 */ 364 364 365 if (cbinfo->crypt .keydata==alpha_sec_keydata)365 if (cbinfo->cryptinfo.keydata==alpha_sec_keydata) 366 366 passphrase=alpha_passphrase; 367 else if (cbinfo->crypt .keydata==bravo_sec_keydata)367 else if (cbinfo->cryptinfo.keydata==bravo_sec_keydata) 368 368 passphrase=bravo_passphrase; 369 369 else 370 370 assert(0); 371 371 // *(content->secret_key_passphrase.passphrase)=ops_malloc_passphrase(no_passphrase); 372 cbinfo->crypt .passphrase=ops_malloc_passphrase(passphrase);372 cbinfo->cryptinfo.passphrase=ops_malloc_passphrase(passphrase); 373 373 return OPS_KEEP_MEMORY; 374 374 break; openpgpsdk/trunk/tests/test_packet_types.c
r572 r574 23 23 24 24 #include <openpgpsdk/types.h> 25 #include <openpgpsdk/hash.h> 25 26 #include "openpgpsdk/packet.h" 26 27 #include "openpgpsdk/packet-parse.h" openpgpsdk/trunk/tests/test_rsa_decrypt.c
r573 r574 149 149 150 150 // setup keyring and passphrase callback 151 pinfo->cbinfo.crypt .keyring=&sec_keyring;152 pinfo->cbinfo.crypt .cb_get_passphrase=test_cb_get_passphrase;151 pinfo->cbinfo.cryptinfo.keyring=&sec_keyring; 152 pinfo->cbinfo.cryptinfo.cb_get_passphrase=test_cb_get_passphrase; 153 153 154 154 // Set up armour/passphrase options openpgpsdk/trunk/tests/test_rsa_signature.c
r573 r574 25 25 #include "openpgpsdk/keyring.h" 26 26 #include <openpgpsdk/armour.h> 27 #include <openpgpsdk/create.h> 27 28 #include "openpgpsdk/packet.h" 28 29 #include "openpgpsdk/packet-parse.h"
