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.

92 lines
2.8 KiB

  1. From 693b3ac5a53e89a0cdeab0f728d24a6e16864f5c 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/18] OpenPGP: Delete key as file, for Gnuk.
  6. ---
  7. src/libopensc/card-openpgp.c | 51 +++++++++++++++++++++++++++++++++++++++++++-
  8. 1 file changed, 50 insertions(+), 1 deletion(-)
  9. diff --git a/src/libopensc/card-openpgp.c b/src/libopensc/card-openpgp.c
  10. index a666163..19d3b04 100644
  11. --- a/src/libopensc/card-openpgp.c
  12. +++ b/src/libopensc/card-openpgp.c
  13. @@ -2437,6 +2437,44 @@ static int pgp_card_ctl(sc_card_t *card, unsigned long cmd, void *ptr)
  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. @@ -2444,6 +2482,7 @@ pgp_delete_file(sc_card_t *card, const sc_path_t *path)
  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. @@ -2459,10 +2498,20 @@ pgp_delete_file(sc_card_t *card, const sc_path_t *path)
  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);
  85. --
  86. 1.9.3