1 /* qualified.c - Routines related to qualified signatures
2 * Copyright (C) 2005, 2007 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 2 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, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
32 #ifdef HAVE_LANGINFO_CODESET
41 /* We open the file only once and keep the open file pointer as well
42 as the name of the file here. Note that, a listname not equal to
43 NULL indicates that this module has been intialized and if the
44 LISTFP is also NULL, no list of qualified signatures exists. */
45 static char *listname
;
49 /* Read the trustlist and return entry by entry. KEY must point to a
50 buffer of at least 41 characters. COUNTRY shall be a buffer of at
51 least 3 characters to receive the country code of that qualified
52 signature (i.e. "de" for German and "be" for Belgium).
54 Reading a valid entry returns 0, EOF is indicated by GPG_ERR_EOF
55 and any other error condition is indicated by the appropriate error
58 read_list (char *key
, char *country
, int *lnr
)
69 listname
= make_filename (GNUPG_DATADIR
, "qualified.txt", NULL
);
70 listfp
= fopen (listname
, "r");
71 if (!listfp
&& errno
!= ENOENT
)
73 err
= gpg_error_from_syserror ();
74 log_error (_("can't open `%s': %s\n"), listname
, gpg_strerror (err
));
80 return gpg_error (GPG_ERR_EOF
);
84 if (!fgets (line
, DIM(line
)-1, listfp
) )
87 return gpg_error (GPG_ERR_EOF
);
88 return gpg_error_from_syserror ();
91 if (!*line
|| line
[strlen(line
)-1] != '\n')
93 /* Eat until end of line. */
94 while ( (c
=getc (listfp
)) != EOF
&& c
!= '\n')
96 return gpg_error (*line
? GPG_ERR_LINE_TOO_LONG
97 : GPG_ERR_INCOMPLETE_LINE
);
101 /* Allow for empty lines and spaces */
102 for (p
=line
; spacep (p
); p
++)
105 while (!*p
|| *p
== '\n' || *p
== '#');
107 for (i
=j
=0; (p
[i
] == ':' || hexdigitp (p
+i
)) && j
< 40; i
++)
109 key
[j
++] = p
[i
] >= 'a'? (p
[i
] & 0xdf): p
[i
];
111 if (j
!= 40 || !(spacep (p
+i
) || p
[i
] == '\n'))
113 log_error (_("invalid formatted fingerprint in `%s', line %d\n"),
115 return gpg_error (GPG_ERR_BAD_DATA
);
121 if ( p
[i
] >= 'a' && p
[i
] <= 'z'
122 && p
[i
+1] >= 'a' && p
[i
+1] <= 'z'
123 && (spacep (p
+i
+2) || p
[i
+2] == '\n'))
131 log_error (_("invalid country code in `%s', line %d\n"), listname
, *lnr
);
132 return gpg_error (GPG_ERR_BAD_DATA
);
141 /* Check whether the certificate CERT is included in the list of
142 qualified certificates. This list is similar to the "trustlist.txt"
143 as maintained by gpg-agent and includes fingerprints of root
144 certificates to be used for qualified (legally binding like
145 handwritten) signatures. We keep this list system wide and not
146 per user because it is not a decision of the user.
148 Returns: 0 if the certificate is included. GPG_ERR_NOT_FOUND if it
149 is not in the list or any other error (e.g. if no list of
150 qualified signatures is available. If COUNTRY has not been passed
151 as NULL a string witha maximum length of 2 will be copied into it;
152 thus the caller needs to provide a buffer of length 3. */
154 gpgsm_is_in_qualified_list (ctrl_t ctrl
, ksba_cert_t cert
, char *country
)
165 fpr
= gpgsm_get_fingerprint_hexstring (cert
, GCRY_MD_SHA1
);
167 return gpg_error (GPG_ERR_GENERAL
);
171 while (!(err
= read_list (key
, mycountry
, &lnr
)))
173 if (!strcmp (key
, fpr
))
176 if (gpg_err_code (err
) == GPG_ERR_EOF
)
177 err
= gpg_error (GPG_ERR_NOT_FOUND
);
180 strcpy (country
, mycountry
);
187 /* We know that CERT is a qualified certificate. Ask the user for
188 consent to actually create a signature using this certificate.
189 Returns: 0 for yes, GPG_ERR_CANCEL for no or any otehr error
192 gpgsm_qualified_consent (ctrl_t ctrl
, ksba_cert_t cert
)
195 char *name
, *subject
, *buffer
, *p
;
197 char *orig_codeset
= NULL
;
199 name
= ksba_cert_get_subject (cert
, 0);
201 return gpg_error (GPG_ERR_GENERAL
);
202 subject
= gpgsm_format_name2 (name
, 0);
203 ksba_free (name
); name
= NULL
;
206 /* The Assuan agent protocol requires us to transmit utf-8 strings */
207 orig_codeset
= bind_textdomain_codeset (PACKAGE_GT
, NULL
);
208 #ifdef HAVE_LANGINFO_CODESET
210 orig_codeset
= nl_langinfo (CODESET
);
213 { /* We only switch when we are able to restore the codeset later.
214 Note that bind_textdomain_codeset does only return on memory
215 errors but not if a codeset is not available. Thus we don't
216 bother printing a diagnostic here. */
217 orig_codeset
= xstrdup (orig_codeset
);
218 if (!bind_textdomain_codeset (PACKAGE_GT
, "utf-8"))
220 xfree (orig_codeset
);
227 _("You are about to create a signature using your "
230 "This will create a qualified signature by law "
231 "equated to a handwritten signature.\n\n%s%s"
232 "Are you really sure that you want to do this?"),
233 subject
? subject
:"?",
234 opt
.qualsig_approval
?
236 _("Note, that this software is not officially approved "
237 "to create or verify such signatures.\n"),
238 opt
.qualsig_approval
? "":"\n"
240 err
= gpg_error_from_syserror ();
246 bind_textdomain_codeset (PACKAGE_GT
, orig_codeset
);
248 xfree (orig_codeset
);
254 buffer
= p
= xtrymalloc (strlen (name
) * 3 + 1);
257 err
= gpg_error_from_syserror ();
261 for (s
=name
; *s
; s
++)
263 if (*s
< ' ' || *s
== '+')
265 sprintf (p
, "%%%02X", *(unsigned char *)s
);
277 err
= gpgsm_agent_get_confirmation (ctrl
, buffer
);
284 /* Popup a prompt to inform the user that the signature created is not
285 a qualified one. This is of course only done if we know that we
286 have been approved. */
288 gpgsm_not_qualified_warning (ctrl_t ctrl
, ksba_cert_t cert
)
291 char *name
, *subject
, *buffer
, *p
;
293 char *orig_codeset
= NULL
;
295 if (!opt
.qualsig_approval
)
298 name
= ksba_cert_get_subject (cert
, 0);
300 return gpg_error (GPG_ERR_GENERAL
);
301 subject
= gpgsm_format_name2 (name
, 0);
302 ksba_free (name
); name
= NULL
;
306 /* The Assuan agent protocol requires us to transmit utf-8 strings */
307 orig_codeset
= bind_textdomain_codeset (PACKAGE_GT
, NULL
);
308 #ifdef HAVE_LANGINFO_CODESET
310 orig_codeset
= nl_langinfo (CODESET
);
313 { /* We only switch when we are able to restore the codeset later.
314 Note that bind_textdomain_codeset does only return on memory
315 errors but not if a codeset is not available. Thus we don't
316 bother printing a diagnostic here. */
317 orig_codeset
= xstrdup (orig_codeset
);
318 if (!bind_textdomain_codeset (PACKAGE_GT
, "utf-8"))
320 xfree (orig_codeset
);
327 _("You are about to create a signature using your "
330 "Note, that this certificate will NOT create a "
331 "qualified signature!"),
332 subject
? subject
:"?") < 0 )
333 err
= gpg_error_from_syserror ();
340 bind_textdomain_codeset (PACKAGE_GT
, orig_codeset
);
341 xfree (orig_codeset
);
349 buffer
= p
= xtrymalloc (strlen (name
) * 3 + 1);
352 err
= gpg_error_from_syserror ();
356 for (s
=name
; *s
; s
++)
358 if (*s
< ' ' || *s
== '+')
360 sprintf (p
, "%%%02X", *(unsigned char *)s
);
372 err
= gpgsm_agent_get_confirmation (ctrl
, buffer
);