Esempio n. 1
0
bool AvCaster::Initialize(MainContent* main_content)
{
  Gui       = main_content ;
  CliParams = JUCEApplicationBase::getCommandLineParameterArray() ;

DEBUG_TRACE_INIT_PHASE_1

  if (!ValidateEnvironment()) return false ;

DEBUG_TRACE_INIT_PHASE_2

  // load persistent configuration
  if ((Store = new AvCasterStore()) == nullptr) return false ;

DEBUG_TRACE_INIT_PHASE_3

  // initialze GUI
  SetWindowTitle() ; RefreshGui() ;

DEBUG_TRACE_INIT_PHASE_4

  // initialize gStreamer
  if (!Gstreamer::Initialize(Gui->getWindowHandle())) return false ;

DEBUG_TRACE_INIT_PHASE_5

  if (!HandleCliParams()) return false ;

  SetStatusL(GUI::READY_STATUS_TEXT) ;

  // subscribe to model change events
  Store->listen(true) ;

  return true ;
}
Esempio n. 2
0
static gboolean
DisplayServerCert(const gchar *serverCertPemFile) // IN
{
   gboolean ret = FALSE;
   gchar *cert = NULL;
   FILE *file = NULL;
   GMappedFile *fmap = NULL;

   if (!ValidateEnvironment(FALSE)) {
      goto exit;
   }

   cert = g_build_filename(guestProxyServerDir, "cert.pem", NULL);
   if (!g_file_test(cert, G_FILE_TEST_IS_REGULAR)) {
      Error("Couldn't find the server certificate file: %s.\n", cert);
      goto exit;
   }

   if (serverCertPemFile && strlen(serverCertPemFile)) {
      printf("Copying the server certificate to %s.\n", serverCertPemFile);

      if (!CertUtil_CopyFile(cert, serverCertPemFile)) {
         Error("Failed to copy the certificate file to the file.\n");
         goto exit;
      }
      printf("Successfully copied the server certificate.\n");

   } else {

      fmap = g_mapped_file_new(cert, FALSE, NULL);
      if (fmap) {

         const gchar *content = g_mapped_file_get_contents(fmap);
         gsize length = g_mapped_file_get_length(fmap);

         if (fwrite(content, 1, length, stdout) < length) {
            Error("Failed to display %s: %s.\n", cert, strerror(errno));
            goto exit;
         }
      } else {
         Error("Couldn't open the server certificate file.\n");
         goto exit;
      }
   }

   ret = TRUE;

exit:
   g_free(cert);
   if (file) {
      fclose(file);
   }
   if (fmap) {
      g_mapped_file_unref(fmap);
   }

   return ret;
}
Esempio n. 3
0
static gboolean
RemoveTrustCert(const gchar *clientCertPemFile)
{
   gboolean ret = FALSE;
   int last, num;
   gchar *hash = NULL;
   gchar *src = NULL;
   gchar *dst = NULL;

   if (!ValidateEnvironment(TRUE)) {
      goto exit;
   }

   if (!g_file_test(clientCertPemFile, G_FILE_TEST_IS_REGULAR)) {
      Error("No certificate file found at %s.\n", clientCertPemFile);
      goto exit;
   }

   hash = CertKey_ComputeCertPemFileHash(clientCertPemFile);
   if (!hash) {
      goto exit;
   }

   if (!CertUtil_FindCert(clientCertPemFile, guestProxyTrustedDir, hash,
                         &num, &last) || num < 0) {
      Error("Couldn't find any certificate in the trusted directory.\n");
      goto exit;
   }

   dst = CertUtil_CreateCertFileName(guestProxyTrustedDir, hash, num);
   if (last != num) {
      src = CertUtil_CreateCertFileName(guestProxyTrustedDir, hash, last);
      if (rename(src, dst) != 0) {
         Error("Failed to rename %s to %s with error: %s.",
               src, dst, strerror(errno));
         goto exit;
      }
   } else {
      if (unlink(dst) != 0) {
         Error("Failed to remove %s with error: %s.", dst, strerror(errno));
         goto exit;
      }
   }

   ret = TRUE;
   printf("Successfully removed the certificate.\n");

exit:
   g_free(hash);
   g_free(src);
   g_free(dst);

   return ret;
}
Esempio n. 4
0
static gboolean
AddTrustCert(const gchar *clientCertPemFile)      // IN
{
   gboolean ret = FALSE;
   int last, num;
   gchar *hash = NULL;
   gchar *path = NULL;

   if (!ValidateEnvironment(TRUE)) {
      goto exit;
   }

   if (!g_file_test(clientCertPemFile, G_FILE_TEST_IS_REGULAR)) {
      Error("No certificate file found at %s.\n", clientCertPemFile);
      goto exit;
   }

   hash = CertKey_ComputeCertPemFileHash(clientCertPemFile);
   if (!hash) {
      goto exit;
   }

   if (CertUtil_FindCert(clientCertPemFile, guestProxyTrustedDir, hash,
                        &num, &last) && num >= 0) {
      Error("The specified certificate file already exists: %s.%d.\n",
            hash, num);
      goto exit;
   }

   path = CertUtil_CreateCertFileName(guestProxyTrustedDir, hash, last + 1);
   if (!CertUtil_CopyFile(clientCertPemFile, path)) {
      Error("Unable to add %s to the trusted certificate store.\n",
            clientCertPemFile);
      goto exit;
   }

   printf("Successfully added the %s to the trusted certificate store.\n",
          clientCertPemFile);
   ret = TRUE;

exit:
   g_free(hash);
   g_free(path);

   return ret;
}
Esempio n. 5
0
static gboolean
CreateKeyCert(gboolean force)
{
   gboolean ret = FALSE;
   gchar *cert = NULL;
   gchar *key = NULL;

   if (!ValidateEnvironment(TRUE)) {
      goto exit;
   }

   key  = g_build_filename(guestProxyServerDir, "key.pem", NULL);
   cert = g_build_filename(guestProxyServerDir, "cert.pem", NULL);

   /*
    * If both server key and certificate files already exist and the
    * program is not asked to create them by force, print an warning
    * message about server key/cert files not regenerating.
    */
   if (g_file_test(key, G_FILE_TEST_IS_REGULAR) &&
       g_file_test(cert, G_FILE_TEST_IS_REGULAR) && !force) {
      printf("\nNOTE: both %s and \n      %s already exist.\n"
             "      They are not generated again. To regenerate "
             "them by force,\n      use the \"%s -g -f\" command.\n\n",
             key, cert, g_get_prgname());
      ret = TRUE;
      goto exit;
   }

   printf("Generating the key and certificate files.\n");

   if (!CertKey_GenerateKeyCert(RSA_KEY_LENGTH, CERT_EXPIRED_IN_DAYS,
                                guestProxySslConf, key, cert)) {
      goto exit;
   }

   ret = TRUE;
   printf("Successfully generated the key and certificate files.\n");

exit:
   g_free(key);
   g_free(cert);

   return ret;
}