Changeset 610
- Timestamp:
- 09/01/08 13:31:54
- Files:
-
- openpgpsdk/trunk/include/openpgpsdk/errors.h (modified) (3 diffs)
- openpgpsdk/trunk/include/openpgpsdk/packet-parse.h (modified) (1 diff)
- openpgpsdk/trunk/src/lib/errors.c (modified) (1 diff)
- openpgpsdk/trunk/src/lib/reader_armoured.c (modified) (12 diffs)
- openpgpsdk/trunk/src/lib/validate.c (modified) (1 diff)
- openpgpsdk/trunk/tests/test_rsa_verify.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
openpgpsdk/trunk/include/openpgpsdk/errors.h
r573 r610 30 30 31 31 /** error codes */ 32 // Remember to add names to map in adv_errors.c32 // Remember to add names to map in errors.c 33 33 typedef enum 34 34 { … … 43 43 OPS_E_R_EARLY_EOF =OPS_E_R+2, 44 44 OPS_E_R_BAD_FORMAT =OPS_E_R+3, // For example, malformed armour 45 OPS_E_R_UNCONSUMED_DATA =OPS_E_R+4, 45 OPS_E_R_UNSUPPORTED =OPS_E_R+4, 46 OPS_E_R_UNCONSUMED_DATA =OPS_E_R+5, 46 47 47 48 /* writer errors */ … … 66 67 OPS_E_V=0x5000, /* general validation error */ 67 68 OPS_E_V_BAD_SIGNATURE =OPS_E_V+1, 68 OPS_E_V_UNKNOWN_SIGNER =OPS_E_V+2, 69 OPS_E_V_NO_SIGNATURE =OPS_E_V+2, 70 OPS_E_V_UNKNOWN_SIGNER =OPS_E_V+3, 69 71 70 72 /* Algorithm support errors */ openpgpsdk/trunk/include/openpgpsdk/packet-parse.h
r570 r610 78 78 typedef struct ops_reader_info ops_reader_info_t; 79 79 typedef struct ops_crypt_info ops_crypt_info_t; 80 81 /*82 typedef ops_reader_ret_t ops_reader_t(unsigned char *dest,83 unsigned *plength,84 ops_reader_flags_t flags,85 ops_error_t **errors,86 ops_reader_info_t *rinfo,87 ops_parse_cb_info_t *cbinfo);88 */89 80 90 81 /* openpgpsdk/trunk/src/lib/errors.c
r589 r610 67 67 ERRNAME(OPS_E_V), 68 68 ERRNAME(OPS_E_V_BAD_SIGNATURE), 69 ERRNAME(OPS_E_V_NO_SIGNATURE), 69 70 ERRNAME(OPS_E_V_UNKNOWN_SIGNER), 70 71 openpgpsdk/trunk/src/lib/reader_armoured.c
r609 r610 36 36 #include <openpgpsdk/hash.h> 37 37 #include <openpgpsdk/packet-parse.h> 38 #include "parse_local.h" 38 39 39 40 #include <string.h> … … 42 43 #include <openpgpsdk/final.h> 43 44 44 //static int debug=0;45 static int debug=0; 45 46 46 47 #define CRC24_POLY 0x1864cfbL … … 57 58 AT_TRAILER_NAME, 58 59 } state; 60 61 enum 62 { 63 NONE=0, 64 BEGIN_PGP_MESSAGE, 65 BEGIN_PGP_PUBLIC_KEY_BLOCK, 66 BEGIN_PGP_PRIVATE_KEY_BLOCK, 67 BEGIN_PGP_MULTI, 68 BEGIN_PGP_SIGNATURE, 69 70 END_PGP_MESSAGE, 71 END_PGP_PUBLIC_KEY_BLOCK, 72 END_PGP_PRIVATE_KEY_BLOCK, 73 END_PGP_MULTI, 74 END_PGP_SIGNATURE, 75 76 BEGIN_PGP_SIGNED_MESSAGE 77 } lastseen; 78 59 79 ops_parse_info_t *parse_info; 60 80 ops_boolean_t seen_nl:1; … … 73 93 strictly expect it */ 74 94 95 // it is an error to get a cleartext message without a sig 96 ops_boolean_t expect_sig:1; 97 ops_boolean_t got_sig:1; 98 75 99 // base64 stuff 76 100 unsigned buffered; … … 101 125 } 102 126 127 static void set_lastseen_headerline(dearmour_arg_t* arg, char* buf, ops_error_t **errors) 128 { 129 char* begin_msg="BEGIN PGP MESSAGE"; 130 char* begin_public="BEGIN PGP PUBLIC KEY BLOCK"; 131 char* begin_private="BEGIN PGP PRIVATE KEY BLOCK"; 132 char* begin_multi="BEGIN PGP MESSAGE, PART "; 133 char* begin_sig="BEGIN PGP SIGNATURE"; 134 135 char* end_msg="END PGP MESSAGE"; 136 char* end_public="END PGP PUBLIC KEY BLOCK"; 137 char* end_private="END PGP PRIVATE KEY BLOCK"; 138 char* end_multi="END PGP MESSAGE, PART "; 139 char* end_sig="END PGP SIGNATURE"; 140 141 char* begin_signed_msg="BEGIN PGP SIGNED MESSAGE"; 142 143 int prev=arg->lastseen; 144 145 if (!strncmp(buf,begin_msg,strlen(begin_msg))) 146 arg->lastseen=BEGIN_PGP_MESSAGE; 147 if (!strncmp(buf,begin_public,strlen(begin_public))) 148 arg->lastseen=BEGIN_PGP_PUBLIC_KEY_BLOCK; 149 if (!strncmp(buf,begin_private,strlen(begin_private))) 150 arg->lastseen=BEGIN_PGP_PRIVATE_KEY_BLOCK; 151 if (!strncmp(buf,begin_multi,strlen(begin_multi))) 152 arg->lastseen=BEGIN_PGP_MULTI; 153 if (!strncmp(buf,begin_sig,strlen(begin_sig))) 154 arg->lastseen=BEGIN_PGP_SIGNATURE; 155 156 if (!strncmp(buf,end_msg,strlen(end_msg))) 157 arg->lastseen=END_PGP_MESSAGE; 158 if (!strncmp(buf,end_public,strlen(end_public))) 159 arg->lastseen=END_PGP_PUBLIC_KEY_BLOCK; 160 if (!strncmp(buf,end_private,strlen(end_private))) 161 arg->lastseen=END_PGP_PRIVATE_KEY_BLOCK; 162 if (!strncmp(buf,end_multi,strlen(end_multi))) 163 arg->lastseen=END_PGP_MULTI; 164 if (!strncmp(buf,end_sig,strlen(end_sig))) 165 arg->lastseen=END_PGP_SIGNATURE; 166 167 if (!strncmp(buf,begin_signed_msg,strlen(begin_signed_msg))) 168 arg->lastseen=BEGIN_PGP_SIGNED_MESSAGE; 169 170 if (debug) 171 printf("set header: buf=%s, arg->lastseen=%d, prev=%d\n", buf, arg->lastseen, prev); 172 173 switch (arg->lastseen) 174 { 175 case NONE: 176 OPS_ERROR_1(errors,OPS_E_R_BAD_FORMAT,"Unrecognised Header Line %s", buf); 177 break; 178 179 case END_PGP_MESSAGE: 180 if (prev!=BEGIN_PGP_MESSAGE) 181 OPS_ERROR(errors,OPS_E_R_BAD_FORMAT,"Got END PGP MESSAGE, but not after BEGIN"); 182 break; 183 184 case END_PGP_PUBLIC_KEY_BLOCK: 185 if (prev!=BEGIN_PGP_PUBLIC_KEY_BLOCK) 186 OPS_ERROR(errors,OPS_E_R_BAD_FORMAT,"Got END PGP PUBLIC KEY BLOCK, but not after BEGIN"); 187 break; 188 189 case END_PGP_PRIVATE_KEY_BLOCK: 190 if (prev!=BEGIN_PGP_PRIVATE_KEY_BLOCK) 191 OPS_ERROR(errors,OPS_E_R_BAD_FORMAT,"Got END PGP PRIVATE KEY BLOCK, but not after BEGIN"); 192 break; 193 194 case BEGIN_PGP_MULTI: 195 case END_PGP_MULTI: 196 OPS_ERROR(errors,OPS_E_R_UNSUPPORTED,"Multi-part messages are not yet supported"); 197 break; 198 199 case END_PGP_SIGNATURE: 200 if (prev!=BEGIN_PGP_SIGNATURE) 201 OPS_ERROR(errors,OPS_E_R_BAD_FORMAT,"Got END PGP SIGNATURE, but not after BEGIN"); 202 break; 203 204 case BEGIN_PGP_MESSAGE: 205 case BEGIN_PGP_PUBLIC_KEY_BLOCK: 206 case BEGIN_PGP_PRIVATE_KEY_BLOCK: 207 case BEGIN_PGP_SIGNATURE: 208 case BEGIN_PGP_SIGNED_MESSAGE: 209 break; 210 } 211 } 212 103 213 static int read_char(dearmour_arg_t *arg,ops_error_t **errors, 104 214 ops_reader_info_t *rinfo, … … 308 418 hash->add(hash,(unsigned char *)"\r",1); 309 419 hash->add(hash,body->data,body->length); 420 if (debug) 421 { fprintf(stderr,"Got body:\n%s\n",body->data); } 310 422 CB(cbinfo,OPS_PTAG_CT_SIGNED_CLEARTEXT_BODY,&content); 311 423 body->length=0; … … 316 428 if(body->length == sizeof body->data) 317 429 { 430 if (debug) 431 { fprintf(stderr,"Got body (2):\n%s\n",body->data); } 318 432 CB(cbinfo,OPS_PTAG_CT_SIGNED_CLEARTEXT_BODY,&content); 319 433 body->length=0; … … 685 799 return -1; 686 800 801 set_lastseen_headerline(arg,buf,errors); 802 687 803 if(!strcmp(buf,"BEGIN PGP SIGNED MESSAGE")) 688 804 { 689 805 ops_dup_headers(&content.content.signed_cleartext_header.headers,&arg->headers); 690 806 CB(cbinfo,OPS_PTAG_CT_SIGNED_CLEARTEXT_HEADER,&content); 691 692 807 ret=process_dash_escaped(arg,errors,rinfo,cbinfo); 693 808 if(ret <= 0) … … 754 869 buf[n]='\0'; 755 870 871 set_lastseen_headerline(arg,buf,errors); 872 756 873 /* Consume trailing '-' */ 757 874 for(count=1 ; count < 5 ; ++count) … … 777 894 if(!strncmp(buf,"BEGIN ",6)) 778 895 { 896 set_lastseen_headerline(arg,buf,errors); 779 897 if((ret=parse_headers(arg,errors,rinfo,cbinfo)) <= 0) 780 898 return ret; … … 823 941 arg->allow_trailing_whitespace=trailing_whitespace; 824 942 943 arg->expect_sig=ops_false; 944 arg->got_sig=ops_false; 945 825 946 ops_reader_push(parse_info,armoured_data_reader,armoured_data_destroyer,arg); 826 947 } … … 831 952 void ops_reader_pop_dearmour(ops_parse_info_t *pinfo) 832 953 { 833 // dearmour_arg_t *arg=ops_reader_get_arg(ops_parse_get_rinfo(parse_info));834 //free(arg);954 dearmour_arg_t *arg=ops_reader_get_arg(ops_parse_get_rinfo(pinfo)); 955 free(arg); 835 956 ops_reader_pop(pinfo); 836 957 } openpgpsdk/trunk/src/lib/validate.c
r608 r610 351 351 const ops_keydata_t *signer; 352 352 ops_boolean_t valid=ops_false; 353 // unsigned len=0;354 // unsigned char *data=NULL;355 353 ops_memory_t* mem=NULL; 356 354 openpgpsdk/trunk/tests/test_rsa_verify.c
r608 r610 83 83 "-----BEGIN PGP SIGNED MESSAGE-----\nHash: SHA1\n\nmessage to encrypt\n-----BEGIN PGP SIGNATURE-----\nVersion: GnuPG v1.4.6 (GNU/Linux)\n", 84 84 // no signature 85 "-----BEGIN PGP SIGNED MESSAGE-----\nHash: SHA1\n\nmessage to encrypt\n-----BEGIN PGP SIGNATURE-----\nVersion: -----END PGP SIGNATURE-----GnuPG v1.4.6 (GNU/Linux)\n" 85 "-----BEGIN PGP SIGNED MESSAGE-----\nHash: SHA1\n\nmessage to encrypt\n-----BEGIN PGP SIGNATURE-----\nVersion: -----END PGP SIGNATURE-----GnuPG v1.4.6 (GNU/Linux)\n", 86 // no gap after armour headers in message 87 "-----BEGIN PGP SIGNED MESSAGE-----\nHash: SHA1\nmessage to encrypt\n-----BEGIN PGP SIGNATURE-----\nVersion: GnuPG v1.4.6 (GNU/Linux)\n\niJwEAQECAAYFAkiup4kACgkQr5tWFB2nA4mpVwP8DeeMDFrp7ICHYleyW/UmBIQH\ndXuviEA9WK/BUyHVKxLOyciAw18vm1rKJE9Q30GUrFkPvaOV6XZXZMDBXY/CQixT\nHjKRoFapgbzA5hqDeLjjkJ59hjS5jmsOrdyIebOVrF7YaSRji15uAeeIzBQ0lClZ\nupkvjuuc6o0RoS/+otk=\n=itEi\n-----END PGP SIGNATURE-----\n", 88 // no gap after armour headers in signature 89 "-----BEGIN PGP SIGNED MESSAGE-----\nHash: SHA1\n\nmessage to encrypt\n-----BEGIN PGP SIGNATURE-----\nVersion: GnuPG v1.4.6 (GNU/Linux)\niJwEAQECAAYFAkiup4kACgkQr5tWFB2nA4mpVwP8DeeMDFrp7ICHYleyW/UmBIQH\ndXuviEA9WK/BUyHVKxLOyciAw18vm1rKJE9Q30GUrFkPvaOV6XZXZMDBXY/CQixT\nHjKRoFapgbzA5hqDeLjjkJ59hjS5jmsOrdyIebOVrF7YaSRji15uAeeIzBQ0lClZ\nupkvjuuc6o0RoS/+otk=\n=itEi\n-----END PGP SIGNATURE-----\n", 90 // unsupported hash 91 "-----BEGIN PGP SIGNED MESSAGE-----\nHash: SHA256\n\nmessage to encrypt\n-----BEGIN PGP SIGNATURE-----\nVersion: GnuPG v1.4.6 (GNU/Linux)\n\niJwEAQECAAYFAkiup4kACgkQr5tWFB2nA4mpVwP8DeeMDFrp7ICHYleyW/UmBIQH\ndXuviEA9WK/BUyHVKxLOyciAw18vm1rKJE9Q30GUrFkPvaOV6XZXZMDBXY/CQixT\nHjKRoFapgbzA5hqDeLjjkJ59hjS5jmsOrdyIebOVrF7YaSRji15uAeeIzBQ0lClZ\nupkvjuuc6o0RoS/+otk=\n=itEi\n-----END PGP SIGNATURE-----\n", 92 // missing BEGIN SIG 93 "-----BEGIN PGP SIGNED MESSAGE-----\nHash: SHA1\n\nmessage to encrypt\n-----END PGP SIGNATURE-----", 94 86 95 }; 87 96 num_malformed=sizeof (malformed)/sizeof(char *); … … 296 305 297 306 rtn=ops_parse(pinfo); 307 298 308 299 309 if (debug) … … 351 361 // handle result - should fail 352 362 errstack=ops_parse_info_get_errors(pinfo); 363 353 364 // we are expecting one and only one error 354 365 // print out errors if we have actually got a different error
