From 782b4efa734cf7be249445647f49b19385d68832 Mon Sep 17 00:00:00 2001 From: martin Date: Mon, 23 May 2011 17:33:27 +0000 Subject: [PATCH] OpenPGP: get flags & algorithms in pgp_get_card_features() Extend pgp_get_card_features() to get card's flags & supported algorithms from the card: * get algorith values from "algorithm attributes" DOs 0x00c1 - 0x00c3 Signed-off-by: Peter Marschall git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5495 c6295689-39f2-0310-b995-f0e70906c6a9 --- src/libopensc/card-openpgp.c | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/src/libopensc/card-openpgp.c b/src/libopensc/card-openpgp.c index 58944281..442a8392 100644 --- a/src/libopensc/card-openpgp.c +++ b/src/libopensc/card-openpgp.c @@ -265,7 +265,6 @@ static int pgp_init(sc_card_t *card) { struct pgp_priv_data *priv; - unsigned long flags; sc_path_t aid; sc_file_t *file = NULL; struct do_info *info; @@ -285,20 +284,6 @@ pgp_init(sc_card_t *card) card->cla = 0x00; - /* Is this correct? */ - /* OpenPGP card spec 1.1 & 2.0, section 2.1 */ - flags = SC_ALGORITHM_RSA_RAW; - /* OpenPGP card spec 1.1 & 2.0, section 7.2.9 & 7.2.10 */ - flags |= SC_ALGORITHM_RSA_PAD_PKCS1; - flags |= SC_ALGORITHM_RSA_HASH_NONE; - - /* Is this correct? */ - _sc_card_add_rsa_alg(card, 512, flags, 0); - _sc_card_add_rsa_alg(card, 768, flags, 0); - _sc_card_add_rsa_alg(card, 1024, flags, 0); - if (card->type == SC_CARD_TYPE_OPENPGP_V2) - _sc_card_add_rsa_alg(card, 2048, flags, 0); - /* set pointer to correct list of card objects */ priv->pgp_objects = (card->type == SC_CARD_TYPE_OPENPGP_V2) ? pgp2_objects : pgp1_objects; @@ -413,6 +398,27 @@ pgp_get_card_features(sc_card_t *card) /* 2nd byte in "CHV status bytes" DO means "max. PIN length" */ card->max_pin_len = blob->data[1]; } + + /* get supported algorithms & key lengths from "algorithm attributes" DOs */ + for (i = 0x00c1; i < 0x0c3; i++) { + unsigned long flags; + + /* Is this correct? */ + /* OpenPGP card spec 1.1 & 2.0, section 2.1 */ + flags = SC_ALGORITHM_RSA_RAW; + /* OpenPGP card spec 1.1 & 2.0, section 7.2.9 & 7.2.10 */ + flags |= SC_ALGORITHM_RSA_PAD_PKCS1; + flags |= SC_ALGORITHM_RSA_HASH_NONE; + + if ((pgp_get_blob(card, blob73, i, &blob) >= 0) && + (blob->data != NULL) && (blob->len >= 4)) { + if (blob->data[0] == 0x01) { /* Algorithm ID [RFC4880]: RSA */ + unsigned int keylen = bebytes2ushort(blob->data + 1); + + _sc_card_add_rsa_alg(card, keylen, flags, 0); + } + } + } } return SC_SUCCESS;