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.
5
5
* This file is part of GnuPG.
633
633
return gpg_error (GPG_ERR_GENERAL);
635
snprintf (line, DIM(line)-1, "MARKTRUSTED %s S %s", fpr, dn);
635
dnfmt = gpgsm_format_name2 (dn, 0);
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;
640
644
rc = assuan_transact (agent_ctx, line, NULL, NULL,
675
learn_status_cb (void *opaque, const char *line)
677
struct learn_parm_s *parm = opaque;
679
/* Pass progress data to the caller. */
680
if (!strncmp (line, "PROGRESS", 8) && (line[8]==' ' || !line[8]))
684
for (line += 8; *line == ' '; line++)
686
if (gpgsm_status (parm->ctrl, STATUS_PROGRESS, line))
687
return gpg_error (GPG_ERR_ASS_CANCELED);
671
694
learn_cb (void *opaque, const void *buffer, size_t length)
673
696
struct learn_parm_s *parm = opaque;
718
if (gpgsm_status (parm->ctrl, STATUS_PROGRESS, "learncard C 0 0"))
719
return gpg_error (GPG_ERR_ASS_CANCELED);
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);
784
learn_status_cb, &learn_parm);
759
785
xfree (get_membuf (&data, &len));
867
keyinfo_status_cb (void *opaque, const char *line)
869
char **serialno = opaque;
872
if (!strncmp (line, "KEYINFO ", 8) && !*serialno)
874
s = strchr (line+8, ' ');
875
if (s && s[1] == 'T' && s[2] == ' ' && s[3])
878
s2 = strchr (s, ' ');
881
*serialno = xtrymalloc ((s2 - s)+1);
884
memcpy (*serialno, s, s2 - s);
885
(*serialno)[s2 - s] = 0;
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. */
897
gpgsm_agent_keyinfo (ctrl_t ctrl, const char *hexkeygrip, char **r_serialno)
900
char line[ASSUAN_LINELENGTH];
901
char *serialno = NULL;
905
err = start_agent (ctrl);
909
if (!hexkeygrip || strlen (hexkeygrip) != 40)
910
return gpg_error (GPG_ERR_INV_VALUE);
912
snprintf (line, DIM(line)-1, "KEYINFO %s", hexkeygrip);
913
line[DIM(line)-1] = 0;
915
err = assuan_transact (agent_ctx, line, NULL, NULL, NULL, NULL,
916
keyinfo_status_cb, &serialno);
917
if (!err && serialno)
919
/* Sanity check for bad characters. */
920
if (strpbrk (serialno, ":\n\r"))
921
err = GPG_ERR_INV_VALUE;
926
*r_serialno = serialno;