Skip to content

Instantly share code, notes, and snippets.

@Jakuje
Created April 30, 2020 06:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jakuje/bd2317af7c4101f7e49c5d2686b414fd to your computer and use it in GitHub Desktop.
Save Jakuje/bd2317af7c4101f7e49c5d2686b414fd to your computer and use it in GitHub Desktop.
diff --git a/src/libopensc/asn1.c b/src/libopensc/asn1.c
index ad841934..9a077d3a 100644
--- a/src/libopensc/asn1.c
+++ b/src/libopensc/asn1.c
@@ -1506,7 +1506,7 @@ static int asn1_decode_entry(sc_context_t *ctx,struct sc_asn1_entry *entry,
case SC_ASN1_INTEGER:
case SC_ASN1_ENUMERATED:
if (parm != NULL) {
- r = sc_asn1_decode_integer(obj, objlen, (int *) entry->parm, 0);
+ r = sc_asn1_decode_integer(obj, objlen, (int *)entry->parm, 0);
sc_debug(ctx, SC_LOG_DEBUG_ASN1, "%*.*sdecoding '%s' returned %d\n", depth, depth, "",
entry->name, *((int *) entry->parm));
}
diff --git a/src/libopensc/card-cardos.c b/src/libopensc/card-cardos.c
index b7602443..a7648326 100644
--- a/src/libopensc/card-cardos.c
+++ b/src/libopensc/card-cardos.c
@@ -44,19 +44,19 @@ static struct sc_card_driver cardos_drv = {
};
static const struct sc_atr_table cardos_atrs[] = {
- /* 4.0 */
- { "3b:e2:00:ff:c1:10:31:fe:55:c8:02:9c", NULL, NULL, SC_CARD_TYPE_CARDOS_GENERIC, 0, NULL },
- /* cardos m4.2 and above */
- { "3b:f2:18:00:ff:c1:0a:31:fe:55:c8:06:8a", "ff:ff:0f:ff:00:ff:00:ff:ff:00:00:00:00", NULL, SC_CARD_TYPE_CARDOS_M4_2, 0, NULL },
- /* CardOS 4.4 */
- { "3b:d2:18:02:c1:0a:31:fe:58:c8:0d:51", NULL, NULL, SC_CARD_TYPE_CARDOS_M4_4, 0, NULL},
- /* CardOS v5.0 */
- { "3b:d2:18:00:81:31:fe:58:c9:01:14", NULL, NULL, SC_CARD_TYPE_CARDOS_V5_0, 0, NULL},
- /* CardOS v5.3 */
- { "3b:d2:18:00:81:31:fe:58:c9:02:17", NULL, NULL, SC_CARD_TYPE_CARDOS_V5_3, 0, NULL},
- { "3b:d2:18:00:81:31:fe:58:c9:03:16", NULL, NULL, SC_CARD_TYPE_CARDOS_V5_3, 0, NULL},
- { NULL, NULL, NULL, 0, 0, NULL }
-};
+ /* 4.0 */
+ {"3b:e2:00:ff:c1:10:31:fe:55:c8:02:9c", NULL, NULL, SC_CARD_TYPE_CARDOS_GENERIC, 0, NULL},
+ /* cardos m4.2 and above */
+ {"3b:f2:18:00:ff:c1:0a:31:fe:55:c8:06:8a", "ff:ff:0f:ff:00:ff:00:ff:ff:00:00:00:00", NULL, SC_CARD_TYPE_CARDOS_M4_2,
+ 0, NULL},
+ /* CardOS 4.4 */
+ {"3b:d2:18:02:c1:0a:31:fe:58:c8:0d:51", NULL, NULL, SC_CARD_TYPE_CARDOS_M4_4, 0, NULL},
+ /* CardOS v5.0 */
+ {"3b:d2:18:00:81:31:fe:58:c9:01:14", NULL, NULL, SC_CARD_TYPE_CARDOS_V5_0, 0, NULL},
+ /* CardOS v5.3 */
+ {"3b:d2:18:00:81:31:fe:58:c9:02:17", NULL, NULL, SC_CARD_TYPE_CARDOS_V5_3, 0, NULL},
+ {"3b:d2:18:00:81:31:fe:58:c9:03:16", NULL, NULL, SC_CARD_TYPE_CARDOS_V5_3, 0, NULL},
+ {NULL, NULL, NULL, 0, 0, NULL}};
/* private date for cardos driver */
typedef struct cardos_data {
@@ -67,13 +67,11 @@ typedef struct cardos_data {
unsigned long ec_flags;
unsigned long ext_flags;
int rsa_2048;
- const sc_security_env_t * sec_env;
+ const sc_security_env_t *sec_env;
} cardos_data_t;
/* copied from iso7816.c */
-static void fixup_transceive_length(const struct sc_card *card,
- struct sc_apdu *apdu)
-{
+static void fixup_transceive_length(const struct sc_card *card, struct sc_apdu *apdu) {
if (card == NULL || apdu == NULL) {
return;
}
@@ -157,8 +155,8 @@ static int cardos_match_card(sc_card_t *card)
static int cardos_have_2048bit_package(sc_card_t *card)
{
sc_apdu_t apdu;
- u8 rbuf[SC_MAX_APDU_BUFFER_SIZE];
- int r;
+ u8 rbuf[SC_MAX_APDU_BUFFER_SIZE];
+ int r;
const u8 *p = rbuf, *q;
size_t len, tlen = 0, ilen = 0;
@@ -190,18 +188,16 @@ static int cardos_have_2048bit_package(sc_card_t *card)
return 0;
}
-
/* Called from cardos_init for old cards, from cardos_cardctl_parsed_token_info for new cards */
/* TODO see if works from old cards too */
-static int cardos_add_algs(sc_card_t *card, unsigned long flags, unsigned long ec_flags, unsigned long ext_flags)
-{
+static int cardos_add_algs(sc_card_t *card, unsigned long flags, unsigned long ec_flags, unsigned long ext_flags) {
- cardos_data_t * priv = (cardos_data_t *)card->drv_data;
+ cardos_data_t *priv = (cardos_data_t *)card->drv_data;
SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
- _sc_card_add_rsa_alg(card, 512, flags, 0);
- _sc_card_add_rsa_alg(card, 768, flags, 0);
+ _sc_card_add_rsa_alg(card, 512, flags, 0);
+ _sc_card_add_rsa_alg(card, 768, flags, 0);
_sc_card_add_rsa_alg(card, 1024, flags, 0);
if (priv->rsa_2048 == 1) {
_sc_card_add_rsa_alg(card, 1280, flags, 0);
@@ -219,8 +215,8 @@ static int cardos_add_algs(sc_card_t *card, unsigned long flags, unsigned long e
/* TODO need to get sizes from supported_algos too */
if (ec_flags != 0) {
- _sc_card_add_ec_alg(card, 256, ec_flags, priv->ext_flags, NULL);
- _sc_card_add_ec_alg(card, 384, ec_flags, priv->ext_flags, NULL);
+ _sc_card_add_ec_alg(card, 256, ec_flags, priv->ext_flags, NULL);
+ _sc_card_add_ec_alg(card, 384, ec_flags, priv->ext_flags, NULL);
}
return 0;
@@ -228,7 +224,7 @@ static int cardos_add_algs(sc_card_t *card, unsigned long flags, unsigned long e
static int cardos_init(sc_card_t *card)
{
- cardos_data_t * priv = NULL;
+ cardos_data_t *priv = NULL;
unsigned long flags = 0;
size_t data_field_length;
sc_apdu_t apdu;
@@ -248,22 +244,18 @@ static int cardos_init(sc_card_t *card)
/* let user override flags and type from opensc.conf */
/* user can override card->type too.*/
if (card->flags) {
- flags = card->flags;
+ flags = card->flags;
} else {
/* Set up algorithm info. */
flags = 0;
if (card->type == SC_CARD_TYPE_CARDOS_V5_0) {
flags |= SC_ALGORITHM_RSA_PAD_PKCS1;
- } else if(card->type == SC_CARD_TYPE_CARDOS_V5_3) {
- flags |= SC_ALGORITHM_RSA_RAW
- | SC_ALGORITHM_RSA_HASH_NONE
- | SC_ALGORITHM_ONBOARD_KEY_GEN;
+ } else if (card->type == SC_CARD_TYPE_CARDOS_V5_3) {
+ flags |= SC_ALGORITHM_RSA_RAW | SC_ALGORITHM_RSA_HASH_NONE | SC_ALGORITHM_ONBOARD_KEY_GEN;
} else {
- flags |= SC_ALGORITHM_RSA_RAW
- | SC_ALGORITHM_RSA_HASH_NONE
- | SC_ALGORITHM_NEED_USAGE
- | SC_ALGORITHM_ONBOARD_KEY_GEN;
+ flags |= SC_ALGORITHM_RSA_RAW | SC_ALGORITHM_RSA_HASH_NONE | SC_ALGORITHM_NEED_USAGE
+ | SC_ALGORITHM_ONBOARD_KEY_GEN;
}
}
@@ -276,12 +268,9 @@ static int cardos_init(sc_card_t *card)
if (r == 1)
priv->rsa_2048 = 1;
card->caps |= SC_CARD_CAP_APDU_EXT;
- } else if (card->type == SC_CARD_TYPE_CARDOS_M4_3
- || card->type == SC_CARD_TYPE_CARDOS_M4_2B
- || card->type == SC_CARD_TYPE_CARDOS_M4_2C
- || card->type == SC_CARD_TYPE_CARDOS_M4_4
- || card->type == SC_CARD_TYPE_CARDOS_V5_0
- || card->type == SC_CARD_TYPE_CARDOS_V5_3) {
+ } else if (card->type == SC_CARD_TYPE_CARDOS_M4_3 || card->type == SC_CARD_TYPE_CARDOS_M4_2B
+ || card->type == SC_CARD_TYPE_CARDOS_M4_2C || card->type == SC_CARD_TYPE_CARDOS_M4_4
+ || card->type == SC_CARD_TYPE_CARDOS_V5_0 || card->type == SC_CARD_TYPE_CARDOS_V5_3) {
priv->rsa_2048 = 1;
card->caps |= SC_CARD_CAP_APDU_EXT;
/* TODO check this. EC only if in supported_algo */
@@ -314,14 +303,15 @@ static int cardos_init(sc_card_t *card)
/* Use Min card sizes and reader too. for V5_3 at least*/
if (card->type == SC_CARD_TYPE_CARDOS_V5_0 || card->type == SC_CARD_TYPE_CARDOS_V5_3) {
- sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "data_field_length:%"SC_FORMAT_LEN_SIZE_T"u "
- "card->reader->max_send_size:%"SC_FORMAT_LEN_SIZE_T"u "
- "card->reader->max_recv_size:%"SC_FORMAT_LEN_SIZE_T"u %s",
- data_field_length, card->reader->max_send_size, card->reader->max_recv_size,
- (card->caps & SC_CARD_CAP_APDU_EXT) ? "SC_CARD_CAP_APDU_EXT" : " ");
+ sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL,
+ "data_field_length:%" SC_FORMAT_LEN_SIZE_T "u "
+ "card->reader->max_send_size:%" SC_FORMAT_LEN_SIZE_T "u "
+ "card->reader->max_recv_size:%" SC_FORMAT_LEN_SIZE_T "u %s",
+ data_field_length, card->reader->max_send_size, card->reader->max_recv_size,
+ (card->caps & SC_CARD_CAP_APDU_EXT) ? "SC_CARD_CAP_APDU_EXT" : " ");
if (card->caps & SC_CARD_CAP_APDU_EXT) {
- card->max_send_size = data_field_length - 6;
+ card->max_send_size = data_field_length - 6;
#ifdef _WIN32
/* Windows does not support PCSC PART_10 and may have forced reader to 255/256
* https://github.com/OpenSC/OpenSC/commit/eddea6f3c2d3dafc2c09eba6695c745a61b5186f
@@ -358,18 +348,16 @@ static int cardos_init(sc_card_t *card)
return 0;
}
-
/*
* Called from sc_pkcs15_bind_internal by cardctl after tokininfo is parsed.
* Create new flags based on supported_algos.
*/
-int cardos_cardctl_parsed_token_info(sc_card_t *card, struct sc_cardctl_parsed_token_info * ptr)
-{
- cardos_data_t * priv = (cardos_data_t *)card->drv_data;
- unsigned long new_flags= 0;
+int cardos_cardctl_parsed_token_info(sc_card_t *card, struct sc_cardctl_parsed_token_info *ptr) {
+ cardos_data_t *priv = (cardos_data_t *)card->drv_data;
+ unsigned long new_flags = 0;
unsigned long new_ec_flags = 0;
int i;
- struct sc_supported_algo_info (*saa)[SC_MAX_SUPPORTED_ALGORITHMS];
+ struct sc_supported_algo_info(*saa)[SC_MAX_SUPPORTED_ALGORITHMS];
struct sc_supported_algo_info *sa;
assert(ptr != NULL && ptr->tokeninfo != NULL);
@@ -377,7 +365,8 @@ int cardos_cardctl_parsed_token_info(sc_card_t *card, struct sc_cardctl_parsed_t
saa = &(ptr->tokeninfo->supported_algos);
SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
- sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "Original Flags: 0x%8.8lx card->flags:0x%8.8lx", priv->flags, card->flags);
+ sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "Original Flags: 0x%8.8lx card->flags:0x%8.8lx", priv->flags,
+ card->flags);
if (card->flags) {
new_flags = card->flags; /* from card_atr flags */
@@ -385,13 +374,14 @@ int cardos_cardctl_parsed_token_info(sc_card_t *card, struct sc_cardctl_parsed_t
for (i = 0, sa = saa[0]; i < SC_MAX_SUPPORTED_ALGORITHMS; i++, sa++) {
- if (sa->reference == 0 && sa->reference == 0 && sa->mechanism == 0
- && sa->operations == 0 && sa->algo_ref == 0)
+ if (sa->reference == 0 && sa->reference == 0 && sa->mechanism == 0 && sa->operations == 0
+ && sa->algo_ref == 0)
break;
- sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "supported_algos[%d] mechamism:0x%8.8x", i, sa->mechanism);
- switch(sa->mechanism) {
- case 0x01 :
+ sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "supported_algos[%d] mechamism:0x%8.8x", i,
+ sa->mechanism);
+ switch (sa->mechanism) {
+ case 0x01:
/*
* Card appears to use lower 4 bits of reference as key, and upper
* 4 bits as mech for card.
@@ -401,17 +391,15 @@ int cardos_cardctl_parsed_token_info(sc_card_t *card, struct sc_cardctl_parsed_t
*/
if (sa->reference & 0x10) {
sc_log(card->ctx, "Changeing mechanism to CKM_RSA_X_509 based on reference");
- new_flags |= SC_ALGORITHM_RSA_RAW
- | SC_ALGORITHM_RSA_PAD_NONE;
+ new_flags |= SC_ALGORITHM_RSA_RAW | SC_ALGORITHM_RSA_PAD_NONE;
sa->mechanism = 0x03;
} else
- new_flags |= SC_ALGORITHM_RSA_PAD_PKCS1;
+ new_flags |= SC_ALGORITHM_RSA_PAD_PKCS1;
break;
- case 0x03 :
- new_flags |= SC_ALGORITHM_RSA_RAW
- | SC_ALGORITHM_RSA_PAD_NONE;
+ case 0x03:
+ new_flags |= SC_ALGORITHM_RSA_RAW | SC_ALGORITHM_RSA_PAD_NONE;
break;
- case 0x06 :
+ case 0x06:
new_flags |= SC_ALGORITHM_RSA_HASH_SHA1;
break;
case 0x1041:
@@ -423,7 +411,8 @@ int cardos_cardctl_parsed_token_info(sc_card_t *card, struct sc_cardctl_parsed_t
sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "UNKNOWN MECH: 0x%8.8x", sa->mechanism);
}
- sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "New_flags 0x%8.8lx New_ec_flags: 0x%8.8lx", new_flags, new_ec_flags);
+ sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "New_flags 0x%8.8lx New_ec_flags: 0x%8.8lx", new_flags,
+ new_ec_flags);
}
if (new_flags == 0) {
@@ -435,15 +424,15 @@ int cardos_cardctl_parsed_token_info(sc_card_t *card, struct sc_cardctl_parsed_t
}
}
- sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL,"Final New_flags 0x%8.8lx New_ec_flags: 0x%8.8lx", new_flags, new_ec_flags);
+ sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "Final New_flags 0x%8.8lx New_ec_flags: 0x%8.8lx", new_flags,
+ new_ec_flags);
cardos_add_algs(card, new_flags, new_ec_flags, priv->ext_flags);
LOG_FUNC_RETURN(card->ctx, 0);
}
-static int cardos_finish(sc_card_t *card)
-{
+static int cardos_finish(sc_card_t *card) {
int r = 0;
if (card)
@@ -460,68 +449,65 @@ static int cardos_finish(sc_card_t *card)
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
}
-
-
static const struct sc_card_error cardos_errors[] = {
-/* some error inside the card */
-/* i.e. nothing you can do */
-{ 0x6581, SC_ERROR_MEMORY_FAILURE, "EEPROM error; command aborted"},
-{ 0x6fff, SC_ERROR_CARD_CMD_FAILED, "internal assertion error"},
-{ 0x6700, SC_ERROR_WRONG_LENGTH, "LC invalid"},
-{ 0x6985, SC_ERROR_CARD_CMD_FAILED, "no random number available"},
-{ 0x6f81, SC_ERROR_CARD_CMD_FAILED, "file invalid, maybe checksum error"},
-{ 0x6f82, SC_ERROR_CARD_CMD_FAILED, "not enough memory in xram"},
-{ 0x6f84, SC_ERROR_CARD_CMD_FAILED, "general protection fault"},
-
-/* the card doesn't know this combination of ins+cla+p1+p2 */
-/* i.e. command will never work */
-{ 0x6881, SC_ERROR_NO_CARD_SUPPORT, "logical channel not supported"},
-{ 0x6a86, SC_ERROR_INCORRECT_PARAMETERS,"p1/p2 invalid"},
-{ 0x6d00, SC_ERROR_INS_NOT_SUPPORTED, "ins invalid"},
-{ 0x6e00, SC_ERROR_CLASS_NOT_SUPPORTED, "class invalid (hi nibble)"},
-
-/* known command, but incorrectly used */
-/* i.e. command could work, but you need to change something */
-{ 0x6981, SC_ERROR_CARD_CMD_FAILED, "command cannot be used for file structure"},
-{ 0x6a80, SC_ERROR_INCORRECT_PARAMETERS,"invalid parameters in data field"},
-{ 0x6a81, SC_ERROR_NOT_SUPPORTED, "function/mode not supported"},
-{ 0x6a85, SC_ERROR_INCORRECT_PARAMETERS,"lc does not fit the tlv structure"},
-{ 0x6986, SC_ERROR_INCORRECT_PARAMETERS,"no current ef selected"},
-{ 0x6a87, SC_ERROR_INCORRECT_PARAMETERS,"lc does not fit p1/p2"},
-{ 0x6c00, SC_ERROR_WRONG_LENGTH, "le does not fit the data to be sent"},
-{ 0x6f83, SC_ERROR_CARD_CMD_FAILED, "command must not be used in transaction"},
-
-/* (something) not found */
-{ 0x6987, SC_ERROR_INCORRECT_PARAMETERS,"key object for sm not found"},
-{ 0x6f86, SC_ERROR_CARD_CMD_FAILED, "key object not found"},
-{ 0x6a82, SC_ERROR_FILE_NOT_FOUND, "file not found"},
-{ 0x6a83, SC_ERROR_RECORD_NOT_FOUND, "record not found"},
-{ 0x6a88, SC_ERROR_CARD_CMD_FAILED, "object not found"},
-
-/* (something) invalid */
-{ 0x6884, SC_ERROR_CARD_CMD_FAILED, "chaining error"},
-{ 0x6984, SC_ERROR_CARD_CMD_FAILED, "bs object has invalid format"},
-{ 0x6988, SC_ERROR_INCORRECT_PARAMETERS,"key object used for sm has invalid format"},
-
-/* (something) deactivated */
-{ 0x6283, SC_ERROR_CARD_CMD_FAILED, "file is deactivated"},
-{ 0x6983, SC_ERROR_AUTH_METHOD_BLOCKED, "bs object blocked"},
-
-/* access denied */
-{ 0x6300, SC_ERROR_SECURITY_STATUS_NOT_SATISFIED,"authentication failed"},
-{ 0x6982, SC_ERROR_SECURITY_STATUS_NOT_SATISFIED,"required access right not granted"},
-
-/* other errors */
-{ 0x6a84, SC_ERROR_CARD_CMD_FAILED, "not enough memory"},
-
-/* command ok, execution failed */
-{ 0x6f00, SC_ERROR_CARD_CMD_FAILED, "technical error (see eToken developers guide)"},
-
-/* no error, maybe a note */
-{ 0x9000, SC_SUCCESS, NULL},
-{ 0x9001, SC_SUCCESS, "success, but eeprom weakness detected"},
-{ 0x9850, SC_SUCCESS, "over/underflow using in/decrease"}
-};
+ /* some error inside the card */
+ /* i.e. nothing you can do */
+ {0x6581, SC_ERROR_MEMORY_FAILURE, "EEPROM error; command aborted"},
+ {0x6fff, SC_ERROR_CARD_CMD_FAILED, "internal assertion error"},
+ {0x6700, SC_ERROR_WRONG_LENGTH, "LC invalid"},
+ {0x6985, SC_ERROR_CARD_CMD_FAILED, "no random number available"},
+ {0x6f81, SC_ERROR_CARD_CMD_FAILED, "file invalid, maybe checksum error"},
+ {0x6f82, SC_ERROR_CARD_CMD_FAILED, "not enough memory in xram"},
+ {0x6f84, SC_ERROR_CARD_CMD_FAILED, "general protection fault"},
+
+ /* the card doesn't know this combination of ins+cla+p1+p2 */
+ /* i.e. command will never work */
+ {0x6881, SC_ERROR_NO_CARD_SUPPORT, "logical channel not supported"},
+ {0x6a86, SC_ERROR_INCORRECT_PARAMETERS, "p1/p2 invalid"},
+ {0x6d00, SC_ERROR_INS_NOT_SUPPORTED, "ins invalid"},
+ {0x6e00, SC_ERROR_CLASS_NOT_SUPPORTED, "class invalid (hi nibble)"},
+
+ /* known command, but incorrectly used */
+ /* i.e. command could work, but you need to change something */
+ {0x6981, SC_ERROR_CARD_CMD_FAILED, "command cannot be used for file structure"},
+ {0x6a80, SC_ERROR_INCORRECT_PARAMETERS, "invalid parameters in data field"},
+ {0x6a81, SC_ERROR_NOT_SUPPORTED, "function/mode not supported"},
+ {0x6a85, SC_ERROR_INCORRECT_PARAMETERS, "lc does not fit the tlv structure"},
+ {0x6986, SC_ERROR_INCORRECT_PARAMETERS, "no current ef selected"},
+ {0x6a87, SC_ERROR_INCORRECT_PARAMETERS, "lc does not fit p1/p2"},
+ {0x6c00, SC_ERROR_WRONG_LENGTH, "le does not fit the data to be sent"},
+ {0x6f83, SC_ERROR_CARD_CMD_FAILED, "command must not be used in transaction"},
+
+ /* (something) not found */
+ {0x6987, SC_ERROR_INCORRECT_PARAMETERS, "key object for sm not found"},
+ {0x6f86, SC_ERROR_CARD_CMD_FAILED, "key object not found"},
+ {0x6a82, SC_ERROR_FILE_NOT_FOUND, "file not found"},
+ {0x6a83, SC_ERROR_RECORD_NOT_FOUND, "record not found"},
+ {0x6a88, SC_ERROR_CARD_CMD_FAILED, "object not found"},
+
+ /* (something) invalid */
+ {0x6884, SC_ERROR_CARD_CMD_FAILED, "chaining error"},
+ {0x6984, SC_ERROR_CARD_CMD_FAILED, "bs object has invalid format"},
+ {0x6988, SC_ERROR_INCORRECT_PARAMETERS, "key object used for sm has invalid format"},
+
+ /* (something) deactivated */
+ {0x6283, SC_ERROR_CARD_CMD_FAILED, "file is deactivated"},
+ {0x6983, SC_ERROR_AUTH_METHOD_BLOCKED, "bs object blocked"},
+
+ /* access denied */
+ {0x6300, SC_ERROR_SECURITY_STATUS_NOT_SATISFIED, "authentication failed"},
+ {0x6982, SC_ERROR_SECURITY_STATUS_NOT_SATISFIED, "required access right not granted"},
+
+ /* other errors */
+ {0x6a84, SC_ERROR_CARD_CMD_FAILED, "not enough memory"},
+
+ /* command ok, execution failed */
+ {0x6f00, SC_ERROR_CARD_CMD_FAILED, "technical error (see eToken developers guide)"},
+
+ /* no error, maybe a note */
+ {0x9000, SC_SUCCESS, NULL},
+ {0x9001, SC_SUCCESS, "success, but eeprom weakness detected"},
+ {0x9850, SC_SUCCESS, "over/underflow using in/decrease"}};
static int cardos_check_sw(sc_card_t *card, unsigned int sw1, unsigned int sw2)
{
@@ -530,14 +516,13 @@ static int cardos_check_sw(sc_card_t *card, unsigned int sw1, unsigned int sw2)
for (i = 0; i < err_count; i++) {
if (cardos_errors[i].SWs == ((sw1 << 8) | sw2)) {
- if ( cardos_errors[i].errorstr )
- sc_log(card->ctx, "%s\n",
- cardos_errors[i].errorstr);
+ if (cardos_errors[i].errorstr)
+ sc_log(card->ctx, "%s\n", cardos_errors[i].errorstr);
return cardos_errors[i].errorno;
}
}
- sc_log(card->ctx, "Unknown SWs; SW1=%02X, SW2=%02X\n", sw1, sw2);
+ sc_log(card->ctx, "Unknown SWs; SW1=%02X, SW2=%02X\n", sw1, sw2);
return SC_ERROR_CARD_CMD_FAILED;
}
@@ -696,10 +681,7 @@ static void parse_sec_attr(sc_file_t *file, const u8 *buf, size_t len)
add_acl_entry(file, idx[i], (u8)((i < len) ? buf[i] : 0xFF));
}
-static int cardos_select_file(sc_card_t *card,
- const sc_path_t *in_path,
- sc_file_t **file)
-{
+static int cardos_select_file(sc_card_t *card, const sc_path_t *in_path, sc_file_t **file) {
int r;
SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
@@ -985,14 +967,10 @@ cardos_restore_security_env(sc_card_t *card, int se_num)
* with the same ID.
* XXX Need to find out how the Aladdin drivers do it.
*/
-static int
-cardos_set_security_env(sc_card_t *card,
- const sc_security_env_t *env,
- int se_num)
-{
- cardos_data_t* priv = (cardos_data_t*)card->drv_data;
+static int cardos_set_security_env(sc_card_t *card, const sc_security_env_t *env, int se_num) {
+ cardos_data_t *priv = (cardos_data_t *)card->drv_data;
sc_apdu_t apdu;
- u8 data[9];
+ u8 data[9];
int key_id, r;
assert(card != NULL && env != NULL);
@@ -1095,7 +1073,7 @@ cardos_set_security_env(sc_card_t *card,
sc_log(card->ctx, "reference=%d, mechanism=%d, operations=%d, algo_ref=%d",
alg.reference, alg.mechanism, alg.operations, alg.algo_ref);
}
- priv -> algorithm_ids_in_tokeninfo_count = algorithm_id_count;
+ priv->algorithm_ids_in_tokeninfo_count = algorithm_id_count;
} while (0);
LOG_FUNC_RETURN(card->ctx, r);
@@ -1106,10 +1084,7 @@ cardos_set_security_env(sc_card_t *card,
*/
/* internal function to do the actual signature computation */
-static int
-do_compute_signature(sc_card_t *card, const u8 *data, size_t datalen,
- u8 *out, size_t outlen)
-{
+static int do_compute_signature(sc_card_t *card, const u8 *data, size_t datalen, u8 *out, size_t outlen) {
/* cardos_data_t* priv = (cardos_data_t*)card->drv_dataa */;
int r;
sc_apdu_t apdu;
@@ -1139,7 +1114,7 @@ static int
cardos_compute_signature(sc_card_t *card, const u8 *data, size_t datalen,
u8 *out, size_t outlen)
{
- cardos_data_t* priv;
+ cardos_data_t *priv;
int r;
sc_context_t *ctx;
int do_rsa_pure_sig = 0;
@@ -1149,7 +1124,7 @@ cardos_compute_signature(sc_card_t *card, const u8 *data, size_t datalen,
assert(card != NULL && data != NULL && out != NULL);
ctx = card->ctx;
- priv = (cardos_data_t*)card->drv_data;
+ priv = (cardos_data_t *)card->drv_data;
SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_VERBOSE);
/* sec_env has algorithm_flags set from sc_get_encoding_flags sec_flags
@@ -1252,7 +1227,7 @@ cardos_decipher(struct sc_card *card,
const u8 * crgram, size_t crgram_len,
u8 * out, size_t outlen)
{
- cardos_data_t* priv = (cardos_data_t*)card->drv_data;
+ cardos_data_t *priv = (cardos_data_t *)card->drv_data;
int r;
size_t card_max_send_size = card->max_send_size;
size_t reader_max_send_size = card->reader->max_send_size;
@@ -1278,8 +1253,8 @@ cardos_decipher(struct sc_card *card,
/* removed padding is always > 1 byte */
/* add back missing leading zero if card dropped it */
if (rsize == crgram_len - 1 && rsize < outlen) {
- memmove(out+1, out, rsize);
- out[0] =0x00;
+ memmove(out + 1, out, rsize);
+ out[0] = 0x00;
r++;
}
}
@@ -1521,9 +1496,8 @@ cardos_card_ctl(sc_card_t *card, unsigned long cmd, void *ptr)
case SC_CARDCTL_CARDOS_GENERATE_KEY:
return cardos_generate_key(card,
(struct sc_cardctl_cardos_genkey_info *) ptr);
- case SC_CARDCTL_PARSED_TOKEN_INFO:
- return cardos_cardctl_parsed_token_info(card,
- (struct sc_cardctl_parsed_token_info *) ptr);
+ case SC_CARDCTL_PARSED_TOKEN_INFO:
+ return cardos_cardctl_parsed_token_info(card, (struct sc_cardctl_parsed_token_info *)ptr);
case SC_CARDCTL_LIFECYCLE_GET:
return cardos_lifecycle_get(card, (int *) ptr);
case SC_CARDCTL_LIFECYCLE_SET:
@@ -1574,14 +1548,10 @@ cardos_pin_cmd(struct sc_card *card, struct sc_pin_cmd_data *data,
static int
cardos_logout(sc_card_t *card)
{
- if (card->type == SC_CARD_TYPE_CARDOS_M4_01
- || card->type == SC_CARD_TYPE_CARDOS_M4_2
- || card->type == SC_CARD_TYPE_CARDOS_M4_2B
- || card->type == SC_CARD_TYPE_CARDOS_M4_2C
- || card->type == SC_CARD_TYPE_CARDOS_M4_3
- || card->type == SC_CARD_TYPE_CARDOS_M4_4
- || card->type == SC_CARD_TYPE_CARDOS_V5_0
- || card->type == SC_CARD_TYPE_CARDOS_V5_3) {
+ if (card->type == SC_CARD_TYPE_CARDOS_M4_01 || card->type == SC_CARD_TYPE_CARDOS_M4_2
+ || card->type == SC_CARD_TYPE_CARDOS_M4_2B || card->type == SC_CARD_TYPE_CARDOS_M4_2C
+ || card->type == SC_CARD_TYPE_CARDOS_M4_3 || card->type == SC_CARD_TYPE_CARDOS_M4_4
+ || card->type == SC_CARD_TYPE_CARDOS_V5_0 || card->type == SC_CARD_TYPE_CARDOS_V5_3) {
sc_apdu_t apdu;
int r;
sc_path_t path;
diff --git a/src/libopensc/cardctl.h b/src/libopensc/cardctl.h
index 632be2fd..9ddb5c6f 100644
--- a/src/libopensc/cardctl.h
+++ b/src/libopensc/cardctl.h
@@ -72,7 +72,7 @@ enum {
/*
* TCOS specific calls
*/
- SC_CARDCTL_TCOS_BASE = _CTL_PREFIX('T','C','S'),
+ SC_CARDCTL_TCOS_BASE = _CTL_PREFIX('T', 'C', 'S'),
SC_CARDCTL_TCOS_SETPERM,
/*
@@ -127,11 +127,11 @@ enum {
SC_CARDCTL_INCRYPTO34_GENERATE_KEY,
SC_CARDCTL_INCRYPTO34_CHANGE_KEY_DATA,
SC_CARDCTL_INCRYPTO34_ERASE_FILES,
-
+
/*
* Muscle specific calls
*/
- SC_CARDCTL_MUSCLE_BASE = _CTL_PREFIX('M','S','C'),
+ SC_CARDCTL_MUSCLE_BASE = _CTL_PREFIX('M', 'S', 'C'),
SC_CARDCTL_MUSCLE_GENERATE_KEY,
SC_CARDCTL_MUSCLE_EXTRACT_KEY,
SC_CARDCTL_MUSCLE_IMPORT_KEY,
@@ -140,26 +140,26 @@ enum {
/*
* ASEPCOS specific calls
*/
- SC_CARDCTL_ASEPCOS_BASE = _CTL_PREFIX('A','S','E'),
+ SC_CARDCTL_ASEPCOS_BASE = _CTL_PREFIX('A', 'S', 'E'),
SC_CARDCTL_ASEPCOS_CHANGE_KEY,
SC_CARDCTL_ASEPCOS_AKN2FILEID,
SC_CARDCTL_ASEPCOS_SET_SATTR,
SC_CARDCTL_ASEPCOS_ACTIVATE_FILE,
- /*
+ /*
* ruToken specific calls
*/
- SC_CARDCTL_RUTOKEN_BASE = _CTL_PREFIX('R', 'T', 'K'),
- /* PUT_DATA */
- SC_CARDCTL_RUTOKEN_CREATE_DO,
- SC_CARDCTL_RUTOKEN_CHANGE_DO,
- SC_CARDCTL_RUTOKEN_GENERATE_KEY_DO,
- SC_CARDCTL_RUTOKEN_DELETE_DO,
- SC_CARDCTL_RUTOKEN_GET_INFO,
- /* NON STANDARD */
- SC_CARDCTL_RUTOKEN_GET_DO_INFO,
- SC_CARDCTL_RUTOKEN_GOST_ENCIPHER,
- SC_CARDCTL_RUTOKEN_GOST_DECIPHER,
+ SC_CARDCTL_RUTOKEN_BASE = _CTL_PREFIX('R', 'T', 'K'),
+ /* PUT_DATA */
+ SC_CARDCTL_RUTOKEN_CREATE_DO,
+ SC_CARDCTL_RUTOKEN_CHANGE_DO,
+ SC_CARDCTL_RUTOKEN_GENERATE_KEY_DO,
+ SC_CARDCTL_RUTOKEN_DELETE_DO,
+ SC_CARDCTL_RUTOKEN_GET_INFO,
+ /* NON STANDARD */
+ SC_CARDCTL_RUTOKEN_GET_DO_INFO,
+ SC_CARDCTL_RUTOKEN_GOST_ENCIPHER,
+ SC_CARDCTL_RUTOKEN_GOST_DECIPHER,
SC_CARDCTL_RUTOKEN_FORMAT_INIT,
SC_CARDCTL_RUTOKEN_FORMAT_END,
@@ -223,14 +223,14 @@ enum {
SC_CARDCTL_CAC_FINAL_GET_CERT_OBJECTS,
SC_CARDCTL_CAC_GET_ACA_PATH,
- /*
+ /*
* AuthentIC v3
*/
- SC_CARDCTL_AUTHENTIC_BASE = _CTL_PREFIX('A','V','3'),
- SC_CARDCTL_AUTHENTIC_SDO_CREATE,
- SC_CARDCTL_AUTHENTIC_SDO_DELETE,
- SC_CARDCTL_AUTHENTIC_SDO_STORE,
- SC_CARDCTL_AUTHENTIC_SDO_GENERATE,
+ SC_CARDCTL_AUTHENTIC_BASE = _CTL_PREFIX('A', 'V', '3'),
+ SC_CARDCTL_AUTHENTIC_SDO_CREATE,
+ SC_CARDCTL_AUTHENTIC_SDO_DELETE,
+ SC_CARDCTL_AUTHENTIC_SDO_STORE,
+ SC_CARDCTL_AUTHENTIC_SDO_GENERATE,
/*
* Coolkey specific calls
@@ -243,13 +243,13 @@ enum {
SC_CARDCTL_COOLKEY_GET_TOKEN_INFO,
SC_CARDCTL_COOLKEY_FIND_OBJECT,
- /*
+ /*
* IAS/ECC
*/
- SC_CARDCTL_IASECC_BASE = _CTL_PREFIX('E','C','C'),
+ SC_CARDCTL_IASECC_BASE = _CTL_PREFIX('E', 'C', 'C'),
SC_CARDCTL_IASECC_GET_FREE_KEY_REFERENCE,
- SC_CARDCTL_IASECC_SDO_MAGIC = _CTL_PREFIX('S','D','O') | 'M',
- SC_CARDCTL_IASECC_SDO_MAGIC_PUT_DATA = _CTL_PREFIX('S','D','O') | 'P',
+ SC_CARDCTL_IASECC_SDO_MAGIC = _CTL_PREFIX('S', 'D', 'O') | 'M',
+ SC_CARDCTL_IASECC_SDO_MAGIC_PUT_DATA = _CTL_PREFIX('S', 'D', 'O') | 'P',
SC_CARDCTL_IASECC_SDO_PUT_DATA,
SC_CARDCTL_IASECC_SDO_KEY_RSA_PUT_DATA,
SC_CARDCTL_IASECC_SDO_GET_DATA,
@@ -277,21 +277,21 @@ enum {
/*
* DNIe specific calls
*/
- SC_CARDCTL_DNIE_BASE = _CTL_PREFIX('D', 'N', 'I'),
+ SC_CARDCTL_DNIE_BASE = _CTL_PREFIX('D', 'N', 'I'),
SC_CARDCTL_DNIE_GENERATE_KEY,
SC_CARDCTL_DNIE_GET_INFO,
/*
* isoApplet Java Card Applet
*/
- SC_CARDCTL_ISOAPPLET_BASE = _CTL_PREFIX('I','S','O'),
+ SC_CARDCTL_ISOAPPLET_BASE = _CTL_PREFIX('I', 'S', 'O'),
SC_CARDCTL_ISOAPPLET_GENERATE_KEY,
SC_CARDCTL_ISOAPPLET_IMPORT_KEY,
/*
* GIDS cards
*/
- SC_CARDCTL_GIDS_BASE = _CTL_PREFIX('G','I','D'),
+ SC_CARDCTL_GIDS_BASE = _CTL_PREFIX('G', 'I', 'D'),
SC_CARDCTL_GIDS_GET_ALL_CONTAINERS,
SC_CARDCTL_GIDS_GET_CONTAINER_DETAIL,
SC_CARDCTL_GIDS_SELECT_KEY_REFERENCE,
@@ -356,7 +356,7 @@ typedef struct sc_cardctl_pkcs11_init_pin {
*/
struct sc_cardctl_parsed_token_info {
unsigned int flags;
- struct sc_pkcs15_tokeninfo * tokeninfo;
+ struct sc_pkcs15_tokeninfo *tokeninfo;
};
/*
diff --git a/src/libopensc/cards.h b/src/libopensc/cards.h
index 8d58fb93..5a9797f7 100644
--- a/src/libopensc/cards.h
+++ b/src/libopensc/cards.h
@@ -119,7 +119,7 @@ enum {
SC_CARD_TYPE_OBERTHUR_32K_BIO,
SC_CARD_TYPE_OBERTHUR_64K,
/* Oberthur 'COSMO v7' with applet 'AuthentIC v3.2' */
- SC_CARD_TYPE_OBERTHUR_AUTHENTIC_3_2 = 11100,
+ SC_CARD_TYPE_OBERTHUR_AUTHENTIC_3_2 = 11100,
/* belpic driver */
SC_CARD_TYPE_BELPIC_BASE = 12000,
@@ -213,9 +213,9 @@ enum {
/* Spanish DNIe card */
SC_CARD_TYPE_DNIE_BASE = 27000,
- SC_CARD_TYPE_DNIE_BLANK, /* ATR LC byte: 00 */
- SC_CARD_TYPE_DNIE_ADMIN, /* ATR LC byte: 01 */
- SC_CARD_TYPE_DNIE_USER, /* ATR LC byte: 03 */
+ SC_CARD_TYPE_DNIE_BLANK, /* ATR LC byte: 00 */
+ SC_CARD_TYPE_DNIE_ADMIN, /* ATR LC byte: 01 */
+ SC_CARD_TYPE_DNIE_USER, /* ATR LC byte: 03 */
SC_CARD_TYPE_DNIE_TERMINATED, /* ATR LC byte: 0F */
/* JavaCards with isoApplet */
diff --git a/src/libopensc/pkcs15-prkey.c b/src/libopensc/pkcs15-prkey.c
index a6c05415..a56822c7 100644
--- a/src/libopensc/pkcs15-prkey.c
+++ b/src/libopensc/pkcs15-prkey.c
@@ -52,24 +52,23 @@
*/
#define C_ASN1_SUPPORTED_ALGORITHMS_SIZE (SC_MAX_SUPPORTED_ALGORITHMS + 1)
static const struct sc_asn1_entry c_asn1_supported_algorithms[C_ASN1_SUPPORTED_ALGORITHMS_SIZE] = {
- { "algorithmReference", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL },
- { "algorithmReference", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL },
- { "algorithmReference", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL },
- { "algorithmReference", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL },
- { "algorithmReference", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL },
- { "algorithmReference", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL },
- { "algorithmReference", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL },
- { "algorithmReference", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL },
- { "algorithmReference", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL },
- { "algorithmReference", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL },
- { "algorithmReference", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL },
- { "algorithmReference", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL },
- { "algorithmReference", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL },
- { "algorithmReference", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL },
- { "algorithmReference", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL },
- { "algorithmReference", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL },
- { NULL, 0, 0, 0, NULL, NULL }
-};
+ {"algorithmReference", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL},
+ {"algorithmReference", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL},
+ {"algorithmReference", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL},
+ {"algorithmReference", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL},
+ {"algorithmReference", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL},
+ {"algorithmReference", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL},
+ {"algorithmReference", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL},
+ {"algorithmReference", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL},
+ {"algorithmReference", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL},
+ {"algorithmReference", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL},
+ {"algorithmReference", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL},
+ {"algorithmReference", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL},
+ {"algorithmReference", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL},
+ {"algorithmReference", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL},
+ {"algorithmReference", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL},
+ {"algorithmReference", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL},
+ {NULL, 0, 0, 0, NULL, NULL}};
#define C_ASN1_COM_KEY_ATTR_SIZE 7
static const struct sc_asn1_entry c_asn1_com_key_attr[C_ASN1_COM_KEY_ATTR_SIZE] = {
diff --git a/src/libopensc/pkcs15-skey.c b/src/libopensc/pkcs15-skey.c
index 4e58355a..a3b35dd1 100644
--- a/src/libopensc/pkcs15-skey.c
+++ b/src/libopensc/pkcs15-skey.c
@@ -32,24 +32,23 @@
*/
#define C_ASN1_SUPPORTED_ALGORITHMS_SIZE (SC_MAX_SUPPORTED_ALGORITHMS + 1)
static const struct sc_asn1_entry c_asn1_supported_algorithms[C_ASN1_SUPPORTED_ALGORITHMS_SIZE] = {
- { "algorithmReference", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL },
- { "algorithmReference", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL },
- { "algorithmReference", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL },
- { "algorithmReference", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL },
- { "algorithmReference", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL },
- { "algorithmReference", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL },
- { "algorithmReference", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL },
- { "algorithmReference", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL },
- { "algorithmReference", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL },
- { "algorithmReference", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL },
- { "algorithmReference", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL },
- { "algorithmReference", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL },
- { "algorithmReference", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL },
- { "algorithmReference", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL },
- { "algorithmReference", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL },
- { "algorithmReference", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL },
- { NULL, 0, 0, 0, NULL, NULL }
-};
+ {"algorithmReference", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL},
+ {"algorithmReference", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL},
+ {"algorithmReference", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL},
+ {"algorithmReference", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL},
+ {"algorithmReference", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL},
+ {"algorithmReference", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL},
+ {"algorithmReference", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL},
+ {"algorithmReference", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL},
+ {"algorithmReference", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL},
+ {"algorithmReference", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL},
+ {"algorithmReference", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL},
+ {"algorithmReference", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL},
+ {"algorithmReference", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL},
+ {"algorithmReference", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL},
+ {"algorithmReference", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL},
+ {"algorithmReference", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL},
+ {NULL, 0, 0, 0, NULL, NULL}};
#define C_ASN1_COM_KEY_ATTR_SIZE 7
static const struct sc_asn1_entry c_asn1_com_key_attr[C_ASN1_COM_KEY_ATTR_SIZE] = {
diff --git a/src/libopensc/pkcs15.c b/src/libopensc/pkcs15.c
index 7f0c2251..1b5bc0ed 100644
--- a/src/libopensc/pkcs15.c
+++ b/src/libopensc/pkcs15.c
@@ -28,11 +28,11 @@
#include <assert.h>
#include <ctype.h>
-#include "internal.h"
-#include "cardctl.h"
-#include "pkcs15.h"
#include "asn1.h"
+#include "cardctl.h"
#include "common/libscdl.h"
+#include "internal.h"
+#include "pkcs15.h"
#ifdef ENABLE_OPENSSL
#include <openssl/sha.h>
@@ -67,24 +67,23 @@ static const struct sc_asn1_entry c_asn1_algorithm_info_parameters[3] = {
* in src/libopensc/types.h SC_MAX_SUPPORTED_ALGORITHMS defined as 16
*/
static const struct sc_asn1_entry c_asn1_supported_algorithms[SC_MAX_SUPPORTED_ALGORITHMS + 1] = {
- { "algorithmInfo", SC_ASN1_STRUCT, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_OPTIONAL, NULL, NULL },
- { "algorithmInfo", SC_ASN1_STRUCT, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_OPTIONAL, NULL, NULL },
- { "algorithmInfo", SC_ASN1_STRUCT, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_OPTIONAL, NULL, NULL },
- { "algorithmInfo", SC_ASN1_STRUCT, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_OPTIONAL, NULL, NULL },
- { "algorithmInfo", SC_ASN1_STRUCT, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_OPTIONAL, NULL, NULL },
- { "algorithmInfo", SC_ASN1_STRUCT, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_OPTIONAL, NULL, NULL },
- { "algorithmInfo", SC_ASN1_STRUCT, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_OPTIONAL, NULL, NULL },
- { "algorithmInfo", SC_ASN1_STRUCT, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_OPTIONAL, NULL, NULL },
- { "algorithmInfo", SC_ASN1_STRUCT, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_OPTIONAL, NULL, NULL },
- { "algorithmInfo", SC_ASN1_STRUCT, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_OPTIONAL, NULL, NULL },
- { "algorithmInfo", SC_ASN1_STRUCT, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_OPTIONAL, NULL, NULL },
- { "algorithmInfo", SC_ASN1_STRUCT, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_OPTIONAL, NULL, NULL },
- { "algorithmInfo", SC_ASN1_STRUCT, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_OPTIONAL, NULL, NULL },
- { "algorithmInfo", SC_ASN1_STRUCT, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_OPTIONAL, NULL, NULL },
- { "algorithmInfo", SC_ASN1_STRUCT, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_OPTIONAL, NULL, NULL },
- { "algorithmInfo", SC_ASN1_STRUCT, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_OPTIONAL, NULL, NULL },
- { NULL, 0, 0, 0, NULL, NULL }
-};
+ {"algorithmInfo", SC_ASN1_STRUCT, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_OPTIONAL, NULL, NULL},
+ {"algorithmInfo", SC_ASN1_STRUCT, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_OPTIONAL, NULL, NULL},
+ {"algorithmInfo", SC_ASN1_STRUCT, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_OPTIONAL, NULL, NULL},
+ {"algorithmInfo", SC_ASN1_STRUCT, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_OPTIONAL, NULL, NULL},
+ {"algorithmInfo", SC_ASN1_STRUCT, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_OPTIONAL, NULL, NULL},
+ {"algorithmInfo", SC_ASN1_STRUCT, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_OPTIONAL, NULL, NULL},
+ {"algorithmInfo", SC_ASN1_STRUCT, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_OPTIONAL, NULL, NULL},
+ {"algorithmInfo", SC_ASN1_STRUCT, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_OPTIONAL, NULL, NULL},
+ {"algorithmInfo", SC_ASN1_STRUCT, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_OPTIONAL, NULL, NULL},
+ {"algorithmInfo", SC_ASN1_STRUCT, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_OPTIONAL, NULL, NULL},
+ {"algorithmInfo", SC_ASN1_STRUCT, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_OPTIONAL, NULL, NULL},
+ {"algorithmInfo", SC_ASN1_STRUCT, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_OPTIONAL, NULL, NULL},
+ {"algorithmInfo", SC_ASN1_STRUCT, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_OPTIONAL, NULL, NULL},
+ {"algorithmInfo", SC_ASN1_STRUCT, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_OPTIONAL, NULL, NULL},
+ {"algorithmInfo", SC_ASN1_STRUCT, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_OPTIONAL, NULL, NULL},
+ {"algorithmInfo", SC_ASN1_STRUCT, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_OPTIONAL, NULL, NULL},
+ {NULL, 0, 0, 0, NULL, NULL}};
#define C_ASN1_LAST_UPDATE_SIZE 3
static const struct sc_asn1_entry c_asn1_last_update[C_ASN1_LAST_UPDATE_SIZE] = {
@@ -318,11 +317,10 @@ sc_pkcs15_encode_tokeninfo(sc_context_t *ctx, sc_pkcs15_tokeninfo_t *ti,
sc_format_asn1_entry(asn1_algo_infos[ii] + 1, &ti->supported_algos[ii].mechanism, &mechanism_len, 1);
sc_format_asn1_entry(asn1_algo_infos[ii] + 2,
asn1_algo_infos_parameters[ii], NULL, 1);
- if (!sc_valid_oid(&ti->supported_algos[ii].parameters)) {
+ if (!sc_valid_oid(&ti->supported_algos[ii].parameters)) {
sc_format_asn1_entry(asn1_algo_infos_parameters[ii] + 0,
NULL, NULL, 1);
- }
- else {
+ } else {
sc_format_asn1_entry(asn1_algo_infos_parameters[ii] + 1,
&ti->supported_algos[ii].parameters, &parameter_len, 0);
}
@@ -1168,7 +1166,7 @@ sc_pkcs15_bind_internal(struct sc_pkcs15_card *p15card, struct sc_aid *aid)
/* If card has not created algorithms, let it look at token info */
sc_log(ctx, " card->algorithms:%p card->algorithm_count:%d", card->algorithms, card->algorithm_count);
if (!card->algorithms && card->algorithm_count == 0) {
- struct sc_cardctl_parsed_token_info parsed_token_info;
+ struct sc_cardctl_parsed_token_info parsed_token_info;
sc_log(ctx, " passing sc_cardctl_parsed_token_info ");
/* TODO could set flags here */
@@ -1177,7 +1175,6 @@ sc_pkcs15_bind_internal(struct sc_pkcs15_card *p15card, struct sc_aid *aid)
sc_card_ctl(p15card->card, SC_CARDCTL_PARSED_TOKEN_INFO, &parsed_token_info);
}
-
if (!p15card->tokeninfo->serial_number && 0 == card->serialnr.len) {
sc_card_ctl(p15card->card, SC_CARDCTL_GET_SERIALNR, &card->serialnr);
}
diff --git a/src/libopensc/types.h b/src/libopensc/types.h
index 17035b55..c564189d 100644
--- a/src/libopensc/types.h
+++ b/src/libopensc/types.h
@@ -56,7 +56,7 @@ typedef unsigned char u8;
* src/libopensc/pkcs15-prkey.c and src/libopensc/pkcs15-skey.c
* `grep "src/libopensc/types.h SC_MAX_SUPPORTED_ALGORITHMS defined as"'
*/
-#define SC_MAX_SUPPORTED_ALGORITHMS 16
+#define SC_MAX_SUPPORTED_ALGORITHMS 16
struct sc_lv_data {
unsigned char *value;
diff --git a/src/tools/pkcs11-tool.c b/src/tools/pkcs11-tool.c
index b1674a76..a497ebf7 100644
--- a/src/tools/pkcs11-tool.c
+++ b/src/tools/pkcs11-tool.c
@@ -5045,7 +5045,7 @@ static int test_signature(CK_SESSION_HANDLE sess)
if (firstMechType == CKM_RSA_X_509) {
/* make sure our data is smaller than the modulus - 11 */
- memset(data, 0, 11); /* in effect is zero padding */
+ memset(data, 0, 11); /* in effect is zero padding */
}
ck_mech.mechanism = firstMechType;
diff --git a/src/tools/pkcs15-tool.c b/src/tools/pkcs15-tool.c
index 363bfb82..467f6c6a 100644
--- a/src/tools/pkcs15-tool.c
+++ b/src/tools/pkcs15-tool.c
@@ -54,10 +54,10 @@ typedef unsigned __int32 uint32_t;
#endif
#include <limits.h>
-#include "libopensc/pkcs15.h"
#include "libopensc/asn1.h"
-#include "util.h"
+#include "libopensc/pkcs15.h"
#include "pkcs11/pkcs11-display.h"
+#include "util.h"
static const char *app_name = "pkcs15-tool";
@@ -640,11 +640,11 @@ static void print_prkey_info(const struct sc_pkcs15_object *obj)
printf("\n");
printf("\tAlgo_refs : ");
/* zero may be valid and don't know how many were read print at least 1*/
- for (i = 0; i< SC_MAX_SUPPORTED_ALGORITHMS; i++) {
+ for (i = 0; i < SC_MAX_SUPPORTED_ALGORITHMS; i++) {
if (prkey->algo_refs[i] != 0)
last_algo_refs = i;
}
- for (i = 0; i< last_algo_refs + 1; i++) {
+ for (i = 0; i < last_algo_refs + 1; i++) {
printf("%s%u", (i == 0) ? "" : ", ", prkey->algo_refs[i]);
}
printf("\n");
@@ -1658,15 +1658,18 @@ static int list_apps(FILE *fout)
return 0;
}
-
static void print_supported_algo_info_operations(unsigned int operation)
{
size_t i;
- const char *operations[] = {
- "compute_checksum", "compute_signature", "verify_checksum", "verify_signature",
- "encipher", "decipher", "hash", "generate/derive_key"
- };
+ const char *operations[] = {"compute_checksum",
+ "compute_signature",
+ "verify_checksum",
+ "verify_signature",
+ "encipher",
+ "decipher",
+ "hash",
+ "generate/derive_key"};
const size_t operations_count = NELEMENTS(operations);
for (i = 0; i < operations_count; i++)
if (operation & (1 << i))
@@ -1706,30 +1709,30 @@ static void list_info(void)
}
printf("\n");
for (i = 0; i < SC_MAX_SUPPORTED_ALGORITHMS; i++) {
- struct sc_supported_algo_info * sa = &p15card->tokeninfo->supported_algos[i];
+ struct sc_supported_algo_info *sa = &p15card->tokeninfo->supported_algos[i];
- if (sa->reference == 0 && sa->reference == 0 && sa->mechanism == 0
- && sa->operations == 0 && sa->algo_ref == 0)
- break;
+ if (sa->reference == 0 && sa->reference == 0 && sa->mechanism == 0 && sa->operations == 0
+ && sa->algo_ref == 0)
+ break;
printf("\t\t sc_supported_algo_info[%d]:\n", i);
printf("\t\t\t reference : %u (0x%02x)\n", sa->reference, sa->reference);
printf("\t\t\t mechanism : [0x%02x] %s\n", sa->mechanism, lookup_enum(MEC_T, sa->mechanism));
if (sc_valid_oid(&sa->parameters)) {
printf("\t\t\t parameters: %i", sa->parameters.value[0]);
- for (idx = 1; idx < SC_MAX_OBJECT_ID_OCTETS && sa->parameters.value[idx] != -1 ; idx++)
+ for (idx = 1; idx < SC_MAX_OBJECT_ID_OCTETS && sa->parameters.value[idx] != -1; idx++)
printf(".%i", sa->parameters.value[idx]);
printf("\n");
}
- printf("\t\t\t operations : [0x%2.2x]",sa->operations);
+ printf("\t\t\t operations : [0x%2.2x]", sa->operations);
print_supported_algo_info_operations(sa->operations);
printf("\n");
- if (sc_valid_oid((const struct sc_object_id*)&sa->algo_id)) {
+ if (sc_valid_oid((const struct sc_object_id *)&sa->algo_id)) {
printf("\t\t\t algo_id : %i", sa->algo_id.value[0]);
- for (idx = 1; idx < SC_MAX_OBJECT_ID_OCTETS && sa->algo_id.value[idx] != -1 ; idx++)
+ for (idx = 1; idx < SC_MAX_OBJECT_ID_OCTETS && sa->algo_id.value[idx] != -1; idx++)
printf(".%i", sa->algo_id.value[idx]);
printf("\n");
}
- printf("\t\t\t algo_ref : [0x%02x]\n",sa->algo_ref);
+ printf("\t\t\t algo_ref : [0x%02x]\n", sa->algo_ref);
}
printf((compact) ? "\n" : "\n\n");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment