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
b2770127
Commit
b2770127
authored
Dec 04, 2009
by
Owen Rudge
Committed by
Alexandre Julliard
Dec 07, 2009
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
imagehlp/tests: Add tests for adding/removing multiple certificates.
parent
5bcc37a9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
14 deletions
+54
-14
integrity.c
dlls/imagehlp/tests/integrity.c
+54
-14
No files found.
dlls/imagehlp/tests/integrity.c
View file @
b2770127
...
@@ -31,6 +31,7 @@ static HMODULE hImageHlp;
...
@@ -31,6 +31,7 @@ static HMODULE hImageHlp;
static
char
test_dll_path
[
MAX_PATH
];
static
char
test_dll_path
[
MAX_PATH
];
static
BOOL
(
WINAPI
*
pImageAddCertificate
)(
HANDLE
,
LPWIN_CERTIFICATE
,
PDWORD
);
static
BOOL
(
WINAPI
*
pImageAddCertificate
)(
HANDLE
,
LPWIN_CERTIFICATE
,
PDWORD
);
static
BOOL
(
WINAPI
*
pImageEnumerateCertificates
)(
HANDLE
,
WORD
,
PDWORD
,
PDWORD
,
DWORD
);
static
BOOL
(
WINAPI
*
pImageGetCertificateData
)(
HANDLE
,
DWORD
,
LPWIN_CERTIFICATE
,
PDWORD
);
static
BOOL
(
WINAPI
*
pImageGetCertificateData
)(
HANDLE
,
DWORD
,
LPWIN_CERTIFICATE
,
PDWORD
);
static
BOOL
(
WINAPI
*
pImageGetCertificateHeader
)(
HANDLE
,
DWORD
,
LPWIN_CERTIFICATE
);
static
BOOL
(
WINAPI
*
pImageGetCertificateHeader
)(
HANDLE
,
DWORD
,
LPWIN_CERTIFICATE
);
static
BOOL
(
WINAPI
*
pImageRemoveCertificate
)(
HANDLE
,
DWORD
);
static
BOOL
(
WINAPI
*
pImageRemoveCertificate
)(
HANDLE
,
DWORD
);
...
@@ -87,6 +88,8 @@ static char test_cert_data[] =
...
@@ -87,6 +88,8 @@ static char test_cert_data[] =
,
0x46
,
0xCA
,
0xEB
,
0xEA
,
0x67
,
0x89
,
0x49
,
0x7C
,
0x43
,
0xA2
,
0x52
,
0xD9
,
0x41
,
0xCC
,
0x65
,
0x46
,
0xCA
,
0xEB
,
0xEA
,
0x67
,
0x89
,
0x49
,
0x7C
,
0x43
,
0xA2
,
0x52
,
0xD9
,
0x41
,
0xCC
,
0x65
,
0xED
,
0x2D
,
0xA1
,
0x00
,
0x31
,
0x00
};
,
0xED
,
0x2D
,
0xA1
,
0x00
,
0x31
,
0x00
};
static
char
test_cert_data_2
[]
=
{
0xDE
,
0xAD
,
0xBE
,
0xEF
,
0x01
,
0x02
,
0x03
};
static
BOOL
copy_dll_file
(
void
)
static
BOOL
copy_dll_file
(
void
)
{
{
char
sys_dir
[
MAX_PATH
+
15
];
char
sys_dir
[
MAX_PATH
+
15
];
...
@@ -116,7 +119,17 @@ static BOOL copy_dll_file(void)
...
@@ -116,7 +119,17 @@ static BOOL copy_dll_file(void)
return
TRUE
;
return
TRUE
;
}
}
static
void
test_add_certificate
(
void
)
static
DWORD
get_file_size
(
void
)
{
WIN32_FILE_ATTRIBUTE_DATA
info
;
if
(
GetFileAttributesEx
(
test_dll_path
,
GetFileExInfoStandard
,
&
info
))
return
0
;
return
info
.
nFileSizeLow
;
}
static
void
test_add_certificate
(
char
*
cert_data
,
int
len
)
{
{
HANDLE
hFile
;
HANDLE
hFile
;
LPWIN_CERTIFICATE
cert
;
LPWIN_CERTIFICATE
cert
;
...
@@ -131,7 +144,7 @@ static void test_add_certificate(void)
...
@@ -131,7 +144,7 @@ static void test_add_certificate(void)
return
;
return
;
}
}
cert_len
=
sizeof
(
WIN_CERTIFICATE
)
+
sizeof
(
test_cert_data
)
;
cert_len
=
sizeof
(
WIN_CERTIFICATE
)
+
len
;
cert
=
HeapAlloc
(
GetProcessHeap
(),
HEAP_ZERO_MEMORY
,
cert_len
);
cert
=
HeapAlloc
(
GetProcessHeap
(),
HEAP_ZERO_MEMORY
,
cert_len
);
if
(
!
cert
)
if
(
!
cert
)
...
@@ -144,7 +157,7 @@ static void test_add_certificate(void)
...
@@ -144,7 +157,7 @@ static void test_add_certificate(void)
cert
->
dwLength
=
cert_len
;
cert
->
dwLength
=
cert_len
;
cert
->
wRevision
=
WIN_CERT_REVISION_1_0
;
cert
->
wRevision
=
WIN_CERT_REVISION_1_0
;
cert
->
wCertificateType
=
WIN_CERT_TYPE_PKCS_SIGNED_DATA
;
cert
->
wCertificateType
=
WIN_CERT_TYPE_PKCS_SIGNED_DATA
;
CopyMemory
(
cert
->
bCertificate
,
test_cert_data
,
sizeof
(
test_cert_data
)
);
CopyMemory
(
cert
->
bCertificate
,
cert_data
,
len
);
ok
(
pImageAddCertificate
(
hFile
,
cert
,
&
index
),
"Unable to add certificate to image, error %x
\n
"
,
GetLastError
());
ok
(
pImageAddCertificate
(
hFile
,
cert
,
&
index
),
"Unable to add certificate to image, error %x
\n
"
,
GetLastError
());
...
@@ -152,7 +165,7 @@ static void test_add_certificate(void)
...
@@ -152,7 +165,7 @@ static void test_add_certificate(void)
CloseHandle
(
hFile
);
CloseHandle
(
hFile
);
}
}
static
void
test_get_certificate
(
void
)
static
void
test_get_certificate
(
char
*
cert_data
,
int
index
)
{
{
HANDLE
hFile
;
HANDLE
hFile
;
LPWIN_CERTIFICATE
cert
;
LPWIN_CERTIFICATE
cert
;
...
@@ -167,7 +180,7 @@ static void test_get_certificate(void)
...
@@ -167,7 +180,7 @@ static void test_get_certificate(void)
return
;
return
;
}
}
ret
=
pImageGetCertificateData
(
hFile
,
0
,
NULL
,
&
cert_len
);
ret
=
pImageGetCertificateData
(
hFile
,
index
,
NULL
,
&
cert_len
);
err
=
GetLastError
();
err
=
GetLastError
();
ok
((
ret
==
FALSE
)
&&
(
err
==
ERROR_INSUFFICIENT_BUFFER
),
"ImageGetCertificateData gave unexpected result; ret=%d / err=%x
\n
"
,
ret
,
err
);
ok
((
ret
==
FALSE
)
&&
(
err
==
ERROR_INSUFFICIENT_BUFFER
),
"ImageGetCertificateData gave unexpected result; ret=%d / err=%x
\n
"
,
ret
,
err
);
...
@@ -181,17 +194,17 @@ static void test_get_certificate(void)
...
@@ -181,17 +194,17 @@ static void test_get_certificate(void)
return
;
return
;
}
}
ok
(
ret
=
pImageGetCertificateData
(
hFile
,
0
,
cert
,
&
cert_len
),
"Unable to retrieve certificate; err=%x
\n
"
,
GetLastError
());
ok
(
ret
=
pImageGetCertificateData
(
hFile
,
index
,
cert
,
&
cert_len
),
"Unable to retrieve certificate; err=%x
\n
"
,
GetLastError
());
ok
(
memcmp
(
cert
->
bCertificate
,
test_
cert_data
,
cert_len
-
sizeof
(
WIN_CERTIFICATE
))
==
0
,
"Certificate retrieved did not match original
\n
"
);
ok
(
memcmp
(
cert
->
bCertificate
,
cert_data
,
cert_len
-
sizeof
(
WIN_CERTIFICATE
))
==
0
,
"Certificate retrieved did not match original
\n
"
);
HeapFree
(
GetProcessHeap
(),
0
,
cert
);
HeapFree
(
GetProcessHeap
(),
0
,
cert
);
CloseHandle
(
hFile
);
CloseHandle
(
hFile
);
}
}
static
void
test_remove_certificate
(
void
)
static
void
test_remove_certificate
(
int
index
)
{
{
DWORD
orig_count
=
0
,
count
=
0
;
HANDLE
hFile
;
HANDLE
hFile
;
WIN_CERTIFICATE
cert
;
hFile
=
CreateFileA
(
test_dll_path
,
GENERIC_READ
|
GENERIC_WRITE
,
FILE_SHARE_READ
,
NULL
,
OPEN_EXISTING
,
FILE_ATTRIBUTE_NORMAL
,
NULL
);
hFile
=
CreateFileA
(
test_dll_path
,
GENERIC_READ
|
GENERIC_WRITE
,
FILE_SHARE_READ
,
NULL
,
OPEN_EXISTING
,
FILE_ATTRIBUTE_NORMAL
,
NULL
);
...
@@ -201,16 +214,21 @@ static void test_remove_certificate(void)
...
@@ -201,16 +214,21 @@ static void test_remove_certificate(void)
return
;
return
;
}
}
ok
(
pImageRemoveCertificate
(
hFile
,
0
),
"Unable to remove certificate from file; err=%x
\n
"
,
GetLastError
());
ok
(
pImageEnumerateCertificates
(
hFile
,
CERT_SECTION_TYPE_ANY
,
&
orig_count
,
NULL
,
0
),
"Unable to enumerate certificates in file; err=%x
\n
"
,
GetLastError
());
ok
(
pImageRemoveCertificate
(
hFile
,
index
),
"Unable to remove certificate from file; err=%x
\n
"
,
GetLastError
());
/* Test to see if the certificate has actually been removed */
/* Test to see if the certificate has actually been removed */
ok
(
pImageGetCertificateHeader
(
hFile
,
0
,
&
cert
)
==
FALSE
,
"Certificate header retrieval succeeded when it should have failed
\n
"
);
pImageEnumerateCertificates
(
hFile
,
CERT_SECTION_TYPE_ANY
,
&
count
,
NULL
,
0
);
ok
(
count
==
orig_count
-
1
,
"Certificate count mismatch; orig=%d new=%d
\n
"
,
orig_count
,
count
);
CloseHandle
(
hFile
);
CloseHandle
(
hFile
);
}
}
START_TEST
(
integrity
)
START_TEST
(
integrity
)
{
{
DWORD
file_size
,
file_size_orig
;
hImageHlp
=
LoadLibraryA
(
"imagehlp.dll"
);
hImageHlp
=
LoadLibraryA
(
"imagehlp.dll"
);
if
(
!
hImageHlp
)
if
(
!
hImageHlp
)
...
@@ -225,14 +243,36 @@ START_TEST(integrity)
...
@@ -225,14 +243,36 @@ START_TEST(integrity)
return
;
return
;
}
}
file_size_orig
=
get_file_size
();
pImageAddCertificate
=
(
void
*
)
GetProcAddress
(
hImageHlp
,
"ImageAddCertificate"
);
pImageAddCertificate
=
(
void
*
)
GetProcAddress
(
hImageHlp
,
"ImageAddCertificate"
);
pImageEnumerateCertificates
=
(
void
*
)
GetProcAddress
(
hImageHlp
,
"ImageEnumerateCertificates"
);
pImageGetCertificateData
=
(
void
*
)
GetProcAddress
(
hImageHlp
,
"ImageGetCertificateData"
);
pImageGetCertificateData
=
(
void
*
)
GetProcAddress
(
hImageHlp
,
"ImageGetCertificateData"
);
pImageGetCertificateHeader
=
(
void
*
)
GetProcAddress
(
hImageHlp
,
"ImageGetCertificateHeader"
);
pImageGetCertificateHeader
=
(
void
*
)
GetProcAddress
(
hImageHlp
,
"ImageGetCertificateHeader"
);
pImageRemoveCertificate
=
(
void
*
)
GetProcAddress
(
hImageHlp
,
"ImageRemoveCertificate"
);
pImageRemoveCertificate
=
(
void
*
)
GetProcAddress
(
hImageHlp
,
"ImageRemoveCertificate"
);
test_add_certificate
();
test_add_certificate
(
test_cert_data
,
sizeof
(
test_cert_data
));
test_get_certificate
();
test_get_certificate
(
test_cert_data
,
0
);
test_remove_certificate
();
test_remove_certificate
(
0
);
file_size
=
get_file_size
();
ok
(
file_size
==
file_size_orig
,
"File size different after add and remove (old: %d; new: %d)
\n
"
,
file_size_orig
,
file_size
);
/* Try adding multiple certificates */
test_add_certificate
(
test_cert_data
,
sizeof
(
test_cert_data
));
test_add_certificate
(
test_cert_data_2
,
sizeof
(
test_cert_data_2
));
test_get_certificate
(
test_cert_data
,
0
);
test_get_certificate
(
test_cert_data_2
,
1
);
/* Remove the first one and verify the second certificate is intact */
test_remove_certificate
(
0
);
test_get_certificate
(
test_cert_data_2
,
0
);
test_remove_certificate
(
0
);
file_size
=
get_file_size
();
ok
(
file_size
==
file_size_orig
,
"File size different after add and remove (old: %d; new: %d)
\n
"
,
file_size_orig
,
file_size
);
FreeLibrary
(
hImageHlp
);
FreeLibrary
(
hImageHlp
);
DeleteFile
(
test_dll_path
);
DeleteFile
(
test_dll_path
);
...
...
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