Beispiel #1
0
static void
do_get_string( int mode, const char *keyword, byte *area, size_t areasize )
{
    size_t n, len;
    char *p=NULL;
    int yes=0;

    n = area[0] << 8 | area[1];
    /* fixme: do some sanity checks here */
    if( mode == 1 )
	p = tty_get( keyword );
    else if( mode == 3 )
	p = tty_get_hidden( keyword );
    else
	yes = tty_get_answer_is_yes( keyword );
    if( p ) {
	len = strlen(p);
	memcpy( area+n+2, p, len );
	area[n] = len >> 8;
	area[n+1] = len;
	xfree(p);
    }
    else { /* bool */
Beispiel #2
0
/* Query the card, show a list of already stored keys and ask the user
   where to store the key.  Returns the key number or 0 for cancel
   operation. */
static int
query_card (APP app)
{
  int keyno = 0;
  char *serialno, *disp_name, *pubkey_url;
  unsigned char *fpr1, *fpr2, *fpr3;


  if (app_openpgp_cardinfo (app,
                            &serialno,
                            &disp_name,
                            &pubkey_url,
                            &fpr1, &fpr2, &fpr3))
    return 0;


  for (;;)
    {
      char *answer;

      tty_printf ("\n");

      tty_printf ("Serial number ....: %s\n",
                  serialno? serialno : "[none]");
      tty_printf ("Name of cardholder: %s\n",
                  disp_name && *disp_name? disp_name : "[not set]");
      tty_printf ("URL of public key : %s\n",
                  pubkey_url && *pubkey_url? pubkey_url : "[not set]");
      tty_printf ("Signature key ....:");
      show_sha1_fpr (fpr1);
      tty_printf ("Encryption key....:");
      show_sha1_fpr (fpr2);
      tty_printf ("Authentication key:");
      show_sha1_fpr (fpr3);

      tty_printf ("\n"
                  "1 - store as signature key and reset usage counter\n"
                  "2 - store as encryption key\n"
                  "3 - store as authentication key\n"
                  "Q - quit\n"
                  "\n");

      answer = tty_get("Your selection? ");
      tty_kill_prompt();
      if (strlen (answer) != 1)
        ;
      else if ( *answer == '1' )
        {
          if ( (fpr1 && !fpr_is_zero (fpr1)) )
            {
              tty_printf ("\n");
              log_error ("WARNING: signature key does already exists!\n");
              tty_printf ("\n");
              if ( tty_get_answer_is_yes ("Replace existing key? ") )
                {
                  keyno = 1;
                  break;
                }
            }
          else
            {
              keyno = 1;
              break;
            }
        }
      else if ( *answer == '2' )
        {
          if ( (fpr2 && !fpr_is_zero (fpr2)) )
            {
              tty_printf ("\n");
              log_error ("WARNING: encryption key does already exists!\n");
              tty_printf ("\n");
              if ( tty_get_answer_is_yes ("Replace existing key? ") )
                {
                  keyno = 2;
                  break;
                }
            }
          else
            {
              keyno = 2;
              break;
            }
        }
      else if ( *answer == '3' )
        {
          if ( (fpr3 && !fpr_is_zero (fpr3)) )
            {
              tty_printf ("\n");
              log_error ("WARNING: authentication key does already exists!\n");
              tty_printf ("\n");
              if ( tty_get_answer_is_yes ("Replace existing key? ") )
                {
                  keyno = 3;
                  break;
                }
            }
          else
            {
              keyno = 3;
              break;
            }
        }
      else if ( *answer == 'q' || *answer == 'Q')
        {
          keyno = 0;
          break;
        }
    }

  xfree (serialno);
  xfree (disp_name);
  xfree (pubkey_url);
  xfree (fpr1);
  xfree (fpr2);
  xfree (fpr3);

  return keyno;
}