Changeset 521
- Timestamp:
- 11/28/07 17:37:27
- Files:
-
- openpgpsdk/trunk/include/openpgpsdk/errors.h (modified) (2 diffs)
- openpgpsdk/trunk/include/openpgpsdk/packet.h (modified) (2 diffs)
- openpgpsdk/trunk/include/openpgpsdk/validate.h (modified) (1 diff)
- openpgpsdk/trunk/src/advanced/adv_armour.c (modified) (2 diffs)
- openpgpsdk/trunk/src/advanced/adv_fingerprint.c (modified) (3 diffs)
- openpgpsdk/trunk/src/advanced/adv_keyring.c (modified) (3 diffs)
- openpgpsdk/trunk/src/advanced/adv_openssl_crypto.c (modified) (4 diffs)
- openpgpsdk/trunk/src/advanced/adv_packet-parse.c (modified) (10 diffs)
- openpgpsdk/trunk/src/advanced/adv_packet-show.c (modified) (2 diffs)
- openpgpsdk/trunk/src/advanced/adv_signature.c (modified) (15 diffs)
- openpgpsdk/trunk/src/advanced/adv_validate.c (modified) (8 diffs)
- openpgpsdk/trunk/tests/Makefile.template (modified) (1 diff)
- openpgpsdk/trunk/tests/test_common.c (modified) (6 diffs)
- openpgpsdk/trunk/tests/test_crypt_mpi.c (modified) (1 diff)
- openpgpsdk/trunk/tests/test_rsa_decrypt.c (modified) (7 diffs)
- openpgpsdk/trunk/tests/test_rsa_encrypt.c (modified) (1 diff)
- openpgpsdk/trunk/tests/test_rsa_signature.c (modified) (8 diffs)
- openpgpsdk/trunk/tests/test_rsa_verify.c (modified) (8 diffs)
- openpgpsdk/trunk/tests/tests.h (modified) (2 diffs)
- openpgpsdk/trunk/tests/tests_gpg.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
openpgpsdk/trunk/include/openpgpsdk/errors.h
r517 r521 40 40 OPS_E_C=0x4000, /* general creator error */ 41 41 42 /* validation errors */ 43 OPS_E_V=0x5000, /* general validation error */ 44 OPS_E_V_BAD_SIGNATURE =OPS_E_V+1, 45 OPS_E_V_UNKNOWN_SIGNER =OPS_E_V+2, 46 42 47 /* Algorithm support errors */ 43 OPS_E_ALG=0x 5000, /* general algorithm error */48 OPS_E_ALG=0x6000, /* general algorithm error */ 44 49 OPS_E_ALG_UNSUPPORTED_SYMMETRIC_ALG =OPS_E_ALG+1, 45 50 OPS_E_ALG_UNSUPPORTED_PUBLIC_KEY_ALG =OPS_E_ALG+2, … … 48 53 49 54 /* Protocol errors */ 50 OPS_E_PROTO=0x 6000, /* general protocol error */55 OPS_E_PROTO=0x7000, /* general protocol error */ 51 56 OPS_E_PROTO_BAD_SYMMETRIC_DECRYPT =OPS_E_PROTO+2, 52 57 OPS_E_PROTO_UNKNOWN_SS =OPS_E_PROTO+3, openpgpsdk/trunk/include/openpgpsdk/packet.h
r480 r521 560 560 size_t v4_hashed_data_start; /* only valid if accumulate is set */ 561 561 size_t v4_hashed_data_length; 562 unsigned char* v4_hashed_data; 562 563 ops_hash_t *hash; /*!< if set, the hash filled in for the data so far */ 563 564 ops_boolean_t creation_time_set:1; … … 801 802 { 802 803 unsigned length; 803 unsigned char data[8192]; 804 unsigned char data[8192]; // \todo fix hard-coded value? 804 805 } ops_signed_cleartext_body_t; 805 806 openpgpsdk/trunk/include/openpgpsdk/validate.h
r517 r521 25 25 { 26 26 ATTRIBUTE, 27 ID 27 ID, 28 28 } last_seen; 29 29 ops_user_id_t user_id; 30 30 ops_user_attribute_t user_attribute; 31 unsigned char hash[OPS_MAX_HASH_SIZE]; 31 32 const ops_keyring_t *keyring; 32 33 validate_reader_arg_t *rarg; 33 34 ops_validate_result_t *result; 34 } validate_ cb_arg_t;35 } validate_key_cb_arg_t; 35 36 37 typedef struct 38 { 39 enum 40 { 41 LITERAL_DATA, 42 SIGNED_CLEARTEXT 43 } use; 44 union 45 { 46 ops_literal_data_body_t literal_data_body; 47 ops_signed_cleartext_body_t signed_cleartext_body; 48 } data; 49 unsigned char hash[OPS_MAX_HASH_SIZE]; 50 const ops_keyring_t *keyring; 51 validate_reader_arg_t *rarg; 52 ops_validate_result_t *result; 53 } validate_data_cb_arg_t; 54 55 ops_boolean_t ops_check_signature(const unsigned char *hash, 56 unsigned length, 57 const ops_signature_t *sig, 58 const ops_public_key_t *signer); 36 59 // EOF openpgpsdk/trunk/src/advanced/adv_armour.c
r457 r521 15 15 16 16 #include <openpgpsdk/final.h> 17 18 static int debug=0; 17 19 18 20 #define CRC24_INIT 0xb704ceL … … 813 815 unsigned n; 814 816 817 if (debug) 818 { 819 unsigned int i=0; 820 fprintf(stderr,"dash_escaped_writer writing %d:\n", length); 821 for (i=0; i<length; i++) 822 { 823 fprintf(stderr,"0x%02x ", src[i]); 824 if (!((i+1) % 16)) 825 fprintf(stderr,"\n"); 826 else if (!((i+1) % 8)) 827 fprintf(stderr," "); 828 } 829 fprintf(stderr,"\n"); 830 } 831 815 832 // XXX: make this efficient 816 833 for(n=0 ; n < length ; ++n) openpgpsdk/trunk/src/advanced/adv_fingerprint.c
r516 r521 18 18 19 19 #include <openpgpsdk/final.h> 20 21 static int debug=0; 20 22 21 23 /** … … 64 66 ops_build_public_key(mem,key,ops_false); 65 67 68 if (debug) 69 { fprintf(stderr,"--- creating key fingerprint\n"); } 70 66 71 ops_hash_sha1(&sha1); 67 72 sha1.init(&sha1); … … 73 78 sha1.add(&sha1,ops_memory_get_data(mem),l); 74 79 sha1.finish(&sha1,fp->fingerprint); 80 81 if (debug) 82 { fprintf(stderr,"--- finished creating key fingerprint\n"); } 75 83 76 84 fp->length=20; openpgpsdk/trunk/src/advanced/adv_keyring.c
r516 r521 8 8 #include <openpgpsdk/validate.h> 9 9 #include "keyring_local.h" 10 #include "parse_local.h" 11 10 12 #include <stdlib.h> 11 13 #include <string.h> … … 185 187 return OPS_KEEP_MEMORY; 186 188 189 case OPS_PARSER_PACKET_END: 190 // nothing to do 191 break; 192 187 193 default: 188 194 fprintf(stderr,"Unexpected tag %d (0x%x)\n",content_->tag, … … 209 215 ops_key_data_reader_set(pinfo,key); 210 216 ops_parse_cb_set(pinfo,decrypt_cb,&arg); 217 pinfo->rinfo.accumulate=ops_true; 211 218 212 219 ops_parse(pinfo); openpgpsdk/trunk/src/advanced/adv_openssl_crypto.c
r516 r521 15 15 #include <openpgpsdk/final.h> 16 16 17 static int debug=0; 18 17 19 static void md5_init(ops_hash_t *hash) 18 20 { … … 45 47 static void sha1_init(ops_hash_t *hash) 46 48 { 49 if (debug) 50 { 51 fprintf(stderr,"***\n***\nsha1_init\n***\n"); 52 } 47 53 assert(!hash->data); 48 54 hash->data=malloc(sizeof(SHA_CTX)); … … 53 59 unsigned length) 54 60 { 61 if (debug) 62 { 63 unsigned int i=0; 64 fprintf(stderr,"adding %d to hash:\n ", length); 65 for (i=0; i<length; i++) 66 { 67 fprintf(stderr,"0x%02x ", data[i]); 68 if (!((i+1) % 16)) 69 fprintf(stderr,"\n"); 70 else if (!((i+1) % 8)) 71 fprintf(stderr," "); 72 } 73 fprintf(stderr,"\n"); 74 } 55 75 SHA1_Update(hash->data,data,length); 56 76 } … … 59 79 { 60 80 SHA1_Final(out,hash->data); 81 if (debug) 82 { 83 unsigned i=0; 84 fprintf(stderr,"***\n***\nsha1_finish\n***\n"); 85 for (i=0; i<20; i++) 86 fprintf(stderr,"0x%02x ",out[i]); 87 fprintf(stderr,"\n"); 88 } 61 89 free(hash->data); 62 90 hash->data=NULL; openpgpsdk/trunk/src/advanced/adv_packet-parse.c
r520 r521 27 27 28 28 #include <openpgpsdk/final.h> 29 30 static int debug=0; 29 31 30 32 typedef struct … … 1341 1343 return 0; 1342 1344 CBP(pinfo,OPS_PTAG_RAW_SS,&content); 1343 return 1;1345 return 1; 1344 1346 } 1345 1347 … … 1631 1633 * \see RFC2440bis-12 5.2.3 1632 1634 */ 1633 static int parse_v4_signature(ops_region_t *region,ops_parse_info_t *pinfo, 1634 size_t v4_hashed_data_start) 1635 static int parse_v4_signature(ops_region_t *region,ops_parse_info_t *pinfo) 1635 1636 { 1636 1637 unsigned char c[1]; 1637 1638 ops_parser_content_t content; 1638 1639 1640 // clear signature 1639 1641 memset(&C.signature,'\0',sizeof C.signature); 1642 1643 /* We need to hash the packet data from version through the hashed subpacket data */ 1644 1645 C.signature.v4_hashed_data_start=pinfo->rinfo.alength-1; 1646 1647 /* Set version,type,algorithms */ 1648 1640 1649 C.signature.version=OPS_V4; 1641 C.signature.v4_hashed_data_start=v4_hashed_data_start;1642 1650 1643 1651 if(!limited_read(c,1,region,pinfo)) … … 1660 1668 if(!parse_signature_subpackets(&C.signature,region,pinfo)) 1661 1669 return 0; 1670 1662 1671 C.signature.v4_hashed_data_length=pinfo->rinfo.alength 1663 -C.signature.v4_hashed_data_start; 1672 -C.signature.v4_hashed_data_start; 1673 1674 // copy hashed subpackets 1675 if (C.signature.v4_hashed_data) 1676 free(C.signature.v4_hashed_data); 1677 C.signature.v4_hashed_data=ops_mallocz(C.signature.v4_hashed_data_length); 1678 1679 if (!pinfo->rinfo.accumulate) 1680 { 1681 /* We must accumulate, else we can't check the signature */ 1682 fprintf(stderr,"*** ERROR: must set accumulate to true\n"); 1683 assert(0); 1684 } 1685 1686 memcpy(C.signature.v4_hashed_data, 1687 pinfo->rinfo.accumulated+C.signature.v4_hashed_data_start, 1688 C.signature.v4_hashed_data_length); 1664 1689 1665 1690 if(!parse_signature_subpackets(&C.signature,region,pinfo)) … … 1739 1764 unsigned char c[1]; 1740 1765 ops_parser_content_t content; 1741 size_t v4_hashed_data_start;1742 1766 1743 1767 assert(region->length_read == 0); /* We should not have read anything so far */ … … 1745 1769 memset(&content,'\0',sizeof content); 1746 1770 1747 v4_hashed_data_start=pinfo->rinfo.alength;1748 1771 if(!limited_read(c,1,region,pinfo)) 1749 1772 return 0; … … 1752 1775 return parse_v3_signature(region,pinfo); 1753 1776 else if(c[0] == 4) 1754 return parse_v4_signature(region,pinfo ,v4_hashed_data_start);1777 return parse_v4_signature(region,pinfo); 1755 1778 1756 1779 OPS_ERROR_1(&pinfo->errors,OPS_E_PROTO_BAD_SIGNATURE_VRSN, … … 2236 2259 ops_parse_info_t *pinfo) 2237 2260 { 2238 int debug=0;2239 2261 unsigned char c[1]; 2240 2262 ops_parser_content_t content; … … 2397 2419 ops_parse_cb_info_t *cbinfo) 2398 2420 { 2399 int debug=0;2400 2421 2401 2422 /* … … 3125 3146 pinfo->rinfo.pinfo=pinfo; 3126 3147 3148 // should copy accumulate flags from other reader? RW 3149 pinfo->rinfo.accumulate=rinfo->accumulate; 3150 3127 3151 ops_reader_set(pinfo,reader,destroyer,arg); 3128 3152 } openpgpsdk/trunk/src/advanced/adv_packet-show.c
r426 r521 41 41 { OPS_PTAG_CT_SE_IP_DATA, "Sym. Encrypted and Integrity Protected Data" }, 42 42 { OPS_PTAG_CT_MDC, "Modification Detection Code" }, 43 { OPS_PARSER_PTAG, "OPS_PARSER_PTAG" }, 44 { OPS_PTAG_RAW_SS, "OPS_PTAG_RAW_SS" }, 45 { OPS_PTAG_SS_ALL, "OPS_PTAG_SS_ALL" }, 46 { OPS_PARSER_PACKET_END, "OPS_PARSER_PACKET_END" }, 47 { OPS_PTAG_SIGNATURE_SUBPACKET_BASE, "OPS_PTAG_SIGNATURE_SUBPACKET_BASE" }, 48 /* 49 { OPS_PTAG_SS_CREATION_TIME, "SS: Signature Creation Time" }, 50 { OPS_PTAG_SS_EXPIRATION_TIME, "SS: Signature Expiration Time" }, 51 { OPS_PTAG_SS_TRUST, "SS: Trust" }, 52 { OPS_PTAG_SS_REGEXP, "SS: Regexp" }, 53 { OPS_PTAG_SS_REVOCABLE, "SS: Revocable" }, 54 { OPS_PTAG_SS_KEY_EXPIRATION_TIME, "SS: Key Expiration Time" }, 55 { OPS_PTAG_SS_RESERVED, "SS: Reserved" }, 56 { OPS_PTAG_SS_PREFERRED_SKA, "SS: Preferred SKA" }, 57 { OPS_PTAG_SS_REVOCATION_KEY, "SS: Revocation Key" }, 58 { OPS_PTAG_SS_ISSUER_KEY_ID, "SS: Issuer Key Id" }, 59 { OPS_PTAG_SS_NOTATION_DATA, "SS: Notation Data" }, 60 { OPS_PTAG_SS_PREFERRED_HASH, "SS: Preferred Hash" }, 61 { OPS_PTAG_SS_PREFERRED_COMPRESSION,"SS: Preferred Compression" }, 62 { OPS_PTAG_SS_KEY_SERVER_PREFS, "SS: Preferred Key Server" }, 63 { OPS_PTAG_SS_PRIMARY_USER_ID, "SS: Primary User ID" }, 64 { OPS_PTAG_SS_POLICY_URL, "SS: Policy URL" }, 65 { OPS_PTAG_SS_KEY_FLAGS, "SS: Key Flags" }, 66 { OPS_PTAG_SS_SIGNERS_USER_ID, "SS: Signers User ID" }, 67 { OPS_PTAG_SS_REVOCATION_REASON, "SS: Revocation Reason" }, 68 { OPS_PTAG_SS_FEATURES, "SS: Features" }, 69 */ 70 { OPS_PTAG_CT_LITERAL_DATA_HEADER, "CT: Literal Data Header" }, 71 { OPS_PTAG_CT_LITERAL_DATA_BODY, "CT: Literal Data Body" }, 72 { OPS_PTAG_CT_SIGNATURE_HEADER, "CT: Signature Header" }, 73 { OPS_PTAG_CT_SIGNATURE_FOOTER, "CT: Signature Footer" }, 74 { OPS_PTAG_CT_ARMOUR_HEADER, "CT: Armour Header" }, 75 { OPS_PTAG_CT_ARMOUR_TRAILER, "CT: Armour Trailer" }, 76 { OPS_PTAG_CT_SIGNED_CLEARTEXT_HEADER, "CT: Signed Cleartext Header" }, 77 { OPS_PTAG_CT_SIGNED_CLEARTEXT_BODY, "CT: Signed Cleartext Body" }, 78 { OPS_PTAG_CT_SIGNED_CLEARTEXT_TRAILER, "CT: Signed Cleartext Trailer" }, 79 { OPS_PTAG_CT_UNARMOURED_TEXT, "CT: Unarmoured Text" }, 80 { OPS_PTAG_CT_ENCRYPTED_SECRET_KEY, "CT: Encrypted Secret Key" }, 81 { OPS_PTAG_CT_SE_DATA_HEADER, "CT: Sym Encrypted Data Header" }, 82 { OPS_PTAG_CT_SE_DATA_BODY, "CT: Sym Encrypted Data Body" }, 83 { OPS_PTAG_CT_SE_IP_DATA_HEADER, "CT: Sym Encrypted IP Data Header" }, 84 { OPS_PTAG_CT_SE_IP_DATA_BODY, "CT: Sym Encrypted IP Data Body" }, 85 { OPS_PTAG_CT_ENCRYPTED_PK_SESSION_KEY, "CT: Encrypted PK Session Key" }, 86 { OPS_PARSER_CMD_GET_SK_PASSPHRASE, "CMD: Get Secret Key Passphrase" }, 87 { OPS_PARSER_CMD_GET_SECRET_KEY, "CMD: Get Secret Key" }, 88 { OPS_PARSER_ERROR, "OPS_PARSER_ERROR" }, 89 { OPS_PARSER_ERRCODE, "OPS_PARSER_ERRCODE" }, 90 43 91 { (int) NULL, (char *)NULL }, /* this is the end-of-array marker */ 44 92 }; … … 460 508 const char *ops_show_packet_tag(ops_packet_tag_t packet_tag) 461 509 { 462 return show_packet_tag(packet_tag,packet_tag_map); 510 char *rtn=NULL; 511 rtn=show_packet_tag(packet_tag,packet_tag_map); 512 513 if (!rtn) 514 rtn="Unknown Tag"; 515 516 return rtn; 463 517 } 464 518 openpgpsdk/trunk/src/advanced/adv_signature.c
r459 r521 9 9 10 10 #include <openpgpsdk/final.h> 11 12 static int debug=0; 11 13 12 14 /** \ingroup Create … … 41 43 0x03,0x02,0x1A,0x05,0x00,0x04,0x14 }; 42 44 45 ops_boolean_t encode_hash_buf(const unsigned char *M, size_t mLen, 46 const ops_hash_algorithm_t hash_alg, 47 unsigned char* EM 48 ) 49 { 50 // implementation of EMSA-PKCS1-v1_5, as defined in OpenPGP RFC 51 52 unsigned i; 53 54 int n=0; 55 ops_hash_t hash; 56 // unsigned char hashout[OPS_MAX_HASH_SIZE]; 57 int hash_sz=0; 58 int encoded_hash_sz=0; 59 int prefix_sz=0; 60 unsigned padding_sz=0; 61 unsigned encoded_msg_sz=0; 62 unsigned char* prefix=NULL; 63 64 assert(hash_alg == OPS_HASH_SHA1); 65 66 // 1. Apply hash function to M 67 68 ops_hash_any(&hash,hash_alg); 69 hash.init(&hash); 70 hash.add(&hash,M,mLen); 71 72 // \todo combine with rsa_sign 73 74 // 2. Get hash prefix 75 76 switch(hash_alg) 77 { 78 case OPS_HASH_SHA1: 79 prefix=prefix_sha1; 80 prefix_sz=sizeof prefix_sha1; 81 hash_sz=OPS_SHA1_HASH_SIZE; 82 encoded_hash_sz=hash_sz+prefix_sz; 83 // \todo why is Ben using a PS size of 90 in rsa_sign? 84 // (keysize-hashsize-1-2) 85 padding_sz=90; 86 break; 87 88 default: 89 assert(0); 90 } 91 92 // \todo 3. Test for len being too short 93 94 // 4 and 5. Generate PS and EM 95 96 EM[0]=0x00; 97 EM[1]=0x01; 98 99 for (i=0; i<padding_sz; i++) 100 EM[2+i]=0xFF; 101 102 i+=2; 103 104 EM[i++]=0x00; 105 106 memcpy(&EM[i],prefix,prefix_sz); 107 i+=prefix_sz; 108 109 // finally, write out hashed result 110 111 n=hash.finish(&hash,&EM[i]); 112 113 encoded_msg_sz=i+hash_sz-1; 114 115 // \todo test n for OK response? 116 117 if (debug) 118 { 119 fprintf(stderr,"Encoded Message: \n"); 120 for (i=0; i<encoded_msg_sz; i++) 121 fprintf(stderr,"%2x ", EM[i]); 122 fprintf(stderr,"\n"); 123 } 124 125 return ops_true; 126 } 127 43 128 // XXX: both this and verify would be clearer if the signature were 44 129 // treated as an MPI. … … 55 140 BIGNUM *bn; 56 141 142 57 143 // XXX: we assume hash is sha-1 for now 58 144 hashsize=20+sizeof prefix_sha1; … … 64 150 hashbuf[0]=0; 65 151 hashbuf[1]=1; 152 if (debug) 153 { printf("rsa_sign: PS is %d\n", keysize-hashsize-1-2); } 66 154 for(n=2 ; n < keysize-hashsize-1 ; ++n) 67 155 hashbuf[n]=0xff; … … 135 223 return ops_false; 136 224 225 if (debug) 226 { 227 int zz; 228 229 printf("\n"); 230 printf("hashbuf\n"); 231 for (zz=0; zz<plen; zz++) 232 { printf("%02x ", hashbuf[n+zz]); } 233 printf("\n"); 234 printf("prefix\n"); 235 for (zz=0; zz<plen; zz++) 236 { printf("%02x ", prefix[zz]); } 237 printf("\n"); 238 239 printf("\n"); 240 printf("hashbuf2\n"); 241 unsigned uu; 242 for (uu=0; uu<hash_length; uu++) 243 { printf("%02x ", hashbuf[n+plen+uu]); } 244 printf("\n"); 245 printf("hash\n"); 246 for (uu=0; uu<hash_length; uu++) 247 { printf("%02x ", hash[uu]); } 248 printf("\n"); 249 } 137 250 if(memcmp(&hashbuf[n],prefix,plen) 138 251 || memcmp(&hashbuf[n+plen],hash,hash_length)) … … 163 276 } 164 277 165 static void init_ signature(ops_hash_t *hash,const ops_signature_t *sig,278 static void init_key_signature(ops_hash_t *hash,const ops_signature_t *sig, 166 279 const ops_public_key_t *key) 167 280 { … … 189 302 } 190 303 191 static ops_boolean_tcheck_signature(const unsigned char *hash,unsigned length,304 ops_boolean_t ops_check_signature(const unsigned char *hash,unsigned length, 192 305 const ops_signature_t *sig, 193 306 const ops_public_key_t *signer) … … 228 341 n=hash->finish(hash,hashout); 229 342 230 return check_signature(hashout,n,sig,signer);343 return ops_check_signature(hashout,n,sig,signer); 231 344 } 232 345 … … 261 374 size_t user_id_len=strlen((char *)id->user_id); 262 375 263 init_ signature(&hash,sig,key);376 init_key_signature(&hash,sig,key); 264 377 265 378 if(sig->version == OPS_V4) … … 293 406 ops_hash_t hash; 294 407 295 init_ signature(&hash,sig,key);408 init_key_signature(&hash,sig,key); 296 409 297 410 if(sig->version == OPS_V4) … … 325 438 ops_hash_t hash; 326 439 327 init_ signature(&hash,sig,key);440 init_key_signature(&hash,sig,key); 328 441 hash_add_key(&hash,subkey); 329 442 … … 349 462 ops_hash_t hash; 350 463 351 init_ signature(&hash,sig,key);464 init_key_signature(&hash,sig,key); 352 465 return finalise_signature(&hash,sig,signer,raw_packet); 353 466 } … … 422 535 sig->hashed_data_length=-1; 423 536 424 init_ signature(&sig->hash,&sig->sig,key);537 init_key_signature(&sig->hash,&sig->sig,key); 425 538 426 539 ops_hash_add_int(&sig->hash,0xb4,1); … … 474 587 size_t length) 475 588 { 589 if (debug) 590 { fprintf(stderr,"ops_signature_add_data adds to hash\n"); } 476 591 sig->hash.add(&sig->hash,buf,length); 477 592 } … … 520 635 521 636 // add the packet from version number to end of hashed subpackets 637 638 if (debug) 639 { fprintf(stderr, "--- Adding packet to hash from version number to hashed subpkts\n"); } 640 522 641 sig->hash.add(&sig->hash,ops_memory_get_data(sig->mem), 523 642 sig->unhashed_count_offset); 643 /* what is this??? should delete? RW 524 644 ops_hash_add_int(&sig->hash,sig->sig.version,1); 525 645 ops_hash_add_int(&sig->hash,0xff,1); 526 646 // +6 for version, type, pk alg, hash alg, hashed subpacket length 527 647 ops_hash_add_int(&sig->hash,sig->hashed_data_length+6,4); 648 */ 649 650 if (debug) 651 { fprintf(stderr, "--- Finished adding packet to hash from version number to hashed subpkts\n"); } 528 652 529 653 // XXX: technically, we could figure out how big the signature is openpgpsdk/trunk/src/advanced/adv_validate.c
r517 r521 1 1 #include <openpgpsdk/packet-parse.h> 2 #include <openpgpsdk/packet-show.h> 2 3 #include <openpgpsdk/keyring.h> 3 4 #include "keyring_local.h" 4 5 #include <openpgpsdk/util.h> 5 6 #include <openpgpsdk/signature.h> 7 #include <openpgpsdk/memory.h> 6 8 #include <openpgpsdk/validate.h> 7 9 #include <assert.h> … … 9 11 10 12 #include <openpgpsdk/final.h> 13 14 static int debug=0; 15 16 static ops_boolean_t check_binary_signature(const unsigned len, 17 const unsigned char *data, 18 const ops_signature_t *sig, 19 const ops_public_key_t *signer __attribute__((unused))) 20 { 21 // Does the signed hash match the given hash? 22 23 int n=0; 24 ops_hash_t hash; 25 unsigned char hashout[OPS_MAX_HASH_SIZE]; 26 27 //common_init_signature(&hash,sig); 28 ops_hash_any(&hash,sig->hash_algorithm); 29 hash.init(&hash); 30 hash.add(&hash,data,len); 31 hash.add(&hash,sig->v4_hashed_data,sig->v4_hashed_data_length); 32 n=hash.finish(&hash,hashout); 33 34 // return ops_false; 35 return ops_check_signature(hashout,n,sig,signer); 36 } 11 37 12 38 static int key_data_reader(void *dest,size_t length,ops_error_t **errors, … … 41 67 42 68 ops_parse_cb_return_t 43 validate_ cb(const ops_parser_content_t *content_,ops_parse_cb_info_t *cbinfo)69 validate_key_cb(const ops_parser_content_t *content_,ops_parse_cb_info_t *cbinfo) 44 70 { 45 71 const ops_parser_content_union_t *content=&content_->content; 46 validate_ cb_arg_t *arg=ops_parse_cb_get_arg(cbinfo);72 validate_key_cb_arg_t *arg=ops_parse_cb_get_arg(cbinfo); 47 73 ops_error_t **errors=ops_parse_cb_get_errors(cbinfo); 48 74 const ops_key_data_t *signer; 49 75 ops_boolean_t valid=ops_false; 76 77 if (debug) 78 printf("%s\n",ops_show_packet_tag(content_->tag)); 50 79 51 80 switch(content_->tag) … … 129 158 break; 130 159 131 case OPS_SIG_BINARY: 160 #ifdef MOVED 132 161 case OPS_SIG_TEXT: 162 #endif 133 163 case OPS_SIG_STANDALONE: 134 164 case OPS_SIG_PRIMARY: … … 142 172 143 173 default: 144 fprintf(stderr,"Unexpected signature type=0x%02x\n", 145 content->signature.type); 146 exit(1); 174 OPS_ERROR_1(errors, OPS_E_UNIMPLEMENTED, 175 "Unexpected signature type 0x%02x\n", content->signature.type); 147 176 } 148 177 … … 173 202 } 174 203 204 ops_parse_cb_return_t 205 validate_data_cb(const ops_parser_content_t *content_,ops_parse_cb_info_t *cbinfo) 206 { 207 const ops_parser_content_union_t *content=&content_->content; 208 validate_data_cb_arg_t *arg=ops_parse_cb_get_arg(cbinfo); 209 ops_error_t **errors=ops_parse_cb_get_errors(cbinfo); 210 const ops_key_data_t *signer; 211 ops_boolean_t valid=ops_false; 212 // unsigned len=0; 213 // unsigned char *data=NULL; 214 ops_memory_t* mem=NULL; 215 216 if (debug) 217 printf("%s\n",ops_show_packet_tag(content_->tag)); 218 219 switch(content_->tag) 220 { 221 case OPS_PTAG_CT_SIGNED_CLEARTEXT_HEADER: 222 // ignore - this gives us the "Armor Header" line "Hash: SHA1" or similar 223 break; 224 225 case OPS_PTAG_CT_LITERAL_DATA_HEADER: 226 // ignore 227 break; 228 229 case OPS_PTAG_CT_LITERAL_DATA_BODY: 230 arg->data.literal_data_body=content->literal_data_body; 231 arg->use=LITERAL_DATA; 232 return OPS_KEEP_MEMORY; 233 break; 234 235 case OPS_PTAG_CT_SIGNED_CLEARTEXT_BODY: 236 arg->data.signed_cleartext_body=content->signed_cleartext_body; 237 arg->use=SIGNED_CLEARTEXT; 238 return OPS_KEEP_MEMORY; 239 break; 240 241 case OPS_PTAG_CT_SIGNED_CLEARTEXT_TRAILER: 242 // this gives us an ops_hash_t struct 243 break; 244 245 case OPS_PTAG_CT_SIGNATURE: // V3 sigs 246 // this gives us a signature struct with all info about hash alg, etc from the packet 247 break; 248 249 case OPS_PTAG_CT_SIGNATURE_FOOTER: // V4 sigs 250 251 if (debug) 252 { 253 printf("\n*** hashed data:\n"); 254 unsigned int zzz=0; 255 for (zzz=0; zzz<content->signature.v4_hashed_data_length; zzz++) 256 printf("0x%02x ", content->signature.v4_hashed_data[zzz]); 257 printf("\n"); 258 printf(" type=%02x signer_id=",content->signature.type); 259 hexdump(content->signature.signer_id, 260 sizeof content->signature.signer_id); 261 } 262 263 signer=ops_keyring_find_key_by_id(arg->keyring, 264 content->signature.signer_id); 265 if(!signer) 266 { 267 OPS_ERROR(errors,OPS_E_V_UNKNOWN_SIGNER,"Unknown Signer"); 268 printf(" UNKNOWN SIGNER\n"); 269 ++arg->result->unknown_signer_count; 270 break; 271 } 272 273 mem=ops_memory_new(); 274 ops_memory_init(mem,128); 275 276 switch(content->signature.type) 277 { 278 case OPS_SIG_BINARY: 279 switch(arg->use) 280 { 281 case LITERAL_DATA: 282 ops_memory_add(mem, 283 arg->data.literal_data_body.data, 284 arg->data.literal_data_body.length); 285 break; 286 287 case SIGNED_CLEARTEXT: 288 ops_memory_add(mem, 289 arg->data.signed_cleartext_body.data, 290 arg->data.signed_cleartext_body.length); 291 break; 292 293 default: 294 assert (0); 295 } 296 297 valid=check_binary_signature(ops_memory_get_length(mem), 298 ops_memory_get_data(mem), 299 &content->signature, 300 ops_get_public_key_from_data(signer)); 301 break; 302 303 OPS_ERROR_1(errors, OPS_E_UNIMPLEMENTED, 304 "Verification of signature type 0x%02x not yet implemented\n", content->signature.type); 305 break; 306 307 default: 308 OPS_ERROR_1(errors, OPS_E_UNIMPLEMENTED, 309 "Unexpected signature type 0x%02x\n", content->signature.type); 310 exit(1); 311 } 312 ops_memory_free(mem); 313 314 if(valid) 315 { 316 ++arg->result->valid_count; 317 } 318 else 319 { 320 OPS_ERROR(errors,OPS_E_V_BAD_SIGNATURE,"Bad Signature"); 321 printf(" BAD SIGNATURE\n"); 322 ++arg->result->invalid_count; 323 } 324 break; 325 326 // ignore these 327 case OPS_PARSER_PTAG: 328 case OPS_PTAG_CT_SIGNATURE_HEADER: 329 // case OPS_PTAG_CT_SIGNATURE: 330 break; 331 332 default: 333 fprintf(stderr,"unexpected tag=0x%x\n",content_->tag); 334 assert(0); 335 break; 336 } 337 return OPS_RELEASE_MEMORY; 338 } 339 175 340 static void key_data_destroyer(ops_reader_info_t *rinfo) 176 341 { free(ops_reader_get_arg(rinfo)); } … … 189 354 } 190 355 356 /* 357 * Validate all signatures on a single key against the given keyring 358 */ 191 359 static void validate_key_signatures(ops_validate_result_t *result,const ops_key_data_t *key, 192 360 const ops_keyring_t *keyring) 193 361 { 194 362 ops_parse_info_t *pinfo; 195 validate_ cb_arg_t carg;363 validate_key_cb_arg_t carg; 196 364 197 365 memset(&carg,'\0',sizeof carg); … … 203 371 carg.keyring=keyring; 204 372 205 ops_parse_cb_set(pinfo,validate_ cb,&carg);373 ops_parse_cb_set(pinfo,validate_key_cb,&carg); 206 374 ops_key_data_reader_set(pinfo,key); 207 375 openpgpsdk/trunk/tests/Makefile.template
r517 r521 42 42 43 43 .depend: *.[ch] ../include/openpgpsdk/*.h $(CUNIT_INC) 44 45 44 $(CC) $(CFLAGS) -E -M *.c > .depend 46 45 openpgpsdk/trunk/tests/test_common.c
r517 r521 72 72 close(fd); 73 73 74 snprintf(cmd,MAXBUF,"gpg -- openpgp --quiet --gen-key --s2k-cipher-algo \"AES\" --expert --homedir=%s --batch %s",dir,keydetails);74 snprintf(cmd,MAXBUF,"gpg --quiet --no-tty --openpgp --quiet --gen-key --s2k-cipher-algo \"AES\" --expert --homedir=%s --batch %s",dir,keydetails); 75 75 system(cmd); 76 76 … … 94 94 close(fd); 95 95 96 snprintf(cmd,MAXBUF,"gpg -- openpgp --quiet --gen-key --s2k-cipher-algo \"AES\" --expert --homedir=%s --batch %s",dir,keydetails);96 snprintf(cmd,MAXBUF,"gpg --quiet --no-tty --openpgp --quiet --gen-key --s2k-cipher-algo \"AES\" --expert --homedir=%s --batch %s",dir,keydetails); 97 97 system(cmd); 98 98 … … 184 184 char* create_testtext(const char *text) 185 185 { 186 const unsigned int repeats=1 00;186 const unsigned int repeats=1; 187 187 unsigned int i=0; 188 188 … … 261 261 break; 262 262 263 case OPS_PARSER_PACKET_END: 264 // nothing to do 265 break; 266 263 267 case OPS_PARSER_ERROR: 264 268 printf("parse error: %s\n",content->error.error); … … 386 390 // move definition to better location 387 391 ops_parse_cb_return_t 388 validate_cb(const ops_parser_content_t *content_,ops_parse_cb_info_t *cbinfo); 389 390 ops_parse_cb_return_t 391 callback_signature(const ops_parser_content_t *content_,ops_parse_cb_info_t *cbinfo) 392 validate_key_cb(const ops_parser_content_t *content_,ops_parse_cb_info_t *cbinfo); 393 ops_parse_cb_return_t 394 validate_data_cb(const ops_parser_content_t *content_,ops_parse_cb_info_t *cbinfo); 395 396 ops_parse_cb_return_t 397 callback_data_signature(const ops_parser_content_t *content_,ops_parse_cb_info_t *cbinfo) 392 398 { 393 399 // ops_parser_content_union_t* content=(ops_parser_content_union_t *)&content_->content; … … 399 405 switch(content_->tag) 400 406 { 407 case OPS_PTAG_CT_SIGNED_CLEARTEXT_HEADER: 408 case OPS_PTAG_CT_SIGNED_CLEARTEXT_BODY: 409 case OPS_PTAG_CT_SIGNED_CLEARTEXT_TRAILER: 410 401 411 case OPS_PTAG_CT_ONE_PASS_SIGNATURE: 402 412 case OPS_PTAG_CT_SIGNATURE_HEADER: 403 413 case OPS_PTAG_CT_SIGNATURE_FOOTER: 404 return validate_cb(content_,cbinfo); 414 415 case OPS_PTAG_CT_LITERAL_DATA_HEADER: 416 case OPS_PTAG_CT_LITERAL_DATA_BODY: 417 418 case OPS_PTAG_CT_SIGNATURE: 419 return validate_data_cb(content_,cbinfo); 405 420 break; 406 421 openpgpsdk/trunk/tests/test_crypt_mpi.c
r514 r521 42 42 close(fd); 43 43 44 snprintf(cmd,MAXBUF,"gpg --quiet -- gen-key --expert --homedir=%s--batch %s",dir,keydetails);44 snprintf(cmd,MAXBUF,"gpg --quiet --no-tty --homedir=%s --gen-key --expert --batch %s",dir,keydetails); 45 45 system(cmd); 46 46 openpgpsdk/trunk/tests/test_rsa_decrypt.c
r518 r521 121 121 122 122 // default symmetric algorithm 123 snprintf(cmd,MAXBUF,"gpg -- homedir=%s --force-mdc --compress-level 0 --quiet --encrypt --recipient Alpha %s/%s", dir, dir, filename_rsa_noarmour_nopassphrase);123 snprintf(cmd,MAXBUF,"gpg --quiet --no-tty --homedir=%s --force-mdc --compress-level 0 --quiet --encrypt --recipient Alpha %s/%s", dir, dir, filename_rsa_noarmour_nopassphrase); 124 124 if (system(cmd)) 125 125 { … … 131 131 /* 132 132 // IDEA 133 snprintf(cmd,MAXBUF,"gpg -- homedir=%s --cipher-algo \"IDEA\" --output=%s/IDEA_%s.gpg --force-mdc --compress-level 0 --quiet --encrypt --recipient Alpha %s/%s", dir, dir, filename_rsa_noarmour_nopassphrase, dir, filename_rsa_noarmour_nopassphrase);133 snprintf(cmd,MAXBUF,"gpg --quiet --no-tty --homedir=%s --cipher-algo \"IDEA\" --output=%s/IDEA_%s.gpg --force-mdc --compress-level 0 --quiet --encrypt --recipient Alpha %s/%s", dir, dir, filename_rsa_noarmour_nopassphrase, dir, filename_rsa_noarmour_nopassphrase); 134 134 if (system(cmd)) 135 135 { … … 140 140 141 141 // TripleDES 142 snprintf(cmd,MAXBUF,"gpg -- homedir=%s --cipher-algo \"3DES\" --output=%s/3DES_%s.gpg --force-mdc --compress-level 0 --quiet--encrypt --recipient Alpha %s/%s", dir, dir, filename_rsa_noarmour_nopassphrase, dir, filename_rsa_noarmour_nopassphrase);142 snprintf(cmd,MAXBUF,"gpg --quiet --no-tty --homedir=%s --cipher-algo \"3DES\" --output=%s/3DES_%s.gpg --force-mdc --compress-level 0 --encrypt --recipient Alpha %s/%s", dir, dir, filename_rsa_noarmour_nopassphrase, dir, filename_rsa_noarmour_nopassphrase); 143 143 if (system(cmd)) 144 144 { … … 147 147 148 148 // Cast5 149 snprintf(cmd,MAXBUF,"gpg -- homedir=%s --cipher-algo \"CAST5\" --output=%s/CAST5_%s.gpg --force-mdc --compress-level 0 --quiet--encrypt --recipient Alpha %s/%s", dir, dir, filename_rsa_noarmour_nopassphrase, dir, filename_rsa_noarmour_nopassphrase);149 snprintf(cmd,MAXBUF,"gpg --quiet --no-tty --homedir=%s --cipher-algo \"CAST5\" --output=%s/CAST5_%s.gpg --force-mdc --compress-level 0 --encrypt --recipient Alpha %s/%s", dir, dir, filename_rsa_noarmour_nopassphrase, dir, filename_rsa_noarmour_nopassphrase); 150 150 if (system(cmd)) 151 151 { … … 154 154 155 155 // AES128 156 snprintf(cmd,MAXBUF,"gpg -- homedir=%s --cipher-algo \"AES\" --output=%s/AES128_%s.gpg --force-mdc --compress-level 0 --quiet--encrypt --recipient Alpha %s/%s", dir, dir, filename_rsa_noarmour_nopassphrase, dir, filename_rsa_noarmour_nopassphrase);156 snprintf(cmd,MAXBUF,"gpg --quiet --no-tty --homedir=%s --cipher-algo \"AES\" --output=%s/AES128_%s.gpg --force-mdc --compress-level 0 --encrypt --recipient Alpha %s/%s", dir, dir, filename_rsa_noarmour_nopassphrase, dir, filename_rsa_noarmour_nopassphrase); 157 157 if (system(cmd)) 158 158 { … … 161 161 162 162 // AES256 163 snprintf(cmd,MAXBUF,"gpg -- homedir=%s --cipher-algo \"AES256\" --output=%s/AES256_%s.gpg --force-mdc --compress-level 0 --quiet--encrypt --recipient Alpha %s/%s", dir, dir, filename_rsa_noarmour_nopassphrase, dir, filename_rsa_noarmour_nopassphrase);163 snprintf(cmd,MAXBUF,"gpg --quiet --no-tty --homedir=%s --cipher-algo \"AES256\" --output=%s/AES256_%s.gpg --force-mdc --compress-level 0 --encrypt --recipient Alpha %s/%s", dir, dir, filename_rsa_noarmour_nopassphrase, dir, filename_rsa_noarmour_nopassphrase); 164 164 if (system(cmd)) 165 165 { … … 169 169 170 170 #ifdef TODO 171 snprintf(cmd,MAXBUF,"gpg -- openpgp --quiet--encrypt --personal-cipher-preferences='CAST5' --armor --homedir=%s --recipient Alpha %s/%s", dir, dir, filename_rsa_armour_nopassphrase);172 if (system(cmd)) 173 { 174 return 1; 175 } 176 177 snprintf(cmd,MAXBUF,"gpg -- openpgp --quiet--encrypt --s2k-cipher-algo CAST5 --homedir=%s --recipient Bravo %s/%s", dir, dir, filename_rsa_noarmour_passphrase);178 if (system(cmd)) 179 { 180 return 1; 181 } 182 183 snprintf(cmd,MAXBUF,"gpg -- openpgp --quiet--encrypt --s2k-cipher-algo CAST5 --armor --homedir=%s --recipient Bravo %s/%s", dir, dir, filename_rsa_armour_passphrase);171 snprintf(cmd,MAXBUF,"gpg --quiet --no-tty --openpgp --encrypt --personal-cipher-preferences='CAST5' --armor --homedir=%s --recipient Alpha %s/%s", dir, dir, filename_rsa_armour_nopassphrase); 172 if (system(cmd)) 173 { 174 return 1; 175 } 176 177 snprintf(cmd,MAXBUF,"gpg --quiet --no-tty --openpgp --encrypt --s2k-cipher-algo CAST5 --homedir=%s --recipient Bravo %s/%s", dir, dir, filename_rsa_noarmour_passphrase); 178 if (system(cmd)) 179 { 180 return 1; 181 } 182 183 snprintf(cmd,MAXBUF,"gpg --quiet --no-tty --openpgp --encrypt --s2k-cipher-algo CAST5 --armor --homedir=%s --recipient Bravo %s/%s", dir, dir, filename_rsa_armour_passphrase); 184 184 if (system(cmd)) 185 185 { openpgpsdk/trunk/tests/test_rsa_encrypt.c
r518 r521 267 267 snprintf(pp,MAXBUF," --passphrase %s ", bravo_passphrase); 268 268 snprintf(decrypted_file,MAXBUF,"%s/decrypted_%s",dir,filename); 269 snprintf(cmd,MAXBUF,"gpg -- decrypt --output=%s --quiet--homedir %s %s %s",decrypted_file, dir, pp, encrypted_file);269 snprintf(cmd,MAXBUF,"gpg --quiet --no-tty --decrypt --output=%s --homedir %s %s %s",decrypted_file, dir, pp, encrypted_file); 270 270 // printf("cmd: %s\n", cmd); 271 271 rtn=system(cmd); openpgpsdk/trunk/tests/test_rsa_signature.c
r518 r521 12 12 #include "openpgpsdk/validate.h" 13 13 14 // \todo change this once we know it works 15 #include "../src/advanced/parse_local.h" 16 14 17 #include "tests.h" 15 18 19 static int debug=0; 16 20 static int do_gpgtest=0; 17 21 … … 147 151 int fd=0; 148 152 ops_parse_info_t *pinfo=NULL; 149 validate_ cb_arg_t validate_arg;153 validate_data_cb_arg_t validate_arg; 150 154 ops_validate_result_t result; 151 155 int rtn=0; 156 157 if (debug) 158 { 159 fprintf(stderr,"\n***\n*** Starting to parse for validation\n***\n"); 160 } 152 161 153 162 // open signed file … … 166 175 167 176 pinfo=ops_parse_info_new(); 168 ops_parse_cb_set(pinfo,callback_verify,&validate_arg); 169 ops_reader_set_fd(pinfo,fd); 170 177 171 178 memset(&validate_arg,'\0',sizeof validate_arg); 172 179 validate_arg.result=&result; … … 174 181 validate_arg.rarg=ops_reader_get_arg_from_pinfo(pinfo); 175 182 183 ops_parse_options(pinfo,OPS_PTAG_SS_ALL,OPS_PARSE_PARSED); 184 ops_parse_cb_set(pinfo,callback_verify,&validate_arg); 185 ops_reader_set_fd(pinfo,fd); 186 pinfo->rinfo.accumulate=ops_true; 187 176 188 // Set up armour/passphrase options 177 189 … … 190 202 ops_reader_pop_dearmour(pinfo); 191 203 192 ops_public_key_free(&validate_arg.pkey);193 if (validate_arg.subkey.version)194 ops_public_key_free(&validate_arg.subkey);195 ops_user_id_free(&validate_arg.user_id);196 ops_user_attribute_free(&validate_arg.user_attribute);197 204 ops_parse_info_delete(pinfo); 198 205 … … 203 210 // Check signature with GPG 204 211 205 snprintf(cmd,MAXBUF,"gpg -- verify --quiet --homedir %s %s", dir, signed_file);212 snprintf(cmd,MAXBUF,"gpg --quiet --no-tty --verify --quiet --homedir %s %s", dir, signed_file); 206 213 rtn=system(cmd); 207 214 CU_ASSERT(rtn==0); … … 265 272 return NULL; 266 273 274 #ifdef TBD 267 275 if (NULL == CU_add_test(suite, "Armoured, passphrase", test_rsa_signature_armour_passphrase)) 268 276 return NULL; 269 277 #endif 270 278 271 279 return suite; … … 304 312 callback_verify(const ops_parser_content_t *content_,ops_parse_cb_info_t *cbinfo) 305 313 { 306 // ops_parser_content_union_t* content=(ops_parser_content_union_t *)&content_->content; 307 308 // ops_print_packet(content_); 314 int debug=0; 315 316 if (debug) 317 { ops_print_packet(content_); } 309 318 310 319 switch(content_->tag) 311 { 312 case OPS_PTAG_CT_LITERAL_DATA_HEADER: 320 { 321 case OPS_PTAG_RAW_SS: 322 case OPS_PTAG_SS_CREATION_TIME: 323 case OPS_PTAG_SS_ISSUER_KEY_ID: 324 // \todo should free memory? 325 return OPS_KEEP_MEMORY; 326 327 case OPS_PTAG_CT_ONE_PASS_SIGNATURE: 328 case OPS_PTAG_CT_ARMOUR_HEADER: 329 case OPS_PTAG_CT_ARMOUR_TRAILER: 313 330 break; 314 315 case OPS_PTAG_CT_LITERAL_DATA_BODY: 316 return callback_literal_data(content_,cbinfo); 317 break; 318 319 case OPS_PTAG_CT_ONE_PASS_SIGNATURE: 320 case OPS_PTAG_CT_SIGNATURE: 321 case OPS_PTAG_CT_SIGNED_CLEARTEXT_HEADER: 322 case OPS_PTAG_CT_SIGNED_CLEARTEXT_BODY: 323 case OPS_PTAG_CT_SIGNED_CLEARTEXT_TRAILER: 324 case OPS_PTAG_CT_ARMOUR_HEADER: 325 case OPS_PTAG_CT_ARMOUR_TRAILER: 326 break; 327 331 332 case OPS_PTAG_CT_SIGNATURE: 333 case OPS_PTAG_CT_SIGNED_CLEARTEXT_HEADER: 334 case OPS_PTAG_CT_SIGNED_CLEARTEXT_BODY: 335 case OPS_PTAG_CT_SIGNED_CLEARTEXT_TRAILER: 328 336 case OPS_PTAG_CT_SIGNATURE_HEADER: 329 337 case OPS_PTAG_CT_SIGNATURE_FOOTER: 330 return callback_signature(content_, cbinfo); 331 332 /* 333 case OPS_PTAG_CT_UNARMOURED_TEXT: 334 printf("OPS_PTAG_CT_UNARMOURED_TEXT\n"); 335 if(!skipping) 336 { 337 puts("Skipping..."); 338 skipping=ops_true; 339 } 340 fwrite(content->unarmoured_text.data,1, 341 content->unarmoured_text.length,stdout); 342 break; 343 344 case OPS_PTAG_CT_PK_SESSION_KEY: 345 return callback_pk_session_key(content_,cbinfo); 346 347 case OPS_PARSER_CMD_GET_SECRET_KEY: 348 return callback_cmd_get_secret_key(content_,cbinfo); 349 350 case OPS_PARSER_CMD_GET_SK_PASSPHRASE: 351 return callback_cmd_get_secret_key_passphrase(content_,cbinfo); 352 338 case OPS_PTAG_CT_LITERAL_DATA_HEADER: 353 339 case OPS_PTAG_CT_LITERAL_DATA_BODY: 354 return callback_literal_data(content_,cbinfo); 355 // text=ops_mallocz(content->literal_data_body.length+1); 356 // memcpy(text,content->literal_data_body.data,content->literal_data_body.length); 357 // break; 358 359 case OPS_PARSER_PTAG: 360 case OPS_PTAG_CT_ARMOUR_HEADER: 361 case OPS_PTAG_CT_ARMOUR_TRAILER: 362 case OPS_PTAG_CT_ENCRYPTED_PK_SESSION_KEY: 363 case OPS_PTAG_CT_COMPRESSED: 364 case OPS_PTAG_CT_SE_IP_DATA_BODY: 365 case OPS_PTAG_CT_SE_IP_DATA_HEADER: 366 // Ignore these packets 367 // They're handled in ops_parse_one_packet() 368 // and nothing else needs to be done 369 break; 370 */ 340 return callback_data_signature(content_, cbinfo); 371 341 372 342 default: openpgpsdk/trunk/tests/test_rsa_verify.c
r517 r521 11 11 #include "openpgpsdk/validate.h" 12 12 13 // \todo change this once we know it works 14 #include "../src/advanced/parse_local.h" 15 13 16 #include "tests.h" 14 17 … … 37 40 switch(content_->tag) 38 41 { 42 /* 39 43 case OPS_PTAG_CT_LITERAL_DATA_HEADER: 40 44 break; … … 43 47 return callback_literal_data(content_,cbinfo); 44 48 break; 49 */ 45 50 46 51 case OPS_PTAG_CT_ONE_PASS_SIGNATURE: 52 break; 53 47 54 case OPS_PTAG_CT_SIGNATURE: 48 break;49 50 55 case OPS_PTAG_CT_SIGNATURE_HEADER: 51 56 case OPS_PTAG_CT_SIGNATURE_FOOTER: 52 return callback_signature(content_, cbinfo); 57 case OPS_PTAG_CT_LITERAL_DATA_HEADER: 58 case OPS_PTAG_CT_LITERAL_DATA_BODY: 59 return callback_data_signature(content_, cbinfo); 53 60 54 61 /* … … 116 123 // Now sign the test files with GPG 117 124 118 snprintf(cmd,MAXBUF,"gpg -- homedir=%s --quiet--openpgp --compress-level 0 --sign --local-user %s %s/%s",125 snprintf(cmd,MAXBUF,"gpg --quiet --no-tty --homedir=%s --openpgp --compress-level 0 --sign --local-user %s %s/%s", 119 126 dir, alpha_name, dir, filename_rsa_noarmour_nopassphrase); 120 127 if (system(cmd)) 121 128 { return 1; } 122 129 123 snprintf(cmd,MAXBUF,"gpg -- homedir=%s --quiet--compress-level 0 --sign --armour --local-user %s %s/%s",130 snprintf(cmd,MAXBUF,"gpg --quiet --no-tty --homedir=%s --compress-level 0 --sign --armour --local-user %s %s/%s", 124 131 dir, alpha_name, dir, filename_rsa_armour_nopassphrase); 125 132 if (system(cmd)) 126 133 { return 1; } 127 134 128 snprintf(cmd,MAXBUF,"gpg -- homedir=%s --quiet--compress-level 0 --sign --local-user %s --passphrase %s %s/%s",135 snprintf(cmd,MAXBUF,"gpg --quiet --no-tty --homedir=%s --compress-level 0 --sign --local-user %s --passphrase %s %s/%s", 129 136 dir, bravo_name, bravo_passphrase, dir, filename_rsa_noarmour_passphrase); 130 137 if (system(cmd)) 131 138 { return 1; } 132 139 133 snprintf(cmd,MAXBUF,"gpg -- homedir=%s --quiet--compress-level 0 --sign --armour --local-user %s --passphrase %s %s/%s",140 snprintf(cmd,MAXBUF,"gpg --quiet --no-tty --homedir=%s --compress-level 0 --sign --armour --local-user %s --passphrase %s %s/%s", 134 141 dir, bravo_name, bravo_passphrase, dir, filename_rsa_armour_passphrase); 135 142 if (system(cmd)) … … 156 163 int fd=0; 157 164 ops_parse_info_t *pinfo=NULL; 158 validate_ cb_arg_t validate_arg;165 validate_data_cb_arg_t validate_arg; 159 166 ops_validate_result_t result; 160 167 int rtn=0; … … 179 186 180 187 pinfo=ops_parse_info_new(); 181 ops_parse_cb_set(pinfo,callback,&validate_arg);182 ops_reader_set_fd(pinfo,fd);183 188 184 189 memset(&validate_arg,'\0',sizeof validate_arg); … … 187 192 validate_arg.rarg=ops_reader_get_arg_from_pinfo(pinfo); 188 193 194 ops_parse_cb_set(pinfo,callback,&validate_arg); 195 ops_reader_set_fd(pinfo,fd); 196 pinfo->rinfo.accumulate=ops_true; 197 189 198 // Set up armour/passphrase options 190 199 … … 203 212 ops_reader_pop_dearmour(pinfo); 204 213 205 ops_public_key_free(&validate_arg.pkey);206 if (validate_arg.subkey.version)207 ops_public_key_free(&validate_arg.subkey);208 ops_user_id_free(&validate_arg.user_id);209 ops_user_attribute_free(&validate_arg.user_attribute);210 214 ops_parse_info_delete(pinfo); 211 215 openpgpsdk/trunk/tests/tests.h
r517 r521 28 28 extern CU_pSuite suite_rsa_decrypt(); 29 29 extern CU_pSuite suite_rsa_encrypt(); 30 extern CU_pSuite suite_rsa_encrypt_GPGtest();31 30 extern CU_pSuite suite_rsa_signature(); 32 31 extern CU_pSuite suite_rsa_verify(); 32 33 extern CU_pSuite suite_rsa_decrypt_GPGtest(); 34 extern CU_pSuite suite_rsa_encrypt_GPGtest(); 35 extern CU_pSuite suite_rsa_signature_GPGtest(); 36 extern CU_pSuite suite_rsa_verify_GPGtest(); 33 37 34 38 // utility functions … … 55 59 callback_pk_session_key(const ops_parser_content_t *content_,ops_parse_cb_info_t *cbinfo); 56 60 ops_parse_cb_return_t 57 callback_ signature(const ops_parser_content_t *content_,ops_parse_cb_info_t *cbinfo);61 callback_data_signature(const ops_parser_content_t *content_,ops_parse_cb_info_t *cbinfo); 58 62 59 63 void reset_vars(); openpgpsdk/trunk/tests/tests_gpg.c
r517 r521 30 30 } 31 31 32 #ifdef TODO 33 if (NULL == suite_rsa_decrypt_GPGtest()) 32 if (NULL == suite_rsa_signature_GPGtest()) 34 33 { 35 34 CU_cleanup_registry(); … … 37 36 } 38 37 39 if (NULL == suite_rsa_signature_GPGtest()) 38 #ifdef TODO 39 40 if (NULL == suite_rsa_decrypt_GPGtest()) 40 41 { 41 42 CU_cleanup_registry(); … … 66 67 return CU_get_error(); 67 68 } 68 #endif69 #endif 69 70 70 71 // Run tests
