From a2d1673d6622e39c41f061e1bffb5ca05c803320 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Mon, 25 Jul 2005 14:35:04 +0000 Subject: * findkey.c (agent_public_key_from_file): Fixed array assignment. This was the cause for random segvs. * call-agent.c (gpgsm_agent_readkey): New. --- sm/call-agent.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) (limited to 'sm/call-agent.c') diff --git a/sm/call-agent.c b/sm/call-agent.c index 92a29928c..c47f6b19a 100644 --- a/sm/call-agent.c +++ b/sm/call-agent.c @@ -1,5 +1,5 @@ /* call-agent.c - divert operations to the agent - * Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. + * Copyright (C) 2001, 2002, 2003, 2005 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -432,6 +432,51 @@ gpgsm_agent_genkey (ctrl_t ctrl, return 0; } + +/* Call the agent to read the public key part for a given keygrip. */ +int +gpgsm_agent_readkey (ctrl_t ctrl, const char *hexkeygrip, + ksba_sexp_t *r_pubkey) +{ + int rc; + membuf_t data; + size_t len; + unsigned char *buf; + char line[ASSUAN_LINELENGTH]; + + *r_pubkey = NULL; + rc = start_agent (ctrl); + if (rc) + return rc; + + rc = assuan_transact (agent_ctx, "RESET",NULL, NULL, NULL, NULL, NULL, NULL); + if (rc) + return map_assuan_err (rc); + + snprintf (line, DIM(line)-1, "READKEY %s", hexkeygrip); + line[DIM(line)-1] = 0; + + init_membuf (&data, 1024); + rc = assuan_transact (agent_ctx, line, + membuf_data_cb, &data, + NULL, NULL, NULL, NULL); + if (rc) + { + xfree (get_membuf (&data, &len)); + return map_assuan_err (rc); + } + buf = get_membuf (&data, &len); + if (!buf) + return gpg_error (GPG_ERR_ENOMEM); + if (!gcry_sexp_canon_len (buf, len, NULL, NULL)) + { + xfree (buf); + return gpg_error (GPG_ERR_INV_SEXP); + } + *r_pubkey = buf; + return 0; +} + /* Ask the agent whether the certificate is in the list of trusted keys */ -- cgit v1.2.3