Changeset 521

Show
Ignore:
Timestamp:
11/28/07 17:37:27
Author:
rachel
Message:

Initial implementation of Validation of Document Signatures.
(Note: Does not yet interoperate with GPG)
Renamed validate_cb to more accurate name of validate_key_cb.
Implemented validate_data_cb to handle validation of documents & signed cleartext.
Added in error-handling when validation fails.
Turned off unwanted debug output.

Files:

Legend:

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

    r517 r521  
    4040    OPS_E_C=0x4000,     /* general creator error */ 
    4141 
     42    /* validation errors */ 
     43    OPS_E_V=0x5000, /* general validation error */ 
     44    OPS_E_V_BAD_SIGNATURE       =OPS_E_V+1, 
     45    OPS_E_V_UNKNOWN_SIGNER      =OPS_E_V+2, 
     46 
    4247    /* Algorithm support errors */ 
    43     OPS_E_ALG=0x5000,                 /* general algorithm error */ 
     48    OPS_E_ALG=0x6000,                 /* general algorithm error */ 
    4449    OPS_E_ALG_UNSUPPORTED_SYMMETRIC_ALG         =OPS_E_ALG+1, 
    4550    OPS_E_ALG_UNSUPPORTED_PUBLIC_KEY_ALG        =OPS_E_ALG+2, 
     
    4853 
    4954    /* Protocol errors */ 
    50     OPS_E_PROTO=0x6000,       /* general protocol error */ 
     55    OPS_E_PROTO=0x7000,       /* general protocol error */ 
    5156    OPS_E_PROTO_BAD_SYMMETRIC_DECRYPT   =OPS_E_PROTO+2, 
    5257    OPS_E_PROTO_UNKNOWN_SS              =OPS_E_PROTO+3, 
  • openpgpsdk/trunk/include/openpgpsdk/packet.h

    r480 r521  
    560560    size_t                      v4_hashed_data_start; /* only valid if accumulate is set */ 
    561561    size_t                      v4_hashed_data_length; 
     562    unsigned char* v4_hashed_data; 
    562563    ops_hash_t                  *hash;          /*!< if set, the hash filled in for the data so far */ 
    563564    ops_boolean_t               creation_time_set:1; 
     
    801802    { 
    802803    unsigned                    length; 
    803     unsigned char               data[8192]; 
     804    unsigned char               data[8192]; // \todo fix hard-coded value? 
    804805    } ops_signed_cleartext_body_t; 
    805806 
  • openpgpsdk/trunk/include/openpgpsdk/validate.h

    r517 r521  
    2525        { 
    2626        ATTRIBUTE, 
    27         ID 
     27        ID, 
    2828        } last_seen; 
    2929    ops_user_id_t user_id; 
    3030    ops_user_attribute_t user_attribute; 
     31    unsigned char hash[OPS_MAX_HASH_SIZE]; 
    3132    const ops_keyring_t *keyring; 
    3233    validate_reader_arg_t *rarg; 
    3334    ops_validate_result_t *result; 
    34     } validate_cb_arg_t; 
     35    } validate_key_cb_arg_t; 
    3536 
     37typedef struct 
     38    { 
     39    enum 
     40        { 
     41        LITERAL_DATA, 
     42        SIGNED_CLEARTEXT 
     43        } use; 
     44    union 
     45        { 
     46        ops_literal_data_body_t literal_data_body;  
     47        ops_signed_cleartext_body_t signed_cleartext_body;  
     48        } data; 
     49    unsigned char hash[OPS_MAX_HASH_SIZE]; 
     50    const ops_keyring_t *keyring; 
     51    validate_reader_arg_t *rarg; 
     52    ops_validate_result_t *result; 
     53    } validate_data_cb_arg_t; 
     54 
     55ops_boolean_t ops_check_signature(const unsigned char *hash, 
     56                                  unsigned length, 
     57                                  const ops_signature_t *sig, 
     58                                  const ops_public_key_t *signer); 
    3659// EOF 
  • openpgpsdk/trunk/src/advanced/adv_armour.c

    r457 r521  
    1515 
    1616#include <openpgpsdk/final.h> 
     17 
     18static int debug=0; 
    1719 
    1820#define CRC24_INIT 0xb704ceL 
     
    813815    unsigned n; 
    814816 
     817    if (debug) 
     818        { 
     819        unsigned int i=0; 
     820        fprintf(stderr,"dash_escaped_writer writing %d:\n", length); 
     821        for (i=0; i<length; i++) 
     822            { 
     823            fprintf(stderr,"0x%02x ", src[i]); 
     824            if (!((i+1) % 16)) 
     825                fprintf(stderr,"\n"); 
     826            else if (!((i+1) % 8)) 
     827                fprintf(stderr,"  "); 
     828            } 
     829        fprintf(stderr,"\n"); 
     830        } 
     831 
    815832    // XXX: make this efficient 
    816833    for(n=0 ; n < length ; ++n) 
  • openpgpsdk/trunk/src/advanced/adv_fingerprint.c

    r516 r521  
    1818 
    1919#include <openpgpsdk/final.h> 
     20 
     21static int debug=0; 
    2022 
    2123/** 
     
    6466        ops_build_public_key(mem,key,ops_false); 
    6567 
     68    if (debug) 
     69        { fprintf(stderr,"--- creating key fingerprint\n"); } 
     70 
    6671        ops_hash_sha1(&sha1); 
    6772        sha1.init(&sha1); 
     
    7378        sha1.add(&sha1,ops_memory_get_data(mem),l); 
    7479        sha1.finish(&sha1,fp->fingerprint); 
     80 
     81    if (debug) 
     82        { fprintf(stderr,"--- finished creating key fingerprint\n"); } 
    7583 
    7684        fp->length=20; 
  • openpgpsdk/trunk/src/advanced/adv_keyring.c

    r516 r521  
    88#include <openpgpsdk/validate.h> 
    99#include "keyring_local.h" 
     10#include "parse_local.h" 
     11 
    1012#include <stdlib.h> 
    1113#include <string.h> 
     
    185187        return OPS_KEEP_MEMORY; 
    186188 
     189 case OPS_PARSER_PACKET_END: 
     190     // nothing to do 
     191     break; 
     192 
    187193    default: 
    188194        fprintf(stderr,"Unexpected tag %d (0x%x)\n",content_->tag, 
     
    209215    ops_key_data_reader_set(pinfo,key); 
    210216    ops_parse_cb_set(pinfo,decrypt_cb,&arg); 
     217    pinfo->rinfo.accumulate=ops_true; 
    211218 
    212219    ops_parse(pinfo); 
  • openpgpsdk/trunk/src/advanced/adv_openssl_crypto.c

    r516 r521  
    1515#include <openpgpsdk/final.h> 
    1616 
     17static int debug=0; 
     18 
    1719static void md5_init(ops_hash_t *hash) 
    1820    { 
     
    4547static void sha1_init(ops_hash_t *hash) 
    4648    { 
     49    if (debug) 
     50        { 
     51        fprintf(stderr,"***\n***\nsha1_init\n***\n"); 
     52        } 
    4753    assert(!hash->data); 
    4854    hash->data=malloc(sizeof(SHA_CTX)); 
     
    5359                     unsigned length) 
    5460    { 
     61    if (debug) 
     62        { 
     63        unsigned int i=0; 
     64        fprintf(stderr,"adding %d to hash:\n ", length); 
     65        for (i=0; i<length; i++) 
     66            { 
     67            fprintf(stderr,"0x%02x ", data[i]); 
     68            if (!((i+1) % 16)) 
     69                fprintf(stderr,"\n"); 
     70            else if (!((i+1) % 8)) 
     71                fprintf(stderr,"  "); 
     72            } 
     73        fprintf(stderr,"\n"); 
     74        } 
    5575    SHA1_Update(hash->data,data,length); 
    5676    } 
     
    5979    { 
    6080    SHA1_Final(out,hash->data); 
     81    if (debug) 
     82        { 
     83        unsigned i=0; 
     84        fprintf(stderr,"***\n***\nsha1_finish\n***\n"); 
     85        for (i=0; i<20; i++) 
     86            fprintf(stderr,"0x%02x ",out[i]); 
     87        fprintf(stderr,"\n"); 
     88        } 
    6189    free(hash->data); 
    6290    hash->data=NULL; 
  • openpgpsdk/trunk/src/advanced/adv_packet-parse.c

    r520 r521  
    2727 
    2828#include <openpgpsdk/final.h> 
     29 
     30static int debug=0; 
    2931 
    3032typedef struct 
     
    13411343            return 0; 
    13421344        CBP(pinfo,OPS_PTAG_RAW_SS,&content); 
    1343        return 1; 
     1345    return 1; 
    13441346        } 
    13451347 
     
    16311633 * \see RFC2440bis-12 5.2.3 
    16321634 */ 
    1633 static int parse_v4_signature(ops_region_t *region,ops_parse_info_t *pinfo, 
    1634                               size_t v4_hashed_data_start) 
     1635static int parse_v4_signature(ops_region_t *region,ops_parse_info_t *pinfo) 
    16351636    { 
    16361637    unsigned char c[1]; 
    16371638    ops_parser_content_t content; 
    1638  
     1639     
     1640    // clear signature 
    16391641    memset(&C.signature,'\0',sizeof C.signature); 
     1642 
     1643    /* We need to hash the packet data from version through the hashed subpacket data */ 
     1644 
     1645    C.signature.v4_hashed_data_start=pinfo->rinfo.alength-1; 
     1646 
     1647    /* Set version,type,algorithms */ 
     1648 
    16401649    C.signature.version=OPS_V4; 
    1641     C.signature.v4_hashed_data_start=v4_hashed_data_start; 
    16421650 
    16431651    if(!limited_read(c,1,region,pinfo)) 
     
    16601668    if(!parse_signature_subpackets(&C.signature,region,pinfo)) 
    16611669        return 0; 
     1670 
    16621671    C.signature.v4_hashed_data_length=pinfo->rinfo.alength 
    1663         -C.signature.v4_hashed_data_start; 
     1672        -C.signature.v4_hashed_data_start; 
     1673 
     1674    // copy hashed subpackets 
     1675    if (C.signature.v4_hashed_data) 
     1676        free(C.signature.v4_hashed_data); 
     1677    C.signature.v4_hashed_data=ops_mallocz(C.signature.v4_hashed_data_length); 
     1678 
     1679    if (!pinfo->rinfo.accumulate) 
     1680        { 
     1681        /* We must accumulate, else we can't check the signature */ 
     1682        fprintf(stderr,"*** ERROR: must set accumulate to true\n"); 
     1683        assert(0); 
     1684        } 
     1685 
     1686    memcpy(C.signature.v4_hashed_data, 
     1687           pinfo->rinfo.accumulated+C.signature.v4_hashed_data_start, 
     1688           C.signature.v4_hashed_data_length); 
    16641689 
    16651690    if(!parse_signature_subpackets(&C.signature,region,pinfo)) 
     
    17391764    unsigned char c[1]; 
    17401765    ops_parser_content_t content; 
    1741     size_t v4_hashed_data_start; 
    17421766 
    17431767    assert(region->length_read == 0);  /* We should not have read anything so far */ 
     
    17451769    memset(&content,'\0',sizeof content); 
    17461770 
    1747     v4_hashed_data_start=pinfo->rinfo.alength; 
    17481771    if(!limited_read(c,1,region,pinfo)) 
    17491772        return 0; 
     
    17521775        return parse_v3_signature(region,pinfo); 
    17531776    else if(c[0] == 4) 
    1754         return parse_v4_signature(region,pinfo,v4_hashed_data_start); 
     1777        return parse_v4_signature(region,pinfo); 
    17551778 
    17561779    OPS_ERROR_1(&pinfo->errors,OPS_E_PROTO_BAD_SIGNATURE_VRSN, 
     
    22362259                                ops_parse_info_t *pinfo) 
    22372260    { 
    2238     int debug=0; 
    22392261    unsigned char c[1]; 
    22402262    ops_parser_content_t content; 
     
    23972419                             ops_parse_cb_info_t *cbinfo) 
    23982420    { 
    2399     int debug=0; 
    24002421 
    24012422    /* 
     
    31253146    pinfo->rinfo.pinfo=pinfo; 
    31263147 
     3148    // should copy accumulate flags from other reader? RW 
     3149    pinfo->rinfo.accumulate=rinfo->accumulate; 
     3150     
    31273151    ops_reader_set(pinfo,reader,destroyer,arg); 
    31283152    } 
  • openpgpsdk/trunk/src/advanced/adv_packet-show.c

    r426 r521  
    4141    { OPS_PTAG_CT_SE_IP_DATA,           "Sym. Encrypted and Integrity Protected Data" }, 
    4242    { OPS_PTAG_CT_MDC,                  "Modification Detection Code" }, 
     43    { OPS_PARSER_PTAG,                  "OPS_PARSER_PTAG" }, 
     44    { OPS_PTAG_RAW_SS,                  "OPS_PTAG_RAW_SS" }, 
     45    { OPS_PTAG_SS_ALL,                  "OPS_PTAG_SS_ALL" }, 
     46    { OPS_PARSER_PACKET_END,            "OPS_PARSER_PACKET_END" }, 
     47    { OPS_PTAG_SIGNATURE_SUBPACKET_BASE, "OPS_PTAG_SIGNATURE_SUBPACKET_BASE" }, 
     48    /* 
     49    { OPS_PTAG_SS_CREATION_TIME,        "SS: Signature Creation Time" }, 
     50    { OPS_PTAG_SS_EXPIRATION_TIME,      "SS: Signature Expiration Time" }, 
     51    { OPS_PTAG_SS_TRUST,                "SS: Trust" }, 
     52    { OPS_PTAG_SS_REGEXP,               "SS: Regexp" }, 
     53    { OPS_PTAG_SS_REVOCABLE,            "SS: Revocable" }, 
     54    { OPS_PTAG_SS_KEY_EXPIRATION_TIME,  "SS: Key Expiration Time" }, 
     55    { OPS_PTAG_SS_RESERVED,             "SS: Reserved" }, 
     56    { OPS_PTAG_SS_PREFERRED_SKA,        "SS: Preferred SKA" }, 
     57    { OPS_PTAG_SS_REVOCATION_KEY,       "SS: Revocation Key" }, 
     58    { OPS_PTAG_SS_ISSUER_KEY_ID,        "SS: Issuer Key Id" }, 
     59    { OPS_PTAG_SS_NOTATION_DATA,        "SS: Notation Data" }, 
     60    { OPS_PTAG_SS_PREFERRED_HASH,       "SS: Preferred Hash" }, 
     61    { OPS_PTAG_SS_PREFERRED_COMPRESSION,"SS: Preferred Compression" }, 
     62    { OPS_PTAG_SS_KEY_SERVER_PREFS,     "SS: Preferred Key Server" }, 
     63    { OPS_PTAG_SS_PRIMARY_USER_ID,      "SS: Primary User ID" }, 
     64    { OPS_PTAG_SS_POLICY_URL,           "SS: Policy URL" }, 
     65    { OPS_PTAG_SS_KEY_FLAGS,            "SS: Key Flags" }, 
     66    { OPS_PTAG_SS_SIGNERS_USER_ID,      "SS: Signers User ID" }, 
     67    { OPS_PTAG_SS_REVOCATION_REASON,    "SS: Revocation Reason" }, 
     68    { OPS_PTAG_SS_FEATURES,             "SS: Features" }, 
     69*/ 
     70    { OPS_PTAG_CT_LITERAL_DATA_HEADER,  "CT: Literal Data Header" }, 
     71    { OPS_PTAG_CT_LITERAL_DATA_BODY,    "CT: Literal Data Body" }, 
     72    { OPS_PTAG_CT_SIGNATURE_HEADER,     "CT: Signature Header" }, 
     73    { OPS_PTAG_CT_SIGNATURE_FOOTER,     "CT: Signature Footer" }, 
     74    { OPS_PTAG_CT_ARMOUR_HEADER,        "CT: Armour Header" }, 
     75    { OPS_PTAG_CT_ARMOUR_TRAILER,       "CT: Armour Trailer" }, 
     76    { OPS_PTAG_CT_SIGNED_CLEARTEXT_HEADER, "CT: Signed Cleartext Header" }, 
     77    { OPS_PTAG_CT_SIGNED_CLEARTEXT_BODY, "CT: Signed Cleartext Body" }, 
     78    { OPS_PTAG_CT_SIGNED_CLEARTEXT_TRAILER, "CT: Signed Cleartext Trailer" }, 
     79    { OPS_PTAG_CT_UNARMOURED_TEXT,      "CT: Unarmoured Text" }, 
     80    { OPS_PTAG_CT_ENCRYPTED_SECRET_KEY, "CT: Encrypted Secret Key" }, 
     81    { OPS_PTAG_CT_SE_DATA_HEADER,       "CT: Sym Encrypted Data Header" }, 
     82    { OPS_PTAG_CT_SE_DATA_BODY,         "CT: Sym Encrypted Data Body" }, 
     83    { OPS_PTAG_CT_SE_IP_DATA_HEADER,    "CT: Sym Encrypted IP Data Header" }, 
     84    { OPS_PTAG_CT_SE_IP_DATA_BODY,      "CT: Sym Encrypted IP Data Body" }, 
     85    { OPS_PTAG_CT_ENCRYPTED_PK_SESSION_KEY, "CT: Encrypted PK Session Key" }, 
     86    { OPS_PARSER_CMD_GET_SK_PASSPHRASE, "CMD: Get Secret Key Passphrase" }, 
     87    { OPS_PARSER_CMD_GET_SECRET_KEY,    "CMD: Get Secret Key" }, 
     88    { OPS_PARSER_ERROR,                 "OPS_PARSER_ERROR" }, 
     89    { OPS_PARSER_ERRCODE,               "OPS_PARSER_ERRCODE" }, 
     90 
    4391    { (int) NULL,               (char *)NULL }, /* this is the end-of-array marker */ 
    4492    }; 
     
    460508const char *ops_show_packet_tag(ops_packet_tag_t packet_tag) 
    461509    { 
    462     return show_packet_tag(packet_tag,packet_tag_map); 
     510    char *rtn=NULL; 
     511    rtn=show_packet_tag(packet_tag,packet_tag_map); 
     512 
     513    if (!rtn) 
     514        rtn="Unknown Tag"; 
     515 
     516    return rtn; 
    463517    } 
    464518 
  • openpgpsdk/trunk/src/advanced/adv_signature.c

    r459 r521  
    99 
    1010#include <openpgpsdk/final.h> 
     11 
     12static int debug=0; 
    1113 
    1214/** \ingroup Create 
     
    4143                                     0x03,0x02,0x1A,0x05,0x00,0x04,0x14 }; 
    4244 
     45ops_boolean_t encode_hash_buf(const unsigned char *M, size_t mLen, 
     46                           const ops_hash_algorithm_t hash_alg, 
     47                           unsigned char* EM 
     48) 
     49    { 
     50    // implementation of EMSA-PKCS1-v1_5, as defined in OpenPGP RFC 
     51 
     52    unsigned i; 
     53 
     54    int n=0; 
     55    ops_hash_t hash; 
     56    //    unsigned char hashout[OPS_MAX_HASH_SIZE]; 
     57    int hash_sz=0; 
     58    int encoded_hash_sz=0; 
     59    int prefix_sz=0; 
     60    unsigned padding_sz=0; 
     61    unsigned encoded_msg_sz=0; 
     62    unsigned char* prefix=NULL; 
     63 
     64    assert(hash_alg == OPS_HASH_SHA1); 
     65 
     66    // 1. Apply hash function to M 
     67 
     68    ops_hash_any(&hash,hash_alg); 
     69    hash.init(&hash); 
     70    hash.add(&hash,M,mLen); 
     71 
     72    // \todo combine with rsa_sign 
     73 
     74    // 2. Get hash prefix 
     75 
     76    switch(hash_alg) 
     77        { 
     78    case OPS_HASH_SHA1: 
     79        prefix=prefix_sha1;  
     80        prefix_sz=sizeof prefix_sha1; 
     81        hash_sz=OPS_SHA1_HASH_SIZE; 
     82        encoded_hash_sz=hash_sz+prefix_sz; 
     83        // \todo why is Ben using a PS size of 90 in rsa_sign? 
     84        // (keysize-hashsize-1-2) 
     85        padding_sz=90; 
     86        break; 
     87 
     88    default: 
     89        assert(0); 
     90        } 
     91 
     92    // \todo 3. Test for len being too short 
     93 
     94    // 4 and 5. Generate PS and EM 
     95 
     96    EM[0]=0x00; 
     97    EM[1]=0x01; 
     98 
     99    for (i=0; i<padding_sz; i++) 
     100        EM[2+i]=0xFF; 
     101 
     102    i+=2; 
     103 
     104    EM[i++]=0x00; 
     105 
     106    memcpy(&EM[i],prefix,prefix_sz); 
     107    i+=prefix_sz; 
     108 
     109    // finally, write out hashed result 
     110     
     111    n=hash.finish(&hash,&EM[i]); 
     112 
     113    encoded_msg_sz=i+hash_sz-1; 
     114 
     115    // \todo test n for OK response? 
     116 
     117    if (debug) 
     118        { 
     119        fprintf(stderr,"Encoded Message: \n"); 
     120        for (i=0; i<encoded_msg_sz; i++) 
     121            fprintf(stderr,"%2x ", EM[i]); 
     122        fprintf(stderr,"\n"); 
     123        } 
     124 
     125    return ops_true; 
     126    } 
     127 
    43128// XXX: both this and verify would be clearer if the signature were 
    44129// treated as an MPI. 
     
    55140    BIGNUM *bn; 
    56141 
     142 
    57143    // XXX: we assume hash is sha-1 for now 
    58144    hashsize=20+sizeof prefix_sha1; 
     
    64150    hashbuf[0]=0; 
    65151    hashbuf[1]=1; 
     152    if (debug) 
     153        { printf("rsa_sign: PS is %d\n", keysize-hashsize-1-2); } 
    66154    for(n=2 ; n < keysize-hashsize-1 ; ++n) 
    67155        hashbuf[n]=0xff; 
     
    135223        return ops_false; 
    136224 
     225    if (debug) 
     226        { 
     227        int zz; 
     228 
     229        printf("\n"); 
     230        printf("hashbuf\n"); 
     231        for (zz=0; zz<plen; zz++) 
     232            { printf("%02x ", hashbuf[n+zz]); } 
     233        printf("\n"); 
     234        printf("prefix\n"); 
     235        for (zz=0; zz<plen; zz++) 
     236            { printf("%02x ", prefix[zz]); } 
     237        printf("\n"); 
     238 
     239        printf("\n"); 
     240        printf("hashbuf2\n"); 
     241        unsigned uu; 
     242        for (uu=0; uu<hash_length; uu++) 
     243            { printf("%02x ", hashbuf[n+plen+uu]); } 
     244        printf("\n"); 
     245        printf("hash\n"); 
     246        for (uu=0; uu<hash_length; uu++) 
     247            { printf("%02x ", hash[uu]); } 
     248        printf("\n"); 
     249        } 
    137250    if(memcmp(&hashbuf[n],prefix,plen) 
    138251       || memcmp(&hashbuf[n+plen],hash,hash_length)) 
     
    163276    } 
    164277 
    165 static void init_signature(ops_hash_t *hash,const ops_signature_t *sig, 
     278static void init_key_signature(ops_hash_t *hash,const ops_signature_t *sig, 
    166279                           const ops_public_key_t *key) 
    167280    { 
     
    189302    } 
    190303 
    191 static ops_boolean_t check_signature(const unsigned char *hash,unsigned length, 
     304ops_boolean_t ops_check_signature(const unsigned char *hash,unsigned length, 
    192305                                     const ops_signature_t *sig, 
    193306                                     const ops_public_key_t *signer) 
     
    228341    n=hash->finish(hash,hashout); 
    229342 
    230     return check_signature(hashout,n,sig,signer); 
     343    return ops_check_signature(hashout,n,sig,signer); 
    231344    } 
    232345 
     
    261374    size_t user_id_len=strlen((char *)id->user_id); 
    262375 
    263     init_signature(&hash,sig,key); 
     376    init_key_signature(&hash,sig,key); 
    264377 
    265378    if(sig->version == OPS_V4) 
     
    293406    ops_hash_t hash; 
    294407 
    295     init_signature(&hash,sig,key); 
     408    init_key_signature(&hash,sig,key); 
    296409 
    297410    if(sig->version == OPS_V4) 
     
    325438    ops_hash_t hash; 
    326439 
    327     init_signature(&hash,sig,key); 
     440    init_key_signature(&hash,sig,key); 
    328441    hash_add_key(&hash,subkey); 
    329442 
     
    349462    ops_hash_t hash; 
    350463 
    351     init_signature(&hash,sig,key); 
     464    init_key_signature(&hash,sig,key); 
    352465    return finalise_signature(&hash,sig,signer,raw_packet); 
    353466    } 
     
    422535    sig->hashed_data_length=-1; 
    423536 
    424     init_signature(&sig->hash,&sig->sig,key); 
     537    init_key_signature(&sig->hash,&sig->sig,key); 
    425538 
    426539    ops_hash_add_int(&sig->hash,0xb4,1); 
     
    474587                            size_t length) 
    475588    { 
     589    if (debug) 
     590        { fprintf(stderr,"ops_signature_add_data adds to hash\n"); } 
    476591    sig->hash.add(&sig->hash,buf,length); 
    477592    } 
     
    520635 
    521636    // add the packet from version number to end of hashed subpackets 
     637 
     638    if (debug) 
     639        { fprintf(stderr, "--- Adding packet to hash from version number to hashed subpkts\n"); } 
     640 
    522641    sig->hash.add(&sig->hash,ops_memory_get_data(sig->mem), 
    523642                  sig->unhashed_count_offset); 
     643    /* what is this??? should delete? RW 
    524644    ops_hash_add_int(&sig->hash,sig->sig.version,1); 
    525645    ops_hash_add_int(&sig->hash,0xff,1); 
    526646    // +6 for version, type, pk alg, hash alg, hashed subpacket length 
    527647    ops_hash_add_int(&sig->hash,sig->hashed_data_length+6,4); 
     648    */ 
     649 
     650    if (debug) 
     651        { fprintf(stderr, "--- Finished adding packet to hash from version number to hashed subpkts\n"); } 
    528652 
    529653    // XXX: technically, we could figure out how big the signature is 
  • openpgpsdk/trunk/src/advanced/adv_validate.c

    r517 r521  
    11#include <openpgpsdk/packet-parse.h> 
     2#include <openpgpsdk/packet-show.h> 
    23#include <openpgpsdk/keyring.h> 
    34#include "keyring_local.h" 
    45#include <openpgpsdk/util.h> 
    56#include <openpgpsdk/signature.h> 
     7#include <openpgpsdk/memory.h> 
    68#include <openpgpsdk/validate.h> 
    79#include <assert.h> 
     
    911 
    1012#include <openpgpsdk/final.h> 
     13 
     14static int debug=0; 
     15 
     16static ops_boolean_t check_binary_signature(const unsigned len, 
     17                                            const unsigned char *data, 
     18                                            const ops_signature_t *sig,  
     19                                            const ops_public_key_t *signer __attribute__((unused))) 
     20    { 
     21    // Does the signed hash match the given hash? 
     22 
     23    int n=0; 
     24    ops_hash_t hash; 
     25    unsigned char hashout[OPS_MAX_HASH_SIZE]; 
     26 
     27    //common_init_signature(&hash,sig); 
     28    ops_hash_any(&hash,sig->hash_algorithm); 
     29    hash.init(&hash); 
     30    hash.add(&hash,data,len); 
     31    hash.add(&hash,sig->v4_hashed_data,sig->v4_hashed_data_length); 
     32    n=hash.finish(&hash,hashout); 
     33 
     34    //    return ops_false; 
     35    return ops_check_signature(hashout,n,sig,signer); 
     36    } 
    1137 
    1238static int key_data_reader(void *dest,size_t length,ops_error_t **errors, 
     
    4167 
    4268ops_parse_cb_return_t 
    43 validate_cb(const ops_parser_content_t *content_,ops_parse_cb_info_t *cbinfo) 
     69validate_key_cb(const ops_parser_content_t *content_,ops_parse_cb_info_t *cbinfo) 
    4470    { 
    4571    const ops_parser_content_union_t *content=&content_->content; 
    46     validate_cb_arg_t *arg=ops_parse_cb_get_arg(cbinfo); 
     72    validate_key_cb_arg_t *arg=ops_parse_cb_get_arg(cbinfo); 
    4773    ops_error_t **errors=ops_parse_cb_get_errors(cbinfo); 
    4874    const ops_key_data_t *signer; 
    4975    ops_boolean_t valid=ops_false; 
     76 
     77    if (debug) 
     78        printf("%s\n",ops_show_packet_tag(content_->tag)); 
    5079 
    5180    switch(content_->tag) 
     
    129158            break; 
    130159 
    131     case OPS_SIG_BINARY: 
     160#ifdef MOVED 
    132161    case OPS_SIG_TEXT: 
     162#endif 
    133163    case OPS_SIG_STANDALONE: 
    134164    case OPS_SIG_PRIMARY: 
     
    142172 
    143173        default: 
    144             fprintf(stderr,"Unexpected signature type=0x%02x\n", 
    145                     content->signature.type); 
    146             exit(1); 
     174            OPS_ERROR_1(errors, OPS_E_UNIMPLEMENTED, 
     175                    "Unexpected signature type 0x%02x\n", content->signature.type); 
    147176            } 
    148177 
     
    173202    } 
    174203 
     204ops_parse_cb_return_t 
     205validate_data_cb(const ops_parser_content_t *content_,ops_parse_cb_info_t *cbinfo) 
     206    { 
     207    const ops_parser_content_union_t *content=&content_->content; 
     208    validate_data_cb_arg_t *arg=ops_parse_cb_get_arg(cbinfo); 
     209    ops_error_t **errors=ops_parse_cb_get_errors(cbinfo); 
     210    const ops_key_data_t *signer; 
     211    ops_boolean_t valid=ops_false; 
     212    //    unsigned len=0; 
     213    //    unsigned char *data=NULL; 
     214    ops_memory_t* mem=NULL; 
     215 
     216    if (debug) 
     217        printf("%s\n",ops_show_packet_tag(content_->tag)); 
     218 
     219    switch(content_->tag) 
     220        { 
     221    case OPS_PTAG_CT_SIGNED_CLEARTEXT_HEADER: 
     222        // ignore - this gives us the "Armor Header" line "Hash: SHA1" or similar 
     223        break; 
     224 
     225    case OPS_PTAG_CT_LITERAL_DATA_HEADER: 
     226        // ignore 
     227        break; 
     228 
     229    case OPS_PTAG_CT_LITERAL_DATA_BODY: 
     230        arg->data.literal_data_body=content->literal_data_body; 
     231        arg->use=LITERAL_DATA; 
     232        return OPS_KEEP_MEMORY; 
     233        break; 
     234 
     235    case OPS_PTAG_CT_SIGNED_CLEARTEXT_BODY: 
     236        arg->data.signed_cleartext_body=content->signed_cleartext_body; 
     237        arg->use=SIGNED_CLEARTEXT; 
     238        return OPS_KEEP_MEMORY; 
     239        break; 
     240 
     241    case OPS_PTAG_CT_SIGNED_CLEARTEXT_TRAILER: 
     242        // this gives us an ops_hash_t struct 
     243        break; 
     244 
     245    case OPS_PTAG_CT_SIGNATURE: // V3 sigs 
     246        // this gives us a signature struct with all info about hash alg, etc from the packet 
     247        break; 
     248 
     249    case OPS_PTAG_CT_SIGNATURE_FOOTER: // V4 sigs 
     250         
     251        if (debug) 
     252            { 
     253            printf("\n*** hashed data:\n"); 
     254            unsigned int zzz=0; 
     255            for (zzz=0; zzz<content->signature.v4_hashed_data_length; zzz++) 
     256                printf("0x%02x ", content->signature.v4_hashed_data[zzz]); 
     257            printf("\n"); 
     258            printf("  type=%02x signer_id=",content->signature.type); 
     259            hexdump(content->signature.signer_id, 
     260                    sizeof content->signature.signer_id); 
     261            } 
     262 
     263        signer=ops_keyring_find_key_by_id(arg->keyring, 
     264                                          content->signature.signer_id); 
     265        if(!signer) 
     266            { 
     267            OPS_ERROR(errors,OPS_E_V_UNKNOWN_SIGNER,"Unknown Signer"); 
     268            printf(" UNKNOWN SIGNER\n"); 
     269            ++arg->result->unknown_signer_count; 
     270            break; 
     271            } 
     272         
     273        mem=ops_memory_new(); 
     274        ops_memory_init(mem,128); 
     275         
     276        switch(content->signature.type) 
     277            { 
     278        case OPS_SIG_BINARY: 
     279            switch(arg->use) 
     280                { 
     281            case LITERAL_DATA: 
     282                ops_memory_add(mem, 
     283                               arg->data.literal_data_body.data, 
     284                               arg->data.literal_data_body.length); 
     285                break; 
     286 
     287            case SIGNED_CLEARTEXT: 
     288                ops_memory_add(mem, 
     289                               arg->data.signed_cleartext_body.data, 
     290                               arg->data.signed_cleartext_body.length); 
     291                break; 
     292 
     293            default: 
     294                assert (0); 
     295                } 
     296 
     297            valid=check_binary_signature(ops_memory_get_length(mem),  
     298                                         ops_memory_get_data(mem), 
     299                                         &content->signature, 
     300                                         ops_get_public_key_from_data(signer)); 
     301            break; 
     302 
     303        OPS_ERROR_1(errors, OPS_E_UNIMPLEMENTED, 
     304                    "Verification of signature type 0x%02x not yet implemented\n", content->signature.type); 
     305                    break; 
     306 
     307        default: 
     308            OPS_ERROR_1(errors, OPS_E_UNIMPLEMENTED, 
     309                    "Unexpected signature type 0x%02x\n", content->signature.type); 
     310            exit(1); 
     311            } 
     312    ops_memory_free(mem); 
     313 
     314        if(valid) 
     315            { 
     316            ++arg->result->valid_count; 
     317            } 
     318        else 
     319            { 
     320        OPS_ERROR(errors,OPS_E_V_BAD_SIGNATURE,"Bad Signature"); 
     321            printf(" BAD SIGNATURE\n"); 
     322            ++arg->result->invalid_count; 
     323            } 
     324        break; 
     325 
     326        // ignore these 
     327    case OPS_PARSER_PTAG: 
     328    case OPS_PTAG_CT_SIGNATURE_HEADER: 
     329        //    case OPS_PTAG_CT_SIGNATURE: 
     330        break; 
     331 
     332    default: 
     333        fprintf(stderr,"unexpected tag=0x%x\n",content_->tag); 
     334        assert(0); 
     335        break; 
     336        } 
     337    return OPS_RELEASE_MEMORY; 
     338    } 
     339 
    175340static void key_data_destroyer(ops_reader_info_t *rinfo) 
    176341    { free(ops_reader_get_arg(rinfo)); } 
     
    189354    } 
    190355 
     356/*  
     357 * Validate all signatures on a single key against the given keyring 
     358 */ 
    191359static void validate_key_signatures(ops_validate_result_t *result,const ops_key_data_t *key, 
    192360                                    const ops_keyring_t *keyring) 
    193361    { 
    194362    ops_parse_info_t *pinfo; 
    195     validate_cb_arg_t carg; 
     363    validate_key_cb_arg_t carg; 
    196364 
    197365    memset(&carg,'\0',sizeof carg); 
     
    203371    carg.keyring=keyring; 
    204372 
    205     ops_parse_cb_set(pinfo,validate_cb,&carg); 
     373    ops_parse_cb_set(pinfo,validate_key_cb,&carg); 
    206374    ops_key_data_reader_set(pinfo,key); 
    207375 
  • openpgpsdk/trunk/tests/Makefile.template

    r517 r521  
    4242 
    4343.depend: *.[ch] ../include/openpgpsdk/*.h $(CUNIT_INC) 
    44  
    4544        $(CC) $(CFLAGS) -E -M *.c > .depend 
    4645 
  • openpgpsdk/trunk/tests/test_common.c

    r517 r521  
    7272    close(fd); 
    7373 
    74     snprintf(cmd,MAXBUF,"gpg --openpgp --quiet --gen-key --s2k-cipher-algo \"AES\" --expert --homedir=%s --batch %s",dir,keydetails); 
     74    snprintf(cmd,MAXBUF,"gpg --quiet --no-tty --openpgp --quiet --gen-key --s2k-cipher-algo \"AES\" --expert --homedir=%s --batch %s",dir,keydetails); 
    7575    system(cmd); 
    7676 
     
    9494    close(fd); 
    9595 
    96     snprintf(cmd,MAXBUF,"gpg --openpgp --quiet --gen-key --s2k-cipher-algo \"AES\" --expert --homedir=%s --batch %s",dir,keydetails); 
     96    snprintf(cmd,MAXBUF,"gpg --quiet --no-tty --openpgp --quiet --gen-key --s2k-cipher-algo \"AES\" --expert --homedir=%s --batch %s",dir,keydetails); 
    9797    system(cmd); 
    9898     
     
    184184char* create_testtext(const char *text) 
    185185    { 
    186     const unsigned int repeats=100
     186    const unsigned int repeats=1
    187187    unsigned int i=0; 
    188188 
     
    261261        break; 
    262262         
     263    case OPS_PARSER_PACKET_END: 
     264        // nothing to do 
     265        break; 
     266 
    263267    case OPS_PARSER_ERROR: 
    264268        printf("parse error: %s\n",content->error.error); 
     
    386390// move definition to better location 
    387391ops_parse_cb_return_t 
    388 validate_cb(const ops_parser_content_t *content_,ops_parse_cb_info_t *cbinfo); 
    389  
    390 ops_parse_cb_return_t 
    391 callback_signature(const ops_parser_content_t *content_,ops_parse_cb_info_t *cbinfo) 
     392validate_key_cb(const ops_parser_content_t *content_,ops_parse_cb_info_t *cbinfo); 
     393ops_parse_cb_return_t 
     394validate_data_cb(const ops_parser_content_t *content_,ops_parse_cb_info_t *cbinfo); 
     395 
     396ops_parse_cb_return_t 
     397callback_data_signature(const ops_parser_content_t *content_,ops_parse_cb_info_t *cbinfo) 
    392398    { 
    393399    //    ops_parser_content_union_t* content=(ops_parser_content_union_t *)&content_->content; 
     
    399405    switch(content_->tag) 
    400406        { 
     407    case OPS_PTAG_CT_SIGNED_CLEARTEXT_HEADER: 
     408    case OPS_PTAG_CT_SIGNED_CLEARTEXT_BODY: 
     409    case OPS_PTAG_CT_SIGNED_CLEARTEXT_TRAILER: 
     410 
    401411    case OPS_PTAG_CT_ONE_PASS_SIGNATURE: 
    402412    case OPS_PTAG_CT_SIGNATURE_HEADER: 
    403413    case OPS_PTAG_CT_SIGNATURE_FOOTER: 
    404         return validate_cb(content_,cbinfo); 
     414 
     415    case OPS_PTAG_CT_LITERAL_DATA_HEADER: 
     416    case OPS_PTAG_CT_LITERAL_DATA_BODY: 
     417 
     418    case OPS_PTAG_CT_SIGNATURE: 
     419        return validate_data_cb(content_,cbinfo); 
    405420        break; 
    406421 
  • openpgpsdk/trunk/tests/test_crypt_mpi.c

    r514 r521  
    4242    close(fd); 
    4343 
    44     snprintf(cmd,MAXBUF,"gpg --quiet --gen-key --expert --homedir=%s --batch %s",dir,keydetails); 
     44    snprintf(cmd,MAXBUF,"gpg --quiet --no-tty --homedir=%s --gen-key --expert --batch %s",dir,keydetails); 
    4545    system(cmd); 
    4646 
  • openpgpsdk/trunk/tests/test_rsa_decrypt.c

    r518 r521  
    121121 
    122122    // default symmetric algorithm 
    123     snprintf(cmd,MAXBUF,"gpg --homedir=%s --force-mdc --compress-level 0 --quiet --encrypt --recipient Alpha %s/%s", dir, dir, filename_rsa_noarmour_nopassphrase); 
     123    snprintf(cmd,MAXBUF,"gpg --quiet --no-tty --homedir=%s --force-mdc --compress-level 0 --quiet --encrypt --recipient Alpha %s/%s", dir, dir, filename_rsa_noarmour_nopassphrase); 
    124124    if (system(cmd)) 
    125125        { 
     
    131131    /* 
    132132    // IDEA 
    133     snprintf(cmd,MAXBUF,"gpg --homedir=%s --cipher-algo \"IDEA\" --output=%s/IDEA_%s.gpg  --force-mdc --compress-level 0 --quiet --encrypt --recipient Alpha %s/%s", dir, dir, filename_rsa_noarmour_nopassphrase, dir, filename_rsa_noarmour_nopassphrase); 
     133    snprintf(cmd,MAXBUF,"gpg --quiet --no-tty --homedir=%s --cipher-algo \"IDEA\" --output=%s/IDEA_%s.gpg  --force-mdc --compress-level 0 --quiet --encrypt --recipient Alpha %s/%s", dir, dir, filename_rsa_noarmour_nopassphrase, dir, filename_rsa_noarmour_nopassphrase); 
    134134    if (system(cmd)) 
    135135        { 
     
    140140 
    141141    // TripleDES  
    142     snprintf(cmd,MAXBUF,"gpg --homedir=%s --cipher-algo \"3DES\" --output=%s/3DES_%s.gpg  --force-mdc --compress-level 0 --quiet --encrypt --recipient Alpha %s/%s", dir, dir, filename_rsa_noarmour_nopassphrase, dir, filename_rsa_noarmour_nopassphrase); 
     142    snprintf(cmd,MAXBUF,"gpg --quiet --no-tty --homedir=%s --cipher-algo \"3DES\" --output=%s/3DES_%s.gpg  --force-mdc --compress-level 0 --encrypt --recipient Alpha %s/%s", dir, dir, filename_rsa_noarmour_nopassphrase, dir, filename_rsa_noarmour_nopassphrase); 
    143143    if (system(cmd)) 
    144144        { 
     
    147147 
    148148    // Cast5 
    149     snprintf(cmd,MAXBUF,"gpg --homedir=%s --cipher-algo \"CAST5\" --output=%s/CAST5_%s.gpg  --force-mdc --compress-level 0 --quiet --encrypt --recipient Alpha %s/%s", dir, dir, filename_rsa_noarmour_nopassphrase, dir, filename_rsa_noarmour_nopassphrase); 
     149    snprintf(cmd,MAXBUF,"gpg --quiet --no-tty --homedir=%s --cipher-algo \"CAST5\" --output=%s/CAST5_%s.gpg  --force-mdc --compress-level 0 --encrypt --recipient Alpha %s/%s", dir, dir, filename_rsa_noarmour_nopassphrase, dir, filename_rsa_noarmour_nopassphrase); 
    150150    if (system(cmd)) 
    151151        { 
     
    154154 
    155155    // AES128 
    156     snprintf(cmd,MAXBUF,"gpg --homedir=%s --cipher-algo \"AES\" --output=%s/AES128_%s.gpg  --force-mdc --compress-level 0 --quiet --encrypt --recipient Alpha %s/%s", dir, dir, filename_rsa_noarmour_nopassphrase, dir, filename_rsa_noarmour_nopassphrase); 
     156    snprintf(cmd,MAXBUF,"gpg --quiet --no-tty --homedir=%s --cipher-algo \"AES\" --output=%s/AES128_%s.gpg  --force-mdc --compress-level 0 --encrypt --recipient Alpha %s/%s", dir, dir, filename_rsa_noarmour_nopassphrase, dir, filename_rsa_noarmour_nopassphrase); 
    157157    if (system(cmd)) 
    158158        { 
     
    161161 
    162162    // AES256 
    163     snprintf(cmd,MAXBUF,"gpg --homedir=%s --cipher-algo \"AES256\" --output=%s/AES256_%s.gpg  --force-mdc --compress-level 0 --quiet --encrypt --recipient Alpha %s/%s", dir, dir, filename_rsa_noarmour_nopassphrase, dir, filename_rsa_noarmour_nopassphrase); 
     163    snprintf(cmd,MAXBUF,"gpg --quiet --no-tty --homedir=%s --cipher-algo \"AES256\" --output=%s/AES256_%s.gpg  --force-mdc --compress-level 0 --encrypt --recipient Alpha %s/%s", dir, dir, filename_rsa_noarmour_nopassphrase, dir, filename_rsa_noarmour_nopassphrase); 
    164164    if (system(cmd)) 
    165165        { 
     
    169169 
    170170#ifdef TODO 
    171     snprintf(cmd,MAXBUF,"gpg --openpgp --quiet --encrypt --personal-cipher-preferences='CAST5' --armor --homedir=%s --recipient Alpha %s/%s", dir, dir, filename_rsa_armour_nopassphrase); 
    172     if (system(cmd)) 
    173         { 
    174         return 1; 
    175         } 
    176      
    177     snprintf(cmd,MAXBUF,"gpg --openpgp --quiet --encrypt --s2k-cipher-algo CAST5 --homedir=%s --recipient Bravo %s/%s", dir, dir, filename_rsa_noarmour_passphrase); 
    178     if (system(cmd)) 
    179         { 
    180         return 1; 
    181         } 
    182  
    183     snprintf(cmd,MAXBUF,"gpg --openpgp --quiet --encrypt --s2k-cipher-algo CAST5 --armor --homedir=%s --recipient Bravo %s/%s", dir, dir, filename_rsa_armour_passphrase); 
     171    snprintf(cmd,MAXBUF,"gpg --quiet --no-tty --openpgp --encrypt --personal-cipher-preferences='CAST5' --armor --homedir=%s --recipient Alpha %s/%s", dir, dir, filename_rsa_armour_nopassphrase); 
     172    if (system(cmd)) 
     173        { 
     174        return 1; 
     175        } 
     176     
     177    snprintf(cmd,MAXBUF,"gpg --quiet --no-tty --openpgp --encrypt --s2k-cipher-algo CAST5 --homedir=%s --recipient Bravo %s/%s", dir, dir, filename_rsa_noarmour_passphrase); 
     178    if (system(cmd)) 
     179        { 
     180        return 1; 
     181        } 
     182 
     183    snprintf(cmd,MAXBUF,"gpg --quiet --no-tty --openpgp --encrypt --s2k-cipher-algo CAST5 --armor --homedir=%s --recipient Bravo %s/%s", dir, dir, filename_rsa_armour_passphrase); 
    184184    if (system(cmd)) 
    185185        { 
  • openpgpsdk/trunk/tests/test_rsa_encrypt.c

    r518 r521  
    267267            snprintf(pp,MAXBUF," --passphrase %s ", bravo_passphrase); 
    268268        snprintf(decrypted_file,MAXBUF,"%s/decrypted_%s",dir,filename); 
    269         snprintf(cmd,MAXBUF,"gpg --decrypt --output=%s --quiet --homedir %s %s %s",decrypted_file, dir, pp, encrypted_file); 
     269        snprintf(cmd,MAXBUF,"gpg --quiet --no-tty --decrypt --output=%s --homedir %s %s %s",decrypted_file, dir, pp, encrypted_file); 
    270270        //    printf("cmd: %s\n", cmd); 
    271271        rtn=system(cmd); 
  • openpgpsdk/trunk/tests/test_rsa_signature.c

    r518 r521  
    1212#include "openpgpsdk/validate.h" 
    1313 
     14// \todo change this once we know it works 
     15#include "../src/advanced/parse_local.h" 
     16 
    1417#include "tests.h" 
    1518 
     19static int debug=0; 
    1620static int do_gpgtest=0; 
    1721 
     
    147151        int fd=0; 
    148152        ops_parse_info_t *pinfo=NULL; 
    149         validate_cb_arg_t validate_arg; 
     153        validate_data_cb_arg_t validate_arg; 
    150154        ops_validate_result_t result; 
    151155        int rtn=0; 
     156 
     157        if (debug) 
     158            { 
     159            fprintf(stderr,"\n***\n*** Starting to parse for validation\n***\n"); 
     160            } 
    152161 
    153162    // open signed file 
     
    166175         
    167176        pinfo=ops_parse_info_new(); 
    168         ops_parse_cb_set(pinfo,callback_verify,&validate_arg); 
    169         ops_reader_set_fd(pinfo,fd); 
    170          
     177 
    171178        memset(&validate_arg,'\0',sizeof validate_arg); 
    172179        validate_arg.result=&result; 
     
    174181        validate_arg.rarg=ops_reader_get_arg_from_pinfo(pinfo); 
    175182         
     183        ops_parse_options(pinfo,OPS_PTAG_SS_ALL,OPS_PARSE_PARSED); 
     184        ops_parse_cb_set(pinfo,callback_verify,&validate_arg); 
     185        ops_reader_set_fd(pinfo,fd); 
     186        pinfo->rinfo.accumulate=ops_true; 
     187         
    176188        // Set up armour/passphrase options 
    177189         
     
    190202            ops_reader_pop_dearmour(pinfo); 
    191203         
    192         ops_public_key_free(&validate_arg.pkey); 
    193         if (validate_arg.subkey.version) 
    194             ops_public_key_free(&validate_arg.subkey); 
    195         ops_user_id_free(&validate_arg.user_id); 
    196         ops_user_attribute_free(&validate_arg.user_attribute); 
    197204        ops_parse_info_delete(pinfo); 
    198205         
     
    203210        // Check signature with GPG 
    204211 
    205         snprintf(cmd,MAXBUF,"gpg --verify --quiet --homedir %s %s", dir, signed_file); 
     212        snprintf(cmd,MAXBUF,"gpg --quiet --no-tty --verify --quiet --homedir %s %s", dir, signed_file); 
    206213        rtn=system(cmd); 
    207214        CU_ASSERT(rtn==0); 
     
    265272            return NULL; 
    266273     
     274#ifdef TBD 
    267275    if (NULL == CU_add_test(suite, "Armoured, passphrase", test_rsa_signature_armour_passphrase)) 
    268276            return NULL; 
    269      
     277#endif     
    270278     
    271279    return suite; 
     
    304312callback_verify(const ops_parser_content_t *content_,ops_parse_cb_info_t *cbinfo) 
    305313    { 
    306     //    ops_parser_content_union_t* content=(ops_parser_content_union_t *)&content_->content; 
    307  
    308     //        ops_print_packet(content_); 
     314    int debug=0; 
     315 
     316    if (debug) 
     317        { ops_print_packet(content_); } 
    309318 
    310319    switch(content_->tag) 
    311         { 
    312     case OPS_PTAG_CT_LITERAL_DATA_HEADER: 
     320        { 
     321    case OPS_PTAG_RAW_SS: 
     322    case OPS_PTAG_SS_CREATION_TIME: 
     323    case OPS_PTAG_SS_ISSUER_KEY_ID: 
     324        // \todo should free memory? 
     325        return OPS_KEEP_MEMORY; 
     326         
     327    case OPS_PTAG_CT_ONE_PASS_SIGNATURE: 
     328    case OPS_PTAG_CT_ARMOUR_HEADER: 
     329    case OPS_PTAG_CT_ARMOUR_TRAILER: 
    313330        break; 
    314  
    315     case OPS_PTAG_CT_LITERAL_DATA_BODY: 
    316         return callback_literal_data(content_,cbinfo); 
    317         break; 
    318  
    319     case OPS_PTAG_CT_ONE_PASS_SIGNATURE: 
    320  case OPS_PTAG_CT_SIGNATURE: 
    321  case OPS_PTAG_CT_SIGNED_CLEARTEXT_HEADER: 
    322  case OPS_PTAG_CT_SIGNED_CLEARTEXT_BODY: 
    323  case OPS_PTAG_CT_SIGNED_CLEARTEXT_TRAILER: 
    324  case OPS_PTAG_CT_ARMOUR_HEADER: 
    325  case OPS_PTAG_CT_ARMOUR_TRAILER: 
    326         break; 
    327  
     331         
     332    case OPS_PTAG_CT_SIGNATURE: 
     333    case OPS_PTAG_CT_SIGNED_CLEARTEXT_HEADER: 
     334    case OPS_PTAG_CT_SIGNED_CLEARTEXT_BODY: 
     335    case OPS_PTAG_CT_SIGNED_CLEARTEXT_TRAILER: 
    328336    case OPS_PTAG_CT_SIGNATURE_HEADER: 
    329337    case OPS_PTAG_CT_SIGNATURE_FOOTER: 
    330         return callback_signature(content_, cbinfo); 
    331  
    332         /* 
    333     case OPS_PTAG_CT_UNARMOURED_TEXT: 
    334         printf("OPS_PTAG_CT_UNARMOURED_TEXT\n"); 
    335         if(!skipping) 
    336             { 
    337             puts("Skipping..."); 
    338             skipping=ops_true; 
    339             } 
    340         fwrite(content->unarmoured_text.data,1, 
    341                content->unarmoured_text.length,stdout); 
    342         break; 
    343  
    344     case OPS_PTAG_CT_PK_SESSION_KEY: 
    345         return callback_pk_session_key(content_,cbinfo); 
    346  
    347     case OPS_PARSER_CMD_GET_SECRET_KEY: 
    348         return callback_cmd_get_secret_key(content_,cbinfo); 
    349  
    350     case OPS_PARSER_CMD_GET_SK_PASSPHRASE: 
    351         return callback_cmd_get_secret_key_passphrase(content_,cbinfo); 
    352  
     338    case OPS_PTAG_CT_LITERAL_DATA_HEADER: 
    353339    case OPS_PTAG_CT_LITERAL_DATA_BODY: 
    354         return callback_literal_data(content_,cbinfo); 
    355         //      text=ops_mallocz(content->literal_data_body.length+1); 
    356         //      memcpy(text,content->literal_data_body.data,content->literal_data_body.length); 
    357         //              break; 
    358  
    359     case OPS_PARSER_PTAG: 
    360     case OPS_PTAG_CT_ARMOUR_HEADER: 
    361     case OPS_PTAG_CT_ARMOUR_TRAILER: 
    362     case OPS_PTAG_CT_ENCRYPTED_PK_SESSION_KEY: 
    363     case OPS_PTAG_CT_COMPRESSED: 
    364     case OPS_PTAG_CT_SE_IP_DATA_BODY: 
    365     case OPS_PTAG_CT_SE_IP_DATA_HEADER: 
    366         // Ignore these packets  
    367         // They're handled in ops_parse_one_packet() 
    368         // and nothing else needs to be done 
    369         break; 
    370 */ 
     340        return callback_data_signature(content_, cbinfo); 
    371341 
    372342    default: 
  • openpgpsdk/trunk/tests/test_rsa_verify.c

    r517 r521  
    1111#include "openpgpsdk/validate.h" 
    1212 
     13// \todo change this once we know it works 
     14#include "../src/advanced/parse_local.h" 
     15 
    1316#include "tests.h" 
    1417 
     
    3740    switch(content_->tag) 
    3841        { 
     42        /* 
    3943    case OPS_PTAG_CT_LITERAL_DATA_HEADER: 
    4044        break; 
     
    4347        return callback_literal_data(content_,cbinfo); 
    4448        break; 
     49        */ 
    4550 
    4651    case OPS_PTAG_CT_ONE_PASS_SIGNATURE: 
     52        break; 
     53 
    4754    case OPS_PTAG_CT_SIGNATURE: 
    48         break; 
    49  
    5055    case OPS_PTAG_CT_SIGNATURE_HEADER: 
    5156    case OPS_PTAG_CT_SIGNATURE_FOOTER: 
    52         return callback_signature(content_, cbinfo); 
     57    case OPS_PTAG_CT_LITERAL_DATA_HEADER: 
     58    case OPS_PTAG_CT_LITERAL_DATA_BODY: 
     59        return callback_data_signature(content_, cbinfo); 
    5360 
    5461        /* 
     
    116123    // Now sign the test files with GPG 
    117124 
    118     snprintf(cmd,MAXBUF,"gpg --homedir=%s --quiet --openpgp --compress-level 0 --sign --local-user %s %s/%s", 
     125    snprintf(cmd,MAXBUF,"gpg --quiet --no-tty --homedir=%s --openpgp --compress-level 0 --sign --local-user %s %s/%s", 
    119126             dir, alpha_name, dir, filename_rsa_noarmour_nopassphrase); 
    120127    if (system(cmd)) 
    121128        { return 1; } 
    122129 
    123     snprintf(cmd,MAXBUF,"gpg --homedir=%s --quiet --compress-level 0 --sign --armour --local-user %s %s/%s", 
     130    snprintf(cmd,MAXBUF,"gpg --quiet --no-tty --homedir=%s --compress-level 0 --sign --armour --local-user %s %s/%s", 
    124131             dir, alpha_name, dir, filename_rsa_armour_nopassphrase); 
    125132    if (system(cmd)) 
    126133        { return 1; } 
    127134 
    128     snprintf(cmd,MAXBUF,"gpg --homedir=%s --quiet --compress-level 0 --sign --local-user %s --passphrase %s %s/%s", 
     135    snprintf(cmd,MAXBUF,"gpg --quiet --no-tty --homedir=%s --compress-level 0 --sign --local-user %s --passphrase %s %s/%s", 
    129136             dir, bravo_name, bravo_passphrase, dir, filename_rsa_noarmour_passphrase); 
    130137    if (system(cmd)) 
    131138        { return 1; } 
    132139 
    133     snprintf(cmd,MAXBUF,"gpg --homedir=%s --quiet --compress-level 0 --sign --armour --local-user %s --passphrase %s %s/%s", 
     140    snprintf(cmd,MAXBUF,"gpg --quiet --no-tty  --homedir=%s --compress-level 0 --sign --armour --local-user %s --passphrase %s %s/%s", 
    134141             dir, bravo_name, bravo_passphrase, dir, filename_rsa_armour_passphrase); 
    135142    if (system(cmd)) 
     
    156163    int fd=0; 
    157164    ops_parse_info_t *pinfo=NULL; 
    158     validate_cb_arg_t validate_arg; 
     165    validate_data_cb_arg_t validate_arg; 
    159166    ops_validate_result_t result; 
    160167    int rtn=0; 
     
    179186 
    180187    pinfo=ops_parse_info_new(); 
    181     ops_parse_cb_set(pinfo,callback,&validate_arg); 
    182     ops_reader_set_fd(pinfo,fd); 
    183188 
    184189    memset(&validate_arg,'\0',sizeof validate_arg); 
     
    187192    validate_arg.rarg=ops_reader_get_arg_from_pinfo(pinfo); 
    188193 
     194    ops_parse_cb_set(pinfo,callback,&validate_arg); 
     195    ops_reader_set_fd(pinfo,fd); 
     196    pinfo->rinfo.accumulate=ops_true; 
     197 
    189198    // Set up armour/passphrase options 
    190199 
     
    203212        ops_reader_pop_dearmour(pinfo); 
    204213 
    205     ops_public_key_free(&validate_arg.pkey); 
    206     if (validate_arg.subkey.version) 
    207         ops_public_key_free(&validate_arg.subkey); 
    208     ops_user_id_free(&validate_arg.user_id); 
    209     ops_user_attribute_free(&validate_arg.user_attribute); 
    210214    ops_parse_info_delete(pinfo); 
    211215 
  • openpgpsdk/trunk/tests/tests.h

    r517 r521  
    2828extern CU_pSuite suite_rsa_decrypt(); 
    2929extern CU_pSuite suite_rsa_encrypt(); 
    30 extern CU_pSuite suite_rsa_encrypt_GPGtest(); 
    3130extern CU_pSuite suite_rsa_signature(); 
    3231extern CU_pSuite suite_rsa_verify(); 
     32 
     33extern CU_pSuite suite_rsa_decrypt_GPGtest(); 
     34extern CU_pSuite suite_rsa_encrypt_GPGtest(); 
     35extern CU_pSuite suite_rsa_signature_GPGtest(); 
     36extern CU_pSuite suite_rsa_verify_GPGtest(); 
    3337 
    3438// utility functions 
     
    5559callback_pk_session_key(const ops_parser_content_t *content_,ops_parse_cb_info_t *cbinfo); 
    5660ops_parse_cb_return_t 
    57 callback_signature(const ops_parser_content_t *content_,ops_parse_cb_info_t *cbinfo); 
     61callback_data_signature(const ops_parser_content_t *content_,ops_parse_cb_info_t *cbinfo); 
    5862 
    5963void reset_vars(); 
  • openpgpsdk/trunk/tests/tests_gpg.c

    r517 r521  
    3030        } 
    3131 
    32 #ifdef TODO 
    33     if (NULL == suite_rsa_decrypt_GPGtest())  
     32    if (NULL == suite_rsa_signature_GPGtest())  
    3433        { 
    3534        CU_cleanup_registry(); 
     
    3736        } 
    3837 
    39     if (NULL == suite_rsa_signature_GPGtest())  
     38#ifdef TODO 
     39 
     40    if (NULL == suite_rsa_decrypt_GPGtest())  
    4041        { 
    4142        CU_cleanup_registry(); 
     
    6667        return CU_get_error(); 
    6768        } 
    68 #endif 
     69 #endif 
    6970 
    7071    // Run tests