1 From 42adc35954e18e24f253f710b16d850d1872bce5 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: Wed, 27 Mar 2013 11:38:42 +0700
5 Subject: [PATCH 09/26] PKCS15-OpenPGP: Do not show empty DO in pkcs15
9 src/libopensc/pkcs15-openpgp.c | 18 ++++++++++++++++++
10 1 file changed, 18 insertions(+)
12 diff --git a/src/libopensc/pkcs15-openpgp.c b/src/libopensc/pkcs15-openpgp.c
13 index fea2805..51a2032 100644
14 --- a/src/libopensc/pkcs15-openpgp.c
15 +++ b/src/libopensc/pkcs15-openpgp.c
16 @@ -381,16 +381,34 @@ sc_pkcs15emu_openpgp_add_data(sc_pkcs15_card_t *p15card)
17 sc_pkcs15_object_t dat_obj;
21 memset(&dat_info, 0, sizeof(dat_info));
22 memset(&dat_obj, 0, sizeof(dat_obj));
24 sprintf(name, "PrivDO%d", i);
25 sprintf(path, "3F00010%d", i);
27 + /* Check if the DO can be read.
28 + * We won't expose pkcs15 DATA object if DO is empty.
30 + r = read_file(p15card->card, path, content, sizeof(content));
32 + sc_log(ctx, "Cannot read DO 010%d or there is no data in it", i);
36 sc_format_path(path, &dat_info.path);
37 strlcpy(dat_obj.label, name, sizeof(dat_obj.label));
38 strlcpy(dat_info.app_label, name, sizeof(dat_info.app_label));
40 + /* Add DATA object to slot protected by PIN2 (PW1 with Ref 0x82) */
41 + dat_obj.flags = SC_PKCS15_CO_FLAG_PRIVATE | SC_PKCS15_CO_FLAG_MODIFIABLE;
42 + dat_obj.auth_id.len = 1;
43 + if (i == 1 || i == 3)
44 + dat_obj.auth_id.value[0] = 2;
46 + dat_obj.auth_id.value[0] = 3;
48 sc_log(ctx, "Add %s data object", name);
49 r = sc_pkcs15emu_add_data_object(p15card, &dat_obj, &dat_info);