removed/fixed dead code

This commit is contained in:
Frank Morgner 2015-02-05 00:43:05 +01:00
parent a3fc62f79f
commit 11881a61b8
16 changed files with 37 additions and 154 deletions

View File

@ -662,7 +662,7 @@ static int asepcos_list_files(sc_card_t *card, u8 *buf, size_t blen)
/* 1. get currently selected DF */
r = asepcos_get_current_df_path(card, &bpath);
if (rv != SC_SUCCESS)
if (r != SC_SUCCESS)
return r;
/* 2. re-select DF to get the FID of the child EFs/DFs */
r = sc_select_file(card, &bpath, &tfile);

View File

@ -339,7 +339,7 @@ static int entersafe_transmit_apdu(sc_card_t *card, sc_apdu_t *apdu,
blocks=(apdu->lc+2)/8+1;
cipher_data_size=blocks*8;
cipher_data=malloc(cipher_data_size);
if(!cipher)
if(!cipher_data)
{
r = SC_ERROR_OUT_OF_MEMORY;
goto out;

View File

@ -473,8 +473,6 @@ static int ias_select_file(sc_card_t *card, const sc_path_t *in_path,
r = sc_transmit_apdu(card, &apdu);
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
if (file_out == NULL) {
if (apdu.sw1 == 0x61)
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, 0);
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, sc_check_sw(card, apdu.sw1, apdu.sw2));
}
}

View File

@ -2343,7 +2343,7 @@ iasecc_pin_reset(struct sc_card *card, struct sc_pin_cmd_data *data, int *tries_
if (scb & IASECC_SCB_METHOD_SM) {
rv = iasecc_sm_pin_reset(card, se_num, data);
LOG_FUNC_RETURN(ctx, rv);
LOG_TEST_RET(ctx, rv, "iasecc_sm_pin_reset() reset PUK error");
if (!need_all)
break;
@ -2396,7 +2396,6 @@ static int
iasecc_pin_cmd(struct sc_card *card, struct sc_pin_cmd_data *data, int *tries_left)
{
struct sc_context *ctx = card->ctx;
struct sc_apdu apdu;
int rv;
LOG_FUNC_CALLED(ctx);
@ -2407,29 +2406,24 @@ iasecc_pin_cmd(struct sc_card *card, struct sc_pin_cmd_data *data, int *tries_le
switch (data->cmd) {
case SC_PIN_CMD_VERIFY:
rv = iasecc_pin_verify(card, data->pin_type, data->pin_reference, data->pin1.data, data->pin1.len, tries_left);
LOG_FUNC_RETURN(ctx, rv);
break;
case SC_PIN_CMD_CHANGE:
if (data->pin_type == SC_AC_AUT)
rv = iasecc_keyset_change(card, data, tries_left);
else
rv = iasecc_pin_change(card, data, tries_left);
LOG_FUNC_RETURN(ctx, rv);
break;
case SC_PIN_CMD_UNBLOCK:
rv = iasecc_pin_reset(card, data, tries_left);
LOG_FUNC_RETURN(ctx, rv);
break;
case SC_PIN_CMD_GET_INFO:
rv = iasecc_pin_get_policy(card, data);
LOG_FUNC_RETURN(ctx, rv);
break;
default:
sc_log(ctx, "Other pin commands not supported yet: 0x%X", data->cmd);
LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "Non-supported PIN command");
rv = SC_ERROR_NOT_SUPPORTED;
}
rv = sc_transmit_apdu(card, &apdu);
LOG_TEST_RET(ctx, rv, "APDU transmit failed");
rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
LOG_TEST_RET(ctx, rv, "PIN cmd failed");
LOG_FUNC_RETURN(ctx, rv);
}

View File

@ -508,7 +508,7 @@ static int myeid_set_security_env_rsa(sc_card_t *card, const sc_security_env_t *
sc_apdu_t apdu;
u8 sbuf[SC_MAX_APDU_BUFFER_SIZE];
u8 *p;
int r, locked = 0;
int r;
assert(card != NULL && env != NULL);
LOG_FUNC_CALLED(card->ctx);
@ -564,11 +564,6 @@ static int myeid_set_security_env_rsa(sc_card_t *card, const sc_security_env_t *
apdu.datalen = r;
apdu.data = sbuf;
apdu.resplen = 0;
if (se_num > 0) {
r = sc_lock(card);
LOG_TEST_RET(card->ctx, r, "sc_lock() failed");
locked = 1;
}
if (apdu.datalen != 0)
{
r = sc_transmit_apdu(card, &apdu);
@ -586,16 +581,7 @@ static int myeid_set_security_env_rsa(sc_card_t *card, const sc_security_env_t *
goto err;
}
}
if (se_num <= 0)
return 0;
sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x22, 0xF2, se_num);
r = sc_transmit_apdu(card, &apdu);
sc_unlock(card);
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
return sc_check_sw(card, apdu.sw1, apdu.sw2);
err:
if (locked)
sc_unlock(card);
LOG_FUNC_RETURN(card->ctx, r);
}
@ -605,7 +591,7 @@ static int myeid_set_security_env_ec(sc_card_t *card, const sc_security_env_t *e
sc_apdu_t apdu;
u8 sbuf[SC_MAX_APDU_BUFFER_SIZE];
u8 *p;
int r, locked = 0;
int r;
assert(card != NULL && env != NULL);
LOG_FUNC_CALLED(card->ctx);
@ -661,11 +647,6 @@ static int myeid_set_security_env_ec(sc_card_t *card, const sc_security_env_t *e
apdu.datalen = r;
apdu.data = sbuf;
apdu.resplen = 0;
if (se_num > 0) {
r = sc_lock(card);
LOG_TEST_RET(card->ctx, r, "sc_lock() failed");
locked = 1;
}
if (apdu.datalen != 0)
{
r = sc_transmit_apdu(card, &apdu);
@ -683,16 +664,7 @@ static int myeid_set_security_env_ec(sc_card_t *card, const sc_security_env_t *e
goto err;
}
}
if (se_num <= 0)
return 0;
sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x22, 0xF2, se_num);
r = sc_transmit_apdu(card, &apdu);
sc_unlock(card);
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
return sc_check_sw(card, apdu.sw1, apdu.sw2);
err:
if (locked)
sc_unlock(card);
LOG_FUNC_RETURN(card->ctx, r);
}

View File

@ -1227,8 +1227,6 @@ sc_pkcs15_read_der_file(sc_context_t *ctx, char * filename,
rbuf = NULL;
r = rbuflen;
out:
if (rbuf)
free(rbuf);
if (f > 0)
close(f);

View File

@ -203,15 +203,13 @@ sc_pkcs15_bind_synthetic(sc_pkcs15_card_t *p15card)
free(blocks);
}
/* Total failure */
LOG_FUNC_RETURN(ctx, SC_ERROR_WRONG_CARD);
out: if (r == SC_SUCCESS) {
out:
if (r == SC_SUCCESS) {
p15card->magic = SC_PKCS15_CARD_MAGIC;
p15card->flags |= SC_PKCS15_CARD_FLAG_EMULATED;
}
else if (r != SC_ERROR_WRONG_CARD) {
sc_log(ctx, "Failed to load card emulator: %s", sc_strerror(r));
} else {
if (r != SC_ERROR_WRONG_CARD)
sc_log(ctx, "Failed to load card emulator: %s", sc_strerror(r));
}
LOG_FUNC_RETURN(ctx, r);

View File

@ -70,7 +70,7 @@ static int sc_pkcs15emu_westcos_init(sc_pkcs15_card_t * p15card)
}
else
{
for (i = 0; i < 1; i++) {
for (i = 0; i <= 1; i++) {
unsigned int flags;
struct sc_pkcs15_auth_info pin_info;
struct sc_pkcs15_object pin_obj;

View File

@ -108,7 +108,7 @@ int sc_bin_to_hex(const u8 *in, size_t in_len, char *out, size_t out_len,
pos += 2;
}
*pos = '\0';
return 0;
return SC_SUCCESS;
}
/*
@ -299,7 +299,7 @@ int sc_append_path_id(sc_path_t *dest, const u8 *id, size_t idlen)
return SC_ERROR_INVALID_ARGUMENTS;
memcpy(dest->value + dest->len, id, idlen);
dest->len += idlen;
return 0;
return SC_SUCCESS;
}
int sc_append_file_id(sc_path_t *dest, unsigned int fid)
@ -417,21 +417,21 @@ int sc_file_add_acl_entry(sc_file_t *file, unsigned int operation,
case SC_AC_NEVER:
sc_file_clear_acl_entries(file, operation);
file->acl[operation] = (sc_acl_entry_t *) 1;
return 0;
return SC_SUCCESS;
case SC_AC_NONE:
sc_file_clear_acl_entries(file, operation);
file->acl[operation] = (sc_acl_entry_t *) 2;
return 0;
return SC_SUCCESS;
case SC_AC_UNKNOWN:
sc_file_clear_acl_entries(file, operation);
file->acl[operation] = (sc_acl_entry_t *) 3;
return 0;
return SC_SUCCESS;
default:
/* NONE and UNKNOWN get zapped when a new AC is added.
* If the ACL is NEVER, additional entries will be
* dropped silently. */
if (file->acl[operation] == (sc_acl_entry_t *) 1)
return 0;
return SC_SUCCESS;
if (file->acl[operation] == (sc_acl_entry_t *) 2
|| file->acl[operation] == (sc_acl_entry_t *) 3)
file->acl[operation] = NULL;
@ -441,7 +441,7 @@ int sc_file_add_acl_entry(sc_file_t *file, unsigned int operation,
* of the card's AC with OpenSC's), don't add it again. */
for (p = file->acl[operation]; p != NULL; p = p->next) {
if ((p->method == method) && (p->key_ref == key_ref))
return 0;
return SC_SUCCESS;
}
_new = malloc(sizeof(sc_acl_entry_t));
@ -454,13 +454,13 @@ int sc_file_add_acl_entry(sc_file_t *file, unsigned int operation,
p = file->acl[operation];
if (p == NULL) {
file->acl[operation] = _new;
return 0;
return SC_SUCCESS;
}
while (p->next != NULL)
p = p->next;
p->next = _new;
return 0;
return SC_SUCCESS;
}
const sc_acl_entry_t * sc_file_get_acl_entry(const sc_file_t *file,
@ -629,7 +629,7 @@ int sc_file_set_prop_attr(sc_file_t *file, const u8 *prop_attr,
free(file->prop_attr);
file->prop_attr = NULL;
file->prop_attr_len = 0;
return 0;
return SC_SUCCESS;
}
tmp = (u8 *) realloc(file->prop_attr, prop_attr_len);
if (!tmp) {
@ -643,7 +643,7 @@ int sc_file_set_prop_attr(sc_file_t *file, const u8 *prop_attr,
memcpy(file->prop_attr, prop_attr, prop_attr_len);
file->prop_attr_len = prop_attr_len;
return 0;
return SC_SUCCESS;
}
int sc_file_set_type_attr(sc_file_t *file, const u8 *type_attr,
@ -657,7 +657,7 @@ int sc_file_set_type_attr(sc_file_t *file, const u8 *type_attr,
free(file->type_attr);
file->type_attr = NULL;
file->type_attr_len = 0;
return 0;
return SC_SUCCESS;
}
tmp = (u8 *) realloc(file->type_attr, type_attr_len);
if (!tmp) {
@ -671,7 +671,7 @@ int sc_file_set_type_attr(sc_file_t *file, const u8 *type_attr,
memcpy(file->type_attr, type_attr, type_attr_len);
file->type_attr_len = type_attr_len;
return 0;
return SC_SUCCESS;
}
@ -781,12 +781,12 @@ int _sc_parse_atr(sc_reader_t *reader)
}
}
if (atr_len <= 0)
return 0;
return SC_SUCCESS;
if (n_hist > atr_len)
n_hist = atr_len;
reader->atr_info.hist_bytes_len = n_hist;
reader->atr_info.hist_bytes = p;
return 0;
return SC_SUCCESS;
}
void *sc_mem_alloc_secure(sc_context_t *ctx, size_t len)
@ -840,7 +840,7 @@ int sc_mem_reverse(unsigned char *buf, size_t len)
*(buf + len - 1 - ii) = ch;
}
return 0;
return SC_SUCCESS;
}
static int

View File

@ -2031,7 +2031,7 @@ pkcs15_create_private_key(struct sc_pkcs11_slot *slot, struct sc_profile *profil
}
/* CKA_VALUE arrives in little endian form. pkcs15init framework expects it in a big endian one. */
rc = sc_mem_reverse(gost->d.data, gost->d.len);
if (rv) {
if (rc != SC_SUCCESS) {
rv = sc_to_cryptoki_error(rc, "C_CreateObject");
goto out;
}

View File

@ -760,57 +760,7 @@ C_SignRecoverInit(CK_SESSION_HANDLE hSession, /* the session's handle */
CK_MECHANISM_PTR pMechanism, /* the signature mechanism */
CK_OBJECT_HANDLE hKey) /* handle of the signature key */
{
CK_RV rv;
CK_BBOOL can_sign;
CK_KEY_TYPE key_type;
CK_ATTRIBUTE sign_attribute = { CKA_SIGN, &can_sign, sizeof(can_sign) };
CK_ATTRIBUTE key_type_attr = { CKA_KEY_TYPE, &key_type, sizeof(key_type) };
struct sc_pkcs11_session *session;
struct sc_pkcs11_object *object;
/* FIXME #47: C_SignRecover is not implemented */
return CKR_FUNCTION_NOT_SUPPORTED;
if (pMechanism == NULL_PTR)
return CKR_ARGUMENTS_BAD;
rv = sc_pkcs11_lock();
if (rv != CKR_OK)
return rv;
rv = get_object_from_session(hSession, hKey, &session, &object);
if (rv != CKR_OK) {
if (rv == CKR_OBJECT_HANDLE_INVALID)
rv = CKR_KEY_HANDLE_INVALID;
goto out;
}
if (object->ops->sign == NULL_PTR) {
rv = CKR_KEY_TYPE_INCONSISTENT;
goto out;
}
rv = object->ops->get_attribute(session, object, &sign_attribute);
if (rv != CKR_OK || !can_sign) {
rv = CKR_KEY_TYPE_INCONSISTENT;
goto out;
}
rv = object->ops->get_attribute(session, object, &key_type_attr);
if (rv != CKR_OK) {
rv = CKR_KEY_TYPE_INCONSISTENT;
goto out;
}
/* XXX: need to tell the signature algorithm that we want
* to recover the signature */
sc_log(context, "SignRecover operation initialized\n");
rv = sc_pkcs11_sign_init(session, pMechanism, object, key_type);
out:
sc_log(context, "C_SignRecoverInit() = %sn", lookup_enum ( RV_T, rv ));
sc_pkcs11_unlock();
return rv;
}

View File

@ -363,10 +363,7 @@ authentic_sdo_allocate_prvkey(struct sc_profile *profile, struct sc_card *card,
sc_log(ctx, "sdo(mech:%X,id:%X,acls:%s)", sdo->docp.mech, sdo->docp.id,
sc_dump_hex(sdo->docp.acl_data, sdo->docp.acl_data_len));
if (out)
*out = sdo;
else
free(sdo);
*out = sdo;
LOG_FUNC_RETURN(ctx, SC_SUCCESS);
}

View File

@ -283,12 +283,6 @@ muscle_generate_key(sc_profile_t *profile, sc_pkcs15_card_t *p15card,
pubkey->u.rsa.exponent.len = extArgs.expLength;
pubkey->u.rsa.exponent.data = extArgs.expValue;
if (r < 0) {
if (pubkey->u.rsa.modulus.data)
free (pubkey->u.rsa.modulus.data);
if (pubkey->u.rsa.exponent.data)
free (pubkey->u.rsa.exponent.data);
}
return r;
}

View File

@ -423,9 +423,6 @@ myeid_create_key(struct sc_profile *profile, struct sc_pkcs15_card *p15card,
break;
case SC_PKCS15_TYPE_PRKEY_EC:
LOG_TEST_RET(ctx, SC_ERROR_NOT_IMPLEMENTED, "20140202: waiting for cards and specification from Aventra. VTA");
if (sc_card_find_ec_alg(p15card->card, keybits) == NULL)
LOG_TEST_RET(ctx, SC_ERROR_INVALID_ARGUMENTS,
"Unsupported EC key size");
break;
default:
LOG_TEST_RET(ctx, SC_ERROR_INVALID_ARGUMENTS,
@ -487,13 +484,6 @@ myeid_store_key(struct sc_profile *profile, struct sc_pkcs15_card *p15card,
break;
case SC_PKCS15_TYPE_PRKEY_EC:
LOG_TEST_RET(ctx, SC_ERROR_NOT_IMPLEMENTED, "20140202: waiting for cards and specification from Aventra. VTA");
if (sc_card_find_ec_alg(p15card->card, keybits) == NULL)
LOG_TEST_RET(ctx, SC_ERROR_INVALID_ARGUMENTS, "Unsupported EC key size");
if(key_info->field_length != 0)
keybits = key_info->field_length;
else
key_info->field_length = keybits;
break;
default:
LOG_TEST_RET(ctx, SC_ERROR_INVALID_ARGUMENTS, "Store key failed: Unsupported key type");
@ -576,14 +566,6 @@ myeid_generate_key(struct sc_profile *profile, struct sc_pkcs15_card *p15card,
break;
case SC_PKCS15_TYPE_PRKEY_EC:
LOG_TEST_RET(ctx, SC_ERROR_NOT_IMPLEMENTED, "20140202: waiting for cards and specification from Aventra. VTA");
if (sc_card_find_ec_alg(p15card->card, keybits) == NULL)
LOG_TEST_RET(ctx, SC_ERROR_INVALID_ARGUMENTS, "Unsupported EC key size");
if(key_info->field_length != 0)
keybits = key_info->field_length;
else
key_info->field_length = keybits;
break;
default:
LOG_TEST_RET(ctx, SC_ERROR_INVALID_ARGUMENTS, "Unsupported key type");

View File

@ -278,7 +278,7 @@ void scconf_parse_token(scconf_parser * parser, int token_type, const char *toke
scconf_parse_warning_expect(parser, "\"");
} else {
/* stoken */
stoken = token ? strdup(token) : NULL;
stoken = strdup(token);
if (stoken) {
stoken[len - 1] = '\0';
}

View File

@ -149,7 +149,7 @@ static int opensc_get_conf_entry(const char *config)
}
section = buffer;
name = section == NULL ? NULL : strchr(section+1, ':');
name = strchr(section+1, ':');
key = name == NULL ? NULL : strchr(name+1, ':');
if (key == NULL) {
r = EINVAL;
@ -203,7 +203,7 @@ static int opensc_set_conf_entry(const char *config)
}
section = buffer;
name = section == NULL ? NULL : strchr(section+1, ':');
name = strchr(section+1, ':');
key = name == NULL ? NULL : strchr(name+1, ':');
value = key == NULL ? NULL : strchr(key+1, ':');
if (value == NULL) {