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.

82 lines
2.5 KiB

  1. From fbf8e392db4456de97796259a62ccb972fe24df8 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: Tue, 26 Feb 2013 17:37:16 +0700
  5. Subject: [PATCH 04/18] PKCS15-OpenPGP: Declare DATA objects.
  6. Begin to support read/write DATA object for PKCS-OpenPGP binding.
  7. This object is used by TrueCrypt.
  8. ---
  9. src/libopensc/pkcs15-openpgp.c | 35 +++++++++++++++++++++++++++++++++++
  10. 1 file changed, 35 insertions(+)
  11. diff --git a/src/libopensc/pkcs15-openpgp.c b/src/libopensc/pkcs15-openpgp.c
  12. index 5a8a1ca..9f239ef 100644
  13. --- a/src/libopensc/pkcs15-openpgp.c
  14. +++ b/src/libopensc/pkcs15-openpgp.c
  15. @@ -36,6 +36,7 @@ typedef USHORT ushort;
  16. #endif
  17. int sc_pkcs15emu_openpgp_init_ex(sc_pkcs15_card_t *, sc_pkcs15emu_opt_t *);
  18. +static int sc_pkcs15emu_openpgp_add_data(sc_pkcs15_card_t *);
  19. #define PGP_USER_PIN_FLAGS (SC_PKCS15_PIN_FLAG_CASE_SENSITIVE \
  20. @@ -45,6 +46,8 @@ int sc_pkcs15emu_openpgp_init_ex(sc_pkcs15_card_t *, sc_pkcs15emu_opt_t *);
  21. | SC_PKCS15_PIN_FLAG_UNBLOCK_DISABLED \
  22. | SC_PKCS15_PIN_FLAG_SO_PIN)
  23. +#define PGP_NUM_PRIVDO 4
  24. +
  25. typedef struct _pgp_pin_cfg {
  26. const char *label;
  27. int reference;
  28. @@ -359,6 +362,9 @@ sc_pkcs15emu_openpgp_init(sc_pkcs15_card_t *p15card)
  29. goto failed;
  30. }
  31. + /* PKCS#15 DATA object from OpenPGP private DOs */
  32. + r = sc_pkcs15emu_openpgp_add_data(p15card);
  33. +
  34. return 0;
  35. failed: sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "Failed to initialize OpenPGP emulation: %s\n",
  36. @@ -366,6 +372,35 @@ failed: sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "Failed to initialize OpenPGP e
  37. return r;
  38. }
  39. +static int
  40. +sc_pkcs15emu_openpgp_add_data(sc_pkcs15_card_t *p15card)
  41. +{
  42. + sc_context_t *ctx = p15card->card->ctx;
  43. + int i, r;
  44. +
  45. + LOG_FUNC_CALLED(ctx);
  46. + /* There is 4 private DO from 0101 to 0104 */
  47. + for (i = 1; i <= PGP_NUM_PRIVDO; i++) {
  48. + sc_pkcs15_data_info_t dat_info;
  49. + sc_pkcs15_object_t dat_obj;
  50. + char name[8];
  51. + char path[9];
  52. + memset(&dat_info, 0, sizeof(dat_info));
  53. + memset(&dat_obj, 0, sizeof(dat_obj));
  54. +
  55. + sprintf(name, "PrivDO%d", i);
  56. + sprintf(path, "3F00010%d", i);
  57. +
  58. + sc_format_path(path, &dat_info.path);
  59. + strlcpy(dat_obj.label, name, sizeof(dat_obj.label));
  60. + strlcpy(dat_info.app_label, name, sizeof(dat_info.app_label));
  61. +
  62. + sc_log(ctx, "Add %s data object", name);
  63. + r = sc_pkcs15emu_add_data_object(p15card, &dat_obj, &dat_info);
  64. + }
  65. + LOG_FUNC_RETURN(ctx, r);
  66. +}
  67. +
  68. static int openpgp_detect_card(sc_pkcs15_card_t *p15card)
  69. {
  70. if (p15card->card->type == SC_CARD_TYPE_OPENPGP_V1 || p15card->card->type == SC_CARD_TYPE_OPENPGP_V2
  71. --
  72. 1.9.3