aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@osmocom.org>2020-03-22 11:05:44 +0100
committerHarald Welte <laforge@osmocom.org>2020-06-08 21:16:54 +0200
commitb282de726e9d6f392dbc6c2423eacb0e1dfd130c (patch)
tree06e6fa0a52be2f2d78c4aa50ed9d49a871e5d584
parentef5b9b64342510278f795fedb9ec026f212587a8 (diff)
WIP: PIN validation
-rw-r--r--utils/osmo-sim-test.c27
1 files changed, 20 insertions, 7 deletions
diff --git a/utils/osmo-sim-test.c b/utils/osmo-sim-test.c
index ae55b83e..201d22b1 100644
--- a/utils/osmo-sim-test.c
+++ b/utils/osmo-sim-test.c
@@ -41,6 +41,7 @@
static uint8_t g_class = 0x00; /* UICC/USIM */
static const char *g_output_dir;
+static const char *g_pin;
/* 11.1.1 */
static struct msgb *_select_file(struct osim_chan_hdl *st, uint8_t p1, uint8_t p2,
@@ -77,15 +78,14 @@ static struct msgb *select_file(struct osim_chan_hdl *st, uint16_t fid)
return _select_file(st, 0x00, p2, (uint8_t *)&cfid, 2);
}
-#if 0
/* 11.1.9 */
-static int verify_pin(struct osim_chan_hdl *st, uint8_t pin_nr, char *pin)
+static struct msgb *verify_pin(struct osim_chan_hdl *st, uint8_t pin_nr, const char *pin)
{
struct msgb *msg;
char *pindst;
if (strlen(pin) > 8)
- return -EINVAL;
+ return NULL;
msg = osim_new_apdumsg(g_class, 0x20, 0x00, pin_nr, 8, 0);
pindst = (char *) msgb_put(msg, 8);
@@ -93,9 +93,10 @@ static int verify_pin(struct osim_chan_hdl *st, uint8_t pin_nr, char *pin)
/* Do not copy the terminating \0 */
memcpy(pindst, pin, strlen(pin));
- return osim_transceive_apdu(st, msg);
+ osim_transceive_apdu(st, msg);
+
+ return msg;
}
-#endif
/* 11.1.5 */
static struct msgb *read_record_nr(struct osim_chan_hdl *st, uint8_t rec_nr, uint16_t rec_size)
@@ -464,6 +465,7 @@ static void print_help(void)
" -h --help This message\n"
" -n --reader-num NR Open reader number NR\n"
" -o --output-dir DIR To-be-created output directory for filesystem dump\n"
+ " -p --pin PIN Authenticate using the given PIN\n"
);
}
@@ -477,10 +479,11 @@ static void handle_options(int argc, char **argv)
{ "help", 0, 0, 'h' },
{ "reader-num", 1, 0, 'n' },
{ "output-dir", 1, 0, 'o' },
+ { "pin", 1, 0, 'p' },
{0,0,0,0}
};
- c = getopt_long(argc, argv, "hn:o:",
+ c = getopt_long(argc, argv, "hn:o:p:",
long_options, &option_index);
if (c == -1)
break;
@@ -496,6 +499,9 @@ static void handle_options(int argc, char **argv)
case 'o':
g_output_dir = optarg;
break;
+ case 'p':
+ g_pin = optarg;
+ break;
default:
exit(2);
break;
@@ -645,7 +651,14 @@ int main(int argc, char **argv)
if (!chan)
exit(3);
- //verify_pin(chan, 1, "1653");
+ if (g_pin) {
+ struct msgb *msg;
+ msg = verify_pin(chan, 1, g_pin);
+ if (!msg /*|| FIXME*/) {
+ fprintf(stderr, "Error authenticating PIN: %s\n");
+ exit(6);
+ }
+ }
rc = osim_uicc_scan_apps(chan);
if (rc >= 0) {