예제 #1
0
파일: XmlReader.cpp 프로젝트: tarruda/encfs
bool XmlValue::readB64(const char *path, unsigned char *data, int length) const
{
  XmlValuePtr value = find(path);
  if (!value)
    return false;
  
  std::string s = value->text();
  s.erase(std::remove_if(s.begin(), s.end(), ::isspace), s.end());

  BIO *b64 = BIO_new(BIO_f_base64());
  BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);

  BIO *bmem = BIO_new_mem_buf((void *)s.c_str(), s.size());
  bmem = BIO_push(b64, bmem);

  int decodedSize = BIO_read(bmem, data, length);
  BIO_free_all(b64);
  
  if (decodedSize != length) 
  {
    LOG(ERROR) << "decoding bytes len " << s.size()
               << ", expecting output len " << length
               << ", got " << decodedSize;
    return false;
  }

  return true;
}
예제 #2
0
파일: XmlReader.cpp 프로젝트: tarruda/encfs
bool XmlValue::read(const char *path, bool *out) const
{
  XmlValuePtr value = find(path);
  if (!value)
    return false;

  *out = atoi(value->text().c_str());
  return true;
}
예제 #3
0
파일: XmlReader.cpp 프로젝트: tarruda/encfs
bool XmlValue::read(const char *path, std::string *out) const
{
  XmlValuePtr value = find(path);
  if (!value)
    return false;

  *out = value->text();
  return true;
}
예제 #4
0
파일: XmlReader.cpp 프로젝트: tarruda/encfs
bool XmlValue::read(const char *path, Interface *out) const
{
  XmlValuePtr node = find(path);
  if (!node)
    return false;

  int major, minor;
  bool ok = node->read("name", out->mutable_name())
         && node->read("major", &major)
         && node->read("minor", &minor);

  if (!ok)
    return false;

  out->set_major(major);
  out->set_minor(minor);
  return true;
}
예제 #5
0
// Read a boost::serialization config file using an Xml reader..
bool readV6Config( const char *configFile, 
    EncfsConfig &cfg, ConfigInfo *info)
{
  (void)info;

  XmlReader rdr;
  if (!rdr.load(configFile))
  {
    LOG(ERROR) << "Failed to load config file " << configFile;
    return false;
  }

  XmlValuePtr serialization = rdr["boost_serialization"];
  XmlValuePtr config = (*serialization)["cfg"];
  if (!config) {
    config = (*serialization)["config"];
  }
  if (!config) {
    LOG(ERROR) << "Unable to find XML configuration in file " << configFile;
    return false;
  }

  int version;
  if (!config->read("version", &version) &&
      !config->read("@version", &version)) {
    LOG(ERROR) << "Unable to find version in config file";
    return false;
  }

  // version numbering was complicated by boost::archive 
  if (version == 20 || version >= 20100713)
  {
    VLOG(1) << "found new serialization format";
    cfg.set_revision(version);
  } else if (version == 26800)
  {
    VLOG(1) << "found 20080816 version";
    cfg.set_revision(20080816);
  } else if (version == 26797)
  {
    VLOG(1) << "found 20080813";
    cfg.set_revision(20080813);
  } else if (version < V5Latest)
  {
    LOG(ERROR) << "Invalid version " << version
      << " - please fix config file";
  } else
  {
    LOG(INFO) << "Boost <= 1.41 compatibility mode";
    cfg.set_revision(version);
  }
  VLOG(1) << "subVersion = " << cfg.revision();

  config->read("creator", cfg.mutable_creator());
  config->read("cipherAlg", cfg.mutable_cipher());
  config->read("nameAlg", cfg.mutable_naming());

  //(*config)["keySize"] >> cfg.keySize;
  int blockSize, blockMacBytes, blockMacRandBytes;
  bool uniqueIv, chainedNameIv, externalIv, allowHoles;

  config->read("blockSize", &blockSize);
  config->read("uniqueIV", &uniqueIv);
  config->read("chainedNameIV", &chainedNameIv);
  config->read("externalIVChaining", &externalIv);
  config->read("blockMACBytes", &blockMacBytes);
  config->read("blockMACRandBytes", &blockMacRandBytes);
  config->read("allowHoles", &allowHoles);

  cfg.set_block_size(blockSize);
  cfg.set_unique_iv(uniqueIv);
  cfg.set_chained_iv(chainedNameIv);
  cfg.set_external_iv(externalIv);
  cfg.set_block_mac_bytes(blockMacBytes);
  cfg.set_block_mac_rand_bytes(blockMacRandBytes);
  cfg.set_allow_holes(allowHoles);

  EncryptedKey *encryptedKey = cfg.mutable_key();
  int encodedSize;
  config->read("encodedKeySize", &encodedSize);
  unsigned char *key = new unsigned char[encodedSize];
  config->readB64("encodedKeyData", key, encodedSize);
  encryptedKey->set_ciphertext(key, encodedSize);
  delete[] key;
  
  int keySize;
  config->read("keySize", &keySize);
  encryptedKey->set_size(keySize / 8); // save as size in bytes

  if(cfg.revision() >= 20080816)
  {
    int saltLen;
    config->read("saltLen", &saltLen);
    unsigned char *salt = new unsigned char[saltLen];
    config->readB64("saltData", salt, saltLen);
    encryptedKey->set_salt(salt, saltLen);
    delete[] salt;

    int kdfIterations, desiredKDFDuration;
    config->read("kdfIterations", &kdfIterations);
    config->read("desiredKDFDuration", &desiredKDFDuration);
    encryptedKey->set_kdf_iterations(kdfIterations);
    encryptedKey->set_kdf_duration(desiredKDFDuration);
  } else
  {
    encryptedKey->clear_salt();
    encryptedKey->set_kdf_iterations(16);
    encryptedKey->clear_kdf_duration();
  }

  return true;
}