Changeset 385
- Timestamp:
- 02/22/06 17:15:37
- Files:
-
- openpgpsdk/trunk/src/packet-parse.c (modified) (111 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
openpgpsdk/trunk/src/packet-parse.c
r384 r385 26 26 * \param len Number of octets to read 27 27 * \param subregion 28 * \param p arse_info How to parse28 * \param pinfo How to parse 29 29 * 30 30 * \return 1 on success, 0 on failure 31 31 */ 32 32 static int limited_read_data(ops_data_t *data,unsigned int len, 33 ops_region_t *subregion,ops_parse_info_t *p arse_info)33 ops_region_t *subregion,ops_parse_info_t *pinfo) 34 34 { 35 35 data->len = len; … … 41 41 return 0; 42 42 43 if (!ops_limited_read(data->contents, data->len,subregion, 44 &parse_info->errors,&parse_info->rinfo, 45 &parse_info->cbinfo)) 43 if (!ops_limited_read(data->contents, data->len,subregion,&pinfo->errors, 44 &pinfo->rinfo,&pinfo->cbinfo)) 46 45 return 0; 47 46 … … 55 54 * \param data 56 55 * \param subregion 57 * \param p arse_info56 * \param pinfo 58 57 * 59 58 * \return 1 on success, 0 on failure 60 59 */ 61 60 static int read_data(ops_data_t *data,ops_region_t *subregion, 62 ops_parse_info_t *p arse_info)61 ops_parse_info_t *pinfo) 63 62 { 64 63 int len; … … 66 65 len=subregion->length-subregion->length_read; 67 66 68 return(limited_read_data(data,len,subregion,p arse_info));67 return(limited_read_data(data,len,subregion,pinfo)); 69 68 } 70 69 … … 96 95 } 97 96 98 static int read_string(char **str, ops_region_t *subregion, ops_parse_info_t *p arse_info)99 { 100 return (read_unsigned_string((unsigned char **)str, subregion, p arse_info));97 static int read_string(char **str, ops_region_t *subregion, ops_parse_info_t *pinfo) 98 { 99 return (read_unsigned_string((unsigned char **)str, subregion, pinfo)); 101 100 } 102 101 … … 149 148 * Use this function, rather than calling the reader directly. 150 149 * 151 * If the accumulate flag is set in *p arse_info, the function150 * If the accumulate flag is set in *pinfo, the function 152 151 * adds the read data to the accumulated data, and updates 153 152 * the accumulated length. This is useful if, for example, … … 158 157 * \param *plength 159 158 * \param flags 160 * \param *p arse_info159 * \param *pinfo 161 160 * 162 161 * \return OPS_R_OK … … 207 206 static ops_reader_ret_t base_read(unsigned char *dest,unsigned *plength, 208 207 ops_reader_flags_t flags, 209 ops_parse_info_t * info)210 { 211 return sub_base_read(dest,plength,flags,& info->errors,&info->rinfo,212 & info->cbinfo);208 ops_parse_info_t *pinfo) 209 { 210 return sub_base_read(dest,plength,flags,&pinfo->errors,&pinfo->rinfo, 211 &pinfo->cbinfo); 213 212 } 214 213 … … 227 226 */ 228 227 static ops_reader_ret_t read_scalar(unsigned *result,unsigned length, 229 ops_parse_info_t *p arse_info)228 ops_parse_info_t *pinfo) 230 229 { 231 230 unsigned t=0; … … 239 238 unsigned one=1; 240 239 241 ret=base_read(c,&one,0,p arse_info);240 ret=base_read(c,&one,0,pinfo); 242 241 if(ret != OPS_R_OK) 243 242 return ret; … … 262 261 * \param length How many bytes to read 263 262 * \param *region Pointer to packet region 264 * \param *p arse_info How to parse, including callback function263 * \param *pinfo How to parse, including callback function 265 264 * \return 1 on success, 0 on error 266 265 */ … … 322 321 * \param length How many bytes to skip 323 322 * \param *region Pointer to packet region 324 * \param *p arse_info How to parse323 * \param *pinfo How to parse 325 324 * \return 1 on success, 0 on error (calls the cb with OPS_PARSER_ERROR in limited_read()). 326 325 */ 327 326 static int limited_skip(unsigned length,ops_region_t *region, 328 ops_parse_info_t *p arse_info)327 ops_parse_info_t *pinfo) 329 328 { 330 329 unsigned char buf[8192]; … … 333 332 { 334 333 int n=length%8192; 335 if(!limited_read(buf,n,region,p arse_info))334 if(!limited_read(buf,n,region,pinfo)) 336 335 return 0; 337 336 length-=n; … … 350 349 * \param length How many bytes make up this scalar (at most 4) 351 350 * \param *region Pointer to current packet region 352 * \param *p arse_info How to parse351 * \param *pinfo How to parse 353 352 * \param *cb The callback 354 353 * \return 1 on success, 0 on error (calls the cb with OPS_PARSER_ERROR in limited_read()). … … 358 357 static int limited_read_scalar(unsigned *dest,unsigned length, 359 358 ops_region_t *region, 360 ops_parse_info_t *p arse_info)359 ops_parse_info_t *pinfo) 361 360 { 362 361 unsigned char c[4]; … … 366 365 assert(length <= 4); 367 366 assert(sizeof(*dest) >= 4); 368 if(!limited_read(c,length,region,p arse_info))367 if(!limited_read(c,length,region,pinfo)) 369 368 return 0; 370 369 … … 389 388 * \param length How many bytes make up this scalar (at most 4) 390 389 * \param *region Pointer to current packet region 391 * \param *p arse_info How to parse390 * \param *pinfo How to parse 392 391 * \param *cb The callback 393 392 * \return 1 on success, 0 on error (calls the cb with OPS_PARSER_ERROR in limited_read()). … … 397 396 static int limited_read_size_t_scalar(size_t *dest,unsigned length, 398 397 ops_region_t *region, 399 ops_parse_info_t *p arse_info)398 ops_parse_info_t *pinfo) 400 399 { 401 400 unsigned tmp; … … 405 404 /* Note that because the scalar is at most 4 bytes, we don't care 406 405 if size_t is bigger than usigned */ 407 if(!limited_read_scalar(&tmp,length,region,p arse_info))406 if(!limited_read_scalar(&tmp,length,region,pinfo)) 408 407 return 0; 409 408 … … 430 429 */ 431 430 static int limited_read_time(time_t *dest,ops_region_t *region, 432 ops_parse_info_t *p arse_info)433 { 434 return limited_read_scalar((unsigned *)dest,4,region,p arse_info);431 ops_parse_info_t *pinfo) 432 { 433 return limited_read_scalar((unsigned *)dest,4,region,pinfo); 435 434 } 436 435 … … 458 457 */ 459 458 static int limited_read_mpi(BIGNUM **pbn,ops_region_t *region, 460 ops_parse_info_t *p arse_info)459 ops_parse_info_t *pinfo) 461 460 { 462 461 unsigned length; … … 468 467 ops_boolean_t ret; 469 468 470 p arse_info->reading_mpi_length=ops_true;471 ret=limited_read_scalar(&length,2,region,p arse_info);472 p arse_info->reading_mpi_length=ops_false;469 pinfo->reading_mpi_length=ops_true; 470 ret=limited_read_scalar(&length,2,region,pinfo); 471 pinfo->reading_mpi_length=ops_false; 473 472 if(!ret) 474 473 return 0; … … 480 479 481 480 assert(length <= 8192); 482 if(!limited_read(buf,length,region,p arse_info))481 if(!limited_read(buf,length,region,pinfo)) 483 482 return 0; 484 483 485 484 if((buf[0] >> nonzero) != 0 || !(buf[0]&(1 << (nonzero-1)))) 486 485 { 487 ERRCODEP(p arse_info,OPS_E_P_MPI_FORMAT_ERROR); /* XXX: Ben, one part of this constraint does not apply to encrypted MPIs the draft says. -- peter */486 ERRCODEP(pinfo,OPS_E_P_MPI_FORMAT_ERROR); /* XXX: Ben, one part of this constraint does not apply to encrypted MPIs the draft says. -- peter */ 488 487 return 0; 489 488 } … … 498 497 * 499 498 * \param *length Where the decoded length will be put 500 * \param *p arse_info How to parse499 * \param *pinfo How to parse 501 500 * \return 1 if OK, else 0 502 501 * 503 502 */ 504 503 505 static int read_new_length(unsigned *length,ops_parse_info_t *p arse_info)504 static int read_new_length(unsigned *length,ops_parse_info_t *pinfo) 506 505 { 507 506 unsigned char c[1]; 508 507 unsigned one=1; 509 508 510 if(base_read(c,&one,0,p arse_info) != OPS_R_OK)509 if(base_read(c,&one,0,pinfo) != OPS_R_OK) 511 510 return 0; 512 511 if(c[0] < 192) … … 519 518 unsigned t=(c[0]-192) << 8; 520 519 521 if(base_read(c,&one,0,p arse_info) != OPS_R_OK)520 if(base_read(c,&one,0,pinfo) != OPS_R_OK) 522 521 return 0; 523 522 *length=t+c[0]+192; 524 523 return 1; 525 524 } 526 return (read_scalar(length,4,p arse_info) == OPS_R_OK ? 1 : 0);525 return (read_scalar(length,4,pinfo) == OPS_R_OK ? 1 : 0); 527 526 } 528 527 … … 545 544 */ 546 545 static int limited_read_new_length(unsigned *length,ops_region_t *region, 547 ops_parse_info_t *p arse_info)546 ops_parse_info_t *pinfo) 548 547 { 549 548 unsigned char c[1]; 550 549 551 if(!limited_read(c,1,region,p arse_info))550 if(!limited_read(c,1,region,pinfo)) 552 551 return 0; 553 552 if(c[0] < 192) … … 560 559 unsigned t=(c[0]-192) << 8; 561 560 562 if(!limited_read(c,1,region,p arse_info))561 if(!limited_read(c,1,region,pinfo)) 563 562 return 0; 564 563 *length=t+c[0]+192; 565 564 return 1; 566 565 } 567 return limited_read_scalar(length,4,region,p arse_info);566 return limited_read_scalar(length,4,region,pinfo); 568 567 } 569 568 … … 824 823 825 824 static int parse_public_key_data(ops_public_key_t *key,ops_region_t *region, 826 ops_parse_info_t *p arse_info)825 ops_parse_info_t *pinfo) 827 826 { 828 827 ops_parser_content_t content; … … 831 830 assert (region->length_read == 0); /* We should not have read anything so far */ 832 831 833 if(!limited_read(c,1,region,p arse_info))832 if(!limited_read(c,1,region,pinfo)) 834 833 return 0; 835 834 key->version=c[0]; 836 835 if(key->version < 2 || key->version > 4) 837 ERR1P(p arse_info,"Bad public key version (0x%02x)",key->version);838 839 if(!limited_read_time(&key->creation_time,region,p arse_info))836 ERR1P(pinfo,"Bad public key version (0x%02x)",key->version); 837 838 if(!limited_read_time(&key->creation_time,region,pinfo)) 840 839 return 0; 841 840 842 841 key->days_valid=0; 843 842 if((key->version == 2 || key->version == 3) 844 && !limited_read_scalar(&key->days_valid,2,region,p arse_info))845 return 0; 846 847 if(!limited_read(c,1,region,p arse_info))843 && !limited_read_scalar(&key->days_valid,2,region,pinfo)) 844 return 0; 845 846 if(!limited_read(c,1,region,pinfo)) 848 847 return 0; 849 848 … … 853 852 { 854 853 case OPS_PKA_DSA: 855 if(!limited_read_mpi(&key->key.dsa.p,region,p arse_info)856 || !limited_read_mpi(&key->key.dsa.q,region,p arse_info)857 || !limited_read_mpi(&key->key.dsa.g,region,p arse_info)858 || !limited_read_mpi(&key->key.dsa.y,region,p arse_info))854 if(!limited_read_mpi(&key->key.dsa.p,region,pinfo) 855 || !limited_read_mpi(&key->key.dsa.q,region,pinfo) 856 || !limited_read_mpi(&key->key.dsa.g,region,pinfo) 857 || !limited_read_mpi(&key->key.dsa.y,region,pinfo)) 859 858 return 0; 860 859 break; … … 863 862 case OPS_PKA_RSA_ENCRYPT_ONLY: 864 863 case OPS_PKA_RSA_SIGN_ONLY: 865 if(!limited_read_mpi(&key->key.rsa.n,region,p arse_info)866 || !limited_read_mpi(&key->key.rsa.e,region,p arse_info))864 if(!limited_read_mpi(&key->key.rsa.n,region,pinfo) 865 || !limited_read_mpi(&key->key.rsa.e,region,pinfo)) 867 866 return 0; 868 867 break; … … 870 869 case OPS_PKA_ELGAMAL: 871 870 case OPS_PKA_ELGAMAL_ENCRYPT_OR_SIGN: 872 if(!limited_read_mpi(&key->key.elgamal.p,region,p arse_info)873 || !limited_read_mpi(&key->key.elgamal.g,region,p arse_info)874 || !limited_read_mpi(&key->key.elgamal.y,region,p arse_info))871 if(!limited_read_mpi(&key->key.elgamal.p,region,pinfo) 872 || !limited_read_mpi(&key->key.elgamal.g,region,pinfo) 873 || !limited_read_mpi(&key->key.elgamal.y,region,pinfo)) 875 874 return 0; 876 875 break; 877 876 878 877 default: 879 ERR1P(p arse_info,"Unknown public key algorithm (%d)",key->algorithm);878 ERR1P(pinfo,"Unknown public key algorithm (%d)",key->algorithm); 880 879 } 881 880 … … 898 897 */ 899 898 static int parse_public_key(ops_content_tag_t tag,ops_region_t *region, 900 ops_parse_info_t *p arse_info)899 ops_parse_info_t *pinfo) 901 900 { 902 901 ops_parser_content_t content; 903 902 904 if(!parse_public_key_data(&C.public_key,region,p arse_info))903 if(!parse_public_key_data(&C.public_key,region,pinfo)) 905 904 return 0; 906 905 907 906 // XXX: this test should be done for all packets, surely? 908 907 if(region->length_read != region->length) 909 ERR1P(p arse_info,"Unconsumed data (%d)",908 ERR1P(pinfo,"Unconsumed data (%d)", 910 909 region->length-region->length_read); 911 910 912 CBP(p arse_info,tag,&content);911 CBP(pinfo,tag,&content); 913 912 914 913 return 1; … … 946 945 */ 947 946 948 static int parse_user_attribute(ops_region_t *region, ops_parse_info_t *p arse_info)947 static int parse_user_attribute(ops_region_t *region, ops_parse_info_t *pinfo) 949 948 { 950 949 … … 956 955 assert(region->length_read == 0); /* We should not have read anything so far */ 957 956 958 if(!read_data(&C.user_attribute.data,region,p arse_info))959 return 0; 960 961 CBP(p arse_info,OPS_PTAG_CT_USER_ATTRIBUTE,&content);957 if(!read_data(&C.user_attribute.data,region,pinfo)) 958 return 0; 959 960 CBP(pinfo,OPS_PTAG_CT_USER_ATTRIBUTE,&content); 962 961 963 962 return 1; … … 988 987 * \see RFC2440bis-12 5.11 989 988 */ 990 static int parse_user_id(ops_region_t *region,ops_parse_info_t *p arse_info)989 static int parse_user_id(ops_region_t *region,ops_parse_info_t *pinfo) 991 990 { 992 991 ops_parser_content_t content; … … 997 996 998 997 if(region->length && !limited_read(C.user_id.user_id,region->length,region, 999 p arse_info))998 pinfo)) 1000 999 return 0; 1001 1000 1002 1001 C.user_id.user_id[region->length]='\0'; /* terminate the string */ 1003 1002 1004 CBP(p arse_info,OPS_PTAG_CT_USER_ID,&content);1003 CBP(pinfo,OPS_PTAG_CT_USER_ID,&content); 1005 1004 1006 1005 return 1; … … 1078 1077 */ 1079 1078 static int parse_v3_signature(ops_region_t *region, 1080 ops_parse_info_t *p arse_info)1079 ops_parse_info_t *pinfo) 1081 1080 { 1082 1081 unsigned char c[1]; … … 1086 1085 1087 1086 /* hash info length */ 1088 if(!limited_read(c,1,region,p arse_info))1087 if(!limited_read(c,1,region,pinfo)) 1089 1088 return 0; 1090 1089 if(c[0] != 5) 1091 ERRP(p arse_info,"bad hash info length");1092 1093 if(!limited_read(c,1,region,p arse_info))1090 ERRP(pinfo,"bad hash info length"); 1091 1092 if(!limited_read(c,1,region,pinfo)) 1094 1093 return 0; 1095 1094 C.signature.type=c[0]; 1096 1095 /* XXX: check signature type */ 1097 1096 1098 if(!limited_read_time(&C.signature.creation_time,region,p arse_info))1097 if(!limited_read_time(&C.signature.creation_time,region,pinfo)) 1099 1098 return 0; 1100 1099 C.signature.creation_time_set=ops_true; 1101 1100 1102 if(!limited_read(C.signature.signer_id,OPS_KEY_ID_SIZE,region,p arse_info))1101 if(!limited_read(C.signature.signer_id,OPS_KEY_ID_SIZE,region,pinfo)) 1103 1102 return 0; 1104 1103 C.signature.signer_id_set=ops_true; 1105 1104 1106 if(!limited_read(c,1,region,p arse_info))1105 if(!limited_read(c,1,region,pinfo)) 1107 1106 return 0; 1108 1107 C.signature.key_algorithm=c[0]; 1109 1108 /* XXX: check algorithm */ 1110 1109 1111 if(!limited_read(c,1,region,p arse_info))1110 if(!limited_read(c,1,region,pinfo)) 1112 1111 return 0; 1113 1112 C.signature.hash_algorithm=c[0]; 1114 1113 /* XXX: check algorithm */ 1115 1114 1116 if(!limited_read(C.signature.hash2,2,region,p arse_info))1115 if(!limited_read(C.signature.hash2,2,region,pinfo)) 1117 1116 return 0; 1118 1117 … … 1121 1120 case OPS_PKA_RSA: 1122 1121 case OPS_PKA_RSA_SIGN_ONLY: 1123 if(!limited_read_mpi(&C.signature.signature.rsa.sig,region,p arse_info))1122 if(!limited_read_mpi(&C.signature.signature.rsa.sig,region,pinfo)) 1124 1123 return 0; 1125 1124 break; 1126 1125 1127 1126 case OPS_PKA_DSA: 1128 if(!limited_read_mpi(&C.signature.signature.dsa.r,region,p arse_info)1129 || !limited_read_mpi(&C.signature.signature.dsa.s,region,p arse_info))1127 if(!limited_read_mpi(&C.signature.signature.dsa.r,region,pinfo) 1128 || !limited_read_mpi(&C.signature.signature.dsa.s,region,pinfo)) 1130 1129 return 0; 1131 1130 break; 1132 1131 1133 1132 case OPS_PKA_ELGAMAL_ENCRYPT_OR_SIGN: 1134 if(!limited_read_mpi(&C.signature.signature.elgamal.r,region,p arse_info)1135 || !limited_read_mpi(&C.signature.signature.elgamal.s,region,p arse_info))1133 if(!limited_read_mpi(&C.signature.signature.elgamal.r,region,pinfo) 1134 || !limited_read_mpi(&C.signature.signature.elgamal.s,region,pinfo)) 1136 1135 return 0; 1137 1136 break; 1138 1137 1139 1138 default: 1140 ERR1P(p arse_info,"Bad signature key algorithm (%d)",C.signature.key_algorithm);1139 ERR1P(pinfo,"Bad signature key algorithm (%d)",C.signature.key_algorithm); 1141 1140 } 1142 1141 1143 1142 if(region->length_read != region->length) 1144 ERR1P(p arse_info,"Unconsumed data (%d)",region->length-region->length_read);1145 1146 CBP(p arse_info,OPS_PTAG_CT_SIGNATURE,&content);1143 ERR1P(pinfo,"Unconsumed data (%d)",region->length-region->length_read); 1144 1145 CBP(pinfo,OPS_PTAG_CT_SIGNATURE,&content); 1147 1146 1148 1147 return 1; … … 1167 1166 static int parse_one_signature_subpacket(ops_signature_t *sig, 1168 1167 ops_region_t *region, 1169 ops_parse_info_t *p arse_info)1168 ops_parse_info_t *pinfo) 1170 1169 { 1171 1170 ops_region_t subregion; … … 1177 1176 1178 1177 ops_init_subregion(&subregion,region); 1179 if(!limited_read_new_length(&subregion.length,region,p arse_info))1178 if(!limited_read_new_length(&subregion.length,region,pinfo)) 1180 1179 return 0; 1181 1180 1182 1181 if(subregion.length > region->length) 1183 ERRP(p arse_info,"Subpacket too long");1184 1185 if(!limited_read(c,1,&subregion,p arse_info))1182 ERRP(pinfo,"Subpacket too long"); 1183 1184 if(!limited_read(c,1,&subregion,pinfo)) 1186 1185 return 0; 1187 1186 … … 1193 1192 1194 1193 /* Application wants it delivered raw */ 1195 if(p arse_info->ss_raw[t8]&t7)1194 if(pinfo->ss_raw[t8]&t7) 1196 1195 { 1197 1196 C.ss_raw.tag=content.tag; 1198 1197 C.ss_raw.length=subregion.length-1; 1199 1198 C.ss_raw.raw=malloc(C.ss_raw.length); 1200 if(!limited_read(C.ss_raw.raw,C.ss_raw.length,&subregion,p arse_info))1201 return 0; 1202 CBP(p arse_info,OPS_PTAG_RAW_SS,&content);1199 if(!limited_read(C.ss_raw.raw,C.ss_raw.length,&subregion,pinfo)) 1200 return 0; 1201 CBP(pinfo,OPS_PTAG_RAW_SS,&content); 1203 1202 return 1; 1204 1203 } … … 1209 1208 case OPS_PTAG_SS_EXPIRATION_TIME: 1210 1209 case OPS_PTAG_SS_KEY_EXPIRATION_TIME: 1211 if(!limited_read_time(&C.ss_time.time,&subregion,p arse_info))1210 if(!limited_read_time(&C.ss_time.time,&subregion,pinfo)) 1212 1211 return 0; 1213 1212 if(content.tag == OPS_PTAG_SS_CREATION_TIME) … … 1219 1218 1220 1219 case OPS_PTAG_SS_TRUST: 1221 if(!limited_read(&C.ss_trust.level,1,&subregion,p arse_info)1222 || !limited_read(&C.ss_trust.amount,1,&subregion,p arse_info))1220 if(!limited_read(&C.ss_trust.level,1,&subregion,pinfo) 1221 || !limited_read(&C.ss_trust.amount,1,&subregion,pinfo)) 1223 1222 return 0; 1224 1223 break; 1225 1224 1226 1225 case OPS_PTAG_SS_REVOCABLE: 1227 if(!limited_read(bool,1,&subregion,p arse_info))1226 if(!limited_read(bool,1,&subregion,pinfo)) 1228 1227 return 0; 1229 1228 C.ss_revocable.revocable=!!bool; … … 1232 1231 case OPS_PTAG_SS_ISSUER_KEY_ID: 1233 1232 if(!limited_read(C.ss_issuer_key_id.key_id,OPS_KEY_ID_SIZE, 1234 &subregion,p arse_info))1233 &subregion,pinfo)) 1235 1234 return 0; 1236 1235 memcpy(sig->signer_id,C.ss_issuer_key_id.key_id,OPS_KEY_ID_SIZE); … … 1239 1238 1240 1239 case OPS_PTAG_SS_PREFERRED_SKA: 1241 if(!read_data(&C.ss_preferred_ska.data,&subregion,p arse_info))1240 if(!read_data(&C.ss_preferred_ska.data,&subregion,pinfo)) 1242 1241 return 0; 1243 1242 break; 1244 1243 1245 1244 case OPS_PTAG_SS_PREFERRED_HASH: 1246 if(!read_data(&C.ss_preferred_hash.data,&subregion,p arse_info))1245 if(!read_data(&C.ss_preferred_hash.data,&subregion,pinfo)) 1247 1246 return 0; 1248 1247 break; 1249 1248 1250 1249 case OPS_PTAG_SS_PREFERRED_COMPRESSION: 1251 if(!read_data(&C.ss_preferred_compression.data,&subregion,p arse_info))1250 if(!read_data(&C.ss_preferred_compression.data,&subregion,pinfo)) 1252 1251 return 0; 1253 1252 break; 1254 1253 1255 1254 case OPS_PTAG_SS_PRIMARY_USER_ID: 1256 if(!limited_read (bool,1,&subregion,p arse_info))1255 if(!limited_read (bool,1,&subregion,pinfo)) 1257 1256 return 0; 1258 1257 C.ss_primary_user_id.primary_user_id = !!bool; … … 1260 1259 1261 1260 case OPS_PTAG_SS_KEY_FLAGS: 1262 if(!read_data(&C.ss_key_flags.data,&subregion,p arse_info))1261 if(!read_data(&C.ss_key_flags.data,&subregion,pinfo)) 1263 1262 return 0; 1264 1263 break; 1265 1264 1266 1265 case OPS_PTAG_SS_KEY_SERVER_PREFS: 1267 if(!read_data(&C.ss_key_server_prefs.data,&subregion,p arse_info))1266 if(!read_data(&C.ss_key_server_prefs.data,&subregion,pinfo)) 1268 1267 return 0; 1269 1268 break; 1270 1269 1271 1270 case OPS_PTAG_SS_FEATURES: 1272 if(!read_data(&C.ss_features.data,&subregion,p arse_info))1271 if(!read_data(&C.ss_features.data,&subregion,pinfo)) 1273 1272 return 0; 1274 1273 break; 1275 1274 1276 1275 case OPS_PTAG_SS_SIGNERS_USER_ID: 1277 if(!read_unsigned_string(&C.ss_signers_user_id.user_id,&subregion,p arse_info))1276 if(!read_unsigned_string(&C.ss_signers_user_id.user_id,&subregion,pinfo)) 1278 1277 return 0; 1279 1278 break; 1280 1279 1281 1280 case OPS_PTAG_SS_NOTATION_DATA: 1282 if(!limited_read_data(&C.ss_notation_data.flags,4,&subregion,p arse_info))1281 if(!limited_read_data(&C.ss_notation_data.flags,4,&subregion,pinfo)) 1283 1282 return 0; 1284 1283 if(!limited_read_size_t_scalar(&C.ss_notation_data.name.len,2, 1285 &subregion,p arse_info))1284 &subregion,pinfo)) 1286 1285 return 0; 1287 1286 if(!limited_read_size_t_scalar(&C.ss_notation_data.value.len,2, 1288 &subregion,p arse_info))1287 &subregion,pinfo)) 1289 1288 return 0; 1290 1289 if(!limited_read_data(&C.ss_notation_data.name, 1291 C.ss_notation_data.name.len,&subregion,p arse_info))1290 C.ss_notation_data.name.len,&subregion,pinfo)) 1292 1291 return 0; 1293 1292 if(!limited_read_data(&C.ss_notation_data.value, 1294 C.ss_notation_data.value.len,&subregion,p arse_info))1293 C.ss_notation_data.value.len,&subregion,pinfo)) 1295 1294 return 0; 1296 1295 break; 1297 1296 1298 1297 case OPS_PTAG_SS_POLICY_URL: 1299 if(!read_string(&C.ss_policy_url.text,&subregion,p arse_info))1298 if(!read_string(&C.ss_policy_url.text,&subregion,pinfo)) 1300 1299 return 0; 1301 1300 break; 1302 1301 1303 1302 case OPS_PTAG_SS_REGEXP: 1304 if(!read_string(&C.ss_regexp.text,&subregion, p arse_info))1303 if(!read_string(&C.ss_regexp.text,&subregion, pinfo)) 1305 1304 return 0; 1306 1305 break; 1307 1306 1308 1307 case OPS_PTAG_SS_PREFERRED_KEY_SERVER: 1309 if(!read_string(&C.ss_preferred_key_server.text,&subregion,p arse_info))1308 if(!read_string(&C.ss_preferred_key_server.text,&subregion,pinfo)) 1310 1309 return 0; 1311 1310 break; … … 1322 1321 case OPS_PTAG_SS_USERDEFINED09: 1323 1322 case OPS_PTAG_SS_USERDEFINED10: 1324 if(!read_data(&C.ss_userdefined.data,&subregion,p arse_info))1323 if(!read_data(&C.ss_userdefined.data,&subregion,pinfo)) 1325 1324 return 0; 1326 1325 break; 1327 1326 1328 1327 case OPS_PTAG_SS_RESERVED: 1329 if(!read_data(&C.ss_unknown.data,&subregion,p arse_info))1328 if(!read_data(&C.ss_unknown.data,&subregion,pinfo)) 1330 1329 return 0; 1331 1330 break; … … 1333 1332 case OPS_PTAG_SS_REVOCATION_REASON: 1334 1333 /* first byte is the machine-readable code */ 1335 if(!limited_read(&C.ss_revocation_reason.code,1,&subregion,p arse_info))1334 if(!limited_read(&C.ss_revocation_reason.code,1,&subregion,pinfo)) 1336 1335 return 0; 1337 1336 1338 1337 /* the rest is a human-readable UTF-8 string */ 1339 if(!read_string(&C.ss_revocation_reason.text,&subregion,p arse_info))1338 if(!read_string(&C.ss_revocation_reason.text,&subregion,pinfo)) 1340 1339 return 0; 1341 1340 break; … … 1343 1342 case OPS_PTAG_SS_REVOCATION_KEY: 1344 1343 /* octet 0 = class. Bit 0x80 must be set */ 1345 if(!limited_read (&C.ss_revocation_key.class,1,&subregion,p arse_info))1344 if(!limited_read (&C.ss_revocation_key.class,1,&subregion,pinfo)) 1346 1345 return 0; 1347 1346 if(!(C.ss_revocation_key.class&0x80)) … … 1353 1352 1354 1353 /* octet 1 = algid */ 1355 if(!limited_read(&C.ss_revocation_key.algid,1,&subregion,p arse_info))1354 if(!limited_read(&C.ss_revocation_key.algid,1,&subregion,pinfo)) 1356 1355 return 0; 1357 1356 1358 1357 /* octets 2-21 = fingerprint */ 1359 1358 if(!limited_read(&C.ss_revocation_key.fingerprint[0],20,&subregion, 1360 p arse_info))1359 pinfo)) 1361 1360 return 0; 1362 1361 break; 1363 1362 1364 1363 default: 1365 if(p arse_info->ss_parsed[t8]&t7)1366 ERR1P(p arse_info,"Unknown signature subpacket type (%d)",1364 if(pinfo->ss_parsed[t8]&t7) 1365 ERR1P(pinfo,"Unknown signature subpacket type (%d)", 1367 1366 c[0]&0x7f); 1368 1367 read=ops_false; … … 1371 1370 1372 1371 /* Application doesn't want it delivered parsed */ 1373 if(!(p arse_info->ss_parsed[t8]&t7))1372 if(!(pinfo->ss_parsed[t8]&t7)) 1374 1373 { 1375 1374 if(content.critical) 1376 ERR1P(p arse_info,"Critical signature subpacket ignored (%d)",1375 ERR1P(pinfo,"Critical signature subpacket ignored (%d)", 1377 1376 c[0]&0x7f); 1378 if(!read && !limited_skip(subregion.length-1,&subregion,p arse_info))1377 if(!read && !limited_skip(subregion.length-1,&subregion,pinfo)) 1379 1378 return 0; 1380 1379 // printf("skipped %d length %d\n",c[0]&0x7f,subregion.length); … … 1385 1384 1386 1385 if(read && subregion.length_read != subregion.length) 1387 ERR1P(p arse_info,"Unconsumed data (%d)", subregion.length-subregion.length_read);1386 ERR1P(pinfo,"Unconsumed data (%d)", subregion.length-subregion.length_read); 1388 1387 1389 CBP(p arse_info,content.tag,&content);1388 CBP(pinfo,content.tag,&content); 1390 1389 1391 1390 return 1; … … 1445 1444 static int parse_signature_subpackets(ops_signature_t *sig, 1446 1445 ops_region_t *region, 1447 ops_parse_info_t *p arse_info)1446 ops_parse_info_t *pinfo) 1448 1447 { 1449 1448 ops_region_t subregion; … … 1451 1450 1452 1451 ops_init_subregion(&subregion,region); 1453 if(!limited_read_scalar(&subregion.length,2,region,p arse_info))1452 if(!limited_read_scalar(&subregion.length,2,region,pinfo)) 1454 1453 return 0; 1455 1454 1456 1455 if(subregion.length > region->length) 1457 ERRP(p arse_info,"Subpacket set too long");1456 ERRP(pinfo,"Subpacket set too long"); 1458 1457 1459 1458 while(subregion.length_read < subregion.length) 1460 if(!parse_one_signature_subpacket(sig,&subregion,p arse_info))1459 if(!parse_one_signature_subpacket(sig,&subregion,pinfo)) 1461 1460 return 0; 1462 1461 … … 1464 1463 { 1465 1464 if(!limited_skip(subregion.length-subregion.length_read,&subregion, 1466 p arse_info))1467 ERRP(p arse_info,"Read failed while recovering from subpacket length mismatch");1468 ERRP(p arse_info,"Subpacket length mismatch");1465 pinfo)) 1466 ERRP(pinfo,"Read failed while recovering from subpacket length mismatch"); 1467 ERRP(pinfo,"Subpacket length mismatch"); 1469 1468 } 1470 1469 … … 1485 1484 * \see RFC2440bis-12 5.2.3 1486 1485 */ 1487 static int parse_v4_signature(ops_region_t *region,ops_parse_info_t *p arse_info,1486 static int parse_v4_signature(ops_region_t *region,ops_parse_info_t *pinfo, 1488 1487 size_t v4_hashed_data_start) 1489 1488 { … … 1495 1494 C.signature.v4_hashed_data_start=v4_hashed_data_start; 1496 1495 1497 if(!limited_read(c,1,region,p arse_info))1496 if(!limited_read(c,1,region,pinfo)) 1498 1497 return 0; 1499 1498 C.signature.type=c[0]; 1500 1499 /* XXX: check signature type */ 1501 1500 1502 if(!limited_read(c,1,region,p arse_info))1501 if(!limited_read(c,1,region,pinfo)) 1503 1502 return 0; 1504 1503 C.signature.key_algorithm=c[0]; 1505 1504 /* XXX: check algorithm */ 1506 1505 1507 if(!limited_read(c,1,region,p arse_info))1506 if(!limited_read(c,1,region,pinfo)) 1508 1507 return 0; 1509 1508 C.signature.hash_algorithm=c[0]; 1510 1509 /* XXX: check algorithm */ 1511 1510 1512 CBP(p arse_info,OPS_PTAG_CT_SIGNATURE_HEADER,&content);1513 1514 if(!parse_signature_subpackets(&C.signature,region,p arse_info))1515 return 0; 1516 C.signature.v4_hashed_data_length=p arse_info->rinfo.alength1511 CBP(pinfo,OPS_PTAG_CT_SIGNATURE_HEADER,&content); 1512 1513 if(!parse_signature_subpackets(&C.signature,region,pinfo)) 1514 return 0; 1515 C.signature.v4_hashed_data_length=pinfo->rinfo.alength 1517 1516 -C.signature.v4_hashed_data_start; 1518 1517 1519 if(!parse_signature_subpackets(&C.signature,region,p arse_info))1518 if(!parse_signature_subpackets(&C.signature,region,pinfo)) 1520 1519 return 0; 1521 1520 1522 if(!limited_read(C.signature.hash2,2,region,p arse_info))1521 if(!limited_read(C.signature.hash2,2,region,pinfo)) 1523 1522 return 0; 1524 1523 … … 1526 1525 { 1527 1526 case OPS_PKA_RSA: 1528 if(!limited_read_mpi(&C.signature.signature.rsa.sig,region,p arse_info))1527 if(!limited_read_mpi(&C.signature.signature.rsa.sig,region,pinfo)) 1529 1528 return 0; 1530 1529 break; 1531 1530 1532 1531 case OPS_PKA_DSA: 1533 if(!limited_read_mpi(&C.signature.signature.dsa.r,region,p arse_info))1534 ERRP(p arse_info,"Error reading DSA r field in signature");1535 if (!limited_read_mpi(&C.signature.signature.dsa.s,region,p arse_info))1536 ERRP(p arse_info,"Error reading DSA s field in signature");1532 if(!limited_read_mpi(&C.signature.signature.dsa.r,region,pinfo)) 1533 ERRP(pinfo,"Error reading DSA r field in signature"); 1534 if (!limited_read_mpi(&C.signature.signature.dsa.s,region,pinfo)) 1535 ERRP(pinfo,"Error reading DSA s field in signature"); 1537 1536 break; 1538 1537 1539 1538 case OPS_PKA_ELGAMAL_ENCRYPT_OR_SIGN: 1540 if(!limited_read_mpi(&C.signature.signature.elgamal.r,region,p arse_info)1541 || !limited_read_mpi(&C.signature.signature.elgamal.s,region,p arse_info))1539 if(!limited_read_mpi(&C.signature.signature.elgamal.r,region,pinfo) 1540 || !limited_read_mpi(&C.signature.signature.elgamal.s,region,pinfo)) 1542 1541 return 0; 1543 1542 break; … … 1554 1553 case OPS_PKA_PRIVATE09: 1555 1554 case OPS_PKA_PRIVATE10: 1556 if (!read_data(&C.signature.signature.unknown.data,region,p arse_info))1555 if (!read_data(&C.signature.signature.unknown.data,region,pinfo)) 1557 1556 return 0; 1558 1557 break; 1559 1558 1560 1559 default: 1561 ERR1P(p arse_info,"Bad v4 signature key algorithm (%d)",1560 ERR1P(pinfo,"Bad v4 signature key algorithm (%d)", 1562 1561 C.signature.key_algorithm); 1563 1562 } 1564 1563 1565 1564 if(region->length_read != region->length) 1566 ERR1P(p arse_info,"Unconsumed data (%d)",1565 ERR1P(pinfo,"Unconsumed data (%d)", 1567 1566 region->length-region->length_read); 1568 1567 1569 CBP(p arse_info,OPS_PTAG_CT_SIGNATURE_FOOTER,&content);1568 CBP(pinfo,OPS_PTAG_CT_SIGNATURE_FOOTER,&content); 1570 1569 1571 1570 return 1; … … 1583 1582 * \return 1 on success, 0 on error 1584 1583 */ 1585 static int parse_signature(ops_region_t *region,ops_parse_info_t *p arse_info)1584 static int parse_signature(ops_region_t *region,ops_parse_info_t *pinfo) 1586 1585 { 1587 1586 unsigned char c[1]; … … 1593 1592 memset(&content,'\0',sizeof content); 1594 1593 1595 v4_hashed_data_start=p arse_info->rinfo.alength;1596 if(!limited_read(c,1,region,p arse_info))1594 v4_hashed_data_start=pinfo->rinfo.alength; 1595 if(!limited_read(c,1,region,pinfo)) 1597 1596 return 0; 1598 1597 1599 1598 if(c[0] == 2 || c[0] == 3) 1600 return parse_v3_signature(region,p arse_info);1599 return parse_v3_signature(region,pinfo); 1601 1600 else if(c[0] == 4) 1602 return parse_v4_signature(region,p arse_info,v4_hashed_data_start);1603 ERR1P(p arse_info,"Bad signature version (%d)",c[0]);1604 } 1605 1606 static int parse_compressed(ops_region_t *region,ops_parse_info_t *p arse_info)1601 return parse_v4_signature(region,pinfo,v4_hashed_data_start); 1602 ERR1P(pinfo,"Bad signature version (%d)",c[0]); 1603 } 1604 1605 static int parse_compressed(ops_region_t *region,ops_parse_info_t *pinfo) 1607 1606 { 1608 1607 unsigned char c[1]; 1609 1608 ops_parser_content_t content; 1610 1609 1611 if(!limited_read(c,1,region,p arse_info))1610 if(!limited_read(c,1,region,pinfo)) 1612 1611 return 0; 1613 1612 1614 1613 C.compressed.type=c[0]; 1615 1614 1616 CBP(p arse_info,OPS_PTAG_CT_COMPRESSED,&content);1615 CBP(pinfo,OPS_PTAG_CT_COMPRESSED,&content); 1617 1616 1618 1617 /* The content of a compressed data packet is more OpenPGP packets 1619 1618 once decompressed, so recursively handle them */ 1620 1619 1621 return ops_decompress(region,p arse_info);1622 } 1623 1624 static int parse_one_pass(ops_region_t *region,ops_parse_info_t *p arse_info)1620 return ops_decompress(region,pinfo); 1621 } 1622 1623 static int parse_one_pass(ops_region_t *region,ops_parse_info_t *pinfo) 1625 1624 { 1626 1625 unsigned char c[1]; 1627 1626 ops_parser_content_t content; 1628 1627 1629 if(!limited_read(&C.one_pass_signature.version,1,region,p arse_info))1628 if(!limited_read(&C.one_pass_signature.version,1,region,pinfo)) 1630 1629 return 0; 1631 1630 if(C.one_pass_signature.version != 3) 1632 ERR1P(p arse_info,"Bad one-pass signature version (%d)",1631 ERR1P(pinfo,"Bad one-pass signature version (%d)", 1633 1632 C.one_pass_signature.version); 1634 1633 1635 if(!limited_read(c,1,region,p arse_info))1634 if(!limited_read(c,1,region,pinfo)) 1636 1635 return 0; 1637 1636 C.one_pass_signature.sig_type=c[0]; 1638 1637 1639 if(!limited_read(c,1,region,p arse_info))1638 if(!limited_read(c,1,region,pinfo)) 1640 1639 return 0; 1641 1640 C.one_pass_signature.hash_algorithm=c[0]; 1642 1641 1643 if(!limited_read(c,1,region,p arse_info))1642 if(!limited_read(c,1,region,pinfo)) 1644 1643 return 0; 1645 1644 C.one_pass_signature.key_algorithm=c[0]; 1646 1645 1647 1646 if(!limited_read(C.one_pass_signature.keyid, 1648 sizeof C.one_pass_signature.keyid,region,p arse_info))1649 return 0; 1650 1651 if(!limited_read(c,1,region,p arse_info))1647 sizeof C.one_pass_signature.keyid,region,pinfo)) 1648 return 0; 1649 1650 if(!limited_read(c,1,region,pinfo)) 1652 1651 return 0; 1653 1652 C.one_pass_signature.nested=!!c[0]; 1654 1653 1655 CBP(p arse_info,OPS_PTAG_CT_ONE_PASS_SIGNATURE,&content);1654 CBP(pinfo,OPS_PTAG_CT_ONE_PASS_SIGNATURE,&content); 1656 1655 1657 1656 return 1; … … 1690 1689 1691 1690 static int 1692 parse_trust (ops_region_t *region, ops_parse_info_t *p arse_info)1691 parse_trust (ops_region_t *region, ops_parse_info_t *pinfo) 1693 1692 { 1694 1693 ops_parser_content_t content; 1695 1694 1696 if(!read_data(&C.trust.data,region,p arse_info))1697 return 0; 1698 1699 CBP(p arse_info,OPS_PTAG_CT_TRUST, &content);1695 if(!read_data(&C.trust.data,region,pinfo)) 1696 return 0; 1697 1698 CBP(pinfo,OPS_PTAG_CT_TRUST, &content); 1700 1699 1701 1700 return 1; 1702 1701 } 1703 1702 1704 static int parse_literal_data(ops_region_t *region,ops_parse_info_t *p arse_info)1703 static int parse_literal_data(ops_region_t *region,ops_parse_info_t *pinfo) 1705 1704 { 1706 1705 ops_parser_content_t content; 1707 1706 unsigned char c[1]; 1708 1707 1709 if(!limited_read(c,1,region,p arse_info))1708 if(!limited_read(c,1,region,pinfo)) 1710 1709 return 0; 1711 1710 C.literal_data_header.format=c[0]; 1712 1711 1713 if(!limited_read(c,1,region,p arse_info))1712 if(!limited_read(c,1,region,pinfo)) 1714 1713 return 0; 1715 1714 if(!limited_read((unsigned char *)C.literal_data_header.filename,c[0], 1716 region,p arse_info))1715 region,pinfo)) 1717 1716 return 0; 1718 1717 C.literal_data_header.filename[c[0]]='\0'; 1719 1718 1720 if(!limited_read_time(&C.literal_data_header.modification_time,region,p arse_info))1721 return 0; 1722 1723 CBP(p arse_info,OPS_PTAG_CT_LITERAL_DATA_HEADER,&content);1719 if(!limited_read_time(&C.literal_data_header.modification_time,region,pinfo)) 1720 return 0; 1721 1722 CBP(pinfo,OPS_PTAG_CT_LITERAL_DATA_HEADER,&content); 1724 1723 1725 1724 while(region->length_read < region->length) … … 1730 1729 l=sizeof C.literal_data_body.data; 1731 1730 1732 if(!limited_read(C.literal_data_body.data,l,region,p arse_info))1731 if(!limited_read(C.literal_data_body.data,l,region,pinfo)) 1733 1732 return 0; 1734 1733 1735 1734 C.literal_data_body.length=l; 1736 1735 1737 CBP(p arse_info,OPS_PTAG_CT_LITERAL_DATA_BODY,&content);1736 CBP(pinfo,OPS_PTAG_CT_LITERAL_DATA_BODY,&content); 1738 1737 } 1739 1738 … … 1775 1774 } 1776 1775 1777 static int consume_packet(ops_region_t *region,ops_parse_info_t *p arse_info,1776 static int consume_packet(ops_region_t *region,ops_parse_info_t *pinfo, 1778 1777 ops_boolean_t warn) 1779 1778 { … … 1781 1780 ops_parser_content_t content; 1782 1781 1783 if(read_data(&remainder,region,p arse_info))1782 if(read_data(&remainder,region,pinfo)) 1784 1783 { 1785 1784 /* now throw it away */ 1786 1785 data_free(&remainder); 1787 1786 if(warn) 1788 ERRCODEP(p arse_info,OPS_E_P_PACKET_CONSUMED);1787 ERRCODEP(pinfo,OPS_E_P_PACKET_CONSUMED); 1789 1788 } 1790 1789 else if(warn) 1791 WARNP(p arse_info,"Problem consuming remainder of error packet.");1790 WARNP(pinfo,"Problem consuming remainder of error packet."); 1792 1791 else 1793 1792 return 0; … … 1796 1795 } 1797 1796 1798 static int parse_secret_key(ops_region_t *region,ops_parse_info_t *p arse_info)1797 static int parse_secret_key(ops_region_t *region,ops_parse_info_t *pinfo) 1799 1798 { 1800 1799 ops_parser_content_t content; … … 1810 1809 1811 1810 memset(&content,'\0',sizeof content); 1812 if(!parse_public_key_data(&C.secret_key.public_key,region,p arse_info))1813 return 0; 1814 1815 p arse_info->reading_v3_secret=C.secret_key.public_key.version != OPS_V4;1816 1817 if(!limited_read(c,1,region,p arse_info))1811 if(!parse_public_key_data(&C.secret_key.public_key,region,pinfo)) 1812 return 0; 1813 1814 pinfo->reading_v3_secret=C.secret_key.public_key.version != OPS_V4; 1815 1816 if(!limited_read(c,1,region,pinfo)) 1818 1817 return 0; 1819 1818 C.secret_key.s2k_usage=c[0]; … … 1825 1824 || C.secret_key.s2k_usage == OPS_S2KU_ENCRYPTED_AND_HASHED) 1826 1825 { 1827 if(!limited_read(c,1,region,p arse_info))1826 if(!limited_read(c,1,region,pinfo)) 1828 1827 return 0; 1829 1828 C.secret_key.algorithm=c[0]; 1830 1829 1831 if(!limited_read(c,1,region,p arse_info))1830 if(!limited_read(c,1,region,pinfo)) 1832 1831 return 0; 1833 1832 C.secret_key.s2k_specifier=c[0]; … … 1837 1836 || C.secret_key.s2k_specifier == OPS_S2KS_ITERATED_AND_SALTED); 1838 1837 1839 if(!limited_read(c,1,region,p arse_info))1838 if(!limited_read(c,1,region,pinfo)) 1840 1839 return 0; 1841 1840 C.secret_key.hash_algorithm=c[0]; 1842 1841 1843 1842 if(C.secret_key.s2k_specifier != OPS_S2KS_SIMPLE 1844 && !limited_read(C.secret_key.salt,8,region,p arse_info))1843 && !limited_read(C.secret_key.salt,8,region,pinfo)) 1845 1844 return 0; 1846 1845 1847 1846 if(C.secret_key.s2k_specifier == OPS_S2KS_ITERATED_AND_SALTED) 1848 1847 { 1849 if(!limited_read(c,1,region,p arse_info))1848 if(!limited_read(c,1,region,pinfo)) 1850 1849 return 0; 1851 1850 C.secret_key.octet_count=(16+(c[0]&15)) << ((c[0] >> 4)+6); … … 1878 1877 assert(blocksize > 0 && blocksize <= OPS_MAX_BLOCK_SIZE); 1879 1878 1880 if(!limited_read(C.secret_key.iv,blocksize,region,p arse_info))1879 if(!limited_read(C.secret_key.iv,blocksize,region,pinfo)) 1881 1880 return 0; 1882 1881 … … 1885 1884 pc.content.secret_key_passphrase.passphrase=&passphrase; 1886 1885 pc.content.secret_key_passphrase.secret_key=&C.secret_key; 1887 CBP(p arse_info,OPS_PARSER_CMD_GET_SK_PASSPHRASE,&pc);1886 CBP(pinfo,OPS_PARSER_CMD_GET_SK_PASSPHRASE,&pc); 1888 1887 if(!passphrase) 1889 1888 { 1890 if(!consume_packet(region,p arse_info,ops_false))1889 if(!consume_packet(region,pinfo,ops_false)) 1891 1890 return 0; 1892 1891 1893 CBP(p arse_info,OPS_PTAG_CT_ENCRYPTED_SECRET_KEY,&content);1892 CBP(pinfo,OPS_PTAG_CT_ENCRYPTED_SECRET_KEY,&content); 1894 1893 1895 1894 return 1; … … 1957 1956 decrypt.set_key(&decrypt,key); 1958 1957 1959 ops_reader_push_decrypt(p arse_info,&decrypt,region);1958 ops_reader_push_decrypt(pinfo,&decrypt,region); 1960 1959 1961 1960 /* Since all known encryption for PGP doesn't compress, we can … … 1973 1972 { 1974 1973 ops_hash_sha1(&checkhash); 1975 ops_reader_push_hash(p arse_info,&checkhash);1974 ops_reader_push_hash(pinfo,&checkhash); 1976 1975 } 1977 1976 else 1978 ops_reader_push_sum16(p arse_info);1977 ops_reader_push_sum16(pinfo); 1979 1978 1980 1979 switch(C.secret_key.public_key.algorithm) … … 1983 1982 case OPS_PKA_RSA_ENCRYPT_ONLY: 1984 1983 case OPS_PKA_RSA_SIGN_ONLY: 1985 if(!limited_read_mpi(&C.secret_key.key.rsa.d,region,p arse_info)1986 || !limited_read_mpi(&C.secret_key.key.rsa.p,region,p arse_info)1987 || !limited_read_mpi(&C.secret_key.key.rsa.q,region,p arse_info)1988 || !limited_read_mpi(&C.secret_key.key.rsa.u,region,p arse_info))1984 if(!limited_read_mpi(&C.secret_key.key.rsa.d,region,pinfo) 1985 || !limited_read_mpi(&C.secret_key.key.rsa.p,region,pinfo) 1986 || !limited_read_mpi(&C.secret_key.key.rsa.q,region,pinfo) 1987 || !limited_read_mpi(&C.secret_key.key.rsa.u,region,pinfo)) 1989 1988 ret=0; 1990 1989 break; 1991 1990 1992 1991 case OPS_PKA_DSA: 1993 if(!limited_read_mpi(&C.secret_key.key.dsa.x,region,p arse_info))1992 if(!limited_read_mpi(&C.secret_key.key.dsa.x,region,pinfo)) 1994 1993 ret=0; 1995 1994 break; … … 2002 2001 } 2003 2002 2004 p arse_info->reading_v3_secret=ops_false;2003 pinfo->reading_v3_secret=ops_false; 2005 2004 2006 2005 if(C.secret_key.s2k_usage == OPS_S2KU_ENCRYPTED_AND_HASHED) … … 2008 2007 unsigned char hash[20]; 2009 2008 2010 ops_reader_pop_hash(p arse_info);2009 ops_reader_pop_hash(pinfo); 2011 2010 checkhash.finish(&checkhash,hash); 2012 2011 2013 2012 if(crypted && C.secret_key.public_key.version != OPS_V4) 2014 2013 { 2015 ops_reader_pop_decrypt(p arse_info);2014 ops_reader_pop_decrypt(pinfo); 2016 2015 region=saved_region; 2017 2016 } … … 2019 2018 if(ret) 2020 2019 { 2021 if(!limited_read(C.secret_key.checkhash,20,region,p arse_info))2020 if(!limited_read(C.secret_key.checkhash,20,region,pinfo)) 2022 2021 return 0; 2023 2022 2024 2023 if(memcmp(hash,C.secret_key.checkhash,20)) 2025 ERRP(p arse_info,"Hash mismatch in secret key");2024 ERRP(pinfo,"Hash mismatch in secret key"); 2026 2025 } 2027 2026 } … … 2030 2029 unsigned short sum; 2031 2030 2032 sum=ops_reader_pop_sum16(p arse_info);2031 sum=ops_reader_pop_sum16(pinfo); 2033 2032 2034 2033 if(crypted && C.secret_key.public_key.version != OPS_V4) 2035 2034 { 2036 ops_reader_pop_decrypt(p arse_info);2035 ops_reader_pop_decrypt(pinfo); 2037 2036 region=saved_region; 2038 2037 } … … 2041 2040 { 2042 2041 if(!limited_read_scalar(&C.secret_key.checksum,2,region, 2043 p arse_info))2042 pinfo)) 2044 2043 return 0; 2045 2044 2046 2045 if(sum != C.secret_key.checksum) 2047 ERRP(p arse_info,"Checksum mismatch in secret key");2046 ERRP(pinfo,"Checksum mismatch in secret key"); 2048 2047 } 2049 2048 } 2050 2049 2051 2050 if(crypted && C.secret_key.public_key.version == OPS_V4) 2052 ops_reader_pop_decrypt(p arse_info);2051 ops_reader_pop_decrypt(pinfo); 2053 2052 2054 2053 assert(!ret || region->length_read == region->length); … … 2057 2056 return 0; 2058 2057 2059 CBP(p arse_info,OPS_PTAG_CT_SECRET_KEY,&content);2058 CBP(pinfo,OPS_PTAG_CT_SECRET_KEY,&content); 2060 2059 2061 2060 return 1; … … 2063 2062 2064 2063 static int parse_pk_session_key(ops_region_t *region, 2065 ops_parse_info_t *p arse_info)2064 ops_parse_info_t *pinfo) 2066 2065 { 2067 2066 unsigned char c[1]; … … 2074 2073 const ops_secret_key_t *secret; 2075 2074 2076 if(!limited_read(c,1,region,p arse_info))2075 if(!limited_read(c,1,region,pinfo)) 2077 2076 return 0; 2078 2077 C.pk_session_key.version=c[0]; 2079 2078 if(C.pk_session_key.version != OPS_PKSK_V3) 2080 ERR1P(p arse_info,2079 ERR1P(pinfo, 2081 2080 "Bad public-key encrypted session key version (%d)", 2082 2081 C.pk_session_key.version); 2083 2082 2084 2083 if(!limited_read(C.pk_session_key.key_id, 2085 sizeof C.pk_session_key.key_id,region,p arse_info))2086 return 0; 2087 2088 if(!limited_read(c,1,region,p arse_info))2084 sizeof C.pk_session_key.key_id,region,pinfo)) 2085 return 0; 2086 2087 if(!limited_read(c,1,region,pinfo)) 2089 2088 return 0; 2090 2089 C.pk_session_key.algorithm=c[0]; … … 2093 2092 case OPS_PKA_RSA: 2094 2093 if(!limited_read_mpi(&C.pk_session_key.parameters.rsa.encrypted_m, 2095 region,p arse_info))2094 region,pinfo)) 2096 2095 return 0; 2097 2096 enc_m=C.pk_session_key.parameters.rsa.encrypted_m; … … 2100 2099 case OPS_PKA_ELGAMAL: 2101 2100 if(!limited_read_mpi(&C.pk_session_key.parameters.elgamal.g_to_k, 2102 region,p arse_info)2101 region,pinfo) 2103 2102 || limited_read_mpi(&C.pk_session_key.parameters.elgamal.encrypted_m, 2104 region,p arse_info))2103 region,pinfo)) 2105 2104 return 0; 2106 2105 enc_m=C.pk_session_key.parameters.elgamal.encrypted_m; … … 2108 2107 2109 2108 default: 2110 ERR1P(p arse_info,2109 ERR1P(pinfo, 2111 2110 "Unknown public key algorithm in session key (%d)", 2112 2111 C.pk_session_key.algorithm); … … 2119 2118 pc.content.get_secret_key.pk_session_key=&C.pk_session_key; 2120 2119 2121 CBP(p arse_info,OPS_PARSER_CMD_GET_SECRET_KEY,&pc);2120 CBP(pinfo,OPS_PARSER_CMD_GET_SECRET_KEY,&pc); 2122 2121 2123 2122 if(!secret) 2124 2123 { 2125 CBP(p arse_info,OPS_PTAG_CT_ENCRYPTED_PK_SESSION_KEY,&content);2124 CBP(pinfo,OPS_PTAG_CT_ENCRYPTED_PK_SESSION_KEY,&content); 2126 2125 2127 2126 return 1; … … 2131 2130 2132 2131 if(n < 1) 2133 ERRP(p arse_info,"decrypted message too short");2132 ERRP(pinfo,"decrypted message too short"); 2134 2133 2135 2134 C.pk_session_key.symmetric_algorithm=buf[0]; … … 2137 2136 2138 2137 if((unsigned)n != k+3) 2139 ERR2P(p arse_info,"decrypted message wrong length (got %d expected %d)",2138 ERR2P(pinfo,"decrypted message wrong length (got %d expected %d)", 2140 2139 n,k+3); 2141 2140 … … 2148 2147 // XXX: Check checksum! 2149 2148 2150 CBP(p arse_info,OPS_PTAG_CT_PK_SESSION_KEY,&content);2151 2152 ops_decrypt_any(&p arse_info->decrypt,C.pk_session_key.symmetric_algorithm);2153 p arse_info->decrypt.set_key(&parse_info->decrypt,C.pk_session_key.key);2149 CBP(pinfo,OPS_PTAG_CT_PK_SESSION_KEY,&content); 2150 2151 ops_decrypt_any(&pinfo->decrypt,C.pk_session_key.symmetric_algorithm); 2152 pinfo->decrypt.set_key(&pinfo->decrypt,C.pk_session_key.key); 2154 2153 2155 2154 return 1; … … 2212 2211 } 2213 2212 2214 static int parse_se_data(ops_region_t *region,ops_parse_info_t *p arse_info)2213 static int parse_se_data(ops_region_t *region,ops_parse_info_t *pinfo) 2215 2214 { 2216 2215 ops_parser_content_t content; 2217 2216 2218 2217 /* there's no info to go with this, so just announce it */ 2219 CBP(p arse_info,OPS_PTAG_CT_SE_DATA_HEADER,&content);2218 CBP(pinfo,OPS_PTAG_CT_SE_DATA_HEADER,&content); 2220 2219 2221 2220 /* The content of an encrypted data packet is more OpenPGP packets 2222 2221 once decrypted, so recursively handle them */ 2223 return ops_decrypt_data(OPS_PTAG_CT_SE_DATA_BODY,region,p arse_info);2224 } 2225 2226 static int parse_se_ip_data(ops_region_t *region,ops_parse_info_t *p arse_info)2222 return ops_decrypt_data(OPS_PTAG_CT_SE_DATA_BODY,region,pinfo); 2223 } 2224 2225 static int parse_se_ip_data(ops_region_t *region,ops_parse_info_t *pinfo) 2227 2226 { 2228 2227 unsigned char c[1]; 2229 2228 ops_parser_content_t content; 2230 2229 2231 if(!limited_read(c,1,region,p arse_info))2230 if(!limited_read(c,1,region,pinfo)) 2232 2231 return 0; 2233 2232 C.se_ip_data_header.version=c[0]; 2234 2233 assert(C.se_ip_data_header.version == OPS_SE_IP_V1); 2235 2234 2236 CBP(p arse_info,OPS_PTAG_CT_SE_IP_DATA_HEADER,&content);2235 CBP(pinfo,OPS_PTAG_CT_SE_IP_DATA_HEADER,&content); 2237 2236 2238 2237 /* The content of an encrypted data packet is more OpenPGP packets 2239 2238 once decrypted, so recursively handle them */ 2240 return ops_decrypt_data(OPS_PTAG_CT_SE_IP_DATA_BODY,region,p arse_info);2239 return ops_decrypt_data(OPS_PTAG_CT_SE_IP_DATA_BODY,region,pinfo); 2241 2240 } 2242 2241 … … 2247 2246 * content. 2248 2247 * 2249 * \param *p arse_info How to parse2248 * \param *pinfo How to parse 2250 2249 * \param *pktlen On return, will contain number of bytes in packet 2251 2250 * \return 1 on success, 0 on error, -1 on EOF */ 2252 static int ops_parse_one_packet(ops_parse_info_t *p arse_info,2251 static int ops_parse_one_packet(ops_parse_info_t *pinfo, 2253 2252 unsigned long *pktlen) 2254 2253 { … … 2261 2260 ops_boolean_t indeterminate=ops_false; 2262 2261 2263 C.ptag.position=p arse_info->rinfo.position;2264 2265 ret=base_read(ptag,&one,0,p arse_info);2262 C.ptag.position=pinfo->rinfo.position; 2263 2264 ret=base_read(ptag,&one,0,pinfo); 2266 2265 if(ret == OPS_R_EOF || ret == OPS_R_EARLY_EOF) 2267 2266 return -1; … … 2273 2272 { 2274 2273 C.error.error="Format error (ptag bit not set)"; 2275 CBP(p arse_info,OPS_PARSER_ERROR,&content);2274 CBP(pinfo,OPS_PARSER_ERROR,&content); 2276 2275 return 0; 2277 2276 } … … 2281 2280 C.ptag.content_tag=*ptag&OPS_PTAG_NF_CONTENT_TAG_MASK; 2282 2281 C.ptag.length_type=0; 2283 if(!read_new_length(&C.ptag.length,p arse_info))2282 if(!read_new_length(&C.ptag.length,pinfo)) 2284 2283 return 0; 2285 2284 … … 2293 2292 { 2294 2293 case OPS_PTAG_OF_LT_ONE_BYTE: 2295 ret=read_scalar(&C.ptag.length,1,p arse_info);2294 ret=read_scalar(&C.ptag.length,1,pinfo); 2296 2295 break; 2297 2296 2298 2297 case OPS_PTAG_OF_LT_TWO_BYTE: 2299 ret=read_scalar(&C.ptag.length,2,p arse_info);2298 ret=read_scalar(&C.ptag.length,2,pinfo); 2300 2299 break; 2301 2300 2302 2301 case OPS_PTAG_OF_LT_FOUR_BYTE: 2303 ret=read_scalar(&C.ptag.length,4,p arse_info);2302 ret=read_scalar(&C.ptag.length,4,pinfo); 2304 2303 break; 2305 2304 … … 2314 2313 } 2315 2314 2316 CBP(p arse_info,OPS_PARSER_PTAG,&content);2315 CBP(pinfo,OPS_PARSER_PTAG,&content); 2317 2316 2318 2317 ops_init_subregion(®ion,NULL); … … 2322 2321 { 2323 2322 case OPS_PTAG_CT_SIGNATURE: 2324 r=parse_signature(®ion,p arse_info);2323 r=parse_signature(®ion,pinfo); 2325 2324 break; 2326 2325 2327 2326 case OPS_PTAG_CT_PUBLIC_KEY: 2328 2327 case OPS_PTAG_CT_PUBLIC_SUBKEY: 2329 r=parse_public_key(C.ptag.content_tag,®ion,p arse_info);2328 r=parse_public_key(C.ptag.content_tag,®ion,pinfo); 2330 2329 break; 2331 2330 2332 2331 case OPS_PTAG_CT_TRUST: 2333 r=parse_trust(®ion, p arse_info);2332 r=parse_trust(®ion, pinfo); 2334 2333 break; 2335 2334 2336 2335 case OPS_PTAG_CT_USER_ID: 2337 r=parse_user_id(®ion,p arse_info);2336 r=parse_user_id(®ion,pinfo); 2338 2337 break; 2339 2338 2340 2339 case OPS_PTAG_CT_COMPRESSED: 2341 r=parse_compressed(®ion,p arse_info);2340 r=parse_compressed(®ion,pinfo); 2342 2341 break; 2343 2342 2344 2343 case OPS_PTAG_CT_ONE_PASS_SIGNATURE: 2345 r=parse_one_pass(®ion,p arse_info);2344 r=parse_one_pass(®ion,pinfo); 2346 2345 break; 2347 2346 2348 2347 case OPS_PTAG_CT_LITERAL_DATA: 2349 r=parse_literal_data(®ion,p arse_info);2348 r=parse_literal_data(®ion,pinfo); 2350 2349 break; 2351 2350 2352 2351 case OPS_PTAG_CT_USER_ATTRIBUTE: 2353 r=parse_user_attribute(®ion,p arse_info);2352 r=parse_user_attribute(®ion,pinfo); 2354 2353 break; 2355 2354 2356 2355 case OPS_PTAG_CT_SECRET_KEY: 2357 r=parse_secret_key(®ion,p arse_info);2356 r=parse_secret_key(®ion,pinfo); 2358 2357 break; 2359 2358 2360 2359 case OPS_PTAG_CT_PK_SESSION_KEY: 2361 r=parse_pk_session_key(®ion,p arse_info);2360 r=parse_pk_session_key(®ion,pinfo); 2362 2361 break; 2363 2362 2364 2363 case OPS_PTAG_CT_SE_DATA: 2365 r=parse_se_data(®ion,p arse_info);2364 r=parse_se_data(®ion,pinfo); 2366 2365 break; 2367 2366 2368 2367 case OPS_PTAG_CT_SE_IP_DATA: 2369 r=parse_se_ip_data(®ion,p arse_info);2368 r=parse_se_ip_data(®ion,pinfo); 2370 2369 break; 2371 2370 … … 2373 2372 format_error(&content,"Format error (unknown content tag %d)", 2374 2373 C.ptag.content_tag); 2375 ERRCODEP(p arse_info,OPS_E_P_UNKNOWN_TAG);2374 ERRCODEP(pinfo,OPS_E_P_UNKNOWN_TAG); 2376 2375 r=0; 2377 2376 } … … 2380 2379 2381 2380 if(region.length != region.length_read) 2382 consume_packet(®ion,p arse_info,ops_true);2381 consume_packet(®ion,pinfo,ops_true); 2383 2382 2384 2383 /* set pktlen */ 2385 2384 2386 *pktlen=p arse_info->rinfo.alength;2385 *pktlen=pinfo->rinfo.alength; 2387 2386 2388 2387 /* do callback on entire packet, if desired */ 2389 2388 2390 if(p arse_info->rinfo.accumulate)2391 { 2392 C.packet.length=p arse_info->rinfo.alength;2393 C.packet.raw=p arse_info->rinfo.accumulated;2394 p arse_info->rinfo.accumulated=NULL;2395 p arse_info->rinfo.asize=0;2396 CBP(p arse_info,OPS_PARSER_PACKET_END,&content);2397 } 2398 p arse_info->rinfo.alength=0;2389 if(pinfo->rinfo.accumulate) 2390 { 2391 C.packet.length=pinfo->rinfo.alength; 2392 C.packet.raw=pinfo->rinfo.accumulated; 2393 pinfo->rinfo.accumulated=NULL; 2394 pinfo->rinfo.asize=0; 2395 CBP(pinfo,OPS_PARSER_PACKET_END,&content); 2396 } 2397 pinfo->rinfo.alength=0; 2399 2398 2400 2399 return r ? 1 : 0; … … 2407 2406 * 2408 2407 * All the necessary information for parsing should have been set up by the 2409 * calling function in "*p arse_info" beforehand.2408 * calling function in "*pinfo" beforehand. 2410 2409 * 2411 2410 * That information includes : … … 2420 2419 * \sa See Detailed Description for usage. 2421 2420 * 2422 * \param *p arse_info How to parse2421 * \param *pinfo How to parse 2423 2422 * \return 1 on success in all packets, 0 on error in any packet 2424 * \todo Add some error checking to make sure *p arse_info contains a sensible setup?2423 * \todo Add some error checking to make sure *pinfo contains a sensible setup? 2425 2424 */ 2426 2425 2427 int ops_parse(ops_parse_info_t *p arse_info)2426 int ops_parse(ops_parse_info_t *pinfo) 2428 2427 { 2429 2428 int r; … … 2431 2430 do 2432 2431 { 2433 r=ops_parse_one_packet(p arse_info,&pktlen);2432 r=ops_parse_one_packet(pinfo,&pktlen); 2434 2433 // offset+=pktlen; 2435 2434 } while (r!=-1); 2436 2435 2437 return p arse_info->errors ? 0 : 1;2436 return pinfo->errors ? 0 : 1; 2438 2437 } 2439 2438 … … 2445 2444 */ 2446 2445 2447 int ops_parse_errs(ops_parse_info_t *p arse_info, ops_ulong_list_t *errs)2446 int ops_parse_errs(ops_parse_info_t *pinfo, ops_ulong_list_t *errs) 2448 2447 { 2449 2448 unsigned err; … … 2455 2454 /* can only handle ops_reader_fd for now */ 2456 2455 2457 if (p arse_info->rinfo.reader != ops_reader_fd)2456 if (pinfo->rinfo.reader != ops_reader_fd) 2458 2457 { 2459 2458 fprintf(stderr,"ops_parse_errs: can only handle ops_reader_fd\n"); … … 2461 2460 } 2462 2461 2463 arg=p arse_info->rinfo.arg;2462 arg=pinfo->rinfo.arg; 2464 2463 2465 2464 /* store current state of accumulate flag */ 2466 2465 2467 orig_acc=p arse_info->rinfo.accumulate;2466 orig_acc=pinfo->rinfo.accumulate; 2468 2467 2469 2468 /* set accumulate flag */ 2470 2469 2471 p arse_info->rinfo.accumulate=1;2470 pinfo->rinfo.accumulate=1; 2472 2471 2473 2472 /* now parse each error in turn. */ … … 2489 2488 /* parse packet */ 2490 2489 2491 ops_parse_one_packet(p arse_info,&pktlen);2490 ops_parse_one_packet(pinfo,&pktlen); 2492 2491 2493 2492 } 2494 2493 2495 2494 /* restore accumulate flag original value */ 2496 p arse_info->rinfo.accumulate=orig_acc;2495 pinfo->rinfo.accumulate=orig_acc; 2497 2496 2498 2497 return 1; … … 2506 2505 * subpacket types should be returned parsed or raw or ignored. 2507 2506 * 2508 * \param p arse_info Pointer to previously allocated structure2507 * \param pinfo Pointer to previously allocated structure 2509 2508 * \param tag Packet tag. OPS_PTAG_SS_ALL for all SS tags; or one individual signature subpacket tag 2510 2509 * \param type Parse type 2511 2510 * \todo XXX: Make all packet types optional, not just subpackets */ 2512 void ops_parse_options(ops_parse_info_t *p arse_info,2511 void ops_parse_options(ops_parse_info_t *pinfo, 2513 2512 ops_content_tag_t tag, 2514 2513 ops_parse_type_t type) … … 2521 2520 2522 2521 for(n=0 ; n < 256 ; ++n) 2523 ops_parse_options(p arse_info,OPS_PTAG_SIGNATURE_SUBPACKET_BASE+n,2522 ops_parse_options(pinfo,OPS_PTAG_SIGNATURE_SUBPACKET_BASE+n, 2524 2523 type); 2525 2524 return; … … 2533 2532 { 2534 2533 case OPS_PARSE_RAW: 2535 p arse_info->ss_raw[t8] |= t7;2536 p arse_info->ss_parsed[t8] &= ~t7;2534 pinfo->ss_raw[t8] |= t7; 2535 pinfo->ss_parsed[t8] &= ~t7; 2537 2536 break; 2538 2537 2539 2538 case OPS_PARSE_PARSED: 2540 p arse_info->ss_raw[t8] &= ~t7;2541 p arse_info->ss_parsed[t8] |= t7;2539 pinfo->ss_raw[t8] &= ~t7; 2540 pinfo->ss_parsed[t8] |= t7; 2542 2541 break; 2543 2542 2544 2543 case OPS_PARSE_IGNORE: 2545 p arse_info->ss_raw[t8] &= ~t7;2546 p arse_info->ss_parsed[t8] &= ~t7;2544 pinfo->ss_raw[t8] &= ~t7; 2545 pinfo->ss_parsed[t8] &= ~t7; 2547 2546 break; 2548 2547 }
