📄 driverinterfacetwo.c
字号:
(leb_bits / 8),
encryptedBlock,
plaintextEncryptedBlock
)))
{
DEBUGOUTGUI(DEBUGLEV_ERROR, (TEXT("Unable to decrypt.\n")));
// display MSG
allOK = FALSE;
}
else
{
paddedCheckMAC = plaintextEncryptedBlock;
volumeDetailsBlock = (paddedCheckMAC + (CDB_MAX_MAC_LENGTH / 8));
MACOutSize = -1;
if (!(driver_MACData(
&mainDriver,
currMACAlg,
currHashDriverFilename,
currHashImpl->HashGUID,
currCypherDriverFilename,
currCypherImpl->CypherGUID,
cdkSize_bits,
criticalDataKey,
(leb_bits - MML),
volumeDetailsBlock,
&generatedMAC,
&MACOutSize
)))
{
DEBUGOUTGUI(DEBUGLEV_ERROR, (TEXT("Unable to MAC data.\n")));
// dispay msg
allOK = FALSE;
}
else
{
// Check if we've found a valid hash/cypher combination
MACTest = memcmp(
generatedMAC,
paddedCheckMAC,
(min(
MACOutSize,
CDB_MAX_MAC_LENGTH
) / 8)
);
SecZeroAndFreeMemory(generatedMAC, (MACOutSize / 8));
if (MACTest == 0)
{
DEBUGOUTGUI(DEBUGLEV_INFO, (TEXT("SUCCESS! Found valid hash/cypher combination!\n")));
CDBMetaData->KDFAlgorithm = currKDFAlg;
CDBMetaData->MACAlgorithm = currMACAlg;
wcscpy(
CDBMetaData->HashDeviceName,
currHashDriverFilename
);
CDBMetaData->HashGUID = currHashImpl->HashGUID;
wcscpy(
CDBMetaData->CypherDeviceName,
currCypherDriverFilename
);
CDBMetaData->CypherGUID = currCypherImpl->CypherGUID;
if (!(_driver_ParseVolumeDetailsBlock(
((leb_bits - MML) / 8), // In bytes
volumeDetailsBlock,
CDBDetails
)))
{
DEBUGOUTGUI(DEBUGLEV_WARN, (TEXT("ERROR: FAILED to parse plaintext volume details block to structure\n")));
// At this point, there has been some failure (e.g.
// critical data block version ID or block structure
// incorrect)
// Note that we *don't* set allOK to FALSE; this failure
// is valid and only indicates that the current
// cypher/hash combination are incorrect for the volume;
// not that something has gone wrong with the mount
// operation
}
else
{
DEBUGOUTGUI(DEBUGLEV_INFO, (TEXT("Parsed OK...\n")));
// Sanity check...
if (
(currCypherImpl->KeySize >= 0) &&
(CDBDetails->MasterKeyLength != currCypherImpl->KeySize)
)
{
DEBUGOUTGUI(DEBUGLEV_WARN, (TEXT("ERROR: Sanity check failed(!)\n")));
// Skip to next loop iteration...
continue;
}
else
{
DEBUGOUTGUI(DEBUGLEV_INFO, (TEXT("Got valid decryption cypher/hash combination\n")));
foundOK = TRUE;
// Store information for dump
// purposes
_driver_StoreCriticalDump(
cdkSize_bits,
criticalDataKey,
min(
MACOutSize,
CDB_MAX_MAC_LENGTH
),
paddedCheckMAC,
leb_bits,
plaintextEncryptedBlock,
(leb_bits - MML),
volumeDetailsBlock
);
break; // xxx - it would be nicer to note the
// valid combination and continue - let
// the user decide which valid
// combination to use
}
}
}
}
}
} // for (cypherImplIdx = 0; cypherImplIdx < currDriverInfoCypher->CypherCount; cypherImplIdx++)
if (foundOK)
{
break;
}
cypherDriverIdx++;
} // while (driverFilenamesCypher[cypherDriverIdx] != NULL)
if (foundOK)
{
break;
}
} // for (hashImplIdx = 0; hashImplIdx < currDriverInfoHash->HashCount; hashImplIdx++)
if (foundOK)
{
break;
}
hashDriverIdx++;
} // while (driverFilenamesHash[hashDriverIdx] != NULL)
}
}
// Cleanup...
SecZeroMemory(plaintextEncryptedBlock, sizeof(plaintextEncryptedBlock));
SecZeroAndFreeMemory(criticalDataKey, criticalDataKeySize);
SecZeroAndFreeMemory(IV, (maxIVSize_bits / 8));
for(i = 0; i < countDriversHash; i++)
{
driver_HashFreeDriverDetails(driverInfoHash[i]);
SecZeroAndFreeMemory(
driverInfoHash[i],
sizeof(*(driverInfoHash[0]))
);
}
SecZeroAndFreeMemory(
driverInfoHash,
(countDriversHash * sizeof(*driverInfoHash))
);
for(i = 0; i < countDriversCypher; i++)
{
driver_CypherFreeDriverDetails(driverInfoCypher[i]);
SecZeroAndFreeMemory(
driverInfoCypher[i],
sizeof(*(driverInfoCypher[0]))
);
}
SecZeroAndFreeMemory(
driverInfoCypher,
(countDriversCypher * sizeof(*driverInfoCypher))
);
driver_FreeDriverFilenames(&driverFilenamesHash);
driver_FreeDriverFilenames(&driverFilenamesCypher);
driver_UnloadMainDLL(&mainDriver);
SecZeroMemory(CDB, sizeof(CDB));
if (foundOK)
{
DEBUGOUTGUI(DEBUGLEV_INFO, (TEXT("CDB decoded OK\n")));
}
else
{
DEBUGOUTGUI(DEBUGLEV_INFO, (TEXT("CDB decode FAILED.\n")));
}
DEBUGOUTGUI(DEBUGLEV_EXIT, (TEXT("_driver_ReadVolumeCriticalData_v2_v3\n")));
return foundOK;
}
// =========================================================================
// Read and decrypt CDB
BOOL _driver_ReadVolumeCriticalData(
WCHAR* Filename,
LARGE_INTEGER OffsetWithinFile,
char* UserPassword,
unsigned int SaltLength, // In *bits*
unsigned int KeyIterations,
CDB_DETAILS* CDBDetails,
CDB_METADATA* CDBMetaData
)
{
return _driver_ReadVolumeCriticalData_v2_v3(
Filename,
OffsetWithinFile,
UserPassword,
SaltLength,
KeyIterations,
CDBDetails,
CDBMetaData
);
}
// =========================================================================
void _driver_SecZeroCDBData(
CDB_DETAILS* CDBDetails,
CDB_METADATA* CDBMetaData
)
{
DEBUGOUTGUI(DEBUGLEV_ENTER, (TEXT("_driver_SecZeroCDB\n")));
if (CDBDetails != NULL)
{
if (CDBDetails->MasterKey != NULL)
{
SecZeroAndFreeMemory(
CDBDetails->MasterKey,
(CDBDetails->MasterKeyLength / 8)
);
}
if (CDBDetails->VolumeIV != NULL)
{
SecZeroAndFreeMemory(
CDBDetails->VolumeIV,
(CDBDetails->VolumeIVLength / 8)
);
}
SecZeroMemory(CDBDetails, sizeof(CDBDetails));
}
if (CDBMetaData != NULL)
{
SecZeroMemory(CDBMetaData, sizeof(CDBMetaData));
}
DEBUGOUTGUI(DEBUGLEV_EXIT, (TEXT("_driver_SecZeroCDB\n")));
}
// =========================================================================
BOOL driver_Mount(
WCHAR* Mountpoint,
WCHAR* Filename,
WCHAR* Keyfile,
LARGE_INTEGER OffsetWithinFile,
BOOL CDBAtOffset,
unsigned char* UserPassword,
unsigned int SaltLength, // In *bits*
unsigned int KeyIterations,
BOOL ReadOnly
)
{
BOOL retval = FALSE;
CDB_DETAILS CDBDetails;
CDB_METADATA CDBMetadata;
DIOC_MOUNT* DIOCMount;
DWORD DIOCMountSize;
FREEOTFEBYTE* ptrMasterKey;
FREEOTFEBYTE* ptrVolumeIV;
//FREEOTFEBYTE* ptrMetaData;
WCHAR* CDBFile;
LARGE_INTEGER CDBFileOffset;
DWORD metadataLength; // In bytes
DEBUGOUTGUI(DEBUGLEV_ENTER, (TEXT("driver_Mount\n")));
metadataLength = 0; // Metadata not used anywhere yet.
CDBFile = Filename;
CDBFileOffset.QuadPart = OffsetWithinFile.QuadPart;
if (Keyfile != NULL)
{
if (wcslen(Keyfile) > 0)
{
CDBFile = Keyfile;
CDBFileOffset.QuadPart = 0;
}
}
// Zero structs to initialize...
memset(&CDBDetails, 0, sizeof(CDBDetails));
memset(&CDBMetadata, 0, sizeof(CDBMetadata));
if (_driver_ReadVolumeCriticalData(
CDBFile,
CDBFileOffset,
UserPassword,
SaltLength, // In *bits*
KeyIterations,
&CDBDetails,
&CDBMetadata
))
{
DIOCMountSize = (
sizeof(*DIOCMount) -
sizeof(DIOCMount->MasterKey) -
sizeof(DIOCMount->VolumeIV) -
sizeof(DIOCMount->MetaData) +
CDBDetails.MasterKeyLength +
CDBDetails.VolumeIVLength +
metadataLength
);
DIOCMount = malloc(DIOCMountSize);
if (DIOCMount == NULL)
{
DEBUGOUTGUI(DEBUGLEV_ERROR, (TEXT("Unable to malloc DIOCMount struct (size: %d bytes)\n"), DIOCMountSize));
}
else
{
DEBUGOUTGUI(DEBUGLEV_INFO, (TEXT("Setting up mount DIOC buffer...\n")));
memset(DIOCMount, 0, DIOCMountSize);
// Populate DIOC structure...
wcscpy(DIOCMount->Mountpoint, Mountpoint);
wcscpy(DIOCMount->Filename, Filename);
DIOCMount->DataStart.QuadPart = OffsetWithinFile.QuadPart;
if (CDBAtOffset)
{
DIOCMount->DataStart.QuadPart += (CRITICAL_DATA_LENGTH / 8);
}
DIOCMount->DataEnd.QuadPart = DIOCMount->DataStart.QuadPart +
CDBDetails.PartitionSize.QuadPart;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -