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.

53 lines
1.7 KiB

  1. From 42adc35954e18e24f253f710b16d850d1872bce5 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: Wed, 27 Mar 2013 11:38:42 +0700
  5. Subject: [PATCH 09/26] PKCS15-OpenPGP: Do not show empty DO in pkcs15
  6. emu_init.
  7. ---
  8. src/libopensc/pkcs15-openpgp.c | 18 ++++++++++++++++++
  9. 1 file changed, 18 insertions(+)
  10. diff --git a/src/libopensc/pkcs15-openpgp.c b/src/libopensc/pkcs15-openpgp.c
  11. index fea2805..51a2032 100644
  12. --- a/src/libopensc/pkcs15-openpgp.c
  13. +++ b/src/libopensc/pkcs15-openpgp.c
  14. @@ -381,16 +381,34 @@ sc_pkcs15emu_openpgp_add_data(sc_pkcs15_card_t *p15card)
  15. sc_pkcs15_object_t dat_obj;
  16. char name[8];
  17. char path[9];
  18. + u8 content[254];
  19. memset(&dat_info, 0, sizeof(dat_info));
  20. memset(&dat_obj, 0, sizeof(dat_obj));
  21. sprintf(name, "PrivDO%d", i);
  22. sprintf(path, "3F00010%d", i);
  23. + /* Check if the DO can be read.
  24. + * We won't expose pkcs15 DATA object if DO is empty.
  25. + */
  26. + r = read_file(p15card->card, path, content, sizeof(content));
  27. + if (r <= 0 ) {
  28. + sc_log(ctx, "Cannot read DO 010%d or there is no data in it", i);
  29. + /* Skip */
  30. + continue;
  31. + }
  32. sc_format_path(path, &dat_info.path);
  33. strlcpy(dat_obj.label, name, sizeof(dat_obj.label));
  34. strlcpy(dat_info.app_label, name, sizeof(dat_info.app_label));
  35. + /* Add DATA object to slot protected by PIN2 (PW1 with Ref 0x82) */
  36. + dat_obj.flags = SC_PKCS15_CO_FLAG_PRIVATE | SC_PKCS15_CO_FLAG_MODIFIABLE;
  37. + dat_obj.auth_id.len = 1;
  38. + if (i == 1 || i == 3)
  39. + dat_obj.auth_id.value[0] = 2;
  40. + else
  41. + dat_obj.auth_id.value[0] = 3;
  42. +
  43. sc_log(ctx, "Add %s data object", name);
  44. r = sc_pkcs15emu_add_data_object(p15card, &dat_obj, &dat_info);
  45. }
  46. --
  47. 2.1.3