scd: Extend iso7816_select_path

* scd/iso7816.c (iso7816_select_path): Add arg top_fd.
* scd/app-nks.c (do_readkey): Adjust for this change
(select_ef_by_path: Ditto.

* common/tlv.h: Include membuf.h.
--

Including membuf.h is just for easier backporting.  In 2.3 it is
actually required in tlv.h but in 2.2 we right now only use it
indirect.
This commit is contained in:
Werner Koch 2021-01-26 17:42:55 +01:00
parent 3ce69d8387
commit 855d14d390
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B
5 changed files with 21 additions and 10 deletions

View File

@ -30,6 +30,8 @@
#ifndef SCD_TLV_H
#define SCD_TLV_H 1
#include "membuf.h"
enum tlv_tag_class {
CLASS_UNIVERSAL = 0,

View File

@ -628,7 +628,7 @@ do_readkey (app_t app, ctrl_t ctrl, const char *keyid, unsigned int flags,
return gpg_error (GPG_ERR_UNSUPPORTED_OPERATION);
/* Access the KEYD file which is always in the master directory. */
err = iso7816_select_path (app->slot, path, DIM (path));
err = iso7816_select_path (app_get_slot (app), path, DIM (path), 0);
if (err)
return err;
/* Due to the above select we need to re-select our application. */

View File

@ -501,7 +501,7 @@ select_ef_by_path (app_t app, const unsigned short *path, size_t pathlen)
if (app->app_local->direct_path_selection)
{
err = iso7816_select_path (app->slot, path+1, pathlen-1);
err = iso7816_select_path (app->slot, path+1, pathlen-1, 0);
if (err)
{
log_error ("p15: error selecting path ");
@ -4104,7 +4104,7 @@ app_select_p15 (app_t app)
Using the 2f02 just works. */
unsigned short path[1] = { 0x2f00 };
rc = iso7816_select_path (slot, path, 1);
rc = iso7816_select_path (slot, path, 1, 0);
if (!rc)
{
direct = 1;
@ -4112,7 +4112,7 @@ app_select_p15 (app_t app)
if (def_home_df)
{
path[0] = def_home_df;
rc = iso7816_select_path (slot, path, 1);
rc = iso7816_select_path (slot, path, 1, 0);
}
}
}

View File

@ -193,18 +193,26 @@ iso7816_select_file (int slot, int tag, int is_dir)
}
/* Do a select file command with a direct path. */
/* Do a select file command with a direct path. If TOPDF is set, the
* actual used path is 3f00/<topdf>/<path>. */
gpg_error_t
iso7816_select_path (int slot, const unsigned short *path, size_t pathlen)
iso7816_select_path (int slot, const unsigned short *path, size_t pathlen,
unsigned short topdf)
{
int sw, p0, p1;
unsigned char buffer[100];
int buflen;
int buflen = 0;
if (pathlen/2 >= sizeof buffer)
if (pathlen*2 + 2 >= sizeof buffer)
return gpg_error (GPG_ERR_TOO_LARGE);
for (buflen = 0; pathlen; pathlen--, path++)
if (topdf)
{
buffer[buflen++] = topdf >> 8;
buffer[buflen++] = topdf;
}
for (; pathlen; pathlen--, path++)
{
buffer[buflen++] = (*path >> 8);
buffer[buflen++] = *path;

View File

@ -68,7 +68,8 @@ gpg_error_t iso7816_select_application_ext (int slot,
gpg_error_t iso7816_select_mf (int slot);
gpg_error_t iso7816_select_file (int slot, int tag, int is_dir);
gpg_error_t iso7816_select_path (int slot,
const unsigned short *path, size_t pathlen);
const unsigned short *path, size_t pathlen,
unsigned short top_df);
gpg_error_t iso7816_list_directory (int slot, int list_dirs,
unsigned char **result, size_t *resultlen);
gpg_error_t iso7816_apdu_direct (int slot,