1 /* card-dinsig.c - German signature law (DINSIG) functions
2 * Copyright (C) 2002 Free Software Foundation, Inc.
4 * This file is part of GnuPG.
6 * GnuPG is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * GnuPG is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
20 /* The German signature law and its bylaw (SigG and SigV) is currently
21 used with an interface specification described in DIN V 66291-1.
22 The AID to be used is: 'D27600006601'.
24 The file IDs for certificates utilize the generic format:
26 C being the hex digit 'C' (12).
27 x being the service indicator:
28 '0' := SigG conform digital signature.
29 '1' := entity authentication.
30 '2' := key encipherment.
31 '3' := data encipherment.
33 other values are reserved for future use.
34 y being the security environment number using '0' for cards
35 not supporting a SE number.
36 z being the certificate type:
37 '0' := C.CH (base certificate of ard holder) or C.ICC.
38 '1' .. '7' := C.CH (business or professional certificate
40 '8' .. 'D' := C.CA (certificate of a CA issue by the Root-CA).
41 'E' := C.RCA (self certified certificate of the Root-CA).
44 The file IDs used by default are:
45 '1F00' EF.SSD (security service descriptor). [o,o]
46 '2F02' EF.GDO (global data objects) [m,m]
47 'A000' EF.PROT (signature log). Cyclic file with 20 records of 53 byte.
48 Read and update after user authentication. [o,o]
49 'B000' EF.PK.RCA.DS (public keys of Root-CA). Size is 512b or size
50 of keys. [m (unless a 'C00E' is present),m]
51 'B001' EF.PK.CA.DS (public keys of CAs). Size is 512b or size
53 'C00n' EF.C.CH.DS (digital signature certificate of card holder)
54 with n := 0 .. 7. Size is 2k or size of cert. Read and
55 update allowed after user authentication. [m,m]
56 'C00m' EF.C.CA.DS (digital signature certificate of CA)
57 with m := 8 .. E. Size is 1k or size of cert. Read always
58 allowed, update after uder authentication. [o,o]
59 'C100' EF.C.ICC.AUT (AUT certificate of ICC) [o,m]
60 'C108' EF.C.CA.AUT (AUT certificate of CA) [o,m]
61 'D000' EF.DM (display message) [-,m]
63 The letters in brackets indicate optional or mandatory files: The
64 first for card terminals under full control and the second for
65 "business" card terminals.
67 FIXME: Needs a lot more explanation.
80 #include <opensc/pkcs15.h>
84 #include "card-common.h"
86 static int dinsig_read_cert (CARD card
, const char *certidstr
,
87 unsigned char **cert
, size_t *ncert
);
91 /* See card.c for interface description. Frankly we don't do any real
92 enumeration but just check whether the well know files are
95 dinsig_enum_keypairs (CARD card
, int idx
,
96 unsigned char *keygrip
, char **keyid
)
103 /* fixme: We should locate the application via the EF(DIR) and not
104 assume a Netkey card */
106 rc
= dinsig_read_cert (card
, "DINSIG-DF01.C000", &buf
, &buflen
);
108 rc
= dinsig_read_cert (card
, "DINSIG-DF01.C200", &buf
, &buflen
);
114 rc
= ksba_cert_new (&cert
);
121 rc
= ksba_cert_init_from_mem (cert
, buf
, buflen
);
125 log_error ("failed to parse the certificate at idx %d: %s\n",
126 idx
, gpg_strerror (rc
));
127 ksba_cert_release (cert
);
130 if (card_help_get_keygrip (cert
, keygrip
))
132 log_error ("failed to calculate the keygrip at index %d\n", idx
);
133 ksba_cert_release (cert
);
134 return gpg_error (GPG_ERR_CARD
);
136 ksba_cert_release (cert
);
141 *keyid
= xtrymalloc (17);
143 return gpg_error (gpg_err_code_from_errno (errno
));
145 strcpy (*keyid
, "DINSIG-DF01.C000");
147 strcpy (*keyid
, "DINSIG-DF01.C200");
155 /* See card.c for interface description */
157 dinsig_read_cert (CARD card
, const char *certidstr
,
158 unsigned char **cert
, size_t *ncert
)
162 struct sc_file
*file
;
166 if (!strcmp (certidstr
, "DINSIG-DF01.C000"))
167 sc_format_path ("3F00DF01C000", &path
);
168 else if (!strcmp (certidstr
, "DINSIG-DF01.C200"))
169 sc_format_path ("3F00DF01C200", &path
);
171 return gpg_error (GPG_ERR_INV_ID
);
173 rc
= sc_select_file (card
->scard
, &path
, &file
);
176 log_error ("sc_select_file failed: %s\n", sc_strerror (rc
));
177 return map_sc_err (rc
);
179 if (file
->type
!= SC_FILE_TYPE_WORKING_EF
180 || file
->ef_structure
!= SC_FILE_EF_TRANSPARENT
)
182 log_error ("wrong type or structure of certificate EF\n");
184 return gpg_error (GPG_ERR_CARD
);
186 if (file
->size
< 20) /* check against a somewhat arbitrary length */
188 log_error ("certificate EF too short\n");
190 return gpg_error (GPG_ERR_CARD
);
192 buf
= xtrymalloc (file
->size
);
195 gpg_error_t tmperr
= gpg_error (gpg_err_code_from_errno (errno
));
200 rc
= sc_read_binary (card
->scard
, 0, buf
, file
->size
, 0);
201 if (rc
>= 0 && rc
!= file
->size
)
203 log_error ("short read on certificate EF\n");
206 return gpg_error (GPG_ERR_CARD
);
211 log_error ("error reading certificate EF: %s\n", sc_strerror (rc
));
213 return map_sc_err (rc
);
217 /* The object is not a plain certificate but wrapped into id-at
218 userCertificate - fixme: we should check the specs and decided
219 whether libksba should support it */
220 if (buflen
> 9 && buf
[0] == 0x30 && buf
[4] == 6 && buf
[5] == 3
221 && buf
[6] == 0x55 && buf
[7] == 4 && buf
[8] == 0x24)
223 /* We have to strip the padding. Although this is a good idea
224 anyway, we have to do it due to a KSBA problem; KSBA does not
225 work correct when the buffer is larger than the ASN.1
226 structure and the certificates here are padded with FF. So
227 as a workaround we look at the outer structure to get the
228 size of the entire thing and adjust the buflen. We can only
229 do this when there is a 2 byte length field */
233 seqlen
= ((buf
[2] << 8) | buf
[3]) + 4;
237 memmove (buf
, buf
+9, buflen
-9);
249 /* Bind our operations to the card */
251 card_dinsig_bind (CARD card
)
253 card
->fnc
.enum_keypairs
= dinsig_enum_keypairs
;
254 card
->fnc
.read_cert
= dinsig_read_cert
;
257 #endif /*HAVE_OPENSC*/