mirror of
git://git.gnupg.org/gnupg.git
synced 2024-12-22 10:19:57 +01:00
* card.c (card_open, card_close): Adjusted for changes in OpenSC.
This commit is contained in:
parent
90bc40a9f7
commit
0e44b06cc8
@ -1,3 +1,7 @@
|
||||
2002-03-27 Werner Koch <wk@gnupg.org>
|
||||
|
||||
* card.c (card_open, card_close): Adjusted for changes in OpenSC.
|
||||
|
||||
2002-03-10 Werner Koch <wk@gnupg.org>
|
||||
|
||||
* card-p15.c, card-dinsig.c, card-common.h: New.
|
||||
|
@ -30,10 +30,12 @@ scdaemon_SOURCES = \
|
||||
card-common.h \
|
||||
card-p15.c card-dinsig.c
|
||||
|
||||
|
||||
# fixme: We added -lpcslite because the opensc config script can't cope with
|
||||
# a static only libopensc.
|
||||
scdaemon_LDADD = ../jnlib/libjnlib.a ../assuan/libassuan.a \
|
||||
../common/libcommon.a \
|
||||
$(LIBOPENSC_LIBS) $(LIBGCRYPT_LIBS) $(LIBKSBA_LIBS)
|
||||
$(LIBOPENSC_LIBS) $(LIBGCRYPT_LIBS) $(LIBKSBA_LIBS) \
|
||||
-lpcsclite -lpthread
|
||||
|
||||
|
||||
|
||||
|
@ -262,8 +262,7 @@ p15_sign (CARD card, const char *keyidstr, int hashalgo,
|
||||
goto leave;
|
||||
}
|
||||
|
||||
/* cryptflags |= SC_PKCS15_HASH_SHA1; */
|
||||
/* cryptflags |= SC_PKCS15_PAD_PKCS1_V1_5; */
|
||||
cryptflags |= SC_ALGORITHM_RSA_PAD_PKCS1;
|
||||
|
||||
outbuflen = 1024;
|
||||
outbuf = xtrymalloc (outbuflen);
|
||||
|
114
scd/card.c
114
scd/card.c
@ -28,6 +28,10 @@
|
||||
#include <opensc-pkcs15.h>
|
||||
#include <ksba.h>
|
||||
|
||||
#if SC_MAX_SEC_ATTR_SIZE < 36
|
||||
# error This is not the patched OpenSC version
|
||||
#endif
|
||||
|
||||
#include "scdaemon.h"
|
||||
#include "card-common.h"
|
||||
|
||||
@ -123,7 +127,7 @@ card_open (CARD *rcard)
|
||||
return GNUPG_Out_Of_Core;
|
||||
card->reader = 0;
|
||||
|
||||
rc = sc_establish_context (&card->ctx);
|
||||
rc = sc_establish_context (&card->ctx, "scdaemon");
|
||||
if (rc)
|
||||
{
|
||||
log_error ("failed to establish SC context: %s\n", sc_strerror (rc));
|
||||
@ -138,7 +142,6 @@ card_open (CARD *rcard)
|
||||
card->ctx->error_file = log_get_stream ();
|
||||
if (opt.debug)
|
||||
{
|
||||
card->ctx->debug = 1;
|
||||
card->ctx->debug_file = log_get_stream ();
|
||||
}
|
||||
if (sc_detect_card_presence (card->ctx->reader[card->reader], 0) != 1)
|
||||
@ -197,7 +200,7 @@ card_close (CARD card)
|
||||
}
|
||||
if (card->ctx)
|
||||
{
|
||||
sc_destroy_context (card->ctx);
|
||||
sc_release_context (card->ctx);
|
||||
card->ctx = NULL;
|
||||
}
|
||||
xfree (card);
|
||||
@ -219,6 +222,10 @@ card_get_serial_and_stamp (CARD card, char **serial, time_t *stamp)
|
||||
{
|
||||
char *s;
|
||||
int rc;
|
||||
struct sc_path path;
|
||||
struct sc_file *file;
|
||||
unsigned char buf[12];
|
||||
int i;
|
||||
|
||||
if (!card || !serial || !stamp)
|
||||
return GNUPG_Invalid_Value;
|
||||
@ -248,67 +255,52 @@ card_get_serial_and_stamp (CARD card, char **serial, time_t *stamp)
|
||||
}
|
||||
|
||||
|
||||
if (!card->p15card)
|
||||
{ /* fixme: construct a serial number */
|
||||
/* We should lookup the iso 7812-1 and 8583-3 - argh ISO
|
||||
practice is suppressing innovation - IETF rules! Anyway,
|
||||
we try to get the serialnumber from the 2F00 GDO file. */
|
||||
struct sc_path path;
|
||||
struct sc_file *file;
|
||||
unsigned char buf[12];
|
||||
int i;
|
||||
|
||||
sc_format_path ("3F002F02", &path);
|
||||
rc = sc_select_file (card->scard, &path, &file);
|
||||
if (rc)
|
||||
{
|
||||
log_error ("sc_select_file failed: %s\n", sc_strerror (rc));
|
||||
return GNUPG_Card_Error;
|
||||
}
|
||||
if (file->type != SC_FILE_TYPE_WORKING_EF
|
||||
|| file->ef_structure != SC_FILE_EF_TRANSPARENT)
|
||||
{
|
||||
log_error ("wrong type or structure of GDO file\n");
|
||||
sc_file_free (file);
|
||||
return GNUPG_Card_Error;
|
||||
}
|
||||
if (file->size != 12)
|
||||
{ /* FIXME: Use a real parser */
|
||||
log_error ("unsupported size of GDO file\n");
|
||||
sc_file_free (file);
|
||||
return GNUPG_Card_Error;
|
||||
}
|
||||
|
||||
rc = sc_read_binary (card->scard, 0, buf, DIM (buf), 0);
|
||||
sc_file_free (file);
|
||||
if (rc < 0)
|
||||
{
|
||||
log_error ("error reading GDO file: %s\n", sc_strerror (rc));
|
||||
return GNUPG_Card_Error;
|
||||
}
|
||||
if (rc != file->size)
|
||||
{
|
||||
log_error ("short read on GDO file\n");
|
||||
return GNUPG_Card_Error;
|
||||
}
|
||||
if (buf[0] != 0x5a || buf[1] != 10)
|
||||
{
|
||||
log_error ("invalid structure of GDO file\n");
|
||||
return GNUPG_Card_Error;
|
||||
}
|
||||
*serial = s = xtrymalloc (21);
|
||||
if (!*serial)
|
||||
return GNUPG_Out_Of_Core;
|
||||
for (i=0; i < 10; i++, s += 2)
|
||||
sprintf (s, "%02X", buf[2+i]);
|
||||
return 0;
|
||||
/* We should lookup the iso 7812-1 and 8583-3 - argh ISO
|
||||
practice is suppressing innovation - IETF rules! So we
|
||||
always get the serialnumber from the 2F00 GDO file. */
|
||||
sc_format_path ("3F002F02", &path);
|
||||
rc = sc_select_file (card->scard, &path, &file);
|
||||
if (rc)
|
||||
{
|
||||
log_error ("sc_select_file failed: %s\n", sc_strerror (rc));
|
||||
return GNUPG_Card_Error;
|
||||
}
|
||||
s = card->p15card->serial_number;
|
||||
if (!s || !hexdigitp (s) )
|
||||
return GNUPG_Invalid_Card; /* the serial number is mandatory */
|
||||
*serial = xstrdup (s);
|
||||
if (file->type != SC_FILE_TYPE_WORKING_EF
|
||||
|| file->ef_structure != SC_FILE_EF_TRANSPARENT)
|
||||
{
|
||||
log_error ("wrong type or structure of GDO file\n");
|
||||
sc_file_free (file);
|
||||
return GNUPG_Card_Error;
|
||||
}
|
||||
if (file->size != 12)
|
||||
{ /* FIXME: Use a real parser */
|
||||
log_error ("unsupported size of GDO file\n");
|
||||
sc_file_free (file);
|
||||
return GNUPG_Card_Error;
|
||||
}
|
||||
|
||||
rc = sc_read_binary (card->scard, 0, buf, DIM (buf), 0);
|
||||
sc_file_free (file);
|
||||
if (rc < 0)
|
||||
{
|
||||
log_error ("error reading GDO file: %s\n", sc_strerror (rc));
|
||||
return GNUPG_Card_Error;
|
||||
}
|
||||
if (rc != file->size)
|
||||
{
|
||||
log_error ("short read on GDO file\n");
|
||||
return GNUPG_Card_Error;
|
||||
}
|
||||
if (buf[0] != 0x5a || buf[1] != 10)
|
||||
{
|
||||
log_error ("invalid structure of GDO file\n");
|
||||
return GNUPG_Card_Error;
|
||||
}
|
||||
*serial = s = xtrymalloc (21);
|
||||
if (!*serial)
|
||||
return GNUPG_Out_Of_Core;
|
||||
for (i=0; i < 10; i++, s += 2)
|
||||
sprintf (s, "%02X", buf[2+i]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user