added ccid-test to evaluate the PACE features of ccid-emulator (untested)
git-svn-id: https://vsmartcard.svn.sourceforge.net/svnroot/vsmartcard@153 96b47cad-a561-4643-ad3b-153ac7d7599c
This commit is contained in:
@@ -90,6 +90,34 @@ AC_SUBST(OPENSSL_LIBS)
|
|||||||
AM_CONDITIONAL(WITH_PACE, test "${enable_pace}" != "no")
|
AM_CONDITIONAL(WITH_PACE, test "${enable_pace}" != "no")
|
||||||
AM_COND_IF(WITH_PACE, [AC_DEFINE(WITH_PACE, 1, [enable PACE support])])
|
AM_COND_IF(WITH_PACE, [AC_DEFINE(WITH_PACE, 1, [enable PACE support])])
|
||||||
|
|
||||||
|
# --enable-ccid-test
|
||||||
|
AC_ARG_ENABLE(ccid-test,
|
||||||
|
AS_HELP_STRING([--enable-ccid-test], [Enable test of PACE smartcard reader]),
|
||||||
|
[enable_ccid_test="${enableval}"], [enable_ccid_test=no])
|
||||||
|
if test "x$enable_ccid_test" != xno ; then
|
||||||
|
PKG_CHECK_EXISTS([libpcsclite > 1.4.102],
|
||||||
|
[PKG_CHECK_MODULES([PCSC], [libpcsclite > 1.4.102])],
|
||||||
|
[AC_MSG_WARN([libpcsclite > 1.4.102 not found by pkg-config])])
|
||||||
|
|
||||||
|
saved_CPPFLAGS="$CPPFLAGS"
|
||||||
|
saved_LIBS="$LIBS"
|
||||||
|
CPPFLAGS="$CPPFLAGS $PCSC_CFLAGS"
|
||||||
|
LIBS="$LDFLAGS $PCSC_LIBS"
|
||||||
|
|
||||||
|
AC_CHECK_HEADERS(reader.h, [], [ AC_MSG_ERROR([reader.h not found, install OpenPACE or use ./configure PCSC_CFLAGS=...]) ])
|
||||||
|
AC_CHECK_DECL(FEATURE_EXECUTE_PACE, [],
|
||||||
|
[AC_MSG_ERROR([libpcsclite > 1.4.102 patched with pcsclite_trunk.patch not found, use ./configure PCSC_LIBS=...]) ],
|
||||||
|
[#include <reader.h>])
|
||||||
|
AC_MSG_CHECKING([for SCardEstablishContext])
|
||||||
|
AC_TRY_LINK_FUNC(SCardEstablishContext, [ AC_MSG_RESULT([yes]) ],
|
||||||
|
[ AC_MSG_ERROR([libpcsclite > 1.4.102 not found, use ./configure PCSC_LIBS=...]) ])
|
||||||
|
|
||||||
|
CPPFLAGS="$saved_CPPFLAGS"
|
||||||
|
LIBS="$saved_LIBS"
|
||||||
|
|
||||||
|
enable_ccid_test=yes
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
# Checks for header files.
|
# Checks for header files.
|
||||||
AC_CHECK_HEADERS([arpa/inet.h fcntl.h memory.h stdint.h stdlib.h string.h sys/ioctl.h unistd.h])
|
AC_CHECK_HEADERS([arpa/inet.h fcntl.h memory.h stdint.h stdlib.h string.h sys/ioctl.h unistd.h])
|
||||||
@@ -129,9 +157,12 @@ OPENSC_CFLAGS: ${OPENSC_CFLAGS}
|
|||||||
OPENSC_LIBS: ${OPENSC_LIBS}
|
OPENSC_LIBS: ${OPENSC_LIBS}
|
||||||
OPENSSL_CFLAGS: ${OPENSSL_CFLAGS}
|
OPENSSL_CFLAGS: ${OPENSSL_CFLAGS}
|
||||||
OPENSSL_LIBS: ${OPENSSL_LIBS}
|
OPENSSL_LIBS: ${OPENSSL_LIBS}
|
||||||
|
PCSC_CFLAGS: ${PCSC_CFLAGS}
|
||||||
|
PCSC_LIBS: ${PCSC_LIBS}
|
||||||
|
|
||||||
emulator support: ${enable_ccid}
|
emulator support: ${enable_ccid}
|
||||||
pace support: ${enable_pace}
|
PACE support: ${enable_pace}
|
||||||
|
PACE test for reader ${enable_ccid_test}
|
||||||
|
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
|||||||
@@ -4,13 +4,17 @@ ccid_emulator_SOURCES = ccid.c usbstring.c usb.c binutil.c scutil.c
|
|||||||
ccid_emulator_LDADD = $(OPENSC_LIBS) $(PTHREAD_LIBS)
|
ccid_emulator_LDADD = $(OPENSC_LIBS) $(PTHREAD_LIBS)
|
||||||
ccid_emulator_CFLAGS = $(OPENSC_CFLAGS) $(PTHREAD_CFLAGS)
|
ccid_emulator_CFLAGS = $(OPENSC_CFLAGS) $(PTHREAD_CFLAGS)
|
||||||
|
|
||||||
|
ccid_test_SOURCES = ccid-test.c
|
||||||
|
ccid_test_LDADD = $(PCSC_LIBS)
|
||||||
|
ccid_test_CFLAGS = $(PCSC_CFLAGS)
|
||||||
|
|
||||||
pace_tool_SOURCES = sm.c pace-tool.c binutil.c scutil.c pace.c pace_lib.c
|
pace_tool_SOURCES = sm.c pace-tool.c binutil.c scutil.c pace.c pace_lib.c
|
||||||
pace_tool_LDADD = $(OPENSC_LIBS) $(OPENSSL_LIBS)
|
pace_tool_LDADD = $(OPENSC_LIBS) $(OPENSSL_LIBS)
|
||||||
pace_tool_CFLAGS = $(OPENSC_CFLAGS) $(OPENSSL_CFLAGS)
|
pace_tool_CFLAGS = $(OPENSC_CFLAGS) $(OPENSSL_CFLAGS)
|
||||||
|
|
||||||
bin_PROGRAMS =
|
bin_PROGRAMS =
|
||||||
if WITH_CCID
|
if WITH_CCID
|
||||||
bin_PROGRAMS += ccid-emulator
|
bin_PROGRAMS += ccid-emulator ccid-test
|
||||||
endif
|
endif
|
||||||
if WITH_PACE
|
if WITH_PACE
|
||||||
bin_PROGRAMS += pace-tool
|
bin_PROGRAMS += pace-tool
|
||||||
|
|||||||
121
ccid/src/ccid-test.c
Normal file
121
ccid/src/ccid-test.c
Normal file
@@ -0,0 +1,121 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2010 Frank Morgner
|
||||||
|
*
|
||||||
|
* This file is part of ifdnfc.
|
||||||
|
*
|
||||||
|
* ifdnfc 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.
|
||||||
|
*
|
||||||
|
* ifdnfc 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
|
||||||
|
* ifdnfc. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#include <pcsclite.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <winscard.h>
|
||||||
|
#include <reader.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
LONG rv;
|
||||||
|
SCARDCONTEXT hContext;
|
||||||
|
SCARDHANDLE hCard;
|
||||||
|
LPSTR mszReaders = NULL;
|
||||||
|
int num;
|
||||||
|
char *reader;
|
||||||
|
BYTE pbSendBufferCapabilities [] = {
|
||||||
|
0x01, /* idxFunction = GetReadersPACECapabilities */
|
||||||
|
0x00, /* lengthInputData */
|
||||||
|
0x00, /* lengthInputData */
|
||||||
|
};
|
||||||
|
BYTE pbSendBufferEstablish [] = {
|
||||||
|
0x02, /* idxFunction = EstabishPACEChannel */
|
||||||
|
0x00, /* lengthInputData */
|
||||||
|
0x04, /* lengthInputData */
|
||||||
|
0x03, /* PACE with PIN */
|
||||||
|
0x00, /* length CHAT */
|
||||||
|
0x00, /* length certificate description */
|
||||||
|
0x00, /* length certificate description */
|
||||||
|
};
|
||||||
|
BYTE pbRecvBuffer[1024];
|
||||||
|
DWORD dwActiveProtocol, dwRecvLength, dwReaders;
|
||||||
|
|
||||||
|
if (argc > 1) {
|
||||||
|
if (argc > 2 || sscanf(argv[1], "%d", &num) != 1) {
|
||||||
|
fprintf(stderr, "Usage: %s [reader_num]\n", argv[0]);
|
||||||
|
exit(2);
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
num = 0;
|
||||||
|
|
||||||
|
rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext);
|
||||||
|
if (rv < 0)
|
||||||
|
goto err;
|
||||||
|
|
||||||
|
dwReaders = SCARD_AUTOALLOCATE;
|
||||||
|
rv = SCardListReaders(hContext, NULL, (LPSTR)&mszReaders, &dwReaders);
|
||||||
|
if (rv < 0)
|
||||||
|
goto err;
|
||||||
|
|
||||||
|
int l, i;
|
||||||
|
for (reader = mszReaders, i = 0;
|
||||||
|
dwReaders > 0;
|
||||||
|
l = strlen(reader) + 1, dwReaders -= l, reader += l, i++) {
|
||||||
|
|
||||||
|
if (i == num)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (dwReaders <= 0) {
|
||||||
|
fprintf(stderr, "Could not find reader number %d\n", num);
|
||||||
|
rv = SCARD_E_UNKNOWN_READER;
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
rv = SCardConnect(hContext, reader, SCARD_SHARE_DIRECT, 0, &hCard,
|
||||||
|
&dwActiveProtocol);
|
||||||
|
if (rv < 0)
|
||||||
|
goto err;
|
||||||
|
|
||||||
|
|
||||||
|
rv = SCardControl(hCard, FEATURE_EXECUTE_PACE, pbSendBufferCapabilities,
|
||||||
|
sizeof(pbSendBufferCapabilities), pbRecvBuffer,
|
||||||
|
sizeof(pbRecvBuffer), &dwRecvLength);
|
||||||
|
if (rv < 0)
|
||||||
|
goto err;
|
||||||
|
|
||||||
|
rv = SCardControl(hCard, FEATURE_EXECUTE_PACE, pbSendBufferEstablish,
|
||||||
|
sizeof(pbSendBufferEstablish), pbRecvBuffer,
|
||||||
|
sizeof(pbRecvBuffer), &dwRecvLength);
|
||||||
|
if (rv < 0)
|
||||||
|
goto err;
|
||||||
|
|
||||||
|
|
||||||
|
rv = SCardDisconnect(hCard, SCARD_LEAVE_CARD);
|
||||||
|
if (rv < 0)
|
||||||
|
goto err;
|
||||||
|
|
||||||
|
rv = SCardFreeMemory(hContext, mszReaders);
|
||||||
|
if (rv < 0)
|
||||||
|
goto err;
|
||||||
|
|
||||||
|
|
||||||
|
exit(0);
|
||||||
|
|
||||||
|
err:
|
||||||
|
puts(pcsc_stringify_error(rv));
|
||||||
|
if (mszReaders)
|
||||||
|
SCardFreeMemory(hContext, mszReaders);
|
||||||
|
|
||||||
|
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user