mirror of
https://github.com/veracrypt/VeraCrypt.git
synced 2026-10-05 16:46:35 -05:00
EMV keyfile support: Overall code improvements and bug fixes
This commit is contained in:
81 files changed
+4654
-1574
No files matched your search
+42
-39
@@ -18,7 +18,7 @@
|
||||
#include "VolumeException.h"
|
||||
namespace VeraCrypt
|
||||
{
|
||||
void Keyfile::Apply (const BufferPtr &pool, bool EMVOption) const
|
||||
void Keyfile::Apply (const BufferPtr &pool, bool emvSupportEnabled) const
|
||||
{
|
||||
if (Path.IsDirectory())
|
||||
throw ParameterIncorrect (SRC_POS);
|
||||
@@ -32,57 +32,60 @@ namespace VeraCrypt
|
||||
|
||||
SecureBuffer keyfileBuf (File::GetOptimalReadSize());
|
||||
|
||||
std::wcout << wstring (Path) << std::endl;
|
||||
if (Token::IsKeyfilePathValid (Path, EMVOption)) {
|
||||
// Apply keyfile generated by a security token
|
||||
vector <byte> keyfileData;
|
||||
Token::getTokenKeyfile(wstring(Path))->GetKeyfileData(keyfileData);
|
||||
if (Token::IsKeyfilePathValid (Path, emvSupportEnabled))
|
||||
{
|
||||
// Apply keyfile generated by a security token
|
||||
vector <byte> keyfileData;
|
||||
Token::getTokenKeyfile(wstring(Path))->GetKeyfileData(keyfileData);
|
||||
|
||||
if (keyfileData.size() < MinProcessedLength)
|
||||
throw InsufficientData(SRC_POS, Path);
|
||||
if (keyfileData.size() < MinProcessedLength)
|
||||
throw InsufficientData(SRC_POS, Path);
|
||||
|
||||
for (size_t i = 0; i < keyfileData.size(); i++) {
|
||||
uint32 crc = crc32.Process(keyfileData[i]);
|
||||
for (size_t i = 0; i < keyfileData.size(); i++)
|
||||
{
|
||||
uint32 crc = crc32.Process(keyfileData[i]);
|
||||
|
||||
pool[poolPos++] += (byte)(crc >> 24);
|
||||
pool[poolPos++] += (byte)(crc >> 16);
|
||||
pool[poolPos++] += (byte)(crc >> 8);
|
||||
pool[poolPos++] += (byte) crc;
|
||||
pool[poolPos++] += (byte)(crc >> 24);
|
||||
pool[poolPos++] += (byte)(crc >> 16);
|
||||
pool[poolPos++] += (byte)(crc >> 8);
|
||||
pool[poolPos++] += (byte) crc;
|
||||
|
||||
if (poolPos >= pool.Size())
|
||||
poolPos = 0;
|
||||
if (poolPos >= pool.Size())
|
||||
poolPos = 0;
|
||||
|
||||
if (++totalLength >= MaxProcessedLength)
|
||||
break;
|
||||
}
|
||||
if (++totalLength >= MaxProcessedLength)
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
burn(&keyfileData.front(), keyfileData.size());
|
||||
goto done;
|
||||
}
|
||||
burn(&keyfileData.front(), keyfileData.size());
|
||||
goto done;
|
||||
}
|
||||
|
||||
file.Open (Path, File::OpenRead, File::ShareRead);
|
||||
file.Open (Path, File::OpenRead, File::ShareRead);
|
||||
|
||||
while ((readLength = file.Read (keyfileBuf)) > 0) {
|
||||
for (size_t i = 0; i < readLength; i++) {
|
||||
uint32 crc = crc32.Process(keyfileBuf[i]);
|
||||
pool[poolPos++] += (byte)(crc >> 24);
|
||||
pool[poolPos++] += (byte)(crc >> 16);
|
||||
pool[poolPos++] += (byte)(crc >> 8);
|
||||
pool[poolPos++] += (byte) crc;
|
||||
if (poolPos >= pool.Size())
|
||||
poolPos = 0;
|
||||
if (++totalLength >= MaxProcessedLength)
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
done:
|
||||
while ((readLength = file.Read (keyfileBuf)) > 0)
|
||||
{
|
||||
for (size_t i = 0; i < readLength; i++)
|
||||
{
|
||||
uint32 crc = crc32.Process(keyfileBuf[i]);
|
||||
pool[poolPos++] += (byte)(crc >> 24);
|
||||
pool[poolPos++] += (byte)(crc >> 16);
|
||||
pool[poolPos++] += (byte)(crc >> 8);
|
||||
pool[poolPos++] += (byte) crc;
|
||||
if (poolPos >= pool.Size())
|
||||
poolPos = 0;
|
||||
if (++totalLength >= MaxProcessedLength)
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
done:
|
||||
|
||||
if (totalLength < MinProcessedLength)
|
||||
throw InsufficientData (SRC_POS, Path);
|
||||
}
|
||||
|
||||
shared_ptr <VolumePassword> Keyfile::ApplyListToPassword (shared_ptr <KeyfileList> keyfiles, shared_ptr <VolumePassword> password, bool EMVOption)
|
||||
shared_ptr <VolumePassword> Keyfile::ApplyListToPassword (shared_ptr <KeyfileList> keyfiles, shared_ptr <VolumePassword> password, bool emvSupportEnabled)
|
||||
{
|
||||
if (!password)
|
||||
password.reset (new VolumePassword);
|
||||
@@ -139,7 +142,7 @@ namespace VeraCrypt
|
||||
// Apply all keyfiles
|
||||
foreach_ref (const Keyfile &k, keyfilesExp)
|
||||
{
|
||||
k.Apply (keyfilePool, EMVOption);
|
||||
k.Apply (keyfilePool, emvSupportEnabled);
|
||||
}
|
||||
|
||||
newPassword->Set (keyfilePool);
|
||||
|
||||
Reference in new issue
Block a user