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.
8 src/libopensc/card-openpgp.c | 51 +++++++++++++++++++++++++++++++++++++++++++-
9 1 file changed, 50 insertions(+), 1 deletion(-)
11 diff --git a/src/libopensc/card-openpgp.c b/src/libopensc/card-openpgp.c
12 index a666163..19d3b04 100644
13 --- a/src/libopensc/card-openpgp.c
14 +++ b/src/libopensc/card-openpgp.c
15 @@ -2437,6 +2437,44 @@ static int pgp_card_ctl(sc_card_t *card, unsigned long cmd, void *ptr)
16 LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
20 +/* Internal: Delete key */
22 +gnuk_delete_key(sc_card_t *card, u8 key_id)
24 + sc_context_t *ctx = card->ctx;
28 + LOG_FUNC_CALLED(ctx);
30 + /* Delete fingerprint */
31 + sc_log(ctx, "Delete fingerprints");
32 + r = pgp_put_data(card, 0xC6 + key_id, NULL, 0);
33 + LOG_TEST_RET(ctx, r, "Failed to delete fingerprints");
34 + /* Delete creation time */
35 + sc_log(ctx, "Delete creation time");
36 + r = pgp_put_data(card, 0xCD + key_id, NULL, 0);
37 + LOG_TEST_RET(ctx, r, "Failed to delete creation time");
39 + /* Rewrite Extended Header List */
40 + sc_log(ctx, "Rewrite Extended Header List");
43 + data = "\x4D\x02\xB6";
44 + else if (key_id == 2)
45 + data = "\x4D\x02\xB8";
46 + else if (key_id == 3)
47 + data = "\x4D\x02\xA4";
49 + LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ARGUMENTS);
51 + r = pgp_put_data(card, 0x4D, data, strlen(data) + 1);
53 + LOG_FUNC_RETURN(ctx, r);
57 /* ABI: DELETE FILE */
59 pgp_delete_file(sc_card_t *card, const sc_path_t *path)
60 @@ -2444,6 +2482,7 @@ pgp_delete_file(sc_card_t *card, const sc_path_t *path)
61 struct pgp_priv_data *priv = DRVDATA(card);
67 LOG_FUNC_CALLED(card->ctx);
68 @@ -2459,10 +2498,20 @@ pgp_delete_file(sc_card_t *card, const sc_path_t *path)
70 LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
72 - if (file->id == 0xB601 || file->id == 0xB801 || file->id == 0xA401) {
73 + if (card->type != SC_CARD_TYPE_OPENPGP_GNUK &&
74 + (file->id == 0xB601 || file->id == 0xB801 || file->id == 0xA401)) {
75 /* These tags are just symbolic. We don't really delete it. */
78 + else if (card->type == SC_CARD_TYPE_OPENPGP_GNUK && file->id == 0xB601) {
79 + r = gnuk_delete_key(card, 1);
81 + else if (card->type == SC_CARD_TYPE_OPENPGP_GNUK && file->id == 0xB801) {
82 + r = gnuk_delete_key(card, 2);
84 + else if (card->type == SC_CARD_TYPE_OPENPGP_GNUK && file->id == 0xA401) {
85 + r = gnuk_delete_key(card, 3);
88 /* call pgp_put_data() with zero-sized NULL-buffer to zap the DO contents */
89 r = pgp_put_data(card, file->id, NULL, 0);