Changeset 707
- Timestamp:
- 05/15/12 12:25:47
- Files:
-
- openpgpsdk/trunk/CHANGES (modified) (1 diff)
- openpgpsdk/trunk/include/openpgpsdk/crypto.h (modified) (2 diffs)
- openpgpsdk/trunk/include/openpgpsdk/keyring.h (modified) (4 diffs)
- openpgpsdk/trunk/include/openpgpsdk/packet.h (modified) (5 diffs)
- openpgpsdk/trunk/include/openpgpsdk/signature.h (modified) (1 diff)
- openpgpsdk/trunk/include/openpgpsdk/types.h (modified) (5 diffs)
- openpgpsdk/trunk/include/openpgpsdk/validate.h (modified) (2 diffs)
- openpgpsdk/trunk/src/lib/create.c (modified) (3 diffs)
- openpgpsdk/trunk/src/lib/crypto.c (modified) (3 diffs)
- openpgpsdk/trunk/src/lib/keyring.c (modified) (6 diffs)
- openpgpsdk/trunk/src/lib/openssl_crypto.c (modified) (1 diff)
- openpgpsdk/trunk/src/lib/packet-parse.c (modified) (6 diffs)
- openpgpsdk/trunk/src/lib/reader_armoured.c (modified) (3 diffs)
- openpgpsdk/trunk/src/lib/readerwriter.c (modified) (3 diffs)
- openpgpsdk/trunk/src/lib/signature.c (modified) (4 diffs)
- openpgpsdk/trunk/src/lib/validate.c (modified) (32 diffs)
- openpgpsdk/trunk/src/lib/writer_armour.c (modified) (2 diffs)
- openpgpsdk/trunk/tests/test_dsa_signature.c (modified) (1 diff)
- openpgpsdk/trunk/tests/test_rsa_signature.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
openpgpsdk/trunk/CHANGES
r703 r707 1 1 Changes since V0.9 2 2 ================== 3 4 *) Memory leak fixes and some bug fixes. 5 [Cyril Soler <cyril.soler@imag.fr>] 3 6 4 7 *) Various warnings from gcc 4.6 fixed. openpgpsdk/trunk/include/openpgpsdk/crypto.h
r701 r707 156 156 157 157 // Hash everything that's read 158 void ops_reader_push_hash(ops_parse_info_t *pinfo, ops_hash_t *hash);158 void ops_reader_push_hash(ops_parse_info_t *pinfo, ops_hash_t *hash); 159 159 void ops_reader_pop_hash(ops_parse_info_t *pinfo); 160 160 161 int ops_decrypt_and_unencode_mpi(unsigned char *buf,unsigned buflen,const BIGNUM *encmpi, 162 const ops_secret_key_t *skey); 161 int ops_decrypt_and_unencode_mpi(unsigned char *buf, 162 unsigned buflen, const BIGNUM *encmpi, 163 const ops_secret_key_t *skey); 163 164 ops_boolean_t ops_rsa_encrypt_mpi(const unsigned char *buf, const size_t buflen, 164 const ops_public_key_t *pkey,165 ops_pk_session_key_parameters_t *spk);165 const ops_public_key_t *pkey, 166 ops_pk_session_key_parameters_t *spk); 166 167 167 168 … … 171 172 const struct ops_key_data *key); 172 173 173 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); 174 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); 175 extern void ops_encrypt_stream(ops_create_info_t* cinfo, const ops_keydata_t* public_key, const ops_secret_key_t* secret_key, const ops_boolean_t compress, const ops_boolean_t use_armour); 176 174 ops_boolean_t ops_encrypt_file(const char* input_filename, 175 const char* output_filename, const ops_keydata_t *pub_key, const ops_boolean_t use_armour, const ops_boolean_t allow_overwrite); 176 ops_boolean_t ops_decrypt_file(const char* input_filename, 177 const char* output_filename, 178 ops_keyring_t *keyring, 179 const ops_boolean_t use_armour, 180 const ops_boolean_t allow_overwrite, 181 ops_parse_cb_t* cb_get_passphrase); 182 extern void ops_encrypt_stream(ops_create_info_t* cinfo, 183 const ops_keydata_t* public_key, 184 const ops_secret_key_t* secret_key, 185 const ops_boolean_t compress, 186 const ops_boolean_t use_armour); 187 ops_boolean_t ops_decrypt_memory(const unsigned char *encrypted_memory, 188 int em_length, 189 unsigned char **decrypted_memory, 190 int *out_length, ops_keyring_t* keyring, 191 const ops_boolean_t use_armour, 192 ops_parse_cb_t* cb_get_passphrase) ; 177 193 // Keys 178 ops_boolean_t ops_rsa_generate_keypair(const int numbits, const unsigned long e, ops_keydata_t* keydata); 179 ops_keydata_t* ops_rsa_create_selfsigned_keypair(const int numbits, const unsigned long e, ops_user_id_t * userid); 194 ops_boolean_t ops_rsa_generate_keypair(const int numbits, const unsigned long e, 195 ops_keydata_t* keydata); 196 ops_keydata_t* ops_rsa_create_selfsigned_keypair(const int numbits, 197 const unsigned long e, 198 ops_user_id_t * userid); 180 199 181 200 int ops_dsa_size(const ops_dsa_public_key_t *dsa); 182 DSA_SIG* ops_dsa_sign(unsigned char* hashbuf, unsigned hashsize, const ops_dsa_secret_key_t *sdsa, const ops_dsa_public_key_t *dsa); 201 DSA_SIG* ops_dsa_sign(unsigned char* hashbuf, unsigned hashsize, 202 const ops_dsa_secret_key_t *sdsa, 203 const ops_dsa_public_key_t *dsa); 183 204 #endif openpgpsdk/trunk/include/openpgpsdk/keyring.h
r612 r707 49 49 const char* userid); 50 50 void ops_keydata_free(ops_keydata_t *key); 51 void ops_keydata_copy(ops_keydata_t *dst, const ops_keydata_t *src); 51 52 void ops_keyring_free(ops_keyring_t *keyring); 52 53 void ops_dump_keyring(const ops_keyring_t *keyring); … … 61 62 const char *pphrase); 62 63 63 ops_boolean_t ops_keyring_read_from_file(ops_keyring_t *keyring, const ops_boolean_t armour, const char *filename); 64 ops_boolean_t ops_keyring_read_from_mem(ops_keyring_t *keyring, const ops_boolean_t armour, ops_memory_t *mem); 64 ops_boolean_t ops_keyring_read_from_file(ops_keyring_t *keyring, 65 const ops_boolean_t armour, 66 const char *filename); 67 ops_boolean_t ops_keyring_read_from_mem(ops_keyring_t *keyring, 68 const ops_boolean_t armour, 69 ops_memory_t *mem); 70 ops_boolean_t ops_write_keyring_to_file(const ops_keyring_t *keyring, 71 ops_boolean_t armoured, 72 const char *filename); 65 73 66 74 char *ops_malloc_passphrase(char *passphrase); … … 69 77 void ops_keyring_list(const ops_keyring_t* keyring); 70 78 71 void ops_set_secret_key(ops_parser_content_union_t* content,const ops_keydata_t *key); 79 void ops_set_secret_key(ops_parser_content_union_t* content, 80 const ops_keydata_t *key); 72 81 73 82 const unsigned char* ops_get_key_id(const ops_keydata_t *key); … … 75 84 const unsigned char* ops_get_user_id(const ops_keydata_t *key, unsigned index); 76 85 ops_boolean_t ops_is_key_supported(const ops_keydata_t *key); 77 const ops_keydata_t* ops_keyring_get_key_by_index(const ops_keyring_t *keyring, int index); 86 const ops_keydata_t* ops_keyring_get_key_by_index(const ops_keyring_t *keyring, 87 int index); 78 88 79 ops_user_id_t* ops_add_userid_to_keydata(ops_keydata_t* keydata, const ops_user_id_t* userid); 80 ops_packet_t* ops_add_packet_to_keydata(ops_keydata_t* keydata, const ops_packet_t* packet); 81 void ops_add_signed_userid_to_keydata(ops_keydata_t* keydata, const ops_user_id_t* userid, const ops_packet_t* packet); 89 ops_user_id_t* ops_add_userid_to_keydata(ops_keydata_t *keydata, 90 const ops_user_id_t *userid); 91 ops_packet_t* ops_add_packet_to_keydata(ops_keydata_t* keydata, 92 const ops_packet_t *packet); 93 void ops_add_signed_userid_to_keydata(ops_keydata_t *keydata, 94 const ops_user_id_t *userid, 95 const ops_packet_t* packet); 82 96 83 ops_boolean_t ops_add_selfsigned_userid_to_keydata(ops_keydata_t* keydata, ops_user_id_t* userid); 97 ops_boolean_t ops_add_selfsigned_userid_to_keydata(ops_keydata_t *keydata, 98 ops_user_id_t *userid); 84 99 85 100 ops_keydata_t *ops_keydata_new(void); 86 void ops_keydata_init(ops_keydata_t *keydata, const ops_content_tag_t type);101 void ops_keydata_init(ops_keydata_t *keydata, const ops_content_tag_t type); 87 102 88 103 #endif openpgpsdk/trunk/include/openpgpsdk/packet.h
r705 r707 126 126 */ 127 127 #define OPS_PTAG_NF_CONTENT_TAG_SHIFT 0 128 129 130 128 131 129 … … 698 696 { 699 697 unsigned length; 700 unsigned char data[8192];698 unsigned char *data; 701 699 } ops_literal_data_body_t; 702 700 … … 744 742 { 745 743 unsigned length; 746 unsigned char data[8192]; // \todo fix hard-coded value?744 unsigned char *data; 747 745 } ops_signed_cleartext_body_t; 748 746 … … 916 914 void ops_keyid(unsigned char keyid[OPS_KEY_ID_SIZE], 917 915 const ops_public_key_t *key); 918 void ops_fingerprint(ops_fingerprint_t *fp, const ops_public_key_t *key);916 void ops_fingerprint(ops_fingerprint_t *fp, const ops_public_key_t *key); 919 917 void ops_public_key_free(ops_public_key_t *key); 918 void ops_public_key_copy(ops_public_key_t *dst, const ops_public_key_t *src); 920 919 void ops_user_id_free(ops_user_id_t *id); 921 920 void ops_user_attribute_free(ops_user_attribute_t *att); … … 941 940 void ops_parser_content_free(ops_parser_content_t *c); 942 941 void ops_secret_key_free(ops_secret_key_t *key); 942 void ops_secret_key_copy(ops_secret_key_t *dst, const ops_secret_key_t *src); 943 943 void ops_pk_session_key_free(ops_pk_session_key_t *sk); 944 944 openpgpsdk/trunk/include/openpgpsdk/signature.h
r701 r707 88 88 89 89 // Standard Interface 90 ops_boolean_t ops_sign_file_as_cleartext(const char* input_filename, const char* output_filename, const ops_secret_key_t *skey, const ops_boolean_t overwrite); 91 ops_boolean_t ops_sign_buf_as_cleartext(const char* input, const size_t len, ops_memory_t** output, const ops_secret_key_t *skey); 92 ops_boolean_t 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); 93 ops_memory_t * ops_sign_buf(const void* input, const size_t input_len, const ops_sig_type_t sig_type, const ops_secret_key_t *skey, const ops_boolean_t use_armour); 94 ops_boolean_t ops_writer_push_signed(ops_create_info_t *cinfo, const ops_sig_type_t sig_type, const ops_secret_key_t *skey); 90 ops_boolean_t ops_sign_file_as_cleartext(const char* input_filename, 91 const char* output_filename, 92 const ops_secret_key_t *skey, 93 const ops_boolean_t overwrite); 94 ops_boolean_t ops_sign_buf_as_cleartext(const char* input, 95 const size_t len, ops_memory_t** output, 96 const ops_secret_key_t *skey); 97 ops_boolean_t ops_sign_file(const char* input_filename, 98 const char* output_filename, 99 const ops_secret_key_t *skey, 100 const ops_boolean_t use_armour, 101 const ops_boolean_t overwrite); 102 ops_memory_t * ops_sign_buf(const void* input, 103 const size_t input_len, 104 const ops_sig_type_t sig_type, 105 const ops_secret_key_t *skey, 106 const ops_boolean_t use_armour, 107 ops_boolean_t include_data); 108 ops_boolean_t ops_writer_push_signed(ops_create_info_t *cinfo, 109 const ops_sig_type_t sig_type, 110 const ops_secret_key_t *skey); 95 111 96 112 #endif openpgpsdk/trunk/include/openpgpsdk/types.h
r701 r707 43 43 typedef unsigned ops_boolean_t; 44 44 45 /** ops_content_tag_t */ 46 45 47 /* PTag Content Tags */ 46 48 /***************************/ … … 53 55 * \see RFC4880 5.2.3.1 54 56 */ 57 58 #ifndef __cplusplus 59 typedef enum ops_content_tag_t ops_content_tag_t ; 60 #endif 61 55 62 enum ops_content_tag_t 56 63 { … … 146 153 OPS_PARSER_CMD_GET_SK_PASSPHRASE =0x400, 147 154 OPS_PARSER_CMD_GET_SECRET_KEY =0x400+1, 155 OPS_PARSER_CMD_GET_SK_PASSPHRASE_PREV_WAS_BAD =0x400+2, 148 156 149 157 … … 153 161 }; 154 162 155 /** ops_content_tag_t */ 156 typedef enum ops_content_tag_t ops_content_tag_t; 163 /** Used to specify whether subpackets should be returned raw, parsed or ignored. 164 */ 165 166 enum ops_parse_type_t 167 { 168 OPS_PARSE_RAW, /*!< Callback Raw */ 169 OPS_PARSE_PARSED, /*!< Callback Parsed */ 170 OPS_PARSE_IGNORE, /*!< Don't callback */ 171 }; 157 172 158 173 typedef struct _ops_crypt_t ops_crypt_t; … … 179 194 /** Used to specify whether subpackets should be returned raw, parsed or ignored. 180 195 */ 181 enum ops_parse_type_t182 {183 OPS_PARSE_RAW, /*!< Callback Raw */184 OPS_PARSE_PARSED, /*!< Callback Parsed */185 OPS_PARSE_IGNORE, /*!< Don't callback */186 };187 196 188 197 typedef enum ops_parse_type_t ops_parse_type_t; openpgpsdk/trunk/include/openpgpsdk/validate.h
r683 r707 79 79 SIGNED_CLEARTEXT 80 80 } use; /*<! this is set to indicate what kind of data we have */ 81 81 82 union 82 { 83 ops_literal_data_body_t literal_data_body; /*<! Used to hold Literal Data */ 84 ops_signed_cleartext_body_t signed_cleartext_body; /*<! Used to hold Signed Cleartext */ 85 } data; /*<! the data itself */ 83 { 84 ops_literal_data_body_t literal_data_body; /*<! Used to hold Literal Data */ 85 ops_signed_cleartext_body_t signed_cleartext_body; /*<! Used to hold Signed Cleartext */ 86 } data; 87 86 88 unsigned char hash[OPS_MAX_HASH_SIZE]; /*<! the hash */ 87 89 const ops_keyring_t *keyring; /*<! keyring to use */ … … 99 101 ops_boolean_t ops_validate_file(ops_validate_result_t* result, const char* filename, const int armoured, const ops_keyring_t* keyring); 100 102 ops_boolean_t ops_validate_mem(ops_validate_result_t *result, ops_memory_t* mem, const int armoured, const ops_keyring_t* keyring); 101 102 // EOF 103 ops_boolean_t ops_validate_detached_signature(const void *literal_data, unsigned int literal_data_length, const unsigned char *signature_packet, unsigned int signature_packet_length,const ops_keydata_t *signers_key) ; openpgpsdk/trunk/src/lib/create.c
r701 r707 129 129 130 130 default: 131 fprintf(stderr,"Bad algorithm type in key: %d\n",key->algorithm) ; 131 132 assert(!"unknown key algorithm"); 132 133 } … … 383 384 || !ops_write_mpi(key->key.rsa.q,info) 384 385 || !ops_write_mpi(key->key.rsa.u,info)) 385 {386 if (debug)387 { fprintf(stderr,"4 x mpi not written - problem\n"); } 386 { 387 if (debug) 388 fprintf(stderr,"4 x mpi not written - problem\n"); 388 389 return ops_false; 389 }390 } 390 391 391 392 break; … … 403 404 404 405 ops_writer_pop(info); 405 406 407 free(crypt.encrypt_key); 408 free(crypt.decrypt_key); 409 406 410 return ops_true; 407 }411 } 408 412 409 413 openpgpsdk/trunk/src/lib/crypto.c
r701 r707 180 180 181 181 ops_create_info_t *cinfo; 182 182 #ifdef WINDOWS_SYS 183 183 fd_in=open(input_filename, O_RDONLY | O_BINARY); 184 #else 185 fd_in=open(input_filename, O_RDONLY ); 186 #endif 184 187 if(fd_in < 0) 185 188 { … … 265 268 else 266 269 ops_writer_push_literal(cinfo); 270 } 271 272 /** 273 \ingroup HighLevel_Crypto 274 \brief Decrypt a chunk of memory, containing a encrypted stream. 275 \param input_filename Name of file to be decrypted 276 \param output_filename Name of file to write to. If NULL, the filename is constructed from the input filename, following GPG conventions. 277 \param keyring Keyring to use 278 \param use_armour Expect armoured text, if set 279 \param allow_overwrite Allow output file to overwritten, if set. 280 \param cb_get_passphrase Callback to use to get passphrase 281 */ 282 283 ops_boolean_t ops_decrypt_memory(const unsigned char *encrypted_memory, 284 int em_length, 285 unsigned char **decrypted_memory, 286 int *out_length, ops_keyring_t *keyring, 287 const ops_boolean_t use_armour, 288 ops_parse_cb_t *cb_get_passphrase) 289 { 290 291 // 292 ops_parse_info_t *pinfo=NULL; 293 294 // setup for reading from given input file 295 296 ops_memory_t *input_mem = ops_memory_new() ; 297 ops_memory_add(input_mem,encrypted_memory,em_length) ; 298 299 ops_setup_memory_read(&pinfo, input_mem, NULL, callback_write_parsed, 300 ops_false); 301 302 if (pinfo == NULL) 303 { 304 perror("cannot create memory read"); 305 return ops_false; 306 } 307 308 // setup memory chunk 309 310 ops_memory_t *output_mem = ops_memory_new() ; 311 312 ops_setup_memory_write(&pinfo->cbinfo.cinfo, &output_mem,0) ; 313 314 if (output_mem == NULL) 315 { 316 perror("Cannot create output memory"); 317 ops_teardown_memory_read(pinfo, input_mem); 318 return ops_false; 319 } 320 321 // \todo check for suffix matching armour param 322 323 // setup keyring and passphrase callback 324 pinfo->cbinfo.cryptinfo.keyring=keyring; 325 pinfo->cbinfo.cryptinfo.cb_get_passphrase=cb_get_passphrase; 326 327 // Set up armour/passphrase options 328 329 if (use_armour) 330 ops_reader_push_dearmour(pinfo); 331 332 // Do it 333 334 ops_parse_and_print_errors(pinfo); 335 336 // Unsetup 337 338 if (use_armour) 339 ops_reader_pop_dearmour(pinfo); 340 341 ops_boolean_t res = ops_true; 342 343 // copy output memory to supplied buffer. 344 // 345 *out_length = ops_memory_get_length(output_mem); 346 *decrypted_memory = ops_mallocz(*out_length); 347 memcpy(*decrypted_memory, ops_memory_get_data(output_mem), *out_length); 348 349 ops_teardown_memory_write(pinfo->cbinfo.cinfo, output_mem); 350 ops_teardown_memory_read(pinfo, input_mem); 351 352 return res; 267 353 } 268 354 … … 420 506 421 507 case OPS_PARSER_CMD_GET_SK_PASSPHRASE: 508 case OPS_PARSER_CMD_GET_SK_PASSPHRASE_PREV_WAS_BAD: 422 509 // return callback_cmd_get_secret_key_passphrase(content_,cbinfo); 423 510 return cbinfo->cryptinfo.cb_get_passphrase(content_, cbinfo); openpgpsdk/trunk/src/lib/keyring.c
r704 r707 79 79 keydata->npackets=0; 80 80 81 free(keydata->sigs); 82 81 83 if(keydata->type == OPS_PTAG_CT_PUBLIC_KEY) 82 84 ops_public_key_free(&keydata->key.pkey); 83 85 else 84 86 ops_secret_key_free(&keydata->key.skey); 85 86 87 } 87 88 … … 101 102 free(keydata); 102 103 } 104 105 // \todo check where userid pointers are copied 106 /** 107 \ingroup Core_Keys 108 \brief Copy user id, including contents 109 \param dst Destination User ID 110 \param src Source User ID 111 \note If dst already has a user_id, it will be freed. 112 */ 113 void ops_copy_userid(ops_user_id_t* dst, const ops_user_id_t* src) 114 { 115 int len=strlen((char *)src->user_id); 116 if (dst->user_id) 117 free(dst->user_id); 118 dst->user_id=ops_mallocz(len+1); 119 120 memcpy(dst->user_id, src->user_id, len); 121 } 122 // \todo check where pkt pointers are copied 123 /** 124 \ingroup Core_Keys 125 \brief Copy packet, including contents 126 \param dst Destination packet 127 \param src Source packet 128 \note If dst already has a packet, it will be freed. 129 */ 130 void ops_copy_packet(ops_packet_t* dst, const ops_packet_t* src) 131 { 132 if (dst->raw) 133 free(dst->raw); 134 dst->raw=ops_mallocz(src->length); 135 136 dst->length=src->length; 137 memcpy(dst->raw, src->raw, src->length); 138 } 139 140 141 142 /** 143 \ingroup Core_Keys 144 \brief Copies entire key data 145 \param dst Destination key where to copy 146 \param src Source key to copy 147 */ 148 void ops_keydata_copy(ops_keydata_t *dst,const ops_keydata_t *src) 149 { 150 unsigned n; 151 152 memset(dst, 0, sizeof(ops_keydata_t)); 153 154 dst->uids = (ops_user_id_t*)ops_mallocz(src->nuids * sizeof(ops_user_id_t)); 155 dst->nuids = src->nuids; 156 dst->nuids_allocated = src->nuids; 157 158 for(n=0 ; n < src->nuids ; ++n) 159 ops_copy_userid(&dst->uids[n],&src->uids[n]); 160 161 dst->packets = (ops_packet_t*)ops_mallocz(src->npackets * sizeof(ops_packet_t)); 162 dst->npackets = src->npackets; 163 dst->npackets_allocated = src->npackets; 164 165 for(n=0 ; n < src->npackets ; ++n) 166 ops_copy_packet(&(dst->packets[n]),&(src->packets[n])); 167 168 dst->nsigs = src->nsigs; 169 dst->sigs = (sigpacket_t*)ops_mallocz(src->nsigs * sizeof(sigpacket_t)); 170 dst->nsigs_allocated = src->nsigs; 171 172 for(n=0 ; n < src->nsigs ; ++n) 173 { 174 dst->sigs[n].userid = (ops_user_id_t*)ops_mallocz(sizeof(ops_user_id_t)); 175 dst->sigs[n].packet = (ops_packet_t*)ops_mallocz(sizeof(ops_packet_t)); 176 ops_copy_userid(dst->sigs[n].userid,src->sigs[n].userid); 177 ops_copy_packet(dst->sigs[n].packet,src->sigs[n].packet); 178 } 179 180 dst->key_id[0] = src->key_id[0]; 181 dst->key_id[1] = src->key_id[1]; 182 dst->key_id[2] = src->key_id[2]; 183 dst->key_id[3] = src->key_id[3]; 184 dst->key_id[4] = src->key_id[4]; 185 dst->key_id[5] = src->key_id[5]; 186 dst->key_id[6] = src->key_id[6]; 187 dst->key_id[7] = src->key_id[7]; 188 dst->type = src->type; 189 dst->key = src->key; 190 dst->fingerprint = src->fingerprint; 191 192 if(src->type == OPS_PTAG_CT_PUBLIC_KEY) 193 ops_public_key_copy(&dst->key.pkey,&src->key.pkey); 194 else 195 ops_secret_key_copy(&dst->key.skey,&src->key.skey); 196 } 197 103 198 104 199 /** … … 267 362 ops_parse(pinfo); 268 363 364 ops_parse_info_delete(pinfo); 365 269 366 return arg.skey; 270 367 } … … 363 460 return NULL; 364 461 return &keyring->keys[index]; 365 }366 367 // \todo check where userid pointers are copied368 /**369 \ingroup Core_Keys370 \brief Copy user id, including contents371 \param dst Destination User ID372 \param src Source User ID373 \note If dst already has a user_id, it will be freed.374 */375 void ops_copy_userid(ops_user_id_t* dst, const ops_user_id_t* src)376 {377 int len=strlen((char *)src->user_id);378 if (dst->user_id)379 free(dst->user_id);380 dst->user_id=ops_mallocz(len+1);381 382 memcpy(dst->user_id, src->user_id, len);383 }384 385 // \todo check where pkt pointers are copied386 /**387 \ingroup Core_Keys388 \brief Copy packet, including contents389 \param dst Destination packet390 \param src Source packet391 \note If dst already has a packet, it will be freed.392 */393 void ops_copy_packet(ops_packet_t* dst, const ops_packet_t* src)394 {395 if (dst->raw)396 free(dst->raw);397 dst->raw=ops_mallocz(src->length);398 399 dst->length=src->length;400 memcpy(dst->raw, src->raw, src->length);401 462 } 402 463 … … 624 685 // ops_parse_options(pinfo,OPS_PTAG_SS_ALL,OPS_PARSE_RAW); 625 686 ops_parse_options(pinfo,OPS_PTAG_SS_ALL,OPS_PARSE_PARSED); 626 627 687 fd=open(filename,O_RDONLY | O_BINARY); 628 688 if(fd < 0) … … 907 967 } 908 968 969 /** 970 \ingroup HighLevel_KeyringList 971 972 \brief Saves keyring to specified file 973 974 \param keyring Keyring to save 975 \param armoured Save in ascii armoured format 976 \param output filename 977 978 \return ops_true is anything when ok 979 */ 980 981 ops_boolean_t ops_write_keyring_to_file(const ops_keyring_t *keyring,ops_boolean_t armoured,const char *filename) 982 { 983 ops_create_info_t *info; 984 int fd = ops_setup_file_write(&info, filename, ops_true); 985 986 if (fd < 0) 987 { 988 fprintf(stderr,"ops_write_keyring(): ERROR: Cannot write to %s\n", 989 filename); 990 return ops_false; 991 } 992 993 int i; 994 for(i=0 ; i<keyring->nkeys ; ++i) 995 if(keyring->keys[i].key.pkey.algorithm == OPS_PKA_RSA) 996 ops_write_transferable_public_key(&keyring->keys[i],armoured,info); 997 else 998 { 999 fprintf(stdout, "ops_write_keyring: not writing key. Algorithm not handled: "); 1000 ops_print_public_keydata(&keyring->keys[i]); 1001 fprintf(stdout, "\n"); 1002 } 1003 1004 ops_writer_close(info); 1005 ops_create_info_delete(info); 1006 1007 return ops_true; 1008 } 1009 909 1010 /*\@}*/ 910 1011 openpgpsdk/trunk/src/lib/openssl_crypto.c
r661 r707 747 747 { 748 748 ops_keydata_free(keydata); 749 free(keydata); 749 750 return NULL; 750 751 } openpgpsdk/trunk/src/lib/packet-parse.c
r705 r707 922 922 923 923 case OPS_PARSER_CMD_GET_SK_PASSPHRASE: 924 case OPS_PARSER_CMD_GET_SK_PASSPHRASE_PREV_WAS_BAD: 924 925 ops_cmd_get_passphrase_free(&c->content.secret_key_passphrase); 925 926 break; … … 998 999 } 999 1000 1001 void ops_public_key_copy(ops_public_key_t *dst,const ops_public_key_t *src) 1002 { 1003 *dst = *src ; 1004 1005 switch(src->algorithm) 1006 { 1007 case OPS_PKA_RSA: 1008 case OPS_PKA_RSA_ENCRYPT_ONLY: 1009 case OPS_PKA_RSA_SIGN_ONLY: 1010 dst->key.rsa.n = BN_dup(src->key.rsa.n); 1011 dst->key.rsa.e = BN_dup(src->key.rsa.e); 1012 break; 1013 1014 case OPS_PKA_DSA: 1015 dst->key.dsa.p = BN_dup(src->key.dsa.p); 1016 dst->key.dsa.q = BN_dup(src->key.dsa.q); 1017 dst->key.dsa.g = BN_dup(src->key.dsa.g); 1018 dst->key.dsa.y = BN_dup(src->key.dsa.y); 1019 break; 1020 1021 case OPS_PKA_ELGAMAL: 1022 case OPS_PKA_ELGAMAL_ENCRYPT_OR_SIGN: 1023 dst->key.elgamal.p = BN_dup(src->key.elgamal.p); 1024 dst->key.elgamal.g = BN_dup(src->key.elgamal.g); 1025 dst->key.elgamal.y = BN_dup(src->key.elgamal.y); 1026 break; 1027 1028 //case 0: 1029 // nothing to free 1030 // break; 1031 1032 default: 1033 assert(0); 1034 } 1035 } 1036 1037 1000 1038 /** 1001 1039 \ingroup Core_ReadPackets 1002 1040 */ 1003 static int parse_public_key_data(ops_public_key_t *key, ops_region_t *region,1041 static int parse_public_key_data(ops_public_key_t *key, ops_region_t *region, 1004 1042 ops_parse_info_t *pinfo) 1005 1043 { … … 1214 1252 1215 1253 CBP(pinfo,OPS_PTAG_CT_USER_ID,&content); 1254 1216 1255 return 1; 1217 1256 } … … 2073 2112 unsigned l=region->length-region->length_read; 2074 2113 2075 if(l > sizeof C.literal_data_body.data) 2076 l=sizeof C.literal_data_body.data; 2114 C.literal_data_body.data = (unsigned char *)malloc(l) ; 2077 2115 2078 2116 if(!limited_read(C.literal_data_body.data,l,region,pinfo)) … … 2121 2159 2122 2160 ops_public_key_free(&key->public_key); 2161 } 2162 2163 void ops_secret_key_copy(ops_secret_key_t *dst,const ops_secret_key_t *src) 2164 { 2165 *dst = *src ; 2166 ops_public_key_copy(&dst->public_key,&src->public_key); 2167 2168 switch(src->public_key.algorithm) 2169 { 2170 case OPS_PKA_RSA: 2171 case OPS_PKA_RSA_ENCRYPT_ONLY: 2172 case OPS_PKA_RSA_SIGN_ONLY: 2173 dst->key.rsa.d = BN_dup(src->key.rsa.d) ; 2174 dst->key.rsa.p = BN_dup(src->key.rsa.p) ; 2175 dst->key.rsa.q = BN_dup(src->key.rsa.q) ; 2176 dst->key.rsa.u = BN_dup(src->key.rsa.u) ; 2177 break; 2178 2179 case OPS_PKA_DSA: 2180 dst->key.dsa.x = BN_dup(src->key.dsa.x) ; 2181 break; 2182 2183 default: 2184 fprintf(stderr,"ops_secret_key_copy: Unknown algorithm: %d (%s)\n", 2185 src->public_key.algorithm, 2186 ops_show_pka(src->public_key.algorithm)); 2187 //assert(0); 2188 } 2123 2189 } 2124 2190 … … 2970 3036 pinfo->rinfo.asize=0; 2971 3037 } 3038 else 3039 C.packet.raw = NULL ; 3040 2972 3041 pinfo->rinfo.alength=0; 2973 3042 openpgpsdk/trunk/src/lib/reader_armoured.c
r625 r707 388 388 hash->init(hash); 389 389 390 #define BODYSIZE 4096 391 body->data = malloc(BODYSIZE); 390 392 body->length=0; 391 393 total=0; … … 434 436 body->data[body->length++]=c; 435 437 ++total; 436 if(body->length == sizeof body->data)438 if(body->length == BODYSIZE) 437 439 { 438 440 if (debug) … … 446 448 assert(body->length == 1); 447 449 /* don't send that one character, because its part of the trailer. */ 450 451 free(body->data); 448 452 449 453 trailer->hash=hash; openpgpsdk/trunk/src/lib/readerwriter.c
r671 r707 338 338 339 339 ops_parse_cb_return_t 340 callback_cmd_get_secret_key(const ops_parser_content_t *content_,ops_parse_cb_info_t *cbinfo) 341 { 342 ops_parser_content_union_t* content=(ops_parser_content_union_t *)&content_->content; 340 callback_cmd_get_secret_key(const ops_parser_content_t *content_, 341 ops_parse_cb_info_t *cbinfo) 342 { 343 const ops_parser_content_union_t* content=&content_->content; 343 344 const ops_secret_key_t *secret; 344 345 ops_parser_content_t pc; 345 346 346 347 OPS_USED(cbinfo); 347 348 // ops_print_packet(content_);349 348 350 349 switch(content_->tag) 351 350 { 352 351 case OPS_PARSER_CMD_GET_SECRET_KEY: 353 cbinfo->cryptinfo.keydata=ops_keyring_find_key_by_id(cbinfo->cryptinfo.keyring,content->get_secret_key.pk_session_key->key_id); 354 if (!cbinfo->cryptinfo.keydata || !ops_is_key_secret(cbinfo->cryptinfo.keydata)) 352 cbinfo->cryptinfo.keydata = 353 ops_keyring_find_key_by_id(cbinfo->cryptinfo.keyring, 354 content->get_secret_key.pk_session_key->key_id); 355 if (!cbinfo->cryptinfo.keydata 356 || !ops_is_key_secret(cbinfo->cryptinfo.keydata)) 355 357 return 0; 356 358 357 359 /* now get the key from the data */ 358 360 secret=ops_get_secret_key_from_data(cbinfo->cryptinfo.keydata); 359 while(!secret) 361 int tag_to_use = OPS_PARSER_CMD_GET_SK_PASSPHRASE ; 362 int nbtries = 0 ; 363 364 while( (!secret) && nbtries++ < 3) 360 365 { 361 366 if (!cbinfo->cryptinfo.passphrase) 362 367 { 363 368 memset(&pc,'\0',sizeof pc); 364 pc.content.secret_key_passphrase.passphrase=&cbinfo->cryptinfo.passphrase; 365 CB(cbinfo,OPS_PARSER_CMD_GET_SK_PASSPHRASE,&pc); 369 pc.content.secret_key_passphrase.passphrase= 370 &cbinfo->cryptinfo.passphrase; 371 CB(cbinfo, tag_to_use, &pc); 366 372 if (!cbinfo->cryptinfo.passphrase) 367 373 { … … 371 377 } 372 378 /* then it must be encrypted */ 373 secret=ops_decrypt_secret_key_from_data(cbinfo->cryptinfo.keydata,cbinfo->cryptinfo.passphrase); 379 secret=ops_decrypt_secret_key_from_data(cbinfo->cryptinfo.keydata, 380 cbinfo->cryptinfo.passphrase); 381 382 free(cbinfo->cryptinfo.passphrase) ; 383 cbinfo->cryptinfo.passphrase = NULL ; 384 tag_to_use = OPS_PARSER_CMD_GET_SK_PASSPHRASE_PREV_WAS_BAD ; 374 385 } 375 386 387 if(!secret) 388 return 0; 389 376 390 *content->get_secret_key.secret_key=secret; 377 391 break; … … 381 395 break; 382 396 } 383 397 384 398 return OPS_RELEASE_MEMORY; 385 399 } openpgpsdk/trunk/src/lib/signature.c
r705 r707 1234 1234 \param skey Secret Key 1235 1235 \param use_armour Write armoured text, if set 1236 \param include_data Includes the signed data in the output message. If not, creates a detached signature. 1236 1237 \return New ops_memory_t struct containing signed text 1237 1238 \note It is the caller's responsibility to call ops_memory_free(me) … … 1263 1264 const ops_sig_type_t sig_type, 1264 1265 const ops_secret_key_t *skey, 1265 const ops_boolean_t use_armour) 1266 const ops_boolean_t use_armour, 1267 ops_boolean_t include_data) 1266 1268 { 1267 1269 // \todo allow choice of hash algorithams … … 1310 1312 fprintf(stderr,"** Writing out data now\n"); 1311 1313 1312 ops_write_literal_data_from_buf(input, input_len, ld_type, cinfo); 1314 if(include_data) 1315 ops_write_literal_data_from_buf(input, input_len, ld_type, cinfo); 1313 1316 1314 1317 if (debug) … … 1331 1334 // tidy up 1332 1335 ops_writer_close(cinfo); 1336 free(cinfo) ; 1333 1337 ops_create_signature_delete(sig); 1334 1338 openpgpsdk/trunk/src/lib/validate.c
r666 r707 77 77 trailer[5]=hashedlen; 78 78 hash.add(&hash,&trailer[0],6); 79 79 80 80 break; 81 81 … … 92 92 93 93 static int keydata_reader(void *dest,size_t length,ops_error_t **errors, 94 ops_reader_info_t *rinfo,95 ops_parse_cb_info_t *cbinfo)94 ops_reader_info_t *rinfo, 95 ops_parse_cb_info_t *cbinfo) 96 96 { 97 97 validate_reader_arg_t *arg=ops_reader_get_arg(rinfo); … … 123 123 } 124 124 125 static void copy_signature_info(ops_signature_info_t* dst, const ops_signature_info_t* src) 125 static void copy_signature_info(ops_signature_info_t* dst, 126 const ops_signature_info_t* src) 126 127 { 127 128 memcpy(dst,src,sizeof *src); 128 129 dst->v4_hashed_data=ops_mallocz(src->v4_hashed_data_length); 129 memcpy(dst->v4_hashed_data,src->v4_hashed_data,src->v4_hashed_data_length); 130 } 131 132 static void add_sig_to_valid_list(ops_validate_result_t * result, const ops_signature_info_t* sig) 130 memcpy(dst->v4_hashed_data, src->v4_hashed_data, 131 src->v4_hashed_data_length); 132 } 133 134 static void add_sig_to_valid_list(ops_validate_result_t *result, 135 const ops_signature_info_t *sig) 133 136 { 134 137 size_t newsize; 135 size_t start;136 138 137 139 // increment count … … 146 148 147 149 // copy key ptr to array 148 start=(sizeof *sig) * (result->valid_count-1);149 copy_signature_info(result->valid_sigs+start,sig);150 } 151 152 static void add_sig_to_invalid_list(ops_validate_result_t * result,const ops_signature_info_t *sig)150 copy_signature_info(&result->valid_sigs[result->valid_count-1], sig); 151 } 152 153 static void add_sig_to_invalid_list(ops_validate_result_t *result, 154 const ops_signature_info_t *sig) 153 155 { 154 156 size_t newsize; 155 size_t start;156 157 157 158 // increment count … … 166 167 167 168 // copy key ptr to array 168 start=(sizeof *sig) * (result->invalid_count-1);169 copy_signature_info(result->invalid_sigs+start, sig);170 } 171 172 static void add_sig_to_unknown_list(ops_validate_result_t * result,const ops_signature_info_t *sig)169 copy_signature_info(&result->invalid_sigs[result->invalid_count-1], sig); 170 } 171 172 static void add_sig_to_unknown_list(ops_validate_result_t * result, 173 const ops_signature_info_t *sig) 173 174 { 174 175 size_t newsize; 175 size_t start;176 176 177 177 // increment count … … 186 186 187 187 // copy key id to array 188 start=OPS_KEY_ID_SIZE * (result->unknown_signer_count-1);189 copy_signature_info(result->unknown_sigs+start,sig);188 copy_signature_info(&result->unknown_sigs[result->unknown_signer_count-1], 189 sig); 190 190 } 191 191 192 192 ops_parse_cb_return_t 193 ops_validate_key_cb(const ops_parser_content_t *content_,ops_parse_cb_info_t *cbinfo) 193 ops_validate_key_cb(const ops_parser_content_t *content_, 194 ops_parse_cb_info_t *cbinfo) 194 195 { 195 196 const ops_parser_content_union_t *content=&content_->content; … … 208 209 arg->pkey=content->public_key; 209 210 return OPS_KEEP_MEMORY; 210 211 211 212 case OPS_PTAG_CT_PUBLIC_SUBKEY: 212 213 if(arg->subkey.version) … … 214 215 arg->subkey=content->public_key; 215 216 return OPS_KEEP_MEMORY; 216 217 217 218 case OPS_PTAG_CT_SECRET_KEY: 218 219 arg->skey=content->secret_key; … … 271 272 ops_get_public_key_from_data(signer), 272 273 arg->rarg->key->packets[arg->rarg->packet].raw); 273 274 274 275 break; 275 276 … … 341 342 342 343 ops_parse_cb_return_t 343 validate_data_cb(const ops_parser_content_t *content_,ops_parse_cb_info_t *cbinfo) 344 validate_data_cb(const ops_parser_content_t *content_, 345 ops_parse_cb_info_t *cbinfo) 344 346 { 345 347 const ops_parser_content_union_t *content=&content_->content; … … 364 366 365 367 case OPS_PTAG_CT_LITERAL_DATA_BODY: 366 arg->data.literal_data_body=content->literal_data_body; 368 if(arg->data.literal_data_body.data != NULL) 369 free(arg->data.literal_data_body.data); 370 arg->data.literal_data_body=content->literal_data_body; 367 371 arg->use=LITERAL_DATA; 368 372 return OPS_KEEP_MEMORY; … … 370 374 371 375 case OPS_PTAG_CT_SIGNED_CLEARTEXT_BODY: 372 arg->data.signed_cleartext_body=content->signed_cleartext_body; 376 if(arg->data.signed_cleartext_body.data != NULL) 377 free(arg->data.signed_cleartext_body.data); 378 arg->data.signed_cleartext_body=content->signed_cleartext_body; 373 379 arg->use=SIGNED_CLEARTEXT; 374 380 return OPS_KEEP_MEMORY; … … 381 387 case OPS_PTAG_CT_SIGNATURE: // V3 sigs 382 388 case OPS_PTAG_CT_SIGNATURE_FOOTER: // V4 sigs 383 389 384 390 if (debug) 385 391 { … … 402 408 break; 403 409 } 404 410 405 411 mem=ops_memory_new(); 406 412 ops_memory_init(mem,128); 407 413 408 414 switch(content->signature.info.type) 409 415 { … … 414 420 case LITERAL_DATA: 415 421 ops_memory_add(mem, 416 arg->data.literal_data_body.data,417 arg->data.literal_data_body.length);422 arg->data.literal_data_body.data, 423 arg->data.literal_data_body.length); 418 424 break; 419 425 420 426 case SIGNED_CLEARTEXT: 421 427 ops_memory_add(mem, 422 arg->data.signed_cleartext_body.data,423 arg->data.signed_cleartext_body.length);428 arg->data.signed_cleartext_body.data, 429 arg->data.signed_cleartext_body.length); 424 430 break; 425 431 426 432 default: 427 433 OPS_ERROR_1(errors,OPS_E_UNIMPLEMENTED,"Unimplemented Sig Use %d", arg->use); … … 429 435 break; 430 436 } 431 437 432 438 valid=check_binary_signature(ops_memory_get_length(mem), 433 439 ops_memory_get_data(mem), … … 440 446 "Verification of signature type 0x%02x not yet implemented\n", content->signature.info.type); 441 447 break; 442 448 443 449 } 444 ops_memory_free(mem);450 ops_memory_free(mem); 445 451 446 452 if(valid) 447 { 448 add_sig_to_valid_list(arg->result, &content->signature.info); 449 } 453 add_sig_to_valid_list(arg->result, &content->signature.info); 450 454 else 451 455 { 452 OPS_ERROR(errors,OPS_E_V_BAD_SIGNATURE,"Bad Signature");453 add_sig_to_invalid_list(arg->result, &content->signature.info);456 OPS_ERROR(errors,OPS_E_V_BAD_SIGNATURE,"Bad Signature"); 457 add_sig_to_invalid_list(arg->result, &content->signature.info); 454 458 } 455 459 break; … … 496 500 ops_boolean_t validate_result_status(ops_validate_result_t* result) 497 501 { 498 if (result->invalid_count || result->unknown_signer_count || !result->valid_count) 502 if (result->invalid_count || result->unknown_signer_count 503 || !result->valid_count) 499 504 return ops_false; 500 505 else … … 512 517 * \note It is the caller's responsiblity to free result after use. 513 518 * \sa ops_validate_result_free() 514 519 515 520 Example Code: 516 \code517 void example(const ops_keydata_t* key, const ops_keyring_t *keyring)518 {521 \code 522 void example(const ops_keydata_t* key, const ops_keyring_t *keyring) 523 { 519 524 ops_validate_result_t *result=NULL; 520 525 if (ops_validate_key_signatures(result, key, keyring, callback_cmd_get_passphrase_from_cmdline)==ops_true) … … 527 532 result->unknown_signer_count); 528 533 ops_validate_result_free(result); 529 }530 531 \endcode534 } 535 536 \endcode 532 537 */ 533 538 ops_boolean_t ops_validate_key_signatures(ops_validate_result_t *result,const ops_keydata_t *key, … … 566 571 ops_parse_info_delete(pinfo); 567 572 568 if (result->invalid_count || result->unknown_signer_count || !result->valid_count) 573 if (result->invalid_count || result->unknown_signer_count 574 || !result->valid_count) 569 575 return ops_false; 570 576 else … … 579 585 \note It is the caller's responsibility to free result after use. 580 586 \sa ops_validate_result_free() 581 */587 */ 582 588 ops_boolean_t ops_validate_all_signatures(ops_validate_result_t *result, 583 589 const ops_keyring_t *ring, … … 589 595 memset(result,'\0',sizeof *result); 590 596 for(n=0 ; n < ring->nkeys ; ++n) 591 ops_validate_key_signatures(result,&ring->keys[n],ring, cb_get_passphrase); 597 ops_validate_key_signatures(result,&ring->keys[n],ring, 598 cb_get_passphrase); 592 599 return validate_result_status(result); 593 600 } … … 598 605 \param result Struct to be freed 599 606 \note Must be called after validation functions 600 */607 */ 601 608 void ops_validate_result_free(ops_validate_result_t *result) 602 609 { … … 627 634 \note It is the caller's responsiblity to call ops_validate_result_free(result) after use. 628 635 629 Example code:630 \code631 void example(const char* filename, const int armoured, const ops_keyring_t* keyring)632 {636 Example code: 637 \code 638 void example(const char* filename, const int armoured, const ops_keyring_t* keyring) 639 { 633 640 ops_validate_result_t* result=ops_mallocz(sizeof *result); 634 641 635 642 if (ops_validate_file(result, filename, armoured, keyring)==ops_true) 636 643 { 637 644 printf("OK"); 638 // look at result for details of keys with good signatures639 }640 else641 {642 printf("ERR");643 // look at result for details of failed signatures or unknown signers644 }645 646 ops_validate_result_free(result);645 // look at result for details of keys with good signatures 646 } 647 else 648 { 649 printf("ERR"); 650 // look at result for details of failed signatures or unknown signers 651 } 652 653 ops_validate_result_free(result); 647 654 } 648 655 \endcode 649 */ 650 ops_boolean_t ops_validate_file(ops_validate_result_t *result, const char* filename, const int armoured, const ops_keyring_t* keyring) 656 */ 657 ops_boolean_t ops_validate_file(ops_validate_result_t *result, 658 const char* filename, 659 const int armoured, 660 const ops_keyring_t* keyring) 651 661 { 652 662 ops_parse_info_t *pinfo=NULL; 653 663 validate_data_cb_arg_t validate_arg; 654 655 664 int fd=0; 656 665 657 //658 fd=ops_setup_file_read(&pinfo, filename, &validate_arg, validate_data_cb,ops_true);666 fd=ops_setup_file_read(&pinfo, filename, &validate_arg, validate_data_cb, 667 ops_true); 659 668 if (fd < 0) 660 669 return ops_false; … … 662 671 // Set verification reader and handling options 663 672 664 memset(&validate_arg, '\0',sizeof validate_arg);673 memset(&validate_arg, '\0', sizeof validate_arg); 665 674 validate_arg.result=result; 666 675 validate_arg.keyring=keyring; … … 671 680 if (armoured) 672 681 ops_reader_push_dearmour(pinfo); 673 682 674 683 // Do the verification 675 684 … … 688 697 ops_reader_pop_dearmour(pinfo); 689 698 ops_teardown_file_read(pinfo, fd); 699 700 if(validate_arg.data.literal_data_body.data != NULL) 701 free(validate_arg.data.literal_data_body.data); 690 702 691 703 return validate_result_status(result); … … 703 715 have passed, failed and not been recognised. 704 716 \note It is the caller's responsiblity to call ops_validate_result_free(result) after use. 705 */717 */ 706 718 707 719 ops_boolean_t ops_validate_mem(ops_validate_result_t *result, ops_memory_t* mem, const int armoured, const ops_keyring_t* keyring) … … 710 722 validate_data_cb_arg_t validate_arg; 711 723 712 //713 724 ops_setup_memory_read(&pinfo, mem, &validate_arg, validate_data_cb, ops_true); 714 725 715 726 // Set verification reader and handling options 716 727 717 memset(&validate_arg, '\0',sizeof validate_arg);728 memset(&validate_arg, '\0', sizeof validate_arg); 718 729 validate_arg.result=result; 719 730 validate_arg.keyring=keyring; … … 724 735 if (armoured) 725 736 ops_reader_push_dearmour(pinfo); 726 737 727 738 // Do the verification 728 739 … … 742 753 ops_teardown_memory_read(pinfo, mem); 743 754 755 if(validate_arg.data.literal_data_body.data != NULL) 756 free(validate_arg.data.literal_data_body.data); 757 744 758 return validate_result_status(result); 745 759 } 746 760 747 // eof 761 /** 762 \ingroup HighLevel_Verify 763 \brief Verifies the signature in a detached signature data packet, given the literal data 764 \param literal_data Literal data that is signed 765 \param literal_data_length length of the literal data that is signed 766 \param signature_packet signature packet in binary PGP format 767 \param signature_packet_length length of the signature packet 768 \param signers_key Public key of the signer to check the signature for. 769 \return ops_true if signature validates successfully; ops_false if not 770 */ 771 772 ops_boolean_t 773 ops_validate_detached_signature(const void *literal_data, 774 unsigned int literal_data_length, 775 const unsigned char *signature_packet, 776 unsigned int signature_packet_length, 777 const ops_keydata_t *signers_key) 778 { 779 ops_validate_result_t *result = (ops_validate_result_t*)ops_mallocz(sizeof(ops_validate_result_t)); 780 781 ops_memory_t *mem = ops_memory_new(); 782 ops_memory_add(mem,signature_packet,signature_packet_length); 783 784 ops_parse_info_t *pinfo=NULL; 785 validate_data_cb_arg_t validate_arg; 786 787 ops_setup_memory_read(&pinfo, mem, &validate_arg, validate_data_cb, 788 ops_true); 789 790 // Set verification reader and handling options 791 792 ops_keyring_t tmp_keyring; 793 tmp_keyring.nkeys = 1; 794 tmp_keyring.nkeys_allocated = 1; 795 tmp_keyring.keys = (ops_keydata_t *)signers_key; // this is a const_cast, somehow 796 797 memset(&validate_arg,'\0',sizeof validate_arg); 798 799 validate_arg.result=result; 800 validate_arg.keyring=&tmp_keyring; 801 802 int length = literal_data_length; 803 804 validate_arg.data.literal_data_body.data = malloc(length); 805 memcpy(validate_arg.data.literal_data_body.data, literal_data, length); 806 validate_arg.data.literal_data_body.length = length; 807 808 // Note: Coverity incorrectly reports an error that carg.rarg 809 // is never used. 810 validate_arg.rarg=ops_reader_get_arg_from_pinfo(pinfo); 811 812 //if (armoured) 813 // ops_reader_push_dearmour(pinfo); 814 815 // Do the verification 816 817 ops_parse(pinfo); 818 819 printf("valid=%d, invalid=%d, unknown=%d\n", result->valid_count, 820 result->invalid_count, result->unknown_signer_count); 821 822 // Tidy up 823 //if (armoured) 824 // ops_reader_pop_dearmour(pinfo); 825 826 ops_teardown_memory_read(pinfo, mem); 827 828 ops_boolean_t res = validate_result_status(result); 829 ops_validate_result_free(result); 830 831 if(validate_arg.data.literal_data_body.data != NULL) 832 free(validate_arg.data.literal_data_body.data); 833 834 return res; 835 } openpgpsdk/trunk/src/lib/writer_armour.c
r701 r707 35 35 static int debug=0; 36 36 37 #define LINE_LENGTH 7537 #define LINE_LENGTH 63 38 38 39 39 static const char newline[] = "\r\n"; … … 285 285 } linebreak_arg_t; 286 286 287 #define BREAKPOS 76287 #define BREAKPOS 64 288 288 289 289 static ops_boolean_t linebreak_writer(const unsigned char *src, openpgpsdk/trunk/tests/test_dsa_signature.c
r701 r707 173 173 validate_data_cb_arg_t validate_arg; 174 174 175 mem=ops_sign_buf(input, input_len, OPS_SIG_TEXT, skey, use_armour); 175 mem=ops_sign_buf(input, input_len, OPS_SIG_TEXT, skey, use_armour, 176 ops_true); 176 177 177 178 if (debug) openpgpsdk/trunk/tests/test_rsa_signature.c
r702 r707 207 207 validate_data_cb_arg_t validate_arg; 208 208 209 mem=ops_sign_buf(input, input_len, OPS_SIG_TEXT, skey, use_armour); 209 mem=ops_sign_buf(input, input_len, OPS_SIG_TEXT, skey, use_armour, 210 ops_true); 210 211 211 212 /*
