Skip to content

Commit f05eb3e

Browse files
committed
replace PIV_MAX_OBJECT_SIZE with MAX_FILE_SIZE
simplify code and configuration options
1 parent d7eaed2 commit f05eb3e

File tree

3 files changed

+6
-55
lines changed

3 files changed

+6
-55
lines changed

doc/files/opensc.conf.5.xml.in

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -800,16 +800,6 @@ app <replaceable>application</replaceable> {
800800
<refsect2 id="piv">
801801
<title>Configuration Options for PIV Card</title>
802802
<variablelist>
803-
<varlistentry>
804-
<term>
805-
<option>piv_max_object_size = <replaceable>num</replaceable>;</option>
806-
</term>
807-
<listitem><para>
808-
Max size of a PIV object. The default of 16384 bytes should
809-
work for most cards. It might be overwritten by
810-
<literal>PIV_MAX_OBJECT_SIZE</literal> environment variable.
811-
</para></listitem>
812-
</varlistentry>
813803
<!-- Commented out until PIV SM is built be default
814804
<varlistentry>
815805
<term><option>piv_use_sm = <replaceable>name</replaceable>;</option>
@@ -1824,7 +1814,6 @@ app <replaceable>application</replaceable> {
18241814
</varlistentry>
18251815
<varlistentry>
18261816
<term>
1827-
<envar>PIV_MAX_OBJECT</envar>,
18281817
<envar>PIV_USE_SM</envar>,
18291818
<envar>PIV_PAIRING_CODE</envar>
18301819
</term>

etc/opensc.conf.example.in

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -227,16 +227,6 @@ app default {
227227
}
228228

229229
card_driver PIV-II {
230-
# "piv_max_object_size"
231-
# defines the buffer size used to read PIV objects
232-
# Although NIST sp800-73-4 lists object sizes, these are not hard limits.
233-
# Other PIV-like cards may have larger objects.
234-
# Maximum: 65535
235-
# Minimum: 16384
236-
# Default: 16384
237-
# piv_max_object_size = 16384;
238-
# May be set via environment: PIV_MAX_OBJECT_SIZE=16384
239-
240230
# *NOTE* The following are only useble if OpenSC is configured with --enable-piv-sm
241231
# The names and locations are likely to change in the future
242232
# See: https://github.com/OpenSC/OpenSC/pull/2053/files#r1267388721

src/libopensc/card-piv.c

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ enum {
156156
#define PIV_OBJ_CACHE_VALID 1
157157
#define PIV_OBJ_CACHE_COMPRESSED 2
158158
#define PIV_OBJ_CACHE_NOT_PRESENT 8
159-
#define PIV_MAX_OBJECT_SIZE 16384
160159

161160
typedef struct piv_obj_cache {
162161
u8* obj_data;
@@ -1642,27 +1641,11 @@ static int piv_load_options(sc_card_t *card)
16421641
scconf_block **found_blocks, *block;
16431642

16441643
const char *option = NULL;
1645-
int piv_max_object_size_found = 0;
16461644
#ifdef ENABLE_PIV_SM
16471645
int piv_pairing_code_found = 0;
16481646
int piv_use_sm_found = 0;
16491647
#endif
16501648

1651-
option = getenv("PIV_MAX_OBJECT_SIZE");
1652-
if (option && option[0] != '\0') {
1653-
sc_log(card->ctx, "getenv(\"PIV_MAX_OBJECT_SIZE\")=\"%s\"", option);
1654-
priv->max_object_size = atoi(option);
1655-
if (priv->max_object_size < PIV_MAX_OBJECT_SIZE || priv->max_object_size > MAX_FILE_SIZE) {
1656-
sc_log(card->ctx,"Invalid max_object_size: \"%d\"", priv->max_object_size);
1657-
if (priv->max_object_size < PIV_MAX_OBJECT_SIZE)
1658-
priv->max_object_size = PIV_MAX_OBJECT_SIZE;
1659-
else
1660-
priv->max_object_size = MAX_FILE_SIZE; /* conservative value if error */
1661-
} else
1662-
piv_max_object_size_found = 1;
1663-
sc_log(card->ctx," priv->max_object_size:%d", priv->max_object_size);
1664-
}
1665-
16661649
#ifdef ENABLE_PIV_SM
16671650
/* pairing code is 8 decimal digits and is card specific */
16681651
if ((option = getenv("PIV_PAIRING_CODE")) != NULL) {
@@ -1738,22 +1721,6 @@ static int piv_load_options(sc_card_t *card)
17381721
}
17391722
}
17401723
#endif
1741-
/*
1742-
* Largest object defined in NIST sp800-73-3 and sp800-73-4 is 12710 bytes
1743-
* If for some reason future cards have larger objects, the buffer size can be changed.
1744-
* (This not not max_read_size)
1745-
*/
1746-
if (piv_max_object_size_found == 0) {
1747-
priv->max_object_size = scconf_get_int(block, "piv_max_object_size", PIV_MAX_OBJECT_SIZE);
1748-
if (priv->max_object_size < PIV_MAX_OBJECT_SIZE || priv->max_object_size > MAX_FILE_SIZE) {
1749-
sc_log(card->ctx,"Invalid max_object_size:=\"%d\"", priv->max_object_size);
1750-
if (priv->max_object_size < PIV_MAX_OBJECT_SIZE)
1751-
priv->max_object_size = PIV_MAX_OBJECT_SIZE;
1752-
else
1753-
priv->max_object_size = MAX_FILE_SIZE;
1754-
}
1755-
sc_log(card->ctx,"piv_max_object_size: %d",priv->max_object_size);
1756-
}
17571724
}
17581725
free(found_blocks);
17591726
}
@@ -5470,7 +5437,12 @@ static int piv_match_card_continued(sc_card_t *card)
54705437
LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
54715438

54725439
card->drv_data = priv; /* will free if no match, or pass on to piv_init */
5473-
priv->max_object_size = PIV_MAX_OBJECT_SIZE; /* may be reset later */
5440+
/*
5441+
* Largest object defined in NIST sp800-73-3 and sp800-73-4 is 12710 bytes
5442+
* If for some reason future cards have larger objects, this value needs to
5443+
* be increased here.
5444+
*/
5445+
priv->max_object_size = MAX_FILE_SIZE;
54745446
priv->selected_obj = -1;
54755447
priv->pin_preference = 0x80; /* 800-73-3 part 1, table 3 */
54765448
/* TODO Dual CAC/PIV are bases on 800-73-1 where priv->pin_preference = 0. need to check later */

0 commit comments

Comments
 (0)