Skip to content

Commit

Permalink
openpgp: identify OpenPGP compliance with bcd_version rather than car…
Browse files Browse the repository at this point in the history
…d type
  • Loading branch information
frankmorgner committed Apr 18, 2023
1 parent dec16d6 commit 4e9f4e0
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/libopensc/card-openpgp.c
Expand Up @@ -1780,13 +1780,18 @@ pgp_get_pubkey_pem(sc_card_t *card, unsigned int tag, u8 *buf, size_t buf_len)
* p1: number of an instance (DO 7F21: 0x00 for AUT, 0x01 for DEC and 0x02 for SIG)
*/
static int
pgp_select_data(sc_card_t *card, u8 p1){
pgp_select_data(sc_card_t *card, u8 p1)
{
sc_apdu_t apdu;
u8 apdu_data[6];
int r;
struct pgp_priv_data *priv = DRVDATA(card);

LOG_FUNC_CALLED(card->ctx);

if (priv->bcd_version < OPENPGP_CARD_3_0)
LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);

sc_log(card->ctx, "select data with: %u", p1);

// create apdu data (taken from spec: SELECT DATA 7.2.5.)
Expand Down Expand Up @@ -2179,8 +2184,7 @@ pgp_set_security_env(sc_card_t *card,
/* The SC_SEC_ENV_ALG_PRESENT is set always so let it pass for GNUK */
if ((env->flags & SC_SEC_ENV_ALG_PRESENT)
&& (env->algorithm != SC_ALGORITHM_RSA)
&& (priv->bcd_version < OPENPGP_CARD_3_0)
&& (card->type != SC_CARD_TYPE_OPENPGP_GNUK))
&& (priv->bcd_version < OPENPGP_CARD_3_0))
LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_ARGUMENTS,
"only RSA algorithm supported");

Expand Down Expand Up @@ -2944,13 +2948,13 @@ pgp_update_card_algorithms(sc_card_t *card, sc_cardctl_openpgp_keygen_info_t *ke
{
sc_algorithm_info_t *algo;
u8 id = key_info->key_id;
struct pgp_priv_data *priv = DRVDATA(card);

LOG_FUNC_CALLED(card->ctx);

/* protect incompatible cards against non-RSA */
if (key_info->algorithm != SC_OPENPGP_KEYALGO_RSA
&& card->type < SC_CARD_TYPE_OPENPGP_V3
&& card->type != SC_CARD_TYPE_OPENPGP_GNUK)
&& priv->bcd_version < OPENPGP_CARD_3_0)
LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);

if (id > card->algorithm_count) {
Expand Down Expand Up @@ -2992,13 +2996,13 @@ pgp_gen_key(sc_card_t *card, sc_cardctl_openpgp_keygen_info_t *key_info)
size_t apdu_le;
size_t resplen = 0;
int r = SC_SUCCESS;
struct pgp_priv_data *priv = DRVDATA(card);

LOG_FUNC_CALLED(card->ctx);

/* protect incompatible cards against non-RSA */
if (key_info->algorithm != SC_OPENPGP_KEYALGO_RSA
&& card->type < SC_CARD_TYPE_OPENPGP_V3
&& card->type != SC_CARD_TYPE_OPENPGP_GNUK)
&& priv->bcd_version < OPENPGP_CARD_3_0)
LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
if (key_info->algorithm == SC_OPENPGP_KEYALGO_EDDSA
&& card->type != SC_CARD_TYPE_OPENPGP_GNUK)
Expand Down Expand Up @@ -3358,13 +3362,13 @@ pgp_store_key(sc_card_t *card, sc_cardctl_openpgp_keystore_info_t *key_info)
u8 *data = NULL;
size_t len = 0;
int r;
struct pgp_priv_data *priv = DRVDATA(card);

LOG_FUNC_CALLED(card->ctx);

/* protect incompatible cards against non-RSA */
if (key_info->algorithm != SC_OPENPGP_KEYALGO_RSA
&& card->type < SC_CARD_TYPE_OPENPGP_V3
&& card->type != SC_CARD_TYPE_OPENPGP_GNUK)
&& priv->bcd_version < OPENPGP_CARD_3_0)
LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);

/* Validate */
Expand Down

0 comments on commit 4e9f4e0

Please sign in to comment.