Ejemplo n.º 1
0
static bool testNameCoding(DirNode &dirNode, bool verbose) {
  // encrypt a name
  const char *name[] = {
      "1234567",         "12345678",         "123456789",
      "123456789ABCDEF", "123456789ABCDEF0", "123456789ABCDEF01",
      "test-name",       "test-name2",       "test",
      "../test",         "/foo/bar/blah",    "test-name.21",
      "test-name.22",    "test-name.o",      "1.test",
      "2.test",          "a/b/c/d",          "a/c/d/e",
      "b/c/d/e",         "b/a/c/d",          NULL};

  const char **orig = name;
  while (*orig) {
    if (verbose) cerr << "   coding name \"" << *orig << "\"";

    string encName = dirNode.relativeCipherPath(*orig);

    if (verbose) cerr << " -> \"" << encName.c_str() << "\"";

    // decrypt name
    string decName = dirNode.plainPath(encName.c_str());

    if (decName == *orig) {
      if (verbose) cerr << "   OK\n";
    } else {
      if (verbose) cerr << "   FAILED (got " << decName << ")\n";
      return false;
    }

    orig++;
  }

  return true;
}
Ejemplo n.º 2
0
static
bool testNameCoding( DirNode &dirNode, bool verbose, 
                     bool collisionTest = false )
{
  // encrypt a name
  const char *name[] = {
    "1234567",
    "12345678",
    "123456789",
    "123456789ABCDEF",
    "123456789ABCDEF0",
    "123456789ABCDEF01",
    "test-name",
    "test-name2",
    "test",
    "../test",
    "/foo/bar/blah",
    "test-name.21",
    "test-name.22",
    "test-name.o",
    "1.test",
    "2.test",
    "a/b/c/d",
    "a/c/d/e",
    "b/c/d/e",
    "b/a/c/d",
    NULL 
  };

  const char **orig = name;
  while(*orig)
  {
    if(verbose)
      cerr << "   coding name \"" << *orig << "\"";

    string encName = dirNode.relativeCipherPath( *orig );

    if(verbose)
      cerr << " -> \"" << encName.c_str() << "\"";

    // decrypt name
    string decName = dirNode.plainPath( encName.c_str() );

    if(decName == *orig)
    {
      if(verbose)
        cerr << "   OK\n";
    } else
    {
      if(verbose)
        cerr << "   FAILED (got " << decName << ")\n";
      return false;
    }

    orig++;
  }

  if (collisionTest)
  {
    if (verbose)
      cerr << "Checking for name collections, this will take a while..\n";
    // check for collision rate
    char buf[64];
    unordered_set<string> encryptedNames;
    for (long i=0; i < 10000000; i++) 
    {
      snprintf(buf, sizeof(buf), "%li", i);
      string encName = dirNode.relativeCipherPath( buf );
      // simulate a case-insisitive filesystem..
      std::transform(encName.begin(), encName.end(), encName.begin(),
          ::toupper);

      if (encryptedNames.insert(encName).second == false) {
        cerr << "collision detected after " << i << " iterations";
        break;
      }
    }
    cerr << "NO collisions detected";
  }

  return true;
}