Changeset 3028

Show
Ignore:
Timestamp:
09/26/06 10:55:02 (2 years ago)
Author:
henryk
Message:

Make absolute paths from all paths read from the PKCS#15 directories by prepending the DF(PKCS#15) path if necessary.
Fixes compatibility with Siemens HiPath? SIcurity formatted cards which use relative paths.

Location:
trunk/src/libopensc
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/libopensc/pkcs15-cert.c

    r2815 r3028  
    219219                return r; 
    220220        SC_TEST_RET(ctx, r, "ASN.1 decoding failed"); 
     221        r = sc_pkcs15_make_absolute_path(&p15card->file_app->path, &info.path); 
     222        if (r < 0) 
     223                return r; 
    221224        obj->type = SC_PKCS15_TYPE_CERT_X509; 
    222225        obj->data = malloc(sizeof(info)); 
  • trunk/src/libopensc/pkcs15-data.c

    r2815 r3028  
    110110        if (r == SC_ERROR_ASN1_END_OF_CONTENTS) 
    111111                return r; 
    112  
    113112        SC_TEST_RET(ctx, r, "ASN.1 decoding failed"); 
     113        r = sc_pkcs15_make_absolute_path(&p15card->file_app->path, &info.path); 
     114        if (r < 0) 
     115                return r; 
    114116        obj->type = SC_PKCS15_TYPE_DATA_OBJECT; 
    115117        obj->data = malloc(sizeof(info)); 
  • trunk/src/libopensc/pkcs15-prkey.c

    r2815 r3028  
    154154                SC_FUNC_RETURN(ctx, 0, SC_ERROR_INVALID_ASN1_OBJECT); 
    155155        } 
     156        r = sc_pkcs15_make_absolute_path(&p15card->file_app->path, &info.path); 
     157        if (r < 0) 
     158                return r; 
    156159        obj->data = malloc(sizeof(info)); 
    157160        if (obj->data == NULL) 
  • trunk/src/libopensc/pkcs15-pubkey.c

    r2815 r3028  
    136136                obj->type = SC_PKCS15_TYPE_PUBKEY_DSA; 
    137137        } 
     138        r = sc_pkcs15_make_absolute_path(&p15card->file_app->path, &info.path); 
     139        if (r < 0) 
     140                return r; 
    138141        obj->data = malloc(sizeof(info)); 
    139142        if (obj->data == NULL) 
  • trunk/src/libopensc/pkcs15.c

    r3027 r3028  
    314314        const u8 *p = buf; 
    315315        size_t left = buflen; 
    316         int r, i; 
     316        int r, i, type; 
    317317        sc_path_t path; 
    318318        struct sc_asn1_entry asn1_obj_or_path[] = { 
     
    331331                if (r < 0) 
    332332                        return r; 
    333                 r = sc_pkcs15_add_df(card, odf_indexes[r], &path, NULL); 
     333                type = r; 
     334                r = sc_pkcs15_make_absolute_path(&card->file_app->path, &path); 
     335                if (r < 0) 
     336                        return r; 
     337                r = sc_pkcs15_add_df(card, odf_indexes[type], &path, NULL); 
    334338                if (r) 
    335339                        return r; 
     
    15341538                        return r; 
    15351539                /* If the path length is 0, it's a dummy path then don't add it. 
    1536                  * If the path length isn't include (-1) then it's against the standard 
     1540                 * If the path length isn't included (-1) then it's against the standard 
    15371541                 *   but we'll just ignore it instead of returning an error. */ 
    15381542                if (path.count > 0) { 
     1543                        r = sc_pkcs15_make_absolute_path(&card->file_app->path, &path); 
     1544                        if (r < 0) 
     1545                                return r; 
    15391546                        r = sc_pkcs15_add_unusedspace(card, &path, &auth_id); 
    15401547                        if (r) 
     
    15541561{ 
    15551562        sc_file_t *file = NULL; 
    1556         sc_path_t tmp_path, *path = &tmp_path; 
    15571563        u8      *data = NULL; 
    15581564        size_t  len = 0, offset = 0; 
     
    15721578        } 
    15731579 
    1574         if (in_path->type == SC_PATH_TYPE_FILE_ID) { 
    1575                 /* in case of a FID prepend the application DF */ 
    1576                 memcpy(path, &p15card->file_app->path, sizeof(sc_path_t)); 
    1577                 sc_append_path(path, in_path); 
    1578                 path->index = in_path->index; 
    1579                 path->count = in_path->count; 
    1580         } else { 
    1581                 memcpy(path, in_path, sizeof(sc_path_t)); 
    1582         } 
    15831580        r = -1; /* file state: not in cache */ 
    15841581        if (p15card->opts.use_cache) { 
    1585                 r = sc_pkcs15_read_cached_file(p15card, path, &data, &len); 
     1582                r = sc_pkcs15_read_cached_file(p15card, in_path, &data, &len); 
    15861583        } 
    15871584        if (r) { 
    15881585                r = sc_lock(p15card->card); 
    15891586                SC_TEST_RET(p15card->card->ctx, r, "sc_lock() failed"); 
    1590                 r = sc_select_file(p15card->card, path, &file); 
     1587                r = sc_select_file(p15card->card, in_path, &file); 
    15911588                if (r) 
    15921589                        goto fail_unlock; 
     
    15941591                /* Handle the case where the ASN.1 Path object specified 
    15951592                 * index and length values */ 
    1596                 if (path->count < 0) { 
     1593                if (in_path->count < 0) { 
    15971594                        len = file->size; 
    15981595                        offset = 0; 
    15991596                } else { 
    1600                         offset = path->index; 
    1601                         len = path->count; 
     1597                        offset = in_path->index; 
     1598                        len = in_path->count; 
    16021599                        /* Make sure we're within proper bounds */ 
    16031600                        if (offset >= file->size 
     
    17141711        return sc_hex_to_bin(in, out->value, &out->len); 
    17151712} 
     1713 
     1714int sc_pkcs15_make_absolute_path(const sc_path_t *parent, sc_path_t *child) 
     1715{ 
     1716        if (sc_compare_path_prefix(sc_get_mf_path(), child)) 
     1717                return 0; 
     1718        return sc_concatenate_path(child, parent, child); 
     1719} 
  • trunk/src/libopensc/pkcs15.h

    r2872 r3028  
    633633void sc_der_copy(sc_pkcs15_der_t *, const sc_pkcs15_der_t *); 
    634634void sc_der_clear(sc_pkcs15_der_t *); 
     635/* Prepend 'parent' to 'child' in case 'child' is a relative path */ 
     636int sc_pkcs15_make_absolute_path(const sc_path_t *parent, sc_path_t *child); 
    635637 
    636638/* New object search API.