From f648e29d050cab362cc660c1a5c5109182028768 Mon Sep 17 00:00:00 2001 From: kavsrf Date: Mon, 23 Jan 2017 15:30:22 +0300 Subject: DcsInfo added DcsBoot is driver now (to support DriverOrder list) --- Library/CommonLib/CommonLib.inf | 7 ++++ Library/CommonLib/EfiBluetooth.c | 50 ++++++++++++++++++++++++ Library/CommonLib/EfiFile.c | 19 +++++++++ Library/CommonLib/EfiTpm.c | 34 +++++++++++++++++ Library/PasswordLib/PlatformID.c | 19 +++++++++ Library/VeraCryptLib/DcsConfig.c | 72 +++++++++++++++++++++++++++++++++++ Library/VeraCryptLib/DcsConfig.h | 29 ++++++++++++++ Library/VeraCryptLib/DcsVeraCrypt.c | 53 +------------------------- Library/VeraCryptLib/DcsVeraCrypt.h | 3 -- Library/VeraCryptLib/VeraCryptLib.inf | 2 + 10 files changed, 233 insertions(+), 55 deletions(-) create mode 100644 Library/CommonLib/EfiBluetooth.c create mode 100644 Library/CommonLib/EfiTpm.c create mode 100644 Library/VeraCryptLib/DcsConfig.c create mode 100644 Library/VeraCryptLib/DcsConfig.h (limited to 'Library') diff --git a/Library/CommonLib/CommonLib.inf b/Library/CommonLib/CommonLib.inf index 2c379b8..b5758f5 100644 --- a/Library/CommonLib/CommonLib.inf +++ b/Library/CommonLib/CommonLib.inf @@ -36,6 +36,8 @@ EfiExec.c EfiUsb.c EfiTouch.c + EfiBluetooth.c + EfiTpm.c [Sources.IA32] IA32/EfiCpuHalt.asm @@ -63,3 +65,8 @@ gEfiAbsolutePointerProtocolGuid gEfiGraphicsOutputProtocolGuid gEfiSimpleTextOutProtocolGuid + gEfiBluetoothIoProtocolGuid + gEfiBluetoothHcProtocolGuid + gEfiBluetoothConfigProtocolGuid + gEfiTcgProtocolGuid + gEfiTcg2ProtocolGuid diff --git a/Library/CommonLib/EfiBluetooth.c b/Library/CommonLib/EfiBluetooth.c new file mode 100644 index 0000000..13b03e3 --- /dev/null +++ b/Library/CommonLib/EfiBluetooth.c @@ -0,0 +1,50 @@ +/** @file +EFI BLUETOOTH helpers + +Copyright (c) 2016. Disk Cryptography Services for EFI (DCS), Alex Kolotnikov +Copyright (c) 2016. VeraCrypt, Mounir IDRASSI + +This program and the accompanying materials are licensed and made available +under the terms and conditions of the GNU Lesser General Public License, version 3.0 (LGPL-3.0). + +The full text of the license may be found at +https://opensource.org/licenses/LGPL-3.0 +**/ + +#include +#include +#include +#include +#include +#include +#include + +EFI_HANDLE* gBluetoothIoHandles = NULL; +UINTN gBluetoothIoCount = 0; + +EFI_HANDLE* gBluetoothHcHandles = NULL; +UINTN gBluetoothHcCount = 0; + +EFI_HANDLE* gBluetoothConfigHandles = NULL; +UINTN gBluetoothConfigCount = 0; + +EFI_STATUS +InitBluetooth() { + EFI_STATUS res; + res = EfiGetHandles(ByProtocol, &gEfiBluetoothIoProtocolGuid, 0, &gBluetoothIoHandles, &gBluetoothIoCount); + res = EfiGetHandles(ByProtocol, &gEfiBluetoothHcProtocolGuid, 0, &gBluetoothHcHandles, &gBluetoothHcCount); + res = EfiGetHandles(ByProtocol, &gEfiBluetoothConfigProtocolGuid, 0, &gBluetoothConfigHandles, &gBluetoothConfigCount); + return res; +} + +EFI_STATUS +BluetoothGetIO( + IN EFI_HANDLE Handle, + OUT EFI_BLUETOOTH_IO_PROTOCOL** io + ) { + if (!io) { + return EFI_INVALID_PARAMETER; + } + return gBS->HandleProtocol(Handle, &gEfiBluetoothIoProtocolGuid, (VOID**)io); +} + diff --git a/Library/CommonLib/EfiFile.c b/Library/CommonLib/EfiFile.c index b1e2076..fdc999c 100644 --- a/Library/CommonLib/EfiFile.c +++ b/Library/CommonLib/EfiFile.c @@ -18,6 +18,7 @@ https://opensource.org/licenses/LGPL-3.0 #include #include #include +#include ////////////////////////////////////////////////////////////////////////// // EFI file @@ -151,6 +152,24 @@ FileWrite( return res; } +CHAR8 gFileAsciiPrintBuffer[1024]; + +UINTN +FileAsciiPrint( + IN EFI_FILE *f, + IN CONST CHAR8 *format, + ... + ) { + VA_LIST marker; + UINTN len; + if (f == NULL) return 0; + VA_START(marker, format); + len = AsciiVSPrint((CHAR8*)gFileAsciiPrintBuffer, sizeof(gFileAsciiPrintBuffer), format, marker); + VA_END(marker); + f->Write(f, &len, gFileAsciiPrintBuffer); + return len; +} + EFI_STATUS FileGetInfo( IN EFI_FILE* f, diff --git a/Library/CommonLib/EfiTpm.c b/Library/CommonLib/EfiTpm.c new file mode 100644 index 0000000..9b236c5 --- /dev/null +++ b/Library/CommonLib/EfiTpm.c @@ -0,0 +1,34 @@ +/** @file +EFI TCG/TPM helpers + +Copyright (c) 2016. Disk Cryptography Services for EFI (DCS), Alex Kolotnikov +Copyright (c) 2016. VeraCrypt, Mounir IDRASSI + +This program and the accompanying materials are licensed and made available +under the terms and conditions of the GNU Lesser General Public License, version 3.0 (LGPL-3.0). + +The full text of the license may be found at +https://opensource.org/licenses/LGPL-3.0 +**/ + +#include +#include +#include +#include +#include +#include + +EFI_HANDLE* gTcgHandles = NULL; +UINTN gTcgCount = 0; + +EFI_HANDLE* gTcg2Handles = NULL; +UINTN gTcg2Count = 0; + +EFI_STATUS +InitTcg() { + EFI_STATUS res; + res = EfiGetHandles(ByProtocol, &gEfiTcgProtocolGuid, 0, &gTcgHandles, &gTcgCount); + res = EfiGetHandles(ByProtocol, &gEfiTcg2ProtocolGuid, 0, &gTcg2Handles, &gTcg2Count); + return res; +} + diff --git a/Library/PasswordLib/PlatformID.c b/Library/PasswordLib/PlatformID.c index 63b2e7d..100b0c0 100644 --- a/Library/PasswordLib/PlatformID.c +++ b/Library/PasswordLib/PlatformID.c @@ -24,9 +24,19 @@ SMBIOS_TABLE_ENTRY_POINT* gSmbTable = NULL; EFI_GUID* gSmbSystemUUID = NULL; // Universal unique ID CHAR8* gSmbSystemSerial = NULL; // System serial CHAR8* gSmbSystemSKU = NULL; // SKU number +CHAR8* gSmbSystemManufacture = NULL; // computer manufacture +CHAR8* gSmbSystemModel = NULL; // computer model +CHAR8* gSmbSystemVersion = NULL; // computer version + CHAR8* gSmbBaseBoardSerial = NULL; // Base board serial UINT64* gSmbProcessorID = NULL; // Processor ID +CHAR8* gSmbBiosVendor = NULL; // BIOS vendor +CHAR8* gSmbBiosVersion = NULL; // BIOS version +CHAR8* gSmbBiosDate = NULL; // BIOS date + + + UINTN gBioIndexAuth = 0; typedef struct _DCS_AUTH_DATA_MARK { UINT32 HeaderCrc; @@ -81,9 +91,18 @@ SMBIOSGetSerials() endOfTable = pSMBIOS.Raw + gSmbTable->TableLength; do { SMBIOS_STRUCTURE* smbtbl = (SMBIOS_STRUCTURE*)pos; + // BIOS information + if (smbtbl->Type == 0) { + gSmbBiosVendor = SMBIOSGetString(1, smbtbl, endOfTable); + gSmbBiosVersion = SMBIOSGetString(2, smbtbl, endOfTable); + gSmbBiosDate = SMBIOSGetString(3, smbtbl, endOfTable); + } // System info if (smbtbl->Type == 1) { gSmbSystemUUID = (EFI_GUID*)&pos[8]; + gSmbSystemManufacture = SMBIOSGetString(1, smbtbl, endOfTable); + gSmbSystemModel = SMBIOSGetString(2, smbtbl, endOfTable); + gSmbSystemVersion = SMBIOSGetString(3, smbtbl, endOfTable); gSmbSystemSerial = SMBIOSGetString(4, smbtbl, endOfTable); gSmbSystemSKU = SMBIOSGetString(5, smbtbl, endOfTable); } diff --git a/Library/VeraCryptLib/DcsConfig.c b/Library/VeraCryptLib/DcsConfig.c new file mode 100644 index 0000000..00aa5f8 --- /dev/null +++ b/Library/VeraCryptLib/DcsConfig.c @@ -0,0 +1,72 @@ +/** @file +Interface for DCS + +Copyright (c) 2016. Disk Cryptography Services for EFI (DCS), Alex Kolotnikov +Copyright (c) 2016. VeraCrypt, Mounir IDRASSI + +This program and the accompanying materials +are licensed and made available under the terms and conditions +of the Apache License, Version 2.0. + +The full text of the license may be found at +https://opensource.org/licenses/Apache-2.0 +**/ + +#include +#include + +#include +#include "common/Xml.h" + +////////////////////////////////////////////////////////////////////////// +// Config +////////////////////////////////////////////////////////////////////////// +char *gConfigBuffer = NULL; +UINTN gConfigBufferSize = 0; + +BOOLEAN +ConfigRead(char *configKey, char *configValue, int maxValueSize) +{ + char *xml; + + if (gConfigBuffer == NULL) { + if (FileLoad(NULL, L"\\EFI\\VeraCrypt\\DcsProp", &gConfigBuffer, &gConfigBufferSize) != EFI_SUCCESS) { + return FALSE; + } + } + + xml = gConfigBuffer; + if (xml != NULL) + { + xml = XmlFindElementByAttributeValue(xml, "config", "key", configKey); + if (xml != NULL) + { + XmlGetNodeText(xml, configValue, maxValueSize); + return TRUE; + } + } + + return FALSE; +} + +int ConfigReadInt(char *configKey, int defaultValue) +{ + char s[32]; + if (ConfigRead(configKey, s, sizeof(s))) { + if (*s == '-') { + return (-1) * (int)AsciiStrDecimalToUintn(&s[1]); + } + return (int)AsciiStrDecimalToUintn(s); + } + else + return defaultValue; +} + + +char *ConfigReadString(char *configKey, char *defaultValue, char *str, int maxLen) +{ + if (!ConfigRead(configKey, str, maxLen)) { + AsciiStrCpyS(str, maxLen, defaultValue); + } + return str; +} diff --git a/Library/VeraCryptLib/DcsConfig.h b/Library/VeraCryptLib/DcsConfig.h new file mode 100644 index 0000000..04719d9 --- /dev/null +++ b/Library/VeraCryptLib/DcsConfig.h @@ -0,0 +1,29 @@ +/** @file +Interface for DCS services + +Copyright (c) 2016. Disk Cryptography Services for EFI (DCS), Alex Kolotnikov +Copyright (c) 2016. VeraCrypt, Mounir IDRASSI + +This program and the accompanying materials +are licensed and made available under the terms and conditions +of the Apache License, Version 2.0. + +The full text of the license may be found at +https://opensource.org/licenses/Apache-2.0 +**/ + +#ifndef __DCSCONFIG_H__ +#define __DCSCONFIG_H__ + +#include + +////////////////////////////////////////////////////////////////////////// +// Config +////////////////////////////////////////////////////////////////////////// +extern char *gConfigBuffer; +extern UINTN gConfigBufferSize; + +BOOLEAN ConfigRead(char *configKey, char *configValue, int maxValueSize); +int ConfigReadInt(char *configKey, int defaultValue); +char *ConfigReadString(char *configKey, char *defaultValue, char *str, int maxLen); +#endif diff --git a/Library/VeraCryptLib/DcsVeraCrypt.c b/Library/VeraCryptLib/DcsVeraCrypt.c index 2979064..d5680ba 100644 --- a/Library/VeraCryptLib/DcsVeraCrypt.c +++ b/Library/VeraCryptLib/DcsVeraCrypt.c @@ -23,62 +23,11 @@ https://opensource.org/licenses/Apache-2.0 #include #include "common/Crypto.h" -#include "common/Xml.h" #include "common/Crc.h" #include "BootCommon.h" #include "Library/DcsTpmLib.h" +#include -////////////////////////////////////////////////////////////////////////// -// Config -////////////////////////////////////////////////////////////////////////// -char *gConfigBuffer = NULL; -UINTN gConfigBufferSize = 0; - -BOOL ConfigRead(char *configKey, char *configValue, int maxValueSize) -{ - char *xml; - - if (gConfigBuffer == NULL) { - if (FileLoad(NULL, L"\\EFI\\VeraCrypt\\DcsProp", &gConfigBuffer, &gConfigBufferSize) != EFI_SUCCESS) { - return FALSE; - } - } - - xml = gConfigBuffer; - if (xml != NULL) - { - xml = XmlFindElementByAttributeValue(xml, "config", "key", configKey); - if (xml != NULL) - { - XmlGetNodeText(xml, configValue, maxValueSize); - return TRUE; - } - } - - return FALSE; -} - -int ConfigReadInt(char *configKey, int defaultValue) -{ - char s[32]; - if (ConfigRead(configKey, s, sizeof(s))) { - if (*s == '-') { - return (-1) * (int)AsciiStrDecimalToUintn(&s[1]); - } - return (int)AsciiStrDecimalToUintn(s); - } - else - return defaultValue; -} - - -char *ConfigReadString(char *configKey, char *defaultValue, char *str, int maxLen) -{ - if (!ConfigRead(configKey, str, maxLen)) { - AsciiStrCpyS(str, maxLen, defaultValue); - } - return str; -} /////////////////////////////////////////////////////////////////////////// diff --git a/Library/VeraCryptLib/DcsVeraCrypt.h b/Library/VeraCryptLib/DcsVeraCrypt.h index 23eb4a2..41dc6c2 100644 --- a/Library/VeraCryptLib/DcsVeraCrypt.h +++ b/Library/VeraCryptLib/DcsVeraCrypt.h @@ -19,9 +19,6 @@ https://opensource.org/licenses/Apache-2.0 #include #include -extern char *gConfigBuffer; -extern UINTN gConfigBufferSize; - ////////////////////////////////////////////////////////////////////////// // Auth ////////////////////////////////////////////////////////////////////////// diff --git a/Library/VeraCryptLib/VeraCryptLib.inf b/Library/VeraCryptLib/VeraCryptLib.inf index 529043f..a208f9c 100644 --- a/Library/VeraCryptLib/VeraCryptLib.inf +++ b/Library/VeraCryptLib/VeraCryptLib.inf @@ -62,6 +62,8 @@ crypto\Camellia.c crypto\Camellia.h crypto\cpu.c crypto\cpu.h +DcsConfig.c +DcsConfig.h DcsVeraCrypt.c DcsVeraCrypt.h -- cgit v1.2.3