| 396 | } |
| 397 | |
| 398 | bool CryptConfig::write_updated_config_file(const char *base64key, const char *scryptSalt, int scryptn) |
| 399 | { |
| 400 | bool bret = true; |
| 401 | |
| 402 | try { |
| 403 | |
| 404 | wstring vol = m_VolumeName; |
| 405 | |
| 406 | string volume_name_utf8_enc; |
| 407 | |
| 408 | // if we're recovering a filesystem then base64key isn't null, and we can't decrypt the volume name. |
| 409 | // so ignore the volume name. |
| 410 | if (!base64key) { |
| 411 | if (vol.size() > 0) { |
| 412 | if (vol.size() > MAX_VOLUME_NAME_LENGTH) |
| 413 | vol.erase(MAX_VOLUME_NAME_LENGTH, wstring::npos); |
| 414 | if (!encrypt_string_gcm(vol, GetGcmContentKey(), volume_name_utf8_enc)) { |
| 415 | throw(-1); |
| 416 | } |
| 417 | } |
| 418 | } |
| 419 | |
| 420 | if (m_configPath.size() < 1) |
| 421 | throw(-1); |
| 422 | |
| 423 | wstring config_path = m_configPath; |
| 424 | |
| 425 | const WCHAR *path = &config_path[0]; |
| 426 | |
| 427 | auto File = cppcryptfs::unique_ptr<FILE>(_wfopen_s, fclose, path, L"rb"); |
| 428 | auto fl = File.get(); |
| 429 | |
| 430 | if (!fl) |
| 431 | throw(-1); |
| 432 | |
| 433 | if (fseek(fl, 0, SEEK_END)) |
| 434 | throw(-1); |
| 435 | |
| 436 | long filesize = ftell(fl); |
| 437 | |
| 438 | if (filesize < 0) |
| 439 | throw(-1); |
| 440 | |
| 441 | if (filesize > MAX_CONFIG_FILE_SIZE) |
| 442 | throw(-1); |
| 443 | |
| 444 | if (fseek(fl, 0, SEEK_SET)) |
| 445 | throw(-1); |
| 446 | |
| 447 | std::vector<char> buf(filesize+1); |
| 448 | |
| 449 | size_t len = fread(&buf[0], 1, filesize, fl); |
| 450 | |
| 451 | File.reset(); |
| 452 | |
| 453 | if (len < 0) |
| 454 | throw(-1); |
| 455 |
no test coverage detected