2002-04-06 12:02:28 +00:00
|
|
|
|
/*
|
|
|
|
|
* errors.c: The textual representation of errors
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2001, 2002 Juha Yrj<EFBFBD>l<EFBFBD> <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
|
|
|
|
|
*/
|
|
|
|
|
|
2002-04-07 10:21:00 +00:00
|
|
|
|
#include <stdio.h>
|
2002-04-06 12:02:28 +00:00
|
|
|
|
#include "errors.h"
|
|
|
|
|
|
|
|
|
|
#define DIM(v) (sizeof(v)/(sizeof((v)[0])))
|
|
|
|
|
|
|
|
|
|
const char *sc_strerror(int error)
|
|
|
|
|
{
|
|
|
|
|
const char *rdr_errors[] = {
|
|
|
|
|
"Generic reader error",
|
|
|
|
|
"No readers found",
|
|
|
|
|
"Slot not found",
|
|
|
|
|
"Slot already connected",
|
|
|
|
|
"Card not present",
|
|
|
|
|
"Card removed",
|
|
|
|
|
"Card reset",
|
|
|
|
|
"Transmit failed",
|
2003-10-21 11:11:50 +00:00
|
|
|
|
"Timed out while waiting for user input",
|
|
|
|
|
"Input operation cancelled by user",
|
|
|
|
|
"The two PINs did not match",
|
2002-12-23 18:47:27 +00:00
|
|
|
|
"Message too long (keypad)",
|
2003-10-21 11:11:50 +00:00
|
|
|
|
"Timeout while waiting for event from card reader",
|
2003-02-19 13:36:58 +00:00
|
|
|
|
"Unresponsive card (correctly inserted?)",
|
2003-04-11 14:42:16 +00:00
|
|
|
|
"Reader detached (hotplug device?)",
|
|
|
|
|
"Reader reattached (hotplug device?)",
|
2002-04-06 12:02:28 +00:00
|
|
|
|
};
|
|
|
|
|
const int rdr_base = -SC_ERROR_READER;
|
|
|
|
|
const char *card_errors[] = {
|
|
|
|
|
"Card command failed",
|
|
|
|
|
"File not found",
|
|
|
|
|
"Record not found",
|
|
|
|
|
"Unsupported CLA byte in APDU",
|
|
|
|
|
"Unsupported INS byte in APDU",
|
|
|
|
|
"Incorrect parameters in APDU",
|
|
|
|
|
"Wrong length",
|
|
|
|
|
"Card memory failure",
|
|
|
|
|
"Card does not support the requested operation",
|
|
|
|
|
"Not allowed",
|
|
|
|
|
"Card is invalid or cannot be handled",
|
|
|
|
|
"Security status not satisfied",
|
|
|
|
|
"Authentication method blocked",
|
|
|
|
|
"Unknown data received from card",
|
|
|
|
|
"PIN code or key incorrect",
|
|
|
|
|
"File already exists",
|
2003-10-30 17:03:09 +00:00
|
|
|
|
"Data object not found",
|
2002-04-06 12:02:28 +00:00
|
|
|
|
};
|
|
|
|
|
const int card_base = -SC_ERROR_CARD_CMD_FAILED;
|
|
|
|
|
const char *arg_errors[] = {
|
|
|
|
|
"Invalid arguments",
|
|
|
|
|
"Command too short",
|
|
|
|
|
"Command too long",
|
|
|
|
|
"Buffer too small",
|
|
|
|
|
"Invalid PIN length",
|
2003-11-23 15:33:56 +00:00
|
|
|
|
"Invalid data",
|
2002-04-06 12:02:28 +00:00
|
|
|
|
};
|
|
|
|
|
const int arg_base = -SC_ERROR_INVALID_ARGUMENTS;
|
|
|
|
|
const char *int_errors[] = {
|
|
|
|
|
"Internal error",
|
|
|
|
|
"Invalid ASN.1 object",
|
|
|
|
|
"Required ASN.1 object not found",
|
|
|
|
|
"Premature end of ASN.1 stream",
|
|
|
|
|
"Out of memory",
|
|
|
|
|
"Object not valid",
|
2002-06-18 15:17:15 +00:00
|
|
|
|
"Object not found",
|
2002-04-06 12:02:28 +00:00
|
|
|
|
"Requested object not found",
|
|
|
|
|
"Not supported",
|
2003-07-14 16:56:15 +00:00
|
|
|
|
"Passphrase required",
|
|
|
|
|
"The key is extractable",
|
|
|
|
|
"Decryption failed",
|
|
|
|
|
"Wrong padding",
|
2003-07-16 15:17:57 +00:00
|
|
|
|
"Wrong card",
|
2003-10-21 11:11:50 +00:00
|
|
|
|
"Unable to load external module",
|
2002-04-06 12:02:28 +00:00
|
|
|
|
};
|
|
|
|
|
const int int_base = -SC_ERROR_INTERNAL;
|
|
|
|
|
const char *p15i_errors[] = {
|
|
|
|
|
"Generic PKCS #15 initialization error",
|
|
|
|
|
"Syntax error",
|
|
|
|
|
"Inconsistent or incomplete pkcs15 profile",
|
2002-12-04 12:33:43 +00:00
|
|
|
|
"Key length/algorithm not supported by card",
|
|
|
|
|
"No default (transport) key available",
|
|
|
|
|
"The PKCS#15 Key/certificate ID specified is not unique",
|
2003-04-16 10:20:22 +00:00
|
|
|
|
"Unable to load key and certificate(s) from file",
|
2003-10-13 14:34:52 +00:00
|
|
|
|
"Object is not compatible with intended use",
|
|
|
|
|
"File template not found",
|
|
|
|
|
"Invalid PIN reference",
|
|
|
|
|
"File too small",
|
2002-04-06 12:02:28 +00:00
|
|
|
|
};
|
|
|
|
|
const int p15i_base = -SC_ERROR_PKCS15INIT;
|
|
|
|
|
const char *misc_errors[] = {
|
|
|
|
|
"Unknown error",
|
|
|
|
|
"PKCS#15 compatible SmartCard not found",
|
|
|
|
|
};
|
|
|
|
|
const int misc_base = -SC_ERROR_UNKNOWN;
|
2002-04-07 10:21:00 +00:00
|
|
|
|
const char **errors = NULL;
|
2002-04-06 12:02:28 +00:00
|
|
|
|
int count = 0, err_base = 0;
|
|
|
|
|
|
|
|
|
|
if (error < 0)
|
|
|
|
|
error = -error;
|
|
|
|
|
if (error >= misc_base) {
|
|
|
|
|
errors = misc_errors;
|
|
|
|
|
count = DIM(misc_errors);
|
|
|
|
|
err_base = misc_base;
|
|
|
|
|
} else if (error >= p15i_base) {
|
|
|
|
|
errors = p15i_errors;
|
|
|
|
|
count = DIM(p15i_errors);
|
|
|
|
|
err_base = p15i_base;
|
|
|
|
|
} else if (error >= int_base) {
|
|
|
|
|
errors = int_errors;
|
|
|
|
|
count = DIM(int_errors);
|
|
|
|
|
err_base = int_base;
|
|
|
|
|
} else if (error >= arg_base) {
|
|
|
|
|
errors = arg_errors;
|
|
|
|
|
count = DIM(arg_errors);
|
|
|
|
|
err_base = arg_base;
|
|
|
|
|
} else if (error >= card_base) {
|
|
|
|
|
errors = card_errors;
|
|
|
|
|
count = DIM(card_errors);
|
|
|
|
|
err_base = card_base;
|
|
|
|
|
} else if (error >= rdr_base) {
|
|
|
|
|
errors = rdr_errors;
|
|
|
|
|
count = DIM(rdr_errors);
|
|
|
|
|
err_base = rdr_base;
|
|
|
|
|
}
|
|
|
|
|
error -= err_base;
|
|
|
|
|
if (error >= count || count == 0)
|
|
|
|
|
return misc_errors[0];
|
|
|
|
|
return errors[error];
|
|
|
|
|
}
|