tcos: fix indentation and braces
Increase readability. No content-based changes.
This commit is contained in:
parent
45e29056cc
commit
6b84407c3d
@ -86,7 +86,7 @@ static int tcos_match_card(sc_card_t *card)
|
|||||||
|
|
||||||
static int tcos_init(sc_card_t *card)
|
static int tcos_init(sc_card_t *card)
|
||||||
{
|
{
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
|
|
||||||
tcos_data *data = malloc(sizeof(tcos_data));
|
tcos_data *data = malloc(sizeof(tcos_data));
|
||||||
if (!data) return SC_ERROR_OUT_OF_MEMORY;
|
if (!data) return SC_ERROR_OUT_OF_MEMORY;
|
||||||
@ -95,20 +95,20 @@ static int tcos_init(sc_card_t *card)
|
|||||||
card->drv_data = (void *)data;
|
card->drv_data = (void *)data;
|
||||||
card->cla = 0x00;
|
card->cla = 0x00;
|
||||||
|
|
||||||
flags = SC_ALGORITHM_RSA_RAW;
|
flags = SC_ALGORITHM_RSA_RAW;
|
||||||
flags |= SC_ALGORITHM_RSA_PAD_PKCS1;
|
flags |= SC_ALGORITHM_RSA_PAD_PKCS1;
|
||||||
flags |= SC_ALGORITHM_RSA_HASH_NONE;
|
flags |= SC_ALGORITHM_RSA_HASH_NONE;
|
||||||
|
|
||||||
_sc_card_add_rsa_alg(card, 512, 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, 768, flags, 0);
|
||||||
_sc_card_add_rsa_alg(card, 1024, flags, 0);
|
_sc_card_add_rsa_alg(card, 1024, flags, 0);
|
||||||
|
|
||||||
if (card->type == SC_CARD_TYPE_TCOS_V3) {
|
if (card->type == SC_CARD_TYPE_TCOS_V3) {
|
||||||
card->caps |= SC_CARD_CAP_APDU_EXT;
|
card->caps |= SC_CARD_CAP_APDU_EXT;
|
||||||
_sc_card_add_rsa_alg(card, 1280, flags, 0);
|
_sc_card_add_rsa_alg(card, 1280, flags, 0);
|
||||||
_sc_card_add_rsa_alg(card, 1536, flags, 0);
|
_sc_card_add_rsa_alg(card, 1536, flags, 0);
|
||||||
_sc_card_add_rsa_alg(card, 1792, flags, 0);
|
_sc_card_add_rsa_alg(card, 1792, flags, 0);
|
||||||
_sc_card_add_rsa_alg(card, 2048, flags, 0);
|
_sc_card_add_rsa_alg(card, 2048, flags, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -124,20 +124,20 @@ static int tcos_construct_fci(const sc_file_t *file,
|
|||||||
{
|
{
|
||||||
u8 *p = out;
|
u8 *p = out;
|
||||||
u8 buf[64];
|
u8 buf[64];
|
||||||
size_t n;
|
size_t n;
|
||||||
|
|
||||||
/* FIXME: possible buffer overflow */
|
/* FIXME: possible buffer overflow */
|
||||||
|
|
||||||
*p++ = 0x6F; /* FCI */
|
*p++ = 0x6F; /* FCI */
|
||||||
p++;
|
p++;
|
||||||
|
|
||||||
/* File size */
|
/* File size */
|
||||||
buf[0] = (file->size >> 8) & 0xFF;
|
buf[0] = (file->size >> 8) & 0xFF;
|
||||||
buf[1] = file->size & 0xFF;
|
buf[1] = file->size & 0xFF;
|
||||||
sc_asn1_put_tag(0x81, buf, 2, p, 16, &p);
|
sc_asn1_put_tag(0x81, buf, 2, p, 16, &p);
|
||||||
|
|
||||||
/* File descriptor */
|
/* File descriptor */
|
||||||
n = 0;
|
n = 0;
|
||||||
buf[n] = file->shareable ? 0x40 : 0;
|
buf[n] = file->shareable ? 0x40 : 0;
|
||||||
switch (file->type) {
|
switch (file->type) {
|
||||||
case SC_FILE_TYPE_WORKING_EF:
|
case SC_FILE_TYPE_WORKING_EF:
|
||||||
@ -149,63 +149,60 @@ static int tcos_construct_fci(const sc_file_t *file,
|
|||||||
return SC_ERROR_NOT_SUPPORTED;
|
return SC_ERROR_NOT_SUPPORTED;
|
||||||
}
|
}
|
||||||
buf[n++] |= file->ef_structure & 7;
|
buf[n++] |= file->ef_structure & 7;
|
||||||
if ( (file->ef_structure & 7) > 1) {
|
if ( (file->ef_structure & 7) > 1) {
|
||||||
/* record structured file */
|
/* record structured file */
|
||||||
buf[n++] = 0x41; /* indicate 3rd byte */
|
buf[n++] = 0x41; /* indicate 3rd byte */
|
||||||
buf[n++] = file->record_length;
|
buf[n++] = file->record_length;
|
||||||
}
|
}
|
||||||
sc_asn1_put_tag(0x82, buf, n, p, 8, &p);
|
sc_asn1_put_tag(0x82, buf, n, p, 8, &p);
|
||||||
|
|
||||||
/* File identifier */
|
/* File identifier */
|
||||||
buf[0] = (file->id >> 8) & 0xFF;
|
buf[0] = (file->id >> 8) & 0xFF;
|
||||||
buf[1] = file->id & 0xFF;
|
buf[1] = file->id & 0xFF;
|
||||||
sc_asn1_put_tag(0x83, buf, 2, p, 16, &p);
|
sc_asn1_put_tag(0x83, buf, 2, p, 16, &p);
|
||||||
|
|
||||||
/* Directory name */
|
/* Directory name */
|
||||||
if (file->type == SC_FILE_TYPE_DF) {
|
if (file->type == SC_FILE_TYPE_DF) {
|
||||||
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));
|
||||||
sc_asn1_put_tag(0x84, buf, strlen ((char *) buf), p, 16, &p);
|
sc_asn1_put_tag(0x84, buf, strlen ((char *) buf), p, 16, &p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* File descriptor extension */
|
/* File descriptor extension */
|
||||||
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)
|
buf[n++] = 0x00; /* generic data file */
|
||||||
buf[n++] = 0x00; /* generic data file */
|
}
|
||||||
}
|
sc_asn1_put_tag(0x85, buf, n, p, 16, &p);
|
||||||
sc_asn1_put_tag(0x85, buf, n, p, 16, &p);
|
|
||||||
|
|
||||||
/* Security attributes */
|
/* Security attributes */
|
||||||
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 {
|
||||||
|
/* no attributes given - fall back to default one */
|
||||||
|
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+12, "\xd6\x00\x00\x00\xff\xff", 6); /* upd bin */
|
||||||
|
memcpy (buf+18, "\x60\x00\x00\x00\xff\xff", 6); /* admin grp*/
|
||||||
|
n = 24;
|
||||||
}
|
}
|
||||||
else {
|
sc_asn1_put_tag(0x86, buf, n, p, sizeof (buf), &p);
|
||||||
/* no attributes given - fall back to default one */
|
|
||||||
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+12, "\xd6\x00\x00\x00\xff\xff", 6); /* upd bin */
|
|
||||||
memcpy (buf+18, "\x60\x00\x00\x00\xff\xff", 6); /* admin grp*/
|
|
||||||
n = 24;
|
|
||||||
}
|
|
||||||
sc_asn1_put_tag(0x86, buf, n, p, sizeof (buf), &p);
|
|
||||||
|
|
||||||
|
|
||||||
/* fixup length of FCI */
|
/* fixup length of FCI */
|
||||||
out[1] = p - out - 2;
|
out[1] = p - out - 2;
|
||||||
|
|
||||||
*outlen = p - out;
|
*outlen = p - out;
|
||||||
return 0;
|
return 0;
|
||||||
@ -224,7 +221,7 @@ static int tcos_create_file(sc_card_t *card, sc_file_t *file)
|
|||||||
LOG_TEST_RET(card->ctx, r, "tcos_construct_fci() failed");
|
LOG_TEST_RET(card->ctx, r, "tcos_construct_fci() failed");
|
||||||
|
|
||||||
sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0xE0, 0x00, 0x00);
|
sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0xE0, 0x00, 0x00);
|
||||||
apdu.cla |= 0x80; /* this is an proprietary extension */
|
apdu.cla |= 0x80; /* this is an proprietary extension */
|
||||||
apdu.lc = len;
|
apdu.lc = len;
|
||||||
apdu.datalen = len;
|
apdu.datalen = len;
|
||||||
apdu.data = sbuf;
|
apdu.data = sbuf;
|
||||||
@ -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;
|
||||||
|
|
||||||
@ -272,72 +269,70 @@ static unsigned int map_operations (int commandbyte )
|
|||||||
static void parse_sec_attr(sc_card_t *card,
|
static void parse_sec_attr(sc_card_t *card,
|
||||||
sc_file_t *file, const u8 *buf, size_t len)
|
sc_file_t *file, const u8 *buf, size_t len)
|
||||||
{
|
{
|
||||||
unsigned int op;
|
unsigned int op;
|
||||||
|
|
||||||
/* list directory is not covered by ACLs - so always add an entry */
|
/* list directory is not covered by ACLs - so always add an entry */
|
||||||
sc_file_add_acl_entry (file, SC_AC_OP_LIST_FILES,
|
sc_file_add_acl_entry (file, SC_AC_OP_LIST_FILES,
|
||||||
SC_AC_NONE, SC_AC_KEY_REF_NONE);
|
SC_AC_NONE, SC_AC_KEY_REF_NONE);
|
||||||
/* FIXME: check for what LOCK is used */
|
/* FIXME: check for what LOCK is used */
|
||||||
sc_file_add_acl_entry (file, SC_AC_OP_LOCK,
|
sc_file_add_acl_entry (file, SC_AC_OP_LOCK,
|
||||||
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,
|
||||||
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_INVALIDATE,
|
sc_file_add_acl_entry (file, SC_AC_OP_INVALIDATE,
|
||||||
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,
|
||||||
{
|
"Unknown security command byte %02x\n",
|
||||||
sc_log(card->ctx,
|
buf[0]);
|
||||||
"Unknown security command byte %02x\n",
|
continue;
|
||||||
buf[0]);
|
}
|
||||||
continue;
|
if (!buf[1])
|
||||||
}
|
sc_file_add_acl_entry (file, op,
|
||||||
if (!buf[1])
|
|
||||||
sc_file_add_acl_entry (file, op,
|
|
||||||
SC_AC_NONE,
|
SC_AC_NONE,
|
||||||
SC_AC_KEY_REF_NONE);
|
SC_AC_KEY_REF_NONE);
|
||||||
else
|
else
|
||||||
sc_file_add_acl_entry (file, op,
|
sc_file_add_acl_entry (file, op,
|
||||||
SC_AC_CHV, buf[1]);
|
SC_AC_CHV, buf[1]);
|
||||||
|
|
||||||
if (!buf[2] && !buf[3])
|
if (!buf[2] && !buf[3])
|
||||||
sc_file_add_acl_entry (file, op,
|
sc_file_add_acl_entry (file, op,
|
||||||
SC_AC_NONE,
|
SC_AC_NONE,
|
||||||
SC_AC_KEY_REF_NONE);
|
SC_AC_KEY_REF_NONE);
|
||||||
else
|
else
|
||||||
sc_file_add_acl_entry (file, op,
|
sc_file_add_acl_entry (file, op,
|
||||||
SC_AC_TERM,
|
SC_AC_TERM,
|
||||||
(buf[2]<<8)|buf[3]);
|
(buf[2]<<8)|buf[3]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int tcos_select_file(sc_card_t *card,
|
static int tcos_select_file(sc_card_t *card,
|
||||||
const sc_path_t *in_path,
|
const sc_path_t *in_path,
|
||||||
sc_file_t **file_out)
|
sc_file_t **file_out)
|
||||||
{
|
{
|
||||||
sc_context_t *ctx;
|
sc_context_t *ctx;
|
||||||
sc_apdu_t apdu;
|
sc_apdu_t apdu;
|
||||||
@ -396,8 +391,8 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -437,8 +432,8 @@ static int tcos_list_files(sc_card_t *card, u8 *buf, size_t buflen)
|
|||||||
LOG_TEST_RET(ctx, r, "List Dir failed");
|
LOG_TEST_RET(ctx, r, "List Dir failed");
|
||||||
if (apdu.resplen > buflen) return SC_ERROR_BUFFER_TOO_SMALL;
|
if (apdu.resplen > buflen) return SC_ERROR_BUFFER_TOO_SMALL;
|
||||||
sc_log(ctx,
|
sc_log(ctx,
|
||||||
"got %"SC_FORMAT_LEN_SIZE_T"u %s-FileIDs\n",
|
"got %"SC_FORMAT_LEN_SIZE_T"u %s-FileIDs\n",
|
||||||
apdu.resplen / 2, p1 == 1 ? "DF" : "EF");
|
apdu.resplen / 2, p1 == 1 ? "DF" : "EF");
|
||||||
|
|
||||||
memcpy(buf, apdu.resp, apdu.resplen);
|
memcpy(buf, apdu.resp, apdu.resplen);
|
||||||
buf += apdu.resplen;
|
buf += apdu.resplen;
|
||||||
@ -457,13 +452,13 @@ static int tcos_delete_file(sc_card_t *card, const sc_path_t *path)
|
|||||||
|
|
||||||
SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
|
SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
|
||||||
if (path->type != SC_PATH_TYPE_FILE_ID && path->len != 2) {
|
if (path->type != SC_PATH_TYPE_FILE_ID && path->len != 2) {
|
||||||
sc_log(card->ctx, "File type has to be SC_PATH_TYPE_FILE_ID\n");
|
sc_log(card->ctx, "File type has to be SC_PATH_TYPE_FILE_ID\n");
|
||||||
LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
|
LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
|
||||||
}
|
}
|
||||||
sbuf[0] = path->value[0];
|
sbuf[0] = path->value[0];
|
||||||
sbuf[1] = path->value[1];
|
sbuf[1] = path->value[1];
|
||||||
sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0xE4, 0x00, 0x00);
|
sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0xE4, 0x00, 0x00);
|
||||||
apdu.cla |= 0x80;
|
apdu.cla |= 0x80;
|
||||||
apdu.lc = 2;
|
apdu.lc = 2;
|
||||||
apdu.datalen = 2;
|
apdu.datalen = 2;
|
||||||
apdu.data = sbuf;
|
apdu.data = sbuf;
|
||||||
@ -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))
|
||||||
@ -495,8 +490,8 @@ static int tcos_set_security_env(sc_card_t *card, const sc_security_env_t *env,
|
|||||||
"No Key-Reference in SecEnvironment\n");
|
"No Key-Reference in SecEnvironment\n");
|
||||||
else
|
else
|
||||||
sc_log(ctx,
|
sc_log(ctx,
|
||||||
"Key-Reference %02X (len=%"SC_FORMAT_LEN_SIZE_T"u)\n",
|
"Key-Reference %02X (len=%"SC_FORMAT_LEN_SIZE_T"u)\n",
|
||||||
env->key_ref[0], env->key_ref_len);
|
env->key_ref[0], env->key_ref_len);
|
||||||
/* Key-Reference 0x80 ?? */
|
/* Key-Reference 0x80 ?? */
|
||||||
default_key= !(env->flags & SC_SEC_ENV_KEY_REF_PRESENT) || (env->key_ref_len==1 && env->key_ref[0]==0x80);
|
default_key= !(env->flags & SC_SEC_ENV_KEY_REF_PRESENT) || (env->key_ref_len==1 && env->key_ref[0]==0x80);
|
||||||
sc_log(ctx,
|
sc_log(ctx,
|
||||||
@ -552,9 +547,9 @@ 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);
|
||||||
}
|
}
|
||||||
sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0x2A, 0x9E, 0x9A);
|
sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0x2A, 0x9E, 0x9A);
|
||||||
@ -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;
|
||||||
}
|
}
|
||||||
@ -657,7 +652,7 @@ static int tcos_setperm(sc_card_t *card, int enable_nullpin)
|
|||||||
|
|
||||||
SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
|
SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
|
||||||
sc_format_apdu(card, &apdu, SC_APDU_CASE_1, 0xEE, 0x00, 0x00);
|
sc_format_apdu(card, &apdu, SC_APDU_CASE_1, 0xEE, 0x00, 0x00);
|
||||||
apdu.cla |= 0x80;
|
apdu.cla |= 0x80;
|
||||||
apdu.lc = 0;
|
apdu.lc = 0;
|
||||||
apdu.datalen = 0;
|
apdu.datalen = 0;
|
||||||
apdu.data = NULL;
|
apdu.data = NULL;
|
||||||
|
Loading…
Reference in New Issue
Block a user