MCPcopy Create free account
hub / github.com/bailey27/cppcryptfs / decrypt_reverse_longname

Function decrypt_reverse_longname

libcppcryptfs/filename/cryptfilename.cpp:404–486  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

402
403
404const WCHAR *
405decrypt_reverse_longname(CryptContext *con, LPCWSTR filename, LPCWSTR plain_path, const BYTE *dir_iv, wstring& decrypted_name)
406{
407 HANDLE hFind = INVALID_HANDLE_VALUE;
408 bool found = false;
409
410 try {
411
412 wstring storage = plain_path;
413
414 wstring base64_hash;
415 if (!extract_lfn_base64_hash(filename /* &s[0] */, base64_hash))
416 throw(-1);
417 wstring lfn_path;
418 if (con->m_lfn_cache.lookup(&base64_hash[0], &lfn_path, NULL)) {
419 const WCHAR *ps = wcsrchr(&lfn_path[0], '\\');
420 decrypted_name = ps ? ps + 1 : &lfn_path[0];
421 found = true;
422 } else {
423 // go through all the files in the dir
424 // if the name is long enough to be a long file name (> 175 chars in utf8)
425 // then encrypt it and see if it matches the one we're looking for
426
427 // store any we generate in the lfn cache for later use
428
429 WIN32_FIND_DATA fdata;
430 wstring findspec = storage;
431 findspec += L"*";
432 hFind = FindFirstFile(&findspec[0], &fdata);
433 if (hFind == INVALID_HANDLE_VALUE)
434 throw(-1);
435
436 string utf8name;
437 wstring find_enc;
438 string actual_encrypted;
439 wstring find_base64_hash;
440 wstring find_path;
441
442 do {
443
444 if (!wcscmp(fdata.cFileName, L".") || !wcscmp(fdata.cFileName, L".."))
445 continue;
446
447 if (!unicode_to_utf8(fdata.cFileName, utf8name))
448 throw(-1);
449
450 if (utf8name.length() <= static_cast<size_t>(con->m_shortNameMax))
451 continue;
452
453 if (!encrypt_filename(con, dir_iv, fdata.cFileName, find_enc, &actual_encrypted))
454 throw(-1);
455
456 extract_lfn_base64_hash(&find_enc[0], find_base64_hash);
457
458 find_path = storage;
459 find_path += fdata.cFileName;
460
461 con->m_lfn_cache.store_if_not_there(&find_base64_hash[0], &find_path[0], &actual_encrypted[0]);

Callers 3

decrypt_filenameFunction · 0.85
decrypt_pathFunction · 0.85
unencrypt_pathFunction · 0.85

Calls 5

extract_lfn_base64_hashFunction · 0.85
unicode_to_utf8Function · 0.85
encrypt_filenameFunction · 0.85
store_if_not_thereMethod · 0.80
lookupMethod · 0.45

Tested by

no test coverage detected