~ubuntu-branches/ubuntu/oneiric/gnupg2/oneiric-updates

« back to all changes in this revision

Viewing changes to agent/divert-scd.c

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Viehmann
  • Date: 2008-10-04 10:25:53 UTC
  • mfrom: (5.1.15 intrepid)
  • Revision ID: james.westby@ubuntu.com-20081004102553-fv62pp8dsitxli47
Tags: 2.0.9-3.1
* Non-maintainer upload.
* agent/gpg-agent.c: Deinit the threading library before exec'ing
  the command to run in --daemon mode. And because that still doesn't
  restore the sigprocmask, do that manually. Closes: #499569

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 *
6
6
 * GnuPG is free software; you can redistribute it and/or modify
7
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
 
8
 * the Free Software Foundation; either version 3 of the License, or
9
9
 * (at your option) any later version.
10
10
 *
11
11
 * GnuPG is distributed in the hope that it will be useful,
14
14
 * GNU General Public License for more details.
15
15
 *
16
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
 
17
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
19
18
 */
20
19
 
21
20
#include <config.h>
34
33
 
35
34
 
36
35
static int
37
 
ask_for_card (CTRL ctrl, const unsigned char *shadow_info, char **r_kid)
 
36
ask_for_card (ctrl_t ctrl, const unsigned char *shadow_info, char **r_kid)
38
37
{
39
38
  int rc, i;
40
39
  const unsigned char *s;
147
146
  *r_len = 0;
148
147
 
149
148
  asnlen = DIM(asn);
 
149
  if (!algo || gcry_md_test_algo (algo))
 
150
    return gpg_error (GPG_ERR_DIGEST_ALGO);
150
151
  if (gcry_md_algo_info (algo, GCRYCTL_GET_ASNOID, asn, &asnlen))
151
152
    {
152
153
      log_error ("no object identifier for algo %d\n", algo);
234
235
        }
235
236
      else if (maxbuf == 1)  /* Open the pinentry. */
236
237
        {
237
 
          rc = agent_popup_message_start (ctrl, info, NULL, NULL);
 
238
          rc = agent_popup_message_start (ctrl, info, NULL);
238
239
        }
239
240
      else
240
241
        rc = gpg_error (GPG_ERR_INV_VALUE);
247
248
 again:
248
249
  pi = gcry_calloc_secure (1, sizeof (*pi) + maxbuf + 10);
249
250
  if (!pi)
250
 
    return gpg_error_from_errno (errno);
 
251
    return gpg_error_from_syserror ();
251
252
  pi->max_length = maxbuf-1;
252
253
  pi->min_digits = 0;  /* we want a real passphrase */
253
254
  pi->max_digits = 8;
263
264
          pi2 = gcry_calloc_secure (1, sizeof (*pi) + maxbuf + 10);
264
265
          if (!pi2)
265
266
            {
266
 
              rc = gpg_error_from_errno (errno);
 
267
              rc = gpg_error_from_syserror ();
267
268
              xfree (pi);
268
269
              return rc;
269
270
            }
308
309
 
309
310
 
310
311
int
311
 
divert_pksign (CTRL ctrl, 
 
312
divert_pksign (ctrl_t ctrl, 
312
313
               const unsigned char *digest, size_t digestlen, int algo,
313
314
               const unsigned char *shadow_info, unsigned char **r_sig)
314
315
{
315
316
  int rc;
316
317
  char *kid;
317
318
  size_t siglen;
318
 
  unsigned char *sigval;
319
 
  unsigned char *data;
320
 
  size_t ndata;
 
319
  unsigned char *sigval = NULL;
321
320
 
322
321
  rc = ask_for_card (ctrl, shadow_info, &kid);
323
322
  if (rc)
324
323
    return rc;
325
324
 
326
 
  rc = encode_md_for_card (digest, digestlen, algo, 
327
 
                           &data, &ndata);
328
 
  if (rc)
329
 
    return rc;
330
 
 
331
 
  rc = agent_card_pksign (ctrl, kid, getpin_cb, ctrl,
332
 
                          data, ndata, &sigval, &siglen);
 
325
  if (algo == GCRY_MD_USER_TLS_MD5SHA1)
 
326
    {
 
327
      int save = ctrl->use_auth_call;
 
328
      ctrl->use_auth_call = 1;
 
329
      rc = agent_card_pksign (ctrl, kid, getpin_cb, ctrl,
 
330
                              digest, digestlen, &sigval, &siglen);
 
331
      ctrl->use_auth_call = save;
 
332
    }
 
333
  else
 
334
    {
 
335
      unsigned char *data;
 
336
      size_t ndata;
 
337
 
 
338
      rc = encode_md_for_card (digest, digestlen, algo, &data, &ndata);
 
339
      if (!rc)
 
340
        {
 
341
          rc = agent_card_pksign (ctrl, kid, getpin_cb, ctrl,
 
342
                                  data, ndata, &sigval, &siglen);
 
343
          xfree (data);
 
344
        }
 
345
    }
 
346
 
333
347
  if (!rc)
334
348
    *r_sig = sigval;
335
 
  xfree (data);
 
349
 
336
350
  xfree (kid);
337
 
  
 
351
 
338
352
  return rc;
339
353
}
340
354
 
343
357
   key identified by SHADOW_INFO and return the plaintext in an
344
358
   allocated buffer in R_BUF.  */
345
359
int  
346
 
divert_pkdecrypt (CTRL ctrl,
 
360
divert_pkdecrypt (ctrl_t ctrl,
347
361
                  const unsigned char *cipher,
348
362
                  const unsigned char *shadow_info,
349
363
                  char **r_buf, size_t *r_len)
406
420
 
407
421
 
408
422
int  
409
 
divert_generic_cmd (CTRL ctrl, const char *cmdline, void *assuan_context)
 
423
divert_generic_cmd (ctrl_t ctrl, const char *cmdline, void *assuan_context)
410
424
{
411
425
  return agent_card_scd (ctrl, cmdline, getpin_cb, ctrl, assuan_context);
412
426
}