Skip to content

Commit

Permalink
replace PIV_MAX_OBJECT_SIZE with MAX_FILE_SIZE
Browse files Browse the repository at this point in the history
simplify code and configuration options
  • Loading branch information
frankmorgner authored and Jakuje committed Sep 12, 2023
1 parent fde759a commit ccb6f3c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 55 deletions.
11 changes: 0 additions & 11 deletions doc/files/opensc.conf.5.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -803,16 +803,6 @@ app <replaceable>application</replaceable> {
<refsect2 id="piv">
<title>Configuration Options for PIV Card</title>
<variablelist>
<varlistentry>
<term>
<option>piv_max_object_size = <replaceable>num</replaceable>;</option>
</term>
<listitem><para>
Max size of a PIV object. The default of 16384 bytes should
work for most cards. It might be overwritten by
<literal>PIV_MAX_OBJECT_SIZE</literal> environment variable.
</para></listitem>
</varlistentry>
<!-- Commented out until PIV SM is built be default
<varlistentry>
<term><option>piv_use_sm = <replaceable>name</replaceable>;</option>
Expand Down Expand Up @@ -1830,7 +1820,6 @@ app <replaceable>application</replaceable> {
</varlistentry>
<varlistentry>
<term>
<envar>PIV_MAX_OBJECT</envar>,
<envar>PIV_USE_SM</envar>,
<envar>PIV_PAIRING_CODE</envar>
</term>
Expand Down
10 changes: 0 additions & 10 deletions etc/opensc.conf.example.in
Original file line number Diff line number Diff line change
Expand Up @@ -227,16 +227,6 @@ app default {
}

card_driver PIV-II {
# "piv_max_object_size"
# defines the buffer size used to read PIV objects
# Although NIST sp800-73-4 lists object sizes, these are not hard limits.
# Other PIV-like cards may have larger objects.
# Maximum: 65535
# Minimum: 16384
# Default: 16384
# piv_max_object_size = 16384;
# May be set via environment: PIV_MAX_OBJECT_SIZE=16384

# *NOTE* The following are only useble if OpenSC is configured with --enable-piv-sm
# The names and locations are likely to change in the future
# See: https://github.com/OpenSC/OpenSC/pull/2053/files#r1267388721
Expand Down
40 changes: 6 additions & 34 deletions src/libopensc/card-piv.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ enum {
#define PIV_OBJ_CACHE_VALID 1
#define PIV_OBJ_CACHE_COMPRESSED 2
#define PIV_OBJ_CACHE_NOT_PRESENT 8
#define PIV_MAX_OBJECT_SIZE 16384

typedef struct piv_obj_cache {
u8* obj_data;
Expand Down Expand Up @@ -1642,27 +1641,11 @@ static int piv_load_options(sc_card_t *card)
scconf_block **found_blocks, *block;

const char *option = NULL;
int piv_max_object_size_found = 0;
#ifdef ENABLE_PIV_SM
int piv_pairing_code_found = 0;
int piv_use_sm_found = 0;
#endif

option = getenv("PIV_MAX_OBJECT_SIZE");
if (option && option[0] != '\0') {
sc_log(card->ctx, "getenv(\"PIV_MAX_OBJECT_SIZE\")=\"%s\"", option);
priv->max_object_size = atoi(option);
if (priv->max_object_size < PIV_MAX_OBJECT_SIZE || priv->max_object_size > MAX_FILE_SIZE) {
sc_log(card->ctx,"Invalid max_object_size: \"%d\"", priv->max_object_size);
if (priv->max_object_size < PIV_MAX_OBJECT_SIZE)
priv->max_object_size = PIV_MAX_OBJECT_SIZE;
else
priv->max_object_size = MAX_FILE_SIZE; /* conservative value if error */
} else
piv_max_object_size_found = 1;
sc_log(card->ctx," priv->max_object_size:%d", priv->max_object_size);
}

#ifdef ENABLE_PIV_SM
/* pairing code is 8 decimal digits and is card specific */
if ((option = getenv("PIV_PAIRING_CODE")) != NULL) {
Expand Down Expand Up @@ -1738,22 +1721,6 @@ static int piv_load_options(sc_card_t *card)
}
}
#endif
/*
* Largest object defined in NIST sp800-73-3 and sp800-73-4 is 12710 bytes
* If for some reason future cards have larger objects, the buffer size can be changed.
* (This not not max_read_size)
*/
if (piv_max_object_size_found == 0) {
priv->max_object_size = scconf_get_int(block, "piv_max_object_size", PIV_MAX_OBJECT_SIZE);
if (priv->max_object_size < PIV_MAX_OBJECT_SIZE || priv->max_object_size > MAX_FILE_SIZE) {
sc_log(card->ctx,"Invalid max_object_size:=\"%d\"", priv->max_object_size);
if (priv->max_object_size < PIV_MAX_OBJECT_SIZE)
priv->max_object_size = PIV_MAX_OBJECT_SIZE;
else
priv->max_object_size = MAX_FILE_SIZE;
}
sc_log(card->ctx,"piv_max_object_size: %d",priv->max_object_size);
}
}
free(found_blocks);
}
Expand Down Expand Up @@ -5470,7 +5437,12 @@ static int piv_match_card_continued(sc_card_t *card)
LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);

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

0 comments on commit ccb6f3c

Please sign in to comment.