version 1.6, 2001/07/17 15:16:46 |
version 1.7, 2001/07/17 17:10:44 |
|
|
static unsigned char key_fid[] = {0x00, 0x11}; |
static unsigned char key_fid[] = {0x00, 0x11}; |
static unsigned char DFLTATR[] = {0x81, 0x10, 0x06, 0x01}; |
static unsigned char DFLTATR[] = {0x81, 0x10, 0x06, 0x01}; |
static unsigned char DFLTAUT0[] = {0xad, 0x9f, 0x61, 0xfe, 0xfa, 0x20, 0xce, 0x63}; |
static unsigned char DFLTAUT0[] = {0xad, 0x9f, 0x61, 0xfe, 0xfa, 0x20, 0xce, 0x63}; |
|
static unsigned char AUT0[20]; |
|
|
int aut0_vfyd; |
int aut0_vfyd; |
|
|
|
|
int jlogin(int ac, char *av[]) |
int jlogin(int ac, char *av[]) |
{ |
{ |
int i, vflag = 0, sw; |
int i, vflag = 0, sw; |
unsigned char AUT0[20]; |
|
|
|
if (fd < 0) |
if (fd < 0 && reset(0, NULL) < 0) |
reset(0, NULL); |
return -1; |
|
|
|
cla = cyberflex_inq_class(fd); |
|
if (cla < 0) { |
|
printf("can't determine Cyberflex application class\n"); |
|
return -1; |
|
} |
|
|
optind = optreset = 1; |
optind = optreset = 1; |
|
|
while ((i = getopt(ac, av, "dvx:")) != -1) { |
while ((i = getopt(ac, av, "dvx:")) != -1) { |
|
|
if (get_AUT0(ac, av, "Enter AUT0 passphrase: ", AUT0) < 0) |
if (get_AUT0(ac, av, "Enter AUT0 passphrase: ", AUT0) < 0) |
return -1; |
return -1; |
|
|
cla = cyberflex_inq_class(fd); |
|
|
|
if (vflag) { |
if (vflag) { |
printf("Class %02x\n", cla); |
printf("Class %02x\n", cla); |
for (i = 0; i < 8; i++) |
for (i = 0; i < 8; i++) |
|
|
} |
} |
} |
} |
|
|
if (fd < 0) |
if (fd < 0 && reset(0, NULL) < 0) |
reset(0, NULL); |
return -1; |
if (!aut0_vfyd) |
if (!aut0_vfyd) |
jaut(0, NULL); |
jaut(0, NULL); |
|
|
|
|
unsigned char buf[64]; |
unsigned char buf[64]; |
int n = 0, sw; |
int n = 0, sw; |
|
|
if (fd < 0) |
if (fd < 0 && reset(0, NULL) < 0) |
reset(0, NULL); |
return -1; |
|
|
buf[n++] = 0x90; |
buf[n++] = 0x90; |
buf[n++] = 0x94; /* TA1 */ |
buf[n++] = 0x94; /* TA1 */ |
|
|
unsigned char buf[32]; |
unsigned char buf[32]; |
int i, sw; |
int i, sw; |
|
|
if (fd < 0) |
if (fd < 0 && reset(0, NULL) < 0) |
reset(0, NULL); |
return -1; |
|
|
sectok_apdu(fd, cla, 0xca, 0, 1, 0, NULL, 0x16, buf, &sw); |
sectok_apdu(fd, cla, 0xca, 0, 1, 0, NULL, 0x16, buf, &sw); |
if (sectok_swOK(sw)) { |
if (sectok_swOK(sw)) { |
|
|
char ftype[32], fname[6]; |
char ftype[32], fname[6]; |
unsigned char buf[JDIRSIZE]; |
unsigned char buf[JDIRSIZE]; |
|
|
if (fd < 0) |
if (fd < 0 && reset(0, NULL) < 0) |
reset(0, NULL); |
return -1; |
|
|
for (p2 = 0; ; p2++) { |
for (p2 = 0; ; p2++) { |
if (sectok_apdu(fd, cla, 0xa8, 0, p2, 0, NULL, JDIRSIZE, buf, &sw) < 0) |
if (sectok_apdu(fd, cla, 0xa8, 0, p2, 0, NULL, JDIRSIZE, buf, &sw) < 0) |
|
|
sectok_parse_fname(av[1], fid); |
sectok_parse_fname(av[1], fid); |
sscanf(av[2], "%d", &fsize); |
sscanf(av[2], "%d", &fsize); |
|
|
if (fd < 0) |
if (fd < 0 && reset(0, NULL) < 0) |
reset(0, NULL); |
return -1; |
if (!aut0_vfyd) |
if (!aut0_vfyd) |
jaut(0, NULL); |
jaut(0, NULL); |
|
|
|
|
|
|
sectok_parse_fname(av[1], fid); |
sectok_parse_fname(av[1], fid); |
|
|
if (fd < 0) |
if (fd < 0 && reset(0, NULL) < 0) |
reset(0, NULL); |
return -1; |
if (!aut0_vfyd) |
if (!aut0_vfyd) |
jaut(0, NULL); |
jaut(0, NULL); |
|
|
|
|
if (analyze_load_options(ac, av) < 0) |
if (analyze_load_options(ac, av) < 0) |
return -1; |
return -1; |
|
|
if (fd < 0) |
if (fd < 0 && reset(0, NULL) < 0) |
reset(0, NULL); |
return -1; |
if (!aut0_vfyd) |
if (!aut0_vfyd) |
jaut(0, NULL); |
jaut(0, NULL); |
|
|
|
|
if (analyze_load_options(ac, av) < 0) |
if (analyze_load_options(ac, av) < 0) |
return -1; |
return -1; |
|
|
if (fd < 0) |
if (fd < 0 && reset(0, NULL) < 0) |
reset(0, NULL); |
return -1; |
if (!aut0_vfyd) |
if (!aut0_vfyd) |
jaut(0, NULL); |
jaut(0, NULL); |
|
|
|
|
if (analyze_load_options(ac, av) < 0) |
if (analyze_load_options(ac, av) < 0) |
return -1; |
return -1; |
|
|
if (fd < 0) |
if (fd < 0 && reset(0, NULL) < 0) |
reset(0, NULL); |
return -1; |
|
|
printf ("select applet\n"); |
printf ("select applet\n"); |
printf ("AID "); |
printf ("AID "); |
|
|
{ |
{ |
int sw; |
int sw; |
|
|
if (fd < 0) |
if (fd < 0 && reset(0, NULL) < 0) |
reset(0, NULL); |
return -1; |
|
|
sectok_apdu(fd, cla, 0xa4, 0x04, 0, 0, NULL, 0, NULL, &sw); |
sectok_apdu(fd, cla, 0xa4, 0x04, 0, 0, NULL, 0, NULL, &sw); |
if (!sectok_swOK(sw)) { |
if (!sectok_swOK(sw)) { |
|
|
/* Now let's do it. :) */ |
/* Now let's do it. :) */ |
|
|
/* add the AUT0 */ |
/* add the AUT0 */ |
cyberflex_fill_key_block (data, 0, 1, DFLTAUT0); |
cyberflex_fill_key_block (data, 0, 1, AUT0); |
|
|
/* add the applet sign key */ |
/* add the applet sign key */ |
cyberflex_fill_key_block (data+KEY_BLOCK_SIZE, 5, 0, app_key); |
cyberflex_fill_key_block (data+KEY_BLOCK_SIZE, 5, 0, app_key); |