1
0
mirror of git://git.gnupg.org/gnupg.git synced 2025-01-22 14:57:02 +01:00

* gpgv.c (agent_scd_getattr): Stub.

* misc.c (get_signature_count): New.  Get the signature count from a
smartcard. (pct_expando): Call it here so the %c expando becomes the
number of signatures issued.  This allows for notations or the like with
an automatic signature count.

* ccid-driver.c (usb_get_string_simple): Replacement function to work with
older libusb.
This commit is contained in:
David Shaw 2004-09-15 18:41:36 +00:00
parent e991fb59d1
commit a46e83b8e3
4 changed files with 98 additions and 0 deletions

View File

@ -1,3 +1,16 @@
2004-09-15 David Shaw <dshaw@jabberwocky.com>
* gpgv.c (agent_scd_getattr): Stub.
* misc.c (get_signature_count): New. Get the signature count from
a smartcard.
(pct_expando): Call it here so the %c expando becomes the number
of signatures issued. This allows for notations or the like with
an automatic signature count.
* ccid-driver.c (usb_get_string_simple): Replacement function to
work with older libusb.
2004-09-15 Werner Koch <wk@g10code.com>
* g10.c [HAVE_LIBUSB]: New option --debug-ccid-driver.

View File

@ -214,7 +214,63 @@ static int bulk_out (ccid_driver_t handle, unsigned char *msg, size_t msglen);
static int bulk_in (ccid_driver_t handle, unsigned char *buffer, size_t length,
size_t *nread, int expected_type, int seqno);
#ifndef HAVE_USB_GET_STRING_SIMPLE
/* This function adapted from the libusb 0.1.8 sources. It's here so
that systems with an older libusb can still use smartcards. */
static int usb_get_string_simple(usb_dev_handle *dev, int indx, char *buf,
size_t buflen)
{
char tbuf[256];
int ret, langid, si, di;
/*
* Asking for the zero'th index is special - it returns a string
* descriptor that contains all the language IDs supported by the
* device. Typically there aren't many - often only one. The
* language IDs are 16 bit numbers, and they start at the third byte
* in the descriptor. See USB 2.0 specification, section 9.6.7, for
* more information on this. */
ret=usb_control_msg(dev, USB_ENDPOINT_IN, USB_REQ_GET_DESCRIPTOR,
(USB_DT_STRING << 8), 0, tbuf, sizeof(tbuf), 1000);
if (ret < 0)
return ret;
if (ret < 4)
return -EIO;
langid = tbuf[2] | (tbuf[3] << 8);
ret=usb_control_msg(dev, USB_ENDPOINT_IN, USB_REQ_GET_DESCRIPTOR,
(USB_DT_STRING << 8)+indx,langid,tbuf,sizeof(tbuf),1000);
if (ret < 0)
return ret;
if (tbuf[1] != USB_DT_STRING)
return -EIO;
if (tbuf[0] > ret)
return -EFBIG;
for (di = 0, si = 2; si < tbuf[0]; si += 2) {
if (di >= (buflen - 1))
break;
if (tbuf[si + 1]) /* high byte */
buf[di++] = '?';
else
buf[di++] = tbuf[si];
}
buf[di] = 0;
return di;
}
#endif /* !HAVE_USB_GET_STRING_SIMPLE */
/* Convert a little endian stored 4 byte value into an unsigned
integer. */

View File

@ -45,6 +45,7 @@
#include "i18n.h"
#include "status.h"
#include "g10defs.h"
#include "cardglue.h"
enum cmd_and_opt_values { aNull = 0,
@ -339,6 +340,8 @@ void show_photos(const struct user_attribute *attrs,int count,PKT_public_key *pk
int parse_image_header(const struct user_attribute *attr,byte *type,u32 *len) {return 0;}
char *image_type_to_string(byte type,int string) {return NULL;}
int agent_scd_getattr (const char *name, struct agent_card_info_s *info) {return 0;}
/* Stubs to void linking to ../cipher/cipher.c */
int string_to_cipher_algo( const char *string ) { return 0; }
const char *cipher_algo_to_string( int algo ) { return "?";}

View File

@ -39,6 +39,7 @@
#include "photoid.h"
#include "options.h"
#include "i18n.h"
#include "cardglue.h"
#if defined(__linux__) && defined(__alpha__) && __GLIBC__ < 2
static int
@ -287,6 +288,22 @@ idea_cipher_warn(int show)
}
#endif
static unsigned long get_signature_count(PKT_secret_key *sk)
{
#ifdef ENABLE_CARD_SUPPORT
if(sk && sk->is_protected && sk->protect.s2k.mode==1002)
{
struct agent_card_info_s info;
if(agent_scd_getattr("SIG-COUNTER",&info)==0)
return info.sig_counter;
}
#endif
/* How to do this without a card? */
return 0;
}
/* Expand %-strings. Returns a string which must be m_freed. Returns
NULL if the string cannot be expanded (too large). */
char *
@ -366,6 +383,15 @@ pct_expando(const char *string,struct expando_args *args)
}
break;
case 'c': /* signature count from card, if any. */
if(idx+10<maxlen)
{
sprintf(&ret[idx],"%lu",get_signature_count(args->sk));
idx+=strlen(&ret[idx]);
done=1;
}
break;
case 'p': /* primary pk fingerprint of a sk */
case 'f': /* pk fingerprint */
case 'g': /* sk fingerprint */