2002-04-06 12:02:28 +00:00
|
|
|
/*
|
|
|
|
* errors.c: The textual representation of errors
|
|
|
|
*
|
2006-12-19 21:31:17 +00:00
|
|
|
* Copyright (C) 2001, 2002 Juha Yrjölä <juha.yrjola@iki.fi>
|
2002-04-06 12:02:28 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2015-04-22 21:55:33 +00:00
|
|
|
#if HAVE_CONFIG_H
|
2010-03-04 08:14:36 +00:00
|
|
|
#include "config.h"
|
2015-04-22 21:55:33 +00:00
|
|
|
#endif
|
2010-03-04 08:14:36 +00:00
|
|
|
|
2002-04-07 10:21:00 +00:00
|
|
|
#include <stdio.h>
|
2010-03-04 08:14:36 +00:00
|
|
|
|
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",
|
2010-08-23 10:32:21 +00:00
|
|
|
"UNUSED",
|
|
|
|
"UNUSED",
|
2002-04-06 12:02:28 +00:00
|
|
|
"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",
|
2010-08-23 10:32:21 +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?)",
|
2010-01-15 09:45:11 +00:00
|
|
|
"Reader in use by another application"
|
2002-04-06 12:02:28 +00:00
|
|
|
};
|
|
|
|
const int rdr_base = -SC_ERROR_READER;
|
2011-04-27 14:28:03 +00:00
|
|
|
|
2002-04-06 12:02:28 +00:00
|
|
|
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",
|
2010-01-23 19:12:52 +00:00
|
|
|
"Not enough memory on card",
|
2011-04-27 14:28:03 +00:00
|
|
|
"Part of returned data may be corrupted",
|
2012-10-14 12:35:46 +00:00
|
|
|
"End of file/record reached before reading Le bytes",
|
|
|
|
"Reference data not usable"
|
2002-04-06 12:02:28 +00:00
|
|
|
};
|
|
|
|
const int card_base = -SC_ERROR_CARD_CMD_FAILED;
|
2011-04-27 14:28:03 +00:00
|
|
|
|
2002-04-06 12:02:28 +00:00
|
|
|
const char *arg_errors[] = {
|
|
|
|
"Invalid arguments",
|
2010-08-23 10:32:21 +00:00
|
|
|
"UNUSED",
|
|
|
|
"UNUSED",
|
2002-04-06 12:02:28 +00:00
|
|
|
"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;
|
2011-04-27 14:28:03 +00:00
|
|
|
|
2002-04-06 12:02:28 +00:00
|
|
|
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",
|
2012-11-11 20:47:10 +00:00
|
|
|
"Too many objects",
|
2002-04-06 12:02:28 +00:00
|
|
|
"Object not valid",
|
|
|
|
"Requested object not found",
|
|
|
|
"Not supported",
|
2003-07-14 16:56:15 +00:00
|
|
|
"Passphrase required",
|
2012-05-29 09:29:44 +00:00
|
|
|
"Inconsistent configuration",
|
2003-07-14 16:56:15 +00:00
|
|
|
"Decryption failed",
|
|
|
|
"Wrong padding",
|
2005-09-30 06:35:29 +00:00
|
|
|
"Unsupported card",
|
2003-10-21 11:11:50 +00:00
|
|
|
"Unable to load external module",
|
2009-11-13 19:01:21 +00:00
|
|
|
"EF offset too large",
|
|
|
|
"Not implemented"
|
2002-04-06 12:02:28 +00:00
|
|
|
};
|
|
|
|
const int int_base = -SC_ERROR_INTERNAL;
|
2011-04-27 14:28:03 +00:00
|
|
|
|
2002-04-06 12:02:28 +00:00
|
|
|
const char *p15i_errors[] = {
|
2010-08-23 10:32:21 +00:00
|
|
|
"Generic PKCS#15 initialization error",
|
2002-04-06 12:02:28 +00:00
|
|
|
"Syntax error",
|
2010-08-23 10:32:21 +00:00
|
|
|
"Inconsistent or incomplete PKCS#15 profile",
|
2002-12-04 12:33:43 +00:00
|
|
|
"Key length/algorithm not supported by card",
|
|
|
|
"No default (transport) key available",
|
2011-03-06 11:34:58 +00:00
|
|
|
"Non unique object ID",
|
2003-04-16 10:20:22 +00:00
|
|
|
"Unable to load key and certificate(s) from file",
|
2010-08-23 10:32:21 +00:00
|
|
|
"UNUSED",
|
2003-10-13 14:34:52 +00:00
|
|
|
"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;
|
2011-04-27 14:28:03 +00:00
|
|
|
|
2011-05-13 12:50:24 +00:00
|
|
|
const char *sm_errors[] = {
|
|
|
|
"Generic Secure Messaging error",
|
|
|
|
"Data enciphering error",
|
|
|
|
"Invalid secure messaging level",
|
|
|
|
"No session keys",
|
|
|
|
"Invalid session keys",
|
|
|
|
"Secure Messaging not initialized",
|
|
|
|
"Cannot authenticate card",
|
|
|
|
"Random generation error",
|
|
|
|
"Secure messaging keyset not found",
|
2013-01-06 15:38:33 +00:00
|
|
|
"IFD data missing",
|
|
|
|
"SM not applied",
|
|
|
|
"SM session already active",
|
|
|
|
"Invalid checksum"
|
2011-05-13 12:50:24 +00:00
|
|
|
};
|
2013-01-06 15:38:33 +00:00
|
|
|
const int sm_base = -SC_ERROR_SM;
|
2011-05-13 12:50:24 +00:00
|
|
|
|
2002-04-06 12:02:28 +00:00
|
|
|
const char *misc_errors[] = {
|
|
|
|
"Unknown error",
|
2005-06-16 19:35:31 +00:00
|
|
|
"PKCS#15 compatible smart card not found",
|
2002-04-06 12:02:28 +00:00
|
|
|
};
|
|
|
|
const int misc_base = -SC_ERROR_UNKNOWN;
|
2011-04-27 14:28:03 +00:00
|
|
|
|
|
|
|
const char *no_errors = "Success";
|
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;
|
2010-02-09 15:15:02 +00:00
|
|
|
|
|
|
|
if (!error)
|
|
|
|
return no_errors;
|
2002-04-06 12:02:28 +00:00
|
|
|
if (error < 0)
|
|
|
|
error = -error;
|
2011-04-27 14:28:03 +00:00
|
|
|
|
2002-04-06 12:02:28 +00:00
|
|
|
if (error >= misc_base) {
|
|
|
|
errors = misc_errors;
|
|
|
|
count = DIM(misc_errors);
|
|
|
|
err_base = misc_base;
|
2011-05-13 12:50:24 +00:00
|
|
|
} else if (error >= sm_base) {
|
|
|
|
errors = sm_errors;
|
|
|
|
count = DIM(sm_errors);
|
|
|
|
err_base = sm_base;
|
2002-04-06 12:02:28 +00:00
|
|
|
} 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];
|
|
|
|
}
|