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.

89 lines
2.8 KiB

  1. From 9af45c4cf052e3a6059a3004082f9ee3d2b3b2bf 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: Fri, 12 Apr 2013 15:33:31 +0700
  5. Subject: [PATCH 15/26] OpenPGP: Delete key as file, for Gnuk.
  6. ---
  7. src/libopensc/card-openpgp.c | 51 +++++++++++++++++++++++++++++++++++++++++++-
  8. 1 file changed, 50 insertions(+), 1 deletion(-)
  9. Index: opensc-20150513/src/libopensc/card-openpgp.c
  10. ===================================================================
  11. --- opensc-20150513.orig/src/libopensc/card-openpgp.c
  12. +++ opensc-20150513/src/libopensc/card-openpgp.c
  13. @@ -2448,6 +2448,44 @@ static int pgp_card_ctl(sc_card_t *card,
  14. LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
  15. }
  16. +
  17. +/* Internal: Delete key */
  18. +static int
  19. +gnuk_delete_key(sc_card_t *card, u8 key_id)
  20. +{
  21. + sc_context_t *ctx = card->ctx;
  22. + int r = SC_SUCCESS;
  23. + u8 *data = NULL;
  24. +
  25. + LOG_FUNC_CALLED(ctx);
  26. +
  27. + /* Delete fingerprint */
  28. + sc_log(ctx, "Delete fingerprints");
  29. + r = pgp_put_data(card, 0xC6 + key_id, NULL, 0);
  30. + LOG_TEST_RET(ctx, r, "Failed to delete fingerprints");
  31. + /* Delete creation time */
  32. + sc_log(ctx, "Delete creation time");
  33. + r = pgp_put_data(card, 0xCD + key_id, NULL, 0);
  34. + LOG_TEST_RET(ctx, r, "Failed to delete creation time");
  35. +
  36. + /* Rewrite Extended Header List */
  37. + sc_log(ctx, "Rewrite Extended Header List");
  38. +
  39. + if (key_id == 1)
  40. + data = "\x4D\x02\xB6";
  41. + else if (key_id == 2)
  42. + data = "\x4D\x02\xB8";
  43. + else if (key_id == 3)
  44. + data = "\x4D\x02\xA4";
  45. + else
  46. + LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ARGUMENTS);
  47. +
  48. + r = pgp_put_data(card, 0x4D, data, strlen(data) + 1);
  49. +
  50. + LOG_FUNC_RETURN(ctx, r);
  51. +}
  52. +
  53. +
  54. /* ABI: DELETE FILE */
  55. static int
  56. pgp_delete_file(sc_card_t *card, const sc_path_t *path)
  57. @@ -2455,6 +2493,7 @@ pgp_delete_file(sc_card_t *card, const s
  58. struct pgp_priv_data *priv = DRVDATA(card);
  59. struct blob *blob;
  60. sc_file_t *file;
  61. + u8 key_id;
  62. int r;
  63. LOG_FUNC_CALLED(card->ctx);
  64. @@ -2470,10 +2509,20 @@ pgp_delete_file(sc_card_t *card, const s
  65. if (blob == priv->mf)
  66. LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
  67. - if (file->id == 0xB601 || file->id == 0xB801 || file->id == 0xA401) {
  68. + if (card->type != SC_CARD_TYPE_OPENPGP_GNUK &&
  69. + (file->id == 0xB601 || file->id == 0xB801 || file->id == 0xA401)) {
  70. /* These tags are just symbolic. We don't really delete it. */
  71. r = SC_SUCCESS;
  72. }
  73. + else if (card->type == SC_CARD_TYPE_OPENPGP_GNUK && file->id == 0xB601) {
  74. + r = gnuk_delete_key(card, 1);
  75. + }
  76. + else if (card->type == SC_CARD_TYPE_OPENPGP_GNUK && file->id == 0xB801) {
  77. + r = gnuk_delete_key(card, 2);
  78. + }
  79. + else if (card->type == SC_CARD_TYPE_OPENPGP_GNUK && file->id == 0xA401) {
  80. + r = gnuk_delete_key(card, 3);
  81. + }
  82. else {
  83. /* call pgp_put_data() with zero-sized NULL-buffer to zap the DO contents */
  84. r = pgp_put_data(card, file->id, NULL, 0);