コード例 #1
0
ファイル: FileUtils.cpp プロジェクト: bentolor/encfs
bool readV4Config( const char *configFile, 
    EncfsConfig &config, ConfigInfo *)
{
  bool ok = false;

  // use Config to parse the file and query it..
  ConfigReader cfgRdr;
  if(cfgRdr.load( configFile ))
  {
    try
    {
      cfgRdr["cipher"] >> (*config.mutable_cipher());
      int blockSize;
      cfgRdr["blockSize"] >> blockSize;
      config.set_block_size(blockSize);

      EncryptedKey *key = config.mutable_key();
      cfgRdr["keyData"] >> (*key->mutable_ciphertext());

      // fill in default for V4
      config.mutable_naming()->MergeFrom( makeInterface("nameio/stream", 1, 0, 0) );
      config.set_creator( "EncFS 1.0.x" );

      ok = true;
    } catch( Error &err)
    {
      LOG(WARNING) << "Error parsing config file " << configFile
        << ": " << err.what();
      ok = false;
    }
  }

  return ok;
}
コード例 #2
0
ファイル: FileUtils.cpp プロジェクト: bentolor/encfs
// Read a v5 archive, which is a proprietary binary format.
bool readV5Config( const char *configFile, 
    EncfsConfig &config, ConfigInfo *)
{
  bool ok = false;

  // use Config to parse the file and query it..
  ConfigReader cfgRdr;
  if(cfgRdr.load( configFile ))
  {
    try
    {
      config.set_revision(cfgRdr["subVersion"].readInt(0));
      if(config.revision() > V5Latest)
      {
        /* config file specifies a version outside our supported
           range..   */
        LOG(ERROR) << "Config subversion " << config.revision()
          << " found, but this version of encfs only supports up to version "
          << V5Latest;
        return false;
      }
      if( config.revision() < V5Latest )
      {
        LOG(ERROR) << "This version of EncFS doesn't support "
          << "filesystems created with EncFS releases before 2004-08-13";
        return false;
      }

      cfgRdr["creator"] >> (*config.mutable_creator());
      cfgRdr["cipher"] >> (*config.mutable_cipher());
      cfgRdr["naming"] >> (*config.mutable_naming());

      int blockSize;
      cfgRdr["blockSize"] >> blockSize;
      config.set_block_size(blockSize);

      EncryptedKey *encryptedKey = config.mutable_key();
      int keySize;
      cfgRdr["keySize"] >> keySize;
      encryptedKey->set_size(keySize / 8);
      cfgRdr["keyData"] >> (*encryptedKey->mutable_ciphertext());

      config.set_unique_iv( cfgRdr["uniqueIV"].readBool( false ) );
      config.set_chained_iv( cfgRdr["chainedIV"].readBool( false ) );
      config.set_external_iv( cfgRdr["externalIV"].readBool( false ) );
      config.set_block_mac_bytes( cfgRdr["blockMACBytes"].readInt(0) );
      config.set_block_mac_rand_bytes( cfgRdr["blockMACRandBytes"].readInt(0) );

      ok = true;
    } catch( Error &err)
    {
      LOG(WARNING) << "Error parsing data in config file " << configFile
        << "; " << err.what();
      ok = false;
    }
  }

  return ok;
}