Bläddra i källkod

opensc: bump to git codebase of 20141126 and rebase GnuK patches

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Daniel Golle 10 år sedan
förälder
incheckning
36ed0c44fc
27 ändrade filer med 1209 tillägg och 175 borttagningar
  1. 2
    2
      utils/opensc/Makefile
  2. 23
    32
      utils/opensc/patches/0001-OpenPGP-Detect-and-support-Gnuk-Token.patch
  3. 10
    10
      utils/opensc/patches/0002-OpenPGP-Add-Gnuk-in-pkcs15-emulation-layer.patch
  4. 4
    4
      utils/opensc/patches/0003-OpenPGP-Include-private-DO-to-filesystem-at-driver-i.patch
  5. 9
    9
      utils/opensc/patches/0004-PKCS15-OpenPGP-Declare-DATA-objects.patch
  6. 27
    28
      utils/opensc/patches/0005-OpenPGP-Support-erasing-reset-card.patch
  7. 18
    20
      utils/opensc/patches/0006-openpgp-tool-Support-deleting-key-in-Gnuk.patch
  8. 5
    5
      utils/opensc/patches/0007-OpenPGP-Correct-building-Extended-Header-List-when-i.patch
  9. 6
    6
      utils/opensc/patches/0008-OpenPGP-Read-some-empty-DOs-from-Gnuk.patch
  10. 5
    5
      utils/opensc/patches/0009-PKCS15-OpenPGP-Do-not-show-empty-DO-in-pkcs15-emu_in.patch
  11. 5
    5
      utils/opensc/patches/0010-PKCS15-OpenPGP-Allow-to-store-data-to-pkcs15-data-ob.patch
  12. 6
    6
      utils/opensc/patches/0011-OpenPGP-Provide-enough-buffer-to-read-pubkey-from-Gn.patch
  13. 8
    8
      utils/opensc/patches/0012-OpenPGP-Support-write-certificate-for-Gnuk.patch
  14. 3
    3
      utils/opensc/patches/0013-pkcs15-openpgp-Change-to-sc_put_data-instead-of-sc_u.patch
  15. 6
    6
      utils/opensc/patches/0014-OpenPGP-Overcome-the-restriction-of-even-data-length.patch
  16. 7
    7
      utils/opensc/patches/0015-OpenPGP-Delete-key-as-file-for-Gnuk.patch
  17. 7
    7
      utils/opensc/patches/0016-OpenPGP-Correct-parameter-checking.patch
  18. 6
    6
      utils/opensc/patches/0017-OpenPGP-Make-code-neater.patch
  19. 6
    6
      utils/opensc/patches/0018-Move-declaration-to-top-of-block.patch
  20. 182
    0
      utils/opensc/patches/0019-OpenPGP-Make-indentation-consistent-space-tab.patch
  21. 84
    0
      utils/opensc/patches/0020-OpenPGP-Don-t-use-sc_log-in-openpgp-tool.patch
  22. 112
    0
      utils/opensc/patches/0021-OpenPGP-Don-t-reimplement-gnuk_delete_key-in-openpgp.patch
  23. 87
    0
      utils/opensc/patches/0022-OpenPGP-Use-directly-binary-array-of-APDUs-for-ERASE.patch
  24. 339
    0
      utils/opensc/patches/0023-OpenPGP-Rename-private-blob-type-to-avoid-confusing-.patch
  25. 41
    0
      utils/opensc/patches/0024-OpenPGP-Fix-crash-after-accessing-inexistent-file.patch
  26. 148
    0
      utils/opensc/patches/0025-Replace-hardcode.patch
  27. 53
    0
      utils/opensc/patches/0026-hardcode-defines-for-DO-s.patch

+ 2
- 2
utils/opensc/Makefile Visa fil

@@ -8,7 +8,7 @@
8 8
 include $(TOPDIR)/rules.mk
9 9
 
10 10
 PKG_NAME:=opensc
11
-PKG_VERSION:=20140317
11
+PKG_VERSION:=20141126
12 12
 PKG_RELEASE:=1
13 13
 PKG_LICENSE:=LGPL-2.1+
14 14
 PKG_LICENSE_FILES:=COPYING
@@ -19,7 +19,7 @@ PKG_RELEASE=$(PKG_SOURCE_VERSION)
19 19
 PKG_SOURCE_PROTO:=git
20 20
 PKG_SOURCE_URL:=https://github.com/OpenSC/OpenSC.git
21 21
 PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION)
22
-PKG_SOURCE_VERSION:=de6d61405b271e22244376e4817e16b49018e1ce
22
+PKG_SOURCE_VERSION:=8aadbbd678730dbafb819382da553439887499fd
23 23
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
24 24
 PKG_BUILD_DEPENDS:=+libpcsclite
25 25
 PKG_FIXUP:=libtool

+ 23
- 32
utils/opensc/patches/0001-OpenPGP-Detect-and-support-Gnuk-Token.patch Visa fil

@@ -1,18 +1,18 @@
1
-From c706491fc9b08d4cc6d7b254cf936d6b8d8691bc Mon Sep 17 00:00:00 2001
1
+From 471b40173b73f213ee72bf05735abf3357658197 Mon Sep 17 00:00:00 2001
2 2
 From: =?UTF-8?q?Nguy=E1=BB=85n=20H=E1=BB=93ng=20Qu=C3=A2n?=
3 3
  <ng.hong.quan@gmail.com>
4 4
 Date: Wed, 20 Feb 2013 11:54:30 +0700
5
-Subject: [PATCH 01/18] OpenPGP: Detect and support Gnuk Token.
5
+Subject: [PATCH 01/26] OpenPGP: Detect and support Gnuk Token.
6 6
 
7 7
 http://www.fsij.org/gnuk/
8 8
 ---
9 9
  src/libopensc/card-openpgp.c | 61 ++++++++++++++++++++++++++++++++++----------
10 10
  src/libopensc/cards.h        |  1 +
11
- src/tools/openpgp-tool.c     |  9 +++++--
12
- 3 files changed, 56 insertions(+), 15 deletions(-)
11
+ src/tools/openpgp-tool.c     |  7 ++++-
12
+ 3 files changed, 55 insertions(+), 14 deletions(-)
13 13
 
14 14
 diff --git a/src/libopensc/card-openpgp.c b/src/libopensc/card-openpgp.c
15
-index 743e79c..716052b 100644
15
+index 6774fe1..c785a55 100644
16 16
 --- a/src/libopensc/card-openpgp.c
17 17
 +++ b/src/libopensc/card-openpgp.c
18 18
 @@ -43,6 +43,7 @@
@@ -66,7 +66,7 @@ index 743e79c..716052b 100644
66 66
  				priv->ext_caps |= EXT_CAP_SM;
67 67
  
68 68
  			if ((priv->bcd_version >= OPENPGP_CARD_2_0) && (blob->len >= 10)) {
69
-@@ -1055,12 +1060,18 @@ static int
69
+@@ -1057,12 +1062,18 @@ static int
70 70
  pgp_get_pubkey(sc_card_t *card, unsigned int tag, u8 *buf, size_t buf_len)
71 71
  {
72 72
  	sc_apdu_t	apdu;
@@ -86,7 +86,7 @@ index 743e79c..716052b 100644
86 86
  	apdu.lc = 2;
87 87
  	apdu.data = ushort2bebytes(idbuf, tag);
88 88
  	apdu.datalen = 2;
89
-@@ -1152,6 +1163,7 @@ pgp_put_data(sc_card_t *card, unsigned int tag, const u8 *buf, size_t buf_len)
89
+@@ -1154,6 +1165,7 @@ pgp_put_data(sc_card_t *card, unsigned int tag, const u8 *buf, size_t buf_len)
90 90
  	u8 ins = 0xDA;
91 91
  	u8 p1 = tag >> 8;
92 92
  	u8 p2 = tag & 0xFF;
@@ -94,7 +94,7 @@ index 743e79c..716052b 100644
94 94
  	int r;
95 95
  
96 96
  	LOG_FUNC_CALLED(card->ctx);
97
-@@ -1193,13 +1205,17 @@ pgp_put_data(sc_card_t *card, unsigned int tag, const u8 *buf, size_t buf_len)
97
+@@ -1195,13 +1207,17 @@ pgp_put_data(sc_card_t *card, unsigned int tag, const u8 *buf, size_t buf_len)
98 98
  
99 99
  	/* Build APDU */
100 100
  	if (buf != NULL && buf_len > 0) {
@@ -114,7 +114,7 @@ index 743e79c..716052b 100644
114 114
  		apdu.datalen = buf_len;
115 115
  		apdu.lc = buf_len;
116 116
  	}
117
-@@ -1326,6 +1342,7 @@ pgp_compute_signature(sc_card_t *card, const u8 *data,
117
+@@ -1328,6 +1344,7 @@ pgp_compute_signature(sc_card_t *card, const u8 *data,
118 118
  	struct pgp_priv_data	*priv = DRVDATA(card);
119 119
  	sc_security_env_t	*env = &priv->sec_env;
120 120
  	sc_apdu_t		apdu;
@@ -122,7 +122,7 @@ index 743e79c..716052b 100644
122 122
  	int			r;
123 123
  
124 124
  	LOG_FUNC_CALLED(card->ctx);
125
-@@ -1334,14 +1351,19 @@ pgp_compute_signature(sc_card_t *card, const u8 *data,
125
+@@ -1336,14 +1353,19 @@ pgp_compute_signature(sc_card_t *card, const u8 *data,
126 126
  		LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_ARGUMENTS,
127 127
  				"invalid operation");
128 128
  
@@ -144,7 +144,7 @@ index 743e79c..716052b 100644
144 144
  		break;
145 145
  	case 0x01:
146 146
  	default:
147
-@@ -1350,7 +1372,7 @@ pgp_compute_signature(sc_card_t *card, const u8 *data,
147
+@@ -1352,7 +1374,7 @@ pgp_compute_signature(sc_card_t *card, const u8 *data,
148 148
  	}
149 149
  
150 150
  	apdu.lc = data_len;
@@ -153,7 +153,7 @@ index 743e79c..716052b 100644
153 153
  	apdu.datalen = data_len;
154 154
  	apdu.le = ((outlen >= 256) && !(card->caps & SC_CARD_CAP_APDU_EXT)) ? 256 : outlen;
155 155
  	apdu.resp    = out;
156
-@@ -1374,6 +1396,7 @@ pgp_decipher(sc_card_t *card, const u8 *in, size_t inlen,
156
+@@ -1376,6 +1398,7 @@ pgp_decipher(sc_card_t *card, const u8 *in, size_t inlen,
157 157
  	struct pgp_priv_data	*priv = DRVDATA(card);
158 158
  	sc_security_env_t	*env = &priv->sec_env;
159 159
  	sc_apdu_t	apdu;
@@ -161,7 +161,7 @@ index 743e79c..716052b 100644
161 161
  	u8		*temp = NULL;
162 162
  	int		r;
163 163
  
164
-@@ -1398,7 +1421,7 @@ pgp_decipher(sc_card_t *card, const u8 *in, size_t inlen,
164
+@@ -1400,7 +1423,7 @@ pgp_decipher(sc_card_t *card, const u8 *in, size_t inlen,
165 165
  	case 0x01: /* Decryption key */
166 166
  	case 0x02: /* authentication key */
167 167
  		/* PSO DECIPHER */
@@ -170,7 +170,7 @@ index 743e79c..716052b 100644
170 170
  		break;
171 171
  	case 0x00: /* signature key */
172 172
  	default:
173
-@@ -1407,8 +1430,13 @@ pgp_decipher(sc_card_t *card, const u8 *in, size_t inlen,
173
+@@ -1409,8 +1432,13 @@ pgp_decipher(sc_card_t *card, const u8 *in, size_t inlen,
174 174
  				"invalid key reference");
175 175
  	}
176 176
  
@@ -209,10 +209,10 @@ index 743e79c..716052b 100644
209 209
  		 * sc_format_apdu() */
210 210
  		apdu_le = card->max_recv_size;
211 211
 diff --git a/src/libopensc/cards.h b/src/libopensc/cards.h
212
-index 0fbf9ca..01b08fd 100644
212
+index 7be6667..a3f3634 100644
213 213
 --- a/src/libopensc/cards.h
214 214
 +++ b/src/libopensc/cards.h
215
-@@ -104,6 +104,7 @@ enum {
215
+@@ -105,6 +105,7 @@ enum {
216 216
  	SC_CARD_TYPE_OPENPGP_BASE = 9000,
217 217
  	SC_CARD_TYPE_OPENPGP_V1,
218 218
  	SC_CARD_TYPE_OPENPGP_V2,
@@ -221,27 +221,18 @@ index 0fbf9ca..01b08fd 100644
221 221
  	/* jcop driver */
222 222
  	SC_CARD_TYPE_JCOP_BASE = 10000,
223 223
 diff --git a/src/tools/openpgp-tool.c b/src/tools/openpgp-tool.c
224
-index 7058aaa..8b5e327 100644
224
+index f42e6d6..a24a395 100644
225 225
 --- a/src/tools/openpgp-tool.c
226 226
 +++ b/src/tools/openpgp-tool.c
227
-@@ -32,6 +32,7 @@
228
- #include "libopensc/asn1.h"
227
+@@ -33,6 +33,7 @@
229 228
  #include "libopensc/cards.h"
230 229
  #include "libopensc/cardctl.h"
230
+ #include "libopensc/errors.h"
231 231
 +#include "libopensc/log.h"
232 232
  #include "util.h"
233
+ #include "libopensc/log.h"
233 234
  
234
- #define	OPT_RAW		256
235
-@@ -216,7 +217,7 @@ static void display_data(const struct ef_name_map *mapping, char *value)
236
- 			} else {
237
- 				const char *label = mapping->name;
238
- 
239
--				printf("%s:%*s%s\n", label, 10-strlen(label), "", value);
240
-+				printf("%s:%*s%s\n", label, 10 - (int)strlen(label), "", value);
241
- 			}
242
- 		}
243
- 	}
244
-@@ -390,6 +391,8 @@ int do_genkey(sc_card_t *card, u8 key_id, unsigned int key_len)
235
+@@ -396,6 +397,8 @@ int do_genkey(sc_card_t *card, u8 key_id, unsigned int key_len)
245 236
  	sc_path_t path;
246 237
  	sc_file_t *file;
247 238
  
@@ -250,7 +241,7 @@ index 7058aaa..8b5e327 100644
250 241
  	if (key_id < 1 || key_id > 3) {
251 242
  		printf("Unknown key ID %d.\n", key_id);
252 243
  		return 1;
253
-@@ -481,8 +484,10 @@ int main(int argc, char **argv)
244
+@@ -487,8 +490,10 @@ int main(int argc, char **argv)
254 245
  
255 246
  	/* check card type */
256 247
  	if ((card->type != SC_CARD_TYPE_OPENPGP_V1) &&
@@ -263,5 +254,5 @@ index 7058aaa..8b5e327 100644
263 254
  		goto out;
264 255
  	}
265 256
 -- 
266
-1.9.3
257
+2.1.3
267 258
 

+ 10
- 10
utils/opensc/patches/0002-OpenPGP-Add-Gnuk-in-pkcs15-emulation-layer.patch Visa fil

@@ -1,8 +1,8 @@
1
-From ecc6460d17147b37def27a9b776e1fc5a61408d0 Mon Sep 17 00:00:00 2001
1
+From 00a2c08c9125103ee0bff9af9e7ff42c5cdc14fe Mon Sep 17 00:00:00 2001
2 2
 From: =?UTF-8?q?Nguy=E1=BB=85n=20H=E1=BB=93ng=20Qu=C3=A2n?=
3 3
  <ng.hong.quan@gmail.com>
4 4
 Date: Fri, 12 Apr 2013 17:24:00 +0700
5
-Subject: [PATCH 02/18] OpenPGP: Add Gnuk in pkcs15 emulation layer.
5
+Subject: [PATCH 02/26] OpenPGP: Add Gnuk in pkcs15 emulation layer.
6 6
 
7 7
 ---
8 8
  src/libopensc/pkcs15-openpgp.c | 6 ++++--
@@ -10,10 +10,10 @@ Subject: [PATCH 02/18] OpenPGP: Add Gnuk in pkcs15 emulation layer.
10 10
  2 files changed, 5 insertions(+), 2 deletions(-)
11 11
 
12 12
 diff --git a/src/libopensc/pkcs15-openpgp.c b/src/libopensc/pkcs15-openpgp.c
13
-index d9dc074..5a8a1ca 100644
13
+index 4daaa98..fdf720a 100644
14 14
 --- a/src/libopensc/pkcs15-openpgp.c
15 15
 +++ b/src/libopensc/pkcs15-openpgp.c
16
-@@ -155,7 +155,8 @@ sc_pkcs15emu_openpgp_init(sc_pkcs15_card_t *p15card)
16
+@@ -151,7 +151,8 @@ sc_pkcs15emu_openpgp_init(sc_pkcs15_card_t *p15card)
17 17
  	u8		c4data[10];
18 18
  	u8		c5data[70];
19 19
  	int		r, i;
@@ -23,7 +23,7 @@ index d9dc074..5a8a1ca 100644
23 23
  	sc_path_t path;
24 24
  	sc_file_t *file;
25 25
  
26
-@@ -367,7 +368,8 @@ failed:	sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "Failed to initialize OpenPGP e
26
+@@ -363,7 +364,8 @@ failed:	sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "Failed to initialize OpenPGP e
27 27
  
28 28
  static int openpgp_detect_card(sc_pkcs15_card_t *p15card)
29 29
  {
@@ -34,17 +34,17 @@ index d9dc074..5a8a1ca 100644
34 34
  	else
35 35
  		return SC_ERROR_WRONG_CARD;
36 36
 diff --git a/src/libopensc/pkcs15-syn.c b/src/libopensc/pkcs15-syn.c
37
-index e2f6004..a9f8c0b 100644
37
+index ffbf642..d2c086c 100644
38 38
 --- a/src/libopensc/pkcs15-syn.c
39 39
 +++ b/src/libopensc/pkcs15-syn.c
40
-@@ -112,6 +112,7 @@ int sc_pkcs15_is_emulation_only(sc_card_t *card)
40
+@@ -115,6 +115,7 @@ int sc_pkcs15_is_emulation_only(sc_card_t *card)
41 41
  		case SC_CARD_TYPE_GEMSAFEV1_PTEID:
42 42
  		case SC_CARD_TYPE_OPENPGP_V1:
43 43
  		case SC_CARD_TYPE_OPENPGP_V2:
44 44
 +		case SC_CARD_TYPE_OPENPGP_GNUK:
45 45
  		case SC_CARD_TYPE_SC_HSM:
46
- 			return 1;
47
- 		default:
46
+ 		case SC_CARD_TYPE_DNIE_BASE:
47
+ 		case SC_CARD_TYPE_DNIE_BLANK:
48 48
 -- 
49
-1.9.3
49
+2.1.3
50 50
 

+ 4
- 4
utils/opensc/patches/0003-OpenPGP-Include-private-DO-to-filesystem-at-driver-i.patch Visa fil

@@ -1,8 +1,8 @@
1
-From 5f751ba5628f9d85e9d8dca9939a93f49d2525d0 Mon Sep 17 00:00:00 2001
1
+From 2d348b60ab8c22791b56f291600954abd716a791 Mon Sep 17 00:00:00 2001
2 2
 From: =?UTF-8?q?Nguy=E1=BB=85n=20H=E1=BB=93ng=20Qu=C3=A2n?=
3 3
  <ng.hong.quan@gmail.com>
4 4
 Date: Fri, 22 Mar 2013 17:37:16 +0700
5
-Subject: [PATCH 03/18] OpenPGP: Include private DO to filesystem at driver
5
+Subject: [PATCH 03/26] OpenPGP: Include private DO to filesystem at driver
6 6
  initialization.
7 7
 
8 8
 In old implementation, the DOs which their access is restricted by
@@ -13,7 +13,7 @@ leading to that we cannot read their data later, even if we verified PIN.
13 13
  1 file changed, 1 insertion(+), 1 deletion(-)
14 14
 
15 15
 diff --git a/src/libopensc/card-openpgp.c b/src/libopensc/card-openpgp.c
16
-index 716052b..ead07ae 100644
16
+index c785a55..1cc3923 100644
17 17
 --- a/src/libopensc/card-openpgp.c
18 18
 +++ b/src/libopensc/card-openpgp.c
19 19
 @@ -357,7 +357,7 @@ pgp_init(sc_card_t *card)
@@ -26,5 +26,5 @@ index 716052b..ead07ae 100644
26 26
  			child = pgp_new_blob(card, priv->mf, info->id, sc_file_new());
27 27
  
28 28
 -- 
29
-1.9.3
29
+2.1.3
30 30
 

+ 9
- 9
utils/opensc/patches/0004-PKCS15-OpenPGP-Declare-DATA-objects.patch Visa fil

@@ -1,8 +1,8 @@
1
-From fbf8e392db4456de97796259a62ccb972fe24df8 Mon Sep 17 00:00:00 2001
1
+From fda9b6dd088e734de372fc85c091f88e8607bc2e Mon Sep 17 00:00:00 2001
2 2
 From: =?UTF-8?q?Nguy=E1=BB=85n=20H=E1=BB=93ng=20Qu=C3=A2n?=
3 3
  <ng.hong.quan@gmail.com>
4 4
 Date: Tue, 26 Feb 2013 17:37:16 +0700
5
-Subject: [PATCH 04/18] PKCS15-OpenPGP: Declare DATA objects.
5
+Subject: [PATCH 04/26] PKCS15-OpenPGP: Declare DATA objects.
6 6
 
7 7
 Begin to support read/write DATA object for PKCS-OpenPGP binding.
8 8
 This object is used by TrueCrypt.
@@ -11,18 +11,18 @@ This object is used by TrueCrypt.
11 11
  1 file changed, 35 insertions(+)
12 12
 
13 13
 diff --git a/src/libopensc/pkcs15-openpgp.c b/src/libopensc/pkcs15-openpgp.c
14
-index 5a8a1ca..9f239ef 100644
14
+index fdf720a..fea2805 100644
15 15
 --- a/src/libopensc/pkcs15-openpgp.c
16 16
 +++ b/src/libopensc/pkcs15-openpgp.c
17
-@@ -36,6 +36,7 @@ typedef USHORT ushort;
18
- #endif
17
+@@ -32,6 +32,7 @@
18
+ #include "log.h"
19 19
  
20 20
  int sc_pkcs15emu_openpgp_init_ex(sc_pkcs15_card_t *, sc_pkcs15emu_opt_t *);
21 21
 +static int sc_pkcs15emu_openpgp_add_data(sc_pkcs15_card_t *);
22 22
  
23 23
  
24 24
  #define	PGP_USER_PIN_FLAGS	(SC_PKCS15_PIN_FLAG_CASE_SENSITIVE \
25
-@@ -45,6 +46,8 @@ int sc_pkcs15emu_openpgp_init_ex(sc_pkcs15_card_t *, sc_pkcs15emu_opt_t *);
25
+@@ -41,6 +42,8 @@ int sc_pkcs15emu_openpgp_init_ex(sc_pkcs15_card_t *, sc_pkcs15emu_opt_t *);
26 26
  				| SC_PKCS15_PIN_FLAG_UNBLOCK_DISABLED \
27 27
  				| SC_PKCS15_PIN_FLAG_SO_PIN)
28 28
  
@@ -31,7 +31,7 @@ index 5a8a1ca..9f239ef 100644
31 31
  typedef struct _pgp_pin_cfg {
32 32
  	const char	*label;
33 33
  	int		reference;
34
-@@ -359,6 +362,9 @@ sc_pkcs15emu_openpgp_init(sc_pkcs15_card_t *p15card)
34
+@@ -355,6 +358,9 @@ sc_pkcs15emu_openpgp_init(sc_pkcs15_card_t *p15card)
35 35
  			goto failed;
36 36
  	}
37 37
  
@@ -41,7 +41,7 @@ index 5a8a1ca..9f239ef 100644
41 41
  	return 0;
42 42
  
43 43
  failed:	sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "Failed to initialize OpenPGP emulation: %s\n",
44
-@@ -366,6 +372,35 @@ failed:	sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "Failed to initialize OpenPGP e
44
+@@ -362,6 +368,35 @@ failed:	sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "Failed to initialize OpenPGP e
45 45
  	return r;
46 46
  }
47 47
  
@@ -78,5 +78,5 @@ index 5a8a1ca..9f239ef 100644
78 78
  {
79 79
  	if (p15card->card->type == SC_CARD_TYPE_OPENPGP_V1 || p15card->card->type == SC_CARD_TYPE_OPENPGP_V2
80 80
 -- 
81
-1.9.3
81
+2.1.3
82 82
 

+ 27
- 28
utils/opensc/patches/0005-OpenPGP-Support-erasing-reset-card.patch Visa fil

@@ -1,20 +1,20 @@
1
-From 4cdc5f3102f5ad93d263eea2f8206bb5e9fffc6c Mon Sep 17 00:00:00 2001
1
+From 6d138f0199575516bfaad18cbbafcfa2ee61e58f Mon Sep 17 00:00:00 2001
2 2
 From: =?UTF-8?q?Nguy=E1=BB=85n=20H=E1=BB=93ng=20Qu=C3=A2n?=
3 3
  <ng.hong.quan@gmail.com>
4 4
 Date: Mon, 4 Mar 2013 11:28:08 +0700
5
-Subject: [PATCH 05/18] OpenPGP: Support erasing (reset) card.
5
+Subject: [PATCH 05/26] OpenPGP: Support erasing (reset) card.
6 6
 
7 7
 Command: openpgp-tool --erase
8 8
 ---
9 9
  src/libopensc/card-openpgp.c | 64 ++++++++++++++++++++++++++++++++++++++++++++
10
- src/tools/openpgp-tool.c     | 23 +++++++++++++++-
11
- 2 files changed, 86 insertions(+), 1 deletion(-)
10
+ src/tools/openpgp-tool.c     | 22 ++++++++++++++-
11
+ 2 files changed, 85 insertions(+), 1 deletion(-)
12 12
 
13 13
 diff --git a/src/libopensc/card-openpgp.c b/src/libopensc/card-openpgp.c
14
-index ead07ae..42a9684 100644
14
+index 1cc3923..7349876 100644
15 15
 --- a/src/libopensc/card-openpgp.c
16 16
 +++ b/src/libopensc/card-openpgp.c
17
-@@ -2197,6 +2197,66 @@ out:
17
+@@ -2195,6 +2195,66 @@ out:
18 18
  
19 19
  #endif /* ENABLE_OPENSSL */
20 20
  
@@ -81,7 +81,7 @@ index ead07ae..42a9684 100644
81 81
  /* ABI: card ctl: perform special card-specific operations */
82 82
  static int pgp_card_ctl(sc_card_t *card, unsigned long cmd, void *ptr)
83 83
  {
84
-@@ -2221,6 +2281,10 @@ static int pgp_card_ctl(sc_card_t *card, unsigned long cmd, void *ptr)
84
+@@ -2219,6 +2279,10 @@ static int pgp_card_ctl(sc_card_t *card, unsigned long cmd, void *ptr)
85 85
  		LOG_FUNC_RETURN(card->ctx, r);
86 86
  		break;
87 87
  #endif /* ENABLE_OPENSSL */
@@ -93,53 +93,52 @@ index ead07ae..42a9684 100644
93 93
  
94 94
  	LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
95 95
 diff --git a/src/tools/openpgp-tool.c b/src/tools/openpgp-tool.c
96
-index 8b5e327..0d360a3 100644
96
+index a24a395..de1c9d4 100644
97 97
 --- a/src/tools/openpgp-tool.c
98 98
 +++ b/src/tools/openpgp-tool.c
99
-@@ -76,6 +76,7 @@ static int opt_verify = 0;
100
- static char *verifytype = NULL;
101
- static int opt_pin = 0;
99
+@@ -78,6 +78,7 @@ static int opt_pin = 0;
102 100
  static char *pin = NULL;
101
+ static int opt_dump_do = 0;
102
+ static u8 do_dump_idx;
103 103
 +static int opt_erase = 0;
104 104
  
105 105
  static const char *app_name = "openpgp-tool";
106 106
  
107
-@@ -92,6 +93,7 @@ static const struct option options[] = {
107
+@@ -94,6 +95,7 @@ static const struct option options[] = {
108 108
  	{ "help",      no_argument,       NULL, 'h'        },
109 109
  	{ "verbose",   no_argument,       NULL, 'v'        },
110 110
  	{ "version",   no_argument,       NULL, 'V'        },
111 111
 +	{ "erase",     no_argument,       NULL, 'E'        },
112 112
  	{ "verify",    required_argument, NULL, OPT_VERIFY },
113 113
  	{ "pin",       required_argument, NULL, OPT_PIN },
114
- 	{ NULL, 0, NULL, 0 }
115
-@@ -110,6 +112,7 @@ static const char *option_help[] = {
114
+ 	{ "do",        required_argument, NULL, 'd' },
115
+@@ -113,6 +115,7 @@ static const char *option_help[] = {
116 116
  /* h */	"Print this help message",
117 117
  /* v */	"Verbose operation. Use several times to enable debug output.",
118 118
  /* V */	"Show version number",
119 119
 +/* E */	"Erase (reset) the card",
120 120
  	"Verify PIN (CHV1, CHV2, CHV3...)",
121
- 	"PIN string"
122
- };
123
-@@ -228,7 +231,7 @@ static int decode_options(int argc, char **argv)
121
+ 	"PIN string",
122
+ /* d */ "Dump private data object number <arg> (i.e. PRIVATE-DO-<arg>)"
123
+@@ -232,7 +235,7 @@ static int decode_options(int argc, char **argv)
124 124
  {
125 125
  	int c;
126 126
  
127
--	while ((c = getopt_long(argc, argv,"r:x:CUG:L:hwvV", options, (int *) 0)) != EOF) {
128
-+	while ((c = getopt_long(argc, argv,"r:x:CUG:L:hwvVE", options, (int *) 0)) != EOF) {
127
+-	while ((c = getopt_long(argc, argv,"r:x:CUG:L:hwvVd:", options, (int *) 0)) != EOF) {
128
++	while ((c = getopt_long(argc, argv,"r:x:CUG:L:hwvVd:E", options, (int *) 0)) != EOF) {
129 129
  		switch (c) {
130 130
  		case 'r':
131 131
  			opt_reader = optarg;
132
-@@ -288,6 +291,9 @@ static int decode_options(int argc, char **argv)
133
- 			show_version();
134
- 			exit(EXIT_SUCCESS);
135
- 			break;
132
+@@ -296,6 +299,8 @@ static int decode_options(int argc, char **argv)
133
+ 			do_dump_idx = optarg[0] - '0';
134
+ 			opt_dump_do++;
135
+ 			actions++;
136 136
 +		case 'E':
137 137
 +			opt_erase++;
138
-+			break;
138
+ 			break;
139 139
  		default:
140 140
  			util_print_usage_and_die(app_name, options, option_help, NULL);
141
- 		}
142
-@@ -446,6 +452,18 @@ int do_verify(sc_card_t *card, u8 *type, u8* pin)
141
+@@ -452,6 +457,18 @@ int do_verify(sc_card_t *card, char *type, char *pin)
143 142
  	return r;
144 143
  }
145 144
  
@@ -158,7 +157,7 @@ index 8b5e327..0d360a3 100644
158 157
  int main(int argc, char **argv)
159 158
  {
160 159
  	sc_context_t *ctx = NULL;
161
-@@ -521,6 +539,9 @@ int main(int argc, char **argv)
160
+@@ -531,6 +548,9 @@ int main(int argc, char **argv)
162 161
  		exit(EXIT_FAILURE);
163 162
  	}
164 163
  
@@ -169,5 +168,5 @@ index 8b5e327..0d360a3 100644
169 168
  	sc_unlock(card);
170 169
  	sc_disconnect_card(card);
171 170
 -- 
172
-1.9.3
171
+2.1.3
173 172
 

+ 18
- 20
utils/opensc/patches/0006-openpgp-tool-Support-deleting-key-in-Gnuk.patch Visa fil

@@ -1,18 +1,18 @@
1
-From bbbedd3b358f80a7f98df2b22cf541cb007dd62e Mon Sep 17 00:00:00 2001
1
+From 469b6567d9adc4af6f49fa65534162673060454d Mon Sep 17 00:00:00 2001
2 2
 From: =?UTF-8?q?Nguy=E1=BB=85n=20H=E1=BB=93ng=20Qu=C3=A2n?=
3 3
  <ng.hong.quan@gmail.com>
4 4
 Date: Mon, 4 Mar 2013 18:13:03 +0700
5
-Subject: [PATCH 06/18] openpgp-tool: Support deleting key in Gnuk.
5
+Subject: [PATCH 06/26] openpgp-tool: Support deleting key in Gnuk.
6 6
 
7 7
 ---
8
- src/tools/openpgp-tool.c | 144 ++++++++++++++++++++++++++++++++++++++++++++++-
9
- 1 file changed, 143 insertions(+), 1 deletion(-)
8
+ src/tools/openpgp-tool.c | 142 +++++++++++++++++++++++++++++++++++++++++++++++
9
+ 1 file changed, 142 insertions(+)
10 10
 
11 11
 diff --git a/src/tools/openpgp-tool.c b/src/tools/openpgp-tool.c
12
-index 0d360a3..239c86b 100644
12
+index de1c9d4..374819a 100644
13 13
 --- a/src/tools/openpgp-tool.c
14 14
 +++ b/src/tools/openpgp-tool.c
15
-@@ -39,6 +39,7 @@
15
+@@ -41,6 +41,7 @@
16 16
  #define	OPT_PRETTY	257
17 17
  #define	OPT_VERIFY	258
18 18
  #define	OPT_PIN	    259
@@ -20,33 +20,31 @@ index 0d360a3..239c86b 100644
20 20
  
21 21
  /* define structures */
22 22
  struct ef_name_map {
23
-@@ -77,6 +78,7 @@ static char *verifytype = NULL;
24
- static int opt_pin = 0;
25
- static char *pin = NULL;
23
+@@ -79,6 +80,7 @@ static char *pin = NULL;
24
+ static int opt_dump_do = 0;
25
+ static u8 do_dump_idx;
26 26
  static int opt_erase = 0;
27 27
 +static int opt_delkey = 0;
28 28
  
29 29
  static const char *app_name = "openpgp-tool";
30 30
  
31
-@@ -96,6 +98,7 @@ static const struct option options[] = {
32
- 	{ "erase",     no_argument,       NULL, 'E'        },
31
+@@ -99,6 +101,7 @@ static const struct option options[] = {
33 32
  	{ "verify",    required_argument, NULL, OPT_VERIFY },
34 33
  	{ "pin",       required_argument, NULL, OPT_PIN },
34
+ 	{ "do",        required_argument, NULL, 'd' },
35 35
 +	{ "del-key",   required_argument, NULL, OPT_DELKEY },
36 36
  	{ NULL, 0, NULL, 0 }
37 37
  };
38 38
  
39
-@@ -114,7 +117,8 @@ static const char *option_help[] = {
40
- /* V */	"Show version number",
41
- /* E */	"Erase (reset) the card",
39
+@@ -119,6 +122,7 @@ static const char *option_help[] = {
42 40
  	"Verify PIN (CHV1, CHV2, CHV3...)",
43
--	"PIN string"
44
-+	"PIN string",
41
+ 	"PIN string",
42
+ /* d */ "Dump private data object number <arg> (i.e. PRIVATE-DO-<arg>)"
45 43
 +	"Delete key (1, 2, 3 or all)"
46 44
  };
47 45
  
48 46
  static const struct ef_name_map openpgp_data[] = {
49
-@@ -294,6 +298,14 @@ static int decode_options(int argc, char **argv)
47
+@@ -302,6 +306,14 @@ static int decode_options(int argc, char **argv)
50 48
  		case 'E':
51 49
  			opt_erase++;
52 50
  			break;
@@ -61,7 +59,7 @@ index 0d360a3..239c86b 100644
61 59
  		default:
62 60
  			util_print_usage_and_die(app_name, options, option_help, NULL);
63 61
  		}
64
-@@ -452,6 +464,133 @@ int do_verify(sc_card_t *card, u8 *type, u8* pin)
62
+@@ -457,6 +469,133 @@ int do_verify(sc_card_t *card, char *type, char *pin)
65 63
  	return r;
66 64
  }
67 65
  
@@ -195,7 +193,7 @@ index 0d360a3..239c86b 100644
195 193
  int do_erase(sc_card_t *card)
196 194
  {
197 195
  	int r;
198
-@@ -539,6 +678,9 @@ int main(int argc, char **argv)
196
+@@ -548,6 +687,9 @@ int main(int argc, char **argv)
199 197
  		exit(EXIT_FAILURE);
200 198
  	}
201 199
  
@@ -206,5 +204,5 @@ index 0d360a3..239c86b 100644
206 204
  		exit_status != do_erase(card);
207 205
  
208 206
 -- 
209
-1.9.3
207
+2.1.3
210 208
 

+ 5
- 5
utils/opensc/patches/0007-OpenPGP-Correct-building-Extended-Header-List-when-i.patch Visa fil

@@ -1,8 +1,8 @@
1
-From b6bc7a497e1fe20104f923de1092a35d137ba553 Mon Sep 17 00:00:00 2001
1
+From d210faa377bcec63876f84b82540b110ede16e57 Mon Sep 17 00:00:00 2001
2 2
 From: =?UTF-8?q?Nguy=E1=BB=85n=20H=E1=BB=93ng=20Qu=C3=A2n?=
3 3
  <ng.hong.quan@gmail.com>
4 4
 Date: Mon, 4 Mar 2013 18:14:51 +0700
5
-Subject: [PATCH 07/18] OpenPGP: Correct building Extended Header List when
5
+Subject: [PATCH 07/26] OpenPGP: Correct building Extended Header List when
6 6
  importing keys.
7 7
 
8 8
 ---
@@ -10,10 +10,10 @@ Subject: [PATCH 07/18] OpenPGP: Correct building Extended Header List when
10 10
  1 file changed, 1 insertion(+), 1 deletion(-)
11 11
 
12 12
 diff --git a/src/libopensc/card-openpgp.c b/src/libopensc/card-openpgp.c
13
-index 42a9684..47c1938 100644
13
+index 7349876..91c311b 100644
14 14
 --- a/src/libopensc/card-openpgp.c
15 15
 +++ b/src/libopensc/card-openpgp.c
16
-@@ -1978,7 +1978,7 @@ pgp_build_extended_header_list(sc_card_t *card, sc_cardctl_openpgp_keystore_info
16
+@@ -1977,7 +1977,7 @@ pgp_build_extended_header_list(sc_card_t *card, sc_cardctl_openpgp_keystore_info
17 17
  	u8 *p = NULL;
18 18
  	u8 *components[] = {key_info->e, key_info->p, key_info->q, key_info->n};
19 19
  	size_t componentlens[] = {key_info->e_len, key_info->p_len, key_info->q_len, key_info->n_len};
@@ -23,5 +23,5 @@ index 42a9684..47c1938 100644
23 23
  		"public exponent",
24 24
  		"prime p",
25 25
 -- 
26
-1.9.3
26
+2.1.3
27 27
 

+ 6
- 6
utils/opensc/patches/0008-OpenPGP-Read-some-empty-DOs-from-Gnuk.patch Visa fil

@@ -1,8 +1,8 @@
1
-From d1b8d3588336abac4876c1d537d8e8e5e578bc02 Mon Sep 17 00:00:00 2001
1
+From df98874784a77c96a7a1be54412a02a53fdd3a3e Mon Sep 17 00:00:00 2001
2 2
 From: =?UTF-8?q?Nguy=E1=BB=85n=20H=E1=BB=93ng=20Qu=C3=A2n?=
3 3
  <ng.hong.quan@gmail.com>
4 4
 Date: Mon, 25 Mar 2013 11:58:38 +0700
5
-Subject: [PATCH 08/18] OpenPGP: Read some empty DOs from Gnuk.
5
+Subject: [PATCH 08/26] OpenPGP: Read some empty DOs from Gnuk.
6 6
 
7 7
 In Gnuk, some empty DOs are returned as not exist, instead of existing with empty value.
8 8
 So, we will consider them exist in driver.
@@ -11,10 +11,10 @@ So, we will consider them exist in driver.
11 11
  1 file changed, 25 insertions(+)
12 12
 
13 13
 diff --git a/src/libopensc/card-openpgp.c b/src/libopensc/card-openpgp.c
14
-index 47c1938..9b08bbb 100644
14
+index 91c311b..e7b25c0 100644
15 15
 --- a/src/libopensc/card-openpgp.c
16 16
 +++ b/src/libopensc/card-openpgp.c
17
-@@ -813,6 +813,23 @@ pgp_get_blob(sc_card_t *card, struct blob *blob, unsigned int id,
17
+@@ -815,6 +815,23 @@ pgp_get_blob(sc_card_t *card, struct blob *blob, unsigned int id,
18 18
  		}
19 19
  	}
20 20
  
@@ -38,7 +38,7 @@ index 47c1938..9b08bbb 100644
38 38
  	return SC_ERROR_FILE_NOT_FOUND;
39 39
  }
40 40
  
41
-@@ -1147,6 +1164,14 @@ pgp_get_data(sc_card_t *card, unsigned int tag, u8 *buf, size_t buf_len)
41
+@@ -1149,6 +1166,14 @@ pgp_get_data(sc_card_t *card, unsigned int tag, u8 *buf, size_t buf_len)
42 42
  	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
43 43
  
44 44
  	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
@@ -54,5 +54,5 @@ index 47c1938..9b08bbb 100644
54 54
  
55 55
  	LOG_FUNC_RETURN(card->ctx, apdu.resplen);
56 56
 -- 
57
-1.9.3
57
+2.1.3
58 58
 

+ 5
- 5
utils/opensc/patches/0009-PKCS15-OpenPGP-Do-not-show-empty-DO-in-pkcs15-emu_in.patch Visa fil

@@ -1,8 +1,8 @@
1
-From 6a4457cde65ef44f05b0689415ae7165b06fb8bf Mon Sep 17 00:00:00 2001
1
+From 42adc35954e18e24f253f710b16d850d1872bce5 Mon Sep 17 00:00:00 2001
2 2
 From: =?UTF-8?q?Nguy=E1=BB=85n=20H=E1=BB=93ng=20Qu=C3=A2n?=
3 3
  <ng.hong.quan@gmail.com>
4 4
 Date: Wed, 27 Mar 2013 11:38:42 +0700
5
-Subject: [PATCH 09/18] PKCS15-OpenPGP: Do not show empty DO in pkcs15
5
+Subject: [PATCH 09/26] PKCS15-OpenPGP: Do not show empty DO in pkcs15
6 6
  emu_init.
7 7
 
8 8
 ---
@@ -10,10 +10,10 @@ Subject: [PATCH 09/18] PKCS15-OpenPGP: Do not show empty DO in pkcs15
10 10
  1 file changed, 18 insertions(+)
11 11
 
12 12
 diff --git a/src/libopensc/pkcs15-openpgp.c b/src/libopensc/pkcs15-openpgp.c
13
-index 9f239ef..850dd74 100644
13
+index fea2805..51a2032 100644
14 14
 --- a/src/libopensc/pkcs15-openpgp.c
15 15
 +++ b/src/libopensc/pkcs15-openpgp.c
16
-@@ -385,16 +385,34 @@ sc_pkcs15emu_openpgp_add_data(sc_pkcs15_card_t *p15card)
16
+@@ -381,16 +381,34 @@ sc_pkcs15emu_openpgp_add_data(sc_pkcs15_card_t *p15card)
17 17
  		sc_pkcs15_object_t dat_obj;
18 18
  		char name[8];
19 19
  		char path[9];
@@ -49,5 +49,5 @@ index 9f239ef..850dd74 100644
49 49
  		r = sc_pkcs15emu_add_data_object(p15card, &dat_obj, &dat_info);
50 50
  	}
51 51
 -- 
52
-1.9.3
52
+2.1.3
53 53
 

+ 5
- 5
utils/opensc/patches/0010-PKCS15-OpenPGP-Allow-to-store-data-to-pkcs15-data-ob.patch Visa fil

@@ -1,8 +1,8 @@
1
-From 88ded8fc5802c073caa71b649cee5a3116699b2a Mon Sep 17 00:00:00 2001
1
+From f085e6a5f386875b5b071ef3bf115e4d9bb33bdb Mon Sep 17 00:00:00 2001
2 2
 From: =?UTF-8?q?Nguy=E1=BB=85n=20H=E1=BB=93ng=20Qu=C3=A2n?=
3 3
  <ng.hong.quan@gmail.com>
4 4
 Date: Wed, 27 Mar 2013 11:39:33 +0700
5
-Subject: [PATCH 10/18] PKCS15-OpenPGP: Allow to store data to pkcs15 data
5
+Subject: [PATCH 10/26] PKCS15-OpenPGP: Allow to store data to pkcs15 data
6 6
  object.
7 7
 
8 8
 Only one DO is supported now.
@@ -12,10 +12,10 @@ Only one DO is supported now.
12 12
  2 files changed, 38 insertions(+), 2 deletions(-)
13 13
 
14 14
 diff --git a/src/libopensc/pkcs15-openpgp.c b/src/libopensc/pkcs15-openpgp.c
15
-index 850dd74..b701041 100644
15
+index 51a2032..4cc1c39 100644
16 16
 --- a/src/libopensc/pkcs15-openpgp.c
17 17
 +++ b/src/libopensc/pkcs15-openpgp.c
18
-@@ -397,7 +397,7 @@ sc_pkcs15emu_openpgp_add_data(sc_pkcs15_card_t *p15card)
18
+@@ -393,7 +393,7 @@ sc_pkcs15emu_openpgp_add_data(sc_pkcs15_card_t *p15card)
19 19
  		 */
20 20
  		r = read_file(p15card->card, path, content, sizeof(content));
21 21
  		if (r <= 0 ) {
@@ -87,5 +87,5 @@ index f3a4962..1455580 100755
87 87
  		r = SC_ERROR_NOT_IMPLEMENTED;
88 88
  	}
89 89
 -- 
90
-1.9.3
90
+2.1.3
91 91
 

+ 6
- 6
utils/opensc/patches/0011-OpenPGP-Provide-enough-buffer-to-read-pubkey-from-Gn.patch Visa fil

@@ -1,8 +1,8 @@
1
-From 7231ee09bb628f0401939778decce818ef6e3665 Mon Sep 17 00:00:00 2001
1
+From 752f8981bed49a98d3592ead3aa50e743318dea8 Mon Sep 17 00:00:00 2001
2 2
 From: =?UTF-8?q?Nguy=E1=BB=85n=20H=E1=BB=93ng=20Qu=C3=A2n?=
3 3
  <ng.hong.quan@gmail.com>
4 4
 Date: Fri, 5 Apr 2013 17:18:50 +0700
5
-Subject: [PATCH 11/18] OpenPGP: Provide enough buffer to read pubkey from
5
+Subject: [PATCH 11/26] OpenPGP: Provide enough buffer to read pubkey from
6 6
  Gnuk.
7 7
 
8 8
 ---
@@ -10,7 +10,7 @@ Subject: [PATCH 11/18] OpenPGP: Provide enough buffer to read pubkey from
10 10
  1 file changed, 23 insertions(+), 5 deletions(-)
11 11
 
12 12
 diff --git a/src/libopensc/card-openpgp.c b/src/libopensc/card-openpgp.c
13
-index 9b08bbb..8a1a270 100644
13
+index e7b25c0..1913eca 100644
14 14
 --- a/src/libopensc/card-openpgp.c
15 15
 +++ b/src/libopensc/card-openpgp.c
16 16
 @@ -263,7 +263,12 @@ static struct do_info		pgp2_objects[] = {	/* OpenPGP card spec 2.0 */
@@ -27,7 +27,7 @@ index 9b08bbb..8a1a270 100644
27 27
  
28 28
  #define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
29 29
  struct pgp_priv_data {
30
-@@ -729,6 +734,14 @@ pgp_read_blob(sc_card_t *card, struct blob *blob)
30
+@@ -731,6 +736,14 @@ pgp_read_blob(sc_card_t *card, struct blob *blob)
31 31
  		u8 	buffer[2048];
32 32
  		size_t	buf_len = (card->caps & SC_CARD_CAP_APDU_EXT)
33 33
  				  ? sizeof(buffer) : 256;
@@ -42,7 +42,7 @@ index 9b08bbb..8a1a270 100644
42 42
  		int	r = blob->info->get_fn(card, blob->id, buffer, buf_len);
43 43
  
44 44
  		if (r < 0) {	/* an error occurred */
45
-@@ -1830,6 +1843,7 @@ static int pgp_gen_key(sc_card_t *card, sc_cardctl_openpgp_keygen_info_t *key_in
45
+@@ -1828,6 +1841,7 @@ static int pgp_gen_key(sc_card_t *card, sc_cardctl_openpgp_keygen_info_t *key_in
46 46
  	u8 apdu_case;
47 47
  	u8 *apdu_data;
48 48
  	size_t apdu_le;
@@ -83,5 +83,5 @@ index 9b08bbb..8a1a270 100644
83 83
  	/* Send */
84 84
  	sc_log(card->ctx, "Waiting for the card to generate key...");
85 85
 -- 
86
-1.9.3
86
+2.1.3
87 87
 

+ 8
- 8
utils/opensc/patches/0012-OpenPGP-Support-write-certificate-for-Gnuk.patch Visa fil

@@ -1,18 +1,18 @@
1
-From d8f63eb6fcc1441c12a44850da2fa22a6fe81634 Mon Sep 17 00:00:00 2001
1
+From 5110ae3ba33d165c43ea5eca8f929a82d81cb3fe Mon Sep 17 00:00:00 2001
2 2
 From: =?UTF-8?q?Nguy=E1=BB=85n=20H=E1=BB=93ng=20Qu=C3=A2n?=
3 3
  <ng.hong.quan@gmail.com>
4 4
 Date: Thu, 11 Apr 2013 11:47:51 +0700
5
-Subject: [PATCH 12/18] OpenPGP: Support write certificate for Gnuk.
5
+Subject: [PATCH 12/26] OpenPGP: Support write certificate for Gnuk.
6 6
 
7 7
 ---
8 8
  src/libopensc/card-openpgp.c | 158 +++++++++++++++++++++++++++++++++----------
9 9
  1 file changed, 123 insertions(+), 35 deletions(-)
10 10
 
11 11
 diff --git a/src/libopensc/card-openpgp.c b/src/libopensc/card-openpgp.c
12
-index 8a1a270..d9db948 100644
12
+index 1913eca..7cea84f 100644
13 13
 --- a/src/libopensc/card-openpgp.c
14 14
 +++ b/src/libopensc/card-openpgp.c
15
-@@ -725,6 +725,8 @@ pgp_iterate_blobs(struct blob *blob, int level, void (*func)())
15
+@@ -727,6 +727,8 @@ pgp_iterate_blobs(struct blob *blob, int level, void (*func)())
16 16
  static int
17 17
  pgp_read_blob(sc_card_t *card, struct blob *blob)
18 18
  {
@@ -21,7 +21,7 @@ index 8a1a270..d9db948 100644
21 21
  	if (blob->data != NULL)
22 22
  		return SC_SUCCESS;
23 23
  	if (blob->info == NULL)
24
-@@ -735,6 +737,11 @@ pgp_read_blob(sc_card_t *card, struct blob *blob)
24
+@@ -737,6 +739,11 @@ pgp_read_blob(sc_card_t *card, struct blob *blob)
25 25
  		size_t	buf_len = (card->caps & SC_CARD_CAP_APDU_EXT)
26 26
  				  ? sizeof(buffer) : 256;
27 27
  
@@ -33,7 +33,7 @@ index 8a1a270..d9db948 100644
33 33
  		/* Buffer length for Gnuk pubkey */
34 34
  		if (card->type == SC_CARD_TYPE_OPENPGP_GNUK &&
35 35
  		    (blob->id == 0xa400 || blob->id == 0xb600 || blob->id == 0xb800
36
-@@ -1190,49 +1197,75 @@ pgp_get_data(sc_card_t *card, unsigned int tag, u8 *buf, size_t buf_len)
36
+@@ -1192,49 +1199,75 @@ pgp_get_data(sc_card_t *card, unsigned int tag, u8 *buf, size_t buf_len)
37 37
  	LOG_FUNC_RETURN(card->ctx, apdu.resplen);
38 38
  }
39 39
  
@@ -143,7 +143,7 @@ index 8a1a270..d9db948 100644
143 143
  
144 144
  	/* Extended Header list (004D DO) needs a variant of PUT DATA command */
145 145
  	if (tag == 0x004D) {
146
-@@ -1258,15 +1291,70 @@ pgp_put_data(sc_card_t *card, unsigned int tag, const u8 *buf, size_t buf_len)
146
+@@ -1260,15 +1293,70 @@ pgp_put_data(sc_card_t *card, unsigned int tag, const u8 *buf, size_t buf_len)
147 147
  		apdu.lc = buf_len;
148 148
  	}
149 149
  	else {
@@ -216,5 +216,5 @@ index 8a1a270..d9db948 100644
216 216
  	if (r == SC_ERROR_SECURITY_STATUS_NOT_SATISFIED) {
217 217
  		sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "Please verify PIN first.");
218 218
 -- 
219
-1.9.3
219
+2.1.3
220 220
 

+ 3
- 3
utils/opensc/patches/0013-pkcs15-openpgp-Change-to-sc_put_data-instead-of-sc_u.patch Visa fil

@@ -1,8 +1,8 @@
1
-From e5c94d3f1f7e6a96a98815d6e51190498c357fb6 Mon Sep 17 00:00:00 2001
1
+From 7823e836e8279c8d77786d8f10ffaa83cf50bf1d Mon Sep 17 00:00:00 2001
2 2
 From: =?UTF-8?q?Nguy=E1=BB=85n=20H=E1=BB=93ng=20Qu=C3=A2n?=
3 3
  <ng.hong.quan@gmail.com>
4 4
 Date: Wed, 10 Apr 2013 18:35:58 +0700
5
-Subject: [PATCH 13/18] pkcs15-openpgp: Change to sc_put_data instead of
5
+Subject: [PATCH 13/26] pkcs15-openpgp: Change to sc_put_data instead of
6 6
  sc_update_binary when writing certificate.
7 7
 
8 8
 ---
@@ -27,5 +27,5 @@ index 1455580..be1291e 100755
27 27
  
28 28
  	case SC_PKCS15_TYPE_DATA_OBJECT:
29 29
 -- 
30
-1.9.3
30
+2.1.3
31 31
 

+ 6
- 6
utils/opensc/patches/0014-OpenPGP-Overcome-the-restriction-of-even-data-length.patch Visa fil

@@ -1,8 +1,8 @@
1
-From df8a78e3c8c9d9d591c0d3fa31db7e010eb2c8c2 Mon Sep 17 00:00:00 2001
1
+From 3ff1f7234abb4c42273adedbe06d9e7f9f3a5f9d Mon Sep 17 00:00:00 2001
2 2
 From: =?UTF-8?q?Nguy=E1=BB=85n=20H=E1=BB=93ng=20Qu=C3=A2n?=
3 3
  <ng.hong.quan@gmail.com>
4 4
 Date: Thu, 11 Apr 2013 16:18:31 +0700
5
-Subject: [PATCH 14/18] OpenPGP: Overcome the restriction of even data length
5
+Subject: [PATCH 14/26] OpenPGP: Overcome the restriction of even data length
6 6
  of Gnuk.
7 7
 
8 8
 When write certificate with odd length to Gnuk, we add zero padding to make it even.
@@ -11,10 +11,10 @@ When write certificate with odd length to Gnuk, we add zero padding to make it e
11 11
  1 file changed, 18 insertions(+), 2 deletions(-)
12 12
 
13 13
 diff --git a/src/libopensc/card-openpgp.c b/src/libopensc/card-openpgp.c
14
-index d9db948..a666163 100644
14
+index 7cea84f..7a77a71 100644
15 15
 --- a/src/libopensc/card-openpgp.c
16 16
 +++ b/src/libopensc/card-openpgp.c
17
-@@ -1206,6 +1206,10 @@ static int gnuk_write_certificate(sc_card_t *card, const u8 *buf, size_t length)
17
+@@ -1208,6 +1208,10 @@ static int gnuk_write_certificate(sc_card_t *card, const u8 *buf, size_t length)
18 18
  	sc_apdu_t apdu;
19 19
  	u8 *part;
20 20
  	size_t plen;
@@ -25,7 +25,7 @@ index d9db948..a666163 100644
25 25
  	int r = SC_SUCCESS;
26 26
  
27 27
  	LOG_FUNC_CALLED(ctx);
28
-@@ -1236,8 +1240,20 @@ static int gnuk_write_certificate(sc_card_t *card, const u8 *buf, size_t length)
28
+@@ -1238,8 +1242,20 @@ static int gnuk_write_certificate(sc_card_t *card, const u8 *buf, size_t length)
29 29
  			sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0xD6, i, 0);
30 30
  		}
31 31
  		apdu.flags |= SC_APDU_FLAGS_CHAINING;
@@ -49,5 +49,5 @@ index d9db948..a666163 100644
49 49
  		r = sc_transmit_apdu(card, &apdu);
50 50
  		LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
51 51
 -- 
52
-1.9.3
52
+2.1.3
53 53
 

+ 7
- 7
utils/opensc/patches/0015-OpenPGP-Delete-key-as-file-for-Gnuk.patch Visa fil

@@ -1,18 +1,18 @@
1
-From 693b3ac5a53e89a0cdeab0f728d24a6e16864f5c Mon Sep 17 00:00:00 2001
1
+From 9af45c4cf052e3a6059a3004082f9ee3d2b3b2bf Mon Sep 17 00:00:00 2001
2 2
 From: =?UTF-8?q?Nguy=E1=BB=85n=20H=E1=BB=93ng=20Qu=C3=A2n?=
3 3
  <ng.hong.quan@gmail.com>
4 4
 Date: Fri, 12 Apr 2013 15:33:31 +0700
5
-Subject: [PATCH 15/18] OpenPGP: Delete key as file, for Gnuk.
5
+Subject: [PATCH 15/26] OpenPGP: Delete key as file, for Gnuk.
6 6
 
7 7
 ---
8 8
  src/libopensc/card-openpgp.c | 51 +++++++++++++++++++++++++++++++++++++++++++-
9 9
  1 file changed, 50 insertions(+), 1 deletion(-)
10 10
 
11 11
 diff --git a/src/libopensc/card-openpgp.c b/src/libopensc/card-openpgp.c
12
-index a666163..19d3b04 100644
12
+index 7a77a71..4d0500d 100644
13 13
 --- a/src/libopensc/card-openpgp.c
14 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)
15
+@@ -2435,6 +2435,44 @@ static int pgp_card_ctl(sc_card_t *card, unsigned long cmd, void *ptr)
16 16
  	LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
17 17
  }
18 18
  
@@ -57,7 +57,7 @@ index a666163..19d3b04 100644
57 57
  /* ABI: DELETE FILE */
58 58
  static int
59 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)
60
+@@ -2442,6 +2480,7 @@ pgp_delete_file(sc_card_t *card, const sc_path_t *path)
61 61
  	struct pgp_priv_data *priv = DRVDATA(card);
62 62
  	struct blob *blob;
63 63
  	sc_file_t *file;
@@ -65,7 +65,7 @@ index a666163..19d3b04 100644
65 65
  	int r;
66 66
  
67 67
  	LOG_FUNC_CALLED(card->ctx);
68
-@@ -2459,10 +2498,20 @@ pgp_delete_file(sc_card_t *card, const sc_path_t *path)
68
+@@ -2457,10 +2496,20 @@ pgp_delete_file(sc_card_t *card, const sc_path_t *path)
69 69
  	if (blob == priv->mf)
70 70
  		LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
71 71
  
@@ -88,5 +88,5 @@ index a666163..19d3b04 100644
88 88
  		/* call pgp_put_data() with zero-sized NULL-buffer to zap the DO contents */
89 89
  		r = pgp_put_data(card, file->id, NULL, 0);
90 90
 -- 
91
-1.9.3
91
+2.1.3
92 92
 

+ 7
- 7
utils/opensc/patches/0016-OpenPGP-Correct-parameter-checking.patch Visa fil

@@ -1,18 +1,18 @@
1
-From f96f7536a8c2efd0ba41fd94fe3334e5fa556854 Mon Sep 17 00:00:00 2001
1
+From ee23d262768e7e54ed0fc554bc0b869c65868ace Mon Sep 17 00:00:00 2001
2 2
 From: =?UTF-8?q?Nguy=E1=BB=85n=20H=E1=BB=93ng=20Qu=C3=A2n?=
3 3
  <ng.hong.quan@gmail.com>
4 4
 Date: Tue, 16 Apr 2013 10:19:34 +0700
5
-Subject: [PATCH 16/18] OpenPGP: Correct parameter checking.
5
+Subject: [PATCH 16/26] OpenPGP: Correct parameter checking.
6 6
 
7 7
 ---
8 8
  src/libopensc/card-openpgp.c | 9 +++++++--
9 9
  1 file changed, 7 insertions(+), 2 deletions(-)
10 10
 
11 11
 diff --git a/src/libopensc/card-openpgp.c b/src/libopensc/card-openpgp.c
12
-index 19d3b04..196c094 100644
12
+index 4d0500d..beeee83 100644
13 13
 --- a/src/libopensc/card-openpgp.c
14 14
 +++ b/src/libopensc/card-openpgp.c
15
-@@ -1221,6 +1221,8 @@ static int gnuk_write_certificate(sc_card_t *card, const u8 *buf, size_t length)
15
+@@ -1223,6 +1223,8 @@ static int gnuk_write_certificate(sc_card_t *card, const u8 *buf, size_t length)
16 16
  		LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
17 17
  		/* Check response */
18 18
  		r = sc_check_sw(card, apdu.sw1, apdu.sw2);
@@ -21,7 +21,7 @@ index 19d3b04..196c094 100644
21 21
  		LOG_FUNC_RETURN(card->ctx, length);
22 22
  	}
23 23
  
24
-@@ -2448,6 +2450,11 @@ gnuk_delete_key(sc_card_t *card, u8 key_id)
24
+@@ -2446,6 +2448,11 @@ gnuk_delete_key(sc_card_t *card, u8 key_id)
25 25
  
26 26
  	LOG_FUNC_CALLED(ctx);
27 27
  
@@ -33,7 +33,7 @@ index 19d3b04..196c094 100644
33 33
  	/* Delete fingerprint */
34 34
  	sc_log(ctx, "Delete fingerprints");
35 35
  	r = pgp_put_data(card, 0xC6 + key_id, NULL, 0);
36
-@@ -2466,8 +2473,6 @@ gnuk_delete_key(sc_card_t *card, u8 key_id)
36
+@@ -2464,8 +2471,6 @@ gnuk_delete_key(sc_card_t *card, u8 key_id)
37 37
  		data = "\x4D\x02\xB8";
38 38
  	else if (key_id == 3)
39 39
  		data = "\x4D\x02\xA4";
@@ -43,5 +43,5 @@ index 19d3b04..196c094 100644
43 43
  	r = pgp_put_data(card, 0x4D, data, strlen(data) + 1);
44 44
  
45 45
 -- 
46
-1.9.3
46
+2.1.3
47 47
 

+ 6
- 6
utils/opensc/patches/0017-OpenPGP-Make-code-neater.patch Visa fil

@@ -1,18 +1,18 @@
1
-From 8a69525a60391b46db4994033527d219d2adaa4e Mon Sep 17 00:00:00 2001
1
+From f4aec38233010953cea72c367bccc71c3687b2f1 Mon Sep 17 00:00:00 2001
2 2
 From: =?UTF-8?q?Nguy=E1=BB=85n=20H=E1=BB=93ng=20Qu=C3=A2n?=
3 3
  <ng.hong.quan@gmail.com>
4 4
 Date: Tue, 16 Apr 2013 16:02:17 +0700
5
-Subject: [PATCH 17/18] OpenPGP: Make code neater
5
+Subject: [PATCH 17/26] OpenPGP: Make code neater
6 6
 
7 7
 ---
8 8
  src/libopensc/card-openpgp.c | 8 ++------
9 9
  1 file changed, 2 insertions(+), 6 deletions(-)
10 10
 
11 11
 diff --git a/src/libopensc/card-openpgp.c b/src/libopensc/card-openpgp.c
12
-index 196c094..c4ef3b6 100644
12
+index beeee83..ca0d01b 100644
13 13
 --- a/src/libopensc/card-openpgp.c
14 14
 +++ b/src/libopensc/card-openpgp.c
15
-@@ -1220,10 +1220,7 @@ static int gnuk_write_certificate(sc_card_t *card, const u8 *buf, size_t length)
15
+@@ -1222,10 +1222,7 @@ static int gnuk_write_certificate(sc_card_t *card, const u8 *buf, size_t length)
16 16
  		r = sc_transmit_apdu(card, &apdu);
17 17
  		LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
18 18
  		/* Check response */
@@ -24,7 +24,7 @@ index 196c094..c4ef3b6 100644
24 24
  	}
25 25
  
26 26
  	/* Ref: gnuk_put_binary_libusb.py and gnuk_token.py in Gnuk source tree */
27
-@@ -1260,8 +1257,7 @@ static int gnuk_write_certificate(sc_card_t *card, const u8 *buf, size_t length)
27
+@@ -1262,8 +1259,7 @@ static int gnuk_write_certificate(sc_card_t *card, const u8 *buf, size_t length)
28 28
  		r = sc_transmit_apdu(card, &apdu);
29 29
  		LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
30 30
  		/* Check response */
@@ -35,5 +35,5 @@ index 196c094..c4ef3b6 100644
35 35
  		/* To next part */
36 36
  		i++;
37 37
 -- 
38
-1.9.3
38
+2.1.3
39 39
 

+ 6
- 6
utils/opensc/patches/0018-Move-declaration-to-top-of-block.patch Visa fil

@@ -1,18 +1,18 @@
1
-From a099f951d085d3abfefeead14a4af06913cb67d2 Mon Sep 17 00:00:00 2001
1
+From c84c84169f7a73eab27f6a9b13b77432baa5c3f8 Mon Sep 17 00:00:00 2001
2 2
 From: =?UTF-8?q?Nguy=E1=BB=85n=20H=E1=BB=93ng=20Qu=C3=A2n?=
3 3
  <ng.hong.quan@gmail.com>
4 4
 Date: Wed, 8 May 2013 16:51:21 +0700
5
-Subject: [PATCH 18/18] Move declaration to top of block.
5
+Subject: [PATCH 18/26] Move declaration to top of block.
6 6
 
7 7
 ---
8 8
  src/libopensc/card-openpgp.c | 3 ++-
9 9
  1 file changed, 2 insertions(+), 1 deletion(-)
10 10
 
11 11
 diff --git a/src/libopensc/card-openpgp.c b/src/libopensc/card-openpgp.c
12
-index c4ef3b6..7f2006e 100644
12
+index ca0d01b..037ef73 100644
13 13
 --- a/src/libopensc/card-openpgp.c
14 14
 +++ b/src/libopensc/card-openpgp.c
15
-@@ -736,6 +736,7 @@ pgp_read_blob(sc_card_t *card, struct blob *blob)
15
+@@ -738,6 +738,7 @@ pgp_read_blob(sc_card_t *card, struct blob *blob)
16 16
  		u8 	buffer[2048];
17 17
  		size_t	buf_len = (card->caps & SC_CARD_CAP_APDU_EXT)
18 18
  				  ? sizeof(buffer) : 256;
@@ -20,7 +20,7 @@ index c4ef3b6..7f2006e 100644
20 20
  
21 21
  		/* Buffer length for certificate */
22 22
  		if (blob->id == DO_CERT && priv->max_cert_size > 0) {
23
-@@ -749,7 +750,7 @@ pgp_read_blob(sc_card_t *card, struct blob *blob)
23
+@@ -751,7 +752,7 @@ pgp_read_blob(sc_card_t *card, struct blob *blob)
24 24
  			buf_len = MAXLEN_RESP_PUBKEY_GNUK;
25 25
  		}
26 26
  
@@ -30,5 +30,5 @@ index c4ef3b6..7f2006e 100644
30 30
  		if (r < 0) {	/* an error occurred */
31 31
  			blob->status = r;
32 32
 -- 
33
-1.9.3
33
+2.1.3
34 34
 

+ 182
- 0
utils/opensc/patches/0019-OpenPGP-Make-indentation-consistent-space-tab.patch Visa fil

@@ -0,0 +1,182 @@
1
+From c6abf7976f64be5191dc80fecdbcb07daab7a2e0 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: Sun, 3 Nov 2013 01:45:56 +0800
5
+Subject: [PATCH 19/26] OpenPGP: Make indentation consistent (space -> tab).
6
+
7
+---
8
+ src/libopensc/card-openpgp.c | 22 ++++++++---------
9
+ src/tools/openpgp-tool.c     | 56 ++++++++++++++++++++++----------------------
10
+ 2 files changed, 39 insertions(+), 39 deletions(-)
11
+
12
+diff --git a/src/libopensc/card-openpgp.c b/src/libopensc/card-openpgp.c
13
+index 037ef73..ae40940 100644
14
+--- a/src/libopensc/card-openpgp.c
15
++++ b/src/libopensc/card-openpgp.c
16
+@@ -192,12 +192,12 @@ static struct do_info		pgp1_objects[] = {	/* OpenPGP card spec 1.1 */
17
+ 	{ 0x5f35, SIMPLE,      READ_ALWAYS | WRITE_PIN3,  NULL,               sc_put_data },
18
+ 	{ 0x5f50, SIMPLE,      READ_ALWAYS | WRITE_PIN3,  sc_get_data,        sc_put_data },
19
+ 	{ 0x7f49, CONSTRUCTED, READ_ALWAYS | WRITE_NEVER, NULL,               NULL        },
20
+-	{ 0xa400, CONSTRUCTED, READ_ALWAYS | WRITE_NEVER,  pgp_get_pubkey,     NULL        },
21
+-	{ 0xa401, SIMPLE,      READ_ALWAYS | WRITE_PIN3, pgp_get_pubkey_pem, NULL        },
22
+-	{ 0xb600, CONSTRUCTED, READ_ALWAYS | WRITE_NEVER,  pgp_get_pubkey,     NULL        },
23
+-	{ 0xb601, SIMPLE,      READ_ALWAYS | WRITE_PIN3, pgp_get_pubkey_pem, NULL        },
24
+-	{ 0xb800, CONSTRUCTED, READ_ALWAYS | WRITE_NEVER,  pgp_get_pubkey,     NULL        },
25
+-	{ 0xb801, SIMPLE,      READ_ALWAYS | WRITE_PIN3, pgp_get_pubkey_pem, NULL        },
26
++	{ 0xa400, CONSTRUCTED, READ_ALWAYS | WRITE_NEVER, pgp_get_pubkey,     NULL        },
27
++	{ 0xa401, SIMPLE,      READ_ALWAYS | WRITE_PIN3,  pgp_get_pubkey_pem, NULL        },
28
++	{ 0xb600, CONSTRUCTED, READ_ALWAYS | WRITE_NEVER, pgp_get_pubkey,     NULL        },
29
++	{ 0xb601, SIMPLE,      READ_ALWAYS | WRITE_PIN3,  pgp_get_pubkey_pem, NULL        },
30
++	{ 0xb800, CONSTRUCTED, READ_ALWAYS | WRITE_NEVER, pgp_get_pubkey,     NULL        },
31
++	{ 0xb801, SIMPLE,      READ_ALWAYS | WRITE_PIN3,  pgp_get_pubkey_pem, NULL        },
32
+ 	{ 0, 0, 0, NULL, NULL },
33
+ };
34
+ 
35
+@@ -253,11 +253,11 @@ static struct do_info		pgp2_objects[] = {	/* OpenPGP card spec 2.0 */
36
+ 	/* The 0xA401, 0xB601, 0xB801 are just symbolic, it does not represent any real DO.
37
+ 	 * However, their R/W access condition may block the process of importing key in pkcs15init.
38
+ 	 * So we set their accesses condition as WRITE_PIN3 (writable). */
39
+-	{ 0xa401, SIMPLE,      READ_ALWAYS | WRITE_PIN3, pgp_get_pubkey_pem, NULL        },
40
+-	{ 0xb600, CONSTRUCTED, READ_ALWAYS | WRITE_NEVER,  pgp_get_pubkey,     NULL        },
41
+-	{ 0xb601, SIMPLE,      READ_ALWAYS | WRITE_PIN3, pgp_get_pubkey_pem, NULL        },
42
+-	{ 0xb800, CONSTRUCTED, READ_ALWAYS | WRITE_NEVER,  pgp_get_pubkey,     NULL        },
43
+-	{ 0xb801, SIMPLE,      READ_ALWAYS | WRITE_PIN3, pgp_get_pubkey_pem, NULL        },
44
++	{ 0xa401, SIMPLE,      READ_ALWAYS | WRITE_PIN3,  pgp_get_pubkey_pem, NULL        },
45
++	{ 0xb600, CONSTRUCTED, READ_ALWAYS | WRITE_NEVER, pgp_get_pubkey,     NULL        },
46
++	{ 0xb601, SIMPLE,      READ_ALWAYS | WRITE_PIN3,  pgp_get_pubkey_pem, NULL        },
47
++	{ 0xb800, CONSTRUCTED, READ_ALWAYS | WRITE_NEVER, pgp_get_pubkey,     NULL        },
48
++	{ 0xb801, SIMPLE,      READ_ALWAYS | WRITE_PIN3,  pgp_get_pubkey_pem, NULL        },
49
+ 	{ 0, 0, 0, NULL, NULL },
50
+ };
51
+ 
52
+diff --git a/src/tools/openpgp-tool.c b/src/tools/openpgp-tool.c
53
+index 374819a..a0334ca 100644
54
+--- a/src/tools/openpgp-tool.c
55
++++ b/src/tools/openpgp-tool.c
56
+@@ -37,11 +37,11 @@
57
+ #include "util.h"
58
+ #include "libopensc/log.h"
59
+ 
60
+-#define	OPT_RAW		256
61
+-#define	OPT_PRETTY	257
62
+-#define	OPT_VERIFY	258
63
+-#define	OPT_PIN	    259
64
+-#define	OPT_DELKEY  260
65
++#define OPT_RAW     256
66
++#define OPT_PRETTY  257
67
++#define OPT_VERIFY  258
68
++#define OPT_PIN     259
69
++#define OPT_DELKEY  260
70
+ 
71
+ /* define structures */
72
+ struct ef_name_map {
73
+@@ -142,10 +142,10 @@ static const struct ef_name_map openpgp_data[] = {
74
+ static void show_version(void)
75
+ {
76
+ 	fprintf(stderr,
77
+-		"openpgp-tool - OpenPGP card utility version " PACKAGE_VERSION "\n"
78
+-		"\n"
79
+-		"Copyright (c) 2012 Peter Marschall <peter@adpm.de>\n"
80
+-		"Licensed under LGPL v2\n");
81
++	        "openpgp-tool - OpenPGP card utility version " PACKAGE_VERSION "\n"
82
++	        "\n"
83
++	        "Copyright (c) 2012 Peter Marschall <peter@adpm.de>\n"
84
++	        "Licensed under LGPL v2\n");
85
+ }
86
+ 
87
+ 
88
+@@ -176,16 +176,16 @@ static char *prettify_language(char *str)
89
+ {
90
+ 	if (str != NULL) {
91
+ 		switch (strlen(str)) {
92
+-			case 8:	memmove(str+7, str+6, 1+strlen(str+6));
93
++			case 8: memmove(str+7, str+6, 1+strlen(str+6));
94
+ 				str[6] = ',';
95
+ 				/* fall through */
96
+-			case 6:	memmove(str+5, str+4, 1+strlen(str+4));
97
++			case 6: memmove(str+5, str+4, 1+strlen(str+4));
98
+ 				str[4] = ',';
99
+ 				/* fall through */
100
+-			case 4:	memmove(str+3, str+2, 1+strlen(str+2));
101
++			case 4: memmove(str+3, str+2, 1+strlen(str+2));
102
+ 				str[2] = ',';
103
+ 				/* fall through */
104
+-			case 2:  return str;
105
++			case 2: return str;
106
+ 		}
107
+ 	}
108
+ 	return NULL;
109
+@@ -197,10 +197,10 @@ static char *prettify_gender(char *str)
110
+ {
111
+ 	if (str != NULL) {
112
+ 		switch (*str) {
113
+-			case '0':  return "unknown";
114
+-			case '1':  return "male";
115
+-			case '2':  return "female";
116
+-			case '9':  return "not applicable";
117
++			case '0': return "unknown";
118
++			case '1': return "male";
119
++			case '2': return "female";
120
++			case '9': return "not applicable";
121
+ 		}
122
+ 	}
123
+ 	return NULL;
124
+@@ -218,7 +218,7 @@ static void display_data(const struct ef_name_map *mapping, char *value)
125
+ 				char *envvar;
126
+ 
127
+ 				envvar = malloc(strlen(mapping->env_name) +
128
+-						strlen(value) + 2);
129
++				                strlen(value) + 2);
130
+ 				if (envvar != NULL) {
131
+ 					strcpy(envvar, mapping->env_name);
132
+ 					strcat(envvar, "=");
133
+@@ -346,20 +346,20 @@ static int do_userinfo(sc_card_t *card)
134
+ 		if (!count)
135
+ 			continue;
136
+ 
137
+-		if (count > (int)sizeof(buf) - 1)   {
138
++		if (count > (int)sizeof(buf) - 1) {
139
+ 			fprintf(stderr, "Too small buffer to read the OpenPGP data\n");
140
+ 			return EXIT_FAILURE;
141
+ 		}
142
+-	
143
+-        	r = sc_read_binary(card, 0, buf, count, 0);
144
+-               	if (r < 0) {
145
++
146
++		r = sc_read_binary(card, 0, buf, count, 0);
147
++		if (r < 0) {
148
+ 			fprintf(stderr, "%s: read failed - %s\n", openpgp_data[i].ef, sc_strerror(r));
149
+ 			return EXIT_FAILURE;
150
+-        	}
151
+-               	if (r != count) {
152
+-                        fprintf(stderr, "%s: expecting %d, got only %d bytes\n", openpgp_data[i].ef, count, r);
153
++		}
154
++		if (r != count) {
155
++			fprintf(stderr, "%s: expecting %d, got only %d bytes\n", openpgp_data[i].ef, count, r);
156
+ 			return EXIT_FAILURE;
157
+-        	}
158
++		}
159
+ 
160
+ 		buf[count] = '\0';
161
+ 
162
+@@ -628,7 +628,7 @@ int main(int argc, char **argv)
163
+ 	r = sc_context_create(&ctx, &ctx_param);
164
+ 	if (r) {
165
+ 		util_fatal("failed to establish context: %s\n",
166
+-			sc_strerror(r));
167
++		           sc_strerror(r));
168
+ 		return EXIT_FAILURE;
169
+ 	}
170
+ 
171
+@@ -640,7 +640,7 @@ int main(int argc, char **argv)
172
+ 	r = util_connect_card(ctx, &card, opt_reader, opt_wait, verbose);
173
+ 	if (r) {
174
+ 		util_fatal("failed to connect to card: %s\n",
175
+-			sc_strerror(r));
176
++		           sc_strerror(r));
177
+ 		return EXIT_FAILURE;
178
+ 	}
179
+ 
180
+-- 
181
+2.1.3
182
+

+ 84
- 0
utils/opensc/patches/0020-OpenPGP-Don-t-use-sc_log-in-openpgp-tool.patch Visa fil

@@ -0,0 +1,84 @@
1
+From 9acf5c1ad7d8a32b472203d3bd8860ea2cbde0e7 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: Sun, 3 Nov 2013 02:53:35 +0800
5
+Subject: [PATCH 20/26] OpenPGP: Don't use sc_log in openpgp-tool.
6
+
7
+---
8
+ src/tools/openpgp-tool.c | 21 +++++++++++----------
9
+ 1 file changed, 11 insertions(+), 10 deletions(-)
10
+
11
+diff --git a/src/tools/openpgp-tool.c b/src/tools/openpgp-tool.c
12
+index a0334ca..505abd9 100644
13
+--- a/src/tools/openpgp-tool.c
14
++++ b/src/tools/openpgp-tool.c
15
+@@ -414,8 +414,6 @@ int do_genkey(sc_card_t *card, u8 key_id, unsigned int key_len)
16
+ 	sc_path_t path;
17
+ 	sc_file_t *file;
18
+ 
19
+-	LOG_FUNC_CALLED(card->ctx);
20
+-
21
+ 	if (key_id < 1 || key_id > 3) {
22
+ 		printf("Unknown key ID %d.\n", key_id);
23
+ 		return 1;
24
+@@ -479,14 +477,14 @@ int delete_key_gnuk(sc_card_t *card, u8 key_id)
25
+ 	u8 *data = NULL;
26
+ 
27
+ 	/* Delete fingerprint */
28
+-	sc_log(ctx, "Delete fingerprints");
29
++	fprintf(stdout, "Delete fingerprints");
30
+ 	r |= sc_put_data(card, 0xC6 + key_id, NULL, 0);
31
+ 	/* Delete creation time */
32
+-	sc_log(ctx, "Delete creation time");
33
++	fprintf(stdout, "Delete creation time");
34
+ 	r |= sc_put_data(card, 0xCD + key_id, NULL, 0);
35
+ 
36
+ 	/* Rewrite Extended Header List */
37
+-	sc_log(ctx, "Rewrite Extended Header List");
38
++	fprintf(stdout, "Rewrite Extended Header List");
39
+ 
40
+ 	if (key_id == 1)
41
+ 		data = "\x4D\x02\xB6";
42
+@@ -534,15 +532,18 @@ int delete_key_openpgp(sc_card_t *card, u8 key_id)
43
+ 		/* Build APDU from binary array */
44
+ 		r = sc_bytes2apdu(card->ctx, buf, len0, &apdu);
45
+ 		if (r) {
46
+-			sc_log(ctx, "Failed to build APDU");
47
+-			LOG_FUNC_RETURN(ctx, SC_ERROR_INTERNAL);
48
++			fprintf(stderr, "Failed to build APDU: %s\n", sc_strerror(r));
49
++			return r;
50
+ 		}
51
+ 		apdu.resp = rbuf;
52
+ 		apdu.resplen = sizeof(rbuf);
53
+ 
54
+ 		/* Send APDU to card */
55
+ 		r = sc_transmit_apdu(card, &apdu);
56
+-		LOG_TEST_RET(ctx, r, "Transmiting APDU failed");
57
++		if (r) {
58
++			fprintf(stderr, "Transmiting APDU failed: %s\n", sc_strerror(r));
59
++			return r;
60
++		}
61
+ 	}
62
+ 	/* TODO: Rewrite Extended Header List.
63
+ 	 * Not support by OpenGPG v2 yet */
64
+@@ -557,7 +558,7 @@ int delete_key(sc_card_t *card, u8 key_id)
65
+ 	LOG_FUNC_CALLED(ctx);
66
+ 	/* Check key ID */
67
+ 	if (key_id < 1 || key_id > 3) {
68
+-		sc_log(ctx, "Invalid key ID %d", key_id);
69
++		fprintf(stderr, "Invalid key ID %d", key_id);
70
+ 		LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ARGUMENTS);
71
+ 	}
72
+ 
73
+@@ -649,7 +650,7 @@ int main(int argc, char **argv)
74
+ 	    (card->type != SC_CARD_TYPE_OPENPGP_V2) &&
75
+ 	    (card->type != SC_CARD_TYPE_OPENPGP_GNUK)) {
76
+ 		util_error("not an OpenPGP card");
77
+-		sc_log(card->ctx, "Card type %X", card->type);
78
++		fprintf(stderr, "Card type %X\n", card->type);
79
+ 		exit_status = EXIT_FAILURE;
80
+ 		goto out;
81
+ 	}
82
+-- 
83
+2.1.3
84
+

+ 112
- 0
utils/opensc/patches/0021-OpenPGP-Don-t-reimplement-gnuk_delete_key-in-openpgp.patch Visa fil

@@ -0,0 +1,112 @@
1
+From 0fdbf868976172486af210accafbab163452ff78 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: Sun, 3 Nov 2013 11:26:25 +0800
5
+Subject: [PATCH 21/26] OpenPGP: Don't reimplement gnuk_delete_key in
6
+ openpgp-tool.
7
+
8
+---
9
+ src/tools/openpgp-tool.c | 64 ++++++------------------------------------------
10
+ 1 file changed, 8 insertions(+), 56 deletions(-)
11
+
12
+diff --git a/src/tools/openpgp-tool.c b/src/tools/openpgp-tool.c
13
+index 505abd9..a7796e7 100644
14
+--- a/src/tools/openpgp-tool.c
15
++++ b/src/tools/openpgp-tool.c
16
+@@ -468,38 +468,6 @@ int do_verify(sc_card_t *card, char *type, char *pin)
17
+ }
18
+ 
19
+ /**
20
+- * Delete key, for Gnuk.
21
+- **/
22
+-int delete_key_gnuk(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
+-	/* Delete fingerprint */
29
+-	fprintf(stdout, "Delete fingerprints");
30
+-	r |= sc_put_data(card, 0xC6 + key_id, NULL, 0);
31
+-	/* Delete creation time */
32
+-	fprintf(stdout, "Delete creation time");
33
+-	r |= sc_put_data(card, 0xCD + key_id, NULL, 0);
34
+-
35
+-	/* Rewrite Extended Header List */
36
+-	fprintf(stdout, "Rewrite Extended Header List");
37
+-
38
+-	if (key_id == 1)
39
+-		data = "\x4D\x02\xB6";
40
+-	else if (key_id == 2)
41
+-		data = "\x4D\x02\xB8";
42
+-	else if (key_id == 3)
43
+-		data = "\x4D\x02\xA4";
44
+-	else
45
+-		return SC_ERROR_INVALID_ARGUMENTS;
46
+-
47
+-	r |= sc_put_data(card, 0x4D, data, strlen(data) + 1);
48
+-	return r;
49
+-}
50
+-
51
+-/**
52
+  * Delete key, for OpenPGP card.
53
+  * This function is not complete and is reserved for future version (> 2) of OpenPGP card.
54
+  **/
55
+@@ -547,32 +515,13 @@ int delete_key_openpgp(sc_card_t *card, u8 key_id)
56
+ 	}
57
+ 	/* TODO: Rewrite Extended Header List.
58
+ 	 * Not support by OpenGPG v2 yet */
59
+-	LOG_FUNC_RETURN(ctx, r);
60
+-}
61
+-
62
+-int delete_key(sc_card_t *card, u8 key_id)
63
+-{
64
+-	sc_context_t *ctx = card->ctx;
65
+-	int r;
66
+-
67
+-	LOG_FUNC_CALLED(ctx);
68
+-	/* Check key ID */
69
+-	if (key_id < 1 || key_id > 3) {
70
+-		fprintf(stderr, "Invalid key ID %d", key_id);
71
+-		LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ARGUMENTS);
72
+-	}
73
+-
74
+-	if (card->type == SC_CARD_TYPE_OPENPGP_GNUK)
75
+-		r = delete_key_gnuk(card, key_id);
76
+-	else
77
+-		r = delete_key_openpgp(card, key_id);
78
+-
79
+-	LOG_FUNC_RETURN(ctx, r);
80
++	return r;
81
+ }
82
+ 
83
+ int do_delete_key(sc_card_t *card, u8 key_id)
84
+ {
85
+ 	sc_context_t *ctx = card->ctx;
86
++	sc_path_t path;
87
+ 	int r = SC_SUCCESS;
88
+ 
89
+ 	/* Currently, only Gnuk supports deleting keys */
90
+@@ -586,13 +535,16 @@ int do_delete_key(sc_card_t *card, u8 key_id)
91
+ 		return SC_ERROR_INVALID_ARGUMENTS;
92
+ 	}
93
+ 	if (key_id == 1 || key_id == 'a') {
94
+-		r |= delete_key(card, 1);
95
++		sc_format_path("B601", &path);
96
++		r |= sc_delete_file(card, &path);
97
+ 	}
98
+ 	if (key_id == 2 || key_id == 'a') {
99
+-		r |= delete_key(card, 2);
100
++		sc_format_path("B801", &path);
101
++		r |= sc_delete_file(card, &path);
102
+ 	}
103
+ 	if (key_id == 3 || key_id == 'a') {
104
+-		r |= delete_key(card, 3);
105
++		sc_format_path("A401", &path);
106
++		r |= sc_delete_file(card, &path);
107
+ 	}
108
+ 	return r;
109
+ }
110
+-- 
111
+2.1.3
112
+

+ 87
- 0
utils/opensc/patches/0022-OpenPGP-Use-directly-binary-array-of-APDUs-for-ERASE.patch Visa fil

@@ -0,0 +1,87 @@
1
+From 0cd2a488d86006bb2740a4e73e7a0d859e1bf33c 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: Sun, 13 Jul 2014 17:37:59 +0800
5
+Subject: [PATCH 22/26] OpenPGP: Use directly binary array of APDUs for ERASE
6
+ command.
7
+
8
+I used a string presentation before and it needed an extra conversion step.
9
+---
10
+ src/libopensc/card-openpgp.c | 47 +++++++++++++++++++++++---------------------
11
+ 1 file changed, 25 insertions(+), 22 deletions(-)
12
+
13
+diff --git a/src/libopensc/card-openpgp.c b/src/libopensc/card-openpgp.c
14
+index ae40940..724fe73 100644
15
+--- a/src/libopensc/card-openpgp.c
16
++++ b/src/libopensc/card-openpgp.c
17
+@@ -2347,24 +2347,27 @@ out:
18
+ static int pgp_erase_card(sc_card_t *card)
19
+ {
20
+ 	sc_context_t *ctx = card->ctx;
21
+-	u8 *apdustring[10] = {
22
+-		"00:20:00:81:08:40:40:40:40:40:40:40:40",
23
+-		"00:20:00:81:08:40:40:40:40:40:40:40:40",
24
+-		"00:20:00:81:08:40:40:40:40:40:40:40:40",
25
+-		"00:20:00:81:08:40:40:40:40:40:40:40:40",
26
+-		"00:20:00:83:08:40:40:40:40:40:40:40:40",
27
+-		"00:20:00:83:08:40:40:40:40:40:40:40:40",
28
+-		"00:20:00:83:08:40:40:40:40:40:40:40:40",
29
+-		"00:20:00:83:08:40:40:40:40:40:40:40:40",
30
+-		"00:e6:00:00",
31
+-		"00:44:00:00"
32
++	/* Special series of commands to erase OpenPGP card,
33
++	 * according to https://www.crypto-stick.com/en/faq
34
++	 * (How to reset a Crypto Stick? question).
35
++	 * Gnuk is known not to support this feature. */
36
++	u8 apdu_binaries[10][13] = {
37
++		{0, 0x20, 0, 0x81, 0x08, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40},
38
++		{0, 0x20, 0, 0x81, 0x08, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40},
39
++		{0, 0x20, 0, 0x81, 0x08, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40},
40
++		{0, 0x20, 0, 0x81, 0x08, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40},
41
++		{0, 0x20, 0, 0x83, 0x08, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40},
42
++		{0, 0x20, 0, 0x83, 0x08, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40},
43
++		{0, 0x20, 0, 0x83, 0x08, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40},
44
++		{0, 0x20, 0, 0x83, 0x08, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40},
45
++		{0, 0xe6, 0, 0},
46
++		{0, 0x44, 0, 0}
47
+ 	};
48
++	u8 apdu_lens[10] = {13, 13, 13, 13, 13, 13, 13, 13, 4, 4};
49
+ 	u8 buf[SC_MAX_APDU_BUFFER_SIZE];
50
+ 	u8 rbuf[SC_MAX_APDU_BUFFER_SIZE];
51
+ 	sc_apdu_t apdu;
52
+-	size_t len0;
53
+-	int commandsnum = 10;
54
+-	int i, r;
55
++	int i, l, r;
56
+ 
57
+ 	LOG_FUNC_CALLED(ctx);
58
+ 
59
+@@ -2376,17 +2379,17 @@ static int pgp_erase_card(sc_card_t *card)
60
+ 	sc_log(ctx, "Card is OpenPGP v2. Erase card.");
61
+ 
62
+ 	/* Iterate over 10 commands above */
63
+-	for (i = 0; i < commandsnum; i++) {
64
+-		/* Convert the string to binary array */
65
+-		len0 = sizeof(buf);
66
+-		sc_hex_to_bin(apdustring[i], buf, &len0);
67
+-		printf("Sending: ");
68
+-		for (r = 0; r < len0; r++)
69
+-			printf("%02X ", buf[r]);
70
++	for (i = 0; i < sizeof(apdu_lens); i++) {
71
++		/* Length of the binary array of the current command */
72
++		l = apdu_lens[i];
73
++		/* Print the command to console */
74
++		printf("Sending %d: ", i);
75
++		for (r = 0; r < l; r++)
76
++			printf("%02X ", apdu_binaries[i][r]);
77
+ 		printf("\n");
78
+ 
79
+ 		/* Build APDU from binary array */
80
+-		r = sc_bytes2apdu(card->ctx, buf, len0, &apdu);
81
++		r = sc_bytes2apdu(card->ctx, apdu_binaries[i], l, &apdu);
82
+ 		if (r) {
83
+ 			sc_log(ctx, "Failed to build APDU");
84
+ 			LOG_FUNC_RETURN(ctx, SC_ERROR_INTERNAL);
85
+-- 
86
+2.1.3
87
+

+ 339
- 0
utils/opensc/patches/0023-OpenPGP-Rename-private-blob-type-to-avoid-confusing-.patch Visa fil

@@ -0,0 +1,339 @@
1
+From 6f56ea4cfc52323002d818731a50a31e863b6843 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: Sun, 13 Jul 2014 19:41:36 +0800
5
+Subject: [PATCH 23/26] OpenPGP: Rename private "blob" type to avoid confusing
6
+ with variable name.
7
+
8
+This name has been used for both data type and variable name of that
9
+type.
10
+---
11
+ src/libopensc/card-openpgp.c | 96 ++++++++++++++++++++++----------------------
12
+ 1 file changed, 49 insertions(+), 47 deletions(-)
13
+
14
+diff --git a/src/libopensc/card-openpgp.c b/src/libopensc/card-openpgp.c
15
+index 724fe73..ca3173c 100644
16
+--- a/src/libopensc/card-openpgp.c
17
++++ b/src/libopensc/card-openpgp.c
18
+@@ -111,9 +111,9 @@ enum _card_state {
19
+ 	CARD_STATE_ACTIVATED      = 0x05
20
+ };
21
+ 
22
+-struct blob {
23
+-	struct blob *	next;	/* pointer to next sibling */
24
+-	struct blob *	parent;	/* pointer to parent */
25
++typedef struct pgp_blob {
26
++	struct pgp_blob *	next;	/* pointer to next sibling */
27
++	struct pgp_blob *	parent;	/* pointer to parent */
28
+ 	struct do_info *info;
29
+ 
30
+ 	sc_file_t *	file;
31
+@@ -122,8 +122,8 @@ struct blob {
32
+ 
33
+ 	unsigned char *	data;
34
+ 	unsigned int	len;
35
+-	struct blob *	files;	/* pointer to 1st child */
36
+-};
37
++	struct pgp_blob *	files;	/* pointer to 1st child */
38
++} pgp_blob_t;
39
+ 
40
+ struct do_info {
41
+ 	unsigned int	id;		/* ID of the DO in question */
42
+@@ -141,12 +141,12 @@ struct do_info {
43
+ 
44
+ static int		pgp_get_card_features(sc_card_t *card);
45
+ static int		pgp_finish(sc_card_t *card);
46
+-static void		pgp_iterate_blobs(struct blob *, int, void (*func)());
47
++static void		pgp_iterate_blobs(pgp_blob_t *, int, void (*func)());
48
+ 
49
+-static int		pgp_get_blob(sc_card_t *card, struct blob *blob,
50
+-				 unsigned int id, struct blob **ret);
51
+-static struct blob *	pgp_new_blob(sc_card_t *, struct blob *, unsigned int, sc_file_t *);
52
+-static void		pgp_free_blob(struct blob *);
53
++static int		pgp_get_blob(sc_card_t *card, pgp_blob_t *blob,
54
++				 unsigned int id, pgp_blob_t **ret);
55
++static pgp_blob_t *	pgp_new_blob(sc_card_t *, pgp_blob_t *, unsigned int, sc_file_t *);
56
++static void		pgp_free_blob(pgp_blob_t *);
57
+ static int		pgp_get_pubkey(sc_card_t *, unsigned int,
58
+ 				u8 *, size_t);
59
+ static int		pgp_get_pubkey_pem(sc_card_t *, unsigned int,
60
+@@ -272,8 +272,8 @@ static struct do_info		pgp2_objects[] = {	/* OpenPGP card spec 2.0 */
61
+ 
62
+ #define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
63
+ struct pgp_priv_data {
64
+-	struct blob *		mf;
65
+-	struct blob *		current;	/* currently selected file */
66
++	pgp_blob_t *		mf;
67
++	pgp_blob_t *		current;	/* currently selected file */
68
+ 
69
+ 	enum _version		bcd_version;
70
+ 	struct do_info		*pgp_objects;
71
+@@ -311,7 +311,7 @@ pgp_init(sc_card_t *card)
72
+ 	sc_file_t	*file = NULL;
73
+ 	struct do_info	*info;
74
+ 	int		r;
75
+-	struct blob 	*child = NULL;
76
++	pgp_blob_t 	*child = NULL;
77
+ 
78
+ 	LOG_FUNC_CALLED(card->ctx);
79
+ 
80
+@@ -389,7 +389,7 @@ pgp_get_card_features(sc_card_t *card)
81
+ 	unsigned char *hist_bytes = card->atr.value;
82
+ 	size_t atr_len = card->atr.len;
83
+ 	size_t i = 0;
84
+-	struct blob *blob, *blob6e, *blob73;
85
++	pgp_blob_t *blob, *blob6e, *blob73;
86
+ 
87
+ 	/* parse card capabilities from historical bytes */
88
+ 	while ((i < atr_len) && (hist_bytes[i] != 0x73))
89
+@@ -526,7 +526,7 @@ pgp_finish(sc_card_t *card)
90
+ 
91
+ /* internal: fill a blob's data */
92
+ static int
93
+-pgp_set_blob(struct blob *blob, const u8 *data, size_t len)
94
++pgp_set_blob(pgp_blob_t *blob, const u8 *data, size_t len)
95
+ {
96
+ 	if (blob->data)
97
+ 		free(blob->data);
98
+@@ -620,16 +620,16 @@ pgp_attach_acl(sc_card_t *card, sc_file_t *file, struct do_info *info)
99
+ }
100
+ 
101
+ /* internal: append a blob to the list of children of a given parent blob */
102
+-static struct blob *
103
+-pgp_new_blob(sc_card_t *card, struct blob *parent, unsigned int file_id,
104
++static pgp_blob_t *
105
++pgp_new_blob(sc_card_t *card, pgp_blob_t *parent, unsigned int file_id,
106
+ 		sc_file_t *file)
107
+ {
108
+-	struct blob *blob = NULL;
109
++	pgp_blob_t *blob = NULL;
110
+ 
111
+ 	if (file == NULL)
112
+ 		return NULL;
113
+ 
114
+-	if ((blob = calloc(1, sizeof(struct blob))) != NULL) {
115
++	if ((blob = calloc(1, sizeof(pgp_blob_t))) != NULL) {
116
+ 		struct pgp_priv_data *priv = DRVDATA (card);
117
+ 		struct do_info *info;
118
+ 
119
+@@ -643,7 +643,7 @@ pgp_new_blob(sc_card_t *card, struct blob *parent, unsigned int file_id,
120
+ 		blob->parent = parent;
121
+ 
122
+ 		if (parent != NULL) {
123
+-			struct blob **p;
124
++			pgp_blob_t **p;
125
+ 
126
+ 			/* set file's path = parent's path + file's id */
127
+ 			blob->file->path = parent->file->path;
128
+@@ -681,11 +681,11 @@ pgp_new_blob(sc_card_t *card, struct blob *parent, unsigned int file_id,
129
+ 
130
+ /* internal: free a blob including its content */
131
+ static void
132
+-pgp_free_blob(struct blob *blob)
133
++pgp_free_blob(pgp_blob_t *blob)
134
+ {
135
+ 	if (blob) {
136
+ 		if (blob->parent) {
137
+-			struct blob **p;
138
++			pgp_blob_t **p;
139
+ 
140
+ 			/* remove blob from list of parent's children */
141
+ 			for (p = &blob->parent->files; *p != NULL && *p != blob; p = &(*p)->next)
142
+@@ -705,14 +705,14 @@ pgp_free_blob(struct blob *blob)
143
+ 
144
+ /* internal: iterate through the blob tree, calling a function for each blob */
145
+ static void
146
+-pgp_iterate_blobs(struct blob *blob, int level, void (*func)())
147
++pgp_iterate_blobs(pgp_blob_t *blob, int level, void (*func)())
148
+ {
149
+ 	if (blob) {
150
+ 		if (level > 0) {
151
+-			struct blob *child = blob->files;
152
++			pgp_blob_t *child = blob->files;
153
+ 
154
+ 			while (child != NULL) {
155
+-				struct blob *next = child->next;
156
++				pgp_blob_t *next = child->next;
157
+ 
158
+ 				pgp_iterate_blobs(child, level-1, func);
159
+ 				child = next;
160
+@@ -725,7 +725,7 @@ pgp_iterate_blobs(struct blob *blob, int level, void (*func)())
161
+ 
162
+ /* internal: read a blob's contents from card */
163
+ static int
164
+-pgp_read_blob(sc_card_t *card, struct blob *blob)
165
++pgp_read_blob(sc_card_t *card, pgp_blob_t *blob)
166
+ {
167
+ 	struct pgp_priv_data *priv = DRVDATA (card);
168
+ 
169
+@@ -772,7 +772,7 @@ pgp_read_blob(sc_card_t *card, struct blob *blob)
170
+  * The OpenPGP card has a TLV encoding according ASN.1 BER-encoding rules.
171
+  */
172
+ static int
173
+-pgp_enumerate_blob(sc_card_t *card, struct blob *blob)
174
++pgp_enumerate_blob(sc_card_t *card, pgp_blob_t *blob)
175
+ {
176
+ 	const u8	*in;
177
+ 	int		r;
178
+@@ -789,7 +789,7 @@ pgp_enumerate_blob(sc_card_t *card, struct blob *blob)
179
+ 		unsigned int	cla, tag, tmptag;
180
+ 		size_t		len;
181
+ 		const u8	*data = in;
182
+-		struct blob	*new;
183
++		pgp_blob_t	*new;
184
+ 
185
+ 		r = sc_asn1_read_tag(&data, blob->len - (in - blob->data),
186
+ 					&cla, &tag, &len);
187
+@@ -819,10 +819,10 @@ pgp_enumerate_blob(sc_card_t *card, struct blob *blob)
188
+ 
189
+ /* internal: find a blob by ID below a given parent, filling its contents when necessary */
190
+ static int
191
+-pgp_get_blob(sc_card_t *card, struct blob *blob, unsigned int id,
192
+-		struct blob **ret)
193
++pgp_get_blob(sc_card_t *card, pgp_blob_t *blob, unsigned int id,
194
++		pgp_blob_t **ret)
195
+ {
196
+-	struct blob		*child;
197
++	pgp_blob_t		*child;
198
+ 	int			r;
199
+ 
200
+ 	if ((r = pgp_enumerate_blob(card, blob)) < 0)
201
+@@ -858,10 +858,10 @@ pgp_get_blob(sc_card_t *card, struct blob *blob, unsigned int id,
202
+ 
203
+ /* Internal: search recursively for a blob by ID below a given root */
204
+ static int
205
+-pgp_seek_blob(sc_card_t *card, struct blob *root, unsigned int id,
206
+-		struct blob **ret)
207
++pgp_seek_blob(sc_card_t *card, pgp_blob_t *root, unsigned int id,
208
++		pgp_blob_t **ret)
209
+ {
210
+-	struct blob	*child;
211
++	pgp_blob_t	*child;
212
+ 	int			r;
213
+ 
214
+ 	if ((r = pgp_get_blob(card, root, id, ret)) == 0)
215
+@@ -883,11 +883,11 @@ pgp_seek_blob(sc_card_t *card, struct blob *root, unsigned int id,
216
+ }
217
+ 
218
+ /* internal: find a blob by tag - pgp_seek_blob with optimizations */
219
+-static struct blob *
220
++static pgp_blob_t *
221
+ pgp_find_blob(sc_card_t *card, unsigned int tag)
222
+ {
223
+ 	struct pgp_priv_data *priv = DRVDATA(card);
224
+-	struct blob *blob = NULL;
225
++	pgp_blob_t *blob = NULL;
226
+ 	int r;
227
+ 
228
+ 	/* Check if current selected blob is which we want to test*/
229
+@@ -941,7 +941,7 @@ static int
230
+ pgp_select_file(sc_card_t *card, const sc_path_t *path, sc_file_t **ret)
231
+ {
232
+ 	struct pgp_priv_data *priv = DRVDATA(card);
233
+-	struct blob	*blob;
234
++	pgp_blob_t	*blob;
235
+ 	unsigned int	path_start = 0;
236
+ 	unsigned int	n;
237
+ 	sc_path_t dummy_path;
238
+@@ -1022,7 +1022,7 @@ static int
239
+ pgp_list_files(sc_card_t *card, u8 *buf, size_t buflen)
240
+ {
241
+ 	struct pgp_priv_data *priv = DRVDATA(card);
242
+-	struct blob	*blob;
243
++	pgp_blob_t	*blob;
244
+ 	unsigned int	k;
245
+ 	int		r;
246
+ 
247
+@@ -1058,7 +1058,7 @@ pgp_read_binary(sc_card_t *card, unsigned int idx,
248
+ 		u8 *buf, size_t count, unsigned long flags)
249
+ {
250
+ 	struct pgp_priv_data *priv = DRVDATA(card);
251
+-	struct blob	*blob;
252
++	pgp_blob_t	*blob;
253
+ 	int		r;
254
+ 
255
+ 	LOG_FUNC_CALLED(card->ctx);
256
+@@ -1134,7 +1134,7 @@ static int
257
+ pgp_get_pubkey_pem(sc_card_t *card, unsigned int tag, u8 *buf, size_t buf_len)
258
+ {
259
+ 	struct pgp_priv_data *priv = DRVDATA(card);
260
+-	struct blob	*blob, *mod_blob, *exp_blob;
261
++	pgp_blob_t	*blob, *mod_blob, *exp_blob;
262
+ 	sc_pkcs15_pubkey_t pubkey;
263
+ 	u8		*data;
264
+ 	size_t		len;
265
+@@ -1329,7 +1329,7 @@ static int
266
+ pgp_put_data(sc_card_t *card, unsigned int tag, const u8 *buf, size_t buf_len)
267
+ {
268
+ 	struct pgp_priv_data *priv = DRVDATA(card);
269
+-	struct blob *affected_blob = NULL;
270
++	pgp_blob_t *affected_blob = NULL;
271
+ 	struct do_info *dinfo = NULL;
272
+ 	int r;
273
+ 
274
+@@ -1603,7 +1603,7 @@ static int
275
+ pgp_update_new_algo_attr(sc_card_t *card, sc_cardctl_openpgp_keygen_info_t *key_info)
276
+ {
277
+ 	struct pgp_priv_data *priv = DRVDATA(card);
278
+-	struct blob *algo_blob;
279
++	pgp_blob_t *algo_blob;
280
+ 	unsigned int old_modulus_len;     /* Measured in bit */
281
+ 	unsigned int old_exponent_len;
282
+ 	const unsigned int tag = 0x00C0 | key_info->keytype;
283
+@@ -1708,7 +1708,7 @@ pgp_calculate_and_store_fingerprint(sc_card_t *card, time_t ctime,
284
+ 	u8 *p; /* Use this pointer to set fp_buffer content */
285
+ 	size_t pk_packet_len;
286
+ 	unsigned int tag;
287
+-	struct blob *fpseq_blob;
288
++	pgp_blob_t *fpseq_blob;
289
+ 	u8 *newdata;
290
+ 	int r;
291
+ 
292
+@@ -1797,7 +1797,7 @@ pgp_update_pubkey_blob(sc_card_t *card, u8* modulus, size_t modulus_len,
293
+                        u8* exponent, size_t exponent_len, u8 key_id)
294
+ {
295
+ 	struct pgp_priv_data *priv = DRVDATA(card);
296
+-	struct blob *pk_blob;
297
++	pgp_blob_t *pk_blob;
298
+ 	unsigned int blob_id;
299
+ 	sc_pkcs15_pubkey_t pubkey;
300
+ 	u8 *data = NULL;
301
+@@ -1939,6 +1939,8 @@ static int pgp_update_card_algorithms(sc_card_t *card, sc_cardctl_openpgp_keygen
302
+  **/
303
+ static int pgp_gen_key(sc_card_t *card, sc_cardctl_openpgp_keygen_info_t *key_info)
304
+ {
305
++	struct pgp_priv_data *priv = DRVDATA(card);
306
++	pgp_blob_t *algo_blob;
307
+ 	sc_apdu_t apdu;
308
+ 	/* Temporary variables to hold APDU params */
309
+ 	u8 apdu_case;
310
+@@ -2132,7 +2134,7 @@ pgp_build_extended_header_list(sc_card_t *card, sc_cardctl_openpgp_keystore_info
311
+ 	};
312
+ 	size_t comp_to_add = 3;
313
+ 	size_t req_e_len = 0;     /* The exponent length specified in Algorithm Attributes */
314
+-	struct blob *alat_blob;
315
++	pgp_blob_t *alat_blob;
316
+ 	u8 i;
317
+ 	int r;
318
+ 
319
+@@ -2483,7 +2485,7 @@ static int
320
+ pgp_delete_file(sc_card_t *card, const sc_path_t *path)
321
+ {
322
+ 	struct pgp_priv_data *priv = DRVDATA(card);
323
+-	struct blob *blob;
324
++	pgp_blob_t *blob;
325
+ 	sc_file_t *file;
326
+ 	u8 key_id;
327
+ 	int r;
328
+@@ -2533,7 +2535,7 @@ pgp_update_binary(sc_card_t *card, unsigned int idx,
329
+ 		  const u8 *buf, size_t count, unsigned long flags)
330
+ {
331
+ 	struct pgp_priv_data *priv = DRVDATA(card);
332
+-	struct blob *blob = priv->current;
333
++	pgp_blob_t *blob = priv->current;
334
+ 	int r = SC_SUCCESS;
335
+ 
336
+ 	LOG_FUNC_CALLED(card->ctx);
337
+-- 
338
+2.1.3
339
+

+ 41
- 0
utils/opensc/patches/0024-OpenPGP-Fix-crash-after-accessing-inexistent-file.patch Visa fil

@@ -0,0 +1,41 @@
1
+From 8a87a4ee9107f250254d5c93c6fd62224c400ce7 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: Mon, 14 Jul 2014 01:30:28 +0800
5
+Subject: [PATCH 24/26] OpenPGP: Fix crash after accessing inexistent file.
6
+
7
+---
8
+ src/libopensc/card-openpgp.c | 3 ---
9
+ 1 file changed, 3 deletions(-)
10
+
11
+diff --git a/src/libopensc/card-openpgp.c b/src/libopensc/card-openpgp.c
12
+index ca3173c..94c69ae 100644
13
+--- a/src/libopensc/card-openpgp.c
14
++++ b/src/libopensc/card-openpgp.c
15
+@@ -973,7 +973,6 @@ pgp_select_file(sc_card_t *card, const sc_path_t *path, sc_file_t **ret)
16
+ 			 * So we set its size to be the same as max certificate size the card supports. */
17
+ 			(*ret)->size = priv->max_cert_size;
18
+ 		}
19
+-		priv->current = NULL;
20
+ 		LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
21
+ 	}
22
+ 
23
+@@ -990,7 +989,6 @@ pgp_select_file(sc_card_t *card, const sc_path_t *path, sc_file_t **ret)
24
+ 		/* This file ID is refered when importing key&certificate via pkcs15init, like above.
25
+ 		 * We pretend to successfully find this inexistent file. */
26
+ 		if (id == 0x4402 || id == 0x5f48) {
27
+-			priv->current = NULL;
28
+ 			if (ret == NULL)
29
+ 				/* No need to return file */
30
+ 				LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
31
+@@ -1002,7 +1000,6 @@ pgp_select_file(sc_card_t *card, const sc_path_t *path, sc_file_t **ret)
32
+ 		}
33
+ 
34
+ 		if (r < 0) {	/* failure */
35
+-			priv->current = NULL;
36
+ 			LOG_FUNC_RETURN(card->ctx, r);
37
+ 		}
38
+ 	}
39
+-- 
40
+2.1.3
41
+

+ 148
- 0
utils/opensc/patches/0025-Replace-hardcode.patch Visa fil

@@ -0,0 +1,148 @@
1
+From da70a41383e2ab81fbcc89fb1067f5a189e0fb97 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: Sun, 9 Nov 2014 15:58:40 +0700
5
+Subject: [PATCH 25/26] Replace hardcode.
6
+
7
+---
8
+ src/libopensc/card-openpgp.c | 72 +++++++++++++++++++++++++-------------------
9
+ 1 file changed, 41 insertions(+), 31 deletions(-)
10
+
11
+diff --git a/src/libopensc/card-openpgp.c b/src/libopensc/card-openpgp.c
12
+index 94c69ae..1e6e338 100644
13
+--- a/src/libopensc/card-openpgp.c
14
++++ b/src/libopensc/card-openpgp.c
15
+@@ -152,6 +152,24 @@ static int		pgp_get_pubkey(sc_card_t *, unsigned int,
16
+ static int		pgp_get_pubkey_pem(sc_card_t *, unsigned int,
17
+ 				u8 *, size_t);
18
+ 
19
++/* The DO holding X.509 certificate is constructed but does not contain child DO.
20
++ * We should notice this when building fake file system later. */
21
++#define DO_CERT                  0x7f21
22
++/* Control Reference Template of private keys. Ref: Section 4.3.3.7 of OpenPGP card v2 spec.
23
++ * Here we seen it as DO just for convenient */
24
++#define DO_SIGN                  0xb600
25
++#define DO_ENCR                  0xb800
26
++#define DO_AUTH                  0xa400
27
++/* These DO does not exist. They are defined and used just for ease of implementation */
28
++#define DO_SIGN_SYM              0xb601
29
++#define DO_ENCR_SYM              0xb801
30
++#define DO_AUTH_SYM              0xa401
31
++/* Maximum length for response buffer when reading pubkey. This value is calculated with
32
++ * 4096-bit key length */
33
++#define MAXLEN_RESP_PUBKEY       527
34
++/* Gnuk only support 1 key length (2048 bit) */
35
++#define MAXLEN_RESP_PUBKEY_GNUK  271
36
++
37
+ static struct do_info		pgp1_objects[] = {	/* OpenPGP card spec 1.1 */
38
+ 	{ 0x004f, SIMPLE,      READ_ALWAYS | WRITE_NEVER, NULL,               NULL        },
39
+ 	{ 0x005b, SIMPLE,      READ_ALWAYS | WRITE_PIN3,  NULL,               sc_put_data },
40
+@@ -192,12 +210,12 @@ static struct do_info		pgp1_objects[] = {	/* OpenPGP card spec 1.1 */
41
+ 	{ 0x5f35, SIMPLE,      READ_ALWAYS | WRITE_PIN3,  NULL,               sc_put_data },
42
+ 	{ 0x5f50, SIMPLE,      READ_ALWAYS | WRITE_PIN3,  sc_get_data,        sc_put_data },
43
+ 	{ 0x7f49, CONSTRUCTED, READ_ALWAYS | WRITE_NEVER, NULL,               NULL        },
44
+-	{ 0xa400, CONSTRUCTED, READ_ALWAYS | WRITE_NEVER, pgp_get_pubkey,     NULL        },
45
+-	{ 0xa401, SIMPLE,      READ_ALWAYS | WRITE_PIN3,  pgp_get_pubkey_pem, NULL        },
46
+-	{ 0xb600, CONSTRUCTED, READ_ALWAYS | WRITE_NEVER, pgp_get_pubkey,     NULL        },
47
+-	{ 0xb601, SIMPLE,      READ_ALWAYS | WRITE_PIN3,  pgp_get_pubkey_pem, NULL        },
48
+-	{ 0xb800, CONSTRUCTED, READ_ALWAYS | WRITE_NEVER, pgp_get_pubkey,     NULL        },
49
+-	{ 0xb801, SIMPLE,      READ_ALWAYS | WRITE_PIN3,  pgp_get_pubkey_pem, NULL        },
50
++	{ DO_AUTH,     CONSTRUCTED, READ_ALWAYS | WRITE_NEVER, pgp_get_pubkey,     NULL   },
51
++	{ DO_AUTH_SYM, SIMPLE,      READ_ALWAYS | WRITE_PIN3,  pgp_get_pubkey_pem, NULL   },
52
++	{ DO_SIGN,     CONSTRUCTED, READ_ALWAYS | WRITE_NEVER, pgp_get_pubkey,     NULL   },
53
++	{ DO_SIGN_SYM, SIMPLE,      READ_ALWAYS | WRITE_PIN3,  pgp_get_pubkey_pem, NULL   },
54
++	{ DO_ENCR,     CONSTRUCTED, READ_ALWAYS | WRITE_NEVER, pgp_get_pubkey,     NULL   },
55
++	{ DO_ENCR_SYM, SIMPLE,      READ_ALWAYS | WRITE_PIN3,  pgp_get_pubkey_pem, NULL   },
56
+ 	{ 0, 0, 0, NULL, NULL },
57
+ };
58
+ 
59
+@@ -246,30 +264,21 @@ static struct do_info		pgp2_objects[] = {	/* OpenPGP card spec 2.0 */
60
+ 	{ 0x5f52, SIMPLE,      READ_ALWAYS | WRITE_NEVER, sc_get_data,        NULL        },
61
+ 	/* The 7F21 is constructed DO in spec, but in practice, its content can be retrieved
62
+ 	 * as simple DO (no need to parse TLV). */
63
+-	{ 0x7f21, SIMPLE,      READ_ALWAYS | WRITE_PIN3,  sc_get_data,        sc_put_data },
64
++	{ DO_CERT, SIMPLE,      READ_ALWAYS | WRITE_PIN3,  sc_get_data,        sc_put_data },
65
+ 	{ 0x7f48, CONSTRUCTED, READ_NEVER  | WRITE_NEVER, NULL,               NULL        },
66
+ 	{ 0x7f49, CONSTRUCTED, READ_ALWAYS | WRITE_NEVER, NULL,               NULL        },
67
+-	{ 0xa400, CONSTRUCTED, READ_ALWAYS | WRITE_NEVER, pgp_get_pubkey,     NULL        },
68
++	{ DO_AUTH,     CONSTRUCTED, READ_ALWAYS | WRITE_NEVER, pgp_get_pubkey,     NULL   },
69
+ 	/* The 0xA401, 0xB601, 0xB801 are just symbolic, it does not represent any real DO.
70
+ 	 * However, their R/W access condition may block the process of importing key in pkcs15init.
71
+ 	 * So we set their accesses condition as WRITE_PIN3 (writable). */
72
+-	{ 0xa401, SIMPLE,      READ_ALWAYS | WRITE_PIN3,  pgp_get_pubkey_pem, NULL        },
73
+-	{ 0xb600, CONSTRUCTED, READ_ALWAYS | WRITE_NEVER, pgp_get_pubkey,     NULL        },
74
+-	{ 0xb601, SIMPLE,      READ_ALWAYS | WRITE_PIN3,  pgp_get_pubkey_pem, NULL        },
75
+-	{ 0xb800, CONSTRUCTED, READ_ALWAYS | WRITE_NEVER, pgp_get_pubkey,     NULL        },
76
+-	{ 0xb801, SIMPLE,      READ_ALWAYS | WRITE_PIN3,  pgp_get_pubkey_pem, NULL        },
77
++	{ DO_AUTH_SYM, SIMPLE,      READ_ALWAYS | WRITE_PIN3,  pgp_get_pubkey_pem, NULL   },
78
++	{ DO_SIGN,     CONSTRUCTED, READ_ALWAYS | WRITE_NEVER, pgp_get_pubkey,     NULL   },
79
++	{ DO_SIGN_SYM, SIMPLE,      READ_ALWAYS | WRITE_PIN3,  pgp_get_pubkey_pem, NULL   },
80
++	{ DO_ENCR,     CONSTRUCTED, READ_ALWAYS | WRITE_NEVER, pgp_get_pubkey,     NULL   },
81
++	{ DO_ENCR_SYM, SIMPLE,      READ_ALWAYS | WRITE_PIN3,  pgp_get_pubkey_pem, NULL   },
82
+ 	{ 0, 0, 0, NULL, NULL },
83
+ };
84
+ 
85
+-/* The DO holding X.509 certificate is constructed but does not contain child DO.
86
+- * We should notice this when building fake file system later. */
87
+-#define DO_CERT                  0x7f21
88
+-/* Maximum length for response buffer when reading pubkey. This value is calculated with
89
+- * 4096-bit key length */
90
+-#define MAXLEN_RESP_PUBKEY       527
91
+-/* Gnuk only support 1 key length (2048 bit) */
92
+-#define MAXLEN_RESP_PUBKEY_GNUK  271
93
+-
94
+ #define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
95
+ struct pgp_priv_data {
96
+ 	pgp_blob_t *		mf;
97
+@@ -747,8 +756,9 @@ pgp_read_blob(sc_card_t *card, pgp_blob_t *blob)
98
+ 
99
+ 		/* Buffer length for Gnuk pubkey */
100
+ 		if (card->type == SC_CARD_TYPE_OPENPGP_GNUK &&
101
+-		    (blob->id == 0xa400 || blob->id == 0xb600 || blob->id == 0xb800
102
+-		     || blob->id == 0xa401 || blob->id == 0xb601 || blob->id == 0xb801)) {
103
++		    (blob->id == DO_AUTH || blob->id == DO_SIGN || blob->id == DO_ENCR
104
++		     || blob->id == DO_AUTH_SYM || blob->id == DO_SIGN_SYM
105
++		     || blob->id == DO_ENCR_SYM)) {
106
+ 			buf_len = MAXLEN_RESP_PUBKEY_GNUK;
107
+ 		}
108
+ 
109
+@@ -1804,11 +1814,11 @@ pgp_update_pubkey_blob(sc_card_t *card, u8* modulus, size_t modulus_len,
110
+ 	LOG_FUNC_CALLED(card->ctx);
111
+ 
112
+ 	if (key_id == SC_OPENPGP_KEY_SIGN)
113
+-		blob_id = 0xB601;
114
++		blob_id = DO_SIGN_SYM;
115
+ 	else if (key_id == SC_OPENPGP_KEY_ENCR)
116
+-		blob_id = 0xB801;
117
++		blob_id = DO_ENCR_SYM;
118
+ 	else if (key_id == SC_OPENPGP_KEY_AUTH)
119
+-		blob_id = 0xA401;
120
++		blob_id = DO_AUTH_SYM;
121
+ 	else {
122
+ 		sc_log(card->ctx, "Unknown key id %X.", key_id);
123
+ 		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
124
+@@ -2501,17 +2511,17 @@ pgp_delete_file(sc_card_t *card, const sc_path_t *path)
125
+ 		LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
126
+ 
127
+ 	if (card->type != SC_CARD_TYPE_OPENPGP_GNUK &&
128
+-	    (file->id == 0xB601 || file->id == 0xB801 || file->id == 0xA401)) {
129
++	    (file->id == DO_SIGN_SYM || file->id == DO_ENCR_SYM || file->id == DO_AUTH_SYM)) {
130
+ 		/* These tags are just symbolic. We don't really delete it. */
131
+ 		r = SC_SUCCESS;
132
+ 	}
133
+-	else if (card->type == SC_CARD_TYPE_OPENPGP_GNUK && file->id == 0xB601) {
134
++	else if (card->type == SC_CARD_TYPE_OPENPGP_GNUK && file->id == DO_SIGN_SYM) {
135
+ 		r = gnuk_delete_key(card, 1);
136
+ 	}
137
+-	else if (card->type == SC_CARD_TYPE_OPENPGP_GNUK && file->id == 0xB801) {
138
++	else if (card->type == SC_CARD_TYPE_OPENPGP_GNUK && file->id == DO_ENCR_SYM) {
139
+ 		r = gnuk_delete_key(card, 2);
140
+ 	}
141
+-	else if (card->type == SC_CARD_TYPE_OPENPGP_GNUK && file->id == 0xA401) {
142
++	else if (card->type == SC_CARD_TYPE_OPENPGP_GNUK && file->id == DO_AUTH_SYM) {
143
+ 		r = gnuk_delete_key(card, 3);
144
+ 	}
145
+ 	else {
146
+-- 
147
+2.1.3
148
+

+ 53
- 0
utils/opensc/patches/0026-hardcode-defines-for-DO-s.patch Visa fil

@@ -0,0 +1,53 @@
1
+From b9dae832db54b206a15bcc12e290cef50f31c3d0 Mon Sep 17 00:00:00 2001
2
+From: george <ggkitsas@yahoo.com>
3
+Date: Tue, 11 Nov 2014 16:16:15 +0100
4
+Subject: [PATCH 26/26] hardcode->defines for DO's
5
+
6
+---
7
+ src/libopensc/card-openpgp.c | 16 ++++++++++++++--
8
+ 1 file changed, 14 insertions(+), 2 deletions(-)
9
+
10
+diff --git a/src/libopensc/card-openpgp.c b/src/libopensc/card-openpgp.c
11
+index 1e6e338..8464914 100644
12
+--- a/src/libopensc/card-openpgp.c
13
++++ b/src/libopensc/card-openpgp.c
14
+@@ -164,6 +164,18 @@ static int		pgp_get_pubkey_pem(sc_card_t *, unsigned int,
15
+ #define DO_SIGN_SYM              0xb601
16
+ #define DO_ENCR_SYM              0xb801
17
+ #define DO_AUTH_SYM              0xa401
18
++/* Private DO's */
19
++#define DO_PRIV1                 0x0101
20
++#define DO_PRIV2                 0x0102
21
++#define DO_PRIV3                 0x0103
22
++#define DO_PRIV4                 0x0104
23
++/* Cardholder information DO's */
24
++#define DO_CARDHOLDER            0x65
25
++#define DO_NAME                  0x5b
26
++#define DO_LANG_PREF             0x5f2d
27
++#define DO_SEX                   0x5f35
28
++
29
++
30
+ /* Maximum length for response buffer when reading pubkey. This value is calculated with
31
+  * 4096-bit key length */
32
+ #define MAXLEN_RESP_PUBKEY       527
33
+@@ -851,7 +863,7 @@ pgp_get_blob(sc_card_t *card, pgp_blob_t *blob, unsigned int id,
34
+ 	/* Special case:
35
+ 	 * Gnuk does not have default value for children of DO 65 (DOs 5B, 5F2D, 5F35)
36
+ 	 * So, if these blob was not found, we create it. */
37
+-	if (blob->id == 0x65 && (id == 0x5B || id == 0x5F2D || id == 0x5F35)) {
38
++	if (blob->id == DO_CARDHOLDER && (id == DO_NAME || id == DO_LANG_PREF || id == DO_SEX)) {
39
+ 		sc_log(card->ctx, "Create blob %X under %X", id, blob->id);
40
+ 		child = pgp_new_blob(card, blob, id, sc_file_new());
41
+ 		if (child) {
42
+@@ -1198,7 +1210,7 @@ pgp_get_data(sc_card_t *card, unsigned int tag, u8 *buf, size_t buf_len)
43
+ 	/* For Gnuk card, if there is no certificate, it returns error instead of empty data.
44
+ 	 * So, for this case, we ignore error and consider success */
45
+ 	if (r == SC_ERROR_DATA_OBJECT_NOT_FOUND && card->type == SC_CARD_TYPE_OPENPGP_GNUK
46
+-        && (tag == DO_CERT || tag == 0x0101 || tag == 0x0102 || tag == 0x0103 || tag == 0x0104)) {
47
++        && (tag == DO_CERT || tag == DO_PRIV1 || tag == DO_PRIV2 || tag == DO_PRIV3 || tag == DO_PRIV4)) {
48
+ 		r = SC_SUCCESS;
49
+ 		apdu.resplen = 0;
50
+ 	}
51
+-- 
52
+2.1.3
53
+