liburcu: Update to 0.8.6
[feed/packages.git] / utils / opensc / patches / 0015-OpenPGP-Delete-key-as-file-for-Gnuk.patch
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 ---
8 src/libopensc/card-openpgp.c | 51 +++++++++++++++++++++++++++++++++++++++++++-
9 1 file changed, 50 insertions(+), 1 deletion(-)
10
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);
17 }
18
19 +
20 +/* Internal: Delete key */
21 +static int
22 +gnuk_delete_key(sc_card_t *card, u8 key_id)
23 +{
24 + sc_context_t *ctx = card->ctx;
25 + int r = SC_SUCCESS;
26 + u8 *data = NULL;
27 +
28 + LOG_FUNC_CALLED(ctx);
29 +
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");
38 +
39 + /* Rewrite Extended Header List */
40 + sc_log(ctx, "Rewrite Extended Header List");
41 +
42 + if (key_id == 1)
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";
48 + else
49 + LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ARGUMENTS);
50 +
51 + r = pgp_put_data(card, 0x4D, data, strlen(data) + 1);
52 +
53 + LOG_FUNC_RETURN(ctx, r);
54 +}
55 +
56 +
57 /* ABI: DELETE FILE */
58 static int
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);
62 struct blob *blob;
63 sc_file_t *file;
64 + u8 key_id;
65 int r;
66
67 LOG_FUNC_CALLED(card->ctx);
68 @@ -2459,10 +2498,20 @@ pgp_delete_file(sc_card_t *card, const sc_path_t *path)
69 if (blob == priv->mf)
70 LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
71
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. */
76 r = SC_SUCCESS;
77 }
78 + else if (card->type == SC_CARD_TYPE_OPENPGP_GNUK && file->id == 0xB601) {
79 + r = gnuk_delete_key(card, 1);
80 + }
81 + else if (card->type == SC_CARD_TYPE_OPENPGP_GNUK && file->id == 0xB801) {
82 + r = gnuk_delete_key(card, 2);
83 + }
84 + else if (card->type == SC_CARD_TYPE_OPENPGP_GNUK && file->id == 0xA401) {
85 + r = gnuk_delete_key(card, 3);
86 + }
87 else {
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);
90 --
91 1.9.3
92