bool TestExtFile::test_file_get_contents() {
  Variant f = f_fopen("test/test_ext_file.tmp", "w");
  f_fputs(f, "testing file_get_contents");
  f_fclose(f);

  VS(f_file_get_contents("test/test_ext_file.tmp"),
     "testing file_get_contents");

  VS(f_unserialize(f_file_get_contents("compress.zlib://test/test_zlib_file")),
     CREATE_VECTOR1("rblock:216105"));
  return Count(true);
}
bool TestExtOpenssl::test_openssl_csr_export_to_file() {
  Variant csr = f_openssl_csr_new(null, null);
  VERIFY(!csr.isNull());

  const char *tmp = "test/test_csr.tmp";
  f_unlink(tmp);
  VS(f_file_get_contents(tmp), false);
  f_openssl_csr_export_to_file(csr, tmp);
  VERIFY(f_file_get_contents(tmp).toString().size() > 400);
  f_unlink(tmp);

  return Count(true);
}
bool TestExtOpenssl::test_openssl_pkey_export_to_file() {
  const char *tmp = "test/test_pkey.tmp";
  f_unlink(tmp);
  VS(f_file_get_contents(tmp), false);

  Variant privkey = f_openssl_pkey_new();
  VERIFY(!privkey.isNull());
  f_openssl_pkey_export_to_file(privkey, tmp, "1234");

  VERIFY(f_file_get_contents(tmp).toString().size() > 400);
  f_unlink(tmp);
  return Count(true);
}
bool TestExtOpenssl::test_openssl_pkcs12_export_to_file() {
  Variant privkey = f_openssl_pkey_new();
  VERIFY(!privkey.isNull());
  Variant csr = f_openssl_csr_new(null, privkey);
  VERIFY(!csr.isNull());
  Variant scert = f_openssl_csr_sign(csr, null, privkey, 365);

  const char *tmp = "test/test_pkcs12.tmp";
  f_unlink(tmp);
  VS(f_file_get_contents(tmp), false);
  f_openssl_pkcs12_export_to_file(scert, tmp, privkey, "1234");
  VERIFY(f_file_get_contents(tmp).toString().size() > 400);
  f_unlink(tmp);
  return Count(true);
}
bool TestExtOpenssl::test_openssl_x509_free() {
  Variant fcert = f_file_get_contents("test/test_x509.crt");
  Variant cert = f_openssl_x509_read(fcert);
  VERIFY(!cert.toObject().isNull());
  f_openssl_x509_free(cert);
  return Count(true);
}
bool TestExtOpenssl::test_openssl_pkcs7_sign() {
  Variant privkey = f_openssl_pkey_new();
  VERIFY(!privkey.isNull());
  Variant csr = f_openssl_csr_new(null, privkey);
  VERIFY(!csr.isNull());
  Variant scert = f_openssl_csr_sign(csr, null, privkey, 365);
  Variant pubkey = f_openssl_csr_get_public_key(csr);
  VERIFY(!pubkey.isNull());

  String data = "some secret data";
  const char *infile = "test/test_pkcs7.in";
  const char *outfile = "test/test_pkcs7.out";
  f_unlink(infile);
  f_unlink(outfile);
  f_file_put_contents(infile, data);

  VERIFY(f_openssl_pkcs7_sign
         (infile, outfile, scert, privkey,
          CREATE_MAP2("To", "*****@*****.**","From", "*****@*****.**")));

  const char *tmp = "test/test_x509.tmp";
  f_unlink(tmp);
  VS(f_file_get_contents(tmp), false);
  VERIFY(f_openssl_x509_export_to_file(scert, tmp));

  VS(f_openssl_pkcs7_verify(outfile, 0, infile, Variant(tmp).toArray()), true);
  f_unlink(infile);
  f_unlink(outfile);
  f_unlink(tmp);
  return Count(true);
}
bool TestExtOpenssl::test_openssl_x509_parse() {
  Variant fcert = f_file_get_contents("test/test_x509.crt");
  Variant cert = f_openssl_x509_read(fcert);
  Variant info = f_openssl_x509_parse(cert);
  VS(info["subject"]["O"], "RSA Data Security, Inc.");
  return Count(true);
}
bool TestExtOpenssl::test_openssl_x509_checkpurpose() {
  Variant fcert = f_file_get_contents("test/test_x509.crt");
  Variant cert = f_openssl_x509_read(fcert);
  VS(f_openssl_x509_checkpurpose(cert, k_X509_PURPOSE_SSL_CLIENT), 0);
  VS(f_openssl_x509_checkpurpose(cert, k_X509_PURPOSE_SSL_SERVER), 0);
  return Count(true);
}
bool TestExtOpenssl::test_openssl_pkey_free() {
  Variant fkey = f_file_get_contents("test/test_public.pem");
  Variant k = f_openssl_pkey_get_public(fkey);
  VERIFY(!same(k, false));
  VERIFY(!k.isNull());
  f_openssl_pkey_free(k);
  return Count(true);
}
bool TestExtOpenssl::test_openssl_x509_export_to_file() {
  Variant fcert = f_file_get_contents("test/test_x509.crt");
  Variant cert = f_openssl_x509_read(fcert);

  const char *tmp = "test/test_x509.tmp";
  f_unlink(tmp);
  VS(f_file_get_contents(tmp), false);
  VERIFY(f_openssl_x509_export_to_file(cert, tmp));

  Variant fcert2 = f_file_get_contents(tmp);
  Variant cert2 = f_openssl_x509_read(fcert2);
  Variant info = f_openssl_x509_parse(cert2);
  VS(info["subject"]["O"], "RSA Data Security, Inc.");

  f_unlink(tmp);
  return Count(true);
}
bool TestExtOpenssl::test_openssl_pkey_get_details() {
  {
    Variant fkey = f_file_get_contents("test/test_public.pem");
    Variant k = f_openssl_pkey_get_public(fkey);
    VERIFY(!same(k, false));
    VERIFY(!k.isNull());
    VS(f_openssl_pkey_get_details(k)["bits"], 1024);
  }
  {
    Variant fkey = f_file_get_contents("test/test_private.pem");
    Variant k = f_openssl_pkey_get_private(fkey);
    VERIFY(!same(k, false));
    VERIFY(!k.isNull());
    VS(f_openssl_pkey_get_details(k)["bits"], 512);
  }
  return Count(true);
}
Esempio n. 12
0
bool TestExtOpenssl::test_openssl_x509_export() {
  Variant fcert = f_file_get_contents("test/test_x509.crt");
  Variant cert = f_openssl_x509_read(fcert);
  Variant out;
  VERIFY(f_openssl_x509_export(cert, ref(out)));
  Variant cert2 = f_openssl_x509_read(out);
  Variant info = f_openssl_x509_parse(cert2);
  VS(info[s_subject][s_O], "RSA Data Security, Inc.");
  return Count(true);
}
Esempio n. 13
0
bool TestExtMailparse::test_mailparse_msg_create() {
  const char *files[] = { "mime", "phpcvs1", "qp", "uue" };

  for (unsigned int i = 0; i < sizeof(files)/sizeof(files[0]); i++) {
    string file = files[i];
    string testname = "test/ext/test_ext_mailparse." + file + ".txt";
    string expname = "test/ext/test_ext_mailparse." + file + ".exp";

    Variant mime = f_mailparse_msg_create();
    PlainFile input;
    input.open(testname, "r");
    while (!input.eof()) {
      String data = input.read(1024);
      if (!data.isNull()) {
        f_mailparse_msg_parse(mime, data);
      }
    }
    input.close();

    Array arr = f_mailparse_msg_get_structure(mime);
    f_ob_start();
    echo("Message: "); echo(file.c_str()); echo("\n");
    for (ArrayIter iter(arr); iter; ++iter) {
      Variant partname = iter.second();
      int depth = f_count(f_explode(".", partname)) - 1;
      String indent = f_str_repeat("  ", depth * 2);

      Variant subpart = f_mailparse_msg_get_part(mime, partname);
      if (subpart.isNull()) {
        f_var_dump(partname); echo("\n");
        f_var_dump(arr);
        break;
      }

      Variant data = f_mailparse_msg_get_part_data(subpart);
      echo("\n"); echo(indent); echo("Part "); echo(partname); echo("\n");
      f_ksort(ref(data));
      for (ArrayIter iter(data); iter; ++iter) {
        String key = iter.first().toString();
        if (key != "headers" && key != "ending-pos-body") {
          echo(indent); echo(key); echo(" => ");
          f_var_dump(iter.second());
        }
      }
    }
    String output = f_ob_get_contents();

    Variant expect = f_file_get_contents(expname.c_str());
    VS(output, expect);
    f_ob_end_clean();
  }

  return Count(true);
}
Esempio n. 14
0
// Tries to read the contents of the file whose path is specified in m_file.
// If the path cannot be resolved and is relative, the path of the sandbox
// is used to qualify the relative path. If the contents cannot be retrieved
// m_code will be an empty string.
// The function returns false if the reply to the client fails during the
// sending process.
bool CmdList::onServer(DebuggerProxy &proxy) {
  auto savedWarningFrequency = RuntimeOption::WarningFrequency;
  RuntimeOption::WarningFrequency = 0;
  m_code = f_file_get_contents(m_file.c_str());
  if (!proxy.isLocal() && !m_code.toBoolean() && m_file[0] != '/') {
    DSandboxInfo info = proxy.getSandbox();
    if (info.m_path.empty()) {
      raise_warning("path for sandbox %s is not setup, run a web request",
                    info.desc().c_str());
    } else {
      std::string full_path = info.m_path + m_file;
      m_code = f_file_get_contents(full_path.c_str());
    }
  }
  RuntimeOption::WarningFrequency = savedWarningFrequency;
  if (!m_code.toBoolean() && m_file == "systemlib.php") {
    m_code = SystemLib::s_source;
  }
  return proxy.sendToClient((DebuggerCommand*)this);
}
Esempio n. 15
0
bool CmdInstrument::onClientVM(DebuggerClient *client) {
  if (DebuggerCommand::onClient(client)) return true;
  if (client->argCount() == 1) {
    if (client->argValue(1) == "list" || client->argValue(1) == "l") {
      listInst(client);
      return true;
    }
    if (client->argValue(1) == "clear" || client->argValue(1) == "c") {
      clearInst(client);
      return true;
    }
  }
  if (client->argCount() < 2 || client->argValue(1) == "help") {
    return help(client);
  }

  std::string loc = client->argValue(1);
  std::string file = client->argValue(2);
  std::string desc;
  if (client->argCount() >= 3) {
    desc = client->argValue(3);
  }
  Variant code = f_file_get_contents(file.c_str());
  if (code.isNull()) {
    client->error("Unable to read from file %s", file.c_str());
    return false;
  }
  m_instPoints = client->getInstPoints();
  if (loc == "here") {
    InstPointInfoPtr ipi(new InstPointInfo());
    ipi->setLocHere();
    ipi->m_code = code.toString();
    ipi->m_desc = desc;
    m_instPoints->push_back(ipi);
  } else if (loc.rfind("()") == loc.size() - 2){
    InstPointInfoPtr ipi(new InstPointInfo());
    ipi->setLocFuncEntry(loc.substr(0, loc.size() - 2));
    ipi->m_code = code.toString();
    ipi->m_desc = desc;
    m_instPoints->push_back(ipi);
  } else {
    client->error("Not implemented\n");
    return true;
  }
  m_type = ActionWrite;
  CmdInstrumentPtr instCmdPtr = client->xend<CmdInstrument>(this);
  if (!instCmdPtr->m_enabled) {
    client->error("Instrumentation is not enabled on the server");
  }
  client->setInstPoints(instCmdPtr->m_ips);
  CmdInstrument::PrintInstPoints(client);
  return true;
}
Esempio n. 16
0
Array f_get_meta_tags(CStrRef filename, bool use_include_path /* = false */) {
  String f = f_file_get_contents(filename);

  Variant matches;
  f_preg_match_all("/<meta\\s+name=\"(.*?)\"\\s+content=\"(.*?)\".*?>/s",
                   f, ref(matches), k_PREG_SET_ORDER);

  Array ret = Array::Create();
  for (ArrayIter iter(matches); iter; ++iter) {
    Array pair = iter.second();
    ret.set(normalize_variable_name(pair[1].toString()), pair[2]);
  }
  return ret;
}
bool TestExtOpenssl::test_openssl_pkcs7_encrypt() {
  Variant privkey = f_openssl_pkey_new();
  VERIFY(!privkey.isNull());
  Variant csr = f_openssl_csr_new(null, privkey);
  VERIFY(!csr.isNull());
  Variant scert = f_openssl_csr_sign(csr, null, privkey, 365);
  Variant pubkey = f_openssl_csr_get_public_key(csr);
  VERIFY(!pubkey.isNull());

  String data = "some secret data";
  const char *infile = "test/test_pkcs7.in";
  const char *outfile = "test/test_pkcs7.out";
  f_unlink(infile);
  f_unlink(outfile);
  f_file_put_contents(infile, data);

  VERIFY(f_openssl_pkcs7_encrypt
         (infile, outfile, scert,
          CREATE_MAP2("To", "*****@*****.**","From", "*****@*****.**")));

  f_unlink(infile);
  VERIFY(f_openssl_pkcs7_decrypt(outfile, infile, scert, privkey));
  Variant decrypted = f_file_get_contents(infile);
  f_var_dump(decrypted);
  f_unlink(infile);
  f_unlink(outfile);
  /*
   * PHP didn't work either:

    $privkey = openssl_pkey_new();
    $csr = openssl_csr_new(array(), $privkey);
    $scert = openssl_csr_sign($csr, null, $privkey, 365);

    $data = "some secret data";
    $infile = "test_pkcs7.in";
    $outfile = "test_pkcs7.out";
    file_put_contents($infile, $data);

    openssl_pkcs7_encrypt($infile, $outfile, $scert,
                          array("To" => "*****@*****.**",
                                "From" => "*****@*****.**"));

    var_dump(openssl_pkcs7_decrypt($outfile, $infile, $scert, $privkey));
    $decrypted = file_get_contents($infile);var_dump($decrypted);

   */
  return Count(true);
}
Esempio n. 18
0
xmlDocPtr soap_xmlParseFile(const char *filename) {
  const char *url = strstr(filename, "://");
  if (url) {
    xmlDocPtr ret;
    xmlParserCtxtPtr ctxt = xmlCreateFileParserCtxt(filename);
    if (ctxt) {
      ctxt->keepBlanks = 0;
      ctxt->sax->ignorableWhitespace = soap_ignorableWhitespace;
      ctxt->sax->comment = soap_Comment;
      ctxt->sax->warning = NULL;
      ctxt->sax->error = NULL;
      /*ctxt->sax->fatalError = NULL;*/
      xmlParseDocument(ctxt);
      if (ctxt->wellFormed) {
        ret = ctxt->myDoc;
        if (ret->URL == NULL && ctxt->directory != NULL) {
          ret->URL = xmlCharStrdup(ctxt->directory);
        }
      } else {
        ret = NULL;
        xmlFreeDoc(ctxt->myDoc);
        ctxt->myDoc = NULL;
      }
      xmlFreeParserCtxt(ctxt);
    } else {
      ret = NULL;
    }
    if (ret) {
      cleanup_xml_node((xmlNodePtr)ret);
    }
    return ret;
  }

  Variant content = f_file_get_contents(filename);
  if (!same(content, false)) {
    String scontent = content.toString();
    return soap_xmlParseMemory(scontent.data(), scontent.size());
  }
  return NULL;
}
Esempio n. 19
0
bool TestExtFile::test_file_put_contents() {
  f_file_put_contents("test/test_ext_file.tmp", "testing file_put_contents");
  VS(f_file_get_contents("test/test_ext_file.tmp"),
     "testing file_put_contents");
  return Count(true);
}