- updated to work with latest library version

git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@90 c6295689-39f2-0310-b995-f0e70906c6a9
This commit is contained in:
jey 2001-12-22 20:52:57 +00:00
parent c344e28a92
commit 36965ca6eb
11 changed files with 40 additions and 35 deletions

View File

@ -299,7 +299,7 @@ int main(int argc, char *const argv[])
sc_lock(card);
if (!quiet)
fprintf(stderr, "Trying to find a PKCS#15 compatible card...\n");
r = sc_pkcs15_init(card, &p15card);
r = sc_pkcs15_bind(card, &p15card);
if (r) {
fprintf(stderr, "PKCS#15 initialization failed: %s\n", sc_strerror(r));
err = 1;
@ -315,7 +315,7 @@ int main(int argc, char *const argv[])
end:
if (p15card)
sc_pkcs15_destroy(p15card);
sc_pkcs15_unbind(p15card);
if (card) {
sc_unlock(card);
sc_disconnect_card(card);

View File

@ -74,8 +74,8 @@ diff -ruN openssh-3.0.2p1/configure.ac openssh-new/configure.ac
+ if test "$ac_cv_header_opensc_pkcs15_h" != yes; then
+ AC_MSG_ERROR(Can't find opensc-pkcs15.h)
+ fi
+ AC_CHECK_LIB(opensc, sc_pkcs15_init)
+ if test "$ac_cv_lib_opensc_sc_pkcs15_init" != yes; then
+ AC_CHECK_LIB(opensc, sc_pkcs15_bind)
+ if test "$ac_cv_lib_opensc_sc_pkcs15_bind" != yes; then
+ AC_MSG_ERROR(Can't find libopensc)
+ fi
+ AC_DEFINE(SMARTCARD)
@ -157,7 +157,7 @@ diff -ruN openssh-3.0.2p1/scard-opensc.c openssh-new/scard-opensc.c
+ r = sc_connect_card(ctx, sc_reader_id, &card);
+ if (r)
+ goto err;
+ r = sc_pkcs15_init(card, &p15card);
+ r = sc_pkcs15_bind(card, &p15card);
+ if (r)
+ goto err;
+ return 0;
@ -464,7 +464,7 @@ diff -ruN openssh-3.0.2p1/scard-opensc.c openssh-new/scard-opensc.c
+sc_close(void)
+{
+ if (p15card) {
+ sc_pkcs15_destroy(p15card);
+ sc_pkcs15_unbind(p15card);
+ p15card = NULL;
+ }
+ if (card) {

View File

@ -262,7 +262,8 @@ PAM_EXTERN int pam_sm_authenticate(pam_handle_t * pamh, int flags, int argc, con
printf("establish_context() failed: %s\n", sc_strerror(r));
return PAM_AUTH_ERR;
}
ctx->use_std_output = 1;
ctx->debug = 0;
for (i = 0; i < ctx->reader_count; i++) {
if (sc_detect_card(ctx, i) == 1) {
DBG(printf("Connecting to %s...\n", ctx->readers[i]));
@ -281,7 +282,7 @@ PAM_EXTERN int pam_sm_authenticate(pam_handle_t * pamh, int flags, int argc, con
locked = 1;
DBG(printf("PKCS#15 init...\n"));
r = sc_pkcs15_init(card, &p15card);
r = sc_pkcs15_bind(card, &p15card);
if (r != 0) {
printf("PKCS#15 initialization failed: %s\n", sc_strerror(r));
goto end;
@ -346,7 +347,7 @@ end:
if (cert)
X509_free(cert);
if (p15card)
sc_pkcs15_destroy(p15card);
sc_pkcs15_unbind(p15card);
if (card)
sc_disconnect_card(card);
if (ctx)

View File

@ -101,7 +101,7 @@ int slot_connect(int id)
return CKR_TOKEN_NOT_PRESENT;
}
r = sc_pkcs15_init(card, &slot[id].p15card);
r = sc_pkcs15_bind(card, &slot[id].p15card);
if (r) {
LOG("sc_pkcs15_init failed for slot %d (r=%d)\n", id, r);
/* PKCS#15 compatible SC probably not present */
@ -161,7 +161,7 @@ int slot_disconnect(int id)
slot[id].flags = 0;
if (slot[id].p15card != NULL) {
sc_disconnect_card(slot[id].p15card->card);
sc_pkcs15_destroy(slot[id].p15card);
sc_pkcs15_unbind(slot[id].p15card);
slot[id].p15card = NULL;
}

View File

@ -24,7 +24,7 @@ int test()
sc_lock(card);
#if 1
r = sc_pkcs15_init(card, &p15card);
r = sc_pkcs15_bind(card, &p15card);
if (r < 0) {
fprintf(stderr, "PKCS#15 init failed: %s\n", sc_strerror(r));
goto err;
@ -34,10 +34,9 @@ int test()
fprintf(stderr, "PIN code enum failed: %s\n", sc_strerror(r));
goto err;
}
memcpy(path.value, "\x51\x10", 2);
path.len = 2;
sc_format_path("5110", &path);
ctx->debug = 3;
r = sc_select_file(card, &file, &path, SC_SELECT_FILE_BY_PATH);
r = sc_select_file(card, &file, &path);
ctx->debug = 0;
if (r) {
fprintf(stderr, "sc_select_file failed: %s\n", sc_strerror(r));
@ -95,11 +94,10 @@ int test2()
struct sc_path path;
struct sc_file file;
memcpy(path.value, "\x3F\x00", 2);
path.len = 2;
sc_format_path("3F00", &path);
ctx->debug = 3;
r = sc_select_file(card, &file, &path, SC_SELECT_FILE_BY_PATH);
r = sc_select_file(card, &file, &path);
if (r) {
fprintf(stderr, "SELECT FILE failed: %s\n", sc_strerror(r));
return r;
@ -115,7 +113,7 @@ int test3()
struct sc_pkcs15_pin_info *pin;
struct sc_pkcs15_prkey_info *key;
r = sc_pkcs15_init(card, &p15card);
r = sc_pkcs15_bind(card, &p15card);
if (r) {
fprintf(stderr, "pkcs15 init failed: %s\n", sc_strerror(r));
return -1;

View File

@ -31,7 +31,7 @@ int main(int argc, char *argv[])
if (c == 0)
gettimeofday(&tv1, NULL);
sc_lock(card);
r = sc_get_random(card, buf, 14);
r = sc_get_challenge(card, buf, 14);
sc_unlock(card);
if (r == 0) {
int i, jaljella = 39;

View File

@ -41,7 +41,7 @@ int main(int argc, char *argv[])
printf("Looking for a PKCS#15 compatible Smart Card... ");
fflush(stdout);
sc_lock(card);
i = sc_pkcs15_init(card, &p15card);
i = sc_pkcs15_bind(card, &p15card);
sc_unlock(card);
if (i) {
fprintf(stderr, "failed: %s\n", sc_strerror(i));

View File

@ -83,7 +83,7 @@ int main(int argc, char *argv[])
printf("Looking for a PKCS#15 compatible Smart Card... ");
fflush(stdout);
sc_lock(card);
i = sc_pkcs15_init(card, &p15card);
i = sc_pkcs15_bind(card, &p15card);
sc_unlock(card);
if (i) {
fprintf(stderr, "failed: %s\n", sc_strerror(i));

View File

@ -33,7 +33,7 @@ int main(int argc, char *argv[])
}
if (c == 0)
gettimeofday(&tv1, NULL);
i = sc_get_random(card, buf, 8);
i = sc_get_challenge(card, buf, 8);
if (i != 0) {
fprintf(stderr, "sc_get_random() failed: %s\n", sc_strerror(i));
sc_test_cleanup();

View File

@ -99,13 +99,13 @@ void print_usage_and_die()
exit(2);
}
const char * get_pin(struct sc_pkcs15_pin_info *pinfo)
char * get_pin(struct sc_pkcs15_pin_info *pinfo)
{
char buf[80];
char *pincode;
if (opt_pincode != NULL)
return opt_pincode;
return strdup(opt_pincode);
sprintf(buf, "Enter PIN [%s]: ", pinfo->com_attr.label);
while (1) {
pincode = getpass(buf);
@ -221,10 +221,10 @@ int main(int argc, char * const argv[])
struct sc_pkcs15_prkey_info *key;
struct sc_pkcs15_pin_info *pin;
struct sc_pkcs15_id id;
const char *pincode;
char *pincode;
while (1) {
c = getopt_long(argc, argv, "sdk:r:i:o:qp:d", options, &long_optind);
c = getopt_long(argc, argv, "sck:r:i:o:qp:d", options, &long_optind);
if (c == -1)
break;
if (c == '?')
@ -295,7 +295,7 @@ int main(int argc, char * const argv[])
sc_lock(card);
if (!quiet)
fprintf(stderr, "Trying to find a PKCS#15 compatible card...\n");
r = sc_pkcs15_init(card, &p15card);
r = sc_pkcs15_bind(card, &p15card);
if (r) {
fprintf(stderr, "PKCS#15 initialization failed: %s\n", sc_strerror(r));
err = 1;
@ -341,6 +341,7 @@ int main(int argc, char * const argv[])
err = 5;
goto end;
}
free(pincode);
if (!quiet)
fprintf(stderr, "PIN code correct.\n");
if (do_decipher) {
@ -355,7 +356,7 @@ int main(int argc, char * const argv[])
}
end:
if (p15card)
sc_pkcs15_destroy(p15card);
sc_pkcs15_unbind(p15card);
if (card) {
sc_unlock(card);
sc_disconnect_card(card);

View File

@ -359,7 +359,7 @@ int enum_dir(struct sc_path path, int depth)
u8 buf[2048];
const char *tmps;
r = sc_select_file(card, &file, &path, SC_SELECT_FILE_BY_PATH);
r = sc_select_file(card, &file, &path);
if (r) {
fprintf(stderr, "SELECT FILE failed: %s\n", sc_strerror(r));
return 1;
@ -440,8 +440,7 @@ int list_files()
struct sc_path path;
int r;
memcpy(path.value, "\x3F\x00", 2);
path.len = 2;
sc_format_path("3F00", &path);
r = enum_dir(path, 0);
return r;
}
@ -500,6 +499,7 @@ int learn_card()
return 1;
}
printf("Caching %d certificate(s)...\n", r);
p15card->use_cache = 0;
for (i = 0; i < p15card->cert_count; i++) {
struct sc_pkcs15_cert_info *cinfo = &p15card->cert_info[i];
struct sc_pkcs15_cert *cert;
@ -556,6 +556,11 @@ int send_apdu()
apdu.data = sbuf;
apdu.datalen = apdu.lc;
len -= apdu.lc;
if (len < 0) {
fprintf(stderr, "APDU too short (need %d bytes).\n",
-len);
return 2;
}
if (len) {
apdu.le = *p++;
len--;
@ -573,7 +578,7 @@ int send_apdu()
} else
apdu.cse = SC_APDU_CASE_1;
ctx->debug = 4;
ctx->debug = 5;
r = sc_transmit_apdu(card, &apdu);
ctx->debug = opt_debug;
if (r) {
@ -717,7 +722,7 @@ int main(int argc, char * const argv[])
goto end;
if (!quiet)
fprintf(stderr, "Trying to find a PKCS#15 compatible card...\n");
r = sc_pkcs15_init(card, &p15card);
r = sc_pkcs15_bind(card, &p15card);
if (r) {
fprintf(stderr, "PKCS#15 initialization failed: %s\n", sc_strerror(r));
err = 1;
@ -757,7 +762,7 @@ int main(int argc, char * const argv[])
}
end:
if (p15card)
sc_pkcs15_destroy(p15card);
sc_pkcs15_unbind(p15card);
if (card) {
sc_unlock(card);
sc_disconnect_card(card);