|
Lines 89-94
sc_init(void)
Link Here
|
| 89 |
r = sc_establish_context(&ctx, "openssh"); |
89 |
r = sc_establish_context(&ctx, "openssh"); |
| 90 |
if (r) |
90 |
if (r) |
| 91 |
goto err; |
91 |
goto err; |
|
|
92 |
if (sc_reader_id >= ctx->reader_count) { |
| 93 |
r=SC_ERROR_NO_READERS_FOUND; |
| 94 |
error("Illegal reader number. Only %d reader(s) configured.\n", |
| 95 |
ctx->reader_count); |
| 96 |
goto err; |
| 97 |
} |
| 92 |
r = sc_connect_card(ctx->reader[sc_reader_id], 0, &card); |
98 |
r = sc_connect_card(ctx->reader[sc_reader_id], 0, &card); |
| 93 |
if (r) |
99 |
if (r) |
| 94 |
goto err; |
100 |
goto err; |
|
Lines 143-153
sc_prkey_op_init(RSA *rsa, struct sc_pkc
Link Here
|
| 143 |
*key_obj_out = key_obj; |
149 |
*key_obj_out = key_obj; |
| 144 |
return 0; |
150 |
return 0; |
| 145 |
} else if (r) { |
151 |
} else if (r) { |
|
|
152 |
/* some other OpenSC internal error */ |
| 146 |
error("Unable to find PIN object from SmartCard: %s", |
153 |
error("Unable to find PIN object from SmartCard: %s", |
| 147 |
sc_strerror(r)); |
154 |
sc_strerror(r)); |
| 148 |
goto err; |
155 |
goto err; |
| 149 |
} |
156 |
} |
| 150 |
pin = pin_obj->data; |
157 |
pin = pin_obj->data; |
|
|
158 |
|
| 159 |
if ((pin->auth_id.len > 0) && (! sc_pin)) { |
| 160 |
/* we need a pin, we don't have one. let's ask. */ |
| 161 |
char *passphrase; |
| 162 |
passphrase = read_passphrase("Enter passphrase for key:", 0); |
| 163 |
if (! passphrase) |
| 164 |
goto err; |
| 165 |
if (strcmp(passphrase, "") == 0) |
| 166 |
goto err; |
| 167 |
r = sc_lock(card); |
| 168 |
if (r) { |
| 169 |
error("Unable to lock smartcard: %s", |
| 170 |
sc_strerror(r)); |
| 171 |
memset(passphrase, 0, strlen(passphrase)); |
| 172 |
xfree(passphrase); |
| 173 |
goto err; |
| 174 |
} |
| 175 |
r = sc_pkcs15_verify_pin(p15card, pin, |
| 176 |
passphrase, strlen(passphrase)); |
| 177 |
memset(passphrase, 0, strlen(passphrase)); |
| 178 |
xfree(passphrase); |
| 179 |
if (r) { |
| 180 |
sc_unlock(card); |
| 181 |
error("PIN code verification failed: %s", |
| 182 |
sc_strerror(r)); |
| 183 |
goto err; |
| 184 |
} |
| 185 |
*key_obj_out = key_obj; |
| 186 |
return 0; |
| 187 |
} |
| 151 |
r = sc_lock(card); |
188 |
r = sc_lock(card); |
| 152 |
if (r) { |
189 |
if (r) { |
| 153 |
error("Unable to lock smartcard: %s", sc_strerror(r)); |
190 |
error("Unable to lock smartcard: %s", sc_strerror(r)); |