Ticket #179: gemsafeV1.key_ref.patch
| File gemsafeV1.key_ref.patch, 2.6 KB (added by dengert, 4 years ago) |
|---|
-
pkcs15-gemsafeV1.c
114 114 { NULL, NULL, 0, 0, NULL, 0, NULL, 0} 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; 123 125 size_t objlen, certlen; … … 146 148 return 0; 147 149 } 148 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; 169 } 170 149 171 /* Using (block+1) in while loop avoids using final cert object data block */ 150 172 while (!found && ( (block+1) * 248 < objlen) ) { 151 173 /* Check current buffer */ … … 193 215 const char *fn_name = "sc_pkcs15emu_gemsafe_init"; 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; 198 221 struct sc_card *card = p15card->card; … … 252 275 struct sc_pkcs15_id p15Id; 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; 258 281 sc_pkcs15_format_id(gemsafe_cert[i].id, &p15Id); … … 284 307 pauthId = &authId; 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 } 293 326
