1
1
/* command.c - gpg-agent command handler
2
2
* Copyright (C) 2001, 2002, 2003, 2004, 2005,
3
* 2006, 2008 Free Software Foundation, Inc.
3
* 2006, 2008, 2009 Free Software Foundation, Inc.
5
5
* This file is part of GnuPG.
178
186
&& (!s[n] || spacep (s+n) || s[n] == '='));
189
/* Return a pointer to the argument of the option with NAME. If such
190
an option is not given, it returns NULL. */
192
option_value (const char *line, const char *name)
195
int n = strlen (name);
197
s = strstr (line, name);
198
if (s && (s == line || spacep (s-1))
199
&& s[n] && (spacep (s+n) || s[n] == '='))
202
s += strspn (s, " ");
203
if (*s && !spacep(s))
182
210
/* Skip over options. It is assumed that leading spaces have been
183
211
removed (this is the case for lines passed to a handler from
597
602
if (has_option (line, "--hash=sha1"))
598
603
algo = GCRY_MD_SHA1;
604
else if (has_option (line, "--hash=sha224"))
605
algo = GCRY_MD_SHA224;
599
606
else if (has_option (line, "--hash=sha256"))
600
607
algo = GCRY_MD_SHA256;
608
else if (has_option (line, "--hash=sha384"))
609
algo = GCRY_MD_SHA384;
610
else if (has_option (line, "--hash=sha512"))
611
algo = GCRY_MD_SHA512;
601
612
else if (has_option (line, "--hash=rmd160"))
602
613
algo = GCRY_MD_RMD160;
603
614
else if (has_option (line, "--hash=md5"))
822
/* KEYINFO [--list] <keygrip>
824
Return information about the key specified by the KEYGRIP. If the
825
key is not available GPG_ERR_NOT_FOUND is returned. If the option
826
--list is given the keygrip is ignored and information about all
827
available keys are returned. The information is returned as a
828
status line with this format:
830
KEYINFO <keygrip> <type> <serialno> <idstr>
832
KEYGRIP is the keygrip.
834
TYPE is describes the type of the key:
835
'D' - Regular key stored on disk,
836
'T' - Key is stored on a smartcard (token).
839
SERIALNO is an ASCII string with the serial number of the
840
smartcard. If the serial number is not known a single
841
dash '-' is used instead.
843
IDSTR is the IDSTR used to distinguish keys on a smartcard. If it
844
is not known a dash is used instead.
846
More information may be added in the future.
849
do_one_keyinfo (ctrl_t ctrl, const unsigned char *grip)
854
unsigned char *shadow_info = NULL;
855
char *serialno = NULL;
857
const char *keytypestr;
859
err = agent_key_info_from_file (ctrl, grip, &keytype, &shadow_info);
863
/* Reformat the grip so that we use uppercase as good style. */
864
bin2hex (grip, 20, hexgrip);
866
if (keytype == PRIVATE_KEY_CLEAR
867
|| keytype == PRIVATE_KEY_PROTECTED)
869
else if (keytype == PRIVATE_KEY_SHADOWED)
876
err = parse_shadow_info (shadow_info, &serialno, &idstr);
881
err = agent_write_status (ctrl, "KEYINFO",
884
serialno? serialno : "-",
896
cmd_keyinfo (assuan_context_t ctx, char *line)
898
ctrl_t ctrl = assuan_get_pointer (ctx);
900
unsigned char grip[20];
904
list_mode = has_option (line, "--list");
905
line = skip_options (line);
910
struct dirent *dir_entry;
913
dirname = make_filename_try (opt.homedir, GNUPG_PRIVATE_KEYS_DIR, NULL);
916
err = gpg_error_from_syserror ();
919
dir = opendir (dirname);
922
err = gpg_error_from_syserror ();
928
while ( (dir_entry = readdir (dir)) )
930
if (strlen (dir_entry->d_name) != 44
931
|| strcmp (dir_entry->d_name + 40, ".key"))
933
strncpy (hexgrip, dir_entry->d_name, 40);
936
if ( hex2bin (hexgrip, grip, 20) < 0 )
937
continue; /* Bad hex string. */
939
err = do_one_keyinfo (ctrl, grip);
947
err = parse_keygrip (ctx, line, grip);
950
err = do_one_keyinfo (ctrl, grip);
956
if (err && gpg_err_code (err) != GPG_ERR_NOT_FOUND)
957
log_error ("command keyinfo failed: %s\n", gpg_strerror (err));
869
1024
char *cacheid = NULL, *desc = NULL, *prompt = NULL, *errtext = NULL;
1025
const char *desc2 = _("Please re-enter this passphrase");
871
1027
void *cache_marker;
872
int opt_data, opt_check, opt_no_ask;
1028
int opt_data, opt_check, opt_no_ask, opt_qualbar;
1030
char *repeat_errtext = NULL;
874
1032
opt_data = has_option (line, "--data");
875
1033
opt_check = has_option (line, "--check");
876
1034
opt_no_ask = has_option (line, "--no-ask");
1035
if (has_option_name (line, "--repeat"))
1037
p = option_value (line, "--repeat");
1039
opt_repeat = atoi (p);
1043
opt_qualbar = has_option (line, "--qualitybar");
877
1044
line = skip_options (line);
941
1108
plus_to_blank (desc);
947
rc = agent_get_passphrase (ctrl, &response, desc, prompt, errtext);
951
&& check_passphrase_constraints (ctrl, response, 0));
1111
rc = agent_get_passphrase (ctrl, &response, desc, prompt,
1112
repeat_errtext? repeat_errtext:errtext,
1114
xfree (repeat_errtext);
1115
repeat_errtext = NULL;
956
agent_put_cache (cacheid, CACHE_MODE_USER, response, 0);
957
rc = send_back_passphrase (ctx, opt_data, response);
1120
if (opt_check && check_passphrase_constraints (ctrl, response, 0))
1125
for (i = 0; i < opt_repeat; i++)
1129
rc = agent_get_passphrase (ctrl, &response2, desc2, prompt,
1133
if (strcmp (response2, response))
1137
repeat_errtext = try_percent_escape
1138
(_("does not match - try again"), NULL);
1139
if (!repeat_errtext)
1141
rc = gpg_error_from_syserror ();
1151
agent_put_cache (cacheid, CACHE_MODE_USER, response, 0);
1152
rc = send_back_passphrase (ctx, opt_data, response);
958
1154
xfree (response);
1438
1638
rc = agent_scd_check_running ()? 0 : gpg_error (GPG_ERR_GENERAL);
1640
else if (!strncmp (line, "cmd_has_option", 14)
1641
&& (line[14] == ' ' || line[14] == '\t' || !line[14]))
1645
while (*line == ' ' || *line == '\t')
1648
rc = gpg_error (GPG_ERR_MISSING_VALUE);
1652
while (*line && (*line != ' ' && *line != '\t'))
1655
rc = gpg_error (GPG_ERR_MISSING_VALUE);
1659
while (*line == ' ' || *line == '\t')
1662
rc = gpg_error (GPG_ERR_MISSING_VALUE);
1666
if (!command_has_option (cmd, cmdopt))
1667
rc = gpg_error (GPG_ERR_GENERAL);
1441
1673
rc = set_error (GPG_ERR_ASS_PARAMETER, "unknown value for WHAT");
1574
1820
{ "GETEVENTCOUNTER",cmd_geteventcounter },
1575
1821
{ "ISTRUSTED", cmd_istrusted },
1576
1822
{ "HAVEKEY", cmd_havekey },
1823
{ "KEYINFO", cmd_keyinfo },
1577
1824
{ "SIGKEY", cmd_sigkey },
1578
1825
{ "SETKEY", cmd_sigkey },
1579
1826
{ "SETKEYDESC", cmd_setkeydesc },