Merge pull request #840 from cjkoenig/update_liburcu
[feed/packages.git] / utils / opensc / patches / 0004-PKCS15-OpenPGP-Declare-DATA-objects.patch
1 From fda9b6dd088e734de372fc85c091f88e8607bc2e 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: Tue, 26 Feb 2013 17:37:16 +0700
5 Subject: [PATCH 04/26] PKCS15-OpenPGP: Declare DATA objects.
6
7 Begin to support read/write DATA object for PKCS-OpenPGP binding.
8 This object is used by TrueCrypt.
9 ---
10 src/libopensc/pkcs15-openpgp.c | 35 +++++++++++++++++++++++++++++++++++
11 1 file changed, 35 insertions(+)
12
13 diff --git a/src/libopensc/pkcs15-openpgp.c b/src/libopensc/pkcs15-openpgp.c
14 index fdf720a..fea2805 100644
15 --- a/src/libopensc/pkcs15-openpgp.c
16 +++ b/src/libopensc/pkcs15-openpgp.c
17 @@ -32,6 +32,7 @@
18 #include "log.h"
19
20 int sc_pkcs15emu_openpgp_init_ex(sc_pkcs15_card_t *, sc_pkcs15emu_opt_t *);
21 +static int sc_pkcs15emu_openpgp_add_data(sc_pkcs15_card_t *);
22
23
24 #define PGP_USER_PIN_FLAGS (SC_PKCS15_PIN_FLAG_CASE_SENSITIVE \
25 @@ -41,6 +42,8 @@ int sc_pkcs15emu_openpgp_init_ex(sc_pkcs15_card_t *, sc_pkcs15emu_opt_t *);
26 | SC_PKCS15_PIN_FLAG_UNBLOCK_DISABLED \
27 | SC_PKCS15_PIN_FLAG_SO_PIN)
28
29 +#define PGP_NUM_PRIVDO 4
30 +
31 typedef struct _pgp_pin_cfg {
32 const char *label;
33 int reference;
34 @@ -355,6 +358,9 @@ sc_pkcs15emu_openpgp_init(sc_pkcs15_card_t *p15card)
35 goto failed;
36 }
37
38 + /* PKCS#15 DATA object from OpenPGP private DOs */
39 + r = sc_pkcs15emu_openpgp_add_data(p15card);
40 +
41 return 0;
42
43 failed: sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "Failed to initialize OpenPGP emulation: %s\n",
44 @@ -362,6 +368,35 @@ failed: sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "Failed to initialize OpenPGP e
45 return r;
46 }
47
48 +static int
49 +sc_pkcs15emu_openpgp_add_data(sc_pkcs15_card_t *p15card)
50 +{
51 + sc_context_t *ctx = p15card->card->ctx;
52 + int i, r;
53 +
54 + LOG_FUNC_CALLED(ctx);
55 + /* There is 4 private DO from 0101 to 0104 */
56 + for (i = 1; i <= PGP_NUM_PRIVDO; i++) {
57 + sc_pkcs15_data_info_t dat_info;
58 + sc_pkcs15_object_t dat_obj;
59 + char name[8];
60 + char path[9];
61 + memset(&dat_info, 0, sizeof(dat_info));
62 + memset(&dat_obj, 0, sizeof(dat_obj));
63 +
64 + sprintf(name, "PrivDO%d", i);
65 + sprintf(path, "3F00010%d", i);
66 +
67 + sc_format_path(path, &dat_info.path);
68 + strlcpy(dat_obj.label, name, sizeof(dat_obj.label));
69 + strlcpy(dat_info.app_label, name, sizeof(dat_info.app_label));
70 +
71 + sc_log(ctx, "Add %s data object", name);
72 + r = sc_pkcs15emu_add_data_object(p15card, &dat_obj, &dat_info);
73 + }
74 + LOG_FUNC_RETURN(ctx, r);
75 +}
76 +
77 static int openpgp_detect_card(sc_pkcs15_card_t *p15card)
78 {
79 if (p15card->card->type == SC_CARD_TYPE_OPENPGP_V1 || p15card->card->type == SC_CARD_TYPE_OPENPGP_V2
80 --
81 2.1.3
82