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>
|
2002-03-10 Werner Koch <wk@gnupg.org>
|
||||||
|
|
||||||
* card-p15.c, card-dinsig.c, card-common.h: New.
|
* card-p15.c, card-dinsig.c, card-common.h: New.
|
||||||
|
@ -30,10 +30,12 @@ scdaemon_SOURCES = \
|
|||||||
card-common.h \
|
card-common.h \
|
||||||
card-p15.c card-dinsig.c
|
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 \
|
scdaemon_LDADD = ../jnlib/libjnlib.a ../assuan/libassuan.a \
|
||||||
../common/libcommon.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;
|
goto leave;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* cryptflags |= SC_PKCS15_HASH_SHA1; */
|
cryptflags |= SC_ALGORITHM_RSA_PAD_PKCS1;
|
||||||
/* cryptflags |= SC_PKCS15_PAD_PKCS1_V1_5; */
|
|
||||||
|
|
||||||
outbuflen = 1024;
|
outbuflen = 1024;
|
||||||
outbuf = xtrymalloc (outbuflen);
|
outbuf = xtrymalloc (outbuflen);
|
||||||
|
114
scd/card.c
114
scd/card.c
@ -28,6 +28,10 @@
|
|||||||
#include <opensc-pkcs15.h>
|
#include <opensc-pkcs15.h>
|
||||||
#include <ksba.h>
|
#include <ksba.h>
|
||||||
|
|
||||||
|
#if SC_MAX_SEC_ATTR_SIZE < 36
|
||||||
|
# error This is not the patched OpenSC version
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "scdaemon.h"
|
#include "scdaemon.h"
|
||||||
#include "card-common.h"
|
#include "card-common.h"
|
||||||
|
|
||||||
@ -123,7 +127,7 @@ card_open (CARD *rcard)
|
|||||||
return GNUPG_Out_Of_Core;
|
return GNUPG_Out_Of_Core;
|
||||||
card->reader = 0;
|
card->reader = 0;
|
||||||
|
|
||||||
rc = sc_establish_context (&card->ctx);
|
rc = sc_establish_context (&card->ctx, "scdaemon");
|
||||||
if (rc)
|
if (rc)
|
||||||
{
|
{
|
||||||
log_error ("failed to establish SC context: %s\n", sc_strerror (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 ();
|
card->ctx->error_file = log_get_stream ();
|
||||||
if (opt.debug)
|
if (opt.debug)
|
||||||
{
|
{
|
||||||
card->ctx->debug = 1;
|
|
||||||
card->ctx->debug_file = log_get_stream ();
|
card->ctx->debug_file = log_get_stream ();
|
||||||
}
|
}
|
||||||
if (sc_detect_card_presence (card->ctx->reader[card->reader], 0) != 1)
|
if (sc_detect_card_presence (card->ctx->reader[card->reader], 0) != 1)
|
||||||
@ -197,7 +200,7 @@ card_close (CARD card)
|
|||||||
}
|
}
|
||||||
if (card->ctx)
|
if (card->ctx)
|
||||||
{
|
{
|
||||||
sc_destroy_context (card->ctx);
|
sc_release_context (card->ctx);
|
||||||
card->ctx = NULL;
|
card->ctx = NULL;
|
||||||
}
|
}
|
||||||
xfree (card);
|
xfree (card);
|
||||||
@ -219,6 +222,10 @@ card_get_serial_and_stamp (CARD card, char **serial, time_t *stamp)
|
|||||||
{
|
{
|
||||||
char *s;
|
char *s;
|
||||||
int rc;
|
int rc;
|
||||||
|
struct sc_path path;
|
||||||
|
struct sc_file *file;
|
||||||
|
unsigned char buf[12];
|
||||||
|
int i;
|
||||||
|
|
||||||
if (!card || !serial || !stamp)
|
if (!card || !serial || !stamp)
|
||||||
return GNUPG_Invalid_Value;
|
return GNUPG_Invalid_Value;
|
||||||
@ -248,67 +255,52 @@ card_get_serial_and_stamp (CARD card, char **serial, time_t *stamp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!card->p15card)
|
/* We should lookup the iso 7812-1 and 8583-3 - argh ISO
|
||||||
{ /* fixme: construct a serial number */
|
practice is suppressing innovation - IETF rules! So we
|
||||||
/* We should lookup the iso 7812-1 and 8583-3 - argh ISO
|
always get the serialnumber from the 2F00 GDO file. */
|
||||||
practice is suppressing innovation - IETF rules! Anyway,
|
sc_format_path ("3F002F02", &path);
|
||||||
we try to get the serialnumber from the 2F00 GDO file. */
|
rc = sc_select_file (card->scard, &path, &file);
|
||||||
struct sc_path path;
|
if (rc)
|
||||||
struct sc_file *file;
|
{
|
||||||
unsigned char buf[12];
|
log_error ("sc_select_file failed: %s\n", sc_strerror (rc));
|
||||||
int i;
|
return GNUPG_Card_Error;
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
s = card->p15card->serial_number;
|
if (file->type != SC_FILE_TYPE_WORKING_EF
|
||||||
if (!s || !hexdigitp (s) )
|
|| file->ef_structure != SC_FILE_EF_TRANSPARENT)
|
||||||
return GNUPG_Invalid_Card; /* the serial number is mandatory */
|
{
|
||||||
*serial = xstrdup (s);
|
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)
|
if (!*serial)
|
||||||
return GNUPG_Out_Of_Core;
|
return GNUPG_Out_Of_Core;
|
||||||
|
for (i=0; i < 10; i++, s += 2)
|
||||||
|
sprintf (s, "%02X", buf[2+i]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user