changeset 31:cca7d0528f89

fc-simtool sws-auth-adm1 implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 17 Mar 2021 00:42:47 +0000
parents 25530c262137
children d0be3802410a
files simtool/Makefile simtool/chvfunc.c simtool/cmdtab.c simtool/sws.c
diffstat 4 files changed, 53 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/simtool/Makefile	Wed Mar 17 00:19:18 2021 +0000
+++ b/simtool/Makefile	Wed Mar 17 00:42:47 2021 +0000
@@ -2,7 +2,7 @@
 CFLAGS=	-O2
 CPPFLAGS=-I../libcommon
 PROG=	fc-simtool
-OBJS=	a38.o bfsearch.o chv.o chvext.o cmdtab.o curfile.o dumpdir.o \
+OBJS=	a38.o bfsearch.o chv.o chvext.o chvfunc.o cmdtab.o curfile.o dumpdir.o \
 	erasefile.o fplmn.o getresp.o grcard1.o grcard2.o hlread.o \
 	inval_rehab.o lndwrite.o main.o miscadm.o opldump.o oplprog.o \
 	pbcommon.o pbdump.o pberase.o pbrestore.o pbupd_imm.o pbupd_immhex.o \
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/simtool/chvfunc.c	Wed Mar 17 00:42:47 2021 +0000
@@ -0,0 +1,35 @@
+/*
+ * This module implements a functional interface to CHV commands,
+ * intended for high-level wrappers like sws-*.
+ */
+
+#include <sys/types.h>
+#include <stdio.h>
+#include "simresp.h"
+
+verify_chv_func(p2, pin)
+	unsigned p2;
+	char *pin;
+{
+	u_char cmd[13];
+	int rc;
+
+	/* VERIFY CHV command APDU */
+	cmd[0] = 0xA0;
+	cmd[1] = 0x20;
+	cmd[2] = 0x00;
+	cmd[3] = p2;
+	cmd[4] = 8;
+	rc = encode_pin_entry(pin, cmd + 5);
+	if (rc < 0)
+		return(rc);
+	rc = apdu_exchange(cmd, 13);
+	if (rc < 0)
+		return(rc);
+	if (sim_resp_sw != 0x9000) {
+		fprintf(stderr, "bad SW response to VERIFY CHV: %04X\n",
+			sim_resp_sw);
+		return(-1);
+	}
+	return(0);
+}
--- a/simtool/cmdtab.c	Wed Mar 17 00:19:18 2021 +0000
+++ b/simtool/cmdtab.c	Wed Mar 17 00:42:47 2021 +0000
@@ -89,6 +89,7 @@
 extern int cmd_smsp_set_tag();
 extern int cmd_spn();
 extern int cmd_sst();
+extern int cmd_sws_auth_adm1();
 extern int cmd_sws_lookup();
 extern int cmd_telecom_sum();
 extern int cmd_terminal_profile();
@@ -217,6 +218,7 @@
 	{"smsp-set-tag", 3, 7, 0, cmd_smsp_set_tag},
 	{"spn", 0, 0, 1, cmd_spn},
 	{"sst", 0, 0, 1, cmd_sst},
+	{"sws-auth-adm1", 0, 0, 0, cmd_sws_auth_adm1},
 	{"sws-lookup", 1, 18, 1, cmd_sws_lookup},
 	{"telecom-sum", 0, 0, 0, cmd_telecom_sum},
 	{"terminal-profile", 1, 1, 0, cmd_terminal_profile},
--- a/simtool/sws.c	Wed Mar 17 00:19:18 2021 +0000
+++ b/simtool/sws.c	Wed Mar 17 00:42:47 2021 +0000
@@ -47,3 +47,18 @@
 	}
 	return(0);
 }
+
+cmd_sws_auth_adm1()
+{
+	int rc;
+	struct dbread_state dbs;
+	char *pin;
+
+	rc = lookup_sws_card(&dbs);
+	if (rc < 0)
+		return(rc);
+	pin = dbread_find_key_req(&dbs, "ADM1");
+	if (!pin)
+		return(-1);
+	return verify_chv_func(0x0A, pin);
+}