gnupg port to openct, but not working

Andreas Jellinghaus aj@dungeon.inka.de
Fri Aug 15 17:08:02 2003


--=-6Tuggp0j71IYGNFI3HmI
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Oops.

Now the patch with my changes to gnupg 1.9.0 is attached.

Andreas


--=-6Tuggp0j71IYGNFI3HmI
Content-Disposition: attachment; filename=gnupg-patch
Content-Type: text/x-patch; name=gnupg-patch; charset=UTF-8
Content-Transfer-Encoding: 7bit

diff -udrp gnupg-1.9.0.orig/g10/Makefile.am gnupg-1.9.0/g10/Makefile.am
--- gnupg-1.9.0.orig/g10/Makefile.am	2003-08-05 18:05:12.000000000 +0200
+++ gnupg-1.9.0/g10/Makefile.am	2003-08-15 14:44:29.000000000 +0200
@@ -20,7 +20,7 @@
 ## Process this file with automake to produce Makefile.in
 
 localedir = $(datadir)/locale
-INCLUDES = -I$(top_srcdir)/common -I$(top_srcdir)/include -I$(top_srcdir)/intl -DLOCALEDIR=\"$(localedir)\"
+INCLUDES = -I$(top_srcdir)/common -I$(top_srcdir)/include -I$(top_srcdir)/intl -DLOCALEDIR=\"$(localedir)\" @LIBASSUAN_CFLAGS@
 
 EXTRA_DIST = options.skel
 # it seems that we can't use this with automake 1.5
@@ -110,8 +110,8 @@ gpgv2_SOURCES = gpgv.c           \
 #	       $(common_source)
 
 LDADD =  $(needed_libs) @INTLLIBS@ @CAPLIBS@ @ZLIBS@ 
-gpg2_LDADD = $(LIBGCRYPT_LIBS) $(LDADD) -lassuan -lgpg-error
-gpgv2_LDADD = $(LIBGCRYPT_LIBS) $(LDADD) -lassuan -lgpg-error
+gpg2_LDADD = $(LIBGCRYPT_LIBS) $(LDADD) @LIBASSUAN_LIBS@ -lgpg-error
+gpgv2_LDADD = $(LIBGCRYPT_LIBS) $(LDADD) @LIBASSUAN_LIBS@ -lgpg-error
 
 $(PROGRAMS): $(needed_libs)
 
diff -udrp gnupg-1.9.0.orig/g10/Makefile.in gnupg-1.9.0/g10/Makefile.in
--- gnupg-1.9.0.orig/g10/Makefile.in	2003-08-05 19:32:08.000000000 +0200
+++ gnupg-1.9.0/g10/Makefile.in	2003-08-15 14:44:29.000000000 +0200
@@ -221,7 +221,7 @@ target_os = @target_os@
 target_vendor = @target_vendor@
 
 localedir = $(datadir)/locale
-INCLUDES = -I$(top_srcdir)/common -I$(top_srcdir)/include -I$(top_srcdir)/intl -DLOCALEDIR=\"$(localedir)\"
+INCLUDES = -I$(top_srcdir)/common -I$(top_srcdir)/include -I$(top_srcdir)/intl -DLOCALEDIR=\"$(localedir)\" @LIBASSUAN_CFLAGS@
 
 EXTRA_DIST = options.skel
 @HAVE_DOSISH_SYSTEM_FALSE@AM_CFLAGS = -DGNUPG_LIBEXECDIR="\"$(libexecdir)\""
@@ -309,8 +309,8 @@ gpgv2_SOURCES = gpgv.c           \
 #	       ks-db.h \
 #	       $(common_source)
 LDADD = $(needed_libs) @INTLLIBS@ @CAPLIBS@ @ZLIBS@ 
-gpg2_LDADD = $(LIBGCRYPT_LIBS) $(LDADD) -lassuan -lgpg-error
-gpgv2_LDADD = $(LIBGCRYPT_LIBS) $(LDADD) -lassuan -lgpg-error
+gpg2_LDADD = $(LIBGCRYPT_LIBS) $(LDADD) @LIBASSUAN_LIBS@ -lgpg-error
+gpgv2_LDADD = $(LIBGCRYPT_LIBS) $(LDADD) @LIBASSUAN_LIBS@ -lgpg-error
 subdir = g10
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
 mkinstalldirs = $(SHELL) $(top_srcdir)/scripts/mkinstalldirs
diff -udrp gnupg-1.9.0.orig/scd/apdu.c gnupg-1.9.0/scd/apdu.c
--- gnupg-1.9.0.orig/scd/apdu.c	2003-08-05 16:57:23.000000000 +0200
+++ gnupg-1.9.0/scd/apdu.c	2003-08-15 16:52:44.000000000 +0200
@@ -26,6 +26,10 @@
 #include <dlfcn.h>
 #include <assert.h>
 
+#include <openct/openct.h>
+#include <openct/logging.h>
+#include <openct/error.h>
+
 #include "scdaemon.h"
 #include "apdu.h"
 
@@ -39,85 +43,15 @@
 static struct {
   int used;            /* True if slot is used. */
   unsigned short port; /* Port number:  0 = unused, 1 - dev/tty */
-  int is_ctapi;        /* This is a ctAPI driver. */
-  struct {
-    unsigned long context;
-    unsigned long card;
-    unsigned long protocol;
-  } pcsc;
   int status;
   unsigned char atr[33];
   size_t atrlen;
+  int openct_reader;
+  int openct_slot;
+  ct_handle *openct_handle;
 } reader_table[MAX_READER];                          
 
 
-/* ct API function pointer. */
-static char (*CT_init) (unsigned short ctn, unsigned short Pn);
-static char (*CT_data) (unsigned short ctn, unsigned char *dad,
-                        unsigned char *sad, unsigned short lc,
-                        unsigned char *cmd, unsigned short *lr,
-                        unsigned char *rsp);
-static char (*CT_close) (unsigned short ctn);
-
-/* PC/SC constants and function pointer. */
-#define PCSC_SCOPE_USER      0 
-#define PCSC_SCOPE_TERMINAL  1 
-#define PCSC_SCOPE_SYSTEM    2 
-#define PCSC_SCOPE_GLOBAL    3 
-
-#define PCSC_PROTOCOL_T0     1 
-#define PCSC_PROTOCOL_T1     2 
-#define PCSC_PROTOCOL_RAW    4 
-
-#define PCSC_SHARE_EXCLUSIVE 1
-#define PCSC_SHARE_SHARED    2
-#define PCSC_SHARE_DIRECT    3
-
-#define PCSC_LEAVE_CARD      0
-#define PCSC_RESET_CARD      1
-#define PCSC_UNPOWER_CARD    2
-#define PCSC_EJECT_CARD      3
-
-struct pcsc_io_request_s {
-  unsigned long protocol; 
-  unsigned long pci_len;
-};
-
-typedef struct pcsc_io_request_s *pcsc_io_request_t;
-
-long (*pcsc_establish_context) (unsigned long scope,
-                                const void *reserved1,
-                                const void *reserved2,
-                                unsigned long *r_context);
-long (*pcsc_release_context) (unsigned long context);
-long (*pcsc_list_readers) (unsigned long context, const char *groups,
-                        char *readers, unsigned long *readerslen);
-long (*pcsc_connect) (unsigned long context,
-                      const char *reader,
-                      unsigned long share_mode,
-                      unsigned long preferred_protocols,
-                      unsigned long *r_card,
-                      unsigned long *r_active_protocol);
-long (*pcsc_disconnect) (unsigned long card, unsigned long disposition);
-long (*pcsc_status) (unsigned long card,
-                     char *reader, unsigned long *readerlen,
-                     unsigned long *r_state, unsigned long *r_protocol,
-                     unsigned char *atr, unsigned long *atrlen);
-long (*pcsc_begin_transaction) (unsigned long card);
-long (*pcsc_end_transaction) (unsigned long card);
-long (*pcsc_transmit) (unsigned long card,
-                       const pcsc_io_request_t send_pci,
-                       const unsigned char *send_buffer,
-                       unsigned long send_len,
-                       pcsc_io_request_t recv_pci,
-                       unsigned char *recv_buffer,
-                       unsigned long *recv_len);
-long (*pcsc_set_timeout) (unsigned long context, unsigned long timeout);
-
-
-
-
-
 /* 
       Helper
  */
@@ -141,7 +75,6 @@ new_reader_slot (void)    
       return -1;
     }
   reader_table[reader].used = 1;
-  reader_table[reader].is_ctapi = 0;
   return reader;
 }
 
@@ -149,24 +82,18 @@ new_reader_slot (void)    
 static void
 dump_reader_status (int reader)
 {
-  if (reader_table[reader].is_ctapi)
-    {
-      log_info ("reader slot %d: %s\n", reader,
-                reader_table[reader].status == 1? "Processor ICC present" :
-                reader_table[reader].status == 0? "Memory ICC present" :
-                "ICC not present" );
-    }
-  else
-    {
-      log_info ("reader slot %d: active protocol:", reader);
-      if ((reader_table[reader].pcsc.protocol & PCSC_PROTOCOL_T0))
-        log_printf (" T0");
-      else if ((reader_table[reader].pcsc.protocol & PCSC_PROTOCOL_T1))
-        log_printf (" T1");
-      else if ((reader_table[reader].pcsc.protocol & PCSC_PROTOCOL_RAW))
-        log_printf (" raw");
-      log_printf ("\n");
-    }
+  ct_info_t info;
+
+  if (reader < 0 || reader >= MAX_READER)
+    return;
+
+  ct_reader_info(reader_table[reader].openct_reader, &info);
+
+  log_info("reader number: %d\n", reader);
+  log_info("reader name: %s\n", info.ct_name);
+  log_info("reader slots: %d\n", info.ct_slots);
+  if (info.ct_display) log_info("reader has a display.\n");
+  if (info.ct_keypad) log_info("reader has a keypad.\n");
 
   if (reader_table[reader].status != -1)
     {
@@ -177,330 +104,68 @@ dump_reader_status (int reader)
 }
 
 
-
-/* 
-       ct API Interface 
- */
-
 static const char *
-ct_error_string (long err)
-{
-  switch (err)
-    {
-    case 0: return "okay";
-    case -1: return "invalid data";
-    case -8: return "ct error";
-    case -10: return "transmission error";
-    case -11: return "memory allocation error";
-    case -128: return "HTSI error";
-    default: return "unknown CT-API error";
-    }
-}
-
-/* Wait for the card in READER and activate it.  Return -1 on error or
-   0 on success. */
-static int
-ct_activate_card (int reader)
+openct_error_string (long err)
 {
-  int rc, count;
-
-  for (count = 0; count < CARD_CONNECT_TIMEOUT; count++)
-    {
-      unsigned char dad[1], sad[1], cmd[11], buf[256];
-      unsigned short buflen;
-
-      if (count)
-        ; /* FIXME: we should use a more reliable timer than sleep. */
-
-      /* Check whether card has been inserted. */
-      dad[0] = 1;     /* Destination address: CT. */    
-      sad[0] = 2;     /* Source address: Host. */
-
-      cmd[0] = 0x20;  /* Class byte. */
-      cmd[1] = 0x13;  /* Request status. */
-      cmd[2] = 0x00;  /* From kernel. */
-      cmd[3] = 0x80;  /* Return card's DO. */
-      cmd[4] = 0x00;
-
-      buflen = DIM(buf);
-
-      rc = CT_data (reader, dad, sad, 5, cmd, &buflen, buf);
-      if (rc || buflen < 2 || buf[buflen-2] != 0x90)
-        {
-          log_error ("ct_activate_card: can't get status of reader %d: %s\n",
-                     reader, ct_error_string (rc));
-          return -1;
-        }
-
-      if (buf[0] == 0x05)
-        { /* Connected, now activate the card. */           
-          dad[0] = 1;    /* Destination address: CT. */    
-          sad[0] = 2;    /* Source address: Host. */
-
-          cmd[0] = 0x20;  /* Class byte. */
-          cmd[1] = 0x12;  /* Request ICC. */
-          cmd[2] = 0x01;  /* From first interface. */
-          cmd[3] = 0x01;  /* Return card's ATR. */
-          cmd[4] = 0x00;
-
-          buflen = DIM(buf);
-
-          rc = CT_data (reader, dad, sad, 5, cmd, &buflen, buf);
-          if (rc || buflen < 2 || buf[buflen-2] != 0x90)
-            {
-              log_error ("ct_activate_card(%d): activation failed: %s\n",
-                         reader, ct_error_string (rc));
-              return -1;
-            }
-
-          /* Store the type and the ATR. */
-          if (buflen - 2 > DIM (reader_table[0].atr))
-            {
-              log_error ("ct_activate_card(%d): ATR too long\n", reader);
-              return -1;
-            }
-
-          reader_table[reader].status = buf[buflen - 1];
-          memcpy (reader_table[reader].atr, buf, buflen - 2);
-          reader_table[reader].atrlen = buflen - 2;
-          return 0;
-        }
-
-    }
- 
-  log_info ("ct_activate_card(%d): timeout waiting for card\n", reader);
-  return -1;
+  return ct_strerror(err);
 }
 
+/* 
+       OpenCT Interface
+ */
 
-/* Open a reader and return an internal handle for it.  PORT is a
-   non-negative value with the port number of the reader. USB readers
-   do have port numbers starting at 32769. */
 static int
-open_ct_reader (int port)
+open_openct_reader (const char *portstr)
 {
-  int rc, reader;
+  int reader, rc;
 
-  if (port < 0 || port > 0xffff)
-    {
-      log_error ("open_ct_reader: invalid port %d requested\n", port);
-      return -1;
-    }
   reader = new_reader_slot ();
   if (reader == -1)
-    return reader;
-  reader_table[reader].port = port;
-
-  rc = CT_init (reader, (unsigned short)port);
-  if (rc)
-    {
-      log_error ("apdu_open_ct_reader failed on port %d: %s\n",
-                 port, ct_error_string (rc));
-      reader_table[reader].used = 0;
-      return -1;
-    }
-
-  rc = ct_activate_card (reader);
-  if (rc)
-    {
-      reader_table[reader].used = 0;
-      return -1;
-    }
-
-  reader_table[reader].is_ctapi = 1;
-  dump_reader_status (reader);
-  return reader;
-}
-
-
-/* Actually send the APDU of length APDULEN to SLOT and return a
-   maximum of *BUFLEN data in BUFFER, the actual retruned size will be
-   set to BUFLEN.  Returns: CT API error code. */
-static int
-ct_send_apdu (int slot, unsigned char *apdu, size_t apdulen,
-              unsigned char *buffer, size_t *buflen)
-{
-  int rc;
-  unsigned char dad[1], sad[1];
-  unsigned short ctbuflen;
-  
-  dad[0] = 0;     /* Destination address: Card. */    
-  sad[0] = 2;     /* Source address: Host. */
-  ctbuflen = *buflen;
-  if (DBG_CARD_IO)
-    log_printhex ("  CT_data:", apdu, apdulen);
-  rc = CT_data (slot, dad, sad, apdulen, apdu, &ctbuflen, buffer);
-  *buflen = ctbuflen;
-
-  /* FIXME: map the errorcodes to GNUPG ones, so that they can be
-     shared between CTAPI and PCSC. */
-  return rc;
-}
-
-
-
-static const char *
-pcsc_error_string (long err)
-{
-  const char *s;
+    return -1;
 
-  if (!err)
-    return "okay";
-  if ((err & 0x80100000) != 0x80100000)
-    return "invalid PC/SC error code";
-  err &= 0xffff;
-  switch (err)
-    {
-    case 0x0002: s = "cancelled"; break;
-    case 0x000e: s = "can't dispose"; break;
-    case 0x0008: s = "insufficient buffer"; break;   
-    case 0x0015: s = "invalid ATR"; break;
-    case 0x0003: s = "invalid handle"; break;
-    case 0x0004: s = "invalid parameter"; break; 
-    case 0x0005: s = "invalid target"; break;
-    case 0x0011: s = "invalid value"; break; 
-    case 0x0006: s = "no memory"; break;  
-    case 0x0013: s = "comm error"; break;      
-    case 0x0001: s = "internal error"; break;     
-    case 0x0014: s = "unknown error"; break; 
-    case 0x0007: s = "waited too long"; break;  
-    case 0x0009: s = "unknown reader"; break;
-    case 0x000a: s = "timeout"; break; 
-    case 0x000b: s = "sharing violation"; break;       
-    case 0x000c: s = "no smartcard"; break;
-    case 0x000d: s = "unknown card"; break;   
-    case 0x000f: s = "proto mismatch"; break;          
-    case 0x0010: s = "not ready"; break;               
-    case 0x0012: s = "system cancelled"; break;        
-    case 0x0016: s = "not transacted"; break;
-    case 0x0017: s = "reader unavailable"; break; 
-    case 0x0065: s = "unsupported card"; break;        
-    case 0x0066: s = "unresponsive card"; break;       
-    case 0x0067: s = "unpowered card"; break;          
-    case 0x0068: s = "reset card"; break;              
-    case 0x0069: s = "removed card"; break;            
-    case 0x006a: s = "inserted card"; break;           
-    case 0x001f: s = "unsupported feature"; break;     
-    case 0x0019: s = "PCI too small"; break;           
-    case 0x001a: s = "reader unsupported"; break;      
-    case 0x001b: s = "duplicate reader"; break;        
-    case 0x001c: s = "card unsupported"; break;        
-    case 0x001d: s = "no service"; break;              
-    case 0x001e: s = "service stopped"; break;      
-    default:     s = "unknown PC/SC error code"; break;
+  if (portstr) {
+    rc = sscanf(portstr,"%d:%d", &reader_table[reader].openct_reader,
+	  & reader_table[reader].openct_slot);
+    if (rc != 2) {
+      rc = sscanf(portstr,"%d", &reader_table[reader].openct_reader);
+      if (rc != 1) {
+        log_error("need a number as port string: %s", portstr);
+        return -1;
+      }
+      reader_table[reader].openct_slot=0;
     }
-  return s;
-}
-
-/* 
-       PC/SC Interface
- */
+  } else {
+      reader_table[reader].openct_reader=0;
+      reader_table[reader].openct_slot=0;
+  }
 
-static int
-open_pcsc_reader (const char *portstr)
-{
-  long err;
-  int slot;
-  char *list = NULL;
-  unsigned long nreader, listlen, atrlen;
-  char *p;
-  unsigned long card_state, card_protocol;
+  reader_table[reader].openct_handle =
+    ct_reader_connect(reader_table[reader].openct_reader);
 
-  slot = new_reader_slot ();
-  if (slot == -1)
+  if (!reader_table[reader].openct_handle) {
+    log_error("ct_reader_connect socket failed\n");
     return -1;
+  }
 
-  err = pcsc_establish_context (PCSC_SCOPE_SYSTEM, NULL, NULL,
-                                &reader_table[slot].pcsc.context);
-  if (err)
-    {
-      log_error ("pcsc_establish_context failed: %s (0x%lx)\n",
-                 pcsc_error_string (err), err);
-      reader_table[slot].used = 0;
-      return -1;
-    }
-  
-  err = pcsc_list_readers (reader_table[slot].pcsc.context,
-                           NULL, NULL, &nreader);
-  if (!err)
-    {
-      list = xtrymalloc (nreader+1); /* Better add 1 for safety reasons. */
-      if (!list)
-        {
-          log_error ("error allocating memory for reader list\n");
-          pcsc_release_context (reader_table[slot].pcsc.context);
-          reader_table[slot].used = 0;
-          return -1;
-        }
-      err = pcsc_list_readers (reader_table[slot].pcsc.context,
-                               NULL, list, &nreader);
-    }
-  if (err)
-    {
-      log_error ("pcsc_list_readers failed: %s (0x%lx)\n",
-                 pcsc_error_string (err), err);
-      pcsc_release_context (reader_table[slot].pcsc.context);
-      reader_table[slot].used = 0;
-      xfree (list);
-      return -1;
-    }
+  rc = ct_card_request(reader_table[reader].openct_handle, 
+                     reader_table[reader].openct_slot, 0, NULL,
+                     &reader_table[reader].atr,
+                     sizeof(reader_table[reader].atr) -1);
+  if (rc < 0) {
+     log_error("openct_reader_connect read failed: %s\n",
+                      ct_strerror(rc));
+     return -1;
+  }
 
-  listlen = nreader;
-  p = list;
-  while (nreader)
-    {
-      if (!*p && !p[1])
-        break;
-      log_info ("detected reader `%s'\n", p);
-      if (nreader < (strlen (p)+1))
-        {
-          log_error ("invalid response from pcsc_list_readers\n");
-          break;
-        }
-      nreader -= strlen (p)+1;
-      p += strlen (p) + 1;
-    }
+  if (rc == 0) {
+    log_error("openct_reader_connect recved no data\n");
+    return -1;
+  }
 
-  err = pcsc_connect (reader_table[slot].pcsc.context,
-                      portstr? portstr : list,
-                      PCSC_SHARE_EXCLUSIVE,
-                      PCSC_PROTOCOL_T0|PCSC_PROTOCOL_T1,
-                      &reader_table[slot].pcsc.card,
-                      &reader_table[slot].pcsc.protocol);
-  if (err)
-    {
-      log_error ("pcsc_connect failed: %s (0x%lx)\n",
-                  pcsc_error_string (err), err);
-      pcsc_release_context (reader_table[slot].pcsc.context);
-      reader_table[slot].used = 0;
-      xfree (list);
-      return -1;
-    }      
-  
-  atrlen = 32;
-  /* (We need to pass a dummy buffer.  We use LIST because it ought to
-     be large enough.) */
-  err = pcsc_status (reader_table[slot].pcsc.card,
-                     list, &listlen,
-                     &card_state, &card_protocol,
-                     reader_table[slot].atr, &atrlen);
-  xfree (list);
-  if (err)
-    {
-      log_error ("pcsc_status failed: %s (0x%lx)\n",
-                  pcsc_error_string (err), err);
-      pcsc_release_context (reader_table[slot].pcsc.context);
-      reader_table[slot].used = 0;
-      return -1;
-    }
-  if (atrlen >= DIM (reader_table[0].atr))
-    log_bug ("ATR returned by pcsc_status is too large\n");
-  reader_table[slot].atrlen = atrlen;
-/*   log_debug ("state    from pcsc_status: 0x%lx\n", card_state); */
-/*   log_debug ("protocol from pcsc_status: 0x%lx\n", card_protocol); */
+ reader_table[reader].atrlen=rc;
 
-  dump_reader_status (slot); 
-  return slot;
+  dump_reader_status (reader); 
+  return reader;
 }
 
 
@@ -508,31 +173,17 @@ open_pcsc_reader (const char *portstr)
    maximum of *BUFLEN data in BUFFER, the actual returned size will be
    set to BUFLEN.  Returns: CT API error code. */
 static int
-pcsc_send_apdu (int slot, unsigned char *apdu, size_t apdulen,
+openct_send_apdu (int slot, unsigned char *apdu, size_t apdulen,
                 unsigned char *buffer, size_t *buflen)
 {
-  long err;
-  struct pcsc_io_request_s send_pci;
-  unsigned long recv_len;
-  
-  if (DBG_CARD_IO)
-    log_printhex ("  CT_data:", apdu, apdulen);
+  int rc;
 
-  if ((reader_table[slot].pcsc.protocol & PCSC_PROTOCOL_T1))
-      send_pci.protocol = PCSC_PROTOCOL_T1;
-  else
-      send_pci.protocol = PCSC_PROTOCOL_T0;
-  send_pci.pci_len = sizeof send_pci;
-  recv_len = *buflen;
-  err = pcsc_transmit (reader_table[slot].pcsc.card,
-                       &send_pci, apdu, apdulen,
-                       NULL, buffer, &recv_len);
-  *buflen = recv_len;
-  if (err)
-    log_error ("pcsc_transmit failed: %s (0x%lx)\n",
-               pcsc_error_string (err), err);
-  
-  return err? -1:0;
+
+  rc = ct_card_transact(reader_table[slot].openct_handle,
+		  reader_table[slot].openct_slot,
+		  apdu, apdulen, buffer, buflen);
+
+  return rc;
 }
 
 
@@ -549,81 +200,7 @@ pcsc_send_apdu (int slot, unsigned char 
 int
 apdu_open_reader (const char *portstr)
 {
-  static int pcsc_api_loaded, ct_api_loaded;
-
-  if (opt.ctapi_driver && *opt.ctapi_driver)
-    {
-      int port = portstr? atoi (portstr) : 32768;
-
-      if (!ct_api_loaded)
-        {
-          void *handle;
-          
-          handle = dlopen (opt.ctapi_driver, RTLD_LAZY);
-          if (!handle)
-            {
-              log_error ("apdu_open_reader: failed to open driver: %s",
-                         dlerror ());
-              return -1;
-            }
-          CT_init = dlsym (handle, "CT_init");
-          CT_data = dlsym (handle, "CT_data");
-          CT_close = dlsym (handle, "CT_close");
-          if (!CT_init || !CT_data || !CT_close)
-            {
-              log_error ("apdu_open_reader: invalid ctAPI driver\n");
-              dlclose (handle);
-              return -1;
-            }
-          ct_api_loaded = 1;
-        }
-      return open_ct_reader (port);
-    }
-
-  
-  /* No ctAPI configured, so lets try the PC/SC API */
-  if (!pcsc_api_loaded)
-    {
-      void *handle;
-
-      handle = dlopen ("libpcsclite.so", RTLD_LAZY);
-      if (!handle)
-        {
-          log_error ("apdu_open_reader: failed to open driver: %s",
-                     dlerror ());
-          return -1;
-        }
-
-      pcsc_establish_context = dlsym (handle, "SCardEstablishContext");
-      pcsc_release_context   = dlsym (handle, "SCardReleaseContext");
-      pcsc_list_readers      = dlsym (handle, "SCardListReaders");
-      pcsc_connect           = dlsym (handle, "SCardConnect");
-      pcsc_disconnect        = dlsym (handle, "SCardDisconnect");
-      pcsc_status            = dlsym (handle, "SCardStatus");
-      pcsc_begin_transaction = dlsym (handle, "SCardBeginTransaction");
-      pcsc_end_transaction   = dlsym (handle, "SCardEndTransaction");
-      pcsc_transmit          = dlsym (handle, "SCardTransmit");
-      pcsc_set_timeout       = dlsym (handle, "SCardSetTimeout");
-
-      if (!pcsc_establish_context
-          || !pcsc_release_context  
-          || !pcsc_list_readers     
-          || !pcsc_connect          
-          || !pcsc_disconnect
-          || !pcsc_status
-          || !pcsc_begin_transaction
-          || !pcsc_end_transaction
-          || !pcsc_transmit         
-          || !pcsc_set_timeout)
-        {
-          log_error ("apdu_open_reader: invalid PC/SC driver\n");
-          dlclose (handle);
-          return -1;
-        }
-      pcsc_api_loaded = 1;
-    }
-  
-  return open_pcsc_reader (portstr);
+  return open_openct_reader (portstr);
 }
 
 
@@ -649,10 +226,7 @@ error_string (int slot, long rc)
 {
   if (slot < 0 || slot >= MAX_READER || !reader_table[slot].used )
     return "[invalid slot]";
-  if (reader_table[slot].is_ctapi)
-    return ct_error_string (rc);
-  else
-    return pcsc_error_string (rc);
+  return openct_error_string (rc);
 }
 
 
@@ -663,10 +237,7 @@ send_apdu (int slot, unsigned char *apdu
 {
   if (slot < 0 || slot >= MAX_READER || !reader_table[slot].used )
     return SW_HOST_NO_DRIVER;
-  if (reader_table[slot].is_ctapi)
-    return ct_send_apdu (slot, apdu, apdulen, buffer, buflen);
-  else
-    return pcsc_send_apdu (slot, apdu, apdulen, buffer, buflen);
+  return openct_send_apdu (slot, apdu, apdulen, buffer, buflen);
 }
 
 /* Send an APDU to the card in SLOT.  The APDU is created from all
@@ -859,6 +430,3 @@ apdu_send_simple (int slot, int class, i
   return apdu_send_le (slot, class, ins, p0, p1, lc, data, -1, NULL, NULL);
 }
 
-
-
-
diff -udrp gnupg-1.9.0.orig/scd/card-p15.c gnupg-1.9.0/scd/card-p15.c
--- gnupg-1.9.0.orig/scd/card-p15.c	2003-07-03 20:10:13.000000000 +0200
+++ gnupg-1.9.0/scd/card-p15.c	2003-08-15 14:44:29.000000000 +0200
@@ -136,7 +136,7 @@ p15_enum_keypairs (CARD card, int idx,
       log_info ("certificate for private key %d not found: %s\n",
                 idx, sc_strerror (rc));
       /* note, that we return the ID anyway */
-      rc = gpg_error (GPG_ERR_MISSING_CERTIFICATE);
+      rc = gpg_error (GPG_ERR_MISSING_CERT);
       goto return_keyid;
     }
   certinfo = tmpobj->data;
@@ -339,7 +339,7 @@ p15_prepare_key (CARD card, const char *
   if (rc < 0)
     {
       log_error ("private key not found: %s\n", sc_strerror(rc));
-      return gpg_error (GPG_ERR_NO_SECRET_KEY);
+      return gpg_error (GPG_ERR_NO_SECKEY);
     }
 
   rc = sc_pkcs15_find_pin_by_auth_id (card->p15card,
@@ -357,7 +357,7 @@ p15_prepare_key (CARD card, const char *
   rc = pincb (pincb_arg, pinobj->label, &pinvalue);
   if (rc)
     {
-      log_info ("PIN callback returned error: %s\n", gnupg_strerror (rc));
+      log_info ("PIN callback returned error: %s\n", gpg_strerror (rc));
       return rc;
     }
 
diff -udrp gnupg-1.9.0.orig/scd/Makefile.am gnupg-1.9.0/scd/Makefile.am
--- gnupg-1.9.0.orig/scd/Makefile.am	2003-07-31 17:28:01.000000000 +0200
+++ gnupg-1.9.0/scd/Makefile.am	2003-08-15 16:45:34.000000000 +0200
@@ -38,7 +38,7 @@ scdaemon_SOURCES = \
 
 scdaemon_LDADD = ../jnlib/libjnlib.a ../common/libcommon.a \
 	  $(OPENSC_LIBS) $(LIBGCRYPT_LIBS) $(KSBA_LIBS) $(LIBASSUAN_LIBS) \
-	 -lgpg-error @INTLLIBS@ -ldl
+	 -lgpg-error @INTLLIBS@ -lopenct
 
 sc_investigate_SOURCES = \
 	sc-investigate.c scdaemon.h \
@@ -50,7 +50,7 @@ sc_investigate_SOURCES = \
 
 sc_investigate_LDADD = \
 	../jnlib/libjnlib.a ../common/libcommon.a \
-	$(LIBGCRYPT_LIBS) @INTLLIBS@ -lgpg-error -ldl
+	$(LIBGCRYPT_LIBS) @INTLLIBS@ -lgpg-error -lopenct
 
 
 sc_copykeys_SOURCES = \
@@ -64,7 +64,7 @@ sc_copykeys_SOURCES = \
 sc_copykeys_LDADD = \
 	../jnlib/libjnlib.a ../common/libcommon.a \
 	../common/libsimple-pwquery.a \
-	$(LIBGCRYPT_LIBS) -lgpg-error @INTLLIBS@ -ldl
+	$(LIBGCRYPT_LIBS) -lgpg-error @INTLLIBS@ -lopenct
 
 
 
diff -udrp gnupg-1.9.0.orig/scd/Makefile.in gnupg-1.9.0/scd/Makefile.in
--- gnupg-1.9.0.orig/scd/Makefile.in	2003-08-05 19:32:17.000000000 +0200
+++ gnupg-1.9.0/scd/Makefile.in	2003-08-15 16:45:47.000000000 +0200
@@ -239,7 +239,7 @@ scdaemon_SOURCES = \
 
 scdaemon_LDADD = ../jnlib/libjnlib.a ../common/libcommon.a \
 	  $(OPENSC_LIBS) $(LIBGCRYPT_LIBS) $(KSBA_LIBS) $(LIBASSUAN_LIBS) \
-	 -lgpg-error @INTLLIBS@ -ldl
+	 -lgpg-error @INTLLIBS@ -lopenct
 
 
 sc_investigate_SOURCES = \
@@ -253,7 +253,7 @@ sc_investigate_SOURCES = \
 
 sc_investigate_LDADD = \
 	../jnlib/libjnlib.a ../common/libcommon.a \
-	$(LIBGCRYPT_LIBS) @INTLLIBS@ -lgpg-error -ldl
+	$(LIBGCRYPT_LIBS) @INTLLIBS@ -lgpg-error -lopenct
 
 
 sc_copykeys_SOURCES = \
@@ -268,7 +268,7 @@ sc_copykeys_SOURCES = \
 sc_copykeys_LDADD = \
 	../jnlib/libjnlib.a ../common/libcommon.a \
 	../common/libsimple-pwquery.a \
-	$(LIBGCRYPT_LIBS) -lgpg-error @INTLLIBS@ -ldl
+	$(LIBGCRYPT_LIBS) -lgpg-error @INTLLIBS@ -lopenct
 
 subdir = scd
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4

--=-6Tuggp0j71IYGNFI3HmI--