Exemplo n.º 1
0
static
PKCS11H_BOOL
pkcs11_pin_prompt_hook (
	void * const global_data,
	void * const user_data,
	const pkcs11h_token_id_t token,
	const unsigned retry,
	char * const pin,
	const size_t max_pin
) {
	char cmd[1024];
	assuan_context_t ctx = user_data;
	unsigned char *pin_read = NULL;
	size_t pin_len;
	int rc;
	int ret = FALSE;

	(void)global_data;

	snprintf (
		cmd,
		sizeof(cmd),
		"NEEDPIN PIN required for token '%s' (try %u)",
		token->display,
		retry
	);

	if ((rc = assuan_inquire (ctx, cmd, &pin_read, &pin_len, 1024))) {
		common_log (LOG_WARNING,"PIN inquire error: %d", rc);
		goto cleanup;
	}

	if (pin_len==0 || (pin_len+1 > max_pin)) {
		goto cleanup;
	}

	strcpy (pin, (char *)pin_read);

	ret = TRUE;

cleanup:

	if (pin_read != NULL) {
		memset (pin_read, 0, strlen ((char *)pin_read));
		free (pin_read);
		pin_read = NULL;
	}

	return ret;
}
Exemplo n.º 2
0
static
PKCS11H_BOOL
pkcs11_token_prompt_hook (
	void * const global_data,
	void * const user_data,
	const pkcs11h_token_id_t token,
	const unsigned retry
) {
	char cmd[1024];
	unsigned char *user_read = NULL;
	size_t user_read_len = 0;
	assuan_context_t ctx = user_data;
	int rc;
	int ret = FALSE;

	(void)global_data;
	(void)retry;

	snprintf (
		cmd,
		sizeof(cmd),
		"NEEDPIN Please insert token '%s' !!!DO NOT ENTER PIN HERE!!!!",
		token->display
	);

	if ((rc = assuan_inquire (ctx, cmd, &user_read, &user_read_len, 1024))) {
		common_log (LOG_WARNING, "Token inquire error: %d", rc);
		goto cleanup;
	}

	if (!strcmp ((char *)user_read, "cancel")) {
		goto cleanup;
	}

	ret = TRUE;

cleanup:

	if (user_read != NULL) {
		memset (user_read, 0, strlen ((char *)user_read));
		free (user_read);
		user_read = NULL;
	}

	return ret;
}
Exemplo n.º 3
0
/* Helper to notify the client about Pinentry events.  Because that
   might disturb some older clients, this is only done when enabled
   via an option.  If it is not enabled we tell Windows to allow
   setting the foreground window right here.  Returns an gpg error
   code. */
gpg_error_t
gpg_proxy_pinentry_notify (ctrl_t ctrl, const unsigned char *line)
{
  if (!ctrl || !ctrl->server_local
      || !ctrl->server_local->allow_pinentry_notify)
    {
      gnupg_allow_set_foregound_window ((pid_t)strtoul (line+17, NULL, 10));
      /* Client might be interested in that event - send as status line.  */
      if (!strncmp (line, "PINENTRY_LAUNCHED", 17)
          && (line[17]==' '||!line[17]))
        {
          for (line += 17; *line && spacep (line); line++)
            ;
          write_status_text (STATUS_PINENTRY_LAUNCHED, line);
        }
      return 0;
    }
  return assuan_inquire (ctrl->server_local->assuan_ctx, line, NULL, NULL, 0);
}
Exemplo n.º 4
0
/* Handle the NEEDPIN inquiry. */
static gpg_error_t
inq_needpin (void *opaque, const char *line)
{
  struct inq_needpin_s *parm = opaque;
  const char *s;
  char *pin;
  size_t pinlen;
  int rc;

  parm->any_inq_seen = 1;
  if ((s = has_leading_keyword (line, "NEEDPIN")))
    {
      line = s;
      pinlen = 90;
      pin = gcry_malloc_secure (pinlen);
      if (!pin)
        return out_of_core ();

      rc = parm->getpin_cb (parm->getpin_cb_arg, line, pin, pinlen);
      if (!rc)
        rc = assuan_send_data (parm->ctx, pin, pinlen);
      xfree (pin);
    }
  else if ((s = has_leading_keyword (line, "POPUPPINPADPROMPT")))
    {
      rc = parm->getpin_cb (parm->getpin_cb_arg, s, NULL, 1);
    }
  else if ((s = has_leading_keyword (line, "DISMISSPINPADPROMPT")))
    {
      rc = parm->getpin_cb (parm->getpin_cb_arg, "", NULL, 0);
    }
  else if (parm->passthru)
    {
      unsigned char *value;
      size_t valuelen;
      int rest;
      int needrest = !strncmp (line, "KEYDATA", 8);

      /* Pass the inquiry up to our caller.  We limit the maximum
         amount to an arbitrary value.  As we know that the KEYDATA
         enquiry is pretty sensitive we disable logging then */
      if ((rest = (needrest
                   && !assuan_get_flag (parm->passthru, ASSUAN_CONFIDENTIAL))))
        assuan_begin_confidential (parm->passthru);
      rc = assuan_inquire (parm->passthru, line, &value, &valuelen, 8096);
      if (rest)
        assuan_end_confidential (parm->passthru);
      if (!rc)
        {
          if ((rest = (needrest
                       && !assuan_get_flag (parm->ctx, ASSUAN_CONFIDENTIAL))))
            assuan_begin_confidential (parm->ctx);
          rc = assuan_send_data (parm->ctx, value, valuelen);
          if (rest)
            assuan_end_confidential (parm->ctx);
          xfree (value);
        }
      else
        log_error ("error forwarding inquiry '%s': %s\n",
                   line, gpg_strerror (rc));
    }
  else
    {
      log_error ("unsupported inquiry '%s'\n", line);
      rc = gpg_error (GPG_ERR_ASS_UNKNOWN_INQUIRE);
    }

  return rc;
}