Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wine-winehq
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wine
wine-winehq
Commits
361280b2
Commit
361280b2
authored
Jun 24, 2007
by
Paul Vriens
Committed by
Alexandre Julliard
Jun 25, 2007
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wintrust/tests: Add tests for CryptCATAdminCalcHashFromFileHandle.
parent
d40233a4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
135 additions
and
0 deletions
+135
-0
crypt.c
dlls/wintrust/tests/crypt.c
+135
-0
No files found.
dlls/wintrust/tests/crypt.c
View file @
361280b2
...
...
@@ -26,10 +26,15 @@
#include "wine/test.h"
static
char
selfname
[
MAX_PATH
];
static
CHAR
CURR_DIR
[
MAX_PATH
];
static
HMODULE
hWintrust
=
0
;
static
BOOL
(
WINAPI
*
pCryptCATAdminAcquireContext
)(
HCATADMIN
*
,
const
GUID
*
,
DWORD
);
static
BOOL
(
WINAPI
*
pCryptCATAdminReleaseContext
)(
HCATADMIN
,
DWORD
);
static
BOOL
(
WINAPI
*
pCryptCATAdminCalcHashFromFileHandle
)(
HANDLE
hFile
,
DWORD
*
,
BYTE
*
,
DWORD
);
#define WINTRUST_GET_PROC(func) \
p ## func = (void*)GetProcAddress(hWintrust, #func); \
...
...
@@ -49,6 +54,7 @@ static BOOL InitFunctionPtrs(void)
WINTRUST_GET_PROC
(
CryptCATAdminAcquireContext
)
WINTRUST_GET_PROC
(
CryptCATAdminReleaseContext
)
WINTRUST_GET_PROC
(
CryptCATAdminCalcHashFromFileHandle
)
return
TRUE
;
}
...
...
@@ -159,12 +165,141 @@ static void test_context(void)
ok
(
ret
,
"Expected success
\n
"
);
}
/* TODO: Check whether SHA-1 is the algorithm that's always used */
static
void
test_calchash
(
void
)
{
BOOL
ret
;
HANDLE
file
;
DWORD
hashsize
=
0
;
BYTE
*
hash
;
BYTE
expectedhash
[
20
]
=
{
0x3a
,
0xa1
,
0x19
,
0x08
,
0xec
,
0xa6
,
0x0d
,
0x2e
,
0x7e
,
0xcc
,
0x7a
,
0xca
,
0xf5
,
0xb8
,
0x2e
,
0x62
,
0x6a
,
0xda
,
0xf0
,
0x19
};
CHAR
temp
[
MAX_PATH
];
DWORD
written
;
if
(
!
pCryptCATAdminCalcHashFromFileHandle
)
{
skip
(
"CryptCATAdminCalcHashFromFileHandle is not available
\n
"
);
return
;
}
/* All NULL */
SetLastError
(
0xdeadbeef
);
ret
=
pCryptCATAdminCalcHashFromFileHandle
(
NULL
,
NULL
,
NULL
,
0
);
todo_wine
{
ok
(
!
ret
,
"Expected failure
\n
"
);
ok
(
GetLastError
()
==
ERROR_INVALID_PARAMETER
,
"Expected ERROR_INVALID_PARAMETER, got %d
\n
"
,
GetLastError
());
}
/* NULL filehandle, rest is legal */
SetLastError
(
0xdeadbeef
);
ret
=
pCryptCATAdminCalcHashFromFileHandle
(
NULL
,
&
hashsize
,
NULL
,
0
);
todo_wine
{
ok
(
!
ret
,
"Expected failure
\n
"
);
ok
(
GetLastError
()
==
ERROR_INVALID_PARAMETER
,
"Expected ERROR_INVALID_PARAMETER, got %d
\n
"
,
GetLastError
());
}
/* Correct filehandle, rest is NULL */
file
=
CreateFileA
(
selfname
,
GENERIC_READ
,
0
,
NULL
,
OPEN_EXISTING
,
0
,
NULL
);
SetLastError
(
0xdeadbeef
);
ret
=
pCryptCATAdminCalcHashFromFileHandle
(
file
,
NULL
,
NULL
,
0
);
todo_wine
{
ok
(
!
ret
,
"Expected failure
\n
"
);
ok
(
GetLastError
()
==
ERROR_INVALID_PARAMETER
,
"Expected ERROR_INVALID_PARAMETER, got %d
\n
"
,
GetLastError
());
}
CloseHandle
(
file
);
/* All OK, but dwFlags set to 1 */
file
=
CreateFileA
(
selfname
,
GENERIC_READ
,
0
,
NULL
,
OPEN_EXISTING
,
0
,
NULL
);
SetLastError
(
0xdeadbeef
);
ret
=
pCryptCATAdminCalcHashFromFileHandle
(
file
,
&
hashsize
,
NULL
,
1
);
todo_wine
{
ok
(
!
ret
,
"Expected failure
\n
"
);
ok
(
GetLastError
()
==
ERROR_INVALID_PARAMETER
,
"Expected ERROR_INVALID_PARAMETER, got %d
\n
"
,
GetLastError
());
}
CloseHandle
(
file
);
/* All OK, requesting the size of the hash */
file
=
CreateFileA
(
selfname
,
GENERIC_READ
,
0
,
NULL
,
OPEN_EXISTING
,
0
,
NULL
);
SetLastError
(
0xdeadbeef
);
ret
=
pCryptCATAdminCalcHashFromFileHandle
(
file
,
&
hashsize
,
NULL
,
0
);
ok
(
ret
,
"Expected success
\n
"
);
todo_wine
{
ok
(
hashsize
==
20
,
" Expected a hash size of 20, got %d
\n
"
,
hashsize
);
ok
(
GetLastError
()
==
ERROR_INSUFFICIENT_BUFFER
,
"Expected ERROR_INSUFFICIENT_BUFFER, got %d
\n
"
,
GetLastError
());
}
CloseHandle
(
file
);
/* All OK, retrieve the hash
* Double the hash buffer to see what happens to the size parameter
*/
file
=
CreateFileA
(
selfname
,
GENERIC_READ
,
0
,
NULL
,
OPEN_EXISTING
,
0
,
NULL
);
hashsize
*=
2
;
hash
=
HeapAlloc
(
GetProcessHeap
(),
0
,
hashsize
);
SetLastError
(
0xdeadbeef
);
ret
=
pCryptCATAdminCalcHashFromFileHandle
(
file
,
&
hashsize
,
hash
,
0
);
ok
(
ret
,
"Expected success
\n
"
);
todo_wine
{
ok
(
hashsize
==
20
,
" Expected a hash size of 20, got %d
\n
"
,
hashsize
);
ok
(
GetLastError
()
==
ERROR_SUCCESS
,
"Expected ERROR_SUCCESS, got %d
\n
"
,
GetLastError
());
}
CloseHandle
(
file
);
HeapFree
(
GetProcessHeap
(),
0
,
hash
);
/* Do the same test with a file created and filled by ourselves (and we thus
* have a known hash for).
*/
GetTempFileNameA
(
CURR_DIR
,
"hsh"
,
0
,
temp
);
file
=
CreateFileA
(
temp
,
GENERIC_WRITE
,
0
,
NULL
,
OPEN_EXISTING
,
0
,
NULL
);
WriteFile
(
file
,
"Text in this file is needed to create a know hash"
,
49
,
&
written
,
NULL
);
CloseHandle
(
file
);
/* All OK, first request the size and then retrieve the hash */
file
=
CreateFileA
(
temp
,
GENERIC_READ
,
0
,
NULL
,
OPEN_EXISTING
,
0
,
NULL
);
hashsize
=
0
;
pCryptCATAdminCalcHashFromFileHandle
(
file
,
&
hashsize
,
NULL
,
0
);
hash
=
HeapAlloc
(
GetProcessHeap
(),
0
,
hashsize
);
SetLastError
(
0xdeadbeef
);
ret
=
pCryptCATAdminCalcHashFromFileHandle
(
file
,
&
hashsize
,
hash
,
0
);
ok
(
ret
,
"Expected success
\n
"
);
todo_wine
{
ok
(
GetLastError
()
==
ERROR_SUCCESS
,
"Expected ERROR_SUCCESS, got %d
\n
"
,
GetLastError
());
ok
(
!
memcmp
(
hash
,
expectedhash
,
sizeof
(
expectedhash
)),
"Hashes didn't match
\n
"
);
}
CloseHandle
(
file
);
HeapFree
(
GetProcessHeap
(),
0
,
hash
);
DeleteFileA
(
temp
);
}
START_TEST
(
crypt
)
{
int
myARGC
;
char
**
myARGV
;
if
(
!
InitFunctionPtrs
())
return
;
myARGC
=
winetest_get_mainargs
(
&
myARGV
);
strcpy
(
selfname
,
myARGV
[
0
]);
GetCurrentDirectoryA
(
MAX_PATH
,
CURR_DIR
);
test_context
();
test_calchash
();
FreeLibrary
(
hWintrust
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment