diff options
author | Jim Rees <rees@cvs.openbsd.org> | 2001-07-17 17:10:45 +0000 |
---|---|---|
committer | Jim Rees <rees@cvs.openbsd.org> | 2001-07-17 17:10:45 +0000 |
commit | 968868ac8f088d0a6c0a1bf445f80b0f9c9b6ecc (patch) | |
tree | 185a339e7189bb09d8a9b002fb25df2994046cf5 | |
parent | 0215d6152a7614f090df5ce6c8e6c852e5205888 (diff) |
more better error checking
-rw-r--r-- | usr.bin/sectok/cmds.c | 31 | ||||
-rw-r--r-- | usr.bin/sectok/cyberflex.c | 58 |
2 files changed, 47 insertions, 42 deletions
diff --git a/usr.bin/sectok/cmds.c b/usr.bin/sectok/cmds.c index 4ff39949da5..b9ffe00f421 100644 --- a/usr.bin/sectok/cmds.c +++ b/usr.bin/sectok/cmds.c @@ -1,4 +1,4 @@ -/* $Id: cmds.c,v 1.6 2001/07/17 15:16:46 rees Exp $ */ +/* $Id: cmds.c,v 1.7 2001/07/17 17:10:44 rees Exp $ */ /* * Smartcard commander. @@ -149,7 +149,7 @@ int reset(int ac, char *av[]) vflag = 1; break; case 'f': - rflags |= SCRFORCE; + rflags |= STRFORCE; break; } } @@ -164,11 +164,12 @@ int reset(int ac, char *av[]) aut0_vfyd = 0; - n = scxreset(fd, rflags, atr, &sw); + n = sectok_reset(fd, rflags, atr, &sw); if (vflag) parse_atr(fd, SCRV, atr, n, ¶m); - if (sw != SCEOK) { - printf("%s\n", scerrtab[sw]); + if (!sectok_swOK(sw)) { + printf("sectok_reset: %s\n", sectok_get_sw(sw)); + dclose(0, NULL); return -1; } @@ -224,8 +225,8 @@ int apdu(int ac, char *av[]) } #endif - if (fd < 0) - reset(0, NULL); + if (fd < 0 && reset(0, NULL) < 0) + return -1; n = scrw(fd, xcl, ins, p1, p2, p3, buf, sizeof obuf, obuf, &r1, &r2); @@ -249,8 +250,8 @@ int selfid(int ac, char *av[]) return -1; } - if (fd < 0) - reset(0, NULL); + if (fd < 0 && reset(0, NULL) < 0) + return -1; sectok_parse_fname(av[1], fid); if (sectok_selectfile(fd, cla, fid, &sw) < 0) { @@ -266,8 +267,8 @@ int isearch(int ac, char *av[]) int i, r1, r2; unsigned char buf[256]; - if (fd < 0) - reset(0, NULL); + if (fd < 0 && reset(0, NULL) < 0) + return -1; /* find instructions */ for (i = 0; i < 0xff; i += 2) @@ -298,8 +299,8 @@ int dread(int ac, char *av[]) sscanf(av[1], "%d", &fsize); - if (fd < 0) - reset(0, NULL); + if (fd < 0 && reset(0, NULL) < 0) + return -1; for (p3 = 0; fsize && p3 < 100000; p3 += n) { n = (fsize < CARDIOSIZE) ? fsize : CARDIOSIZE; @@ -329,8 +330,8 @@ int dwrite(int ac, char *av[]) return -1; } - if (fd < 0) - reset(0, NULL); + if (fd < 0 && reset(0, NULL) < 0) + return -1; f = fopen(av[1], "r"); if (!f) { diff --git a/usr.bin/sectok/cyberflex.c b/usr.bin/sectok/cyberflex.c index 6df6a2488b5..0827a7c7cb3 100644 --- a/usr.bin/sectok/cyberflex.c +++ b/usr.bin/sectok/cyberflex.c @@ -1,4 +1,4 @@ -/* $Id: cyberflex.c,v 1.6 2001/07/17 15:16:46 rees Exp $ */ +/* $Id: cyberflex.c,v 1.7 2001/07/17 17:10:44 rees Exp $ */ /* copyright 1999, 2000 @@ -60,6 +60,7 @@ such damages. static unsigned char key_fid[] = {0x00, 0x11}; static unsigned char DFLTATR[] = {0x81, 0x10, 0x06, 0x01}; static unsigned char DFLTAUT0[] = {0xad, 0x9f, 0x61, 0xfe, 0xfa, 0x20, 0xce, 0x63}; +static unsigned char AUT0[20]; int aut0_vfyd; @@ -128,10 +129,15 @@ get_AUT0(int ac, char *av[], char *prompt, unsigned char *digest) int jlogin(int ac, char *av[]) { int i, vflag = 0, sw; - unsigned char AUT0[20]; - if (fd < 0) - reset(0, NULL); + if (fd < 0 && reset(0, NULL) < 0) + return -1; + + cla = cyberflex_inq_class(fd); + if (cla < 0) { + printf("can't determine Cyberflex application class\n"); + return -1; + } optind = optreset = 1; @@ -146,8 +152,6 @@ int jlogin(int ac, char *av[]) if (get_AUT0(ac, av, "Enter AUT0 passphrase: ", AUT0) < 0) return -1; - cla = cyberflex_inq_class(fd); - if (vflag) { printf("Class %02x\n", cla); for (i = 0; i < 8; i++) @@ -188,8 +192,8 @@ int jdefault(int ac, char *av[]) } } - if (fd < 0) - reset(0, NULL); + if (fd < 0 && reset(0, NULL) < 0) + return -1; if (!aut0_vfyd) jaut(0, NULL); @@ -207,8 +211,8 @@ int jatr(int ac, char *av[]) unsigned char buf[64]; int n = 0, sw; - if (fd < 0) - reset(0, NULL); + if (fd < 0 && reset(0, NULL) < 0) + return -1; buf[n++] = 0x90; buf[n++] = 0x94; /* TA1 */ @@ -237,8 +241,8 @@ int jdata(int ac, char *av[]) unsigned char buf[32]; int i, sw; - if (fd < 0) - reset(0, NULL); + if (fd < 0 && reset(0, NULL) < 0) + return -1; sectok_apdu(fd, cla, 0xca, 0, 1, 0, NULL, 0x16, buf, &sw); if (sectok_swOK(sw)) { @@ -268,8 +272,8 @@ int ls(int ac, char *av[]) char ftype[32], fname[6]; unsigned char buf[JDIRSIZE]; - if (fd < 0) - reset(0, NULL); + if (fd < 0 && reset(0, NULL) < 0) + return -1; for (p2 = 0; ; p2++) { if (sectok_apdu(fd, cla, 0xa8, 0, p2, 0, NULL, JDIRSIZE, buf, &sw) < 0) @@ -311,8 +315,8 @@ int jcreate(int ac, char *av[]) sectok_parse_fname(av[1], fid); sscanf(av[2], "%d", &fsize); - if (fd < 0) - reset(0, NULL); + if (fd < 0 && reset(0, NULL) < 0) + return -1; if (!aut0_vfyd) jaut(0, NULL); @@ -336,8 +340,8 @@ int jdelete(int ac, char *av[]) sectok_parse_fname(av[1], fid); - if (fd < 0) - reset(0, NULL); + if (fd < 0 && reset(0, NULL) < 0) + return -1; if (!aut0_vfyd) jaut(0, NULL); @@ -423,8 +427,8 @@ int jload(int ac, char *av[]) if (analyze_load_options(ac, av) < 0) return -1; - if (fd < 0) - reset(0, NULL); + if (fd < 0 && reset(0, NULL) < 0) + return -1; if (!aut0_vfyd) jaut(0, NULL); @@ -588,8 +592,8 @@ int junload(int ac, char *av[]) if (analyze_load_options(ac, av) < 0) return -1; - if (fd < 0) - reset(0, NULL); + if (fd < 0 && reset(0, NULL) < 0) + return -1; if (!aut0_vfyd) jaut(0, NULL); @@ -638,8 +642,8 @@ int jselect(int ac, char *av[]) if (analyze_load_options(ac, av) < 0) return -1; - if (fd < 0) - reset(0, NULL); + if (fd < 0 && reset(0, NULL) < 0) + return -1; printf ("select applet\n"); printf ("AID "); @@ -672,8 +676,8 @@ int jdeselect(int ac, char *av[]) { int sw; - if (fd < 0) - reset(0, NULL); + if (fd < 0 && reset(0, NULL) < 0) + return -1; sectok_apdu(fd, cla, 0xa4, 0x04, 0, 0, NULL, 0, NULL, &sw); if (!sectok_swOK(sw)) { @@ -732,7 +736,7 @@ int cyberflex_load_key (int fd, unsigned char *buf) /* Now let's do it. :) */ /* add the AUT0 */ - cyberflex_fill_key_block (data, 0, 1, DFLTAUT0); + cyberflex_fill_key_block (data, 0, 1, AUT0); /* add the applet sign key */ cyberflex_fill_key_block (data+KEY_BLOCK_SIZE, 5, 0, app_key); |