Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for OpenPGP applet selection #1232

Merged
merged 6 commits into from
Jan 22, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
OpenPGP: Added support for PIN logout and status
  • Loading branch information
frankmorgner committed Jan 17, 2018
commit 006ba77e7c13f12d983a66bc36279b4f820f1f03
38 changes: 37 additions & 1 deletion src/libopensc/card-openpgp.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ enum _version { /* 2-byte BCD-alike encoded version number */
OPENPGP_CARD_1_1 = 0x0101,
OPENPGP_CARD_2_0 = 0x0200,
OPENPGP_CARD_2_1 = 0x0201,
OPENPGP_CARD_3_0 = 0x0300
OPENPGP_CARD_3_0 = 0x0300,
OPENPGP_CARD_3_1 = 0x0301,
};

enum _access { /* access flags for the respective DO/file */
Expand Down Expand Up @@ -536,6 +537,10 @@ pgp_get_card_features(sc_card_t *card)
}
}

if (priv->bcd_version >= OPENPGP_CARD_3_1) {
card->caps |= SC_CARD_CAP_ISO7816_PIN_INFO;
}

if ((pgp_get_blob(card, priv->mf, 0x006e, &blob6e) >= 0) &&
(pgp_get_blob(card, blob6e, 0x0073, &blob73) >= 0)) {

Expand Down Expand Up @@ -1617,6 +1622,36 @@ pgp_pin_cmd(sc_card_t *card, struct sc_pin_cmd_data *data, int *tries_left)
}


int pgp_logout(struct sc_card *card)
{
int r = SC_SUCCESS;
struct pgp_priv_data *priv = DRVDATA(card);

LOG_FUNC_CALLED(card->ctx);

if (priv->bcd_version >= OPENPGP_CARD_3_1) {
unsigned char pin_reference;
for (pin_reference = 0x81; pin_reference <= 0x83; pin_reference++) {
int tmp = iso7816_logout(card, pin_reference);
if (r == SC_SUCCESS) {
r = tmp;
}
}
} else {
sc_path_t path;
sc_file_t *file = NULL;

/* select application "OpenPGP" */
sc_format_path("D276:0001:2401", &path);
path.type = SC_PATH_TYPE_DF_NAME;
r = iso_ops->select_file(card, &path, &file);
sc_file_free(file);
}

LOG_FUNC_RETURN(card->ctx, r);
}


/**
* ABI: set security environment.
*/
Expand Down Expand Up @@ -2834,6 +2869,7 @@ sc_get_driver(void)
pgp_ops.read_binary = pgp_read_binary;
pgp_ops.write_binary = pgp_write_binary;
pgp_ops.pin_cmd = pgp_pin_cmd;
pgp_ops.logout = pgp_logout;
pgp_ops.get_data = pgp_get_data;
pgp_ops.put_data = pgp_put_data;
pgp_ops.set_security_env= pgp_set_security_env;
Expand Down
16 changes: 16 additions & 0 deletions src/libopensc/iso7816.c
Original file line number Diff line number Diff line change
Expand Up @@ -1417,3 +1417,19 @@ int iso7816_write_binary_sfid(sc_card_t *card, unsigned char sfid,
err:
return r;
}

int iso7816_logout(sc_card_t *card, unsigned char pin_reference)
{
int r;
sc_apdu_t apdu;

sc_format_apdu(card, &apdu, SC_APDU_CASE_1, 0x20, 0xFF, pin_reference);

r = sc_transmit_apdu(card, &apdu);
if (r < 0)
return r;

r = sc_check_sw(card, apdu.sw1, apdu.sw2);

return r;
}
10 changes: 10 additions & 0 deletions src/libopensc/opensc.h
Original file line number Diff line number Diff line change
Expand Up @@ -1418,6 +1418,16 @@ int iso7816_read_binary_sfid(sc_card_t *card, unsigned char sfid,
int iso7816_write_binary_sfid(sc_card_t *card, unsigned char sfid,
u8 *ef, size_t ef_len);

/**
* @brief Set verification status of a specific PIN to “not verified”
*
* @param[in] card
* @param[in] pin_reference PIN reference written to P2
*
* @note The appropriate directory must be selected before calling this function.
* */
int iso7816_logout(sc_card_t *card, unsigned char pin_reference);

#ifdef __cplusplus
}
#endif
Expand Down