summaryrefslogtreecommitdiffstats
path: root/scd
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2002-03-28 12:43:24 +0100
committerWerner Koch <wk@gnupg.org>2002-03-28 12:43:24 +0100
commit0e44b06cc8a80c257a73e170631a7c3770266eb7 (patch)
tree426de69359c9b5cdd370ea3d90b48b1b190ddb9e /scd
parent* divert-scd.c (encode_md_for_card): Don't do the pkcs-1 padding, (diff)
downloadgnupg2-0e44b06cc8a80c257a73e170631a7c3770266eb7.tar.xz
gnupg2-0e44b06cc8a80c257a73e170631a7c3770266eb7.zip
* card.c (card_open, card_close): Adjusted for changes in OpenSC.
Diffstat (limited to 'scd')
-rw-r--r--scd/ChangeLog4
-rw-r--r--scd/Makefile.am6
-rw-r--r--scd/card-p15.c3
-rw-r--r--scd/card.c112
4 files changed, 61 insertions, 64 deletions
diff --git a/scd/ChangeLog b/scd/ChangeLog
index 399c6f544..9f0a13d98 100644
--- a/scd/ChangeLog
+++ b/scd/ChangeLog
@@ -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.
diff --git a/scd/Makefile.am b/scd/Makefile.am
index 2e01303c4..6639aa1c1 100644
--- a/scd/Makefile.am
+++ b/scd/Makefile.am
@@ -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
diff --git a/scd/card-p15.c b/scd/card-p15.c
index 950508fdb..14a274480 100644
--- a/scd/card-p15.c
+++ b/scd/card-p15.c
@@ -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);
diff --git a/scd/card.c b/scd/card.c
index e59f88bc9..0c8bf7c03 100644
--- a/scd/card.c
+++ b/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);
+ /* 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;
+ }
+ 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);
- 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;
+ 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;
}
- s = card->p15card->serial_number;
- if (!s || !hexdigitp (s) )
- return GNUPG_Invalid_Card; /* the serial number is mandatory */
- *serial = xstrdup (s);
+ *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;
}