Changeset 517

Show
Ignore:
Timestamp:
10/18/07 13:01:04
Author:
rachel
Message:

Added OPS_E_UNIMPLEMENTED error
Changed cbinfo struct to support stacked errors in callbacks
Changed RSA encryption test *NOT* to enforce writing of multiple packets
Changed RSA signature test to use OPS validation

Files:

Legend:

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

    r516 r517  
    99 
    1010/** error codes */ 
     11// Remember to add names to map in adv_errors.c 
    1112typedef enum  
    1213    { 
     
    1415    OPS_E_FAIL=0x0001,  /* general error */ 
    1516    OPS_E_SYSTEM_ERROR=0x0002, /* system error, look at errno for details */ 
     17    OPS_E_UNIMPLEMENTED=0x0003, /* feature not yet implemented */ 
    1618 
    1719    /* reader errors */ 
  • openpgpsdk/trunk/include/openpgpsdk/packet-parse.h

    r470 r517  
    9999void ops_parse_cb_push(ops_parse_info_t *pinfo,ops_parse_cb_t *cb,void *arg); 
    100100void *ops_parse_cb_get_arg(ops_parse_cb_info_t *cbinfo); 
     101void *ops_parse_cb_get_errors(ops_parse_cb_info_t *cbinfo); 
    101102void ops_reader_set(ops_parse_info_t *pinfo,ops_reader_t *reader,ops_reader_destroyer_t *destroyer,void *arg); 
    102103void ops_reader_push(ops_parse_info_t *pinfo,ops_reader_t *reader,ops_reader_destroyer_t *destroyer,void *arg); 
  • openpgpsdk/trunk/include/openpgpsdk/validate.h

    r454 r517  
    1010void ops_key_data_reader_set(ops_parse_info_t *pinfo, 
    1111                             const ops_key_data_t *key); 
     12 
     13typedef struct 
     14    { 
     15    const ops_key_data_t *key; 
     16    unsigned packet; 
     17    unsigned offset; 
     18    } validate_reader_arg_t; 
     19 
     20typedef struct 
     21    { 
     22    ops_public_key_t pkey; 
     23    ops_public_key_t subkey; 
     24    enum 
     25        { 
     26        ATTRIBUTE, 
     27        ID 
     28        } last_seen; 
     29    ops_user_id_t user_id; 
     30    ops_user_attribute_t user_attribute; 
     31    const ops_keyring_t *keyring; 
     32    validate_reader_arg_t *rarg; 
     33    ops_validate_result_t *result; 
     34    } validate_cb_arg_t; 
     35 
     36// EOF 
  • openpgpsdk/trunk/plan/OpenPGP.omniplan/contents.xml

    r513 r517  
    3333                        <false/> 
    3434                        <key>GanttVisibleRect</key> 
    35                         <string>{{-15, 398}, {622, 640}}</string> 
     35                        <string>{{-15, 337}, {622, 640}}</string> 
    3636                        <key>OutlineVisibleRect</key> 
    37                         <string>{{0, 398}, {634, 640}}</string> 
     37                        <string>{{0, 337}, {634, 640}}</string> 
    3838                        <key>SelectedPlanView</key> 
    3939                        <integer>1</integer> 
     
    479479        <dict> 
    480480                <key>nextId</key> 
    481                 <integer>145</integer> 
     481                <integer>161</integer> 
    482482        </dict> 
    483483        <key>taskUserKeys</key> 
     
    505505                        <real>22.399999618530273</real> 
    506506                        <key>workSeconds</key> 
    507                         <real>2283840</real> 
    508                         <key>workTime</key> 
    509                         <real>634.4000244140625</real> 
     507                        <real>2543040</real> 
     508                        <key>workTime</key> 
     509                        <real>706.4000244140625</real> 
    510510                </dict> 
    511511                <dict> 
     
    579579                                <integer>132</integer> 
    580580                                <integer>138</integer> 
     581                                <integer>145</integer> 
     582                                <integer>150</integer> 
    581583                        </array> 
    582584                        <key>objectId</key> 
     
    585587                        <string>Finish Implementation</string> 
    586588                        <key>workSeconds</key> 
    587                         <real>633600</real> 
    588                         <key>workTime</key> 
    589                         <real>176</real> 
     589                        <real>691200</real> 
     590                        <key>workTime</key> 
     591                        <real>192</real> 
    590592                </dict> 
    591593                <dict> 
     
    810812                                <integer>133</integer> 
    811813                                <integer>126</integer> 
     814                                <integer>156</integer> 
     815                                <integer>157</integer> 
     816                                <integer>158</integer> 
     817                                <integer>159</integer> 
    812818                        </array> 
    813819                        <key>doneSeconds</key> 
     
    820826                        <real>12</real> 
    821827                        <key>workSeconds</key> 
    822                         <real>547200</real> 
    823                         <key>workTime</key> 
    824                         <real>152</real> 
     828                        <real>662400</real> 
     829                        <key>workTime</key> 
     830                        <real>184</real> 
    825831                </dict> 
    826832                <dict> 
     
    917923                        <real>10.399999618530273</real> 
    918924                        <key>workSeconds</key> 
    919                         <real>584640</real> 
    920                         <key>workTime</key> 
    921                         <real>162.39999389648438</real> 
     925                        <real>671040</real> 
     926                        <key>workTime</key> 
     927                        <real>186.39999389648438</real> 
    922928                </dict> 
    923929                <dict> 
     
    927933                                <integer>51</integer> 
    928934                                <integer>56</integer> 
     935                                <integer>151</integer> 
     936                                <integer>152</integer> 
    929937                        </array> 
    930938                        <key>doneSeconds</key> 
     
    964972                        <real>4</real> 
    965973                        <key>workSeconds</key> 
    966                         <real>129600</real> 
    967                         <key>workTime</key> 
    968                         <real>36</real> 
     974                        <real>187200</real> 
     975                        <key>workTime</key> 
     976                        <real>52</real> 
    969977                </dict> 
    970978                <dict> 
     
    976984                                <integer>116</integer> 
    977985                                <integer>125</integer> 
     986                                <integer>154</integer> 
    978987                        </array> 
    979988                        <key>doneSeconds</key> 
     
    988997                        <real>6.4000000953674316</real> 
    989998                        <key>workSeconds</key> 
    990                         <real>138240</real> 
    991                         <key>workTime</key> 
    992                         <real>38.400001525878906</real> 
     999                        <real>167040</real> 
     1000                        <key>workTime</key> 
     1001                        <real>46.400001525878906</real> 
    9931002                </dict> 
    9941003                <dict> 
     
    35663575                        <key>workTime</key> 
    35673576                        <real>16</real> 
     3577                </dict> 
     3578                <dict> 
     3579                        <key>objectId</key> 
     3580                        <integer>145</integer> 
     3581                        <key>task</key> 
     3582                        <string>Integrate stream encryption</string> 
     3583                        <key>workSeconds</key> 
     3584                        <real>28800</real> 
     3585                        <key>workTime</key> 
     3586                        <real>8</real> 
     3587                </dict> 
     3588                <dict> 
     3589                        <key>objectId</key> 
     3590                        <integer>150</integer> 
     3591                        <key>task</key> 
     3592                        <string>Triple-DES</string> 
     3593                        <key>workSeconds</key> 
     3594                        <real>28800</real> 
     3595                        <key>workTime</key> 
     3596                        <real>8</real> 
     3597                </dict> 
     3598                <dict> 
     3599                        <key>objectId</key> 
     3600                        <integer>151</integer> 
     3601                        <key>task</key> 
     3602                        <string>Large files</string> 
     3603                        <key>workSeconds</key> 
     3604                        <real>28800</real> 
     3605                        <key>workTime</key> 
     3606                        <real>8</real> 
     3607                </dict> 
     3608                <dict> 
     3609                        <key>objectId</key> 
     3610                        <integer>152</integer> 
     3611                        <key>task</key> 
     3612                        <string>Stream encryption</string> 
     3613                        <key>workSeconds</key> 
     3614                        <real>28800</real> 
     3615                        <key>workTime</key> 
     3616                        <real>8</real> 
     3617                </dict> 
     3618                <dict> 
     3619                        <key>objectId</key> 
     3620                        <integer>154</integer> 
     3621                        <key>task</key> 
     3622                        <string>Large files</string> 
     3623                        <key>workSeconds</key> 
     3624                        <real>28800</real> 
     3625                        <key>workTime</key> 
     3626                        <real>8</real> 
     3627                </dict> 
     3628                <dict> 
     3629                        <key>objectId</key> 
     3630                        <integer>156</integer> 
     3631                        <key>task</key> 
     3632                        <string>Create Key Pair with OPS, test with GPG</string> 
     3633                        <key>workSeconds</key> 
     3634                        <real>28800</real> 
     3635                        <key>workTime</key> 
     3636                        <real>8</real> 
     3637                </dict> 
     3638                <dict> 
     3639                        <key>objectId</key> 
     3640                        <integer>157</integer> 
     3641                        <key>task</key> 
     3642                        <string>Create Key Pair with GPG, test with OPS</string> 
     3643                        <key>workSeconds</key> 
     3644                        <real>28800</real> 
     3645                        <key>workTime</key> 
     3646                        <real>8</real> 
     3647                </dict> 
     3648                <dict> 
     3649                        <key>objectId</key> 
     3650                        <integer>158</integer> 
     3651                        <key>task</key> 
     3652                        <string>Sign Key with OPS, verify with GPG</string> 
     3653                        <key>workSeconds</key> 
     3654                        <real>28800</real> 
     3655                        <key>workTime</key> 
     3656                        <real>8</real> 
     3657                </dict> 
     3658                <dict> 
     3659                        <key>objectId</key> 
     3660                        <integer>159</integer> 
     3661                        <key>task</key> 
     3662                        <string>Sign Key with GPG, verify with OPS</string> 
     3663                        <key>workSeconds</key> 
     3664                        <real>28800</real> 
     3665                        <key>workTime</key> 
     3666                        <real>8</real> 
    35683667                </dict> 
    35693668        </array> 
  • openpgpsdk/trunk/src/advanced/adv_errors.c

    r516 r517  
    2424    { OPS_E_FAIL, "OPS_E_FAIL" }, 
    2525    { OPS_E_SYSTEM_ERROR, "OPS_E_SYSTEM_ERROR" }, 
     26    { OPS_E_UNIMPLEMENTED, "OPS_E_UNIMPLEMENTED" }, 
    2627 
    2728    { OPS_E_R,  "OPS_E_R" }, 
  • openpgpsdk/trunk/src/advanced/adv_packet-parse.c

    r516 r517  
    30453045    pinfo->cbinfo.cb=cb; 
    30463046    pinfo->cbinfo.arg=arg; 
     3047    pinfo->cbinfo.errors=&pinfo->errors; 
    30473048    } 
    30483049 
     
    30583059void *ops_parse_cb_get_arg(ops_parse_cb_info_t *cbinfo) 
    30593060    { return cbinfo->arg; } 
     3061 
     3062void *ops_parse_cb_get_errors(ops_parse_cb_info_t *cbinfo) 
     3063    { return cbinfo->errors; } 
    30603064 
    30613065ops_parse_cb_return_t ops_parse_cb(const ops_parser_content_t *content, 
  • openpgpsdk/trunk/src/advanced/adv_validate.c

    r503 r517  
    1010#include <openpgpsdk/final.h> 
    1111 
    12 typedef struct 
    13     { 
    14     const ops_key_data_t *key; 
    15     unsigned packet; 
    16     unsigned offset; 
    17     } validate_reader_arg_t; 
    18  
    19 typedef struct 
    20     { 
    21     ops_public_key_t pkey; 
    22     ops_public_key_t subkey; 
    23     enum 
    24         { 
    25         ATTRIBUTE, 
    26         ID 
    27         } last_seen; 
    28     ops_user_id_t user_id; 
    29     ops_user_attribute_t user_attribute; 
    30     const ops_keyring_t *keyring; 
    31     validate_reader_arg_t *rarg; 
    32     ops_validate_result_t *result; 
    33     } validate_cb_arg_t; 
    34  
    3512static int key_data_reader(void *dest,size_t length,ops_error_t **errors, 
    3613                           ops_reader_info_t *rinfo, 
     
    6845    const ops_parser_content_union_t *content=&content_->content; 
    6946    validate_cb_arg_t *arg=ops_parse_cb_get_arg(cbinfo); 
     47    ops_error_t **errors=ops_parse_cb_get_errors(cbinfo); 
    7048    const ops_key_data_t *signer; 
    71     ops_boolean_t valid
     49    ops_boolean_t valid=ops_false
    7250 
    7351    switch(content_->tag) 
     
    151129            break; 
    152130 
     131    case OPS_SIG_BINARY: 
     132    case OPS_SIG_TEXT: 
     133    case OPS_SIG_STANDALONE: 
     134    case OPS_SIG_PRIMARY: 
     135    case OPS_SIG_REV_KEY: 
     136    case OPS_SIG_REV_SUBKEY: 
     137    case OPS_SIG_TIMESTAMP: 
     138    case OPS_SIG_3RD_PARTY: 
     139        OPS_ERROR_1(errors, OPS_E_UNIMPLEMENTED, 
     140                    "Verification of signature type 0x%02x not yet implemented\n", content->signature.type); 
     141                    break; 
     142 
    153143        default: 
    154144            fprintf(stderr,"Unexpected signature type=0x%02x\n", 
     
    156146            exit(1); 
    157147            } 
     148 
    158149        if(valid) 
    159150            { 
  • openpgpsdk/trunk/src/advanced/parse_local.h

    r470 r517  
    2525    ops_parse_cb_t *cb; /*!< the callback function to use when parsing */ 
    2626    void *arg; /*!< the args to pass to the callback function */ 
     27    ops_error_t** errors; /*!< the address of the error stack to use */ 
    2728 
    2829    ops_parse_cb_info_t *next; 
  • openpgpsdk/trunk/tests/Makefile.template

    r503 r517  
    1212LIBS=$(LIBDEPS) %CRYPTO_LIBS% %ZLIB% $(DM_LIB) $(CUNIT_LIB) 
    1313 
    14 TESTSRC=tests.c \ 
    15                 test_packet_types.c \ 
     14COMMONTESTSRC= test_packet_types.c \ 
    1615                test_crypt_mpi.c test_rsa_decrypt.c test_rsa_encrypt.c \ 
    1716                test_rsa_signature.c test_rsa_verify.c \ 
    18                 test_crypto.c 
     17                test_crypto.c test_common.c 
     18COMMONTESTOBJ=$(COMMONTESTSRC:.c=.o) 
    1919 
    20 TESTOBJ=$(TESTSRC:.c=.o) 
     20TESTSRC= tests.c  
     21TESTOBJ= $(TESTSRC:.c=.o) 
    2122 
    22 all: Makefile $(CUNIT_LIB) .depend tests 
     23GPGTESTSRC= tests_gpg.c 
     24GPGTESTOBJ= $(GPGTESTSRC:.c=.o) 
    2325 
    24 tests: $(CUNIT_LIB) $(TESTOBJ) $(LIBDEPS) 
    25         $(CC) $(LDFLAGS) -o tests $(TESTOBJ) $(LIBS) 
     26all: Makefile $(CUNIT_LIB) .depend tests tests_gpg 
     27 
     28tests: $(CUNIT_LIB) $(TESTOBJ) $(COMMONTESTOBJ) $(LIBDEPS) 
     29        $(CC) $(LDFLAGS) -o tests $(TESTOBJ) $(COMMONTESTOBJ) $(LIBS) 
     30 
     31tests_gpg: $(CUNIT_LIB) $(GPGTESTOBJ) $(COMMONTESTOBJ) $(LIBDEPS) 
     32        $(CC) $(LDFLAGS) -o tests_gpg $(GPGTESTOBJ) $(COMMONTESTOBJ) $(LIBS) 
    2633 
    2734$(CUNIT_LIB): 
  • openpgpsdk/trunk/tests/test_rsa_decrypt.c

    r514 r517  
    241241    ops_memory_init(mem_literal_data,0); 
    242242    rtn=ops_parse(pinfo); 
     243    ops_print_errors(ops_parse_info_get_errors(pinfo)); 
    243244    CU_ASSERT(rtn==1); 
    244245 
     
    287288    } 
    288289 
     290#ifdef TODO 
     291void test_rsa_decrypt_armour_nopassphrase_cast5(void) 
     292    { 
     293    int armour=1; 
     294    int passphrase=0; 
     295    test_rsa_decrypt(armour,passphrase,filename_rsa_noarmour_nopassphrase,"CAST5"); 
     296    } 
     297#endif 
     298 
    289299void test_rsa_decrypt_noarmour_nopassphrase_aes128(void) 
    290300    { 
     
    354364 
    355365#ifdef TODO 
     366    if (NULL == CU_add_test(suite, "Armoured, no passphrase (CAST5)", test_rsa_decrypt_armour_nopassphrase_cast5)) 
     367            return NULL; 
     368     
    356369    if (NULL == CU_add_test(suite, "Unarmoured, no passphrase (3DES)", test_rsa_decrypt_noarmour_nopassphrase_3des)) 
    357370            return NULL; 
  • openpgpsdk/trunk/tests/test_rsa_encrypt.c

    r514 r517  
    154154    ops_memory_init(mem_literal_data,0); 
    155155    rtn=ops_parse(pinfo); 
     156    ops_print_errors(ops_parse_info_get_errors(pinfo)); 
    156157    CU_ASSERT(rtn==1); 
    157158 
     
    356357    // Do the writing 
    357358 
    358     const unsigned bufsz=16; 
     359    unsigned char* buf=NULL; 
     360    size_t bufsz=16; 
     361    int done=0; 
    359362    for (;;) 
    360363        { 
    361             unsigned char buf[bufsz]; 
     364        buf=realloc(buf,done+bufsz); 
     365         
    362366            int n=0; 
    363367 
    364             n=read(fd_in,buf,sizeof(buf)); 
     368            n=read(fd_in,buf+done,bufsz); 
    365369            if (!n) 
    366370                    break; 
    367371            assert(n>=0); 
    368  
    369         // This does the writing 
    370         ops_write(buf,n,cinfo); 
    371         } 
     372        done+=n; 
     373        } 
     374 
     375    // This does the writing 
     376    ops_write(buf,done,cinfo); 
    372377 
    373378    // Pop the encrypted writer from the stack 
  • openpgpsdk/trunk/tests/test_rsa_signature.c

    r514 r517  
    1010#include "openpgpsdk/std_print.h" 
    1111#include "openpgpsdk/readerwriter.h" 
     12#include "openpgpsdk/validate.h" 
    1213 
    1314#include "tests.h" 
     15 
     16static int do_gpgtest=0; 
    1417 
    1518static char *filename_rsa_noarmour_nopassphrase="ops_rsa_signed_noarmour_nopassphrase.txt"; 
     
    1821static char *filename_rsa_armour_passphrase="ops_rsa_signed_armour_passphrase.txt"; 
    1922 
     23static ops_parse_cb_return_t 
     24callback_verify(const ops_parser_content_t *content_,ops_parse_cb_info_t *cbinfo); 
     25 
    2026/* Signature suite initialization. 
    2127 * Create temporary directory. 
     
    2531int init_suite_rsa_signature(void) 
    2632    { 
     33    do_gpgtest=0; 
     34 
    2735    // Create test files 
    2836 
     
    3341 
    3442    // Return success 
     43    return 0; 
     44    } 
     45 
     46int init_suite_rsa_signature_gpgtest(void) 
     47    { 
     48    init_suite_rsa_signature(); 
     49 
     50    do_gpgtest=1; 
     51 
    3552    return 0; 
    3653    } 
     
    124141    close(fd_out); 
    125142 
    126 #ifdef TODO 
    127      // Check signature with OPS 
     143    // Check 
     144 
     145    if (!do_gpgtest) 
     146        { 
     147        int fd=0; 
     148        ops_parse_info_t *pinfo=NULL; 
     149        validate_cb_arg_t validate_arg; 
     150        ops_validate_result_t result; 
     151        int rtn=0; 
     152 
     153    // open signed file 
     154#ifdef WIN32 
     155        fd=open(signed_file,O_RDONLY | O_BINARY); 
     156#else 
     157        fd=open(signed_file,O_RDONLY); 
    128158#endif 
    129  
    130     // Check signature with GPG 
    131  
    132     snprintf(cmd,MAXBUF,"gpg --verify --quiet --homedir %s %s", dir, signed_file); 
    133     rtn=system(cmd); 
    134     CU_ASSERT(rtn==0); 
     159        if(fd < 0) 
     160            { 
     161            perror(signed_file); 
     162            exit(2); 
     163            } 
     164         
     165        // Set verification reader and handling options 
     166         
     167        pinfo=ops_parse_info_new(); 
     168        ops_parse_cb_set(pinfo,callback_verify,&validate_arg); 
     169        ops_reader_set_fd(pinfo,fd); 
     170         
     171        memset(&validate_arg,'\0',sizeof validate_arg); 
     172        validate_arg.result=&result; 
     173        validate_arg.keyring=&pub_keyring; 
     174        validate_arg.rarg=ops_reader_get_arg_from_pinfo(pinfo); 
     175         
     176        // Set up armour/passphrase options 
     177         
     178        if (has_armour) 
     179            ops_reader_push_dearmour(pinfo,ops_false,ops_false,ops_false); 
     180        //    current_passphrase=has_passphrase ? passphrase : nopassphrase; 
     181         
     182        // Do the verification 
     183         
     184        rtn=ops_parse(pinfo); 
     185        ops_print_errors(ops_parse_info_get_errors(pinfo)); 
     186        CU_ASSERT(rtn==1); 
     187         
     188        } 
     189    else 
     190        { 
     191        // Check signature with GPG 
     192 
     193        snprintf(cmd,MAXBUF,"gpg --verify --quiet --homedir %s %s", dir, signed_file); 
     194        rtn=system(cmd); 
     195        CU_ASSERT(rtn==0); 
     196        } 
    135197    } 
    136198 
     
    198260} 
    199261 
     262CU_pSuite suite_rsa_signature_GPGtest() 
     263{ 
     264    CU_pSuite suite = NULL; 
     265 
     266    suite = CU_add_suite("RSA Signature Suite (GPG interop)", init_suite_rsa_signature_gpgtest, clean_suite_rsa_signature); 
     267 
     268    if (!suite) 
     269            return NULL; 
     270 
     271    // add tests to suite 
     272     
     273#ifdef TBD 
     274    if (NULL == CU_add_test(suite, "Unarmoured, no passphrase", test_rsa_signature_noarmour_nopassphrase)) 
     275            return NULL; 
     276     
     277    if (NULL == CU_add_test(suite, "Unarmoured, passphrase", test_rsa_signature_noarmour_passphrase)) 
     278            return NULL; 
     279#endif /*TBD*/ 
     280     
     281    if (NULL == CU_add_test(suite, "Armoured, no passphrase", test_rsa_signature_armour_nopassphrase)) 
     282            return NULL; 
     283     
     284    if (NULL == CU_add_test(suite, "Armoured, passphrase", test_rsa_signature_armour_passphrase)) 
     285            return NULL; 
     286     
     287     
     288    return suite; 
     289} 
     290 
     291static ops_parse_cb_return_t 
     292callback_verify(const ops_parser_content_t *content_,ops_parse_cb_info_t *cbinfo) 
     293    { 
     294    //    ops_parser_content_union_t* content=(ops_parser_content_union_t *)&content_->content; 
     295 
     296    //        ops_print_packet(content_); 
     297 
     298    switch(content_->tag) 
     299        { 
     300    case OPS_PTAG_CT_LITERAL_DATA_HEADER: 
     301        break; 
     302 
     303    case OPS_PTAG_CT_LITERAL_DATA_BODY: 
     304        return callback_literal_data(content_,cbinfo); 
     305        break; 
     306 
     307    case OPS_PTAG_CT_ONE_PASS_SIGNATURE: 
     308 case OPS_PTAG_CT_SIGNATURE: 
     309 case OPS_PTAG_CT_SIGNED_CLEARTEXT_HEADER: 
     310 case OPS_PTAG_CT_SIGNED_CLEARTEXT_BODY: 
     311 case OPS_PTAG_CT_SIGNED_CLEARTEXT_TRAILER: 
     312 case OPS_PTAG_CT_ARMOUR_HEADER: 
     313 case OPS_PTAG_CT_ARMOUR_TRAILER: 
     314        break; 
     315 
     316    case OPS_PTAG_CT_SIGNATURE_HEADER: 
     317    case OPS_PTAG_CT_SIGNATURE_FOOTER: 
     318        return callback_signature(content_, cbinfo); 
     319 
     320        /* 
     321    case OPS_PTAG_CT_UNARMOURED_TEXT: 
     322        printf("OPS_PTAG_CT_UNARMOURED_TEXT\n"); 
     323        if(!skipping) 
     324            { 
     325            puts("Skipping..."); 
     326            skipping=ops_true; 
     327            } 
     328        fwrite(content->unarmoured_text.data,1, 
     329               content->unarmoured_text.length,stdout); 
     330        break; 
     331 
     332    case OPS_PTAG_CT_PK_SESSION_KEY: 
     333        return callback_pk_session_key(content_,cbinfo); 
     334 
     335    case OPS_PARSER_CMD_GET_SECRET_KEY: 
     336        return callback_cmd_get_secret_key(content_,cbinfo); 
     337 
     338    case OPS_PARSER_CMD_GET_SK_PASSPHRASE: 
     339        return callback_cmd_get_secret_key_passphrase(content_,cbinfo); 
     340 
     341    case OPS_PTAG_CT_LITERAL_DATA_BODY: 
     342        return callback_literal_data(content_,cbinfo); 
     343        //      text=ops_mallocz(content->literal_data_body.length+1); 
     344        //      memcpy(text,content->literal_data_body.data,content->literal_data_body.length); 
     345        //              break; 
     346 
     347    case OPS_PARSER_PTAG: 
     348    case OPS_PTAG_CT_ARMOUR_HEADER: 
     349    case OPS_PTAG_CT_ARMOUR_TRAILER: 
     350    case OPS_PTAG_CT_ENCRYPTED_PK_SESSION_KEY: 
     351    case OPS_PTAG_CT_COMPRESSED: 
     352    case OPS_PTAG_CT_SE_IP_DATA_BODY: 
     353    case OPS_PTAG_CT_SE_IP_DATA_HEADER: 
     354        // Ignore these packets  
     355        // They're handled in ops_parse_one_packet() 
     356        // and nothing else needs to be done 
     357        break; 
     358*/ 
     359 
     360    default: 
     361        return callback_general(content_,cbinfo); 
     362        } 
     363 
     364    return OPS_RELEASE_MEMORY; 
     365    } 
     366 
     367// EOF 
  • openpgpsdk/trunk/tests/test_rsa_verify.c

    r514 r517  
    2222 
    2323#endif /* ATTRIBUTE_UNUSED */ 
    24  
    25 typedef struct 
    26     { 
    27     const ops_key_data_t *key; 
    28     unsigned packet; 
    29     unsigned offset; 
    30     } validate_reader_arg_t; 
    31  
    32 typedef struct 
    33     { 
    34     ops_public_key_t pkey; 
    35     ops_public_key_t subkey; 
    36     enum 
    37         { 
    38         ATTRIBUTE, 
    39         ID 
    40         } last_seen; 
    41     ops_user_id_t user_id; 
    42     ops_user_attribute_t user_attribute; 
    43     const ops_keyring_t *keyring; 
    44     validate_reader_arg_t *rarg; 
    45     ops_validate_result_t *result; 
    46     } validate_cb_arg_t; 
    4724 
    4825static char *filename_rsa_noarmour_nopassphrase="gpg_signed_noarmour_nopassphrase.txt"; 
     
    219196 
    220197    rtn=ops_parse(pinfo); 
     198    ops_print_errors(ops_parse_info_get_errors(pinfo)); 
    221199    CU_ASSERT(rtn==1); 
    222200 
  • openpgpsdk/trunk/tests/tests.c

    r514 r517  
    1414 
    1515#include "tests.h" 
    16  
    17 char dir[MAXBUF+1]; 
    18 ops_keyring_t pub_keyring; 
    19 ops_keyring_t sec_keyring; 
    20 static char* no_passphrase=""; 
    21 ops_memory_t* mem_literal_data=NULL; 
    22  
    23 char *alpha_user_id="Alpha (RSA, no passphrase) <alpha@test.com>"; 
    24 char *alpha_name="Alpha"; 
    25 const ops_public_key_t *alpha_pkey; 
    26 const ops_secret_key_t *alpha_skey; 
    27 const ops_key_data_t *alpha_pub_keydata; 
    28 const ops_key_data_t *alpha_sec_keydata; 
    29 char* alpha_passphrase=""; 
    30  
    31 char *bravo_user_id="Bravo (RSA, passphrase) <bravo@test.com>"; 
    32 char *bravo_name="Bravo"; 
    33 const ops_public_key_t *bravo_pkey; 
    34 const ops_secret_key_t *bravo_skey; 
    35 const ops_key_data_t *bravo_pub_keydata; 
    36 const ops_key_data_t *bravo_sec_keydata; 
    37 char* bravo_passphrase="hello"; 
    38  
    39 const ops_key_data_t *decrypter=NULL; 
    40  
    41 void setup_test_keys() 
    42     { 
    43     char keydetails[MAXBUF+1]; 
    44     char keyring_name[MAXBUF+1]; 
    45     int fd=0; 
    46     char cmd[MAXBUF+1]; 
    47  
    48     char *rsa_nopass="Key-Type: RSA\nKey-Usage: encrypt, sign\nName-Real: Alpha\nName-Comment: RSA, no passphrase\nName-Email: alpha@test.com\nKey-Length: 1024\n"; 
    49     char *rsa_pass="Key-Type: RSA\nKey-Usage: encrypt, sign\nName-Real: Bravo\nName-Comment: RSA, passphrase\nName-Email: bravo@test.com\nPassphrase: hello\nKey-Length: 1024\n"; 
    50  
    51     // Create temp directory 
    52     if (!mktmpdir()) 
    53         return; 
    54  
    55     /* 
    56      * Create a RSA keypair with no passphrase 
    57      */ 
    58  
    59     snprintf(keydetails,MAXBUF,"%s/%s",dir,"keydetails.alpha"); 
    60  
    61 #ifdef WIN32 
    62     if ((fd=open(keydetails,O_WRONLY | O_CREAT | O_EXCL | O_BINARY, 0600))<0) 
    63 #else 
    64     if ((fd=open(keydetails,O_WRONLY | O_CREAT | O_EXCL, 0600))<0) 
    65 #endif 
    66         { 
    67         fprintf(stderr,"Can't create Alpha key details\n"); 
    68         return; 
    69         } 
    70  
    71     write(fd,rsa_nopass,strlen(rsa_nopass)); 
    72     close(fd); 
    73  
    74     snprintf(cmd,MAXBUF,"gpg --openpgp --quiet --gen-key --s2k-cipher-algo \"AES\" --expert --homedir=%s --batch %s",dir,keydetails); 
    75     system(cmd); 
    76  
    77     /* 
    78      * Create a RSA keypair with passphrase 
    79      */ 
    80  
    81     snprintf(keydetails,MAXBUF,"%s/%s",dir,"keydetails.bravo"); 
    82  
    83 #ifdef WIN32 
    84     if ((fd=open(keydetails,O_WRONLY | O_CREAT | O_EXCL | O_BINARY, 0600))<0) 
    85 #else 
    86     if ((fd=open(keydetails,O_WRONLY | O_CREAT | O_EXCL, 0600))<0) 
    87 #endif 
    88         { 
    89         fprintf(stderr,"Can't create Bravo key details\n"); 
    90         return; 
    91         } 
    92  
    93     write(fd,rsa_pass,strlen(rsa_pass)); 
    94     close(fd); 
    95  
    96     snprintf(cmd,MAXBUF,"gpg --openpgp --quiet --gen-key --s2k-cipher-algo \"AES\" --expert --homedir=%s --batch %s",dir,keydetails); 
    97     system(cmd); 
    98      
    99     /* 
    100      * read keyrings 
    101      */ 
    102  
    103     snprintf(keyring_name,MAXBUF,"%s/pubring.gpg", dir); 
    104     ops_keyring_read(&pub_keyring,keyring_name); 
    105  
    106     snprintf(keyring_name,MAXBUF,"%s/secring.gpg", dir); 
    107     ops_keyring_read(&sec_keyring,keyring_name); 
    108  
    109     /* 
    110      * set up key pointers 
    111      */ 
    112  
    113     assert(pub_keyring.nkeys); 
    114  
    115     alpha_pub_keydata=ops_keyring_find_key_by_userid(&pub_keyring, alpha_user_id); 
    116     bravo_pub_keydata=ops_keyring_find_key_by_userid(&pub_keyring, bravo_user_id); 
    117     assert(alpha_pub_keydata); 
    118     assert(bravo_pub_keydata); 
    119  
    120     alpha_sec_keydata=ops_keyring_find_key_by_userid(&sec_keyring, alpha_user_id); 
    121     bravo_sec_keydata=ops_keyring_find_key_by_userid(&sec_keyring, bravo_user_id); 
    122     assert(alpha_sec_keydata); 
    123     assert(bravo_sec_keydata); 
    124  
    125     alpha_pkey=ops_get_public_key_from_data(alpha_pub_keydata); 
    126     alpha_skey=ops_get_secret_key_from_data(alpha_sec_keydata); 
    127     bravo_pkey=ops_get_public_key_from_data(bravo_pub_keydata); 
    128     bravo_skey=ops_decrypt_secret_key_from_data(bravo_sec_keydata,bravo_passphrase); 
    129  
    130     assert(alpha_pkey); 
    131     assert(alpha_skey); 
    132     assert(bravo_pkey); 
    133     assert(bravo_skey); //not yet set because of passphrase 
    134     } 
    135  
    136 static void cleanup() 
    137     { 
    138     char cmd[MAXBUF]; 
    139  
    140     return; 
    141  
    142     /* Remove test dir and files */ 
    143     snprintf(cmd,MAXBUF,"rm -rf %s", dir); 
    144     if (system(cmd)) 
    145         { 
    146         perror("Can't delete test directory "); 
    147         return; 
    148         } 
    149     } 
    15016 
    15117int main() 
     
    18854        } 
    18955 
    190 #ifdef TODO 
    19156    if (NULL == suite_rsa_verify())  
    19257        { 
     
    19459        return CU_get_error(); 
    19560        } 
    196 #endif 
    19761 
    198     if (NULL == suite_rsa_encrypt_GPGtest())  
     62#ifdef TODO 
     63    if (NULL == suite_rsa_create_key()) 
    19964        { 
    20065        CU_cleanup_registry(); 
    20166        return CU_get_error(); 
    20267        } 
     68 
     69    if (NULL == suite_rsa_sign_key()) 
     70        { 
     71        CU_cleanup_registry(); 
     72        return CU_get_error(); 
     73        } 
     74 
     75    if (NULL == suite_rsa_verify_key()) 
     76        { 
     77        CU_cleanup_registry(); 
     78        return CU_get_error(); 
     79        } 
     80#endif 
    20381 
    20482    // Run tests 
     
    21290    } 
    21391 
    214 int mktmpdir (void) 
    215     { 
    216     int limit=10; // don't try indefinitely 
    217     long int rnd=0; 
    218  
    219 #ifdef WIN32 
    220     srand( (unsigned)time( NULL ) ); 
    221 #endif 
    222     while (limit--)  
    223         { 
    224         rnd=random(); 
    225         snprintf(dir,MAXBUF,"./testdir.%ld",rnd); 
    226          
    227         // Try to create directory 
    228 #ifndef WIN32 
    229         if (!mkdir(dir,0700)) 
    230 #else 
    231         if (!_mkdir(dir)) 
    232 #endif 
    233             { 
    234             // success 
    235             return 1; 
    236             } 
    237         else 
    238             { 
    239             fprintf (stderr,"Couldn't open dir: errno=%d\n", errno); 
    240             perror(NULL); 
    241             } 
    242         } 
    243     fprintf(stderr,"Too many temp dirs: please delete them\n"); 
    244     exit(1); 
    245     } 
    246  
    247 char* create_testtext(const char *text) 
    248     { 
    249     const unsigned int repeats=100; 
    250     unsigned int i=0; 
    251  
    252     const unsigned int maxbuf=1024; 
    253     char buf[maxbuf+1]; 
    254     unsigned int sz_one=0; 
    255     unsigned int sz_big=0; 
    256     char* bigbuf=NULL;  
    257  
    258     buf[maxbuf]='\0'; 
    259     snprintf(buf,maxbuf,"%s : Test Text\n", text); 
    260  
    261     sz_one=strlen(buf); 
    262     sz_big=sz_one*repeats+1; 
    263  
    264     bigbuf=ops_mallocz(sz_big);  
    265  
    266    for (i=0; i<repeats; i++) 
    267         { 
    268         char* ptr=bigbuf+ (i*(sz_one-1)); 
    269         snprintf(ptr,sz_one,buf); 
    270         } 
    271  
    272    return bigbuf; 
    273     } 
    274  
    275 void create_testdata(const char *text, unsigned char *buf, const int maxlen) 
    276     { 
    277     char *preamble=" : Test Data :"; 
    278     int i=0; 
    279  
    280     snprintf((char *)buf,maxlen,"%s%s", text, preamble); 
    281  
    282 #ifdef WIN32 
    283     srand( (unsigned)time( NULL ) ); 
    284 #endif 
    285     for (i=strlen(text)+strlen(preamble); i<maxlen; i++) 
    286         { 
    287         buf[i]=(random() & 0xFF); 
    288         } 
    289     } 
    290  
    291 void create_testfile(const char *name) 
    292     { 
    293     char filename[MAXBUF+1]; 
    294     char* testtext=NULL; 
    295  
    296     int fd=0; 
    297     snprintf(filename,MAXBUF,"%s/%s",dir,name); 
    298 #ifdef WIN32 
    299     if ((fd=open(filename,O_WRONLY| O_CREAT | O_EXCL | O_BINARY, 0600))<0) 
    300 #else 
    301     if ((fd=open(filename,O_WRONLY| O_CREAT | O_EXCL, 0600))<0) 
    302 #endif 
    303         return; 
    304  
    305     testtext=create_testtext(name); 
    306     write(fd,testtext,strlen(testtext)); 
    307     close(fd); 
    308     free(testtext); 
    309     } 
    310  
    311 ops_parse_cb_return_t 
    312 callback_general(const ops_parser_content_t *content_,ops_parse_cb_info_t *cbinfo) 
    313     { 
    314     ops_parser_content_union_t* content=(ops_parser_content_union_t *)&content_->content; 
    315      
    316     OPS_USED(cbinfo); 
    317      
    318     //    ops_print_packet(content_); 
    319      
    320     switch(content_->tag) 
    321         { 
    322     case OPS_PARSER_PTAG: 
    323         // ignore 
    324         break; 
    325          
    326     case OPS_PARSER_ERROR: 
    327         printf("parse error: %s\n",content->error.error); 
    328         break; 
    329          
    330     case OPS_PARSER_ERRCODE: 
    331         printf("parse error: %s\n", 
    332                ops_errcode(content->errcode.errcode)); 
    333         break; 
    334          
    335     default: 
    336         fprintf(stderr,"Unexpected packet tag=%d (0x%x)\n",content_->tag, 
    337                 content_->tag); 
    338         assert(0); 
    339         } 
    340      
    341     return OPS_RELEASE_MEMORY; 
    342     } 
    343  
    344 ops_parse_cb_return_t 
    345 callback_cmd_get_secret_key(const ops_parser_content_t *content_,ops_parse_cb_info_t *cbinfo) 
    346     { 
    347     ops_parser_content_union_t* content=(ops_parser_content_union_t *)&content_->content; 
    348     const ops_key_data_t *keydata=NULL; 
    349     const ops_secret_key_t *secret; 
    350     char *passphrase=NULL; 
    351  
    352     OPS_USED(cbinfo); 
    353  
    354 //    ops_print_packet(content_); 
    355  
    356     switch(content_->tag) 
    357         { 
    358     case OPS_PARSER_CMD_GET_SECRET_KEY: 
    359         keydata=ops_keyring_find_key_by_id(&sec_keyring,content->get_secret_key.pk_session_key->key_id); 
    360         if (!keydata || !ops_key_is_secret(keydata)) 
    361             return 0; 
    362  
    363         // Do we need the passphrase and not have it? If so, get it 
    364         passphrase=NULL; 
    365  
    366         /* 
    367          * Hard-coded to allow automated test 
    368          */ 
    369         if (keydata==alpha_sec_keydata) 
    370             passphrase=alpha_passphrase; 
    371         else if (keydata==bravo_sec_keydata) 
    372             passphrase=bravo_passphrase; 
    373         else 
    374             assert(0); 
    375  
    376         /* now get the key from the data */ 
    377         secret=ops_get_secret_key_from_data(keydata); 
    378         while(!secret) 
    379             { 
    380             /* then it must be encrypted */ 
    381             secret=ops_decrypt_secret_key_from_data(keydata,passphrase); 
    382             } 
    383          
    384         *content->get_secret_key.secret_key=secret; 
    385         break; 
    386  
    387     default: 
    388         return callback_general(content_,cbinfo); 
    389         } 
    390      
    391     return OPS_RELEASE_MEMORY; 
    392     } 
    393  
    394 ops_parse_cb_return_t 
    395 callback_cmd_get_secret_key_passphrase(const ops_parser_content_t *content_,ops_parse_cb_info_t *cbinfo) 
    396     { 
    397     ops_parser_content_union_t* content=(ops_parser_content_union_t *)&content_->content; 
    398  
    399     OPS_USED(cbinfo); 
    400  
    401 //    ops_print_packet(content_); 
    402  
    403     switch(content_->tag) 
    404         { 
    405     case OPS_PARSER_CMD_GET_SK_PASSPHRASE: 
    406         /* 
    407           Doing this so the test can be automated. 
    408         */ 
    409         *(content->secret_key_passphrase.passphrase)=ops_malloc_passphrase(no_passphrase); 
    410         return OPS_KEEP_MEMORY; 
    411         break; 
    412          
    413     default: 
    414         return callback_general(content_,cbinfo); 
    415         } 
    416      
    417     return OPS_RELEASE_MEMORY; 
    418     } 
    419  
    420 ops_parse_cb_return_t 
    421 callback_literal_data(const ops_parser_content_t *content_,ops_parse_cb_info_t *cbinfo) 
    422     { 
    423     ops_parser_content_union_t* content=(ops_parser_content_union_t *)&content_->content; 
    424  
    425     OPS_USED(cbinfo); 
    426  
    427     //    ops_print_packet(content_); 
    428  
    429     // Read data from packet into static buffer 
    430     switch(content_->tag) 
    431         { 
    432     case OPS_PTAG_CT_LITERAL_DATA_BODY: 
    433         ops_memory_add(mem_literal_data, 
    434                        content->literal_data_body.data, 
    435                        content->literal_data_body.length); 
    436         break; 
    437  
    438     case OPS_PTAG_CT_LITERAL_DATA_HEADER: 
    439         // ignore 
    440         break; 
    441  
    442     default: 
    443         return callback_general(content_,cbinfo); 
    444         } 
    445  
    446     return OPS_RELEASE_MEMORY; 
    447     } 
    448   
    449 // move definition to better location 
    450 ops_parse_cb_return_t 
    451 validate_cb(const ops_parser_content_t *content_,ops_parse_cb_info_t *cbinfo); 
    452  
    453 ops_parse_cb_return_t 
    454 callback_signature(const ops_parser_content_t *content_,ops_parse_cb_info_t *cbinfo) 
    455     { 
    456     //    ops_parser_content_union_t* content=(ops_parser_content_union_t *)&content_->content; 
    457  
    458     OPS_USED(cbinfo); 
    459  
    460     //    ops_print_packet(content_); 
    461  
    462     switch(content_->tag) 
    463         { 
    464     case OPS_PTAG_CT_ONE_PASS_SIGNATURE: 
    465     case OPS_PTAG_CT_SIGNATURE_HEADER: 
    466     case OPS_PTAG_CT_SIGNATURE_FOOTER: 
    467         return validate_cb(content_,cbinfo); 
    468         break; 
    469  
    470     default: 
    471         return callback_general(content_,cbinfo); 
    472         } 
    473  
    474     return OPS_RELEASE_MEMORY; 
    475     } 
    476   
    477 ops_parse_cb_return_t 
    478 callback_pk_session_key(const ops_parser_content_t *content_,ops_parse_cb_info_t *cbinfo) 
    479     { 
    480     ops_parser_content_union_t* content=(ops_parser_content_union_t *)&content_->content; 
    481      
    482     OPS_USED(cbinfo); 
    483  
    484     //    ops_print_packet(content_); 
    485      
    486     // Read data from packet into static buffer 
    487     switch(content_->tag) 
    488         { 
    489     case OPS_PTAG_CT_PK_SESSION_KEY: 
    490                 //      printf ("OPS_PTAG_CT_PK_SESSION_KEY\n"); 
    491         if(decrypter) 
    492             break; 
    493  
    494         decrypter=ops_keyring_find_key_by_id(&sec_keyring, 
    495                                              content->pk_session_key.key_id); 
    496         if(!decrypter) 
    497             break; 
    498         break; 
    499  
    500     default: 
    501         return callback_general(content_,cbinfo); 
    502         } 
    503  
    504     return OPS_RELEASE_MEMORY; 
    505     } 
    506  
    507 void reset_vars() 
    508     { 
    509     ops_memory_init(mem_literal_data,0); 
    510  
    511     if (decrypter) 
    512         { 
    513         //        free (decrypter); 
    514         decrypter=NULL; 
    515         } 
    516     } 
    517  
    518 int file_compare(char* file1, char* file2) 
    519     { 
    520     FILE *fp1=NULL; 
    521     FILE *fp2=NULL; 
    522     char ch1, ch2; 
    523     int err=0; 
    524  
    525     // open files 
    526     if ((fp1=fopen(file1,"rb"))==NULL) 
    527         { 
    528         fprintf(stderr,"file_compare: cannot open file %s\n",file1); 
    529         return -1; 
    530         } 
    531     if ((fp2=fopen(file2,"rb"))==NULL) 
    532         { 
    533         fprintf(stderr,"file_compare: cannot open file %s\n",file2); 
    534         fclose(fp1); 
    535         return -1; 
    536         } 
    537  
    538     while(!feof(fp1)) 
    539         { 
    540         ch1 = fgetc(fp1); 
    541         if (ferror(fp1)) 
    542             { 
    543             fprintf(stderr,"file_compare: error reading from file %s\n",file1); 
    544             err = -1; 
    545             break; 
    546             } 
    547         ch2 = fgetc(fp2); 
    548         if (ferror(fp2)) 
    549             { 
    550             fprintf(stderr,"file_compare: error reading from file %s\n",file2); 
    551             err = -1; 
    552             break; 
    553             } 
    554         if (ch1 != ch2) 
    555             { 
    556             printf("Files %s and %s differ\n",file1,file2); 
    557             err = 1; 
    558             break; 
    559             } 
    560         } 
    561     fclose(fp1); 
    562     fclose(fp2); 
    563     return err; 
    564     } 
     92// EOF 
  • openpgpsdk/trunk/tests/tests.h

    r514 r517  
    3333 
    3434// utility functions 
     35 
     36void setup_test_keys(); 
     37void cleanup(); 
    3538 
    3639int mktmpdir();