Beispiel #1
0
int
main (int argc, char *argv[])
{
  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;
}
Beispiel #2
0
int main ( int argc, char *argv[] ) {

    sanitize_env();
    struct stat gpg_stat;

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

    LOGD ( "Welcome to pinentry-android\n" );

    // is gnupg even installed?
    if (stat(GPG_APP_PATH, &gpg_stat) < 0) {
        LOGE( "gpg not installed" GPG_APP_PATH );
        exit ( EXIT_FAILURE );
    }

    /*
     * Launch the Android GUI component asyncronously
     */
    if( launch_pinentry_gui( getuid() ) < 0 ) {
        LOGE( "launching activity failed" );
        exit ( EXIT_FAILURE );
    }

    /*
     * Detect if this is an internal or external pinentry
     *
     * internal - gpg, gpg-agent processes, are from the same
     *            application package as the pinentry Activity,
     *            so the uid will be the same.
     * external - gpg, gpg-agent, and pinentry process are different
     *            than the gnupg-for-android app. this occurs when
     *            an app uses the CLI tools we export.
     *
     * The distinction determines where the socket we use to communicate
     * with the Java activity is place in the filesystem.
     */
    if( gpg_stat.st_uid == getuid() ) {
        // internal pinentry
        start_internal_server(); // never returns
        exit ( EXIT_FAILURE );
    } else {
        // external pinentry
        start_external_server( gpg_stat.st_uid );
        exit ( EXIT_FAILURE );
    }
    return -1;
}
Beispiel #3
0
int
main (int argc, char **argv)
{
#ifndef HAVE_W32CE_SYSTEM
    void *handle;
#endif

    w32_infd = STDIN_FILENO;
    w32_outfd = STDOUT_FILENO;

#ifdef HAVE_W32CE_SYSTEM
    parse_std_file_handles (&argc, &argv);
#endif

    pinentry_init (PGMNAME);

    /* Consumes all arguments.  */
    if (pinentry_parse_opts (argc, argv))
        exit (EXIT_SUCCESS);

    /*   debugfp = fopen ("pinentry.log", "w"); */
    /*   if (!debugfp) */
    /*     debugfp = stderr; */

    /* We need to load a function because that one is only available
       since W2000 but not in older NTs.  */
#ifndef HAVE_W32CE_SYSTEM
    handle = LoadLibrary ("user32.dll");
    if (handle)
    {
        void *foo;
        foo = GetProcAddress (handle, "LockSetForegroundWindow");
        if (foo)
            lock_set_foreground_window = foo;
        else
            CloseHandle (handle);
    }
#endif

    if (pinentry_loop2 (w32_infd, w32_outfd))
        return 1;

#ifdef HAVE_W32CE_SYSTEM
    Sleep (400);
#endif
    return 0;
}
Beispiel #4
0
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;
}
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 );
}
Beispiel #6
0
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 ;
    }

}
Beispiel #7
0
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;
}