cleaned up command line options of pace-tool and made it independant from ccid

git-svn-id: https://vsmartcard.svn.sourceforge.net/svnroot/vsmartcard@89 96b47cad-a561-4643-ad3b-153ac7d7599c
This commit is contained in:
frankmorgner
2010-05-04 20:03:54 +00:00
parent fcfbca19d7
commit 170ec3c703
8 changed files with 240 additions and 231 deletions

View File

@@ -16,20 +16,23 @@
* You should have received a copy of the GNU General Public License along with
* ccid. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ccid.h"
#include "util.h"
#include "pace.h"
#include <stdlib.h>
#include <string.h>
static int verbose = 0;
static int doinfo = 0;
static u8 dopacetest = 0;
static u8 pin_id = 0;
static u8 dochangepin = 0;
static const char *newpin = NULL;
static int usb_reader_num = -1;
static const char *pin = NULL;
static const char *cdriver = NULL;
static sc_context_t *ctx = NULL;
static sc_reader_t *reader;
#define OPT_HELP 'h'
#define OPT_READER 'r'
#define OPT_PIN 'i'
@@ -37,7 +40,6 @@ static const char *cdriver = NULL;
#define OPT_CAN 'a'
#define OPT_MRZ 'z'
#define OPT_CHANGE_PIN 'I'
#define OPT_CHANGE_CAN 'A'
#define OPT_VERBOSE 'v'
#define OPT_INFO 'o'
#define OPT_CARD 'c'
@@ -46,12 +48,11 @@ static const struct option options[] = {
{ "help", no_argument, NULL, OPT_HELP },
{ "reader", required_argument, NULL, OPT_READER },
{ "card-driver", required_argument, NULL, OPT_CARD },
{ "test-pin", optional_argument, NULL, OPT_PIN },
{ "test-puk", optional_argument, NULL, OPT_PUK },
{ "test-can", optional_argument, NULL, OPT_CAN },
{ "test-mrz", optional_argument, NULL, OPT_MRZ },
{ "pin", optional_argument, NULL, OPT_PIN },
{ "puk", optional_argument, NULL, OPT_PUK },
{ "can", optional_argument, NULL, OPT_CAN },
{ "mrz", optional_argument, NULL, OPT_MRZ },
{ "new-pin", optional_argument, NULL, OPT_CHANGE_PIN },
{ "new-can", optional_argument, NULL, OPT_CHANGE_CAN },
{ "verbose", no_argument, NULL, OPT_VERBOSE },
{ "info", no_argument, NULL, OPT_INFO },
{ NULL, 0, NULL, 0 }
@@ -64,19 +65,39 @@ static const char *option_help[] = {
"Run PACE with PUK",
"Run PACE with CAN",
"Run PACE with MRZ",
"Change PIN when PACE is finished",
"Change CAN when PACE is finished",
"Install a new PIN",
"Use (several times) to be more verbose",
"Print version, available readers and drivers.",
};
int testpace(u8 pin_id, const char *pin, size_t pinlen,
u8 new_pin_id, const char *new_pin, size_t new_pinlen)
{
int i;
sc_card_t *card;
for (i = 0; i < SC_MAX_SLOTS; i++) {
if (sc_detect_card_presence(reader, 0) & SC_SLOT_CARD_PRESENT) {
sc_connect_card(reader, i, &card);
i = pace_test(card, pin_id, pin, pinlen,
new_pin_id, new_pin, new_pinlen);
if (card && sc_card_valid(card))
sc_disconnect_card(card, 0);
return i;
}
}
fprintf (stderr, "No card found.");
return SC_ERROR_SLOT_NOT_FOUND;
}
int
main (int argc, char **argv)
{
int i, oindex = 0;
while (1) {
i = getopt_long(argc, argv, "hr:i::u::a::z::I::A::voc:", options, &oindex);
i = getopt_long(argc, argv, "hr:i::u::a::z::I::voc:", options, &oindex);
if (i == -1)
break;
switch (i) {
@@ -101,28 +122,24 @@ main (int argc, char **argv)
break;
case OPT_PUK:
/* PACE_PIN from openssl/pace.h */
dopacetest = 4;
pin_id = 4;
pin = optarg;
break;
case OPT_PIN:
/* PACE_PIN from openssl/pace.h */
dopacetest = 3;
pin_id = 3;
pin = optarg;
break;
case OPT_CAN:
/* PACE_PIN from openssl/pace.h */
dopacetest = 2;
pin_id = 2;
pin = optarg;
break;
case OPT_MRZ:
/* PACE_MRZ from openssl/pace.h */
dopacetest = 1;
pin_id = 1;
pin = optarg;
break;
case OPT_CHANGE_CAN:
dochangepin = 2;
newpin = optarg;
break;
case OPT_CHANGE_PIN:
dochangepin = 3;
newpin = optarg;
@@ -148,16 +165,20 @@ main (int argc, char **argv)
if (doinfo) {
fprintf(stderr, "%s 0.9 written by Frank Morgner.\n\n" ,
argv[0]);
return ccid_print_avail(verbose);
return print_avail(verbose);
}
if (ccid_initialize(usb_reader_num, cdriver, verbose) < 0) {
perror("Can't initialize ccid");
i = initialize(usb_reader_num, cdriver, verbose, &ctx, &reader);
if (i < 0) {
perror("Can't initialize reader");
return 1;
}
i = ccid_testpace(dopacetest, pin, !pin ? 0 : strlen(pin),
i = testpace(pin_id, pin, !pin ? 0 : strlen(pin),
dochangepin, newpin, !newpin ? 0 : strlen(newpin));
ccid_shutdown();
if (ctx)
sc_release_context(ctx);
return i;
}