Upgrade to current OpenSC API
Compiles, so far untested git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@229 c6295689-39f2-0310-b995-f0e70906c6a9
This commit is contained in:
parent
9c594003ee
commit
b098c097a1
|
@ -287,13 +287,13 @@ int main(int argc, char *const argv[])
|
|||
err = 1;
|
||||
goto end;
|
||||
}
|
||||
if (sc_detect_card(ctx, opt_reader) != 1) {
|
||||
if (sc_detect_card_presence(ctx->reader[opt_reader], 0) != 1) {
|
||||
fprintf(stderr, "Card not present.\n");
|
||||
return 3;
|
||||
}
|
||||
if (!quiet)
|
||||
fprintf(stderr, "Connecting to card in reader %s...\n", ctx->readers[opt_reader]);
|
||||
r = sc_connect_card(ctx, opt_reader, &card);
|
||||
fprintf(stderr, "Connecting to card in reader %s...\n", ctx->reader[opt_reader]->name);
|
||||
r = sc_connect_card(ctx->reader[opt_reader], 0, &card);
|
||||
if (r) {
|
||||
fprintf(stderr, "Failed to connect to card: %s\n", sc_strerror(r));
|
||||
err = 1;
|
||||
|
@ -322,7 +322,7 @@ end:
|
|||
sc_pkcs15_unbind(p15card);
|
||||
if (card) {
|
||||
sc_unlock(card);
|
||||
sc_disconnect_card(card);
|
||||
sc_disconnect_card(card, 0);
|
||||
}
|
||||
if (ctx)
|
||||
sc_destroy_context(ctx);
|
||||
|
|
|
@ -303,9 +303,9 @@ PAM_EXTERN int pam_sm_authenticate(pam_handle_t * pamh, int flags, int argc, con
|
|||
ctx->debug_file = stdout;
|
||||
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]));
|
||||
if (sc_connect_card(ctx, i, &card) != 0) {
|
||||
if (sc_detect_card_presence(ctx->reader[i], 0) == 1) {
|
||||
DBG(printf("Connecting to %s...\n", ctx->reader[i]->name));
|
||||
if (sc_connect_card(ctx->reader[i], 0, &card) != 0) {
|
||||
printf("Connecting to card failed: %s\n", sc_strerror(r));
|
||||
goto end;
|
||||
}
|
||||
|
@ -388,7 +388,7 @@ end:
|
|||
if (p15card)
|
||||
sc_pkcs15_unbind(p15card);
|
||||
if (card)
|
||||
sc_disconnect_card(card);
|
||||
sc_disconnect_card(card, 0);
|
||||
if (ctx)
|
||||
sc_destroy_context(ctx);
|
||||
return err;
|
||||
|
|
|
@ -64,14 +64,14 @@ static CK_RV pkcs15_bind(struct sc_pkcs11_card *p11card)
|
|||
int rc = sc_pkcs15_bind(p11card->card,
|
||||
(struct sc_pkcs15_card**) &p11card->fw_data);
|
||||
debug(context, "Binding to PKCS#15, rc=%d\n", rc);
|
||||
return sc_to_cryptoki_error(rc, p11card->card->reader);
|
||||
return sc_to_cryptoki_error(rc, p11card->reader);
|
||||
}
|
||||
|
||||
static CK_RV pkcs15_unbind(struct sc_pkcs11_card *p11card)
|
||||
{
|
||||
struct sc_pkcs15_card *card = (struct sc_pkcs15_card*) p11card->fw_data;
|
||||
int rc = sc_pkcs15_unbind(card);
|
||||
return sc_to_cryptoki_error(rc, card->card->reader);
|
||||
return sc_to_cryptoki_error(rc, p11card->reader);
|
||||
}
|
||||
|
||||
static void pkcs15_init_token_info(struct sc_pkcs15_card *card, CK_TOKEN_INFO_PTR pToken)
|
||||
|
@ -152,7 +152,7 @@ static CK_RV pkcs15_create_tokens(struct sc_pkcs11_card *p11card)
|
|||
{
|
||||
struct sc_pkcs15_card *card = (struct sc_pkcs15_card*) p11card->fw_data;
|
||||
struct sc_pkcs11_slot *slot;
|
||||
int i, j, rv, reader = card->card->reader;
|
||||
int i, j, rv, reader = p11card->reader;
|
||||
|
||||
debug(context, "Enumerating PINS\n");
|
||||
rv = sc_pkcs15_enum_pins(card);
|
||||
|
@ -323,7 +323,7 @@ static CK_RV pkcs15_login(struct sc_pkcs11_card *p11card,
|
|||
struct sc_pkcs15_pin_info *pin = (struct sc_pkcs15_pin_info*) fw_token;
|
||||
|
||||
rc = sc_pkcs15_verify_pin(card, pin, pPin, ulPinLen);
|
||||
return sc_to_cryptoki_error(rc, card->card->reader);
|
||||
return sc_to_cryptoki_error(rc, p11card->reader);
|
||||
}
|
||||
|
||||
static CK_RV pkcs15_logout(struct sc_pkcs11_card *p11card, void *fw_token)
|
||||
|
|
|
@ -55,14 +55,14 @@ CK_RV card_detect(int reader)
|
|||
/* Already known to be present? */
|
||||
if (card_table[reader].card == NULL) {
|
||||
/* Check if someone inserted a card */
|
||||
if (sc_detect_card(context, reader) != 1) {
|
||||
if (sc_detect_card_presence(context->reader[reader], 0) != 1) {
|
||||
debug(context, "%d: Card absent\n", reader);
|
||||
return CKR_TOKEN_NOT_PRESENT;
|
||||
}
|
||||
|
||||
/* Detect the card */
|
||||
debug(context, "%d: Connecting to SmartCard\n", reader);
|
||||
rc = sc_connect_card(context, reader, &card_table[reader].card);
|
||||
rc = sc_connect_card(context->reader[reader], 0, &card_table[reader].card);
|
||||
if (rc != SC_SUCCESS)
|
||||
return sc_to_cryptoki_error(rc, reader);
|
||||
}
|
||||
|
@ -112,7 +112,7 @@ CK_RV card_removed(int reader)
|
|||
card->framework = NULL;
|
||||
card->fw_data = NULL;
|
||||
|
||||
sc_disconnect_card(card->card);
|
||||
sc_disconnect_card(card->card, 0);
|
||||
card->card = NULL;
|
||||
|
||||
return CKR_OK;
|
||||
|
|
|
@ -14,7 +14,7 @@ sc_close(struct sc_priv_data *priv)
|
|||
priv->p15card = NULL;
|
||||
}
|
||||
if (priv->card) {
|
||||
sc_disconnect_card(priv->card);
|
||||
sc_disconnect_card(priv->card, 0);
|
||||
priv->card = NULL;
|
||||
}
|
||||
if (priv->ctx) {
|
||||
|
@ -31,7 +31,7 @@ sc_init(struct sc_priv_data *priv)
|
|||
r = sc_establish_context(&priv->ctx);
|
||||
if (r)
|
||||
goto err;
|
||||
r = sc_connect_card(priv->ctx, priv->reader_id, &priv->card);
|
||||
r = sc_connect_card(priv->ctx->reader[priv->reader_id], 0, &priv->card);
|
||||
if (r)
|
||||
goto err;
|
||||
r = sc_pkcs15_bind(priv->card, &priv->p15card);
|
||||
|
|
|
@ -59,7 +59,8 @@ static int init_pkcs15(PluginInstance *inst)
|
|||
r = sc_establish_context(&inst->ctx);
|
||||
if (r)
|
||||
return r;
|
||||
r = sc_connect_card(inst->ctx, 0, &inst->card);
|
||||
inst->reader_id = 0;
|
||||
r = sc_connect_card(inst->ctx->reader[inst->reader_id], 0, &inst->card);
|
||||
if (r)
|
||||
return r;
|
||||
r = sc_pkcs15_bind(inst->card, &inst->p15card);
|
||||
|
@ -76,7 +77,7 @@ static void close_pkcs15(PluginInstance *inst)
|
|||
inst->p15card = NULL;
|
||||
}
|
||||
if (inst->card) {
|
||||
sc_disconnect_card(inst->card);
|
||||
sc_disconnect_card(inst->card, 0);
|
||||
inst->card = NULL;
|
||||
}
|
||||
if (inst->ctx) {
|
||||
|
|
|
@ -12,6 +12,7 @@ typedef struct _PluginInstance
|
|||
{
|
||||
char *signdata;
|
||||
int signdata_len;
|
||||
int reader_id;
|
||||
struct sc_context *ctx;
|
||||
struct sc_card *card;
|
||||
struct sc_pkcs15_card *p15card;
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
struct sc_pkcs15_card *p15card;
|
||||
|
||||
int test()
|
||||
int test(void)
|
||||
{
|
||||
struct sc_file file;
|
||||
struct sc_apdu apdu;
|
||||
|
@ -69,7 +69,7 @@ err:
|
|||
return r;
|
||||
}
|
||||
|
||||
int test2()
|
||||
int test2(void)
|
||||
{
|
||||
int r;
|
||||
struct sc_path path;
|
||||
|
@ -106,7 +106,7 @@ int test2()
|
|||
return 0;
|
||||
}
|
||||
|
||||
int test3()
|
||||
int test3(void)
|
||||
{
|
||||
FILE *inf;
|
||||
u8 buf[256], txt[256];
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
/* Copyright (C) 2001 Juha Yrjölä <juha.yrjola@iki.fi>
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
/* Copyright (C) 2001 Juha Yrjölä <juha.yrjola@iki.fi>
|
||||
* All rights reserved.
|
||||
*
|
||||
|
@ -13,7 +12,7 @@
|
|||
|
||||
struct sc_pkcs15_card *p15card;
|
||||
|
||||
int enum_pins()
|
||||
int enum_pins(void)
|
||||
{
|
||||
int c, i;
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
/* Copyright (C) 2001 Juha Yrjölä <juha.yrjola@iki.fi>
|
||||
* All rights reserved.
|
||||
*
|
||||
|
@ -14,7 +13,7 @@
|
|||
|
||||
struct sc_pkcs15_card *p15card;
|
||||
|
||||
int enum_pins()
|
||||
int enum_pins(void)
|
||||
{
|
||||
int i, c;
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
/* Copyright (C) 2001 Juha Yrjölä <juha.yrjola@iki.fi>
|
||||
* All rights reserved.
|
||||
*
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
/* Copyright (C) 2001 Juha Yrjölä <juha.yrjola@iki.fi>
|
||||
* All rights reserved.
|
||||
*
|
||||
|
@ -24,24 +23,25 @@ int sc_test_init(int *argc, char *argv[])
|
|||
}
|
||||
ctx->error_file = stderr;
|
||||
ctx->debug_file = stdout;
|
||||
i = sc_detect_card(ctx, 0);
|
||||
i = sc_detect_card_presence(ctx->reader[0], 0);
|
||||
printf("Card %s.\n", i == 1 ? "present" : "absent");
|
||||
if (i < 0) {
|
||||
return i;
|
||||
}
|
||||
if (i == 0) {
|
||||
printf("Please insert a smart card.");
|
||||
printf("Please insert a smart card.\n");
|
||||
fflush(stdout);
|
||||
#if 0
|
||||
i = sc_wait_for_card(ctx, -1, -1);
|
||||
printf("\n");
|
||||
if (i < 0)
|
||||
return i;
|
||||
if (i != 1)
|
||||
return -1;
|
||||
#endif
|
||||
c = -1;
|
||||
for (i = 0; i < ctx->reader_count; i++) {
|
||||
if (sc_detect_card(ctx, i) == 1) {
|
||||
printf("Card detected in reader '%s'\n", ctx->readers[i]);
|
||||
if (sc_detect_card_presence(ctx->reader[i], 0) == 1) {
|
||||
printf("Card detected in reader '%s'\n", ctx->reader[i]->name);
|
||||
c = i;
|
||||
break;
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ int sc_test_init(int *argc, char *argv[])
|
|||
c = 0;
|
||||
printf("Connecting... ");
|
||||
fflush(stdout);
|
||||
i = sc_connect_card(ctx, c, &card);
|
||||
i = sc_connect_card(ctx->reader[c], 0, &card);
|
||||
if (i != 0) {
|
||||
printf("Connecting to card failed\n");
|
||||
return i;
|
||||
|
@ -67,8 +67,8 @@ int sc_test_init(int *argc, char *argv[])
|
|||
return 0;
|
||||
}
|
||||
|
||||
void sc_test_cleanup()
|
||||
void sc_test_cleanup(void)
|
||||
{
|
||||
sc_disconnect_card(card);
|
||||
sc_disconnect_card(card, 0);
|
||||
sc_destroy_context(ctx);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue