Changeset 608
- Timestamp:
- 08/29/08 12:40:55
- Files:
-
- openpgpsdk/trunk/src/lib/packet-parse.c (modified) (1 diff)
- openpgpsdk/trunk/src/lib/validate.c (modified) (6 diffs)
- openpgpsdk/trunk/tests/test_rsa_verify.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
openpgpsdk/trunk/src/lib/packet-parse.c
r602 r608 1239 1239 unsigned char c[1]; 1240 1240 ops_parser_content_t content; 1241 1242 // clear signature 1243 memset(&C.signature,'\0',sizeof C.signature); 1241 1244 1242 1245 C.signature.info.version=OPS_V3; openpgpsdk/trunk/src/lib/validate.c
r602 r608 55 55 hash.init(&hash); 56 56 hash.add(&hash,data,len); 57 hash.add(&hash,sig->info.v4_hashed_data,sig->info.v4_hashed_data_length); 58 59 trailer[0]=0x04; // version 60 trailer[1]=0xFF; 61 hashedlen=sig->info.v4_hashed_data_length; 62 trailer[2]=hashedlen >> 24; 63 trailer[3]=hashedlen >> 16; 64 trailer[4]=hashedlen >> 8; 65 trailer[5]=hashedlen; 66 hash.add(&hash,&trailer[0],6); 57 switch (sig->info.version) 58 { 59 case OPS_V3: 60 trailer[0]=sig->info.type; 61 trailer[1]=sig->info.creation_time >> 24; 62 trailer[2]=sig->info.creation_time >> 16; 63 trailer[3]=sig->info.creation_time >> 8; 64 trailer[4]=sig->info.creation_time; 65 hash.add(&hash,&trailer[0],5); 66 break; 67 68 case OPS_V4: 69 hash.add(&hash,sig->info.v4_hashed_data,sig->info.v4_hashed_data_length); 70 71 trailer[0]=0x04; // version 72 trailer[1]=0xFF; 73 hashedlen=sig->info.v4_hashed_data_length; 74 trailer[2]=hashedlen >> 24; 75 trailer[3]=hashedlen >> 16; 76 trailer[4]=hashedlen >> 8; 77 trailer[5]=hashedlen; 78 hash.add(&hash,&trailer[0],6); 79 80 break; 81 82 default: 83 fprintf(stderr,"Invalid signature version %d\n", sig->info.version); 84 return ops_false; 85 } 67 86 68 87 n=hash.finish(&hash,hashout); … … 221 240 return OPS_KEEP_MEMORY; 222 241 223 case OPS_PTAG_CT_SIGNATURE_FOOTER: 242 case OPS_PTAG_CT_SIGNATURE: // V3 sigs 243 case OPS_PTAG_CT_SIGNATURE_FOOTER: // V4 sigs 224 244 /* 225 245 printf(" type=%02x signer_id=",content->signature.type); … … 305 325 case OPS_PARSER_PTAG: 306 326 case OPS_PTAG_CT_SIGNATURE_HEADER: 307 case OPS_PTAG_CT_SIGNATURE: 308 case OPS_PARSER_PACKET_END: 327 case OPS_PARSER_PACKET_END: 309 328 break; 310 329 … … 366 385 367 386 case OPS_PTAG_CT_SIGNATURE: // V3 sigs 368 // this gives us a signature struct with all info about hash alg, etc from the packet369 break;370 371 387 case OPS_PTAG_CT_SIGNATURE_FOOTER: // V4 sigs 372 388 … … 436 452 { 437 453 add_sig_to_valid_list(arg->result, &content->signature.info); 438 // ++arg->result->valid_count;439 454 } 440 455 else 441 456 { 442 457 OPS_ERROR(errors,OPS_E_V_BAD_SIGNATURE,"Bad Signature"); 443 // printf(" BAD SIGNATURE\n");444 // ++arg->result->invalid_count;445 458 add_sig_to_invalid_list(arg->result, &content->signature.info); 446 459 } … … 454 467 case OPS_PTAG_CT_ONE_PASS_SIGNATURE: 455 468 case OPS_PARSER_PACKET_END: 456 // case OPS_PTAG_CT_SIGNATURE:457 469 break; 458 470 openpgpsdk/trunk/tests/test_rsa_verify.c
r607 r608 54 54 55 55 static char *filename_rsa_v3sig="gpg_rsa_sign_v3sig.txt"; 56 static char *filename_rsa_v3sig_fail_bad_sig="gpg_rsa_sign_v3sig_fail_bad_sig.txt"; 56 57 57 58 static char *filename_rsa_hash_md5="gpg_rsa_hash_md5.txt"; … … 111 112 112 113 create_small_testfile(filename_rsa_v3sig); 114 create_small_testfile(filename_rsa_v3sig_fail_bad_sig); 113 115 create_small_testfile(filename_rsa_hash_md5); 114 116 … … 155 157 dir, filename_rsa_v3sig, 156 158 gpgcmd, alpha_name, dir, filename_rsa_v3sig); 159 if (system(cmd)) 160 { return 1; } 161 162 // V3 signature to fail 163 snprintf(cmd,sizeof cmd,"cat %s/%s | %s --compress-level 0 --sign --force-v3-sigs --local-user %s > %s/%s.gpg", 164 dir, filename_rsa_v3sig_fail_bad_sig, 165 gpgcmd, alpha_name, dir, filename_rsa_v3sig_fail_bad_sig); 157 166 if (system(cmd)) 158 167 { return 1; } … … 474 483 } 475 484 485 static void test_rsa_verify_v3sig_fail_bad_sig(void) 486 { 487 int armour=0; 488 assert(pub_keyring.nkeys); 489 490 test_rsa_verify_fail(armour,filename_rsa_v3sig_fail_bad_sig, callback_bad_sig, OPS_E_V_BAD_SIGNATURE); 491 } 492 476 493 static void test_rsa_verify_clearsign_fail_bad_sig(void) 477 494 { … … 527 544 return NULL; 528 545 546 if (NULL == CU_add_test(suite, "V3 signature: should fail on bad sig", test_rsa_verify_v3sig_fail_bad_sig)) 547 return NULL; 548 529 549 if (NULL == CU_add_test(suite, "MD5 Hash", test_rsa_verify_hash_md5)) 530 550 return NULL;
