implemented my own version of libpcsclite

Allows customizing of the default adress to which vpcd or libpcsclite
connect to.

My libpcsclite is currently not thread safe. It should not be installed
together with PCSC-Lite since both packages have conflicting files. Use
./configure --enable-libpcsclite to use my version. Use ./configure
--enable-vpcdhost=ADRESS to define connection mode and adress of vpicc.
This commit is contained in:
Frank Morgner
2013-07-18 14:03:47 +02:00
parent 291178d139
commit cdf68d62b3
17 changed files with 2270 additions and 54 deletions

View File

@@ -1,19 +1,24 @@
VPCD_LIB = $(LIB_PREFIX)vpcd.$(DYN_LIB_EXT)
lib_LTLIBRARIES = libvpcd.la
libvpcd_la_SOURCES = ifd-vpcd.c vpcd.c
libvpcd_la_LIBADD = $(PCSC_LIBS)
libvpcd_la_LDFLAGS = -no-undefined
libvpcd_la_CFLAGS = $(PCSC_CFLAGS)
lib_LTLIBRARIES = libvpcd.la
noinst_HEADERS = vpcd.h
EXTRA_DIST = reader.conf.in
do_subst = $(SED) -e 's,[@]TARGET[@],$(serialdropdir)/$(VPCD_LIB),g'
do_subst = $(SED) \
-e 's,[@]TARGET[@],$(serialdropdir)/$(VPCD_LIB),g' \
-e 's,[@]VPCDHOST[@],$(vpcdhost),g'
if BUILD_LIBPCSCLITE
else
install: install_libvpcd
install_libvpcd: libvpcd.la reader.conf.in
@@ -31,3 +36,5 @@ uninstall_libvpcd:
rm -f $(DESTDIR)$(serialdropdir)/$(VPCD_LIB).$(VERSION) \
$(DESTDIR)$(serialdropdir)/$(VPCD_LIB) \
$(DESTDIR)$(serialconfdir)/vpcd
endif

View File

@@ -1,3 +1,22 @@
/*
* Copyright (C) 2010-2013 Frank Morgner
*
* This file is part of virtualsmartcard.
*
* virtualsmartcard is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option)
* any later version.
*
* virtualsmartcard is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* virtualsmartcard. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ifd-vpcd.h"
#include "vpcd.h"
#include <debuglog.h>
#include <errno.h>
@@ -8,13 +27,12 @@
/* pcscd allows at most 16 readers. We will use 10.
* See PCSCLITE_MAX_READERS_CONTEXTS in pcsclite.h */
#define VICC_MAX_SLOTS \
(PCSCLITE_MAX_READERS_CONTEXTS > 6 ? \
PCSCLITE_MAX_READERS_CONTEXTS-6 : \
1)
const unsigned char VICC_MAX_SLOTS =
PCSCLITE_MAX_READERS_CONTEXTS > 6 ?
PCSCLITE_MAX_READERS_CONTEXTS-6 : 1;
static struct vicc_ctx *ctx[VICC_MAX_SLOTS];
static char *hostname = NULL;
const char *hostname = NULL;
static const char openport[] = "/dev/null";
RESPONSECODE

View File

@@ -0,0 +1,28 @@
/*
* Copyright (C) 2013 Frank Morgner
*
* This file is part of virtualsmartcard.
*
* virtualsmartcard is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option)
* any later version.
*
* virtualsmartcard is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* virtualsmartcard. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _IFD_VPCD_H_
#define _IFD_VPCD_H_
extern const unsigned char VICC_MAX_SLOTS;
extern const char *hostname;
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -1,4 +1,4 @@
FRIENDLYNAME "Virtual PCD"
DEVICENAME /dev/null:0x8C7B
DEVICENAME @VPCDHOST@:0x8C7B
LIBPATH @TARGET@
CHANNELID 0x8C7B

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2009 Frank Morgner
* Copyright (C) 2009-2013 Frank Morgner
*
* This file is part of virtualsmartcard.
*
@@ -18,6 +18,14 @@
*/
#include "vpcd.h"
#if HAVE_CONFIG_H
#include "config.h"
#endif
#if defined HAVE_DECL_MSG_NOSIGNAL && !HAVE_DECL_MSG_NOSIGNAL
#define MSG_NOSIGNAL
#endif
#ifdef _WIN32
#include <winsock2.h>
#include <ws2tcpip.h>
@@ -64,7 +72,7 @@ ssize_t sendall(int sock, const void *buffer, size_t size)
ssize_t r;
for (sent = 0; sent < size; sent += r) {
r = send(sock, (void *) (buffer+sent), size-sent, 0);
r = send(sock, (void *) (buffer+sent), size-sent, MSG_NOSIGNAL);
if (r < 0)
return r;
@@ -74,7 +82,7 @@ ssize_t sendall(int sock, const void *buffer, size_t size)
}
ssize_t recvall(int sock, void *buffer, size_t size) {
return recv(sock, buffer, size, MSG_WAITALL);
return recv(sock, buffer, size, MSG_WAITALL|MSG_NOSIGNAL);
}
static int opensock(unsigned short port)
@@ -90,6 +98,11 @@ static int opensock(unsigned short port)
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void *) &yes, sizeof yes) != 0)
return -1;
#if HAVE_DECL_SO_NOSIGPIPE
if (setsockopt(sock, SOL_SOCKET, SO_NOSIGPIPE, (void *) &yes, sizeof yes) != 0)
return -1;
#endif
memset(&server_sockaddr, 0, sizeof server_sockaddr);
server_sockaddr.sin_family = PF_INET;
server_sockaddr.sin_port = htons(port);
@@ -302,6 +315,9 @@ ssize_t vicc_transmit(struct vicc_ctx *ctx,
int vicc_present(struct vicc_ctx *ctx) {
unsigned char *atr = NULL;
if (!ctx)
return 0;
if (ctx->client_sock < 0) {
if (ctx->server_sock) {
/* server mode, try to accept a client */

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2009 Frank Morgner
* Copyright (C) 2009-2013 Frank Morgner
*
* This file is part of virtualsmartcard.
*