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.

91 lines
3.3 KiB

  1. From 88ded8fc5802c073caa71b649cee5a3116699b2a 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:39:33 +0700
  5. Subject: [PATCH 10/18] PKCS15-OpenPGP: Allow to store data to pkcs15 data
  6. object.
  7. Only one DO is supported now.
  8. ---
  9. src/libopensc/pkcs15-openpgp.c | 2 +-
  10. src/pkcs15init/pkcs15-openpgp.c | 38 +++++++++++++++++++++++++++++++++++++-
  11. 2 files changed, 38 insertions(+), 2 deletions(-)
  12. diff --git a/src/libopensc/pkcs15-openpgp.c b/src/libopensc/pkcs15-openpgp.c
  13. index 850dd74..b701041 100644
  14. --- a/src/libopensc/pkcs15-openpgp.c
  15. +++ b/src/libopensc/pkcs15-openpgp.c
  16. @@ -397,7 +397,7 @@ sc_pkcs15emu_openpgp_add_data(sc_pkcs15_card_t *p15card)
  17. */
  18. r = read_file(p15card->card, path, content, sizeof(content));
  19. if (r <= 0 ) {
  20. - sc_log(ctx, "Cannot read DO 010%d or there is no data in it", i);
  21. + sc_log(ctx, "No data get from DO 010%d", i);
  22. /* Skip */
  23. continue;
  24. }
  25. diff --git a/src/pkcs15init/pkcs15-openpgp.c b/src/pkcs15init/pkcs15-openpgp.c
  26. index f3a4962..1455580 100755
  27. --- a/src/pkcs15init/pkcs15-openpgp.c
  28. +++ b/src/pkcs15init/pkcs15-openpgp.c
  29. @@ -236,13 +236,16 @@ static int openpgp_emu_update_tokeninfo(sc_profile_t *profile, sc_pkcs15_card_t
  30. }
  31. static int openpgp_store_data(struct sc_pkcs15_card *p15card, struct sc_profile *profile,
  32. - struct sc_pkcs15_object *obj, struct sc_pkcs15_der *content,
  33. + struct sc_pkcs15_object *obj, struct sc_pkcs15_der *content,
  34. struct sc_path *path)
  35. {
  36. sc_card_t *card = p15card->card;
  37. + sc_context_t *ctx = card->ctx;
  38. sc_file_t *file;
  39. sc_pkcs15_cert_info_t *cinfo;
  40. sc_pkcs15_id_t *cid;
  41. + sc_pkcs15_data_info_t *dinfo;
  42. + u8 buf[254];
  43. int r;
  44. LOG_FUNC_CALLED(card->ctx);
  45. @@ -282,6 +285,39 @@ static int openpgp_store_data(struct sc_pkcs15_card *p15card, struct sc_profile
  46. content->len, 0);
  47. break;
  48. + case SC_PKCS15_TYPE_DATA_OBJECT:
  49. + dinfo = (sc_pkcs15_data_info_t *) obj->data;
  50. + /* dinfo->app_label contains filename */
  51. + sc_log(ctx, "===== App label %s", dinfo->app_label);
  52. + /* Currently, we only support DO 0101. The reason is that when initializing this
  53. + * pkcs15 emulation, PIN authentication is not applied and we can expose only this DO,
  54. + * which is "read always".
  55. + * If we support other DOs, they will not be exposed, and not helpful to user.
  56. + * I haven't found a way to refresh the list of exposed DOs after verifying PIN yet.
  57. + * http://sourceforge.net/mailarchive/message.php?msg_id=30646373
  58. + **/
  59. + sc_log(ctx, "About to write to DO 0101");
  60. + sc_format_path("0101", path);
  61. + r = sc_select_file(card, path, &file);
  62. + LOG_TEST_RET(card->ctx, r, "Cannot select private DO");
  63. + r = sc_read_binary(card, 0, buf, sizeof(buf), 0);
  64. + if (r < 0) {
  65. + sc_log(ctx, "Cannot read DO 0101");
  66. + break;
  67. + }
  68. + if (r > 0) {
  69. + sc_log(ctx, "DO 0101 is full.");
  70. + r = SC_ERROR_TOO_MANY_OBJECTS;
  71. + break;
  72. + }
  73. + r = sc_pkcs15init_authenticate(profile, p15card, file, SC_AC_OP_UPDATE);
  74. + if (r >= 0 && content->len) {
  75. + r = sc_update_binary(p15card->card, 0,
  76. + (const unsigned char *) content->value,
  77. + content->len, 0);
  78. + }
  79. + break;
  80. +
  81. default:
  82. r = SC_ERROR_NOT_IMPLEMENTED;
  83. }
  84. --
  85. 1.9.3