mirror of
git://git.gnupg.org/gnupg.git
synced 2024-12-31 11:41:32 +01:00
* findkey.c (agent_key_available): New.
* command.c (cmd_havekey): New. (register_commands): And register new command.
This commit is contained in:
parent
fc8d8e9987
commit
2d1d9d928c
@ -1,3 +1,9 @@
|
||||
2002-01-29 Werner Koch <wk@gnupg.org>
|
||||
|
||||
* findkey.c (agent_key_available): New.
|
||||
* command.c (cmd_havekey): New.
|
||||
(register_commands): And register new command.
|
||||
|
||||
2002-01-20 Werner Koch <wk@gnupg.org>
|
||||
|
||||
* command.c (cmd_get_passphrase): Remove the plus signs.
|
||||
|
@ -94,6 +94,7 @@ void start_command_handler (int);
|
||||
|
||||
/*-- findkey.c --*/
|
||||
GCRY_SEXP agent_key_from_file (const unsigned char *grip);
|
||||
int agent_key_available (const unsigned char *grip);
|
||||
|
||||
/*-- query.c --*/
|
||||
int agent_askpin (const char *desc_text, struct pin_entry_info_s *pininfo);
|
||||
|
@ -120,6 +120,37 @@ cmd_marktrusted (ASSUAN_CONTEXT ctx, char *line)
|
||||
|
||||
|
||||
|
||||
/* HAVEKEY <hexstring_with_keygrip>
|
||||
|
||||
Return success when the secret key is available */
|
||||
static int
|
||||
cmd_havekey (ASSUAN_CONTEXT ctx, char *line)
|
||||
{
|
||||
int n;
|
||||
char *p;
|
||||
unsigned char buf[20];
|
||||
|
||||
/* parse the hash value */
|
||||
for (p=line,n=0; hexdigitp (p); p++, n++)
|
||||
;
|
||||
if (*p)
|
||||
return set_error (Parameter_Error, "invalid hexstring");
|
||||
if ((n&1))
|
||||
return set_error (Parameter_Error, "odd number of digits");
|
||||
n /= 2;
|
||||
if (n != 20)
|
||||
return set_error (Parameter_Error, "invalid length of keygrip");
|
||||
|
||||
for (p=line, n=0; n < 20; p += 2, n++)
|
||||
buf[n] = xtoi_2 (p);
|
||||
|
||||
if (agent_key_available (buf))
|
||||
return ASSUAN_No_Secret_Key;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* SIGKEY <hexstring_with_keygrip>
|
||||
SETKEY <hexstring_with_keygrip>
|
||||
|
||||
@ -414,6 +445,7 @@ register_commands (ASSUAN_CONTEXT ctx)
|
||||
int (*handler)(ASSUAN_CONTEXT, char *line);
|
||||
} table[] = {
|
||||
{ "ISTRUSTED", 0, cmd_istrusted },
|
||||
{ "HAVEKEY", 0, cmd_havekey },
|
||||
{ "SIGKEY", 0, cmd_sigkey },
|
||||
{ "SETKEY", 0, cmd_sigkey },
|
||||
{ "SETHASH", 0, cmd_sethash },
|
||||
|
@ -55,9 +55,8 @@ unprotect (GCRY_SEXP s_skey)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* Return the secret key as an S-Exp after locating it using the grip. Returns NULL if key is not available. */
|
||||
/* Return the secret key as an S-Exp after locating it using the grip.
|
||||
Returns NULL if key is not available. */
|
||||
GCRY_SEXP
|
||||
agent_key_from_file (const unsigned char *grip)
|
||||
{
|
||||
@ -125,5 +124,24 @@ agent_key_from_file (const unsigned char *grip)
|
||||
return s_skey;
|
||||
}
|
||||
|
||||
/* Return the secret key as an S-Exp after locating it using the grip.
|
||||
Returns NULL if key is not available. 0 = key is available */
|
||||
int
|
||||
agent_key_available (const unsigned char *grip)
|
||||
{
|
||||
int i;
|
||||
char *fname;
|
||||
char hexgrip[41];
|
||||
|
||||
for (i=0; i < 20; i++)
|
||||
sprintf (hexgrip+2*i, "%02X", grip[i]);
|
||||
hexgrip[40] = 0;
|
||||
|
||||
fname = make_filename (opt.homedir, "private-keys-v1.d", hexgrip, NULL );
|
||||
i = !access (fname, R_OK)? 0 : -1;
|
||||
xfree (fname);
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user