~ubuntu-branches/ubuntu/vivid/gnupg2/vivid-proposed

« back to all changes in this revision

Viewing changes to scd/app-openpgp.c

  • Committer: Package Import Robot
  • Author(s): Dmitrijs Ledkovs
  • Date: 2013-11-01 22:15:05 UTC
  • mfrom: (14.1.8 sid)
  • Revision ID: package-import@ubuntu.com-20131101221505-i1zpbl1qd1a3gsvx
Tags: 2.0.22-1ubuntu1
* Merge from Debian, remaining changes:
  - Drop sh prefix from openpgp test environment as it leads to exec
  invocations of sh /bin/bash leading to syntax errors from sh.  Fixes
  FTBFS detected in Ubuntu saucy archive rebuild.
  - Add udev rules to give gpg access to some smartcard readers;
    Debian #543217.
  - debian/gnupg2.udev: udev rules to set ACLs on SCM smartcard readers.
  - Add upstart user job for gpg-agent.

Show diffs side-by-side

added added

removed removed

Lines of Context:
629
629
    if (*buffer == '\n')
630
630
      break;
631
631
  if (buflen < 2 || buffer[1] != '\x14')
632
 
    return; /* No control sequences.  */
 
632
    {
 
633
      xfree (relptr);
 
634
      return; /* No control sequences.  */
 
635
    }
 
636
 
633
637
  buflen--;
634
638
  buffer++;
635
639
  do
676
680
                      m = strtol (q, &q, 10);
677
681
                    }
678
682
 
 
683
                  if (buflen < ((unsigned char *)q - buffer))
 
684
                    break;
 
685
 
 
686
                  buflen -= ((unsigned char *)q - buffer);
679
687
                  buffer = q;
680
 
                  if (buflen < ((unsigned char *)q - buffer))
681
 
                    {
682
 
                      buflen = 0;
683
 
                      break;
684
 
                    }
685
 
                  else
686
 
                    buflen -= ((unsigned char *)q - buffer);
687
688
 
688
689
                  if (buflen && !(*buffer == '\n' || *buffer == '\x18'))
689
690
                    goto next;
694
695
            }
695
696
        }
696
697
    next:
697
 
      for (; buflen && *buffer != '\x18'; buflen--, buffer++)
698
 
        if (*buffer == '\n')
699
 
          buflen = 1;
 
698
      /* Skip to FS (0x18) or LF (\n).  */
 
699
      for (; buflen && *buffer != '\x18' && *buffer != '\n'; buflen--)
 
700
        buffer++;
700
701
    }
701
 
  while (buflen);
 
702
  while (buflen && *buffer != '\n');
702
703
 
703
704
  xfree (relptr);
704
705
}
2379
2380
                        const unsigned char *rsa_e, size_t rsa_e_len,
2380
2381
                        const unsigned char *rsa_p, size_t rsa_p_len,
2381
2382
                        const unsigned char *rsa_q, size_t rsa_q_len,
 
2383
                        const unsigned char *rsa_u, size_t rsa_u_len,
 
2384
                        const unsigned char *rsa_dp, size_t rsa_dp_len,
 
2385
                        const unsigned char *rsa_dq, size_t rsa_dq_len,
2382
2386
                        unsigned char **result, size_t *resultlen)
2383
2387
{
2384
2388
  size_t rsa_e_reqlen;
2385
 
  unsigned char privkey[7*(1+3)];
 
2389
  unsigned char privkey[7*(1+3+3)];
2386
2390
  size_t privkey_len;
2387
2391
  unsigned char exthdr[2+2+3];
2388
2392
  size_t exthdr_len;
2400
2404
    {
2401
2405
    case RSA_STD:
2402
2406
    case RSA_STD_N:
2403
 
      break;
2404
2407
    case RSA_CRT:
2405
2408
    case RSA_CRT_N:
2406
 
      return gpg_error (GPG_ERR_NOT_SUPPORTED);
 
2409
      break;
2407
2410
 
2408
2411
    default:
2409
2412
      return gpg_error (GPG_ERR_INV_VALUE);
2410
2413
    }
2411
2414
 
2412
 
  /* Get the required length for E.  */
2413
 
  rsa_e_reqlen = app->app_local->keyattr[keyno].e_bits/8;
 
2415
  /* Get the required length for E. Rounded up to the nearest byte  */
 
2416
  rsa_e_reqlen = (app->app_local->keyattr[keyno].e_bits + 7) / 8;
2414
2417
  assert (rsa_e_len <= rsa_e_reqlen);
2415
2418
 
2416
2419
  /* Build the 7f48 cardholder private key template.  */
2426
2429
  tp += add_tlv (tp, 0x93, rsa_q_len);
2427
2430
  datalen += rsa_q_len;
2428
2431
 
 
2432
  if (app->app_local->keyattr[keyno].format == RSA_CRT
 
2433
      || app->app_local->keyattr[keyno].format == RSA_CRT_N)
 
2434
    {
 
2435
      tp += add_tlv (tp, 0x94, rsa_u_len);
 
2436
      datalen += rsa_u_len;
 
2437
      tp += add_tlv (tp, 0x95, rsa_dp_len);
 
2438
      datalen += rsa_dp_len;
 
2439
      tp += add_tlv (tp, 0x96, rsa_dq_len);
 
2440
      datalen += rsa_dq_len;
 
2441
    }
 
2442
 
2429
2443
  if (app->app_local->keyattr[keyno].format == RSA_STD_N
2430
2444
      || app->app_local->keyattr[keyno].format == RSA_CRT_N)
2431
2445
    {
2479
2493
  memcpy (tp, rsa_q, rsa_q_len);
2480
2494
  tp += rsa_q_len;
2481
2495
 
 
2496
  if (app->app_local->keyattr[keyno].format == RSA_CRT
 
2497
      || app->app_local->keyattr[keyno].format == RSA_CRT_N)
 
2498
    {
 
2499
      memcpy (tp, rsa_u, rsa_u_len);
 
2500
      tp += rsa_u_len;
 
2501
      memcpy (tp, rsa_dp, rsa_dp_len);
 
2502
      tp += rsa_dp_len;
 
2503
      memcpy (tp, rsa_dq, rsa_dq_len);
 
2504
      tp += rsa_dq_len;
 
2505
    }
 
2506
 
2482
2507
  if (app->app_local->keyattr[keyno].format == RSA_STD_N
2483
2508
      || app->app_local->keyattr[keyno].format == RSA_CRT_N)
2484
2509
    {
2825
2850
 
2826
2851
  if (app->app_local->extcap.is_v2)
2827
2852
    {
 
2853
      unsigned char *rsa_u, *rsa_dp, *rsa_dq;
 
2854
      size_t rsa_u_len, rsa_dp_len, rsa_dq_len;
 
2855
      gcry_mpi_t mpi_e, mpi_p, mpi_q;
 
2856
      gcry_mpi_t mpi_u = gcry_mpi_snew (0);
 
2857
      gcry_mpi_t mpi_dp = gcry_mpi_snew (0);
 
2858
      gcry_mpi_t mpi_dq = gcry_mpi_snew (0);
 
2859
      gcry_mpi_t mpi_tmp = gcry_mpi_snew (0);
 
2860
      int exmode;
 
2861
 
 
2862
      /* Calculate the u, dp and dq components needed by RSA_CRT cards */
 
2863
      gcry_mpi_scan (&mpi_e, GCRYMPI_FMT_USG, rsa_e, rsa_e_len, NULL);
 
2864
      gcry_mpi_scan (&mpi_p, GCRYMPI_FMT_USG, rsa_p, rsa_p_len, NULL);
 
2865
      gcry_mpi_scan (&mpi_q, GCRYMPI_FMT_USG, rsa_q, rsa_q_len, NULL);
 
2866
 
 
2867
      gcry_mpi_invm (mpi_u, mpi_q, mpi_p);
 
2868
      gcry_mpi_sub_ui (mpi_tmp, mpi_p, 1);
 
2869
      gcry_mpi_invm (mpi_dp, mpi_e, mpi_tmp);
 
2870
      gcry_mpi_sub_ui (mpi_tmp, mpi_q, 1);
 
2871
      gcry_mpi_invm (mpi_dq, mpi_e, mpi_tmp);
 
2872
 
 
2873
      gcry_mpi_aprint (GCRYMPI_FMT_USG, &rsa_u, &rsa_u_len, mpi_u);
 
2874
      gcry_mpi_aprint (GCRYMPI_FMT_USG, &rsa_dp, &rsa_dp_len, mpi_dp);
 
2875
      gcry_mpi_aprint (GCRYMPI_FMT_USG, &rsa_dq, &rsa_dq_len, mpi_dq);
 
2876
 
 
2877
      gcry_mpi_release (mpi_e);
 
2878
      gcry_mpi_release (mpi_p);
 
2879
      gcry_mpi_release (mpi_q);
 
2880
      gcry_mpi_release (mpi_u);
 
2881
      gcry_mpi_release (mpi_dp);
 
2882
      gcry_mpi_release (mpi_dq);
 
2883
      gcry_mpi_release (mpi_tmp);
 
2884
 
2828
2885
      /* Build the private key template as described in section 4.3.3.7 of
2829
2886
         the OpenPGP card specs version 2.0.  */
2830
 
      int exmode;
2831
 
 
2832
2887
      err = build_privkey_template (app, keyno,
2833
2888
                                    rsa_n, rsa_n_len,
2834
2889
                                    rsa_e, rsa_e_len,
2835
2890
                                    rsa_p, rsa_p_len,
2836
2891
                                    rsa_q, rsa_q_len,
 
2892
                                    rsa_u, rsa_u_len,
 
2893
                                    rsa_dp, rsa_dp_len,
 
2894
                                    rsa_dq, rsa_dq_len,
2837
2895
                                    &template, &template_len);
 
2896
      xfree(rsa_u);
 
2897
      xfree(rsa_dp);
 
2898
      xfree(rsa_dq);
 
2899
 
2838
2900
      if (err)
2839
2901
        goto leave;
2840
2902