mirror of
https://github.com/winfsp/winfsp.git
synced 2025-04-22 08:23:05 -05:00
ku: UUID v5 generation
This commit is contained in:
parent
dbdfaeee1f
commit
89ec3e6733
@ -204,6 +204,7 @@
|
||||
<ClCompile Include="..\..\..\tst\winfsp-tests\security-test.c" />
|
||||
<ClCompile Include="..\..\..\tst\winfsp-tests\stream-tests.c" />
|
||||
<ClCompile Include="..\..\..\tst\winfsp-tests\timeout-test.c" />
|
||||
<ClCompile Include="..\..\..\tst\winfsp-tests\uuid5-test.c" />
|
||||
<ClCompile Include="..\..\..\tst\winfsp-tests\version-test.c" />
|
||||
<ClCompile Include="..\..\..\tst\winfsp-tests\volpath-test.c" />
|
||||
<ClCompile Include="..\..\..\tst\winfsp-tests\winfsp-tests.c" />
|
||||
|
@ -106,6 +106,9 @@
|
||||
<ClCompile Include="..\..\..\tst\winfsp-tests\volpath-test.c">
|
||||
<Filter>Source</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\tst\winfsp-tests\uuid5-test.c">
|
||||
<Filter>Source</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\..\ext\tlib\testsuite.h">
|
||||
|
@ -105,7 +105,7 @@
|
||||
<PreprocessorDefinitions> _X86_=1;i386=1;STD_CALL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<AdditionalDependencies>wdmsec.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>cng.lib;wdmsec.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<GenerateMapFile>true</GenerateMapFile>
|
||||
<ProgramDatabaseFile>$(OutDir)$(TargetFileName).pdb</ProgramDatabaseFile>
|
||||
<MapFileName>$(OutDir)$(TargetFileName).map</MapFileName>
|
||||
@ -118,7 +118,7 @@
|
||||
<PreprocessorDefinitions> _X86_=1;i386=1;STD_CALL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<AdditionalDependencies>wdmsec.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>cng.lib;wdmsec.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<GenerateMapFile>true</GenerateMapFile>
|
||||
<ProgramDatabaseFile>$(OutDir)$(TargetFileName).pdb</ProgramDatabaseFile>
|
||||
<MapFileName>$(OutDir)$(TargetFileName).map</MapFileName>
|
||||
@ -131,7 +131,7 @@
|
||||
<PreprocessorDefinitions> _WIN64;_AMD64_;AMD64;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<AdditionalDependencies>wdmsec.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>cng.lib;wdmsec.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<GenerateMapFile>true</GenerateMapFile>
|
||||
<ProgramDatabaseFile>$(OutDir)$(TargetFileName).pdb</ProgramDatabaseFile>
|
||||
<MapFileName>$(OutDir)$(TargetFileName).map</MapFileName>
|
||||
@ -144,7 +144,7 @@
|
||||
<PreprocessorDefinitions> _WIN64;_AMD64_;AMD64;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<AdditionalDependencies>wdmsec.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>cng.lib;wdmsec.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<GenerateMapFile>true</GenerateMapFile>
|
||||
<ProgramDatabaseFile>$(OutDir)$(TargetFileName).pdb</ProgramDatabaseFile>
|
||||
<MapFileName>$(OutDir)$(TargetFileName).map</MapFileName>
|
||||
@ -156,6 +156,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\src\ku\posix.c" />
|
||||
<ClCompile Include="..\..\src\ku\uuid5.c" />
|
||||
<ClCompile Include="..\..\src\sys\cleanup.c" />
|
||||
<ClCompile Include="..\..\src\sys\close.c" />
|
||||
<ClCompile Include="..\..\src\sys\create.c" />
|
||||
|
@ -113,6 +113,9 @@
|
||||
<ClCompile Include="..\..\src\ku\posix.c">
|
||||
<Filter>Source\ku</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\ku\uuid5.c">
|
||||
<Filter>Source\ku</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\src\sys\driver.h">
|
||||
|
134
src/ku/uuid5.c
Normal file
134
src/ku/uuid5.c
Normal file
@ -0,0 +1,134 @@
|
||||
/**
|
||||
* @file dll/uuid5.c
|
||||
*
|
||||
* @copyright 2015-2019 Bill Zissimopoulos
|
||||
*/
|
||||
/*
|
||||
* This file is part of WinFsp.
|
||||
*
|
||||
* You can redistribute it and/or modify it under the terms of the GNU
|
||||
* General Public License version 3 as published by the Free Software
|
||||
* Foundation.
|
||||
*
|
||||
* Licensees holding a valid commercial license may use this software
|
||||
* in accordance with the commercial license agreement provided in
|
||||
* conjunction with the software. The terms and conditions of any such
|
||||
* commercial license agreement shall govern, supersede, and render
|
||||
* ineffective any application of the GPLv3 license to this software,
|
||||
* notwithstanding of any reference thereto in the software or
|
||||
* associated repository.
|
||||
*/
|
||||
|
||||
#include <ku/library.h>
|
||||
#include <bcrypt.h>
|
||||
|
||||
/*
|
||||
* This module is used to create UUID v5 identifiers. UUID v5 identifiers
|
||||
* are effectively SHA1 hashes that are modified to fit within the UUID
|
||||
* format. The resulting identifiers use version 5 and variant 2. The hash
|
||||
* is taken over the concatenation of a namespace ID and a name; the namespace
|
||||
* ID is another UUID and the name can be any string of bytes ("octets").
|
||||
*
|
||||
* For details see RFC 4122: https://tools.ietf.org/html/rfc4122
|
||||
*/
|
||||
|
||||
NTSTATUS FspUuid5Make(const UUID *Namespace, const VOID *Buffer, ULONG Size, UUID *Uuid)
|
||||
{
|
||||
BCRYPT_ALG_HANDLE ProvHandle = 0;
|
||||
BCRYPT_HASH_HANDLE HashHandle = 0;
|
||||
UINT8 Temp[20];
|
||||
NTSTATUS Result;
|
||||
|
||||
/*
|
||||
* Windows UUID's are encoded in little-endian format. RFC 4122 specifies that for
|
||||
* UUID v5 computation, UUID's must be converted to/from big-endian.
|
||||
*
|
||||
* Note that Windows is always little-endian:
|
||||
* https://community.osr.com/discussion/comment/146810/#Comment_146810
|
||||
*/
|
||||
|
||||
/* copy Namespace to local buffer in network byte order (big-endian) */
|
||||
Temp[ 0] = ((PUINT8)Namespace)[ 3];
|
||||
Temp[ 1] = ((PUINT8)Namespace)[ 2];
|
||||
Temp[ 2] = ((PUINT8)Namespace)[ 1];
|
||||
Temp[ 3] = ((PUINT8)Namespace)[ 0];
|
||||
Temp[ 4] = ((PUINT8)Namespace)[ 5];
|
||||
Temp[ 5] = ((PUINT8)Namespace)[ 4];
|
||||
Temp[ 6] = ((PUINT8)Namespace)[ 7];
|
||||
Temp[ 7] = ((PUINT8)Namespace)[ 6];
|
||||
Temp[ 8] = ((PUINT8)Namespace)[ 8];
|
||||
Temp[ 9] = ((PUINT8)Namespace)[ 9];
|
||||
Temp[10] = ((PUINT8)Namespace)[10];
|
||||
Temp[11] = ((PUINT8)Namespace)[11];
|
||||
Temp[12] = ((PUINT8)Namespace)[12];
|
||||
Temp[13] = ((PUINT8)Namespace)[13];
|
||||
Temp[14] = ((PUINT8)Namespace)[14];
|
||||
Temp[15] = ((PUINT8)Namespace)[15];
|
||||
|
||||
/*
|
||||
* Unfortunately we cannot reuse the hashing object, because BCRYPT_HASH_REUSABLE_FLAG
|
||||
* is available in Windows 8 and later. (WinFsp currently supports Windows 7 or later).
|
||||
*/
|
||||
|
||||
Result = BCryptOpenAlgorithmProvider(&ProvHandle, BCRYPT_SHA1_ALGORITHM, 0, 0);
|
||||
if (!NT_SUCCESS(Result))
|
||||
goto exit;
|
||||
|
||||
Result = BCryptCreateHash(ProvHandle, &HashHandle, 0, 0, 0, 0, 0);
|
||||
if (!NT_SUCCESS(Result))
|
||||
goto exit;
|
||||
|
||||
Result = BCryptHashData(HashHandle, (PVOID)Temp, 16, 0);
|
||||
if (!NT_SUCCESS(Result))
|
||||
goto exit;
|
||||
|
||||
Result = BCryptHashData(HashHandle, (PVOID)Buffer, Size, 0);
|
||||
if (!NT_SUCCESS(Result))
|
||||
goto exit;
|
||||
|
||||
Result = BCryptFinishHash(HashHandle, Temp, 20, 0);
|
||||
if (!NT_SUCCESS(Result))
|
||||
goto exit;
|
||||
|
||||
/* copy local buffer to Uuid in host byte order (little-endian) */
|
||||
((PUINT8)Uuid)[ 0] = Temp[ 3];
|
||||
((PUINT8)Uuid)[ 1] = Temp[ 2];
|
||||
((PUINT8)Uuid)[ 2] = Temp[ 1];
|
||||
((PUINT8)Uuid)[ 3] = Temp[ 0];
|
||||
((PUINT8)Uuid)[ 4] = Temp[ 5];
|
||||
((PUINT8)Uuid)[ 5] = Temp[ 4];
|
||||
((PUINT8)Uuid)[ 6] = Temp[ 7];
|
||||
((PUINT8)Uuid)[ 7] = Temp[ 6];
|
||||
((PUINT8)Uuid)[ 8] = Temp[ 8];
|
||||
((PUINT8)Uuid)[ 9] = Temp[ 9];
|
||||
((PUINT8)Uuid)[10] = Temp[10];
|
||||
((PUINT8)Uuid)[11] = Temp[11];
|
||||
((PUINT8)Uuid)[12] = Temp[12];
|
||||
((PUINT8)Uuid)[13] = Temp[13];
|
||||
((PUINT8)Uuid)[14] = Temp[14];
|
||||
((PUINT8)Uuid)[15] = Temp[15];
|
||||
|
||||
/* [RFC 4122 Section 4.3]
|
||||
* Set the four most significant bits (bits 12 through 15) of the
|
||||
* time_hi_and_version field to the appropriate 4-bit version number
|
||||
* from Section 4.1.3.
|
||||
*/
|
||||
Uuid->Data3 = (5 << 12) | (Uuid->Data3 & 0x0fff);
|
||||
|
||||
/* [RFC 4122 Section 4.3]
|
||||
* Set the two most significant bits (bits 6 and 7) of the
|
||||
* clock_seq_hi_and_reserved to zero and one, respectively.
|
||||
*/
|
||||
Uuid->Data4[0] = (2 << 6) | (Uuid->Data4[0] & 0x3f);
|
||||
|
||||
Result = STATUS_SUCCESS;
|
||||
|
||||
exit:
|
||||
if (0 != HashHandle)
|
||||
BCryptDestroyHash(HashHandle);
|
||||
|
||||
if (0 != ProvHandle)
|
||||
BCryptCloseAlgorithmProvider(ProvHandle, 0);
|
||||
|
||||
return Result;
|
||||
}
|
@ -493,6 +493,9 @@ NTSTATUS FspFileNameInExpression(
|
||||
PWCH UpcaseTable,
|
||||
PBOOLEAN PResult);
|
||||
|
||||
/* UUID5 creation (ku) */
|
||||
NTSTATUS FspUuid5Make(const UUID *Namespace, const VOID *Buffer, ULONG Size, UUID *Uuid);
|
||||
|
||||
/* utility */
|
||||
PVOID FspAllocatePoolMustSucceed(POOL_TYPE PoolType, SIZE_T Size, ULONG Tag);
|
||||
PVOID FspAllocateIrpMustSucceed(CCHAR StackSize);
|
||||
|
60
tst/winfsp-tests/uuid5-test.c
Normal file
60
tst/winfsp-tests/uuid5-test.c
Normal file
@ -0,0 +1,60 @@
|
||||
/**
|
||||
* @file uuid5-test.c
|
||||
*
|
||||
* @copyright 2015-2019 Bill Zissimopoulos
|
||||
*/
|
||||
/*
|
||||
* This file is part of WinFsp.
|
||||
*
|
||||
* You can redistribute it and/or modify it under the terms of the GNU
|
||||
* General Public License version 3 as published by the Free Software
|
||||
* Foundation.
|
||||
*
|
||||
* Licensees holding a valid commercial license may use this software
|
||||
* in accordance with the commercial license agreement provided in
|
||||
* conjunction with the software. The terms and conditions of any such
|
||||
* commercial license agreement shall govern, supersede, and render
|
||||
* ineffective any application of the GPLv3 license to this software,
|
||||
* notwithstanding of any reference thereto in the software or
|
||||
* associated repository.
|
||||
*/
|
||||
|
||||
#include <winfsp/winfsp.h>
|
||||
#include <tlib/testsuite.h>
|
||||
|
||||
#include "winfsp-tests.h"
|
||||
|
||||
#pragma comment(lib, "bcrypt.lib")
|
||||
#include <ku/uuid5.c>
|
||||
|
||||
static void uuid5_test(void)
|
||||
{
|
||||
// 6ba7b810-9dad-11d1-80b4-00c04fd430c8
|
||||
static const GUID GuidNs =
|
||||
{ 0x6ba7b810, 0x9dad, 0x11d1, { 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8 } };
|
||||
// 74738ff5-5367-5958-9aee-98fffdcd1876
|
||||
static const GUID Guid0 =
|
||||
{ 0x74738ff5, 0x5367, 0x5958, { 0x9a, 0xee, 0x98, 0xff, 0xfd, 0xcd, 0x18, 0x76 } };
|
||||
// 63b5d721-0b97-5e7a-a550-2f0e589b5478
|
||||
static const GUID Guid1 =
|
||||
{ 0x63b5d721, 0x0b97, 0x5e7a, { 0xa5, 0x50, 0x2f, 0x0e, 0x58, 0x9b, 0x54, 0x78 } };
|
||||
|
||||
NTSTATUS Result;
|
||||
GUID Guid;
|
||||
|
||||
Result = FspUuid5Make(&GuidNs, "www.example.org", 15, &Guid);
|
||||
ASSERT(NT_SUCCESS(Result));
|
||||
ASSERT(IsEqualGUID(&Guid0, &Guid));
|
||||
|
||||
Result = FspUuid5Make(&FspFsvrtDeviceClassGuid, "hello", 5, &Guid);
|
||||
ASSERT(NT_SUCCESS(Result));
|
||||
ASSERT(IsEqualGUID(&Guid1, &Guid));
|
||||
}
|
||||
|
||||
void uuid5_tests(void)
|
||||
{
|
||||
if (OptExternal)
|
||||
return;
|
||||
|
||||
TEST(uuid5_test);
|
||||
}
|
@ -188,6 +188,7 @@ int main(int argc, char *argv[])
|
||||
TESTSUITE(fuse_opt_tests);
|
||||
TESTSUITE(fuse_tests);
|
||||
TESTSUITE(posix_tests);
|
||||
TESTSUITE(uuid5_tests);
|
||||
TESTSUITE(eventlog_tests);
|
||||
TESTSUITE(path_tests);
|
||||
TESTSUITE(dirbuf_tests);
|
||||
|
Loading…
x
Reference in New Issue
Block a user