added vpcd-config
This commit is contained in:
@@ -124,6 +124,22 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
HAVE_QRENCODE=yes
|
||||||
|
PKG_CHECK_EXISTS([libqrencode],
|
||||||
|
[PKG_CHECK_MODULES([QRENCODE], [libqrencode])],
|
||||||
|
[AC_MSG_WARN([libqrencode not found by pkg-config])])
|
||||||
|
CPPFLAGS="$CPPFLAGS $QRENCODE_CFLAGS -I${srcdir}/src/opensc/src"
|
||||||
|
LIBS="$LDFLAGS $QRENCODE_LIBS"
|
||||||
|
AC_CHECK_HEADERS(qrencode.h, [], [ HAVE_QRENCODE=no ])
|
||||||
|
AC_MSG_CHECKING([for QRcode_encodeString])
|
||||||
|
AC_TRY_LINK_FUNC(QRcode_encodeString, [ AC_MSG_RESULT([yes]) ], [ HAVE_QRENCODE=no ])
|
||||||
|
AM_CONDITIONAL(HAVE_QRENCODE, test "${HAVE_QRENCODE}" = "yes")
|
||||||
|
AM_COND_IF(HAVE_QRENCODE, [AC_DEFINE(HAVE_QRENCODE, 1, [enable QR support])])
|
||||||
|
CPPFLAGS="$saved_CPPFLAGS"
|
||||||
|
LIBS="$saved_LIBS"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
PACKAGE_SUMMARY="Smart card emulator written in Python"
|
PACKAGE_SUMMARY="Smart card emulator written in Python"
|
||||||
AC_SUBST(PACKAGE_SUMMARY)
|
AC_SUBST(PACKAGE_SUMMARY)
|
||||||
|
|
||||||
@@ -210,6 +226,8 @@ PTHREAD_LIBS: ${PTHREAD_LIBS}
|
|||||||
PTHREAD_CFLAGS: ${PTHREAD_CFLAGS}
|
PTHREAD_CFLAGS: ${PTHREAD_CFLAGS}
|
||||||
PCSC_CFLAGS: ${PCSC_CFLAGS}
|
PCSC_CFLAGS: ${PCSC_CFLAGS}
|
||||||
PCSC_LIBS: ${PCSC_LIBS}
|
PCSC_LIBS: ${PCSC_LIBS}
|
||||||
|
QRENCODE_CFLAGS: ${QRENCODE_CFLAGS}
|
||||||
|
QRENCODE_LIBS: ${QRENCODE_LIBS}
|
||||||
BUNDLE_HOST: ${BUNDLE_HOST}
|
BUNDLE_HOST: ${BUNDLE_HOST}
|
||||||
LIB_PREFIX: ${LIB_PREFIX}
|
LIB_PREFIX: ${LIB_PREFIX}
|
||||||
DYN_LIB_EXT: ${DYN_LIB_EXT}
|
DYN_LIB_EXT: ${DYN_LIB_EXT}
|
||||||
@@ -230,5 +248,6 @@ AC_CONFIG_FILES([Makefile
|
|||||||
src/ifd-vpcd/Makefile
|
src/ifd-vpcd/Makefile
|
||||||
src/vpcd/Makefile
|
src/vpcd/Makefile
|
||||||
src/vpicc/Makefile
|
src/vpicc/Makefile
|
||||||
|
src/vpcd-config/Makefile
|
||||||
])
|
])
|
||||||
AC_OUTPUT
|
AC_OUTPUT
|
||||||
|
|||||||
@@ -224,6 +224,13 @@ options of |vpicc|.
|
|||||||
|
|
||||||
.. program-output:: vicc --help
|
.. program-output:: vicc --help
|
||||||
|
|
||||||
|
.. versionadded:: 0.7
|
||||||
|
We implemented :command:`vpcd-config` which tries to guess the local IP
|
||||||
|
address and outputs |vpcd|'s configuration. |vpicc|'s options should be
|
||||||
|
chosen accordingly (:option:`--hostname` and :option:`--port`)
|
||||||
|
:command:`vpcd-config` also prints a QR code for configuration of the
|
||||||
|
:ref:`remote-reader`.
|
||||||
|
|
||||||
On Windows you can start |vpicc| with :command:`python.exe src/vpicc/vicc.in`
|
On Windows you can start |vpicc| with :command:`python.exe src/vpicc/vicc.in`
|
||||||
or :command:`python.exe vicc`. Note emulating the German ID card
|
or :command:`python.exe vicc`. Note emulating the German ID card
|
||||||
(:option:`--type nPA`) when running |vpicc| on Windows is currently not
|
(:option:`--type nPA`) when running |vpicc| on Windows is currently not
|
||||||
|
|||||||
@@ -224,6 +224,13 @@ options of |vpicc|.
|
|||||||
|
|
||||||
.. program-output:: vicc --help
|
.. program-output:: vicc --help
|
||||||
|
|
||||||
|
.. versionadded:: 0.7
|
||||||
|
We implemented :command:`vpcd-config` which tries to guess the local IP
|
||||||
|
address and outputs |vpcd|'s configuration. |vpicc|'s options should be
|
||||||
|
chosen accordingly (:option:`--hostname` and :option:`--port`)
|
||||||
|
:command:`vpcd-config` also prints a QR code for configuration of the
|
||||||
|
:ref:`remote-reader`.
|
||||||
|
|
||||||
On Windows you can start |vpicc| with :command:`python.exe src/vpicc/vicc.in`
|
On Windows you can start |vpicc| with :command:`python.exe src/vpicc/vicc.in`
|
||||||
or :command:`python.exe vicc`. Note emulating the German ID card
|
or :command:`python.exe vicc`. Note emulating the German ID card
|
||||||
(:option:`--type nPA`) when running |vpicc| on Windows is currently not
|
(:option:`--type nPA`) when running |vpicc| on Windows is currently not
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
SUBDIRS = vpcd vpicc ifd-vpcd
|
SUBDIRS = vpcd vpicc ifd-vpcd vpcd-config
|
||||||
|
|
||||||
if BUILD_LIBPCSCLITE
|
if BUILD_LIBPCSCLITE
|
||||||
SUBDIRS += pcsclite-vpcd
|
SUBDIRS += pcsclite-vpcd
|
||||||
|
|||||||
@@ -28,8 +28,8 @@
|
|||||||
/* pcscd allows at most 16 readers. We will use 10.
|
/* pcscd allows at most 16 readers. We will use 10.
|
||||||
* See PCSCLITE_MAX_READERS_CONTEXTS in pcsclite.h */
|
* See PCSCLITE_MAX_READERS_CONTEXTS in pcsclite.h */
|
||||||
#define VICC_MAX_SLOTS \
|
#define VICC_MAX_SLOTS \
|
||||||
PCSCLITE_MAX_READERS_CONTEXTS > 6 ? \
|
(PCSCLITE_MAX_READERS_CONTEXTS > 6 ? \
|
||||||
PCSCLITE_MAX_READERS_CONTEXTS-6 : 1
|
PCSCLITE_MAX_READERS_CONTEXTS-6 : 1)
|
||||||
const unsigned char vicc_max_slots = VICC_MAX_SLOTS;
|
const unsigned char vicc_max_slots = VICC_MAX_SLOTS;
|
||||||
|
|
||||||
static struct vicc_ctx *ctx[VICC_MAX_SLOTS];
|
static struct vicc_ctx *ctx[VICC_MAX_SLOTS];
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern const unsigned char VICC_MAX_SLOTS;
|
extern const unsigned char vicc_max_slots;
|
||||||
extern const char *hostname;
|
extern const char *hostname;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|||||||
7
virtualsmartcard/src/vpcd-config/Makefile.am
Normal file
7
virtualsmartcard/src/vpcd-config/Makefile.am
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
EXTRA_DIST = qransi.c
|
||||||
|
|
||||||
|
bin_PROGRAMS = vpcd-config
|
||||||
|
|
||||||
|
vpcd_config_CFLAGS = $(PCSC_CFLAGS) $(QRENCODE_CFLAGS) -I$(srcdir)/../vpcd
|
||||||
|
vpcd_config_SOURCES = vpcd-config.c local-ip.c
|
||||||
|
vpcd_config_LDADD = $(QRENCODE_LIBS)
|
||||||
51
virtualsmartcard/src/vpcd-config/local-ip.c
Normal file
51
virtualsmartcard/src/vpcd-config/local-ip.c
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
/* Derived from http://www.binarytides.com/get-local-ip-c-linux/ by Silver Moon */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Find local ip used as source ip in ip packets.
|
||||||
|
* Use getsockname and a udp connection
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include<stdio.h> //printf
|
||||||
|
#include<string.h> //memset
|
||||||
|
#include<errno.h> //errno
|
||||||
|
#include<sys/socket.h> //socket
|
||||||
|
#include<netinet/in.h> //sockaddr_in
|
||||||
|
#include<arpa/inet.h> //getsockname
|
||||||
|
#include<unistd.h> //close
|
||||||
|
|
||||||
|
#define ERROR_STRING "Unable to guess local IP address"
|
||||||
|
|
||||||
|
const char *local_ip (void)
|
||||||
|
{
|
||||||
|
const char* google_dns_server = "8.8.8.8", *ip = NULL;
|
||||||
|
int dns_port = 53;
|
||||||
|
struct sockaddr_in name;
|
||||||
|
socklen_t namelen = sizeof(name);
|
||||||
|
struct sockaddr_in serv;
|
||||||
|
static char buffer[20];
|
||||||
|
int sock = socket ( AF_INET, SOCK_DGRAM, 0);
|
||||||
|
if(sock < 0) {
|
||||||
|
perror(ERROR_STRING);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
memset( &serv, 0, sizeof(serv) );
|
||||||
|
serv.sin_family = AF_INET;
|
||||||
|
serv.sin_addr.s_addr = inet_addr( google_dns_server );
|
||||||
|
serv.sin_port = htons( dns_port );
|
||||||
|
|
||||||
|
if (0 != connect( sock , (const struct sockaddr*) &serv , sizeof(serv) )
|
||||||
|
|| 0 != getsockname(sock, (struct sockaddr*) &name, &namelen)
|
||||||
|
|| !inet_ntop(AF_INET, &name.sin_addr, buffer, sizeof(buffer) ))
|
||||||
|
goto err;
|
||||||
|
|
||||||
|
ip = buffer;
|
||||||
|
|
||||||
|
err:
|
||||||
|
if (!ip)
|
||||||
|
printf("%s: %s\n" , ERROR_STRING, strerror(errno));
|
||||||
|
if (sock > 0)
|
||||||
|
close(sock);
|
||||||
|
|
||||||
|
return ip;
|
||||||
|
}
|
||||||
45
virtualsmartcard/src/vpcd-config/qransi.c
Normal file
45
virtualsmartcard/src/vpcd-config/qransi.c
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
/* Derived from https://github.com/bengl/qransi by Bryan English */
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <qrencode.h>
|
||||||
|
|
||||||
|
#define WHITE "\033[47m \033[0m"
|
||||||
|
#define BLACK "\033[40m \033[0m"
|
||||||
|
|
||||||
|
void pixels(char* color, int size)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
for(i=0; i<size; i++)
|
||||||
|
printf("%s", color);
|
||||||
|
}
|
||||||
|
|
||||||
|
void whiteRow(int padding, int width)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
for(i=0; i<padding; i++) {
|
||||||
|
pixels(WHITE, (width+(padding*2)));
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int qransi (const char *encodable)
|
||||||
|
{
|
||||||
|
int padding = 2;
|
||||||
|
QRecLevel level = QR_ECLEVEL_L;
|
||||||
|
int x, y, width;
|
||||||
|
unsigned char *data;
|
||||||
|
QRcode * code = QRcode_encodeString(encodable, 0, level, QR_MODE_8, 1);
|
||||||
|
width = code->width;
|
||||||
|
data = code->data;
|
||||||
|
whiteRow(padding, width);
|
||||||
|
for (y=0; y<width; y++) {
|
||||||
|
pixels(WHITE, padding);
|
||||||
|
for (x=0; x<width; x++, data++)
|
||||||
|
pixels(*data&1?BLACK:WHITE, 1);
|
||||||
|
pixels(WHITE, padding);
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
whiteRow(padding, width);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
82
virtualsmartcard/src/vpcd-config/vpcd-config.c
Normal file
82
virtualsmartcard/src/vpcd-config/vpcd-config.c
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2014 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/>.
|
||||||
|
*/
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "vpcd.h"
|
||||||
|
|
||||||
|
extern const char *local_ip (void);
|
||||||
|
|
||||||
|
/* pcscd allows at most 16 readers. We will use 10.
|
||||||
|
* See PCSCLITE_MAX_READERS_CONTEXTS in pcsclite.h */
|
||||||
|
#include <pcsclite.h>
|
||||||
|
#define VICC_MAX_SLOTS \
|
||||||
|
(PCSCLITE_MAX_READERS_CONTEXTS > 6 ? \
|
||||||
|
PCSCLITE_MAX_READERS_CONTEXTS-6 : 1)
|
||||||
|
|
||||||
|
#define ERROR_STRING "Unable to guess local IP address"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef HAVE_QRENCODE
|
||||||
|
|
||||||
|
#include "qransi.c"
|
||||||
|
|
||||||
|
void print_qrcode(const char *uri)
|
||||||
|
{
|
||||||
|
qransi (uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
void print_qrcode(const char *uri)
|
||||||
|
{
|
||||||
|
printf("https://api.qrserver.com/v1/create-qr-code/?data=%s\n", uri);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int main ( int argc , char *argv[] )
|
||||||
|
{
|
||||||
|
char slot;
|
||||||
|
char uri[60];
|
||||||
|
const char *ip = NULL;
|
||||||
|
int fail = 1, port;
|
||||||
|
|
||||||
|
ip = local_ip();
|
||||||
|
if (!ip)
|
||||||
|
goto err;
|
||||||
|
|
||||||
|
for (slot = 1; slot < VICC_MAX_SLOTS; slot++) {
|
||||||
|
port = VPCDPORT+slot-1;
|
||||||
|
printf("VPCD hostname: %s\n", ip);
|
||||||
|
printf("VPCD port: %d\n", port);
|
||||||
|
printf("On your NFC phone with the Remote Smart Card Reader app scan this code:\n", port);
|
||||||
|
sprintf(uri, "vpcd://%s:%d", ip, port);
|
||||||
|
print_qrcode(uri);
|
||||||
|
puts("");
|
||||||
|
}
|
||||||
|
|
||||||
|
fail = 0;
|
||||||
|
|
||||||
|
err:
|
||||||
|
return fail;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user