Changeset 527

Show
Ignore:
Timestamp:
12/12/07 11:24:01
Author:
rachel
Message:

Changes needed to get V4 cleartext sigs working

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • openpgpsdk/trunk/examples/packet-dump.c

    r511 r527  
    1515#include <string.h> 
    1616#include <fcntl.h> 
     17 
     18// \todo change this once we know it works 
     19#include "../src/advanced/parse_local.h" 
    1720 
    1821#include <openpgpsdk/final.h> 
     
    11001103        ops_reader_set_fd(pinfo,fd); 
    11011104 
     1105    pinfo->rinfo.accumulate=ops_true; 
     1106 
    11021107    if(armour) 
    11031108        ops_reader_push_dearmour(pinfo,ops_true,ops_true,ops_true); 
  • openpgpsdk/trunk/include/openpgpsdk/errors.h

    r521 r527  
    4949    OPS_E_ALG_UNSUPPORTED_SYMMETRIC_ALG         =OPS_E_ALG+1, 
    5050    OPS_E_ALG_UNSUPPORTED_PUBLIC_KEY_ALG        =OPS_E_ALG+2, 
    51     OPS_E_ALG_UNSUPPORTED_SIGNATURE_KEY_ALG   =OPS_E_ALG+3, 
     51    OPS_E_ALG_UNSUPPORTED_SIGNATURE_ALG       =OPS_E_ALG+3, 
    5252    OPS_E_ALG_UNSUPPORTED_HASH_ALG              =OPS_E_ALG+4, 
    5353 
  • openpgpsdk/trunk/src/advanced/adv_errors.c

    r517 r527  
    2929    { OPS_E_R_READ_FAILED, "OPS_E_R_READ_FAILED" }, 
    3030    { OPS_E_R_EARLY_EOF, "OPS_E_R_EARLY_EOF" }, 
     31    { OPS_E_R_BAD_FORMAT, "OPS_E_R_BAD_FORMAT" }, 
     32    { OPS_E_R_UNCONSUMED_DATA, "OPS_E_R_UNCONSUMED_DATA" }, 
    3133 
    3234    { OPS_E_W,  "OPS_E_W" }, 
     
    4042    ERR(OPS_E_P_MPI_FORMAT_ERROR), 
    4143 
    42     { OPS_E_PROTO, "OPS_E_PROTO" }, 
    43     { OPS_E_PROTO_BAD_SYMMETRIC_DECRYPT, "OPS_E_PROTO_BAD_SYMMETRIC_DECRYPT" }, 
     44    { OPS_E_C,  "OPS_E_C" }, 
    4445 
    45     { OPS_E_C,  "OPS_E_C" }, 
     46    ERR(OPS_E_V), 
     47    ERR(OPS_E_V_BAD_SIGNATURE), 
     48    ERR(OPS_E_V_UNKNOWN_SIGNER), 
     49 
     50    ERR(OPS_E_ALG), 
     51    ERR(OPS_E_ALG_UNSUPPORTED_SYMMETRIC_ALG), 
     52    ERR(OPS_E_ALG_UNSUPPORTED_PUBLIC_KEY_ALG), 
     53    ERR(OPS_E_ALG_UNSUPPORTED_SIGNATURE_ALG), 
     54    ERR(OPS_E_ALG_UNSUPPORTED_HASH_ALG), 
     55 
     56    ERR(OPS_E_PROTO), 
     57    ERR(OPS_E_PROTO_BAD_SYMMETRIC_DECRYPT), 
     58    ERR(OPS_E_PROTO_UNKNOWN_SS), 
     59    ERR(OPS_E_PROTO_CRITICAL_SS_IGNORED), 
     60    ERR(OPS_E_PROTO_BAD_PUBLIC_KEY_VRSN), 
     61    ERR(OPS_E_PROTO_BAD_SIGNATURE_VRSN), 
     62    ERR(OPS_E_PROTO_BAD_ONE_PASS_SIG_VRSN), 
     63    ERR(OPS_E_PROTO_BAD_PKSK_VRSN), 
     64    ERR(OPS_E_PROTO_DECRYPTED_MSG_WRONG_LEN), 
     65    ERR(OPS_E_PROTO_BAD_SK_CHECKSUM), 
     66 
    4667 
    4768    { (int) NULL,               (char *)NULL }, /* this is the end-of-array marker */ 
  • openpgpsdk/trunk/src/advanced/adv_packet-parse.c

    r521 r527  
    12711271 
    12721272    default: 
    1273         OPS_ERROR_1(&pinfo->errors,OPS_E_ALG_UNSUPPORTED_SIGNATURE_KEY_ALG, 
     1273        OPS_ERROR_1(&pinfo->errors,OPS_E_ALG_UNSUPPORTED_SIGNATURE_ALG, 
    12741274                    "Unsupported signature key algorithm (%s)", 
    12751275                    ops_show_pka(C.signature.key_algorithm)); 
     
    17301730 
    17311731    default: 
    1732         OPS_ERROR_1(&pinfo->errors,OPS_E_ALG_UNSUPPORTED_SIGNATURE_KEY_ALG, 
     1732        OPS_ERROR_1(&pinfo->errors,OPS_E_ALG_UNSUPPORTED_SIGNATURE_ALG, 
    17331733                    "Bad v4 signature key algorithm (%s)", 
    17341734                    ops_show_pka(C.signature.key_algorithm)); 
  • openpgpsdk/trunk/src/advanced/adv_signature.c

    r521 r527  
    179179    { 
    180180    unsigned char sigbuf[8192]; 
    181     unsigned char hashbuf[8192]; 
     181    unsigned char hashbuf_from_sig[8192]; 
    182182    unsigned n; 
    183183    unsigned keysize; 
     
    187187    keysize=BN_num_bytes(rsa->n); 
    188188    /* RSA key can't be bigger than 65535 bits, so... */ 
    189     assert(keysize <= sizeof hashbuf); 
     189    assert(keysize <= sizeof hashbuf_from_sig); 
    190190    assert((unsigned)BN_num_bits(sig->sig) <= 8*sizeof sigbuf); 
    191191    BN_bn2bin(sig->sig,sigbuf); 
    192192 
    193     n=ops_rsa_public_decrypt(hashbuf,sigbuf,(BN_num_bits(sig->sig)+7)/8,rsa); 
     193    n=ops_rsa_public_decrypt(hashbuf_from_sig,sigbuf,(BN_num_bits(sig->sig)+7)/8,rsa); 
     194    int debug_len_decrypted=n; 
    194195 
    195196    if(n != keysize) // obviously, this includes error returns 
    196197        return ops_false; 
    197198 
    198     /* 
    199     printf(" decrypt=%d ",n); 
    200     hexdump(hashbuf,n); 
    201     */ 
    202  
    203199    // XXX: why is there a leading 0? The first byte should be 1... 
    204200    // XXX: because the decrypt should use keysize and not sigsize? 
    205     if(hashbuf[0] != 0 || hashbuf[1] != 1) 
     201    if(hashbuf_from_sig[0] != 0 || hashbuf_from_sig[1] != 1) 
    206202        return ops_false; 
    207203 
     
    217213 
    218214    for(n=2 ; n < keysize-plen-hash_length-1 ; ++n) 
    219         if(hashbuf[n] != 0xff) 
     215        if(hashbuf_from_sig[n] != 0xff) 
    220216            return ops_false; 
    221217 
    222     if(hashbuf[n++] != 0) 
     218    if(hashbuf_from_sig[n++] != 0) 
    223219        return ops_false; 
    224220 
     
    228224 
    229225        printf("\n"); 
    230         printf("hashbuf\n"); 
    231         for (zz=0; zz<plen; zz++) 
    232             { printf("%02x ", hashbuf[n+zz]); } 
     226        printf("hashbuf_from_sig\n"); 
     227        for (zz=0; zz<debug_len_decrypted; zz++) 
     228            { printf("%02x ", hashbuf_from_sig[n+zz]); } 
    233229        printf("\n"); 
    234230        printf("prefix\n"); 
     
    238234 
    239235        printf("\n"); 
    240         printf("hashbuf2\n"); 
     236        printf("hash from sig\n"); 
    241237        unsigned uu; 
    242238        for (uu=0; uu<hash_length; uu++) 
    243             { printf("%02x ", hashbuf[n+plen+uu]); } 
     239            { printf("%02x ", hashbuf_from_sig[n+plen+uu]); } 
    244240        printf("\n"); 
    245         printf("hash\n"); 
     241        printf("hash passed in (should match hash from sig)\n"); 
    246242        for (uu=0; uu<hash_length; uu++) 
    247243            { printf("%02x ", hash[uu]); } 
    248244        printf("\n"); 
    249245        } 
    250     if(memcmp(&hashbuf[n],prefix,plen) 
    251        || memcmp(&hashbuf[n+plen],hash,hash_length)) 
     246    if(memcmp(&hashbuf_from_sig[n],prefix,plen) 
     247       || memcmp(&hashbuf_from_sig[n+plen],hash,hash_length)) 
    252248        return ops_false; 
    253249 
     
    641637    sig->hash.add(&sig->hash,ops_memory_get_data(sig->mem), 
    642638                  sig->unhashed_count_offset); 
    643     /* what is this??? should delete? RW 
     639 
     640    // add final trailer 
    644641    ops_hash_add_int(&sig->hash,sig->sig.version,1); 
    645642    ops_hash_add_int(&sig->hash,0xff,1); 
    646643    // +6 for version, type, pk alg, hash alg, hashed subpacket length 
    647644    ops_hash_add_int(&sig->hash,sig->hashed_data_length+6,4); 
    648     */ 
    649645 
    650646    if (debug) 
  • openpgpsdk/trunk/src/advanced/adv_validate.c

    r521 r527  
    2424    ops_hash_t hash; 
    2525    unsigned char hashout[OPS_MAX_HASH_SIZE]; 
     26    unsigned char trailer[6]; 
     27    unsigned int hashedlen; 
    2628 
    2729    //common_init_signature(&hash,sig); 
     
    3032    hash.add(&hash,data,len); 
    3133    hash.add(&hash,sig->v4_hashed_data,sig->v4_hashed_data_length); 
     34 
     35    trailer[0]=0x04; // version 
     36    trailer[1]=0xFF; 
     37    hashedlen=sig->v4_hashed_data_length; 
     38    trailer[2]=hashedlen >> 24; 
     39    trailer[3]=hashedlen >> 16; 
     40    trailer[4]=hashedlen >> 8; 
     41    trailer[5]=hashedlen; 
     42    hash.add(&hash,&trailer[0],6); 
     43 
    3244    n=hash.finish(&hash,hashout); 
    3345 
     
    277289            { 
    278290        case OPS_SIG_BINARY: 
     291        case OPS_SIG_TEXT: 
    279292            switch(arg->use) 
    280293                { 
     
    292305 
    293306            default: 
    294                 assert (0); 
     307                OPS_ERROR_1(errors,OPS_E_UNIMPLEMENTED,"Unimplemented Sig Use %d", arg->use); 
     308                printf(" Unimplemented Sig Use %d\n", arg->use); 
     309                break; 
    295310                } 
    296311 
     
    308323            OPS_ERROR_1(errors, OPS_E_UNIMPLEMENTED, 
    309324                    "Unexpected signature type 0x%02x\n", content->signature.type); 
    310           exit(1); 
     325            //            exit(1); 
    311326            } 
    312327    ops_memory_free(mem); 
  • openpgpsdk/trunk/tests/test_rsa_verify.c

    r525 r527  
    8282    // and sign them 
    8383 
    84     snprintf(cmd,MAXBUF,"%s --openpgp --compress-level 0 --clearsign --local-user %s --armor %s/%s", 
     84    snprintf(cmd,MAXBUF,"%s --openpgp --compress-level 0 --clearsign --textmode --local-user %s --armor %s/%s", 
    8585             gpgcmd, alpha_name, dir, filename_rsa_clearsign_nopassphrase); 
    8686    if (system(cmd)) 
    8787        { return 1; } 
    8888 
    89     snprintf(cmd,MAXBUF,"%s --openpgp --compress-level 0 --clearsign --local-user %s --passphrase %s --armor %s/%s", 
     89    snprintf(cmd,MAXBUF,"%s --openpgp --compress-level 0 --clearsign --textmode --local-user %s --passphrase %s --armor %s/%s", 
    9090             gpgcmd, bravo_name, bravo_passphrase, dir, filename_rsa_clearsign_passphrase); 
    9191    if (system(cmd))