diff options
author | Werner Koch <wk@gnupg.org> | 2002-01-29 11:05:05 +0100 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 2002-01-29 11:05:05 +0100 |
commit | 2d1d9d928c652f4d9fcab2d9d020c6225c16ee2c (patch) | |
tree | 9d6ced2631cee69c3f8e2dae8396c78ab3fc3a00 | |
parent | * certreqgen.c (create_request): Store the email address in the req. (diff) | |
download | gnupg2-2d1d9d928c652f4d9fcab2d9d020c6225c16ee2c.tar.xz gnupg2-2d1d9d928c652f4d9fcab2d9d020c6225c16ee2c.zip |
* findkey.c (agent_key_available): New.
* command.c (cmd_havekey): New.
(register_commands): And register new command.
-rw-r--r-- | agent/ChangeLog | 6 | ||||
-rw-r--r-- | agent/agent.h | 1 | ||||
-rw-r--r-- | agent/command.c | 32 | ||||
-rw-r--r-- | agent/findkey.c | 24 |
4 files changed, 60 insertions, 3 deletions
diff --git a/agent/ChangeLog b/agent/ChangeLog index 89aaa5401..9a42b4053 100644 --- a/agent/ChangeLog +++ b/agent/ChangeLog @@ -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. diff --git a/agent/agent.h b/agent/agent.h index 6db2f4b9c..d999bdad8 100644 --- a/agent/agent.h +++ b/agent/agent.h @@ -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); diff --git a/agent/command.c b/agent/command.c index 37276991c..bbcab8e7d 100644 --- a/agent/command.c +++ b/agent/command.c @@ -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 }, diff --git a/agent/findkey.c b/agent/findkey.c index 84af44f43..50f832be6 100644 --- a/agent/findkey.c +++ b/agent/findkey.c @@ -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; +} + |