Changeset 620

Show
Ignore:
Timestamp:
09/09/08 11:12:43
Author:
rachel
Message:

Added test to verify armoured message with no headers is OK.
Enforce strict checking of armoured messages.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • openpgpsdk/trunk/include/openpgpsdk/armour.h

    r574 r620  
    2828unsigned ops_crc24(unsigned checksum,unsigned char c); 
    2929 
    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); 
     30void ops_reader_push_dearmour(ops_parse_info_t *parse_info); 
    3431 
    3532void ops_reader_pop_dearmour(ops_parse_info_t *parse_info); 
  • openpgpsdk/trunk/src/lib/crypto.c

    r619 r620  
    292292 
    293293    if (use_armour) 
    294         ops_reader_push_dearmour(pinfo,ops_false,ops_false,ops_false); 
     294        ops_reader_push_dearmour(pinfo); 
    295295     
    296296    // Do it 
  • openpgpsdk/trunk/src/lib/keyring.c

    r619 r620  
    564564 
    565565    if (armour) 
    566         { ops_reader_push_dearmour(pinfo, ops_false, ops_false, ops_false); } 
     566        { ops_reader_push_dearmour(pinfo); } 
    567567 
    568568    if ( ops_parse_and_accumulate(keyring,pinfo) == 0 ) { 
     
    628628 
    629629    if (armour) 
    630         { ops_reader_push_dearmour(pinfo, ops_false, ops_false, ops_false); } 
     630        { ops_reader_push_dearmour(pinfo); } 
    631631 
    632632    if ( ops_parse_and_accumulate(keyring,pinfo) == 0 )  
  • openpgpsdk/trunk/src/lib/packet-print.c

    r616 r620  
    18061806 
    18071807    if(armour) 
    1808         ops_reader_push_dearmour(pinfo,ops_true,ops_true,ops_true); 
     1808        ops_reader_push_dearmour(pinfo); 
    18091809 
    18101810    ops_parse_and_print_errors(pinfo); 
  • openpgpsdk/trunk/src/lib/reader_armoured.c

    r618 r620  
    994994 * \brief Pushes dearmouring reader onto stack 
    995995 * \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 line 
    997  * \param no_gap Allow no blank line at the start of armoured data 
    998  * \param trailing_whitespace Allow armoured data to have trailing whitespace where we strictly would not expect it 
    999996 * \sa ops_reader_pop_dearmour() 
    1000997 */ 
    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) 
     998void 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    */ 
    10051017    { 
    10061018    dearmour_arg_t *arg; 
     
    10081020    arg=ops_mallocz(sizeof *arg); 
    10091021    arg->seen_nl=ops_true; 
     1022/* 
    10101023    arg->allow_headers_without_gap=without_gap; 
    10111024    arg->allow_no_gap=no_gap; 
    10121025    arg->allow_trailing_whitespace=trailing_whitespace; 
    1013  
     1026*/ 
    10141027    arg->expect_sig=ops_false; 
    10151028    arg->got_sig=ops_false; 
  • openpgpsdk/trunk/src/lib/validate.c

    r619 r620  
    609609 
    610610    if (armoured) 
    611         ops_reader_push_dearmour(pinfo,ops_false,ops_false,ops_false); 
     611        ops_reader_push_dearmour(pinfo); 
    612612     
    613613    // Do the verification 
  • openpgpsdk/trunk/tests/test_rsa_decrypt.c

    r619 r620  
    155155 
    156156    if (has_armour) 
    157         ops_reader_push_dearmour(pinfo,ops_false,ops_false,ops_false); 
     157        ops_reader_push_dearmour(pinfo); 
    158158     
    159159    // setup for writing parsed data to mem_out 
  • openpgpsdk/trunk/tests/test_rsa_encrypt.c

    r618 r620  
    150150    // other setup 
    151151    if (use_armour) 
    152         ops_reader_push_dearmour(pinfo,ops_false,ops_false,ops_false); 
     152        ops_reader_push_dearmour(pinfo); 
    153153 
    154154    // do it 
  • openpgpsdk/trunk/tests/test_rsa_signature.c

    r617 r620  
    148148    // Must de-armour because it's clearsigned 
    149149     
    150     ops_reader_push_dearmour(pinfo,ops_false,ops_false,ops_false); 
     150    ops_reader_push_dearmour(pinfo); 
    151151     
    152152    // Do the verification 
     
    252252    // Must de-armour because it's clearsigned 
    253253     
    254     ops_reader_push_dearmour(pinfo,ops_false,ops_false,ops_false); 
     254    ops_reader_push_dearmour(pinfo); 
    255255     
    256256    // Do the verification 
     
    342342     
    343343    if (use_armour) 
    344         ops_reader_push_dearmour(pinfo,ops_false,ops_false,ops_false); 
     344        ops_reader_push_dearmour(pinfo); 
    345345     
    346346    // Do the verification 
     
    407407     
    408408    if (use_armour) 
    409         ops_reader_push_dearmour(pinfo,ops_false,ops_false,ops_false); 
     409        ops_reader_push_dearmour(pinfo); 
    410410     
    411411    // Do the verification 
  • openpgpsdk/trunk/tests/test_rsa_verify.c

    r618 r620  
    5959 
    6060static int num_malformed=0; 
     61static int num_wellformed=0; 
    6162 
    6263typedef ops_parse_cb_return_t (*ops_callback)(const ops_parser_content_t *, ops_parse_cb_info_t *); 
     
    7071    snprintf(filename,maxlen,"malformed_%d.txt",i); 
    7172    } 
     73 
     74static void make_filename_wellformed(char* filename, int maxlen, const int i) 
     75    { 
     76    snprintf(filename,maxlen,"wellformed_%d.txt",i); 
     77    } 
     78 
     79static 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} 
    72104 
    73105static void create_malformed_testfiles() 
     
    102134        "-----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", 
    103135        // 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", 
    105139    }; 
    106140    num_malformed=sizeof (malformed)/sizeof(char *); 
     
    139173 
    140174    create_malformed_testfiles(); 
     175    create_wellformed_testfiles(); 
    141176 
    142177    // Now sign the test files with GPG 
     
    310345 
    311346    if (has_armour) 
    312         ops_reader_push_dearmour(pinfo,ops_false,ops_false,ops_false); 
     347        ops_reader_push_dearmour(pinfo); 
    313348     
    314349    // Do the verification 
     
    378413    if (errstack) 
    379414        { 
     415        CU_ASSERT(ops_has_error(errstack,expected_errcode)); 
    380416        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 
     428static 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)) 
    381456            { 
    382457            printf("\nfilename=%s: errstack->errcode=0x%2x\n", filename, errstack->errcode); 
     
    538613    } 
    539614 
     615static 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 
    540629CU_pSuite suite_rsa_verify() 
    541630{ 
     
    583672            return NULL; 
    584673 
     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 
    585677    return suite; 
    586678}