- added preliminary EMV support
- made a few bug fixes relating to select_file operation git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@107 c6295689-39f2-0310-b995-f0e70906c6a9
This commit is contained in:
parent
2b99f2df14
commit
695ad01b28
|
@ -2,8 +2,8 @@
|
|||
|
||||
lib_LTLIBRARIES = libopensc.la
|
||||
libopensc_la_SOURCES = sc-asn1.c sc-base64.c sc-defaults.c \
|
||||
sc-sec.c sc-log.c sc.c sc-card.c sc-iso7816.c\
|
||||
sc-pkcs15.c sc-pkcs15-cert.c \
|
||||
sc-sec.c sc-log.c sc.c sc-card.c sc-iso7816.c \
|
||||
sc-emv.c sc-pkcs15.c sc-pkcs15-cert.c \
|
||||
sc-pkcs15-pin.c sc-pkcs15-prkey.c \
|
||||
sc-pkcs15-defaults.c sc-pkcs15-sec.c \
|
||||
sc-card-setec.c sc-card-multiflex.c \
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* sc-internal.h: Internal definitions for libopensc
|
||||
*
|
||||
* Copyright (C) 2001 Juha Yrjölä <juha.yrjola@iki.fi>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef _LIBOPENSC_H
|
||||
#define _LIBOPENSC_H
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include "opensc.h"
|
||||
|
||||
#define SC_FILE_MAGIC 0x14426950
|
||||
#define SC_CARD_MAGIC 0x27182818
|
||||
|
||||
/* Internal use only */
|
||||
inline int sc_card_valid(const struct sc_card *card);
|
||||
inline int sc_file_valid(const struct sc_file *file);
|
||||
|
||||
void sc_print_binary(FILE *f, const u8 *buf, int len);
|
||||
int sc_hex_to_bin(const char *in, u8 *out, size_t *outlen);
|
||||
int sc_sw_to_errorcode(struct sc_card *card, int sw1, int sw2);
|
||||
void sc_format_path(const char *path_in, struct sc_path *path_out);
|
||||
|
||||
#endif
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* opensc.h: OpenSC library header file
|
||||
*
|
||||
* Copyright (C) 2001 Juha Yrjölä <juha.yrjola@iki.fi>
|
||||
|
@ -321,6 +321,7 @@ const char *sc_strerror(int error);
|
|||
extern const char *sc_version;
|
||||
|
||||
extern const struct sc_card_driver *sc_get_iso7816_driver(void);
|
||||
extern const struct sc_card_driver *sc_get_emv_driver(void);
|
||||
extern const struct sc_card_driver *sc_get_setec_driver(void);
|
||||
extern const struct sc_card_driver *sc_get_mflex_driver(void);
|
||||
extern const struct sc_card_driver *sc_get_default_driver(void);
|
||||
|
|
|
@ -0,0 +1,90 @@
|
|||
/*
|
||||
* sc-emv.c: Functions specified by the EMV standard
|
||||
*
|
||||
* Copyright (C) 2001 Juha Yrjölä <juha.yrjola@iki.fi>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "sc-internal.h"
|
||||
|
||||
static struct sc_card_operations emv_ops;
|
||||
static const struct sc_card_driver emv_drv = {
|
||||
NULL,
|
||||
"EMV compatible cards",
|
||||
&emv_ops
|
||||
};
|
||||
|
||||
static int emv_finish(struct sc_card *card)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int emv_match_card(struct sc_card *card)
|
||||
{
|
||||
int i, match = -1;
|
||||
const char *str = "BWAVANT";
|
||||
|
||||
for (i = 0; i < card->atr_len - strlen(str); i++)
|
||||
if (memcmp(card->atr + i, str, strlen(str)) == 0) {
|
||||
match = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
if (match == 1)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int emv_init(struct sc_card *card)
|
||||
{
|
||||
card->ops_data = NULL;
|
||||
card->cla = 0x00;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int emv_select_file(struct sc_card *card, const struct sc_path *path,
|
||||
struct sc_file *file)
|
||||
{
|
||||
int r;
|
||||
const struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
|
||||
const struct sc_card_operations *ops = iso_drv->ops;
|
||||
|
||||
r = ops->select_file(card, path, file);
|
||||
if (file != NULL && path->len == 2 && memcmp(path->value, "\x3F\x00", 2) == 0)
|
||||
file->type = SC_FILE_TYPE_DF;
|
||||
return r;
|
||||
}
|
||||
|
||||
static const struct sc_card_driver * sc_get_driver(void)
|
||||
{
|
||||
const struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
|
||||
|
||||
emv_ops = *iso_drv->ops;
|
||||
emv_ops.match_card = emv_match_card;
|
||||
emv_ops.init = emv_init;
|
||||
emv_ops.finish = emv_finish;
|
||||
emv_ops.select_file = emv_select_file;
|
||||
|
||||
return &emv_drv;
|
||||
}
|
||||
|
||||
#if 1
|
||||
const struct sc_card_driver * sc_get_emv_driver(void)
|
||||
{
|
||||
return sc_get_driver();
|
||||
}
|
||||
#endif
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* sc-internal.h: Internal definitions for libopensc
|
||||
*
|
||||
* Copyright (C) 2001 Juha Yrjölä <juha.yrjola@iki.fi>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef _LIBOPENSC_H
|
||||
#define _LIBOPENSC_H
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include "opensc.h"
|
||||
|
||||
#define SC_FILE_MAGIC 0x14426950
|
||||
#define SC_CARD_MAGIC 0x27182818
|
||||
|
||||
/* Internal use only */
|
||||
inline int sc_card_valid(const struct sc_card *card);
|
||||
inline int sc_file_valid(const struct sc_file *file);
|
||||
|
||||
void sc_print_binary(FILE *f, const u8 *buf, int len);
|
||||
int sc_hex_to_bin(const char *in, u8 *out, size_t *outlen);
|
||||
int sc_sw_to_errorcode(struct sc_card *card, int sw1, int sw2);
|
||||
void sc_format_path(const char *path_in, struct sc_path *path_out);
|
||||
|
||||
#endif
|
|
@ -199,6 +199,9 @@ int sc_establish_context(struct sc_context **ctx_out)
|
|||
#if 1
|
||||
ctx->card_drivers[i++] = sc_get_iso7816_driver();
|
||||
#endif
|
||||
#if 1
|
||||
ctx->card_drivers[i++] = sc_get_emv_driver();
|
||||
#endif
|
||||
#if 1
|
||||
/* this should be last in line */
|
||||
ctx->card_drivers[i++] = sc_get_default_driver();
|
||||
|
|
|
@ -401,13 +401,13 @@ int enum_dir(struct sc_path path, int depth)
|
|||
printf("] ");
|
||||
}
|
||||
switch (file.type) {
|
||||
case 0:
|
||||
case SC_FILE_TYPE_WORKING_EF:
|
||||
tmps = "wEF";
|
||||
break;
|
||||
case 1:
|
||||
case SC_FILE_TYPE_INTERNAL_EF:
|
||||
tmps = "iEF";
|
||||
break;
|
||||
case 7:
|
||||
case SC_FILE_TYPE_DF:
|
||||
tmps = "DF";
|
||||
break;
|
||||
default:
|
||||
|
@ -415,14 +415,9 @@ int enum_dir(struct sc_path path, int depth)
|
|||
break;
|
||||
}
|
||||
printf("type: %-3s ", tmps);
|
||||
if (file.type != 7)
|
||||
if (file.type != SC_FILE_TYPE_DF)
|
||||
printf("ef structure: %d ", file.ef_structure);
|
||||
printf("size: %d ", file.size);
|
||||
if (file.type == 0 && 0) {
|
||||
r = sc_read_binary(card, 0, buf, file.size);
|
||||
if (r > 0)
|
||||
hex_dump(buf, r);
|
||||
}
|
||||
if (file.sec_attr_len) {
|
||||
printf("sec: ");
|
||||
/* Octets are as follows:
|
||||
|
@ -434,10 +429,15 @@ int enum_dir(struct sc_path path, int depth)
|
|||
hex_dump(file.sec_attr, file.sec_attr_len);
|
||||
}
|
||||
printf("\n");
|
||||
if (file.type != SC_FILE_TYPE_DF && 1) {
|
||||
r = sc_read_binary(card, 0, buf, file.size);
|
||||
if (r > 0)
|
||||
hex_dump_asc(buf, r);
|
||||
}
|
||||
} else {
|
||||
printf("\n");
|
||||
}
|
||||
if (!sc_file_valid(&file) || file.type == 7) {
|
||||
if (!sc_file_valid(&file) || file.type == SC_FILE_TYPE_DF) {
|
||||
int i;
|
||||
|
||||
r = sc_list_files(card, files, sizeof(files));
|
||||
|
|
Loading…
Reference in New Issue