- Timestamp:
- 08/20/08 17:17:59 (3 months ago)
- Files:
-
- 1 modified
-
trunk/src/libopensc/pkcs15-gemsafeV1.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/libopensc/pkcs15-gemsafeV1.c
r3502 r3557 115 115 }; 116 116 117 static int gemsafe_get_cert_len(sc_card_t *card, sc_path_t *path) 117 static int gemsafe_get_cert_len(sc_card_t *card, sc_path_t *path, 118 int *key_ref) 118 119 { 119 120 const char *fn_name = "gemsafe_get_cert_len"; 120 121 int r; 122 int ind; 121 123 u8 ibuf[248]; 122 124 struct sc_file *file; … … 145 147 sc_error(card->ctx, "%s: Invalid object size: %d\n", fn_name, objlen); 146 148 return 0; 149 } 150 151 /* 152 * We need to find the private key associated with the cert 153 * It looks like the first thing in the block is a table of 154 * which keys are allocated. 155 * We will look for the first allocated key, and save the 156 * key_ref. The table is small and is in the first 248 bytes. 157 * If for some reason this is not true, we can still override 158 * the key_ref in the opensc.conf with flag = n. 159 */ 160 ind = 2; /* skip length */ 161 while (ibuf[ind] == 0x01) { 162 if (ibuf[ind+1] == 0xFE) { 163 *key_ref = ibuf[ind+4]; 164 sc_debug(card->ctx, "Using key_ref %d found at offset %d\n", 165 *key_ref, ind); 166 break; 167 } 168 ind = ind + 8; 147 169 } 148 170 … … 194 216 195 217 int r, i; 218 int key_ref = 0x03; 196 219 struct sc_path path; 197 220 struct sc_file *file = NULL; … … 253 276 254 277 sc_format_path(gemsafe_cert[i].path, &path); 255 if (!gemsafe_get_cert_len(card, &path ))278 if (!gemsafe_get_cert_len(card, &path, &key_ref)) 256 279 /* skip errors */ 257 280 continue; … … 285 308 } else 286 309 pauthId = NULL; 310 /* 311 * the key ref may be different for different sites 312 * by adding flags=n where the low order 4 bits can be 313 * the key ref we can force it. 314 */ 315 if ( p15card->card->flags & 0x0F) { 316 key_ref = p15card->card->flags & 0x0F; 317 sc_debug(p15card->card->ctx, 318 "Overriding key_ref with %d\n", key_ref); 319 } 287 320 sc_pkcs15emu_add_prkey(p15card, &p15Id, gemsafe_prkeys[i].label, 288 321 SC_PKCS15_TYPE_PRKEY_RSA, 289 322 gemsafe_prkeys[i].modulus_len, gemsafe_prkeys[i].usage, 290 &path, gemsafe_prkeys[i].ref, pauthId,323 &path, key_ref, pauthId, 291 324 gemsafe_prkeys[i].obj_flags); 292 325 }
