2008-02-14 20:50:10 +01:00
|
|
|
|
/* call-agent.c - Divert GPGSM operations to the agent
|
|
|
|
|
* Copyright (C) 2001, 2002, 2003, 2005, 2007,
|
2010-06-17 17:44:44 +02:00
|
|
|
|
* 2008, 2009, 2010 Free Software Foundation, Inc.
|
2003-08-05 19:11:04 +02:00
|
|
|
|
*
|
|
|
|
|
* This file is part of GnuPG.
|
|
|
|
|
*
|
|
|
|
|
* GnuPG is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
2007-07-04 21:49:40 +02:00
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2003-08-05 19:11:04 +02:00
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* GnuPG is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2016-11-05 12:02:19 +01:00
|
|
|
|
* along with this program; if not, see <https://www.gnu.org/licenses/>.
|
2003-08-05 19:11:04 +02:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <errno.h>
|
2011-02-04 12:57:53 +01:00
|
|
|
|
#include <unistd.h>
|
2003-08-05 19:11:04 +02:00
|
|
|
|
#include <time.h>
|
|
|
|
|
#ifdef HAVE_LOCALE_H
|
|
|
|
|
#include <locale.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include "gpgsm.h"
|
|
|
|
|
#include <gcrypt.h>
|
|
|
|
|
#include <assuan.h>
|
2017-03-07 12:21:23 +01:00
|
|
|
|
#include "../common/i18n.h"
|
|
|
|
|
#include "../common/asshelp.h"
|
2003-08-05 19:11:04 +02:00
|
|
|
|
#include "keydb.h" /* fixme: Move this to import.c */
|
2017-03-07 12:21:23 +01:00
|
|
|
|
#include "../common/membuf.h"
|
|
|
|
|
#include "../common/shareddefs.h"
|
2016-03-07 18:09:41 +01:00
|
|
|
|
#include "passphrase.h"
|
2003-08-05 19:11:04 +02:00
|
|
|
|
|
|
|
|
|
|
2005-06-16 10:12:03 +02:00
|
|
|
|
static assuan_context_t agent_ctx = NULL;
|
2007-06-21 20:44:48 +02:00
|
|
|
|
|
2003-08-05 19:11:04 +02:00
|
|
|
|
|
2005-06-16 10:12:03 +02:00
|
|
|
|
struct cipher_parm_s
|
|
|
|
|
{
|
2008-02-14 20:50:10 +01:00
|
|
|
|
ctrl_t ctrl;
|
2005-06-16 10:12:03 +02:00
|
|
|
|
assuan_context_t ctx;
|
|
|
|
|
const unsigned char *ciphertext;
|
2003-08-05 19:11:04 +02:00
|
|
|
|
size_t ciphertextlen;
|
|
|
|
|
};
|
|
|
|
|
|
2005-06-16 10:12:03 +02:00
|
|
|
|
struct genkey_parm_s
|
|
|
|
|
{
|
2008-02-14 20:50:10 +01:00
|
|
|
|
ctrl_t ctrl;
|
2005-06-16 10:12:03 +02:00
|
|
|
|
assuan_context_t ctx;
|
|
|
|
|
const unsigned char *sexp;
|
2003-08-05 19:11:04 +02:00
|
|
|
|
size_t sexplen;
|
|
|
|
|
};
|
|
|
|
|
|
2005-06-16 10:12:03 +02:00
|
|
|
|
struct learn_parm_s
|
|
|
|
|
{
|
2003-08-05 19:11:04 +02:00
|
|
|
|
int error;
|
2008-02-13 17:47:14 +01:00
|
|
|
|
ctrl_t ctrl;
|
2005-06-16 10:12:03 +02:00
|
|
|
|
assuan_context_t ctx;
|
2003-08-05 19:11:04 +02:00
|
|
|
|
membuf_t *data;
|
|
|
|
|
};
|
|
|
|
|
|
2010-06-17 17:44:44 +02:00
|
|
|
|
struct import_key_parm_s
|
|
|
|
|
{
|
|
|
|
|
ctrl_t ctrl;
|
|
|
|
|
assuan_context_t ctx;
|
|
|
|
|
const void *key;
|
|
|
|
|
size_t keylen;
|
|
|
|
|
};
|
|
|
|
|
|
2020-05-18 19:32:30 +02:00
|
|
|
|
struct sethash_inq_parm_s
|
|
|
|
|
{
|
|
|
|
|
assuan_context_t ctx;
|
|
|
|
|
const void *data;
|
|
|
|
|
size_t datalen;
|
|
|
|
|
};
|
|
|
|
|
|
2016-03-07 18:09:41 +01:00
|
|
|
|
struct default_inq_parm_s
|
|
|
|
|
{
|
|
|
|
|
ctrl_t ctrl;
|
|
|
|
|
assuan_context_t ctx;
|
|
|
|
|
};
|
2003-08-05 19:11:04 +02:00
|
|
|
|
|
|
|
|
|
|
2016-01-08 10:33:19 +01:00
|
|
|
|
/* Print a warning if the server's version number is less than our
|
|
|
|
|
version number. Returns an error code on a connection problem. */
|
|
|
|
|
static gpg_error_t
|
|
|
|
|
warn_version_mismatch (ctrl_t ctrl, assuan_context_t ctx,
|
|
|
|
|
const char *servername, int mode)
|
|
|
|
|
{
|
2020-09-01 20:43:57 +02:00
|
|
|
|
return warn_server_version_mismatch (ctx, servername, mode,
|
|
|
|
|
gpgsm_status2, ctrl,
|
|
|
|
|
!opt.quiet);
|
2016-01-08 10:33:19 +01:00
|
|
|
|
}
|
|
|
|
|
|
2003-08-05 19:11:04 +02:00
|
|
|
|
/* Try to connect to the agent via socket or fork it off and work by
|
|
|
|
|
pipes. Handle the server's initial greeting */
|
|
|
|
|
static int
|
2004-04-26 15:29:09 +02:00
|
|
|
|
start_agent (ctrl_t ctrl)
|
2003-08-05 19:11:04 +02:00
|
|
|
|
{
|
2007-12-12 11:28:30 +01:00
|
|
|
|
int rc;
|
2007-06-21 20:44:48 +02:00
|
|
|
|
|
2007-12-12 11:28:30 +01:00
|
|
|
|
if (agent_ctx)
|
|
|
|
|
rc = 0; /* fixme: We need a context for each thread or
|
|
|
|
|
serialize the access to the agent (which is
|
|
|
|
|
suitable given that the agent is not MT. */
|
|
|
|
|
else
|
2008-02-14 20:50:10 +01:00
|
|
|
|
{
|
|
|
|
|
rc = start_new_gpg_agent (&agent_ctx,
|
|
|
|
|
GPG_ERR_SOURCE_DEFAULT,
|
|
|
|
|
opt.agent_program,
|
|
|
|
|
opt.lc_ctype, opt.lc_messages,
|
2009-07-07 12:02:41 +02:00
|
|
|
|
opt.session_env,
|
2023-08-29 13:18:13 +02:00
|
|
|
|
opt.autostart?ASSHELP_FLAG_AUTOSTART:0,
|
|
|
|
|
opt.verbose, DBG_IPC,
|
2008-02-14 20:50:10 +01:00
|
|
|
|
gpgsm_status2, ctrl);
|
2011-02-04 12:57:53 +01:00
|
|
|
|
|
2014-11-28 09:44:19 +01:00
|
|
|
|
if (!opt.autostart && gpg_err_code (rc) == GPG_ERR_NO_AGENT)
|
|
|
|
|
{
|
|
|
|
|
static int shown;
|
|
|
|
|
|
|
|
|
|
if (!shown)
|
|
|
|
|
{
|
|
|
|
|
shown = 1;
|
|
|
|
|
log_info (_("no gpg-agent running in this session\n"));
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-01-08 10:33:19 +01:00
|
|
|
|
else if (!rc && !(rc = warn_version_mismatch (ctrl, agent_ctx,
|
|
|
|
|
GPG_AGENT_NAME, 0)))
|
2008-02-14 20:50:10 +01:00
|
|
|
|
{
|
|
|
|
|
/* Tell the agent that we support Pinentry notifications. No
|
|
|
|
|
error checking so that it will work also with older
|
|
|
|
|
agents. */
|
|
|
|
|
assuan_transact (agent_ctx, "OPTION allow-pinentry-notify",
|
|
|
|
|
NULL, NULL, NULL, NULL, NULL, NULL);
|
2016-03-07 18:09:41 +01:00
|
|
|
|
|
|
|
|
|
/* Pass on the pinentry mode. */
|
|
|
|
|
if (opt.pinentry_mode)
|
|
|
|
|
{
|
|
|
|
|
char *tmp = xasprintf ("OPTION pinentry-mode=%s",
|
|
|
|
|
str_pinentry_mode (opt.pinentry_mode));
|
|
|
|
|
rc = assuan_transact (agent_ctx, tmp,
|
|
|
|
|
NULL, NULL, NULL, NULL, NULL, NULL);
|
|
|
|
|
xfree (tmp);
|
|
|
|
|
if (rc)
|
|
|
|
|
log_error ("setting pinentry mode '%s' failed: %s\n",
|
|
|
|
|
str_pinentry_mode (opt.pinentry_mode),
|
|
|
|
|
gpg_strerror (rc));
|
|
|
|
|
}
|
2017-07-17 15:52:26 +02:00
|
|
|
|
|
2018-03-23 09:06:20 +01:00
|
|
|
|
/* Pass on the request origin. */
|
|
|
|
|
if (opt.request_origin)
|
|
|
|
|
{
|
|
|
|
|
char *tmp = xasprintf ("OPTION pretend-request-origin=%s",
|
|
|
|
|
str_request_origin (opt.request_origin));
|
|
|
|
|
rc = assuan_transact (agent_ctx, tmp,
|
|
|
|
|
NULL, NULL, NULL, NULL, NULL, NULL);
|
|
|
|
|
xfree (tmp);
|
|
|
|
|
if (rc)
|
|
|
|
|
log_error ("setting request origin '%s' failed: %s\n",
|
|
|
|
|
str_request_origin (opt.request_origin),
|
|
|
|
|
gpg_strerror (rc));
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-17 15:52:26 +02:00
|
|
|
|
/* In DE_VS mode under Windows we require that the JENT RNG
|
|
|
|
|
* is active. */
|
|
|
|
|
#ifdef HAVE_W32_SYSTEM
|
|
|
|
|
if (!rc && opt.compliance == CO_DE_VS)
|
|
|
|
|
{
|
|
|
|
|
if (assuan_transact (agent_ctx, "GETINFO jent_active",
|
|
|
|
|
NULL, NULL, NULL, NULL, NULL, NULL))
|
|
|
|
|
{
|
|
|
|
|
rc = gpg_error (GPG_ERR_FORBIDDEN);
|
|
|
|
|
log_error (_("%s is not compliant with %s mode\n"),
|
|
|
|
|
GPG_AGENT_NAME,
|
|
|
|
|
gnupg_compliance_option_string (opt.compliance));
|
|
|
|
|
gpgsm_status_with_error (ctrl, STATUS_ERROR,
|
|
|
|
|
"random-compliance", rc);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif /*HAVE_W32_SYSTEM*/
|
|
|
|
|
|
2008-02-14 20:50:10 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-12-12 11:28:30 +01:00
|
|
|
|
if (!ctrl->agent_seen)
|
|
|
|
|
{
|
|
|
|
|
ctrl->agent_seen = 1;
|
|
|
|
|
audit_log_ok (ctrl->audit, AUDIT_AGENT_READY, rc);
|
|
|
|
|
}
|
2007-06-21 20:44:48 +02:00
|
|
|
|
|
2007-12-12 11:28:30 +01:00
|
|
|
|
return rc;
|
2003-08-05 19:11:04 +02:00
|
|
|
|
}
|
|
|
|
|
|
2008-02-14 20:50:10 +01:00
|
|
|
|
/* This is the default inquiry callback. It mainly handles the
|
|
|
|
|
Pinentry notifications. */
|
agent/
2009-11-02 Marcus Brinkmann <marcus@g10code.de>
* command.c (reset_notify): Take LINE arg and return error.
(register_commands): Use assuan_handler_t type.
common/
2009-11-02 Marcus Brinkmann <marcus@g10code.de>
* get-passphrase.c (default_inq_cb, membuf_data_cb): Change return
type to gpg_error_t.
g10/
2009-11-02 Marcus Brinkmann <marcus@g10code.de>
* server.c (reset_notify, input_notify, output_notify): Update to
new assuan interface.
(register_commands): Use assuan_handler_t.
scd/
2009-11-02 Marcus Brinkmann <marcus@g10code.de>
* command.c (reset_notify): Take LINE arg and return error.
(register_commands): Use assuan_handler_t type.
sm/
2009-11-02 Marcus Brinkmann <marcus@g10code.de>
* server.c (reset_notify, input_notify, output_notify): Update to
new assuan interface.
(register_commands): Use assuan_handler_t.
* call-agent.c (membuf_data_cb, default_inq_cb)
(inq_ciphertext_cb, scd_serialno_status_cb)
(scd_keypairinfo_status_cb, istrusted_status_cb)
(learn_status_cb, learn_cb, keyinfo_status_cb): Return gpg_error_t.
2009-11-02 18:47:11 +01:00
|
|
|
|
static gpg_error_t
|
2008-02-14 20:50:10 +01:00
|
|
|
|
default_inq_cb (void *opaque, const char *line)
|
|
|
|
|
{
|
2016-03-07 18:09:41 +01:00
|
|
|
|
gpg_error_t err = 0;
|
|
|
|
|
struct default_inq_parm_s *parm = opaque;
|
|
|
|
|
ctrl_t ctrl = parm->ctrl;
|
2008-02-14 20:50:10 +01:00
|
|
|
|
|
Use has_leading_keyword in the assuan callbacks.
* agent/call-pinentry.c (inq_quality): Use has_leading_keyword.
* agent/call-scd.c (inq_needpin, inq_writekey_parms): Ditto.
* g10/call-agent.c (inq_writecert_parms, keyinfo_status_cb): Ditto.
(inq_genkey_parms, inq_ciphertext_cb, inq_import_key_parms): Ditto.
* g10/call-dirmngr.c (ks_put_inq_cb): Ditto.
* sm/call-agent.c (default_inq_cb, inq_ciphertext_cb): Ditto.
(inq_genkey_parms, istrusted_status_cb, learn_status_cb): Ditto.
(keyinfo_status_cb, inq_import_key_parms): Ditto.
* sm/call-dirmngr.c (inq_certificate, isvalid_status_cb): Ditto.
(lookup_status_cb, run_command_inq_cb, run_command_status_cb): Ditto.
2013-02-22 10:56:13 +01:00
|
|
|
|
if (has_leading_keyword (line, "PINENTRY_LAUNCHED"))
|
2008-02-14 20:50:10 +01:00
|
|
|
|
{
|
|
|
|
|
err = gpgsm_proxy_pinentry_notify (ctrl, line);
|
|
|
|
|
if (err)
|
2011-02-04 12:57:53 +01:00
|
|
|
|
log_error (_("failed to proxy %s inquiry to client\n"),
|
2008-02-14 20:50:10 +01:00
|
|
|
|
"PINENTRY_LAUNCHED");
|
|
|
|
|
/* We do not pass errors to avoid breaking other code. */
|
|
|
|
|
}
|
2016-03-07 18:09:41 +01:00
|
|
|
|
else if ((has_leading_keyword (line, "PASSPHRASE")
|
|
|
|
|
|| has_leading_keyword (line, "NEW_PASSPHRASE"))
|
|
|
|
|
&& opt.pinentry_mode == PINENTRY_MODE_LOOPBACK
|
|
|
|
|
&& have_static_passphrase ())
|
|
|
|
|
{
|
|
|
|
|
const char *s = get_static_passphrase ();
|
2023-11-09 05:36:12 +01:00
|
|
|
|
assuan_begin_confidential (parm->ctx);
|
2016-03-07 18:09:41 +01:00
|
|
|
|
err = assuan_send_data (parm->ctx, s, strlen (s));
|
2023-11-09 05:36:12 +01:00
|
|
|
|
assuan_end_confidential (parm->ctx);
|
2016-03-07 18:09:41 +01:00
|
|
|
|
}
|
2008-02-14 20:50:10 +01:00
|
|
|
|
else
|
2012-06-05 19:29:22 +02:00
|
|
|
|
log_error ("ignoring gpg-agent inquiry '%s'\n", line);
|
2008-02-14 20:50:10 +01:00
|
|
|
|
|
2016-03-07 18:09:41 +01:00
|
|
|
|
return err;
|
2008-02-14 20:50:10 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-05 19:11:04 +02:00
|
|
|
|
|
|
|
|
|
|
2020-05-18 19:32:30 +02:00
|
|
|
|
/* This is the inquiry callback required by the SETHASH command. */
|
|
|
|
|
static gpg_error_t
|
|
|
|
|
sethash_inq_cb (void *opaque, const char *line)
|
|
|
|
|
{
|
|
|
|
|
gpg_error_t err = 0;
|
|
|
|
|
struct sethash_inq_parm_s *parm = opaque;
|
|
|
|
|
|
|
|
|
|
if (has_leading_keyword (line, "TBSDATA"))
|
|
|
|
|
{
|
|
|
|
|
err = assuan_send_data (parm->ctx, parm->data, parm->datalen);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
log_error ("ignoring gpg-agent inquiry '%s'\n", line);
|
|
|
|
|
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-05 19:11:04 +02:00
|
|
|
|
/* Call the agent to do a sign operation using the key identified by
|
2020-05-18 19:32:30 +02:00
|
|
|
|
* the hex string KEYGRIP. If DIGESTALGO is given (DIGEST,DIGESTLEN)
|
|
|
|
|
* gives the to be signed hash created using the given algo. If
|
|
|
|
|
* DIGESTALGO is not given (i.e. zero) (DIGEST,DIGESTALGO) give the
|
|
|
|
|
* entire data to-be-signed. */
|
2003-08-05 19:11:04 +02:00
|
|
|
|
int
|
2004-04-26 15:29:09 +02:00
|
|
|
|
gpgsm_agent_pksign (ctrl_t ctrl, const char *keygrip, const char *desc,
|
2003-08-05 19:11:04 +02:00
|
|
|
|
unsigned char *digest, size_t digestlen, int digestalgo,
|
2005-06-16 10:12:03 +02:00
|
|
|
|
unsigned char **r_buf, size_t *r_buflen )
|
2003-08-05 19:11:04 +02:00
|
|
|
|
{
|
|
|
|
|
int rc, i;
|
|
|
|
|
char *p, line[ASSUAN_LINELENGTH];
|
|
|
|
|
membuf_t data;
|
|
|
|
|
size_t len;
|
2016-09-27 07:45:21 +02:00
|
|
|
|
struct default_inq_parm_s inq_parm;
|
2003-08-05 19:11:04 +02:00
|
|
|
|
|
|
|
|
|
*r_buf = NULL;
|
2004-04-26 15:29:09 +02:00
|
|
|
|
rc = start_agent (ctrl);
|
2003-08-05 19:11:04 +02:00
|
|
|
|
if (rc)
|
|
|
|
|
return rc;
|
2016-12-16 15:50:17 +01:00
|
|
|
|
inq_parm.ctrl = ctrl;
|
2016-09-27 07:45:21 +02:00
|
|
|
|
inq_parm.ctx = agent_ctx;
|
2003-08-05 19:11:04 +02:00
|
|
|
|
|
2020-05-18 19:32:30 +02:00
|
|
|
|
if (digestalgo && digestlen*2 + 50 > DIM(line))
|
2003-08-05 19:11:04 +02:00
|
|
|
|
return gpg_error (GPG_ERR_GENERAL);
|
|
|
|
|
|
|
|
|
|
rc = assuan_transact (agent_ctx, "RESET", NULL, NULL, NULL, NULL, NULL, NULL);
|
|
|
|
|
if (rc)
|
2006-09-06 18:35:52 +02:00
|
|
|
|
return rc;
|
2003-08-05 19:11:04 +02:00
|
|
|
|
|
Fix use cases of snprintf.
* agent/call-pinentry.c, agent/call-scd.c, agent/command.c,
build-aux/speedo/w32/g4wihelp.c, common/get-passphrase.c,
dirmngr/dirmngr.c, g10/call-agent.c, g10/cpr.c, g10/keygen.c,
g10/openfile.c, g10/passphrase.c, scd/app-openpgp.c, scd/scdaemon.c,
sm/call-agent.c, sm/call-dirmngr.c, sm/certreqgen.c: Fix assuming C99.
--
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2016-10-21 05:04:46 +02:00
|
|
|
|
snprintf (line, DIM(line), "SIGKEY %s", keygrip);
|
2003-08-05 19:11:04 +02:00
|
|
|
|
rc = assuan_transact (agent_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL);
|
|
|
|
|
if (rc)
|
2006-09-06 18:35:52 +02:00
|
|
|
|
return rc;
|
2003-08-05 19:11:04 +02:00
|
|
|
|
|
2004-02-13 18:06:50 +01:00
|
|
|
|
if (desc)
|
|
|
|
|
{
|
Fix use cases of snprintf.
* agent/call-pinentry.c, agent/call-scd.c, agent/command.c,
build-aux/speedo/w32/g4wihelp.c, common/get-passphrase.c,
dirmngr/dirmngr.c, g10/call-agent.c, g10/cpr.c, g10/keygen.c,
g10/openfile.c, g10/passphrase.c, scd/app-openpgp.c, scd/scdaemon.c,
sm/call-agent.c, sm/call-dirmngr.c, sm/certreqgen.c: Fix assuming C99.
--
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2016-10-21 05:04:46 +02:00
|
|
|
|
snprintf (line, DIM(line), "SETKEYDESC %s", desc);
|
2004-02-13 18:06:50 +01:00
|
|
|
|
rc = assuan_transact (agent_ctx, line,
|
|
|
|
|
NULL, NULL, NULL, NULL, NULL, NULL);
|
|
|
|
|
if (rc)
|
2006-09-06 18:35:52 +02:00
|
|
|
|
return rc;
|
2004-02-13 18:06:50 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-18 19:32:30 +02:00
|
|
|
|
if (!digestalgo)
|
|
|
|
|
{
|
|
|
|
|
struct sethash_inq_parm_s sethash_inq_parm;
|
|
|
|
|
|
|
|
|
|
sethash_inq_parm.ctx = agent_ctx;
|
|
|
|
|
sethash_inq_parm.data = digest;
|
|
|
|
|
sethash_inq_parm.datalen = digestlen;
|
|
|
|
|
rc = assuan_transact (agent_ctx, "SETHASH --inquire",
|
|
|
|
|
NULL, NULL, sethash_inq_cb, &sethash_inq_parm,
|
|
|
|
|
NULL, NULL);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
snprintf (line, sizeof line, "SETHASH %d ", digestalgo);
|
|
|
|
|
p = line + strlen (line);
|
|
|
|
|
for (i=0; i < digestlen ; i++, p += 2 )
|
|
|
|
|
sprintf (p, "%02X", digest[i]);
|
|
|
|
|
rc = assuan_transact (agent_ctx, line,
|
|
|
|
|
NULL, NULL, NULL, NULL, NULL, NULL);
|
|
|
|
|
}
|
2003-08-05 19:11:04 +02:00
|
|
|
|
if (rc)
|
2006-09-06 18:35:52 +02:00
|
|
|
|
return rc;
|
2003-08-05 19:11:04 +02:00
|
|
|
|
|
|
|
|
|
init_membuf (&data, 1024);
|
|
|
|
|
rc = assuan_transact (agent_ctx, "PKSIGN",
|
2016-03-07 18:09:41 +01:00
|
|
|
|
put_membuf_cb, &data, default_inq_cb, &inq_parm,
|
2008-02-14 20:50:10 +01:00
|
|
|
|
NULL, NULL);
|
2003-08-05 19:11:04 +02:00
|
|
|
|
if (rc)
|
|
|
|
|
{
|
|
|
|
|
xfree (get_membuf (&data, &len));
|
2006-09-06 18:35:52 +02:00
|
|
|
|
return rc;
|
2003-08-05 19:11:04 +02:00
|
|
|
|
}
|
|
|
|
|
*r_buf = get_membuf (&data, r_buflen);
|
|
|
|
|
|
|
|
|
|
if (!gcry_sexp_canon_len (*r_buf, *r_buflen, NULL, NULL))
|
|
|
|
|
{
|
|
|
|
|
xfree (*r_buf); *r_buf = NULL;
|
|
|
|
|
return gpg_error (GPG_ERR_INV_VALUE);
|
|
|
|
|
}
|
|
|
|
|
|
2006-09-06 18:35:52 +02:00
|
|
|
|
return *r_buf? 0 : out_of_core ();
|
2003-08-05 19:11:04 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-11 19:52:15 +02:00
|
|
|
|
/* Call the scdaemon to do a sign operation using the key identified by
|
|
|
|
|
the hex string KEYID. */
|
|
|
|
|
int
|
|
|
|
|
gpgsm_scd_pksign (ctrl_t ctrl, const char *keyid, const char *desc,
|
|
|
|
|
unsigned char *digest, size_t digestlen, int digestalgo,
|
|
|
|
|
unsigned char **r_buf, size_t *r_buflen )
|
|
|
|
|
{
|
2018-11-16 02:27:37 +01:00
|
|
|
|
int rc, i, pkalgo;
|
2006-10-11 19:52:15 +02:00
|
|
|
|
char *p, line[ASSUAN_LINELENGTH];
|
|
|
|
|
membuf_t data;
|
|
|
|
|
size_t len;
|
|
|
|
|
const char *hashopt;
|
|
|
|
|
unsigned char *sigbuf;
|
|
|
|
|
size_t sigbuflen;
|
2016-09-27 07:45:21 +02:00
|
|
|
|
struct default_inq_parm_s inq_parm;
|
2018-11-16 02:27:37 +01:00
|
|
|
|
gcry_sexp_t sig;
|
2006-10-11 19:52:15 +02:00
|
|
|
|
|
2008-10-20 15:53:23 +02:00
|
|
|
|
(void)desc;
|
|
|
|
|
|
2006-10-11 19:52:15 +02:00
|
|
|
|
*r_buf = NULL;
|
|
|
|
|
|
|
|
|
|
switch(digestalgo)
|
|
|
|
|
{
|
|
|
|
|
case GCRY_MD_SHA1: hashopt = "--hash=sha1"; break;
|
|
|
|
|
case GCRY_MD_RMD160:hashopt = "--hash=rmd160"; break;
|
|
|
|
|
case GCRY_MD_MD5: hashopt = "--hash=md5"; break;
|
|
|
|
|
case GCRY_MD_SHA256:hashopt = "--hash=sha256"; break;
|
2019-02-17 18:40:51 +01:00
|
|
|
|
case GCRY_MD_SHA512:hashopt = "--hash=sha512"; break;
|
2011-02-04 12:57:53 +01:00
|
|
|
|
default:
|
2006-10-11 19:52:15 +02:00
|
|
|
|
return gpg_error (GPG_ERR_DIGEST_ALGO);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rc = start_agent (ctrl);
|
|
|
|
|
if (rc)
|
|
|
|
|
return rc;
|
2016-12-16 15:50:17 +01:00
|
|
|
|
inq_parm.ctrl = ctrl;
|
2016-09-27 07:45:21 +02:00
|
|
|
|
inq_parm.ctx = agent_ctx;
|
2006-10-11 19:52:15 +02:00
|
|
|
|
|
|
|
|
|
if (digestlen*2 + 50 > DIM(line))
|
|
|
|
|
return gpg_error (GPG_ERR_GENERAL);
|
|
|
|
|
|
2018-11-16 02:27:37 +01:00
|
|
|
|
/* Get the key type from the scdaemon. */
|
|
|
|
|
snprintf (line, DIM(line), "SCD READKEY %s", keyid);
|
|
|
|
|
init_membuf (&data, 1024);
|
|
|
|
|
rc = assuan_transact (agent_ctx, line,
|
|
|
|
|
put_membuf_cb, &data, NULL, NULL, NULL, NULL);
|
|
|
|
|
if (rc)
|
|
|
|
|
{
|
|
|
|
|
xfree (get_membuf (&data, &len));
|
|
|
|
|
return rc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
p = get_membuf (&data, &len);
|
|
|
|
|
pkalgo = get_pk_algo_from_canon_sexp (p, len);
|
|
|
|
|
xfree (p);
|
|
|
|
|
if (!pkalgo)
|
|
|
|
|
return gpg_error (GPG_ERR_WRONG_PUBKEY_ALGO);
|
|
|
|
|
|
2006-10-11 19:52:15 +02:00
|
|
|
|
p = stpcpy (line, "SCD SETDATA " );
|
|
|
|
|
for (i=0; i < digestlen ; i++, p += 2 )
|
|
|
|
|
sprintf (p, "%02X", digest[i]);
|
|
|
|
|
rc = assuan_transact (agent_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL);
|
|
|
|
|
if (rc)
|
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
|
|
init_membuf (&data, 1024);
|
|
|
|
|
|
Fix use cases of snprintf.
* agent/call-pinentry.c, agent/call-scd.c, agent/command.c,
build-aux/speedo/w32/g4wihelp.c, common/get-passphrase.c,
dirmngr/dirmngr.c, g10/call-agent.c, g10/cpr.c, g10/keygen.c,
g10/openfile.c, g10/passphrase.c, scd/app-openpgp.c, scd/scdaemon.c,
sm/call-agent.c, sm/call-dirmngr.c, sm/certreqgen.c: Fix assuming C99.
--
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2016-10-21 05:04:46 +02:00
|
|
|
|
snprintf (line, DIM(line), "SCD PKSIGN %s %s", hashopt, keyid);
|
2006-10-11 19:52:15 +02:00
|
|
|
|
rc = assuan_transact (agent_ctx, line,
|
2016-03-07 18:09:41 +01:00
|
|
|
|
put_membuf_cb, &data, default_inq_cb, &inq_parm,
|
2008-02-14 20:50:10 +01:00
|
|
|
|
NULL, NULL);
|
2006-10-11 19:52:15 +02:00
|
|
|
|
if (rc)
|
|
|
|
|
{
|
|
|
|
|
xfree (get_membuf (&data, &len));
|
|
|
|
|
return rc;
|
|
|
|
|
}
|
|
|
|
|
sigbuf = get_membuf (&data, &sigbuflen);
|
|
|
|
|
|
2018-11-16 02:27:37 +01:00
|
|
|
|
switch(pkalgo)
|
2006-10-11 19:52:15 +02:00
|
|
|
|
{
|
2018-11-16 02:27:37 +01:00
|
|
|
|
case GCRY_PK_RSA:
|
|
|
|
|
rc = gcry_sexp_build (&sig, NULL, "(sig-val(rsa(s%b)))",
|
2019-07-09 09:59:56 +02:00
|
|
|
|
(int)sigbuflen, sigbuf);
|
2018-11-16 02:27:37 +01:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GCRY_PK_ECC:
|
|
|
|
|
rc = gcry_sexp_build (&sig, NULL, "(sig-val(ecdsa(r%b)(s%b)))",
|
2019-07-09 09:59:56 +02:00
|
|
|
|
(int)sigbuflen/2, sigbuf,
|
|
|
|
|
(int)sigbuflen/2, sigbuf + sigbuflen/2);
|
2018-11-16 02:27:37 +01:00
|
|
|
|
break;
|
|
|
|
|
|
2019-02-17 18:40:51 +01:00
|
|
|
|
case GCRY_PK_EDDSA:
|
|
|
|
|
rc = gcry_sexp_build (&sig, NULL, "(sig-val(eddsa(r%b)(s%b)))",
|
2019-07-09 09:59:56 +02:00
|
|
|
|
(int)sigbuflen/2, sigbuf,
|
|
|
|
|
(int)sigbuflen/2, sigbuf + sigbuflen/2);
|
2019-02-17 18:40:51 +01:00
|
|
|
|
break;
|
|
|
|
|
|
2018-11-16 02:27:37 +01:00
|
|
|
|
default:
|
|
|
|
|
rc = gpg_error (GPG_ERR_WRONG_PUBKEY_ALGO);
|
|
|
|
|
break;
|
2006-10-11 19:52:15 +02:00
|
|
|
|
}
|
|
|
|
|
xfree (sigbuf);
|
2018-11-16 02:27:37 +01:00
|
|
|
|
if (rc)
|
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
|
|
rc = make_canon_sexp (sig, r_buf, r_buflen);
|
|
|
|
|
gcry_sexp_release (sig);
|
|
|
|
|
if (rc)
|
|
|
|
|
return rc;
|
2006-10-11 19:52:15 +02:00
|
|
|
|
|
2020-07-08 14:40:34 +02:00
|
|
|
|
log_assert (gcry_sexp_canon_len (*r_buf, *r_buflen, NULL, NULL));
|
2006-10-11 19:52:15 +02:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-05 19:11:04 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Handle a CIPHERTEXT inquiry. Note, we only send the data,
|
2010-04-23 13:36:59 +02:00
|
|
|
|
assuan_transact takes care of flushing and writing the end */
|
agent/
2009-11-02 Marcus Brinkmann <marcus@g10code.de>
* command.c (reset_notify): Take LINE arg and return error.
(register_commands): Use assuan_handler_t type.
common/
2009-11-02 Marcus Brinkmann <marcus@g10code.de>
* get-passphrase.c (default_inq_cb, membuf_data_cb): Change return
type to gpg_error_t.
g10/
2009-11-02 Marcus Brinkmann <marcus@g10code.de>
* server.c (reset_notify, input_notify, output_notify): Update to
new assuan interface.
(register_commands): Use assuan_handler_t.
scd/
2009-11-02 Marcus Brinkmann <marcus@g10code.de>
* command.c (reset_notify): Take LINE arg and return error.
(register_commands): Use assuan_handler_t type.
sm/
2009-11-02 Marcus Brinkmann <marcus@g10code.de>
* server.c (reset_notify, input_notify, output_notify): Update to
new assuan interface.
(register_commands): Use assuan_handler_t.
* call-agent.c (membuf_data_cb, default_inq_cb)
(inq_ciphertext_cb, scd_serialno_status_cb)
(scd_keypairinfo_status_cb, istrusted_status_cb)
(learn_status_cb, learn_cb, keyinfo_status_cb): Return gpg_error_t.
2009-11-02 18:47:11 +01:00
|
|
|
|
static gpg_error_t
|
2008-02-14 20:50:10 +01:00
|
|
|
|
inq_ciphertext_cb (void *opaque, const char *line)
|
2003-08-05 19:11:04 +02:00
|
|
|
|
{
|
2011-02-04 12:57:53 +01:00
|
|
|
|
struct cipher_parm_s *parm = opaque;
|
2006-09-06 18:35:52 +02:00
|
|
|
|
int rc;
|
2003-08-05 19:11:04 +02:00
|
|
|
|
|
Use has_leading_keyword in the assuan callbacks.
* agent/call-pinentry.c (inq_quality): Use has_leading_keyword.
* agent/call-scd.c (inq_needpin, inq_writekey_parms): Ditto.
* g10/call-agent.c (inq_writecert_parms, keyinfo_status_cb): Ditto.
(inq_genkey_parms, inq_ciphertext_cb, inq_import_key_parms): Ditto.
* g10/call-dirmngr.c (ks_put_inq_cb): Ditto.
* sm/call-agent.c (default_inq_cb, inq_ciphertext_cb): Ditto.
(inq_genkey_parms, istrusted_status_cb, learn_status_cb): Ditto.
(keyinfo_status_cb, inq_import_key_parms): Ditto.
* sm/call-dirmngr.c (inq_certificate, isvalid_status_cb): Ditto.
(lookup_status_cb, run_command_inq_cb, run_command_status_cb): Ditto.
2013-02-22 10:56:13 +01:00
|
|
|
|
if (has_leading_keyword (line, "CIPHERTEXT"))
|
2008-02-14 20:50:10 +01:00
|
|
|
|
{
|
|
|
|
|
assuan_begin_confidential (parm->ctx);
|
|
|
|
|
rc = assuan_send_data (parm->ctx, parm->ciphertext, parm->ciphertextlen);
|
|
|
|
|
assuan_end_confidential (parm->ctx);
|
|
|
|
|
}
|
|
|
|
|
else
|
2016-03-07 18:09:41 +01:00
|
|
|
|
{
|
|
|
|
|
struct default_inq_parm_s inq_parm = { parm->ctrl, parm->ctx };
|
|
|
|
|
rc = default_inq_cb (&inq_parm, line);
|
|
|
|
|
}
|
2008-02-14 20:50:10 +01:00
|
|
|
|
|
2011-02-04 12:57:53 +01:00
|
|
|
|
return rc;
|
2003-08-05 19:11:04 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Call the agent to do a decrypt operation using the key identified by
|
|
|
|
|
the hex string KEYGRIP. */
|
|
|
|
|
int
|
2004-04-26 15:29:09 +02:00
|
|
|
|
gpgsm_agent_pkdecrypt (ctrl_t ctrl, const char *keygrip, const char *desc,
|
2011-02-04 12:57:53 +01:00
|
|
|
|
ksba_const_sexp_t ciphertext,
|
2003-08-05 19:11:04 +02:00
|
|
|
|
char **r_buf, size_t *r_buflen )
|
|
|
|
|
{
|
|
|
|
|
int rc;
|
|
|
|
|
char line[ASSUAN_LINELENGTH];
|
2019-07-23 16:07:17 +02:00
|
|
|
|
membuf_t data;
|
2003-08-05 19:11:04 +02:00
|
|
|
|
struct cipher_parm_s cipher_parm;
|
|
|
|
|
size_t n, len;
|
2006-08-29 18:18:30 +02:00
|
|
|
|
char *p, *buf, *endp;
|
2003-08-05 19:11:04 +02:00
|
|
|
|
size_t ciphertextlen;
|
2011-02-04 12:57:53 +01:00
|
|
|
|
|
2003-08-05 19:11:04 +02:00
|
|
|
|
if (!keygrip || strlen(keygrip) != 40 || !ciphertext || !r_buf || !r_buflen)
|
|
|
|
|
return gpg_error (GPG_ERR_INV_VALUE);
|
|
|
|
|
*r_buf = NULL;
|
|
|
|
|
|
|
|
|
|
ciphertextlen = gcry_sexp_canon_len (ciphertext, 0, NULL, NULL);
|
|
|
|
|
if (!ciphertextlen)
|
|
|
|
|
return gpg_error (GPG_ERR_INV_VALUE);
|
|
|
|
|
|
2004-04-26 15:29:09 +02:00
|
|
|
|
rc = start_agent (ctrl);
|
2003-08-05 19:11:04 +02:00
|
|
|
|
if (rc)
|
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
|
|
rc = assuan_transact (agent_ctx, "RESET", NULL, NULL, NULL, NULL, NULL, NULL);
|
|
|
|
|
if (rc)
|
2006-09-06 18:35:52 +02:00
|
|
|
|
return rc;
|
2003-08-05 19:11:04 +02:00
|
|
|
|
|
2020-07-08 14:40:34 +02:00
|
|
|
|
log_assert ( DIM(line) >= 50 );
|
Fix use cases of snprintf.
* agent/call-pinentry.c, agent/call-scd.c, agent/command.c,
build-aux/speedo/w32/g4wihelp.c, common/get-passphrase.c,
dirmngr/dirmngr.c, g10/call-agent.c, g10/cpr.c, g10/keygen.c,
g10/openfile.c, g10/passphrase.c, scd/app-openpgp.c, scd/scdaemon.c,
sm/call-agent.c, sm/call-dirmngr.c, sm/certreqgen.c: Fix assuming C99.
--
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2016-10-21 05:04:46 +02:00
|
|
|
|
snprintf (line, DIM(line), "SETKEY %s", keygrip);
|
2003-08-05 19:11:04 +02:00
|
|
|
|
rc = assuan_transact (agent_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL);
|
|
|
|
|
if (rc)
|
2006-09-06 18:35:52 +02:00
|
|
|
|
return rc;
|
2003-08-05 19:11:04 +02:00
|
|
|
|
|
2004-02-13 18:06:50 +01:00
|
|
|
|
if (desc)
|
|
|
|
|
{
|
Fix use cases of snprintf.
* agent/call-pinentry.c, agent/call-scd.c, agent/command.c,
build-aux/speedo/w32/g4wihelp.c, common/get-passphrase.c,
dirmngr/dirmngr.c, g10/call-agent.c, g10/cpr.c, g10/keygen.c,
g10/openfile.c, g10/passphrase.c, scd/app-openpgp.c, scd/scdaemon.c,
sm/call-agent.c, sm/call-dirmngr.c, sm/certreqgen.c: Fix assuming C99.
--
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2016-10-21 05:04:46 +02:00
|
|
|
|
snprintf (line, DIM(line), "SETKEYDESC %s", desc);
|
2004-02-13 18:06:50 +01:00
|
|
|
|
rc = assuan_transact (agent_ctx, line,
|
|
|
|
|
NULL, NULL, NULL, NULL, NULL, NULL);
|
|
|
|
|
if (rc)
|
2006-09-06 18:35:52 +02:00
|
|
|
|
return rc;
|
2004-02-13 18:06:50 +01:00
|
|
|
|
}
|
|
|
|
|
|
2003-08-05 19:11:04 +02:00
|
|
|
|
init_membuf (&data, 1024);
|
2008-02-14 20:50:10 +01:00
|
|
|
|
cipher_parm.ctrl = ctrl;
|
2003-08-05 19:11:04 +02:00
|
|
|
|
cipher_parm.ctx = agent_ctx;
|
|
|
|
|
cipher_parm.ciphertext = ciphertext;
|
|
|
|
|
cipher_parm.ciphertextlen = ciphertextlen;
|
|
|
|
|
rc = assuan_transact (agent_ctx, "PKDECRYPT",
|
2016-01-08 06:33:27 +01:00
|
|
|
|
put_membuf_cb, &data,
|
2003-08-05 19:11:04 +02:00
|
|
|
|
inq_ciphertext_cb, &cipher_parm, NULL, NULL);
|
|
|
|
|
if (rc)
|
|
|
|
|
{
|
|
|
|
|
xfree (get_membuf (&data, &len));
|
2006-09-06 18:35:52 +02:00
|
|
|
|
return rc;
|
2003-08-05 19:11:04 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-26 03:00:31 +02:00
|
|
|
|
/* Make sure it is 0 terminated so we can invoke strtoul safely. */
|
|
|
|
|
put_membuf (&data, "", 1);
|
2003-08-05 19:11:04 +02:00
|
|
|
|
buf = get_membuf (&data, &len);
|
|
|
|
|
if (!buf)
|
|
|
|
|
return gpg_error (GPG_ERR_ENOMEM);
|
2020-04-23 10:00:18 +02:00
|
|
|
|
log_assert (len); /* (we forced Nul termination.) */
|
2006-08-29 18:18:30 +02:00
|
|
|
|
|
|
|
|
|
if (*buf == '(')
|
|
|
|
|
{
|
|
|
|
|
if (len < 13 || memcmp (buf, "(5:value", 8) ) /* "(5:valueN:D)\0" */
|
|
|
|
|
return gpg_error (GPG_ERR_INV_SEXP);
|
2019-07-23 16:07:17 +02:00
|
|
|
|
/* Trim any spurious trailing Nuls: */
|
|
|
|
|
while (buf[len-1] == 0)
|
|
|
|
|
len--;
|
|
|
|
|
if (buf[len-1] != ')')
|
|
|
|
|
return gpg_error (GPG_ERR_INV_SEXP);
|
|
|
|
|
len--; /* Drop the final close-paren: */
|
2019-07-26 03:00:31 +02:00
|
|
|
|
p = buf + 8; /* Skip leading parenthesis and the value tag. */
|
|
|
|
|
len -= 8; /* Count only the data of the second part. */
|
2006-08-29 18:18:30 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* For compatibility with older gpg-agents handle the old style
|
2019-07-26 03:00:31 +02:00
|
|
|
|
incomplete S-exps. */
|
|
|
|
|
len--; /* Do not count the Nul. */
|
2006-08-29 18:18:30 +02:00
|
|
|
|
p = buf;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
n = strtoul (p, &endp, 10);
|
2003-08-05 19:11:04 +02:00
|
|
|
|
if (!n || *endp != ':')
|
|
|
|
|
return gpg_error (GPG_ERR_INV_SEXP);
|
|
|
|
|
endp++;
|
2019-07-26 03:00:31 +02:00
|
|
|
|
if (endp-p+n != len)
|
|
|
|
|
return gpg_error (GPG_ERR_INV_SEXP); /* Oops: Inconsistent S-Exp. */
|
2011-02-04 12:57:53 +01:00
|
|
|
|
|
2003-08-05 19:11:04 +02:00
|
|
|
|
memmove (buf, endp, n);
|
2006-08-29 18:18:30 +02:00
|
|
|
|
|
2003-08-05 19:11:04 +02:00
|
|
|
|
*r_buflen = n;
|
|
|
|
|
*r_buf = buf;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Handle a KEYPARMS inquiry. Note, we only send the data,
|
|
|
|
|
assuan_transact takes care of flushing and writing the end */
|
agent/
2009-11-02 Marcus Brinkmann <marcus@g10code.de>
* command.c (reset_notify): Take LINE arg and return error.
(register_commands): Use assuan_handler_t type.
common/
2009-11-02 Marcus Brinkmann <marcus@g10code.de>
* get-passphrase.c (default_inq_cb, membuf_data_cb): Change return
type to gpg_error_t.
g10/
2009-11-02 Marcus Brinkmann <marcus@g10code.de>
* server.c (reset_notify, input_notify, output_notify): Update to
new assuan interface.
(register_commands): Use assuan_handler_t.
scd/
2009-11-02 Marcus Brinkmann <marcus@g10code.de>
* command.c (reset_notify): Take LINE arg and return error.
(register_commands): Use assuan_handler_t type.
sm/
2009-11-02 Marcus Brinkmann <marcus@g10code.de>
* server.c (reset_notify, input_notify, output_notify): Update to
new assuan interface.
(register_commands): Use assuan_handler_t.
* call-agent.c (membuf_data_cb, default_inq_cb)
(inq_ciphertext_cb, scd_serialno_status_cb)
(scd_keypairinfo_status_cb, istrusted_status_cb)
(learn_status_cb, learn_cb, keyinfo_status_cb): Return gpg_error_t.
2009-11-02 18:47:11 +01:00
|
|
|
|
static gpg_error_t
|
2008-02-14 20:50:10 +01:00
|
|
|
|
inq_genkey_parms (void *opaque, const char *line)
|
2003-08-05 19:11:04 +02:00
|
|
|
|
{
|
2011-02-04 12:57:53 +01:00
|
|
|
|
struct genkey_parm_s *parm = opaque;
|
2006-09-06 18:35:52 +02:00
|
|
|
|
int rc;
|
2003-08-05 19:11:04 +02:00
|
|
|
|
|
Use has_leading_keyword in the assuan callbacks.
* agent/call-pinentry.c (inq_quality): Use has_leading_keyword.
* agent/call-scd.c (inq_needpin, inq_writekey_parms): Ditto.
* g10/call-agent.c (inq_writecert_parms, keyinfo_status_cb): Ditto.
(inq_genkey_parms, inq_ciphertext_cb, inq_import_key_parms): Ditto.
* g10/call-dirmngr.c (ks_put_inq_cb): Ditto.
* sm/call-agent.c (default_inq_cb, inq_ciphertext_cb): Ditto.
(inq_genkey_parms, istrusted_status_cb, learn_status_cb): Ditto.
(keyinfo_status_cb, inq_import_key_parms): Ditto.
* sm/call-dirmngr.c (inq_certificate, isvalid_status_cb): Ditto.
(lookup_status_cb, run_command_inq_cb, run_command_status_cb): Ditto.
2013-02-22 10:56:13 +01:00
|
|
|
|
if (has_leading_keyword (line, "KEYPARAM"))
|
2008-02-14 20:50:10 +01:00
|
|
|
|
{
|
|
|
|
|
rc = assuan_send_data (parm->ctx, parm->sexp, parm->sexplen);
|
|
|
|
|
}
|
|
|
|
|
else
|
2016-03-07 18:09:41 +01:00
|
|
|
|
{
|
|
|
|
|
struct default_inq_parm_s inq_parm = { parm->ctrl, parm->ctx };
|
|
|
|
|
rc = default_inq_cb (&inq_parm, line);
|
|
|
|
|
}
|
2008-02-14 20:50:10 +01:00
|
|
|
|
|
2011-02-04 12:57:53 +01:00
|
|
|
|
return rc;
|
2003-08-05 19:11:04 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-08-19 13:43:16 +02:00
|
|
|
|
/* Call the agent to generate a new key */
|
2003-08-05 19:11:04 +02:00
|
|
|
|
int
|
2004-04-26 15:29:09 +02:00
|
|
|
|
gpgsm_agent_genkey (ctrl_t ctrl,
|
|
|
|
|
ksba_const_sexp_t keyparms, ksba_sexp_t *r_pubkey)
|
2003-08-05 19:11:04 +02:00
|
|
|
|
{
|
|
|
|
|
int rc;
|
|
|
|
|
struct genkey_parm_s gk_parm;
|
|
|
|
|
membuf_t data;
|
|
|
|
|
size_t len;
|
2005-06-16 10:12:03 +02:00
|
|
|
|
unsigned char *buf;
|
2020-08-19 13:43:16 +02:00
|
|
|
|
gnupg_isotime_t timebuf;
|
|
|
|
|
char line[ASSUAN_LINELENGTH];
|
2003-08-05 19:11:04 +02:00
|
|
|
|
|
|
|
|
|
*r_pubkey = NULL;
|
2004-04-26 15:29:09 +02:00
|
|
|
|
rc = start_agent (ctrl);
|
2003-08-05 19:11:04 +02:00
|
|
|
|
if (rc)
|
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
|
|
rc = assuan_transact (agent_ctx, "RESET", NULL, NULL, NULL, NULL, NULL, NULL);
|
|
|
|
|
if (rc)
|
2006-09-06 18:35:52 +02:00
|
|
|
|
return rc;
|
2003-08-05 19:11:04 +02:00
|
|
|
|
|
|
|
|
|
init_membuf (&data, 1024);
|
2008-02-14 20:50:10 +01:00
|
|
|
|
gk_parm.ctrl = ctrl;
|
2003-08-05 19:11:04 +02:00
|
|
|
|
gk_parm.ctx = agent_ctx;
|
|
|
|
|
gk_parm.sexp = keyparms;
|
|
|
|
|
gk_parm.sexplen = gcry_sexp_canon_len (keyparms, 0, NULL, NULL);
|
|
|
|
|
if (!gk_parm.sexplen)
|
|
|
|
|
return gpg_error (GPG_ERR_INV_VALUE);
|
2020-08-19 13:43:16 +02:00
|
|
|
|
gnupg_get_isotime (timebuf);
|
|
|
|
|
snprintf (line, sizeof line, "GENKEY --timestamp=%s", timebuf);
|
|
|
|
|
rc = assuan_transact (agent_ctx, line,
|
2016-01-08 06:33:27 +01:00
|
|
|
|
put_membuf_cb, &data,
|
2003-08-05 19:11:04 +02:00
|
|
|
|
inq_genkey_parms, &gk_parm, NULL, NULL);
|
|
|
|
|
if (rc)
|
|
|
|
|
{
|
|
|
|
|
xfree (get_membuf (&data, &len));
|
2006-09-06 18:35:52 +02:00
|
|
|
|
return rc;
|
2003-08-05 19:11:04 +02:00
|
|
|
|
}
|
|
|
|
|
buf = get_membuf (&data, &len);
|
|
|
|
|
if (!buf)
|
|
|
|
|
return gpg_error (GPG_ERR_ENOMEM);
|
|
|
|
|
if (!gcry_sexp_canon_len (buf, len, NULL, NULL))
|
2005-07-25 16:35:04 +02:00
|
|
|
|
{
|
|
|
|
|
xfree (buf);
|
|
|
|
|
return gpg_error (GPG_ERR_INV_SEXP);
|
|
|
|
|
}
|
|
|
|
|
*r_pubkey = buf;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-11 19:52:15 +02:00
|
|
|
|
/* Call the agent to read the public key part for a given keygrip. If
|
|
|
|
|
FROMCARD is true, the key is directly read from the current
|
|
|
|
|
smartcard. In this case HEXKEYGRIP should be the keyID
|
|
|
|
|
(e.g. OPENPGP.3). */
|
2005-07-25 16:35:04 +02:00
|
|
|
|
int
|
2006-10-11 19:52:15 +02:00
|
|
|
|
gpgsm_agent_readkey (ctrl_t ctrl, int fromcard, const char *hexkeygrip,
|
2005-07-25 16:35:04 +02:00
|
|
|
|
ksba_sexp_t *r_pubkey)
|
|
|
|
|
{
|
|
|
|
|
int rc;
|
|
|
|
|
membuf_t data;
|
|
|
|
|
size_t len;
|
|
|
|
|
unsigned char *buf;
|
|
|
|
|
char line[ASSUAN_LINELENGTH];
|
2016-09-27 07:45:21 +02:00
|
|
|
|
struct default_inq_parm_s inq_parm;
|
2005-07-25 16:35:04 +02:00
|
|
|
|
|
|
|
|
|
*r_pubkey = NULL;
|
|
|
|
|
rc = start_agent (ctrl);
|
|
|
|
|
if (rc)
|
|
|
|
|
return rc;
|
2016-12-16 15:50:17 +01:00
|
|
|
|
inq_parm.ctrl = ctrl;
|
2016-09-27 07:45:21 +02:00
|
|
|
|
inq_parm.ctx = agent_ctx;
|
2005-07-25 16:35:04 +02:00
|
|
|
|
|
|
|
|
|
rc = assuan_transact (agent_ctx, "RESET",NULL, NULL, NULL, NULL, NULL, NULL);
|
|
|
|
|
if (rc)
|
2006-09-06 18:35:52 +02:00
|
|
|
|
return rc;
|
2005-07-25 16:35:04 +02:00
|
|
|
|
|
Fix use cases of snprintf.
* agent/call-pinentry.c, agent/call-scd.c, agent/command.c,
build-aux/speedo/w32/g4wihelp.c, common/get-passphrase.c,
dirmngr/dirmngr.c, g10/call-agent.c, g10/cpr.c, g10/keygen.c,
g10/openfile.c, g10/passphrase.c, scd/app-openpgp.c, scd/scdaemon.c,
sm/call-agent.c, sm/call-dirmngr.c, sm/certreqgen.c: Fix assuming C99.
--
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2016-10-21 05:04:46 +02:00
|
|
|
|
snprintf (line, DIM(line), "%sREADKEY %s",
|
2006-10-11 19:52:15 +02:00
|
|
|
|
fromcard? "SCD ":"", hexkeygrip);
|
2005-07-25 16:35:04 +02:00
|
|
|
|
|
|
|
|
|
init_membuf (&data, 1024);
|
|
|
|
|
rc = assuan_transact (agent_ctx, line,
|
2016-01-08 06:33:27 +01:00
|
|
|
|
put_membuf_cb, &data,
|
2016-03-07 18:09:41 +01:00
|
|
|
|
default_inq_cb, &inq_parm, NULL, NULL);
|
2005-07-25 16:35:04 +02:00
|
|
|
|
if (rc)
|
|
|
|
|
{
|
|
|
|
|
xfree (get_membuf (&data, &len));
|
2006-09-06 18:35:52 +02:00
|
|
|
|
return rc;
|
2005-07-25 16:35:04 +02:00
|
|
|
|
}
|
|
|
|
|
buf = get_membuf (&data, &len);
|
|
|
|
|
if (!buf)
|
|
|
|
|
return gpg_error (GPG_ERR_ENOMEM);
|
|
|
|
|
if (!gcry_sexp_canon_len (buf, len, NULL, NULL))
|
2003-08-05 19:11:04 +02:00
|
|
|
|
{
|
|
|
|
|
xfree (buf);
|
|
|
|
|
return gpg_error (GPG_ERR_INV_SEXP);
|
|
|
|
|
}
|
|
|
|
|
*r_pubkey = buf;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-02 11:49:31 +02:00
|
|
|
|
|
2003-08-05 19:11:04 +02:00
|
|
|
|
|
2009-07-02 11:49:31 +02:00
|
|
|
|
/* Take the serial number from LINE and return it verbatim in a newly
|
|
|
|
|
allocated string. We make sure that only hex characters are
|
|
|
|
|
returned. */
|
|
|
|
|
static char *
|
|
|
|
|
store_serialno (const char *line)
|
|
|
|
|
{
|
|
|
|
|
const char *s;
|
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
|
|
for (s=line; hexdigitp (s); s++)
|
|
|
|
|
;
|
|
|
|
|
p = xtrymalloc (s + 1 - line);
|
|
|
|
|
if (p)
|
|
|
|
|
{
|
|
|
|
|
memcpy (p, line, s-line);
|
|
|
|
|
p[s-line] = 0;
|
|
|
|
|
}
|
|
|
|
|
return p;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2015-11-16 12:41:46 +01:00
|
|
|
|
/* Callback for the gpgsm_agent_serialno function. */
|
agent/
2009-11-02 Marcus Brinkmann <marcus@g10code.de>
* command.c (reset_notify): Take LINE arg and return error.
(register_commands): Use assuan_handler_t type.
common/
2009-11-02 Marcus Brinkmann <marcus@g10code.de>
* get-passphrase.c (default_inq_cb, membuf_data_cb): Change return
type to gpg_error_t.
g10/
2009-11-02 Marcus Brinkmann <marcus@g10code.de>
* server.c (reset_notify, input_notify, output_notify): Update to
new assuan interface.
(register_commands): Use assuan_handler_t.
scd/
2009-11-02 Marcus Brinkmann <marcus@g10code.de>
* command.c (reset_notify): Take LINE arg and return error.
(register_commands): Use assuan_handler_t type.
sm/
2009-11-02 Marcus Brinkmann <marcus@g10code.de>
* server.c (reset_notify, input_notify, output_notify): Update to
new assuan interface.
(register_commands): Use assuan_handler_t.
* call-agent.c (membuf_data_cb, default_inq_cb)
(inq_ciphertext_cb, scd_serialno_status_cb)
(scd_keypairinfo_status_cb, istrusted_status_cb)
(learn_status_cb, learn_cb, keyinfo_status_cb): Return gpg_error_t.
2009-11-02 18:47:11 +01:00
|
|
|
|
static gpg_error_t
|
2009-07-02 11:49:31 +02:00
|
|
|
|
scd_serialno_status_cb (void *opaque, const char *line)
|
|
|
|
|
{
|
|
|
|
|
char **r_serialno = opaque;
|
|
|
|
|
const char *keyword = line;
|
|
|
|
|
int keywordlen;
|
|
|
|
|
|
|
|
|
|
for (keywordlen=0; *line && !spacep (line); line++, keywordlen++)
|
|
|
|
|
;
|
|
|
|
|
while (spacep (line))
|
|
|
|
|
line++;
|
|
|
|
|
|
|
|
|
|
if (keywordlen == 8 && !memcmp (keyword, "SERIALNO", keywordlen))
|
|
|
|
|
{
|
|
|
|
|
xfree (*r_serialno);
|
|
|
|
|
*r_serialno = store_serialno (line);
|
|
|
|
|
}
|
2006-09-25 20:29:20 +02:00
|
|
|
|
|
2009-07-02 11:49:31 +02:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Call the agent to read the serial number of the current card. */
|
|
|
|
|
int
|
|
|
|
|
gpgsm_agent_scd_serialno (ctrl_t ctrl, char **r_serialno)
|
|
|
|
|
{
|
|
|
|
|
int rc;
|
|
|
|
|
char *serialno = NULL;
|
2016-09-27 07:45:21 +02:00
|
|
|
|
struct default_inq_parm_s inq_parm;
|
2011-02-04 12:57:53 +01:00
|
|
|
|
|
2009-07-02 11:49:31 +02:00
|
|
|
|
*r_serialno = NULL;
|
|
|
|
|
rc = start_agent (ctrl);
|
|
|
|
|
if (rc)
|
|
|
|
|
return rc;
|
2016-09-27 07:45:21 +02:00
|
|
|
|
inq_parm.ctrl = ctrl;
|
|
|
|
|
inq_parm.ctx = agent_ctx;
|
2009-07-02 11:49:31 +02:00
|
|
|
|
|
|
|
|
|
rc = assuan_transact (agent_ctx, "SCD SERIALNO",
|
|
|
|
|
NULL, NULL,
|
2016-03-07 18:09:41 +01:00
|
|
|
|
default_inq_cb, &inq_parm,
|
2009-07-02 11:49:31 +02:00
|
|
|
|
scd_serialno_status_cb, &serialno);
|
|
|
|
|
if (!rc && !serialno)
|
|
|
|
|
rc = gpg_error (GPG_ERR_INTERNAL);
|
|
|
|
|
if (rc)
|
|
|
|
|
{
|
|
|
|
|
xfree (serialno);
|
|
|
|
|
return rc;
|
|
|
|
|
}
|
|
|
|
|
*r_serialno = serialno;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-11-16 12:41:46 +01:00
|
|
|
|
/* Callback for the gpgsm_agent_serialno function. */
|
agent/
2009-11-02 Marcus Brinkmann <marcus@g10code.de>
* command.c (reset_notify): Take LINE arg and return error.
(register_commands): Use assuan_handler_t type.
common/
2009-11-02 Marcus Brinkmann <marcus@g10code.de>
* get-passphrase.c (default_inq_cb, membuf_data_cb): Change return
type to gpg_error_t.
g10/
2009-11-02 Marcus Brinkmann <marcus@g10code.de>
* server.c (reset_notify, input_notify, output_notify): Update to
new assuan interface.
(register_commands): Use assuan_handler_t.
scd/
2009-11-02 Marcus Brinkmann <marcus@g10code.de>
* command.c (reset_notify): Take LINE arg and return error.
(register_commands): Use assuan_handler_t type.
sm/
2009-11-02 Marcus Brinkmann <marcus@g10code.de>
* server.c (reset_notify, input_notify, output_notify): Update to
new assuan interface.
(register_commands): Use assuan_handler_t.
* call-agent.c (membuf_data_cb, default_inq_cb)
(inq_ciphertext_cb, scd_serialno_status_cb)
(scd_keypairinfo_status_cb, istrusted_status_cb)
(learn_status_cb, learn_cb, keyinfo_status_cb): Return gpg_error_t.
2009-11-02 18:47:11 +01:00
|
|
|
|
static gpg_error_t
|
2009-07-02 11:49:31 +02:00
|
|
|
|
scd_keypairinfo_status_cb (void *opaque, const char *line)
|
|
|
|
|
{
|
|
|
|
|
strlist_t *listaddr = opaque;
|
|
|
|
|
const char *keyword = line;
|
|
|
|
|
int keywordlen;
|
|
|
|
|
strlist_t sl;
|
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
|
|
for (keywordlen=0; *line && !spacep (line); line++, keywordlen++)
|
|
|
|
|
;
|
|
|
|
|
while (spacep (line))
|
|
|
|
|
line++;
|
|
|
|
|
|
|
|
|
|
if (keywordlen == 11 && !memcmp (keyword, "KEYPAIRINFO", keywordlen))
|
|
|
|
|
{
|
|
|
|
|
sl = append_to_strlist (listaddr, line);
|
|
|
|
|
p = sl->d;
|
2019-04-01 19:58:33 +02:00
|
|
|
|
/* Make sure that we only have two tokens so that future
|
|
|
|
|
* extensions of the format won't change the format expected by
|
|
|
|
|
* the caller. */
|
2009-07-02 11:49:31 +02:00
|
|
|
|
while (*p && !spacep (p))
|
|
|
|
|
p++;
|
|
|
|
|
if (*p)
|
|
|
|
|
{
|
|
|
|
|
while (spacep (p))
|
|
|
|
|
p++;
|
|
|
|
|
while (*p && !spacep (p))
|
|
|
|
|
p++;
|
2019-04-01 19:58:33 +02:00
|
|
|
|
if (*p)
|
|
|
|
|
{
|
|
|
|
|
*p++ = 0;
|
|
|
|
|
while (spacep (p))
|
|
|
|
|
p++;
|
|
|
|
|
while (*p && !spacep (p))
|
|
|
|
|
{
|
|
|
|
|
switch (*p++)
|
|
|
|
|
{
|
|
|
|
|
case 'c': sl->flags |= GCRY_PK_USAGE_CERT; break;
|
|
|
|
|
case 's': sl->flags |= GCRY_PK_USAGE_SIGN; break;
|
|
|
|
|
case 'e': sl->flags |= GCRY_PK_USAGE_ENCR; break;
|
|
|
|
|
case 'a': sl->flags |= GCRY_PK_USAGE_AUTH; break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-07-02 11:49:31 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Call the agent to read the keypairinfo lines of the current card.
|
|
|
|
|
The list is returned as a string made up of the keygrip, a space
|
2019-04-01 19:58:33 +02:00
|
|
|
|
and the keyid. The flags of the string carry the usage bits. */
|
2009-07-02 11:49:31 +02:00
|
|
|
|
int
|
|
|
|
|
gpgsm_agent_scd_keypairinfo (ctrl_t ctrl, strlist_t *r_list)
|
|
|
|
|
{
|
|
|
|
|
int rc;
|
|
|
|
|
strlist_t list = NULL;
|
2016-09-27 07:45:21 +02:00
|
|
|
|
struct default_inq_parm_s inq_parm;
|
2011-02-04 12:57:53 +01:00
|
|
|
|
|
2009-07-02 11:49:31 +02:00
|
|
|
|
*r_list = NULL;
|
|
|
|
|
rc = start_agent (ctrl);
|
|
|
|
|
if (rc)
|
|
|
|
|
return rc;
|
2016-09-27 07:45:21 +02:00
|
|
|
|
inq_parm.ctrl = ctrl;
|
|
|
|
|
inq_parm.ctx = agent_ctx;
|
2009-07-02 11:49:31 +02:00
|
|
|
|
|
2019-04-03 13:16:22 +02:00
|
|
|
|
rc = assuan_transact (agent_ctx, "SCD LEARN --keypairinfo",
|
2009-07-02 11:49:31 +02:00
|
|
|
|
NULL, NULL,
|
2016-03-07 18:09:41 +01:00
|
|
|
|
default_inq_cb, &inq_parm,
|
2009-07-02 11:49:31 +02:00
|
|
|
|
scd_keypairinfo_status_cb, &list);
|
|
|
|
|
if (!rc && !list)
|
|
|
|
|
rc = gpg_error (GPG_ERR_NO_DATA);
|
|
|
|
|
if (rc)
|
|
|
|
|
{
|
|
|
|
|
free_strlist (list);
|
|
|
|
|
return rc;
|
|
|
|
|
}
|
|
|
|
|
*r_list = list;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
agent/
2009-11-02 Marcus Brinkmann <marcus@g10code.de>
* command.c (reset_notify): Take LINE arg and return error.
(register_commands): Use assuan_handler_t type.
common/
2009-11-02 Marcus Brinkmann <marcus@g10code.de>
* get-passphrase.c (default_inq_cb, membuf_data_cb): Change return
type to gpg_error_t.
g10/
2009-11-02 Marcus Brinkmann <marcus@g10code.de>
* server.c (reset_notify, input_notify, output_notify): Update to
new assuan interface.
(register_commands): Use assuan_handler_t.
scd/
2009-11-02 Marcus Brinkmann <marcus@g10code.de>
* command.c (reset_notify): Take LINE arg and return error.
(register_commands): Use assuan_handler_t type.
sm/
2009-11-02 Marcus Brinkmann <marcus@g10code.de>
* server.c (reset_notify, input_notify, output_notify): Update to
new assuan interface.
(register_commands): Use assuan_handler_t.
* call-agent.c (membuf_data_cb, default_inq_cb)
(inq_ciphertext_cb, scd_serialno_status_cb)
(scd_keypairinfo_status_cb, istrusted_status_cb)
(learn_status_cb, learn_cb, keyinfo_status_cb): Return gpg_error_t.
2009-11-02 18:47:11 +01:00
|
|
|
|
static gpg_error_t
|
2006-09-25 20:29:20 +02:00
|
|
|
|
istrusted_status_cb (void *opaque, const char *line)
|
|
|
|
|
{
|
|
|
|
|
struct rootca_flags_s *flags = opaque;
|
Use has_leading_keyword in the assuan callbacks.
* agent/call-pinentry.c (inq_quality): Use has_leading_keyword.
* agent/call-scd.c (inq_needpin, inq_writekey_parms): Ditto.
* g10/call-agent.c (inq_writecert_parms, keyinfo_status_cb): Ditto.
(inq_genkey_parms, inq_ciphertext_cb, inq_import_key_parms): Ditto.
* g10/call-dirmngr.c (ks_put_inq_cb): Ditto.
* sm/call-agent.c (default_inq_cb, inq_ciphertext_cb): Ditto.
(inq_genkey_parms, istrusted_status_cb, learn_status_cb): Ditto.
(keyinfo_status_cb, inq_import_key_parms): Ditto.
* sm/call-dirmngr.c (inq_certificate, isvalid_status_cb): Ditto.
(lookup_status_cb, run_command_inq_cb, run_command_status_cb): Ditto.
2013-02-22 10:56:13 +01:00
|
|
|
|
const char *s;
|
2006-09-25 20:29:20 +02:00
|
|
|
|
|
Use has_leading_keyword in the assuan callbacks.
* agent/call-pinentry.c (inq_quality): Use has_leading_keyword.
* agent/call-scd.c (inq_needpin, inq_writekey_parms): Ditto.
* g10/call-agent.c (inq_writecert_parms, keyinfo_status_cb): Ditto.
(inq_genkey_parms, inq_ciphertext_cb, inq_import_key_parms): Ditto.
* g10/call-dirmngr.c (ks_put_inq_cb): Ditto.
* sm/call-agent.c (default_inq_cb, inq_ciphertext_cb): Ditto.
(inq_genkey_parms, istrusted_status_cb, learn_status_cb): Ditto.
(keyinfo_status_cb, inq_import_key_parms): Ditto.
* sm/call-dirmngr.c (inq_certificate, isvalid_status_cb): Ditto.
(lookup_status_cb, run_command_inq_cb, run_command_status_cb): Ditto.
2013-02-22 10:56:13 +01:00
|
|
|
|
if ((s = has_leading_keyword (line, "TRUSTLISTFLAG")))
|
2006-09-25 20:29:20 +02:00
|
|
|
|
{
|
Use has_leading_keyword in the assuan callbacks.
* agent/call-pinentry.c (inq_quality): Use has_leading_keyword.
* agent/call-scd.c (inq_needpin, inq_writekey_parms): Ditto.
* g10/call-agent.c (inq_writecert_parms, keyinfo_status_cb): Ditto.
(inq_genkey_parms, inq_ciphertext_cb, inq_import_key_parms): Ditto.
* g10/call-dirmngr.c (ks_put_inq_cb): Ditto.
* sm/call-agent.c (default_inq_cb, inq_ciphertext_cb): Ditto.
(inq_genkey_parms, istrusted_status_cb, learn_status_cb): Ditto.
(keyinfo_status_cb, inq_import_key_parms): Ditto.
* sm/call-dirmngr.c (inq_certificate, isvalid_status_cb): Ditto.
(lookup_status_cb, run_command_inq_cb, run_command_status_cb): Ditto.
2013-02-22 10:56:13 +01:00
|
|
|
|
line = s;
|
|
|
|
|
if (has_leading_keyword (line, "relax"))
|
2006-09-25 20:29:20 +02:00
|
|
|
|
flags->relax = 1;
|
Use has_leading_keyword in the assuan callbacks.
* agent/call-pinentry.c (inq_quality): Use has_leading_keyword.
* agent/call-scd.c (inq_needpin, inq_writekey_parms): Ditto.
* g10/call-agent.c (inq_writecert_parms, keyinfo_status_cb): Ditto.
(inq_genkey_parms, inq_ciphertext_cb, inq_import_key_parms): Ditto.
* g10/call-dirmngr.c (ks_put_inq_cb): Ditto.
* sm/call-agent.c (default_inq_cb, inq_ciphertext_cb): Ditto.
(inq_genkey_parms, istrusted_status_cb, learn_status_cb): Ditto.
(keyinfo_status_cb, inq_import_key_parms): Ditto.
* sm/call-dirmngr.c (inq_certificate, isvalid_status_cb): Ditto.
(lookup_status_cb, run_command_inq_cb, run_command_status_cb): Ditto.
2013-02-22 10:56:13 +01:00
|
|
|
|
else if (has_leading_keyword (line, "cm"))
|
2007-08-10 18:52:05 +02:00
|
|
|
|
flags->chain_model = 1;
|
2022-02-27 12:03:20 +01:00
|
|
|
|
else if (has_leading_keyword (line, "qual"))
|
|
|
|
|
flags->qualified = 1;
|
2023-04-03 14:06:36 +02:00
|
|
|
|
else if (has_leading_keyword (line, "de-vs"))
|
|
|
|
|
flags->de_vs = 1;
|
2006-09-25 20:29:20 +02:00
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-08-05 19:11:04 +02:00
|
|
|
|
/* Ask the agent whether the certificate is in the list of trusted
|
2008-10-21 17:03:51 +02:00
|
|
|
|
keys. The certificate is either specified by the CERT object or by
|
|
|
|
|
the fingerprint HEXFPR. ROOTCA_FLAGS is guaranteed to be cleared
|
|
|
|
|
on error. */
|
2003-08-05 19:11:04 +02:00
|
|
|
|
int
|
2008-10-21 17:03:51 +02:00
|
|
|
|
gpgsm_agent_istrusted (ctrl_t ctrl, ksba_cert_t cert, const char *hexfpr,
|
2006-09-25 20:29:20 +02:00
|
|
|
|
struct rootca_flags_s *rootca_flags)
|
2003-08-05 19:11:04 +02:00
|
|
|
|
{
|
|
|
|
|
int rc;
|
|
|
|
|
char line[ASSUAN_LINELENGTH];
|
|
|
|
|
|
2006-09-25 20:29:20 +02:00
|
|
|
|
memset (rootca_flags, 0, sizeof *rootca_flags);
|
|
|
|
|
|
2008-10-21 17:03:51 +02:00
|
|
|
|
if (cert && hexfpr)
|
|
|
|
|
return gpg_error (GPG_ERR_INV_ARG);
|
|
|
|
|
|
2004-04-26 15:29:09 +02:00
|
|
|
|
rc = start_agent (ctrl);
|
2003-08-05 19:11:04 +02:00
|
|
|
|
if (rc)
|
|
|
|
|
return rc;
|
|
|
|
|
|
2008-10-21 17:03:51 +02:00
|
|
|
|
if (hexfpr)
|
2003-08-05 19:11:04 +02:00
|
|
|
|
{
|
Fix use cases of snprintf.
* agent/call-pinentry.c, agent/call-scd.c, agent/command.c,
build-aux/speedo/w32/g4wihelp.c, common/get-passphrase.c,
dirmngr/dirmngr.c, g10/call-agent.c, g10/cpr.c, g10/keygen.c,
g10/openfile.c, g10/passphrase.c, scd/app-openpgp.c, scd/scdaemon.c,
sm/call-agent.c, sm/call-dirmngr.c, sm/certreqgen.c: Fix assuming C99.
--
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2016-10-21 05:04:46 +02:00
|
|
|
|
snprintf (line, DIM(line), "ISTRUSTED %s", hexfpr);
|
2003-08-05 19:11:04 +02:00
|
|
|
|
}
|
2008-10-21 17:03:51 +02:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
char *fpr;
|
2003-08-05 19:11:04 +02:00
|
|
|
|
|
2008-10-21 17:03:51 +02:00
|
|
|
|
fpr = gpgsm_get_fingerprint_hexstring (cert, GCRY_MD_SHA1);
|
|
|
|
|
if (!fpr)
|
|
|
|
|
{
|
|
|
|
|
log_error ("error getting the fingerprint\n");
|
|
|
|
|
return gpg_error (GPG_ERR_GENERAL);
|
|
|
|
|
}
|
2011-02-04 12:57:53 +01:00
|
|
|
|
|
Fix use cases of snprintf.
* agent/call-pinentry.c, agent/call-scd.c, agent/command.c,
build-aux/speedo/w32/g4wihelp.c, common/get-passphrase.c,
dirmngr/dirmngr.c, g10/call-agent.c, g10/cpr.c, g10/keygen.c,
g10/openfile.c, g10/passphrase.c, scd/app-openpgp.c, scd/scdaemon.c,
sm/call-agent.c, sm/call-dirmngr.c, sm/certreqgen.c: Fix assuming C99.
--
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2016-10-21 05:04:46 +02:00
|
|
|
|
snprintf (line, DIM(line), "ISTRUSTED %s", fpr);
|
2008-10-21 17:03:51 +02:00
|
|
|
|
xfree (fpr);
|
|
|
|
|
}
|
2003-08-05 19:11:04 +02:00
|
|
|
|
|
2006-09-25 20:29:20 +02:00
|
|
|
|
rc = assuan_transact (agent_ctx, line, NULL, NULL, NULL, NULL,
|
|
|
|
|
istrusted_status_cb, rootca_flags);
|
2007-08-10 18:52:05 +02:00
|
|
|
|
if (!rc)
|
|
|
|
|
rootca_flags->valid = 1;
|
2006-09-06 18:35:52 +02:00
|
|
|
|
return rc;
|
2003-08-05 19:11:04 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Ask the agent to mark CERT as a trusted Root-CA one */
|
|
|
|
|
int
|
2004-04-26 15:29:09 +02:00
|
|
|
|
gpgsm_agent_marktrusted (ctrl_t ctrl, ksba_cert_t cert)
|
2003-08-05 19:11:04 +02:00
|
|
|
|
{
|
|
|
|
|
int rc;
|
2009-03-26 12:33:53 +01:00
|
|
|
|
char *fpr, *dn, *dnfmt;
|
2003-08-05 19:11:04 +02:00
|
|
|
|
char line[ASSUAN_LINELENGTH];
|
2016-09-27 07:45:21 +02:00
|
|
|
|
struct default_inq_parm_s inq_parm;
|
2003-08-05 19:11:04 +02:00
|
|
|
|
|
2004-04-26 15:29:09 +02:00
|
|
|
|
rc = start_agent (ctrl);
|
2003-08-05 19:11:04 +02:00
|
|
|
|
if (rc)
|
|
|
|
|
return rc;
|
2016-09-27 07:45:21 +02:00
|
|
|
|
inq_parm.ctrl = ctrl;
|
|
|
|
|
inq_parm.ctx = agent_ctx;
|
2003-08-05 19:11:04 +02:00
|
|
|
|
|
|
|
|
|
fpr = gpgsm_get_fingerprint_hexstring (cert, GCRY_MD_SHA1);
|
|
|
|
|
if (!fpr)
|
|
|
|
|
{
|
|
|
|
|
log_error ("error getting the fingerprint\n");
|
|
|
|
|
return gpg_error (GPG_ERR_GENERAL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dn = ksba_cert_get_issuer (cert, 0);
|
|
|
|
|
if (!dn)
|
|
|
|
|
{
|
|
|
|
|
xfree (fpr);
|
|
|
|
|
return gpg_error (GPG_ERR_GENERAL);
|
|
|
|
|
}
|
2009-03-26 12:33:53 +01:00
|
|
|
|
dnfmt = gpgsm_format_name2 (dn, 0);
|
|
|
|
|
xfree (dn);
|
|
|
|
|
if (!dnfmt)
|
|
|
|
|
return gpg_error_from_syserror ();
|
Fix use cases of snprintf.
* agent/call-pinentry.c, agent/call-scd.c, agent/command.c,
build-aux/speedo/w32/g4wihelp.c, common/get-passphrase.c,
dirmngr/dirmngr.c, g10/call-agent.c, g10/cpr.c, g10/keygen.c,
g10/openfile.c, g10/passphrase.c, scd/app-openpgp.c, scd/scdaemon.c,
sm/call-agent.c, sm/call-dirmngr.c, sm/certreqgen.c: Fix assuming C99.
--
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2016-10-21 05:04:46 +02:00
|
|
|
|
snprintf (line, DIM(line), "MARKTRUSTED %s S %s", fpr, dnfmt);
|
2009-03-26 12:33:53 +01:00
|
|
|
|
ksba_free (dnfmt);
|
2003-08-05 19:11:04 +02:00
|
|
|
|
xfree (fpr);
|
|
|
|
|
|
2008-02-14 20:50:10 +01:00
|
|
|
|
rc = assuan_transact (agent_ctx, line, NULL, NULL,
|
2016-03-07 18:09:41 +01:00
|
|
|
|
default_inq_cb, &inq_parm, NULL, NULL);
|
2006-09-06 18:35:52 +02:00
|
|
|
|
return rc;
|
2003-08-05 19:11:04 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Ask the agent whether the a corresponding secret key is available
|
|
|
|
|
for the given keygrip */
|
|
|
|
|
int
|
2004-04-26 15:29:09 +02:00
|
|
|
|
gpgsm_agent_havekey (ctrl_t ctrl, const char *hexkeygrip)
|
2003-08-05 19:11:04 +02:00
|
|
|
|
{
|
|
|
|
|
int rc;
|
|
|
|
|
char line[ASSUAN_LINELENGTH];
|
|
|
|
|
|
2004-04-26 15:29:09 +02:00
|
|
|
|
rc = start_agent (ctrl);
|
2003-08-05 19:11:04 +02:00
|
|
|
|
if (rc)
|
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
|
|
if (!hexkeygrip || strlen (hexkeygrip) != 40)
|
|
|
|
|
return gpg_error (GPG_ERR_INV_VALUE);
|
|
|
|
|
|
Fix use cases of snprintf.
* agent/call-pinentry.c, agent/call-scd.c, agent/command.c,
build-aux/speedo/w32/g4wihelp.c, common/get-passphrase.c,
dirmngr/dirmngr.c, g10/call-agent.c, g10/cpr.c, g10/keygen.c,
g10/openfile.c, g10/passphrase.c, scd/app-openpgp.c, scd/scdaemon.c,
sm/call-agent.c, sm/call-dirmngr.c, sm/certreqgen.c: Fix assuming C99.
--
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2016-10-21 05:04:46 +02:00
|
|
|
|
snprintf (line, DIM(line), "HAVEKEY %s", hexkeygrip);
|
2003-08-05 19:11:04 +02:00
|
|
|
|
|
|
|
|
|
rc = assuan_transact (agent_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL);
|
2006-09-06 18:35:52 +02:00
|
|
|
|
return rc;
|
2003-08-05 19:11:04 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
agent/
2009-11-02 Marcus Brinkmann <marcus@g10code.de>
* command.c (reset_notify): Take LINE arg and return error.
(register_commands): Use assuan_handler_t type.
common/
2009-11-02 Marcus Brinkmann <marcus@g10code.de>
* get-passphrase.c (default_inq_cb, membuf_data_cb): Change return
type to gpg_error_t.
g10/
2009-11-02 Marcus Brinkmann <marcus@g10code.de>
* server.c (reset_notify, input_notify, output_notify): Update to
new assuan interface.
(register_commands): Use assuan_handler_t.
scd/
2009-11-02 Marcus Brinkmann <marcus@g10code.de>
* command.c (reset_notify): Take LINE arg and return error.
(register_commands): Use assuan_handler_t type.
sm/
2009-11-02 Marcus Brinkmann <marcus@g10code.de>
* server.c (reset_notify, input_notify, output_notify): Update to
new assuan interface.
(register_commands): Use assuan_handler_t.
* call-agent.c (membuf_data_cb, default_inq_cb)
(inq_ciphertext_cb, scd_serialno_status_cb)
(scd_keypairinfo_status_cb, istrusted_status_cb)
(learn_status_cb, learn_cb, keyinfo_status_cb): Return gpg_error_t.
2009-11-02 18:47:11 +01:00
|
|
|
|
static gpg_error_t
|
2009-03-20 20:04:47 +01:00
|
|
|
|
learn_status_cb (void *opaque, const char *line)
|
|
|
|
|
{
|
|
|
|
|
struct learn_parm_s *parm = opaque;
|
Use has_leading_keyword in the assuan callbacks.
* agent/call-pinentry.c (inq_quality): Use has_leading_keyword.
* agent/call-scd.c (inq_needpin, inq_writekey_parms): Ditto.
* g10/call-agent.c (inq_writecert_parms, keyinfo_status_cb): Ditto.
(inq_genkey_parms, inq_ciphertext_cb, inq_import_key_parms): Ditto.
* g10/call-dirmngr.c (ks_put_inq_cb): Ditto.
* sm/call-agent.c (default_inq_cb, inq_ciphertext_cb): Ditto.
(inq_genkey_parms, istrusted_status_cb, learn_status_cb): Ditto.
(keyinfo_status_cb, inq_import_key_parms): Ditto.
* sm/call-dirmngr.c (inq_certificate, isvalid_status_cb): Ditto.
(lookup_status_cb, run_command_inq_cb, run_command_status_cb): Ditto.
2013-02-22 10:56:13 +01:00
|
|
|
|
const char *s;
|
2009-03-20 20:04:47 +01:00
|
|
|
|
|
|
|
|
|
/* Pass progress data to the caller. */
|
Use has_leading_keyword in the assuan callbacks.
* agent/call-pinentry.c (inq_quality): Use has_leading_keyword.
* agent/call-scd.c (inq_needpin, inq_writekey_parms): Ditto.
* g10/call-agent.c (inq_writecert_parms, keyinfo_status_cb): Ditto.
(inq_genkey_parms, inq_ciphertext_cb, inq_import_key_parms): Ditto.
* g10/call-dirmngr.c (ks_put_inq_cb): Ditto.
* sm/call-agent.c (default_inq_cb, inq_ciphertext_cb): Ditto.
(inq_genkey_parms, istrusted_status_cb, learn_status_cb): Ditto.
(keyinfo_status_cb, inq_import_key_parms): Ditto.
* sm/call-dirmngr.c (inq_certificate, isvalid_status_cb): Ditto.
(lookup_status_cb, run_command_inq_cb, run_command_status_cb): Ditto.
2013-02-22 10:56:13 +01:00
|
|
|
|
if ((s = has_leading_keyword (line, "PROGRESS")))
|
2009-03-20 20:04:47 +01:00
|
|
|
|
{
|
Use has_leading_keyword in the assuan callbacks.
* agent/call-pinentry.c (inq_quality): Use has_leading_keyword.
* agent/call-scd.c (inq_needpin, inq_writekey_parms): Ditto.
* g10/call-agent.c (inq_writecert_parms, keyinfo_status_cb): Ditto.
(inq_genkey_parms, inq_ciphertext_cb, inq_import_key_parms): Ditto.
* g10/call-dirmngr.c (ks_put_inq_cb): Ditto.
* sm/call-agent.c (default_inq_cb, inq_ciphertext_cb): Ditto.
(inq_genkey_parms, istrusted_status_cb, learn_status_cb): Ditto.
(keyinfo_status_cb, inq_import_key_parms): Ditto.
* sm/call-dirmngr.c (inq_certificate, isvalid_status_cb): Ditto.
(lookup_status_cb, run_command_inq_cb, run_command_status_cb): Ditto.
2013-02-22 10:56:13 +01:00
|
|
|
|
line = s;
|
2009-03-20 20:04:47 +01:00
|
|
|
|
if (parm->ctrl)
|
|
|
|
|
{
|
|
|
|
|
if (gpgsm_status (parm->ctrl, STATUS_PROGRESS, line))
|
|
|
|
|
return gpg_error (GPG_ERR_ASS_CANCELED);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
agent/
2009-11-02 Marcus Brinkmann <marcus@g10code.de>
* command.c (reset_notify): Take LINE arg and return error.
(register_commands): Use assuan_handler_t type.
common/
2009-11-02 Marcus Brinkmann <marcus@g10code.de>
* get-passphrase.c (default_inq_cb, membuf_data_cb): Change return
type to gpg_error_t.
g10/
2009-11-02 Marcus Brinkmann <marcus@g10code.de>
* server.c (reset_notify, input_notify, output_notify): Update to
new assuan interface.
(register_commands): Use assuan_handler_t.
scd/
2009-11-02 Marcus Brinkmann <marcus@g10code.de>
* command.c (reset_notify): Take LINE arg and return error.
(register_commands): Use assuan_handler_t type.
sm/
2009-11-02 Marcus Brinkmann <marcus@g10code.de>
* server.c (reset_notify, input_notify, output_notify): Update to
new assuan interface.
(register_commands): Use assuan_handler_t.
* call-agent.c (membuf_data_cb, default_inq_cb)
(inq_ciphertext_cb, scd_serialno_status_cb)
(scd_keypairinfo_status_cb, istrusted_status_cb)
(learn_status_cb, learn_cb, keyinfo_status_cb): Return gpg_error_t.
2009-11-02 18:47:11 +01:00
|
|
|
|
static gpg_error_t
|
2003-08-05 19:11:04 +02:00
|
|
|
|
learn_cb (void *opaque, const void *buffer, size_t length)
|
|
|
|
|
{
|
|
|
|
|
struct learn_parm_s *parm = opaque;
|
|
|
|
|
size_t len;
|
|
|
|
|
char *buf;
|
2003-12-17 13:28:24 +01:00
|
|
|
|
ksba_cert_t cert;
|
2003-08-05 19:11:04 +02:00
|
|
|
|
int rc;
|
2022-02-03 14:14:14 +01:00
|
|
|
|
char *string, *p, *pend;
|
|
|
|
|
strlist_t sl;
|
2003-08-05 19:11:04 +02:00
|
|
|
|
|
|
|
|
|
if (parm->error)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
if (buffer)
|
|
|
|
|
{
|
|
|
|
|
put_membuf (parm->data, buffer, length);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
/* END encountered - process what we have */
|
|
|
|
|
buf = get_membuf (parm->data, &len);
|
|
|
|
|
if (!buf)
|
|
|
|
|
{
|
|
|
|
|
parm->error = gpg_error (GPG_ERR_ENOMEM);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-20 20:04:47 +01:00
|
|
|
|
if (gpgsm_status (parm->ctrl, STATUS_PROGRESS, "learncard C 0 0"))
|
|
|
|
|
return gpg_error (GPG_ERR_ASS_CANCELED);
|
2003-08-05 19:11:04 +02:00
|
|
|
|
|
|
|
|
|
/* FIXME: this should go into import.c */
|
2003-11-12 16:17:44 +01:00
|
|
|
|
rc = ksba_cert_new (&cert);
|
|
|
|
|
if (rc)
|
2003-08-05 19:11:04 +02:00
|
|
|
|
{
|
2003-11-12 16:17:44 +01:00
|
|
|
|
parm->error = rc;
|
2003-08-05 19:11:04 +02:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
rc = ksba_cert_init_from_mem (cert, buf, len);
|
|
|
|
|
if (rc)
|
|
|
|
|
{
|
2003-11-12 16:17:44 +01:00
|
|
|
|
log_error ("failed to parse a certificate: %s\n", gpg_strerror (rc));
|
2003-08-05 19:11:04 +02:00
|
|
|
|
ksba_cert_release (cert);
|
2003-11-12 16:17:44 +01:00
|
|
|
|
parm->error = rc;
|
2003-08-05 19:11:04 +02:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-03 14:14:14 +01:00
|
|
|
|
/* Ignore certificates matching certain extended usage flags. */
|
|
|
|
|
rc = ksba_cert_get_ext_key_usages (cert, &string);
|
|
|
|
|
if (!rc)
|
|
|
|
|
{
|
|
|
|
|
p = string;
|
|
|
|
|
while (p && (pend=strchr (p, ':')))
|
|
|
|
|
{
|
|
|
|
|
*pend++ = 0;
|
|
|
|
|
for (sl=opt.ignore_cert_with_oid;
|
|
|
|
|
sl && strcmp (sl->d, p); sl = sl->next)
|
|
|
|
|
;
|
|
|
|
|
if (sl)
|
|
|
|
|
{
|
|
|
|
|
if (opt.verbose)
|
|
|
|
|
log_info ("certificate ignored due to OID %s\n", sl->d);
|
|
|
|
|
goto leave;
|
|
|
|
|
}
|
|
|
|
|
p = pend;
|
|
|
|
|
if ((p = strchr (p, '\n')))
|
|
|
|
|
p++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (gpg_err_code (rc) != GPG_ERR_NO_DATA)
|
|
|
|
|
log_error (_("error getting key usage information: %s\n"),
|
|
|
|
|
gpg_strerror (rc));
|
|
|
|
|
xfree (string);
|
|
|
|
|
string = NULL;
|
|
|
|
|
|
|
|
|
|
|
2024-05-13 00:09:23 +02:00
|
|
|
|
/* We do not store a certificate with missing issuers as ephemeral
|
2009-07-30 18:45:06 +02:00
|
|
|
|
because we can assume that the --learn-card command has been used
|
|
|
|
|
on purpose. */
|
2008-02-13 17:47:14 +01:00
|
|
|
|
rc = gpgsm_basic_cert_check (parm->ctrl, cert);
|
2010-10-01 22:33:53 +02:00
|
|
|
|
if (rc && gpg_err_code (rc) != GPG_ERR_MISSING_CERT
|
|
|
|
|
&& gpg_err_code (rc) != GPG_ERR_MISSING_ISSUER_CERT)
|
2003-08-05 19:11:04 +02:00
|
|
|
|
log_error ("invalid certificate: %s\n", gpg_strerror (rc));
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
int existed;
|
|
|
|
|
|
2016-11-10 17:01:19 +01:00
|
|
|
|
if (!keydb_store_cert (parm->ctrl, cert, 0, &existed))
|
2003-08-05 19:11:04 +02:00
|
|
|
|
{
|
|
|
|
|
if (opt.verbose > 1 && existed)
|
|
|
|
|
log_info ("certificate already in DB\n");
|
|
|
|
|
else if (opt.verbose && !existed)
|
|
|
|
|
log_info ("certificate imported\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-03 14:14:14 +01:00
|
|
|
|
leave:
|
|
|
|
|
xfree (string);
|
|
|
|
|
string = NULL;
|
2003-08-05 19:11:04 +02:00
|
|
|
|
ksba_cert_release (cert);
|
|
|
|
|
init_membuf (parm->data, 4096);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2011-02-04 12:57:53 +01:00
|
|
|
|
|
2003-08-05 19:11:04 +02:00
|
|
|
|
/* Call the agent to learn about a smartcard */
|
|
|
|
|
int
|
2004-04-26 15:29:09 +02:00
|
|
|
|
gpgsm_agent_learn (ctrl_t ctrl)
|
2003-08-05 19:11:04 +02:00
|
|
|
|
{
|
|
|
|
|
int rc;
|
|
|
|
|
struct learn_parm_s learn_parm;
|
|
|
|
|
membuf_t data;
|
|
|
|
|
size_t len;
|
|
|
|
|
|
2004-04-26 15:29:09 +02:00
|
|
|
|
rc = start_agent (ctrl);
|
2003-08-05 19:11:04 +02:00
|
|
|
|
if (rc)
|
|
|
|
|
return rc;
|
|
|
|
|
|
2016-01-08 10:33:19 +01:00
|
|
|
|
rc = warn_version_mismatch (ctrl, agent_ctx, SCDAEMON_NAME, 2);
|
|
|
|
|
if (rc)
|
|
|
|
|
return rc;
|
|
|
|
|
|
2003-08-05 19:11:04 +02:00
|
|
|
|
init_membuf (&data, 4096);
|
|
|
|
|
learn_parm.error = 0;
|
2008-02-13 17:47:14 +01:00
|
|
|
|
learn_parm.ctrl = ctrl;
|
2003-08-05 19:11:04 +02:00
|
|
|
|
learn_parm.ctx = agent_ctx;
|
|
|
|
|
learn_parm.data = &data;
|
|
|
|
|
rc = assuan_transact (agent_ctx, "LEARN --send",
|
2011-02-04 12:57:53 +01:00
|
|
|
|
learn_cb, &learn_parm,
|
|
|
|
|
NULL, NULL,
|
2009-03-20 20:04:47 +01:00
|
|
|
|
learn_status_cb, &learn_parm);
|
2003-08-05 19:11:04 +02:00
|
|
|
|
xfree (get_membuf (&data, &len));
|
|
|
|
|
if (rc)
|
2006-09-06 18:35:52 +02:00
|
|
|
|
return rc;
|
2003-08-05 19:11:04 +02:00
|
|
|
|
return learn_parm.error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-02-21 14:05:52 +01:00
|
|
|
|
/* Ask the agent to change the passphrase of the key identified by
|
|
|
|
|
HEXKEYGRIP. If DESC is not NULL, display instead of the default
|
|
|
|
|
description message. */
|
2003-08-05 19:11:04 +02:00
|
|
|
|
int
|
2004-04-26 15:29:09 +02:00
|
|
|
|
gpgsm_agent_passwd (ctrl_t ctrl, const char *hexkeygrip, const char *desc)
|
2003-08-05 19:11:04 +02:00
|
|
|
|
{
|
|
|
|
|
int rc;
|
|
|
|
|
char line[ASSUAN_LINELENGTH];
|
2016-09-27 07:45:21 +02:00
|
|
|
|
struct default_inq_parm_s inq_parm;
|
2003-08-05 19:11:04 +02:00
|
|
|
|
|
2004-04-26 15:29:09 +02:00
|
|
|
|
rc = start_agent (ctrl);
|
2003-08-05 19:11:04 +02:00
|
|
|
|
if (rc)
|
|
|
|
|
return rc;
|
2016-09-27 07:45:21 +02:00
|
|
|
|
inq_parm.ctrl = ctrl;
|
|
|
|
|
inq_parm.ctx = agent_ctx;
|
2003-08-05 19:11:04 +02:00
|
|
|
|
|
|
|
|
|
if (!hexkeygrip || strlen (hexkeygrip) != 40)
|
|
|
|
|
return gpg_error (GPG_ERR_INV_VALUE);
|
|
|
|
|
|
2004-02-21 14:05:52 +01:00
|
|
|
|
if (desc)
|
|
|
|
|
{
|
Fix use cases of snprintf.
* agent/call-pinentry.c, agent/call-scd.c, agent/command.c,
build-aux/speedo/w32/g4wihelp.c, common/get-passphrase.c,
dirmngr/dirmngr.c, g10/call-agent.c, g10/cpr.c, g10/keygen.c,
g10/openfile.c, g10/passphrase.c, scd/app-openpgp.c, scd/scdaemon.c,
sm/call-agent.c, sm/call-dirmngr.c, sm/certreqgen.c: Fix assuming C99.
--
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2016-10-21 05:04:46 +02:00
|
|
|
|
snprintf (line, DIM(line), "SETKEYDESC %s", desc);
|
2004-02-21 14:05:52 +01:00
|
|
|
|
rc = assuan_transact (agent_ctx, line,
|
|
|
|
|
NULL, NULL, NULL, NULL, NULL, NULL);
|
|
|
|
|
if (rc)
|
2006-09-06 18:35:52 +02:00
|
|
|
|
return rc;
|
2004-02-21 14:05:52 +01:00
|
|
|
|
}
|
|
|
|
|
|
Fix use cases of snprintf.
* agent/call-pinentry.c, agent/call-scd.c, agent/command.c,
build-aux/speedo/w32/g4wihelp.c, common/get-passphrase.c,
dirmngr/dirmngr.c, g10/call-agent.c, g10/cpr.c, g10/keygen.c,
g10/openfile.c, g10/passphrase.c, scd/app-openpgp.c, scd/scdaemon.c,
sm/call-agent.c, sm/call-dirmngr.c, sm/certreqgen.c: Fix assuming C99.
--
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2016-10-21 05:04:46 +02:00
|
|
|
|
snprintf (line, DIM(line), "PASSWD %s", hexkeygrip);
|
2003-08-05 19:11:04 +02:00
|
|
|
|
|
2008-02-14 20:50:10 +01:00
|
|
|
|
rc = assuan_transact (agent_ctx, line, NULL, NULL,
|
2016-03-07 18:09:41 +01:00
|
|
|
|
default_inq_cb, &inq_parm, NULL, NULL);
|
2006-09-06 18:35:52 +02:00
|
|
|
|
return rc;
|
2003-08-05 19:11:04 +02:00
|
|
|
|
}
|
|
|
|
|
|
2005-11-13 20:07:06 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Ask the agent to pop up a confirmation dialog with the text DESC
|
|
|
|
|
and an okay and cancel button. */
|
|
|
|
|
gpg_error_t
|
|
|
|
|
gpgsm_agent_get_confirmation (ctrl_t ctrl, const char *desc)
|
|
|
|
|
{
|
|
|
|
|
int rc;
|
|
|
|
|
char line[ASSUAN_LINELENGTH];
|
2016-09-27 07:45:21 +02:00
|
|
|
|
struct default_inq_parm_s inq_parm;
|
2005-11-13 20:07:06 +01:00
|
|
|
|
|
|
|
|
|
rc = start_agent (ctrl);
|
|
|
|
|
if (rc)
|
|
|
|
|
return rc;
|
2016-09-27 07:45:21 +02:00
|
|
|
|
inq_parm.ctrl = ctrl;
|
|
|
|
|
inq_parm.ctx = agent_ctx;
|
2005-11-13 20:07:06 +01:00
|
|
|
|
|
Fix use cases of snprintf.
* agent/call-pinentry.c, agent/call-scd.c, agent/command.c,
build-aux/speedo/w32/g4wihelp.c, common/get-passphrase.c,
dirmngr/dirmngr.c, g10/call-agent.c, g10/cpr.c, g10/keygen.c,
g10/openfile.c, g10/passphrase.c, scd/app-openpgp.c, scd/scdaemon.c,
sm/call-agent.c, sm/call-dirmngr.c, sm/certreqgen.c: Fix assuming C99.
--
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2016-10-21 05:04:46 +02:00
|
|
|
|
snprintf (line, DIM(line), "GET_CONFIRMATION %s", desc);
|
2005-11-13 20:07:06 +01:00
|
|
|
|
|
2008-02-14 20:50:10 +01:00
|
|
|
|
rc = assuan_transact (agent_ctx, line, NULL, NULL,
|
2016-03-07 18:09:41 +01:00
|
|
|
|
default_inq_cb, &inq_parm, NULL, NULL);
|
2006-09-06 18:35:52 +02:00
|
|
|
|
return rc;
|
2005-11-13 20:07:06 +01:00
|
|
|
|
}
|
2008-09-30 12:30:20 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Return 0 if the agent is alive. This is useful to make sure that
|
|
|
|
|
an agent has been started. */
|
|
|
|
|
gpg_error_t
|
|
|
|
|
gpgsm_agent_send_nop (ctrl_t ctrl)
|
|
|
|
|
{
|
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
|
|
rc = start_agent (ctrl);
|
|
|
|
|
if (!rc)
|
|
|
|
|
rc = assuan_transact (agent_ctx, "NOP",
|
|
|
|
|
NULL, NULL, NULL, NULL, NULL, NULL);
|
|
|
|
|
return rc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2009-03-06 18:31:27 +01:00
|
|
|
|
|
agent/
2009-11-02 Marcus Brinkmann <marcus@g10code.de>
* command.c (reset_notify): Take LINE arg and return error.
(register_commands): Use assuan_handler_t type.
common/
2009-11-02 Marcus Brinkmann <marcus@g10code.de>
* get-passphrase.c (default_inq_cb, membuf_data_cb): Change return
type to gpg_error_t.
g10/
2009-11-02 Marcus Brinkmann <marcus@g10code.de>
* server.c (reset_notify, input_notify, output_notify): Update to
new assuan interface.
(register_commands): Use assuan_handler_t.
scd/
2009-11-02 Marcus Brinkmann <marcus@g10code.de>
* command.c (reset_notify): Take LINE arg and return error.
(register_commands): Use assuan_handler_t type.
sm/
2009-11-02 Marcus Brinkmann <marcus@g10code.de>
* server.c (reset_notify, input_notify, output_notify): Update to
new assuan interface.
(register_commands): Use assuan_handler_t.
* call-agent.c (membuf_data_cb, default_inq_cb)
(inq_ciphertext_cb, scd_serialno_status_cb)
(scd_keypairinfo_status_cb, istrusted_status_cb)
(learn_status_cb, learn_cb, keyinfo_status_cb): Return gpg_error_t.
2009-11-02 18:47:11 +01:00
|
|
|
|
static gpg_error_t
|
2009-03-06 18:31:27 +01:00
|
|
|
|
keyinfo_status_cb (void *opaque, const char *line)
|
|
|
|
|
{
|
|
|
|
|
char **serialno = opaque;
|
|
|
|
|
const char *s, *s2;
|
|
|
|
|
|
Use has_leading_keyword in the assuan callbacks.
* agent/call-pinentry.c (inq_quality): Use has_leading_keyword.
* agent/call-scd.c (inq_needpin, inq_writekey_parms): Ditto.
* g10/call-agent.c (inq_writecert_parms, keyinfo_status_cb): Ditto.
(inq_genkey_parms, inq_ciphertext_cb, inq_import_key_parms): Ditto.
* g10/call-dirmngr.c (ks_put_inq_cb): Ditto.
* sm/call-agent.c (default_inq_cb, inq_ciphertext_cb): Ditto.
(inq_genkey_parms, istrusted_status_cb, learn_status_cb): Ditto.
(keyinfo_status_cb, inq_import_key_parms): Ditto.
* sm/call-dirmngr.c (inq_certificate, isvalid_status_cb): Ditto.
(lookup_status_cb, run_command_inq_cb, run_command_status_cb): Ditto.
2013-02-22 10:56:13 +01:00
|
|
|
|
if ((s = has_leading_keyword (line, "KEYINFO")) && !*serialno)
|
2009-03-06 18:31:27 +01:00
|
|
|
|
{
|
Use has_leading_keyword in the assuan callbacks.
* agent/call-pinentry.c (inq_quality): Use has_leading_keyword.
* agent/call-scd.c (inq_needpin, inq_writekey_parms): Ditto.
* g10/call-agent.c (inq_writecert_parms, keyinfo_status_cb): Ditto.
(inq_genkey_parms, inq_ciphertext_cb, inq_import_key_parms): Ditto.
* g10/call-dirmngr.c (ks_put_inq_cb): Ditto.
* sm/call-agent.c (default_inq_cb, inq_ciphertext_cb): Ditto.
(inq_genkey_parms, istrusted_status_cb, learn_status_cb): Ditto.
(keyinfo_status_cb, inq_import_key_parms): Ditto.
* sm/call-dirmngr.c (inq_certificate, isvalid_status_cb): Ditto.
(lookup_status_cb, run_command_inq_cb, run_command_status_cb): Ditto.
2013-02-22 10:56:13 +01:00
|
|
|
|
s = strchr (s, ' ');
|
2009-03-06 18:31:27 +01:00
|
|
|
|
if (s && s[1] == 'T' && s[2] == ' ' && s[3])
|
|
|
|
|
{
|
|
|
|
|
s += 3;
|
|
|
|
|
s2 = strchr (s, ' ');
|
|
|
|
|
if ( s2 > s )
|
|
|
|
|
{
|
|
|
|
|
*serialno = xtrymalloc ((s2 - s)+1);
|
|
|
|
|
if (*serialno)
|
|
|
|
|
{
|
|
|
|
|
memcpy (*serialno, s, s2 - s);
|
|
|
|
|
(*serialno)[s2 - s] = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Return the serial number for a secret key. If the returned serial
|
|
|
|
|
number is NULL, the key is not stored on a smartcard. Caller needs
|
|
|
|
|
to free R_SERIALNO. */
|
|
|
|
|
gpg_error_t
|
|
|
|
|
gpgsm_agent_keyinfo (ctrl_t ctrl, const char *hexkeygrip, char **r_serialno)
|
|
|
|
|
{
|
|
|
|
|
gpg_error_t err;
|
|
|
|
|
char line[ASSUAN_LINELENGTH];
|
|
|
|
|
char *serialno = NULL;
|
|
|
|
|
|
|
|
|
|
*r_serialno = NULL;
|
|
|
|
|
|
|
|
|
|
err = start_agent (ctrl);
|
|
|
|
|
if (err)
|
|
|
|
|
return err;
|
|
|
|
|
|
|
|
|
|
if (!hexkeygrip || strlen (hexkeygrip) != 40)
|
|
|
|
|
return gpg_error (GPG_ERR_INV_VALUE);
|
|
|
|
|
|
Fix use cases of snprintf.
* agent/call-pinentry.c, agent/call-scd.c, agent/command.c,
build-aux/speedo/w32/g4wihelp.c, common/get-passphrase.c,
dirmngr/dirmngr.c, g10/call-agent.c, g10/cpr.c, g10/keygen.c,
g10/openfile.c, g10/passphrase.c, scd/app-openpgp.c, scd/scdaemon.c,
sm/call-agent.c, sm/call-dirmngr.c, sm/certreqgen.c: Fix assuming C99.
--
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2016-10-21 05:04:46 +02:00
|
|
|
|
snprintf (line, DIM(line), "KEYINFO %s", hexkeygrip);
|
2009-03-06 18:31:27 +01:00
|
|
|
|
|
|
|
|
|
err = assuan_transact (agent_ctx, line, NULL, NULL, NULL, NULL,
|
|
|
|
|
keyinfo_status_cb, &serialno);
|
|
|
|
|
if (!err && serialno)
|
|
|
|
|
{
|
|
|
|
|
/* Sanity check for bad characters. */
|
|
|
|
|
if (strpbrk (serialno, ":\n\r"))
|
|
|
|
|
err = GPG_ERR_INV_VALUE;
|
|
|
|
|
}
|
|
|
|
|
if (err)
|
|
|
|
|
xfree (serialno);
|
|
|
|
|
else
|
|
|
|
|
*r_serialno = serialno;
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-17 17:44:44 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Ask for the passphrase (this is used for pkcs#12 import/export. On
|
|
|
|
|
success the caller needs to free the string stored at R_PASSPHRASE.
|
|
|
|
|
On error NULL will be stored at R_PASSPHRASE and an appropriate
|
2010-06-21 12:01:24 +02:00
|
|
|
|
error code returned. If REPEAT is true the agent tries to get a
|
|
|
|
|
new passphrase (i.e. asks the user to confirm it). */
|
2010-06-17 17:44:44 +02:00
|
|
|
|
gpg_error_t
|
2010-06-21 12:01:24 +02:00
|
|
|
|
gpgsm_agent_ask_passphrase (ctrl_t ctrl, const char *desc_msg, int repeat,
|
2010-06-17 17:44:44 +02:00
|
|
|
|
char **r_passphrase)
|
|
|
|
|
{
|
|
|
|
|
gpg_error_t err;
|
|
|
|
|
char line[ASSUAN_LINELENGTH];
|
|
|
|
|
char *arg4 = NULL;
|
|
|
|
|
membuf_t data;
|
2016-09-27 07:45:21 +02:00
|
|
|
|
struct default_inq_parm_s inq_parm;
|
2023-11-14 15:08:20 +01:00
|
|
|
|
int wasconf;
|
2010-06-17 17:44:44 +02:00
|
|
|
|
|
|
|
|
|
*r_passphrase = NULL;
|
|
|
|
|
|
|
|
|
|
err = start_agent (ctrl);
|
|
|
|
|
if (err)
|
|
|
|
|
return err;
|
2016-09-27 07:45:21 +02:00
|
|
|
|
inq_parm.ctrl = ctrl;
|
|
|
|
|
inq_parm.ctx = agent_ctx;
|
2010-06-17 17:44:44 +02:00
|
|
|
|
|
|
|
|
|
if (desc_msg && *desc_msg && !(arg4 = percent_plus_escape (desc_msg)))
|
|
|
|
|
return gpg_error_from_syserror ();
|
2011-02-04 12:57:53 +01:00
|
|
|
|
|
Fix use cases of snprintf.
* agent/call-pinentry.c, agent/call-scd.c, agent/command.c,
build-aux/speedo/w32/g4wihelp.c, common/get-passphrase.c,
dirmngr/dirmngr.c, g10/call-agent.c, g10/cpr.c, g10/keygen.c,
g10/openfile.c, g10/passphrase.c, scd/app-openpgp.c, scd/scdaemon.c,
sm/call-agent.c, sm/call-dirmngr.c, sm/certreqgen.c: Fix assuming C99.
--
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2016-10-21 05:04:46 +02:00
|
|
|
|
snprintf (line, DIM(line), "GET_PASSPHRASE --data%s -- X X X %s",
|
2020-07-08 14:54:10 +02:00
|
|
|
|
repeat? " --repeat=1 --check":"",
|
2010-06-21 12:01:24 +02:00
|
|
|
|
arg4);
|
2010-06-17 17:44:44 +02:00
|
|
|
|
xfree (arg4);
|
|
|
|
|
|
|
|
|
|
init_membuf_secure (&data, 64);
|
2023-11-14 15:08:20 +01:00
|
|
|
|
wasconf = assuan_get_flag (agent_ctx, ASSUAN_CONFIDENTIAL);
|
|
|
|
|
assuan_begin_confidential (agent_ctx);
|
2011-02-04 12:57:53 +01:00
|
|
|
|
err = assuan_transact (agent_ctx, line,
|
2016-01-08 06:33:27 +01:00
|
|
|
|
put_membuf_cb, &data,
|
2016-03-07 18:09:41 +01:00
|
|
|
|
default_inq_cb, &inq_parm, NULL, NULL);
|
2023-11-14 15:08:20 +01:00
|
|
|
|
if (!wasconf)
|
|
|
|
|
assuan_end_confidential (agent_ctx);
|
2010-06-17 17:44:44 +02:00
|
|
|
|
|
|
|
|
|
if (err)
|
|
|
|
|
xfree (get_membuf (&data, NULL));
|
2011-02-04 12:57:53 +01:00
|
|
|
|
else
|
2010-06-17 17:44:44 +02:00
|
|
|
|
{
|
|
|
|
|
put_membuf (&data, "", 1);
|
|
|
|
|
*r_passphrase = get_membuf (&data, NULL);
|
|
|
|
|
if (!*r_passphrase)
|
|
|
|
|
err = gpg_error_from_syserror ();
|
|
|
|
|
}
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Retrieve a key encryption key from the agent. With FOREXPORT true
|
|
|
|
|
the key shall be use for export, with false for import. On success
|
|
|
|
|
the new key is stored at R_KEY and its length at R_KEKLEN. */
|
|
|
|
|
gpg_error_t
|
|
|
|
|
gpgsm_agent_keywrap_key (ctrl_t ctrl, int forexport,
|
|
|
|
|
void **r_kek, size_t *r_keklen)
|
|
|
|
|
{
|
|
|
|
|
gpg_error_t err;
|
|
|
|
|
membuf_t data;
|
|
|
|
|
size_t len;
|
|
|
|
|
unsigned char *buf;
|
|
|
|
|
char line[ASSUAN_LINELENGTH];
|
2016-09-27 07:45:21 +02:00
|
|
|
|
struct default_inq_parm_s inq_parm;
|
2010-06-17 17:44:44 +02:00
|
|
|
|
|
|
|
|
|
*r_kek = NULL;
|
|
|
|
|
err = start_agent (ctrl);
|
|
|
|
|
if (err)
|
|
|
|
|
return err;
|
2016-09-27 07:45:21 +02:00
|
|
|
|
inq_parm.ctrl = ctrl;
|
|
|
|
|
inq_parm.ctx = agent_ctx;
|
2010-06-17 17:44:44 +02:00
|
|
|
|
|
Fix use cases of snprintf.
* agent/call-pinentry.c, agent/call-scd.c, agent/command.c,
build-aux/speedo/w32/g4wihelp.c, common/get-passphrase.c,
dirmngr/dirmngr.c, g10/call-agent.c, g10/cpr.c, g10/keygen.c,
g10/openfile.c, g10/passphrase.c, scd/app-openpgp.c, scd/scdaemon.c,
sm/call-agent.c, sm/call-dirmngr.c, sm/certreqgen.c: Fix assuming C99.
--
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2016-10-21 05:04:46 +02:00
|
|
|
|
snprintf (line, DIM(line), "KEYWRAP_KEY %s",
|
2010-06-17 17:44:44 +02:00
|
|
|
|
forexport? "--export":"--import");
|
|
|
|
|
|
|
|
|
|
init_membuf_secure (&data, 64);
|
|
|
|
|
err = assuan_transact (agent_ctx, line,
|
2016-01-08 06:33:27 +01:00
|
|
|
|
put_membuf_cb, &data,
|
2016-03-07 18:09:41 +01:00
|
|
|
|
default_inq_cb, &inq_parm, NULL, NULL);
|
2010-06-17 17:44:44 +02:00
|
|
|
|
if (err)
|
|
|
|
|
{
|
|
|
|
|
xfree (get_membuf (&data, &len));
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
buf = get_membuf (&data, &len);
|
|
|
|
|
if (!buf)
|
|
|
|
|
return gpg_error_from_syserror ();
|
|
|
|
|
*r_kek = buf;
|
|
|
|
|
*r_keklen = len;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Handle the inquiry for an IMPORT_KEY command. */
|
|
|
|
|
static gpg_error_t
|
|
|
|
|
inq_import_key_parms (void *opaque, const char *line)
|
|
|
|
|
{
|
2011-02-04 12:57:53 +01:00
|
|
|
|
struct import_key_parm_s *parm = opaque;
|
2010-06-17 17:44:44 +02:00
|
|
|
|
gpg_error_t err;
|
|
|
|
|
|
Use has_leading_keyword in the assuan callbacks.
* agent/call-pinentry.c (inq_quality): Use has_leading_keyword.
* agent/call-scd.c (inq_needpin, inq_writekey_parms): Ditto.
* g10/call-agent.c (inq_writecert_parms, keyinfo_status_cb): Ditto.
(inq_genkey_parms, inq_ciphertext_cb, inq_import_key_parms): Ditto.
* g10/call-dirmngr.c (ks_put_inq_cb): Ditto.
* sm/call-agent.c (default_inq_cb, inq_ciphertext_cb): Ditto.
(inq_genkey_parms, istrusted_status_cb, learn_status_cb): Ditto.
(keyinfo_status_cb, inq_import_key_parms): Ditto.
* sm/call-dirmngr.c (inq_certificate, isvalid_status_cb): Ditto.
(lookup_status_cb, run_command_inq_cb, run_command_status_cb): Ditto.
2013-02-22 10:56:13 +01:00
|
|
|
|
if (has_leading_keyword (line, "KEYDATA"))
|
2010-06-17 17:44:44 +02:00
|
|
|
|
{
|
|
|
|
|
assuan_begin_confidential (parm->ctx);
|
|
|
|
|
err = assuan_send_data (parm->ctx, parm->key, parm->keylen);
|
|
|
|
|
assuan_end_confidential (parm->ctx);
|
|
|
|
|
}
|
|
|
|
|
else
|
2016-03-07 18:09:41 +01:00
|
|
|
|
{
|
|
|
|
|
struct default_inq_parm_s inq_parm = { parm->ctrl, parm->ctx };
|
|
|
|
|
err = default_inq_cb (&inq_parm, line);
|
|
|
|
|
}
|
2010-06-17 17:44:44 +02:00
|
|
|
|
|
2011-02-04 12:57:53 +01:00
|
|
|
|
return err;
|
2010-06-17 17:44:44 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Call the agent to import a key into the agent. */
|
|
|
|
|
gpg_error_t
|
|
|
|
|
gpgsm_agent_import_key (ctrl_t ctrl, const void *key, size_t keylen)
|
|
|
|
|
{
|
|
|
|
|
gpg_error_t err;
|
|
|
|
|
struct import_key_parm_s parm;
|
2020-08-19 13:43:16 +02:00
|
|
|
|
gnupg_isotime_t timebuf;
|
|
|
|
|
char line[ASSUAN_LINELENGTH];
|
2010-06-17 17:44:44 +02:00
|
|
|
|
|
|
|
|
|
err = start_agent (ctrl);
|
|
|
|
|
if (err)
|
|
|
|
|
return err;
|
|
|
|
|
|
|
|
|
|
parm.ctrl = ctrl;
|
|
|
|
|
parm.ctx = agent_ctx;
|
|
|
|
|
parm.key = key;
|
|
|
|
|
parm.keylen = keylen;
|
|
|
|
|
|
2020-08-19 13:43:16 +02:00
|
|
|
|
gnupg_get_isotime (timebuf);
|
|
|
|
|
snprintf (line, sizeof line, "IMPORT_KEY --timestamp=%s", timebuf);
|
|
|
|
|
err = assuan_transact (agent_ctx, line,
|
2010-06-17 17:44:44 +02:00
|
|
|
|
NULL, NULL, inq_import_key_parms, &parm, NULL, NULL);
|
|
|
|
|
return err;
|
|
|
|
|
}
|
2010-06-21 12:01:24 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Receive a secret key from the agent. KEYGRIP is the hexified
|
|
|
|
|
keygrip, DESC a prompt to be displayed with the agent's passphrase
|
|
|
|
|
question (needs to be plus+percent escaped). On success the key is
|
|
|
|
|
stored as a canonical S-expression at R_RESULT and R_RESULTLEN. */
|
|
|
|
|
gpg_error_t
|
|
|
|
|
gpgsm_agent_export_key (ctrl_t ctrl, const char *keygrip, const char *desc,
|
|
|
|
|
unsigned char **r_result, size_t *r_resultlen)
|
|
|
|
|
{
|
|
|
|
|
gpg_error_t err;
|
|
|
|
|
membuf_t data;
|
|
|
|
|
size_t len;
|
|
|
|
|
unsigned char *buf;
|
|
|
|
|
char line[ASSUAN_LINELENGTH];
|
2016-09-27 07:45:21 +02:00
|
|
|
|
struct default_inq_parm_s inq_parm;
|
2010-06-21 12:01:24 +02:00
|
|
|
|
|
|
|
|
|
*r_result = NULL;
|
|
|
|
|
|
|
|
|
|
err = start_agent (ctrl);
|
|
|
|
|
if (err)
|
|
|
|
|
return err;
|
2016-09-27 07:45:21 +02:00
|
|
|
|
inq_parm.ctrl = ctrl;
|
|
|
|
|
inq_parm.ctx = agent_ctx;
|
2010-06-21 12:01:24 +02:00
|
|
|
|
|
|
|
|
|
if (desc)
|
|
|
|
|
{
|
Fix use cases of snprintf.
* agent/call-pinentry.c, agent/call-scd.c, agent/command.c,
build-aux/speedo/w32/g4wihelp.c, common/get-passphrase.c,
dirmngr/dirmngr.c, g10/call-agent.c, g10/cpr.c, g10/keygen.c,
g10/openfile.c, g10/passphrase.c, scd/app-openpgp.c, scd/scdaemon.c,
sm/call-agent.c, sm/call-dirmngr.c, sm/certreqgen.c: Fix assuming C99.
--
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2016-10-21 05:04:46 +02:00
|
|
|
|
snprintf (line, DIM(line), "SETKEYDESC %s", desc);
|
2010-06-21 12:01:24 +02:00
|
|
|
|
err = assuan_transact (agent_ctx, line,
|
|
|
|
|
NULL, NULL, NULL, NULL, NULL, NULL);
|
|
|
|
|
if (err)
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
Fix use cases of snprintf.
* agent/call-pinentry.c, agent/call-scd.c, agent/command.c,
build-aux/speedo/w32/g4wihelp.c, common/get-passphrase.c,
dirmngr/dirmngr.c, g10/call-agent.c, g10/cpr.c, g10/keygen.c,
g10/openfile.c, g10/passphrase.c, scd/app-openpgp.c, scd/scdaemon.c,
sm/call-agent.c, sm/call-dirmngr.c, sm/certreqgen.c: Fix assuming C99.
--
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2016-10-21 05:04:46 +02:00
|
|
|
|
snprintf (line, DIM(line), "EXPORT_KEY %s", keygrip);
|
2010-06-21 12:01:24 +02:00
|
|
|
|
|
|
|
|
|
init_membuf_secure (&data, 1024);
|
|
|
|
|
err = assuan_transact (agent_ctx, line,
|
2016-01-08 06:33:27 +01:00
|
|
|
|
put_membuf_cb, &data,
|
2016-03-07 18:09:41 +01:00
|
|
|
|
default_inq_cb, &inq_parm, NULL, NULL);
|
2010-06-21 12:01:24 +02:00
|
|
|
|
if (err)
|
|
|
|
|
{
|
|
|
|
|
xfree (get_membuf (&data, &len));
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
buf = get_membuf (&data, &len);
|
|
|
|
|
if (!buf)
|
|
|
|
|
return gpg_error_from_syserror ();
|
|
|
|
|
*r_result = buf;
|
|
|
|
|
*r_resultlen = len;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|