Changeset 620
- Timestamp:
- 09/09/08 11:12:43
- Files:
-
- openpgpsdk/trunk/include/openpgpsdk/armour.h (modified) (1 diff)
- openpgpsdk/trunk/src/lib/crypto.c (modified) (1 diff)
- openpgpsdk/trunk/src/lib/keyring.c (modified) (2 diffs)
- openpgpsdk/trunk/src/lib/packet-print.c (modified) (1 diff)
- openpgpsdk/trunk/src/lib/reader_armoured.c (modified) (2 diffs)
- openpgpsdk/trunk/src/lib/validate.c (modified) (1 diff)
- openpgpsdk/trunk/tests/test_rsa_decrypt.c (modified) (1 diff)
- openpgpsdk/trunk/tests/test_rsa_encrypt.c (modified) (1 diff)
- openpgpsdk/trunk/tests/test_rsa_signature.c (modified) (4 diffs)
- openpgpsdk/trunk/tests/test_rsa_verify.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
openpgpsdk/trunk/include/openpgpsdk/armour.h
r574 r620 28 28 unsigned ops_crc24(unsigned checksum,unsigned char c); 29 29 30 void ops_reader_push_dearmour(ops_parse_info_t *parse_info, 31 ops_boolean_t without_gap, 32 ops_boolean_t no_gap, 33 ops_boolean_t trailing_whitespace); 30 void ops_reader_push_dearmour(ops_parse_info_t *parse_info); 34 31 35 32 void ops_reader_pop_dearmour(ops_parse_info_t *parse_info); openpgpsdk/trunk/src/lib/crypto.c
r619 r620 292 292 293 293 if (use_armour) 294 ops_reader_push_dearmour(pinfo ,ops_false,ops_false,ops_false);294 ops_reader_push_dearmour(pinfo); 295 295 296 296 // Do it openpgpsdk/trunk/src/lib/keyring.c
r619 r620 564 564 565 565 if (armour) 566 { ops_reader_push_dearmour(pinfo , ops_false, ops_false, ops_false); }566 { ops_reader_push_dearmour(pinfo); } 567 567 568 568 if ( ops_parse_and_accumulate(keyring,pinfo) == 0 ) { … … 628 628 629 629 if (armour) 630 { ops_reader_push_dearmour(pinfo , ops_false, ops_false, ops_false); }630 { ops_reader_push_dearmour(pinfo); } 631 631 632 632 if ( ops_parse_and_accumulate(keyring,pinfo) == 0 ) openpgpsdk/trunk/src/lib/packet-print.c
r616 r620 1806 1806 1807 1807 if(armour) 1808 ops_reader_push_dearmour(pinfo ,ops_true,ops_true,ops_true);1808 ops_reader_push_dearmour(pinfo); 1809 1809 1810 1810 ops_parse_and_print_errors(pinfo); openpgpsdk/trunk/src/lib/reader_armoured.c
r618 r620 994 994 * \brief Pushes dearmouring reader onto stack 995 995 * \param parse_info Usual structure containing information about to how to do the parse 996 * \param without_gap Allow headers in armoured data that are not separated from the data by a blank line997 * \param no_gap Allow no blank line at the start of armoured data998 * \param trailing_whitespace Allow armoured data to have trailing whitespace where we strictly would not expect it999 996 * \sa ops_reader_pop_dearmour() 1000 997 */ 1001 void ops_reader_push_dearmour(ops_parse_info_t *parse_info, 1002 ops_boolean_t without_gap, 1003 ops_boolean_t no_gap, 1004 ops_boolean_t trailing_whitespace) 998 void ops_reader_push_dearmour(ops_parse_info_t *parse_info) 999 /* 1000 This function originally had these parameters to cater for 1001 packets which didn't strictly match the RFC. 1002 The initial 0.5 release is only going to support 1003 strict checking. 1004 If it becomes desirable to support loose checking of armoured packets 1005 and these params are reinstated, parse_headers() must be fixed 1006 so that these flags work correctly. 1007 1008 // Allow headers in armoured data that are not separated from the data by a blank line 1009 ops_boolean_t without_gap, 1010 1011 // Allow no blank line at the start of armoured data 1012 ops_boolean_t no_gap, 1013 1014 //Allow armoured data to have trailing whitespace where we strictly would not expect it 1015 ops_boolean_t trailing_whitespace 1016 */ 1005 1017 { 1006 1018 dearmour_arg_t *arg; … … 1008 1020 arg=ops_mallocz(sizeof *arg); 1009 1021 arg->seen_nl=ops_true; 1022 /* 1010 1023 arg->allow_headers_without_gap=without_gap; 1011 1024 arg->allow_no_gap=no_gap; 1012 1025 arg->allow_trailing_whitespace=trailing_whitespace; 1013 1026 */ 1014 1027 arg->expect_sig=ops_false; 1015 1028 arg->got_sig=ops_false; openpgpsdk/trunk/src/lib/validate.c
r619 r620 609 609 610 610 if (armoured) 611 ops_reader_push_dearmour(pinfo ,ops_false,ops_false,ops_false);611 ops_reader_push_dearmour(pinfo); 612 612 613 613 // Do the verification openpgpsdk/trunk/tests/test_rsa_decrypt.c
r619 r620 155 155 156 156 if (has_armour) 157 ops_reader_push_dearmour(pinfo ,ops_false,ops_false,ops_false);157 ops_reader_push_dearmour(pinfo); 158 158 159 159 // setup for writing parsed data to mem_out openpgpsdk/trunk/tests/test_rsa_encrypt.c
r618 r620 150 150 // other setup 151 151 if (use_armour) 152 ops_reader_push_dearmour(pinfo ,ops_false,ops_false,ops_false);152 ops_reader_push_dearmour(pinfo); 153 153 154 154 // do it openpgpsdk/trunk/tests/test_rsa_signature.c
r617 r620 148 148 // Must de-armour because it's clearsigned 149 149 150 ops_reader_push_dearmour(pinfo ,ops_false,ops_false,ops_false);150 ops_reader_push_dearmour(pinfo); 151 151 152 152 // Do the verification … … 252 252 // Must de-armour because it's clearsigned 253 253 254 ops_reader_push_dearmour(pinfo ,ops_false,ops_false,ops_false);254 ops_reader_push_dearmour(pinfo); 255 255 256 256 // Do the verification … … 342 342 343 343 if (use_armour) 344 ops_reader_push_dearmour(pinfo ,ops_false,ops_false,ops_false);344 ops_reader_push_dearmour(pinfo); 345 345 346 346 // Do the verification … … 407 407 408 408 if (use_armour) 409 ops_reader_push_dearmour(pinfo ,ops_false,ops_false,ops_false);409 ops_reader_push_dearmour(pinfo); 410 410 411 411 // Do the verification openpgpsdk/trunk/tests/test_rsa_verify.c
r618 r620 59 59 60 60 static int num_malformed=0; 61 static int num_wellformed=0; 61 62 62 63 typedef ops_parse_cb_return_t (*ops_callback)(const ops_parser_content_t *, ops_parse_cb_info_t *); … … 70 71 snprintf(filename,maxlen,"malformed_%d.txt",i); 71 72 } 73 74 static void make_filename_wellformed(char* filename, int maxlen, const int i) 75 { 76 snprintf(filename,maxlen,"wellformed_%d.txt",i); 77 } 78 79 static void create_wellformed_testfiles() 80 { 81 int i=0; 82 int fd=0; 83 char* wellformed[]= 84 { 85 // no headers 86 "-----BEGIN PGP SIGNED MESSAGE-----\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", 87 }; 88 num_wellformed=sizeof (wellformed)/sizeof(char *); 89 for (i=0; i<num_wellformed; i++) 90 { 91 char fullname[MAXBUF]; 92 char filename[MAXBUF]; 93 make_filename_wellformed(filename,MAXBUF,i); 94 snprintf(fullname,MAXBUF,"%s/%s.asc",dir,filename); 95 if ((fd=open(fullname,O_WRONLY | O_CREAT, 0600)) < 0) 96 { 97 fprintf(stderr,"create_wellformed_testfiles: cannot open file %s for writing\n", fullname); 98 return; 99 } 100 write(fd,wellformed[i],strlen(wellformed[i])); 101 close(fd); 102 } 103 } 72 104 73 105 static void create_malformed_testfiles() … … 102 134 "-----BEGIN PGP SIGNED MESSAGE-----\nUnknown: Header\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", 103 135 // bad armour trailer 104 "-----BEGIN PGP SIGNED MESSAGE-----\nHash: SHA1\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 PPP SIGNATURE-----\n-----END PGP SIGNATURE-----", 136 "-----BEGIN PGP SIGNED MESSAGE-----\nHash: SHA1\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 PPP SIGNATURE-----\n-----END PGP SIGNATURE-----", 137 // no headers and no gap 138 "-----BEGIN PGP SIGNED MESSAGE-----\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", 105 139 }; 106 140 num_malformed=sizeof (malformed)/sizeof(char *); … … 139 173 140 174 create_malformed_testfiles(); 175 create_wellformed_testfiles(); 141 176 142 177 // Now sign the test files with GPG … … 310 345 311 346 if (has_armour) 312 ops_reader_push_dearmour(pinfo ,ops_false,ops_false,ops_false);347 ops_reader_push_dearmour(pinfo); 313 348 314 349 // Do the verification … … 378 413 if (errstack) 379 414 { 415 CU_ASSERT(ops_has_error(errstack,expected_errcode)); 380 416 if (!ops_has_error(errstack,expected_errcode)) 417 { 418 printf("\nfilename=%s: errstack->errcode=0x%2x\n", filename, errstack->errcode); 419 ops_print_errors(errstack); 420 } 421 } 422 CU_ASSERT(rtn==0); 423 424 // clean up 425 ops_parse_info_delete(pinfo); 426 } 427 428 static void test_rsa_verify_wellformed(const int has_armour, const char *filename, ops_callback callback) 429 { 430 int rtn=0; 431 ops_parse_info_t *pinfo=NULL; 432 ops_callback cb=NULL; 433 ops_error_t* errstack=NULL; 434 435 cb = callback==NULL ? callback_verify : callback; 436 437 // setup 438 pinfo=ops_parse_info_new(); 439 440 // parse 441 rtn=test_rsa_verify(has_armour, filename, cb, pinfo); 442 443 // handle result - should fail with UNKNOWN SIGNER but not BAD FORMAT 444 errstack=ops_parse_info_get_errors(pinfo); 445 446 CU_ASSERT(errstack!=NULL); 447 448 // print out errors if we have actually got a different error 449 // to the one expected 450 if (errstack) 451 { 452 CU_ASSERT(ops_has_error(errstack,OPS_E_V_UNKNOWN_SIGNER)); 453 CU_ASSERT(!ops_has_error(errstack,OPS_E_R_BAD_FORMAT)); 454 if (ops_has_error(errstack,OPS_E_R_BAD_FORMAT) 455 || !ops_has_error(errstack,OPS_E_V_UNKNOWN_SIGNER)) 381 456 { 382 457 printf("\nfilename=%s: errstack->errcode=0x%2x\n", filename, errstack->errcode); … … 538 613 } 539 614 615 static void test_rsa_verify_clearsign_fail_wellformed_msg(void) 616 { 617 int i=0; 618 int armour=1; 619 assert(pub_keyring.nkeys); 620 621 for (i=0; i<num_wellformed; i++) 622 { 623 char filename[MAXBUF]; 624 make_filename_wellformed(filename,MAXBUF,i); 625 test_rsa_verify_wellformed(armour,filename,NULL); 626 } 627 } 628 540 629 CU_pSuite suite_rsa_verify() 541 630 { … … 583 672 return NULL; 584 673 674 if (NULL == CU_add_test(suite, "Clearsign: should not get BAD FORMAT on wellformed message", test_rsa_verify_clearsign_fail_wellformed_msg)) 675 return NULL; 676 585 677 return suite; 586 678 }
