~ubuntu-branches/ubuntu/raring/gnupg2/raring-proposed

« back to all changes in this revision

Viewing changes to sm/call-agent.c

  • Committer: Bazaar Package Importer
  • Author(s): Eric Dorland
  • Date: 2009-08-23 20:48:11 UTC
  • mfrom: (1.1.12 upstream)
  • Revision ID: james.westby@ubuntu.com-20090823204811-cajik24rci4xszia
Tags: 2.0.12-1
* New upstream release. (Closes: #499569, #463270, #446494, #314068, 
  #519375, #514587)
* debian/control: Change build dependency on gs to ghoscript, since
  ghoscript has been replaced.
* debian/compat: Use debhelper v7.
* debian/control: Update Standards-Version to 3.8.2.
* debian/control: Use ${misc:Depends}.
* configure.ac: Override pkgdatadir so that it points to
  /usr/share/gnupg2. (Closes: #528734)
* debian/rules: No longer need to specify pkgdatadir at make install
  time.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* call-agent.c - Divert GPGSM operations to the agent
2
2
 * Copyright (C) 2001, 2002, 2003, 2005, 2007,
3
 
 *               2008 Free Software Foundation, Inc.
 
3
 *               2008, 2009 Free Software Foundation, Inc.
4
4
 *
5
5
 * This file is part of GnuPG.
6
6
 *
612
612
gpgsm_agent_marktrusted (ctrl_t ctrl, ksba_cert_t cert)
613
613
{
614
614
  int rc;
615
 
  char *fpr, *dn;
 
615
  char *fpr, *dn, *dnfmt;
616
616
  char line[ASSUAN_LINELENGTH];
617
617
 
618
618
  rc = start_agent (ctrl);
632
632
      xfree (fpr);
633
633
      return gpg_error (GPG_ERR_GENERAL);
634
634
    }
635
 
  snprintf (line, DIM(line)-1, "MARKTRUSTED %s S %s", fpr, dn);
 
635
  dnfmt = gpgsm_format_name2 (dn, 0);
 
636
  xfree (dn);
 
637
  if (!dnfmt)
 
638
    return gpg_error_from_syserror ();
 
639
  snprintf (line, DIM(line)-1, "MARKTRUSTED %s S %s", fpr, dnfmt);
636
640
  line[DIM(line)-1] = 0;
637
 
  ksba_free (dn);
 
641
  ksba_free (dnfmt);
638
642
  xfree (fpr);
639
643
 
640
644
  rc = assuan_transact (agent_ctx, line, NULL, NULL,
668
672
 
669
673
 
670
674
static int
 
675
learn_status_cb (void *opaque, const char *line)
 
676
{
 
677
  struct learn_parm_s *parm = opaque;
 
678
 
 
679
  /* Pass progress data to the caller.  */
 
680
  if (!strncmp (line, "PROGRESS", 8) && (line[8]==' ' || !line[8]))
 
681
    {
 
682
      if (parm->ctrl)
 
683
        {
 
684
          for (line += 8; *line == ' '; line++)
 
685
            ;
 
686
          if (gpgsm_status (parm->ctrl, STATUS_PROGRESS, line))
 
687
            return gpg_error (GPG_ERR_ASS_CANCELED);
 
688
        }
 
689
    }
 
690
  return 0;
 
691
}
 
692
 
 
693
static int
671
694
learn_cb (void *opaque, const void *buffer, size_t length)
672
695
{
673
696
  struct learn_parm_s *parm = opaque;
692
715
      return 0;
693
716
    }
694
717
 
 
718
  if (gpgsm_status (parm->ctrl, STATUS_PROGRESS, "learncard C 0 0"))
 
719
    return gpg_error (GPG_ERR_ASS_CANCELED);
695
720
 
696
721
  /* FIXME: this should go into import.c */
697
722
  rc = ksba_cert_new (&cert);
755
780
  learn_parm.data = &data;
756
781
  rc = assuan_transact (agent_ctx, "LEARN --send",
757
782
                        learn_cb, &learn_parm, 
758
 
                        NULL, NULL, NULL, NULL);
 
783
                        NULL, NULL, 
 
784
                        learn_status_cb, &learn_parm);
759
785
  xfree (get_membuf (&data, &len));
760
786
  if (rc)
761
787
    return rc;
836
862
}
837
863
 
838
864
 
 
865
 
 
866
static int
 
867
keyinfo_status_cb (void *opaque, const char *line)
 
868
{
 
869
  char **serialno = opaque;
 
870
  const char *s, *s2;
 
871
 
 
872
  if (!strncmp (line, "KEYINFO ", 8) && !*serialno)
 
873
    {
 
874
      s = strchr (line+8, ' ');
 
875
      if (s && s[1] == 'T' && s[2] == ' ' && s[3])
 
876
        {
 
877
          s += 3;
 
878
          s2 = strchr (s, ' ');
 
879
          if ( s2 > s )
 
880
            {
 
881
              *serialno = xtrymalloc ((s2 - s)+1);
 
882
              if (*serialno)
 
883
                {
 
884
                  memcpy (*serialno, s, s2 - s);
 
885
                  (*serialno)[s2 - s] = 0;
 
886
                }
 
887
            }
 
888
        }
 
889
    }
 
890
  return 0;
 
891
}
 
892
 
 
893
/* Return the serial number for a secret key.  If the returned serial
 
894
   number is NULL, the key is not stored on a smartcard.  Caller needs
 
895
   to free R_SERIALNO.  */
 
896
gpg_error_t
 
897
gpgsm_agent_keyinfo (ctrl_t ctrl, const char *hexkeygrip, char **r_serialno)
 
898
{
 
899
  gpg_error_t err;
 
900
  char line[ASSUAN_LINELENGTH];
 
901
  char *serialno = NULL;
 
902
 
 
903
  *r_serialno = NULL;
 
904
 
 
905
  err = start_agent (ctrl);
 
906
  if (err)
 
907
    return err;
 
908
 
 
909
  if (!hexkeygrip || strlen (hexkeygrip) != 40)
 
910
    return gpg_error (GPG_ERR_INV_VALUE);
 
911
 
 
912
  snprintf (line, DIM(line)-1, "KEYINFO %s", hexkeygrip);
 
913
  line[DIM(line)-1] = 0;
 
914
 
 
915
  err = assuan_transact (agent_ctx, line, NULL, NULL, NULL, NULL,
 
916
                         keyinfo_status_cb, &serialno);
 
917
  if (!err && serialno)
 
918
    {
 
919
      /* Sanity check for bad characters.  */
 
920
      if (strpbrk (serialno, ":\n\r"))
 
921
        err = GPG_ERR_INV_VALUE;
 
922
    }
 
923
  if (err)
 
924
    xfree (serialno);
 
925
  else
 
926
    *r_serialno = serialno;
 
927
  return err;
 
928
}
 
929