Changeset 496
- Timestamp:
- 08/27/07 16:18:35
- Files:
-
- openpgpsdk/trunk/include/openpgpsdk/errors.h (modified) (3 diffs)
- openpgpsdk/trunk/src/advanced/adv_packet-parse.c (modified) (22 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
openpgpsdk/trunk/include/openpgpsdk/errors.h
r495 r496 17 17 /* reader errors */ 18 18 OPS_E_R=0x1000, /* general reader error */ 19 OPS_E_R_READ_FAILED =OPS_E_R+1, 20 OPS_E_R_EARLY_EOF =OPS_E_R+2, 21 OPS_E_R_BAD_FORMAT =OPS_E_R+3, // For example, malformed armour 19 OPS_E_R_READ_FAILED =OPS_E_R+1, 20 OPS_E_R_EARLY_EOF =OPS_E_R+2, 21 OPS_E_R_BAD_FORMAT =OPS_E_R+3, // For example, malformed armour 22 OPS_E_R_UNCONSUMED_DATA =OPS_E_R+4, 22 23 23 24 /* writer errors */ … … 39 40 /* Algorithm support errors */ 40 41 OPS_E_ALG=0x5000, /* general algorithm error */ 41 OPS_E_ALG_UNSUPPORTED_SYMMETRIC =OPS_E_ALG+1, 42 OPS_E_ALG_UNSUPPORTED_SYMMETRIC_ALG =OPS_E_ALG+1, 43 OPS_E_ALG_UNSUPPORTED_PUBLIC_KEY_ALG =OPS_E_ALG+2, 44 OPS_E_ALG_UNSUPPORTED_SIGNATURE_KEY_ALG =OPS_E_ALG+3, 45 OPS_E_ALG_UNSUPPORTED_HASH_ALG =OPS_E_ALG+4, 42 46 43 47 /* Protocol errors */ 44 48 OPS_E_PROTO=0x6000, /* general protocol error */ 45 OPS_E_PROTO_BAD_SYMMETRIC_DECRYPT =OPS_E_PROTO+2, 46 49 OPS_E_PROTO_BAD_SYMMETRIC_DECRYPT =OPS_E_PROTO+2, 50 OPS_E_PROTO_UNKNOWN_SS =OPS_E_PROTO+3, 51 OPS_E_PROTO_CRITICAL_SS_IGNORED =OPS_E_PROTO+4, 52 OPS_E_PROTO_BAD_PUBLIC_KEY_VRSN =OPS_E_PROTO+5, 53 OPS_E_PROTO_BAD_SIGNATURE_VRSN =OPS_E_PROTO+6, 54 OPS_E_PROTO_BAD_ONE_PASS_SIG_VRSN =OPS_E_PROTO+7, 55 OPS_E_PROTO_BAD_PKSK_VRSN =OPS_E_PROTO+8, 56 OPS_E_PROTO_DECRYPTED_MSG_WRONG_LEN =OPS_E_PROTO+9, 57 OPS_E_PROTO_BAD_SK_CHECKSUM =OPS_E_PROTO+10, 47 58 } ops_errcode_t; 48 59 … … 71 82 #define OPS_ERROR(err,code,fmt) do { ops_push_error(err,code,0,__FILE__,__LINE__,fmt); } while(0) 72 83 #define OPS_ERROR_1(err,code,fmt,arg) do { ops_push_error(err,code,0,__FILE__,__LINE__,fmt,arg); } while(0) 84 #define OPS_ERROR_2(err,code,fmt,arg,arg2) do { ops_push_error(err,code,0,__FILE__,__LINE__,fmt,arg,arg2); } while(0) 85 #define OPS_ERROR_3(err,code,fmt,arg,arg2,arg3) do { ops_push_error(err,code,0,__FILE__,__LINE__,fmt,arg,arg2,arg3); } while(0) 86 #define OPS_ERROR_4(err,code,fmt,arg,arg2,arg3,arg4) do { ops_push_error(err,code,0,__FILE__,__LINE__,fmt,arg,arg2,arg3,arg4); } while(0) 73 87 74 88 #endif /* OPS_ERRORS */ openpgpsdk/trunk/src/advanced/adv_packet-parse.c
r495 r496 131 131 /*! macro to save typing */ 132 132 #define C content.content 133 133 134 /*! set error code in content and run CallBack to handle error */ 134 135 #define ERRCODE(cbinfo,err) do { C.errcode.errcode=err; CB(cbinfo,OPS_PARSER_ERRCODE,&content); } while(0) … … 140 141 #define WARN(warn) do { C.error.error=warn; CB(OPS_PARSER_ERROR,&content);; } while(0) 141 142 #define WARNP(info,warn) do { C.error.error=warn; CBP(info,OPS_PARSER_ERROR,&content); } while(0) 143 #ifdef XXX 142 144 /*! \todo descr ERR1 macro */ 143 145 #define ERR1P(info,fmt,x) do { format_error(&content,(fmt),(x)); CBP(info,OPS_PARSER_ERROR,&content); return ops_false; } while(0) 144 146 #define ERR2P(info,fmt,x,y) do { format_error(&content,(fmt),(x),(y)); CBP(info,OPS_PARSER_ERROR,&content); return ops_false; } while(0) 145 147 #define ERR4P(info,fmt,x,y,z,a) do { format_error(&content,(fmt),(x),(y),(z),(a)); CBP(info,OPS_PARSER_ERROR,&content); return ops_false; } while(0) 148 #endif 146 149 147 150 /* XXX: replace ops_ptag_t with something more appropriate for limiting 148 151 reads */ 149 152 153 #ifdef OLD 150 154 /* Note that this makes the parser non-reentrant, in a limited way */ 151 155 /* It is the caller's responsibility to avoid overflow in the buffer */ … … 161 165 content->content.error.error=buf; 162 166 } 167 #endif 163 168 164 169 /** … … 918 923 ops_parse_info_t *pinfo) 919 924 { 920 ops_parser_content_t content;925 // ops_parser_content_t content; 921 926 unsigned char c[1]; 922 927 … … 927 932 key->version=c[0]; 928 933 if(key->version < 2 || key->version > 4) 929 ERR1P(pinfo,"Bad public key version (0x%02x)",key->version); 934 { 935 OPS_ERROR_1(&pinfo->errors,OPS_E_PROTO_BAD_PUBLIC_KEY_VRSN, 936 "Bad public key version (0x%02x)",key->version); 937 return 0; 938 } 930 939 931 940 if(!limited_read_time(&key->creation_time,region,pinfo)) … … 969 978 970 979 default: 971 ERR1P(pinfo,"Unknown public key algorithm (%d)",key->algorithm); 980 OPS_ERROR_1(&pinfo->errors,OPS_E_ALG_UNSUPPORTED_PUBLIC_KEY_ALG,"Unsupported Public Key algorithm (%s)",ops_show_pka(key->algorithm)); 981 return 0; 972 982 } 973 983 … … 999 1009 // XXX: this test should be done for all packets, surely? 1000 1010 if(region->length_read != region->length) 1001 ERR1P(pinfo,"Unconsumed data (%d)", 1002 region->length-region->length_read); 1011 { 1012 OPS_ERROR_1(&pinfo->errors,OPS_E_R_UNCONSUMED_DATA, 1013 "Unconsumed data (%d)", region->length-region->length_read); 1014 return 0; 1015 } 1003 1016 1004 1017 CBP(pinfo,tag,&content); … … 1230 1243 1231 1244 default: 1232 ERR1P(pinfo,"Bad signature key algorithm (%d)",C.signature.key_algorithm); 1245 OPS_ERROR_1(&pinfo->errors,OPS_E_ALG_UNSUPPORTED_SIGNATURE_KEY_ALG, 1246 "Unsupported signature key algorithm (%s)", 1247 ops_show_pka(C.signature.key_algorithm)); 1248 return 0; 1233 1249 } 1234 1250 1235 1251 if(region->length_read != region->length) 1236 ERR1P(pinfo,"Unconsumed data (%d)",region->length-region->length_read); 1252 { 1253 OPS_ERROR_1(&pinfo->errors,OPS_E_R_UNCONSUMED_DATA,"Unconsumed data (%d)",region->length-region->length_read); 1254 return 0; 1255 } 1237 1256 1238 1257 if(C.signature.signer_id_set) … … 1459 1478 default: 1460 1479 if(pinfo->ss_parsed[t8]&t7) 1461 ERR1P(pinfo,"Unknown signature subpacket type (%d)",1462 c[0]&0x7f);1480 OPS_ERROR_1(&pinfo->errors, OPS_E_PROTO_UNKNOWN_SS, 1481 "Unknown signature subpacket type (%d)", c[0]&0x7f); 1463 1482 read=ops_false; 1464 1483 break; … … 1469 1488 { 1470 1489 if(content.critical) 1471 ERR1P(pinfo,"Critical signature subpacket ignored (%d)", 1472 c[0]&0x7f); 1490 OPS_ERROR_1(&pinfo->errors,OPS_E_PROTO_CRITICAL_SS_IGNORED, 1491 "Critical signature subpacket ignored (%d)", 1492 c[0]&0x7f); 1473 1493 if(!read && !limited_skip(subregion.length-1,&subregion,pinfo)) 1474 1494 return 0; … … 1480 1500 1481 1501 if(read && subregion.length_read != subregion.length) 1482 ERR1P(pinfo,"Unconsumed data (%d)", subregion.length-subregion.length_read); 1502 { 1503 OPS_ERROR_1(&pinfo->errors,OPS_E_R_UNCONSUMED_DATA, 1504 "Unconsumed data (%d)", 1505 subregion.length-subregion.length_read); 1506 return 0; 1507 } 1483 1508 1484 1509 CBP(pinfo,content.tag,&content); … … 1654 1679 1655 1680 default: 1656 ERR1P(pinfo,"Bad v4 signature key algorithm (%d)", 1657 C.signature.key_algorithm); 1681 OPS_ERROR_1(&pinfo->errors,OPS_E_ALG_UNSUPPORTED_SIGNATURE_KEY_ALG, 1682 "Bad v4 signature key algorithm (%s)", 1683 ops_show_pka(C.signature.key_algorithm)); 1684 return 0; 1658 1685 } 1659 1686 1660 1687 if(region->length_read != region->length) 1661 ERR1P(pinfo,"Unconsumed data (%d)", 1662 region->length-region->length_read); 1688 { 1689 OPS_ERROR_1(&pinfo->errors,OPS_E_R_UNCONSUMED_DATA, 1690 "Unconsumed data (%d)", 1691 region->length-region->length_read); 1692 return 0; 1693 } 1663 1694 1664 1695 CBP(pinfo,OPS_PTAG_CT_SIGNATURE_FOOTER,&content); … … 1696 1727 else if(c[0] == 4) 1697 1728 return parse_v4_signature(region,pinfo,v4_hashed_data_start); 1698 ERR1P(pinfo,"Bad signature version (%d)",c[0]); 1729 1730 OPS_ERROR_1(&pinfo->errors,OPS_E_PROTO_BAD_SIGNATURE_VRSN, 1731 "Bad signature version (%d)",c[0]); 1732 return 0; 1699 1733 } 1700 1734 … … 1725 1759 return 0; 1726 1760 if(C.one_pass_signature.version != 3) 1727 ERR1P(pinfo,"Bad one-pass signature version (%d)", 1728 C.one_pass_signature.version); 1761 { 1762 OPS_ERROR_1(&pinfo->errors,OPS_E_PROTO_BAD_ONE_PASS_SIG_VRSN, 1763 "Bad one-pass signature version (%d)", 1764 C.one_pass_signature.version); 1765 return 0; 1766 } 1729 1767 1730 1768 if(!limited_read(c,1,region,pinfo)) … … 2190 2228 C.pk_session_key.version=c[0]; 2191 2229 if(C.pk_session_key.version != OPS_PKSK_V3) 2192 ERR1P(pinfo, 2230 { 2231 OPS_ERROR_1(&pinfo->errors, OPS_E_PROTO_BAD_PKSK_VRSN, 2193 2232 "Bad public-key encrypted session key version (%d)", 2194 2233 C.pk_session_key.version); 2234 return 0; 2235 } 2195 2236 2196 2237 if(!limited_read(C.pk_session_key.key_id, … … 2229 2270 2230 2271 default: 2231 ERR1P(pinfo,2232 "Unknown public key algorithm in session key (%d)",2233 C.pk_session_key.algorithm);2272 OPS_ERROR_1(&pinfo->errors, OPS_E_ALG_UNSUPPORTED_PUBLIC_KEY_ALG, 2273 "Unknown public key algorithm in session key (%s)", 2274 ops_show_pka(C.pk_session_key.algorithm)); 2234 2275 return 0; 2235 2276 } … … 2264 2305 { 2265 2306 // ERR1P 2266 OPS_ERROR_1(&pinfo->errors,OPS_E_ALG_UNSUPPORTED_SYMMETRIC,"Symmetric algorithm %s not supported", ops_show_symmetric_algorithm(C.pk_session_key.symmetric_algorithm)); 2307 OPS_ERROR_1(&pinfo->errors,OPS_E_ALG_UNSUPPORTED_SYMMETRIC_ALG, 2308 "Symmetric algorithm %s not supported", 2309 ops_show_symmetric_algorithm(C.pk_session_key.symmetric_algorithm)); 2267 2310 return 0; 2268 2311 } … … 2282 2325 if((unsigned)n != k+3) 2283 2326 { 2284 ERR2P(pinfo,"decrypted message wrong length (got %d expected %d)", 2285 n,k+3); 2327 OPS_ERROR_2(&pinfo->errors,OPS_E_PROTO_DECRYPTED_MSG_WRONG_LEN, 2328 "decrypted message wrong length (got %d expected %d)", 2329 n,k+3); 2286 2330 return 0; 2287 2331 } … … 2308 2352 if (unencoded_m_buf[k+1]!=cs[0] || unencoded_m_buf[k+2]!=cs[1]) 2309 2353 { 2310 ERR4P(pinfo, "Session key checksum wrong: expected %2x %2x, got %2x %2x", 2354 OPS_ERROR_4(&pinfo->errors, OPS_E_PROTO_BAD_SK_CHECKSUM, 2355 "Session key checksum wrong: expected %2x %2x, got %2x %2x", 2311 2356 cs[0], cs[1], unencoded_m_buf[k+1], unencoded_m_buf[k+2]); 2312 2357 return 0; … … 2463 2508 unsigned char buf[OPS_MAX_BLOCK_SIZE+2]; 2464 2509 size_t b=decrypt->blocksize; 2465 ops_parser_content_t content;2510 // ops_parser_content_t content; 2466 2511 ops_region_t encregion; 2467 2512 … … 2478 2523 { 2479 2524 ops_reader_pop_decrypt(pinfo); 2480 ERR4P(pinfo,"Bad symmetric decrypt (%02x%02x vs %02x%02x)", 2481 buf[b-2],buf[b-1],buf[b],buf[b+1]); 2525 OPS_ERROR_4(&pinfo->errors, OPS_E_PROTO_BAD_SYMMETRIC_DECRYPT, 2526 "Bad symmetric decrypt (%02x%02x vs %02x%02x)", 2527 buf[b-2],buf[b-1],buf[b],buf[b+1]); 2528 return 0; 2482 2529 } 2483 2530 … … 2734 2781 2735 2782 default: 2736 ERR1P(pinfo,"Unknown content tag 0x%x", C.ptag.content_tag); 2783 OPS_ERROR_1(&pinfo->errors,OPS_E_P_UNKNOWN_TAG, 2784 "Unknown content tag 0x%x", C.ptag.content_tag); 2737 2785 r=0; 2738 2786 }
