You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
2.0 KiB

  1. From df98874784a77c96a7a1be54412a02a53fdd3a3e Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Nguy=E1=BB=85n=20H=E1=BB=93ng=20Qu=C3=A2n?=
  3. <ng.hong.quan@gmail.com>
  4. Date: Mon, 25 Mar 2013 11:58:38 +0700
  5. Subject: [PATCH 08/26] OpenPGP: Read some empty DOs from Gnuk.
  6. In Gnuk, some empty DOs are returned as not exist, instead of existing with empty value.
  7. So, we will consider them exist in driver.
  8. ---
  9. src/libopensc/card-openpgp.c | 25 +++++++++++++++++++++++++
  10. 1 file changed, 25 insertions(+)
  11. diff --git a/src/libopensc/card-openpgp.c b/src/libopensc/card-openpgp.c
  12. index 91c311b..e7b25c0 100644
  13. --- a/src/libopensc/card-openpgp.c
  14. +++ b/src/libopensc/card-openpgp.c
  15. @@ -815,6 +815,23 @@ pgp_get_blob(sc_card_t *card, struct blob *blob, unsigned int id,
  16. }
  17. }
  18. + /* This part is for "NOT FOUND" cases */
  19. +
  20. + /* Special case:
  21. + * Gnuk does not have default value for children of DO 65 (DOs 5B, 5F2D, 5F35)
  22. + * So, if these blob was not found, we create it. */
  23. + if (blob->id == 0x65 && (id == 0x5B || id == 0x5F2D || id == 0x5F35)) {
  24. + sc_log(card->ctx, "Create blob %X under %X", id, blob->id);
  25. + child = pgp_new_blob(card, blob, id, sc_file_new());
  26. + if (child) {
  27. + pgp_set_blob(child, NULL, 0);
  28. + *ret = child;
  29. + return SC_SUCCESS;
  30. + }
  31. + else
  32. + sc_log(card->ctx, "Not enough memory to create blob for DO %X");
  33. + }
  34. +
  35. return SC_ERROR_FILE_NOT_FOUND;
  36. }
  37. @@ -1149,6 +1166,14 @@ pgp_get_data(sc_card_t *card, unsigned int tag, u8 *buf, size_t buf_len)
  38. LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  39. r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  40. +
  41. + /* For Gnuk card, if there is no certificate, it returns error instead of empty data.
  42. + * So, for this case, we ignore error and consider success */
  43. + if (r == SC_ERROR_DATA_OBJECT_NOT_FOUND && card->type == SC_CARD_TYPE_OPENPGP_GNUK
  44. + && (tag == DO_CERT || tag == 0x0101 || tag == 0x0102 || tag == 0x0103 || tag == 0x0104)) {
  45. + r = SC_SUCCESS;
  46. + apdu.resplen = 0;
  47. + }
  48. LOG_TEST_RET(card->ctx, r, "Card returned error");
  49. LOG_FUNC_RETURN(card->ctx, apdu.resplen);
  50. --
  51. 2.1.3