summaryrefslogtreecommitdiff
path: root/scard.c
diff options
context:
space:
mode:
authorBen Lindstrom <mouring@eviladmin.org>2002-03-27 17:33:17 +0000
committerBen Lindstrom <mouring@eviladmin.org>2002-03-27 17:33:17 +0000
commit43a5e2f70e3fc38de55b45f580e92b7be84cfa34 (patch)
treebe9d78d5ea3a7e325b01a93383eaf3063076d772 /scard.c
parent38a69e6b53ad05b39081f8531104be6d21970d79 (diff)
- rees@cvs.openbsd.org 2002/03/26 18:46:59
[scard.c] try_AUT0 in read_pubkey too, for those paranoid few who want to acl 'sh'
Diffstat (limited to 'scard.c')
-rw-r--r--scard.c61
1 files changed, 34 insertions, 27 deletions
diff --git a/scard.c b/scard.c
index 779106f85..de53f9d01 100644
--- a/scard.c
+++ b/scard.c
@@ -24,7 +24,7 @@
24 24
25#include "includes.h" 25#include "includes.h"
26#ifdef SMARTCARD 26#ifdef SMARTCARD
27RCSID("$OpenBSD: scard.c,v 1.24 2002/03/25 17:34:27 markus Exp $"); 27RCSID("$OpenBSD: scard.c,v 1.25 2002/03/26 18:46:59 rees Exp $");
28 28
29#include <openssl/evp.h> 29#include <openssl/evp.h>
30#include <sectok.h> 30#include <sectok.h>
@@ -65,6 +65,7 @@ static int cla = 0x00; /* class */
65 65
66static void sc_mk_digest(const char *pin, u_char *digest); 66static void sc_mk_digest(const char *pin, u_char *digest);
67static int get_AUT0(u_char *aut0); 67static int get_AUT0(u_char *aut0);
68static int try_AUT0(void);
68 69
69/* interface to libsectok */ 70/* interface to libsectok */
70 71
@@ -164,6 +165,12 @@ sc_read_pubkey(Key * k)
164 n = xmalloc(len); 165 n = xmalloc(len);
165 /* get n */ 166 /* get n */
166 sectok_apdu(sc_fd, CLA_SSH, INS_GET_PUBKEY, 0, 0, 0, NULL, len, n, &sw); 167 sectok_apdu(sc_fd, CLA_SSH, INS_GET_PUBKEY, 0, 0, 0, NULL, len, n, &sw);
168
169 if (sw == 0x6982) {
170 if (try_AUT0() < 0)
171 goto err;
172 sectok_apdu(sc_fd, CLA_SSH, INS_GET_PUBKEY, 0, 0, 0, NULL, len, n, &sw);
173 }
167 if (!sectok_swOK(sw)) { 174 if (!sectok_swOK(sw)) {
168 error("could not obtain public key: %s", sectok_get_sw(sw)); 175 error("could not obtain public key: %s", sectok_get_sw(sw));
169 goto err; 176 goto err;
@@ -194,32 +201,6 @@ err:
194 return status; 201 return status;
195} 202}
196 203
197static int
198try_AUT0(void)
199{
200 u_char aut0[EVP_MAX_MD_SIZE];
201
202 /* permission denied; try PIN if provided */
203 if (sc_pin && strlen(sc_pin) > 0) {
204 sc_mk_digest(sc_pin, aut0);
205 if (cyberflex_verify_AUT0(sc_fd, cla, aut0, 8) < 0) {
206 error("smartcard passphrase incorrect");
207 return (-1);
208 }
209 } else {
210 /* try default AUT0 key */
211 if (cyberflex_verify_AUT0(sc_fd, cla, DEFAUT0, 8) < 0) {
212 /* default AUT0 key failed; prompt for passphrase */
213 if (get_AUT0(aut0) < 0 ||
214 cyberflex_verify_AUT0(sc_fd, cla, aut0, 8) < 0) {
215 error("smartcard passphrase incorrect");
216 return (-1);
217 }
218 }
219 }
220 return (0);
221}
222
223/* private key operations */ 204/* private key operations */
224 205
225static int 206static int
@@ -463,6 +444,32 @@ get_AUT0(u_char *aut0)
463 return 0; 444 return 0;
464} 445}
465 446
447static int
448try_AUT0(void)
449{
450 u_char aut0[EVP_MAX_MD_SIZE];
451
452 /* permission denied; try PIN if provided */
453 if (sc_pin && strlen(sc_pin) > 0) {
454 sc_mk_digest(sc_pin, aut0);
455 if (cyberflex_verify_AUT0(sc_fd, cla, aut0, 8) < 0) {
456 error("smartcard passphrase incorrect");
457 return (-1);
458 }
459 } else {
460 /* try default AUT0 key */
461 if (cyberflex_verify_AUT0(sc_fd, cla, DEFAUT0, 8) < 0) {
462 /* default AUT0 key failed; prompt for passphrase */
463 if (get_AUT0(aut0) < 0 ||
464 cyberflex_verify_AUT0(sc_fd, cla, aut0, 8) < 0) {
465 error("smartcard passphrase incorrect");
466 return (-1);
467 }
468 }
469 }
470 return (0);
471}
472
466int 473int
467sc_put_key(Key *prv, const char *id) 474sc_put_key(Key *prv, const char *id)
468{ 475{