tcos: fix indentation and braces

Increase readability. No content-based changes.
This commit is contained in:
Julian Strobl 2019-12-31 16:44:20 +01:00 committed by Frank Morgner
parent 45e29056cc
commit 6b84407c3d
1 changed files with 124 additions and 129 deletions

View File

@ -166,8 +166,7 @@ static int tcos_construct_fci(const sc_file_t *file,
if (file->namelen) { if (file->namelen) {
sc_asn1_put_tag(0x84, file->name, file->namelen, sc_asn1_put_tag(0x84, file->name, file->namelen,
p, 16, &p); p, 16, &p);
} } else {
else {
/* TCOS needs one, so we use a faked one */ /* TCOS needs one, so we use a faked one */
snprintf ((char *) buf, sizeof(buf)-1, "foo-%lu", snprintf ((char *) buf, sizeof(buf)-1, "foo-%lu",
(unsigned long) time (NULL)); (unsigned long) time (NULL));
@ -179,8 +178,7 @@ static int tcos_construct_fci(const sc_file_t *file,
if (file->prop_attr_len && file->prop_attr) { if (file->prop_attr_len && file->prop_attr) {
n = file->prop_attr_len; n = file->prop_attr_len;
memcpy(buf, file->prop_attr, n); memcpy(buf, file->prop_attr, n);
} } else {
else {
n = 0; n = 0;
buf[n++] = 0x01; /* not invalidated, permanent */ buf[n++] = 0x01; /* not invalidated, permanent */
if (file->type == SC_FILE_TYPE_WORKING_EF) if (file->type == SC_FILE_TYPE_WORKING_EF)
@ -192,8 +190,7 @@ static int tcos_construct_fci(const sc_file_t *file,
if (file->sec_attr_len && file->sec_attr) { if (file->sec_attr_len && file->sec_attr) {
memcpy(buf, file->sec_attr, file->sec_attr_len); memcpy(buf, file->sec_attr, file->sec_attr_len);
n = file->sec_attr_len; n = file->sec_attr_len;
} } else {
else {
/* no attributes given - fall back to default one */ /* no attributes given - fall back to default one */
memcpy (buf+ 0, "\xa4\x00\x00\x00\xff\xff", 6); /* select */ memcpy (buf+ 0, "\xa4\x00\x00\x00\xff\xff", 6); /* select */
memcpy (buf+ 6, "\xb0\x00\x00\x00\xff\xff", 6); /* read bin */ memcpy (buf+ 6, "\xb0\x00\x00\x00\xff\xff", 6); /* read bin */
@ -235,7 +232,7 @@ static int tcos_create_file(sc_card_t *card, sc_file_t *file)
} }
static unsigned int map_operations (int commandbyte ) static unsigned int map_operations (int commandbyte)
{ {
unsigned int op = (unsigned int)-1; unsigned int op = (unsigned int)-1;
@ -282,16 +279,16 @@ static void parse_sec_attr(sc_card_t *card,
SC_AC_NONE, SC_AC_KEY_REF_NONE); SC_AC_NONE, SC_AC_KEY_REF_NONE);
for (; len >= 6; len -= 6, buf += 6) { for (; len >= 6; len -= 6, buf += 6) {
/* FIXME: temporary hacks */ /* FIXME: temporary hacks */
if (!memcmp(buf, "\xa4\x00\x00\x00\xff\xff", 6)) /* select */ if (!memcmp(buf, "\xa4\x00\x00\x00\xff\xff", 6)) {/* select */
sc_file_add_acl_entry (file, SC_AC_OP_SELECT, sc_file_add_acl_entry (file, SC_AC_OP_SELECT,
SC_AC_NONE, SC_AC_KEY_REF_NONE); SC_AC_NONE, SC_AC_KEY_REF_NONE);
else if (!memcmp(buf, "\xb0\x00\x00\x00\xff\xff", 6)) /*read*/ } else if (!memcmp(buf, "\xb0\x00\x00\x00\xff\xff", 6)) {/*read*/
sc_file_add_acl_entry (file, SC_AC_OP_READ, sc_file_add_acl_entry (file, SC_AC_OP_READ,
SC_AC_NONE, SC_AC_KEY_REF_NONE); SC_AC_NONE, SC_AC_KEY_REF_NONE);
else if (!memcmp(buf, "\xd6\x00\x00\x00\xff\xff", 6)) /*upd*/ } else if (!memcmp(buf, "\xd6\x00\x00\x00\xff\xff", 6)) {/*upd*/
sc_file_add_acl_entry (file, SC_AC_OP_UPDATE, sc_file_add_acl_entry (file, SC_AC_OP_UPDATE,
SC_AC_NONE, SC_AC_KEY_REF_NONE); SC_AC_NONE, SC_AC_KEY_REF_NONE);
else if (!memcmp(buf, "\x60\x00\x00\x00\xff\xff", 6)) {/*adm */ } else if (!memcmp(buf, "\x60\x00\x00\x00\xff\xff", 6)) {/*adm */
sc_file_add_acl_entry (file, SC_AC_OP_WRITE, sc_file_add_acl_entry (file, SC_AC_OP_WRITE,
SC_AC_NONE, SC_AC_KEY_REF_NONE); SC_AC_NONE, SC_AC_KEY_REF_NONE);
sc_file_add_acl_entry (file, SC_AC_OP_CREATE, sc_file_add_acl_entry (file, SC_AC_OP_CREATE,
@ -300,15 +297,13 @@ static void parse_sec_attr(sc_card_t *card,
SC_AC_NONE, SC_AC_KEY_REF_NONE); SC_AC_NONE, SC_AC_KEY_REF_NONE);
sc_file_add_acl_entry (file, SC_AC_OP_REHABILITATE, sc_file_add_acl_entry (file, SC_AC_OP_REHABILITATE,
SC_AC_NONE, SC_AC_KEY_REF_NONE); SC_AC_NONE, SC_AC_KEY_REF_NONE);
} } else {
else {
/* the first byte tells use the command or the /* the first byte tells use the command or the
command group. We have to mask bit 0 command group. We have to mask bit 0
because this one distinguish between AND/OR because this one distinguish between AND/OR
combination of PINs*/ combination of PINs*/
op = map_operations (buf[0]); op = map_operations (buf[0]);
if (op == (unsigned int)-1) if (op == (unsigned int)-1) {
{
sc_log(card->ctx, sc_log(card->ctx,
"Unknown security command byte %02x\n", "Unknown security command byte %02x\n",
buf[0]); buf[0]);
@ -396,7 +391,7 @@ static int tcos_select_file(sc_card_t *card,
r = sc_check_sw(card, apdu.sw1, apdu.sw2); r = sc_check_sw(card, apdu.sw1, apdu.sw2);
if (r || file_out == NULL) SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_VERBOSE, r); if (r || file_out == NULL) SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_VERBOSE, r);
if (apdu.resplen < 1 || apdu.resp[0] != 0x62){ if (apdu.resplen < 1 || apdu.resp[0] != 0x62) {
sc_log(ctx, "received invalid template %02X\n", apdu.resp[0]); sc_log(ctx, "received invalid template %02X\n", apdu.resp[0]);
SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_UNKNOWN_DATA_RECEIVED); SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_UNKNOWN_DATA_RECEIVED);
} }
@ -487,7 +482,7 @@ static int tcos_set_security_env(sc_card_t *card, const sc_security_env_t *env,
tcos3=(card->type==SC_CARD_TYPE_TCOS_V3); tcos3=(card->type==SC_CARD_TYPE_TCOS_V3);
data=(tcos_data *)card->drv_data; data=(tcos_data *)card->drv_data;
if (se_num || (env->operation!=SC_SEC_OPERATION_DECIPHER && env->operation!=SC_SEC_OPERATION_SIGN)){ if (se_num || (env->operation!=SC_SEC_OPERATION_DECIPHER && env->operation!=SC_SEC_OPERATION_SIGN)) {
LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ARGUMENTS); LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ARGUMENTS);
} }
if(!(env->flags & SC_SEC_ENV_KEY_REF_PRESENT)) if(!(env->flags & SC_SEC_ENV_KEY_REF_PRESENT))
@ -552,8 +547,8 @@ static int tcos_compute_signature(sc_card_t *card, const u8 * data, size_t datal
// We can sign (key length / 8) bytes // We can sign (key length / 8) bytes
if (datalen > 256) SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_INVALID_ARGUMENTS); if (datalen > 256) SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_INVALID_ARGUMENTS);
if(((tcos_data *)card->drv_data)->next_sign){ if(((tcos_data *)card->drv_data)->next_sign) {
if(datalen>48){ if(datalen>48) {
sc_log(card->ctx, "Data to be signed is too long (TCOS supports max. 48 bytes)\n"); sc_log(card->ctx, "Data to be signed is too long (TCOS supports max. 48 bytes)\n");
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_INVALID_ARGUMENTS); SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_INVALID_ARGUMENTS);
} }
@ -636,7 +631,7 @@ static int tcos_decipher(sc_card_t *card, const u8 * crgram, size_t crgram_len,
if (apdu.sw1==0x90 && apdu.sw2==0x00) { if (apdu.sw1==0x90 && apdu.sw2==0x00) {
size_t len= (apdu.resplen>outlen) ? outlen : apdu.resplen; size_t len= (apdu.resplen>outlen) ? outlen : apdu.resplen;
unsigned int offset=0; unsigned int offset=0;
if(tcos3 && (data->pad_flags & SC_ALGORITHM_RSA_PAD_PKCS1) && apdu.resp[0]==0 && apdu.resp[1]==2){ if(tcos3 && (data->pad_flags & SC_ALGORITHM_RSA_PAD_PKCS1) && apdu.resp[0]==0 && apdu.resp[1]==2) {
offset=2; while(offset<len && apdu.resp[offset]!=0) ++offset; offset=2; while(offset<len && apdu.resp[offset]!=0) ++offset;
offset=(offset<len-1) ? offset+1 : 0; offset=(offset<len-1) ? offset+1 : 0;
} }