コード例 #1
0
ファイル: pinentry-gtk-2.c プロジェクト: abeluck/pinentry
int
main (int argc, char *argv[])
{
  static GMemVTable secure_mem =
    {
      secentry_malloc,
      secentry_realloc,
      secentry_free,
      NULL,
      NULL,
      NULL
    };

  g_mem_set_vtable (&secure_mem);

  pinentry_init (PGMNAME);

#ifdef FALLBACK_CURSES
  if (pinentry_have_display (argc, argv))
    gtk_init (&argc, &argv);
  else
    pinentry_cmd_handler = curses_cmd_handler;
#else
  gtk_init (&argc, &argv);
#endif

  /* Consumes all arguments.  */
  if (pinentry_parse_opts (argc, argv))
    {
      printf(PGMNAME " " VERSION "\n");
      exit(EXIT_SUCCESS);
    }

  if (pinentry_loop ())
    return 1;

  return 0;
}
コード例 #2
0
JNIEXPORT void JNICALL
Java_info_guardianproject_gpg_pinentry_PinentryDialog_connectToGpgAgent ( JNIEnv * env, jobject self, jint app_uid ) {
    int in, out, sock;

    _ctx.env = env;
    pe_activity_init(&_ctx, self);
    pe_get_internal_gnupghome(&_ctx);

    sock = connect_helper( app_uid );
    if( sock < 0 ) {
        LOGE("connectToGpgAgent aborting");
        return;
    }

    /*
     * we make sure we've connected to the correct server by checking that the
     * app_uid we passed (from our starting Intent) is the same uid of our peer.
     * This should always succeed, and doesn't provide any assurance we're NOT
     * connected to a malicious pinentry, but we check it because we can.
     * If it does fail, something incredibly janky is going on
     */
    struct ucred credentials;
    int ucred_length = sizeof( struct ucred );
    if( getsockopt( sock, SOL_SOCKET, SO_PEERCRED, &credentials, &ucred_length ) ) {
        LOGE("connectToGpgAgent: couldn't obtain peer's credentials");
        close( sock );
        return;
    }

    if( app_uid != credentials.uid ) {
        LOGE( "connectToGpgAgent: authentication error. Something JANKY is going on!" );
        LOGE( "                   expected uid %d, but found %d", app_uid, credentials.uid );
        close( sock );
        return;
    }

    /*
     * fetch the stdin and stdout from the helper
     * over the socket so that we can
     * directly communicate with gpg-agent
     */
    in = recv_fd ( sock );
    if ( in == -1 ) {
        LOGE ( "STDIN receiving failed!\n" );
    }
    out = recv_fd ( sock );
    if ( out == -1 ) {
        LOGE ( "STDOUT receiving failed!\n" );
    }

    /*
     * now we can act like a normal pinentry
     */
    pinentry_init ( "pinentry-android" );

    /* Consumes all arguments.  */
    if ( pinentry_parse_opts ( 0, 0 ) )
        write ( sock, EXIT_SUCCESS, 1 );

    // this only exits when done
    pinentry_loop2 ( in, out );
    LOGD("pinentry_loop2  returned");

    /*
     * the helper proces has stayed alive waiting for us
     * to finish, so here we send back the exit code
     */
    int buf[1] = { EXIT_SUCCESS };
    int r = write ( sock, buf, 1 );
    if ( r < 0 )
        LOGE ( "closing pinentry helper failed:" );
    close( sock );
}
コード例 #3
0
ファイル: main.cpp プロジェクト: Noctem/pinentry-mac
int
main (int argc, char *argv[])
{
  pinentry_init ("pinentry-qt4");

  std::auto_ptr<QApplication> app;

#ifdef FALLBACK_CURSES
  if (!pinentry_have_display (argc, argv))
    pinentry_cmd_handler = curses_cmd_handler;
  else
#endif
    {
      /* Qt does only understand -display but not --display; thus we
         are fixing that here.  The code is pretty simply and may get
         confused if an argument is called "--display". */
      char **new_argv, *p;
      size_t n;
      int i, done;

      for (n=0,i=0; i < argc; i++)
        n += strlen (argv[i])+1;
      n++;
      new_argv = (char**)calloc (argc+1, sizeof *new_argv);
      if (new_argv)
        *new_argv = (char*)malloc (n);
      if (!new_argv || !*new_argv)
        {
          fprintf (stderr, "pinentry-qt4: can't fixup argument list: %s\n",
                   strerror (errno));
          exit (EXIT_FAILURE);

        }
      for (done=0,p=*new_argv,i=0; i < argc; i++)
        if (!done && !strcmp (argv[i], "--display"))
          {
            new_argv[i] = strcpy (p, argv[i]+1);
            p += strlen (argv[i]+1) + 1;
            done = 1;
          }
        else
          {
            new_argv[i] = strcpy (p, argv[i]);
            p += strlen (argv[i]) + 1;
          }

      /* We use a modal dialog window, so we don't need the application
         window anymore.  */
      i = argc;
      app.reset (new QApplication (i, new_argv));
      const QIcon icon( QLatin1String( ":/document-encrypt.png" ) );
      app->setWindowIcon( icon );
    }


  /* Consumes all arguments.  */
  if (pinentry_parse_opts (argc, argv))
    {
      printf ("pinentry-qt4 (pinentry) " /* VERSION */ "\n");
      return EXIT_SUCCESS;
    }
  else
    {
      return pinentry_loop () ? EXIT_FAILURE : EXIT_SUCCESS ;
    }

}
コード例 #4
0
ファイル: main.cpp プロジェクト: JThramer/pinentry-mac
int 
main (int argc, char *argv[])
{
  pinentry_init ("pinentry-qt");

#ifdef FALLBACK_CURSES
  if (!pinentry_have_display (argc, argv))
    pinentry_cmd_handler = curses_cmd_handler;
  else
#endif
    {
      /* Qt does only understand -display but not --display; thus we
         are fixing that here.  The code is pretty simply and may get
         confused if an argument is called "--display". */
      char **new_argv, *p;
      size_t n;
      int i, done;

      for (n=0,i=0; i < argc; i++)
        n += strlen (argv[i])+1;
      n++;
      new_argv = (char**)calloc (argc+1, sizeof *new_argv);
      if (new_argv)
        *new_argv = (char*)malloc (n);
      if (!new_argv || !*new_argv)
        {
          fprintf (stderr, "pinentry-qt: can't fixup argument list: %s\n",
                   strerror (errno));
          exit (EXIT_FAILURE);
          
        }
      for (done=0,p=*new_argv,i=0; i < argc; i++)
        if (!done && !strcmp (argv[i], "--display"))
          {
            new_argv[i] = (char*)"-display";
            done = 1;
          }
        else
          {
            new_argv[i] = strcpy (p, argv[i]);
            p += strlen (argv[i]) + 1;
          }

      /* We use a modal dialog window, so we don't need the application
         window anymore.  */
      i = argc;
      new QApplication (i, new_argv);
    }
  

  /* Consumes all arguments.  */
  if (pinentry_parse_opts (argc, argv))
    {
      printf ("pinentry-qt (pinentry) " VERSION "\n");
      exit (EXIT_SUCCESS);
    }

  if (pinentry_loop ())
    return 1;

  return 0;
}