~ubuntu-branches/ubuntu/karmic/gnupg2/karmic-security

« back to all changes in this revision

Viewing changes to scd/app-dinsig.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:
1
1
/* app-dinsig.c - The DINSIG (DIN V 66291-1) card application.
2
 
 *      Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.
 
2
 * Copyright (C) 2002, 2004, 2005, 2007 Free Software Foundation, Inc.
3
3
 *
4
4
 * This file is part of GnuPG.
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
 
80
79
 
81
80
#include "scdaemon.h"
82
81
 
 
82
#include "i18n.h"
83
83
#include "iso7816.h"
84
84
#include "app-common.h"
85
85
#include "tlv.h"
278
278
            gpg_error_t (*pincb)(void*, const char *, char **),
279
279
            void *pincb_arg)
280
280
{
281
 
  if (!app->did_chv1 || app->force_chv1 ) 
282
 
    {
283
 
      const char *s;
 
281
  const char *s;
 
282
  int rc;
 
283
  iso7816_pininfo_t pininfo;
 
284
 
 
285
  if ( app->did_chv1 && !app->force_chv1 ) 
 
286
    return 0;  /* No need to verify it again.  */
 
287
 
 
288
  memset (&pininfo, 0, sizeof pininfo);
 
289
  pininfo.mode = 1;
 
290
  pininfo.minlen = 6;
 
291
  pininfo.maxlen = 8;
 
292
 
 
293
  if (!opt.disable_keypad
 
294
      && !iso7816_check_keypad (app->slot, ISO7816_VERIFY, &pininfo) )
 
295
    {
 
296
      rc = pincb (pincb_arg,
 
297
                  _("||Please enter your PIN at the reader's keypad"),
 
298
                  NULL);
 
299
      if (rc)
 
300
        {
 
301
          log_info (_("PIN callback returned error: %s\n"),
 
302
                    gpg_strerror (rc));
 
303
          return rc;
 
304
        }
 
305
      rc = iso7816_verify_kp (app->slot, 0x81, "", 0, &pininfo); 
 
306
      /* Dismiss the prompt. */
 
307
      pincb (pincb_arg, NULL, NULL);
 
308
    }
 
309
  else  /* No Keypad.  */
 
310
    {
284
311
      char *pinvalue;
285
 
      int rc;
286
312
 
287
313
      rc = pincb (pincb_arg, "PIN", &pinvalue);
288
314
      if (rc)
302
328
          return gpg_error (GPG_ERR_BAD_PIN);
303
329
        }
304
330
 
305
 
      if (strlen (pinvalue) < 6)
 
331
      if (strlen (pinvalue) < pininfo.minlen)
306
332
        {
307
 
          log_error ("PIN is too short; minimum length is 6\n");
 
333
          log_error ("PIN is too short; minimum length is %d\n",
 
334
                     pininfo.minlen);
308
335
          xfree (pinvalue);
309
336
          return gpg_error (GPG_ERR_BAD_PIN);
310
337
        }
311
 
      else if (strlen (pinvalue) > 8)
 
338
      else if (strlen (pinvalue) > pininfo.maxlen)
312
339
        {
313
 
          log_error ("PIN is too large; maximum length is 8\n");
 
340
          log_error ("PIN is too large; maximum length is %d\n",
 
341
                     pininfo.maxlen);
314
342
          xfree (pinvalue);
315
343
          return gpg_error (GPG_ERR_BAD_PIN);
316
344
        }
325
353
             this. */
326
354
          char paddedpin[8];
327
355
          int i, ndigits;
328
 
 
 
356
          
329
357
          for (ndigits=0, s=pinvalue; *s; ndigits++, s++)
330
358
            ;
331
359
          i = 0;
335
363
          if (i < sizeof paddedpin && *s)
336
364
            paddedpin[i++] = (((*s - '0') << 4) | 0x0f);
337
365
          while (i < sizeof paddedpin)
338
 
              paddedpin[i++] = 0xff;
 
366
            paddedpin[i++] = 0xff;
339
367
          rc = iso7816_verify (app->slot, 0x81, paddedpin, sizeof paddedpin);
340
368
        }
341
 
      if (rc)
342
 
        {
343
 
          log_error ("verify PIN failed\n");
344
 
          xfree (pinvalue);
345
 
          return rc;
346
 
        }
347
 
      app->did_chv1 = 1;
348
369
      xfree (pinvalue);
349
370
    }
350
371
 
 
372
  if (rc)
 
373
    {
 
374
      log_error ("verify PIN failed\n");
 
375
      return rc;
 
376
    }
 
377
  app->did_chv1 = 1;
351
378
  return 0;
352
379
}
353
380
 
429
456
/* Select the DINSIG application on the card in SLOT.  This function
430
457
   must be used before any other DINSIG application functions. */
431
458
gpg_error_t
432
 
app_select_dinsig (APP app)
 
459
app_select_dinsig (app_t app)
433
460
{
434
461
  static char const aid[] = { 0xD2, 0x76, 0x00, 0x00, 0x66, 0x01 };
435
462
  int slot = app->slot;