added vpcd-config

This commit is contained in:
Frank Morgner
2014-09-07 03:19:32 +02:00
parent 2f8ff4a29b
commit 9f746a70c8
10 changed files with 222 additions and 4 deletions

View File

@@ -1,4 +1,4 @@
SUBDIRS = vpcd vpicc ifd-vpcd
SUBDIRS = vpcd vpicc ifd-vpcd vpcd-config
if BUILD_LIBPCSCLITE
SUBDIRS += pcsclite-vpcd

View File

@@ -28,8 +28,8 @@
/* 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
(PCSCLITE_MAX_READERS_CONTEXTS > 6 ? \
PCSCLITE_MAX_READERS_CONTEXTS-6 : 1)
const unsigned char vicc_max_slots = VICC_MAX_SLOTS;
static struct vicc_ctx *ctx[VICC_MAX_SLOTS];

View File

@@ -23,7 +23,7 @@
extern "C" {
#endif
extern const unsigned char VICC_MAX_SLOTS;
extern const unsigned char vicc_max_slots;
extern const char *hostname;
#ifdef __cplusplus

View 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)

View 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;
}

View 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;
}

View 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;
}