Changeset 3478 for trunk/src/libopensc/pkcs15-rutoken.c
- Timestamp:
- 04/18/08 14:08:23 (9 months ago)
- Files:
-
- 1 modified
-
trunk/src/libopensc/pkcs15-rutoken.c (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/libopensc/pkcs15-rutoken.c
r3444 r3478 1 1 /* 2 * PKCS15 emulation layer for ruToken2 * PKCS15 emulation layer for Rutoken 3 3 * 4 4 * Copyright (C) 2007 Pavel Mironchik <rutoken@rutoken.ru> … … 29 29 #include <stdarg.h> 30 30 #include <opensc/opensc.h> 31 #include "cardctl.h"32 31 #include <opensc/log.h> 33 32 #include <opensc/pkcs15.h> 34 35 #define RUT_LABEL "ruToken card" 33 #include "cardctl.h" 36 34 37 35 #define PrKDF_path "3F00FF000001" … … 39 37 #define CDF_path "3F00FF000003" 40 38 #define DODF_path "3F00FF000004" 41 #define AODF_path "3F00FF00 A0DF"39 #define AODF_path "3F00FF000000" 42 40 43 41 static const struct … … 83 81 free(pin_info); 84 82 free(pin_obj); 85 return SC_ERROR_OUT_OF_MEMORY;86 }83 return SC_ERROR_OUT_OF_MEMORY; 84 } 87 85 pin_info->auth_id.len = 1; 88 86 pin_info->auth_id.value[0] = (u8)pinlist[i].reference; … … 98 96 99 97 strncpy(pin_obj->label, pinlist[i].label, SC_PKCS15_MAX_LABEL_SIZE - 1); 100 pin_obj->flags = SC_PKCS15_CO_FLAG_PRIVATE; 101 98 pin_obj->flags = SC_PKCS15_CO_FLAG_PRIVATE; 102 99 sc_pkcs15emu_add_pin_obj(p15card, pin_obj, pin_info); 103 100 free(pin_obj); … … 120 117 char serial[30] = {0}; 121 118 u8 info[8]; 122 119 123 120 /* get the card serial number */ 124 121 if (sc_card_ctl(card, SC_CARDCTL_GET_SERIALNR, &serialnr) < 0) … … 129 126 sc_bin_to_hex(serialnr.value, serialnr.len , serial, sizeof(serial), 0); 130 127 set_string(&p15card->serial_number, serial); 131 132 128 /* get ruToken information */ 133 129 if (sc_card_ctl(card, SC_CARDCTL_RUTOKEN_GET_INFO, info) < 0) … … 136 132 return SC_ERROR_WRONG_CARD; 137 133 } 138 set_string(&p15card->label, RUT_LABEL);134 set_string(&p15card->label, card->name); 139 135 p15card->version = (info[1] >> 4)*10 + (info[1] & 0x0f); 140 136 sc_bin_to_hex(info + 3, 3 , serial, sizeof(serial), 0); 141 137 set_string(&p15card->manufacturer_id, serial); 142 143 138 return SC_SUCCESS; 144 139 } 145 140 146 141 static int sc_pkcs15_rutoken_init_func(sc_pkcs15_card_t *p15card) 147 142 { … … 153 148 int r; 154 149 unsigned int added_pin = 0; 155 150 156 151 if (!p15card || !p15card->card || !p15card->card->ctx 157 152 || !p15card->card->ops … … 159 154 ) 160 155 return SC_ERROR_INVALID_ARGUMENTS; 161 162 156 card = p15card->card; 163 157 ctx = card->ctx; 164 165 158 r = set_card_info(p15card); 166 159 if (r != SC_SUCCESS) 167 {160 { 168 161 sc_error(ctx, "Unable to set card info: %s\n", sc_strerror(r)); 169 162 r = SC_SUCCESS; 170 }163 } 171 164 172 165 for (i = 0; i < sizeof(arr_profile_df)/sizeof(arr_profile_df[0]); ++i) 173 {166 { 174 167 df = NULL; 175 168 sc_format_path(arr_profile_df[i].path, &path); … … 182 175 r = sc_pkcs15_add_df(p15card, arr_profile_df[i].type, &path, df); 183 176 if (df) 184 sc_file_free(df);177 sc_file_free(df); 185 178 186 179 if (r != SC_SUCCESS) break; … … 200 193 } 201 194 202 int sc_pkcs15emu_rutoken_init_ex(sc_pkcs15_card_t *p15card, 203 sc_pkcs15emu_opt_t *opts)195 int sc_pkcs15emu_rutoken_init_ex(sc_pkcs15_card_t *p15card, 196 sc_pkcs15emu_opt_t *opts) 204 197 { 205 198 struct sc_card *card = p15card->card; 206 199 207 200 SC_FUNC_CALLED(card->ctx, 1); 208 209 201 /* check if we have the correct card OS */ 210 if (strcmp(card->name, " rutoken card"))202 if (strcmp(card->name, "Rutoken card")) 211 203 return SC_ERROR_WRONG_CARD; 212 213 204 sc_debug(card->ctx, "%s found", card->name); 214 205 return sc_pkcs15_rutoken_init_func(p15card); 215 206 } 207
