ReactOS 0.4.15-dev-8064-gdaf8068
softpub.c File Reference
#include <stdio.h>
#include <stdarg.h>
#include <windef.h>
#include <winbase.h>
#include <winerror.h>
#include <wintrust.h>
#include <softpub.h>
#include <mssip.h>
#include <winuser.h>
#include "winnls.h"
#include "wine/test.h"
#include <pshpack1.h>
#include <poppack.h>
Include dependency graph for softpub.c:

Go to the source code of this file.

Classes

struct  _SAFE_PROVIDER_FUNCTIONS
 
struct  Imports
 
struct  Imports::__IMPORT_BY_NAME
 
struct  _PeImage
 

Macros

#define WINTRUST_GET_PROC(func)
 
#define CRYPT32_GET_PROC(func)
 
#define VA_START   0x400000
 
#define FILE_PE_START   0x50
 
#define NUM_SECTIONS   3
 
#define FILE_TEXT   0x200
 
#define RVA_TEXT   0x1000
 
#define RVA_BSS   0x2000
 
#define FILE_IDATA   0x400
 
#define RVA_IDATA   0x3000
 
#define FILE_TOTAL   0x600
 
#define RVA_TOTAL   0x4000
 
#define EXIT_PROCESS   (VA_START+RVA_IDATA+FIELD_OFFSET(struct Imports, thunks))
 

Typedefs

typedef void *(WINAPISAFE_MEM_ALLOC) (DWORD)
 
typedef void(WINAPISAFE_MEM_FREE) (void *)
 
typedef BOOL(WINAPISAFE_ADD_STORE) (CRYPT_PROVIDER_DATA *, HCERTSTORE)
 
typedef BOOL(WINAPISAFE_ADD_SGNR) (CRYPT_PROVIDER_DATA *, BOOL, DWORD, struct _CRYPT_PROVIDER_SGNR *)
 
typedef BOOL(WINAPISAFE_ADD_CERT) (CRYPT_PROVIDER_DATA *, DWORD, BOOL, DWORD, PCCERT_CONTEXT)
 
typedef BOOL(WINAPISAFE_ADD_PRIVDATA) (CRYPT_PROVIDER_DATA *, CRYPT_PROVIDER_PRIVDATA *)
 
typedef HRESULT(WINAPISAFE_PROVIDER_INIT_CALL) (CRYPT_PROVIDER_DATA *)
 
typedef HRESULT(WINAPISAFE_PROVIDER_OBJTRUST_CALL) (CRYPT_PROVIDER_DATA *)
 
typedef HRESULT(WINAPISAFE_PROVIDER_SIGTRUST_CALL) (CRYPT_PROVIDER_DATA *)
 
typedef HRESULT(WINAPISAFE_PROVIDER_CERTTRUST_CALL) (CRYPT_PROVIDER_DATA *)
 
typedef HRESULT(WINAPISAFE_PROVIDER_FINALPOLICY_CALL) (CRYPT_PROVIDER_DATA *)
 
typedef HRESULT(WINAPISAFE_PROVIDER_TESTFINALPOLICY_CALL) (CRYPT_PROVIDER_DATA *)
 
typedef HRESULT(WINAPISAFE_PROVIDER_CLEANUP_CALL) (CRYPT_PROVIDER_DATA *)
 
typedef BOOL(WINAPISAFE_PROVIDER_CERTCHKPOLICY_CALL) (CRYPT_PROVIDER_DATA *, DWORD, BOOL, DWORD)
 
typedef struct _SAFE_PROVIDER_FUNCTIONS SAFE_PROVIDER_FUNCTIONS
 

Functions

static BOOL (WINAPI *pWTHelperGetKnownUsages)(DWORD action
 
static DWORD SIP_INDIRECT_DATA *static VOID (WINAPI *CertFreeCertificateChain_p)(PCCERT_CHAIN_CONTEXT)
 
static void InitFunctionPtrs (void)
 
static void test_utils (SAFE_PROVIDER_FUNCTIONS *funcs)
 
static void testInitialize (SAFE_PROVIDER_FUNCTIONS *funcs, GUID *actionID)
 
static void getNotepadPath (WCHAR *notepadPathW, DWORD size)
 
static HANDLE create_temp_file (WCHAR *temp_file)
 
static void testObjTrust (SAFE_PROVIDER_FUNCTIONS *funcs, GUID *actionID)
 
static void testCertTrust (SAFE_PROVIDER_FUNCTIONS *funcs, GUID *actionID)
 
static void test_provider_funcs (void)
 
static void test_sip_create_indirect_data (void)
 
static void test_wintrust (void)
 
static void call_winverify (WCHAR *pathW, LONG *status, BOOL hash_only)
 
static void test_wintrust_digest (void)
 
static void test_get_known_usages (void)
 
static void test_WTHelperGetProvCertFromChain (void)
 
 START_TEST (softpub)
 

Variables

static PCCRYPT_OID_INFO ** usages
 
static const BYTE v1CertWithPubKey []
 
static const BYTE selfSignedCert []
 
static struct _PeImage bin
 
static const BYTE SelfSignedFile32 []
 
static const BYTE SelfSignedFile64 []
 

Macro Definition Documentation

◆ CRYPT32_GET_PROC

#define CRYPT32_GET_PROC (   func)
Value:
func ## _p = (void*)GetProcAddress(hCrypt32, #func); \
if(!func ## _p) { \
trace("GetProcAddress(%s) failed\n", #func); \
}
#define GetProcAddress(x, y)
Definition: compat.h:753
GLenum func
Definition: glext.h:6028

◆ EXIT_PROCESS

#define EXIT_PROCESS   (VA_START+RVA_IDATA+FIELD_OFFSET(struct Imports, thunks))

Definition at line 668 of file softpub.c.

◆ FILE_IDATA

#define FILE_IDATA   0x400

Definition at line 653 of file softpub.c.

◆ FILE_PE_START

#define FILE_PE_START   0x50

Definition at line 648 of file softpub.c.

◆ FILE_TEXT

#define FILE_TEXT   0x200

Definition at line 650 of file softpub.c.

◆ FILE_TOTAL

#define FILE_TOTAL   0x600

Definition at line 655 of file softpub.c.

◆ NUM_SECTIONS

#define NUM_SECTIONS   3

Definition at line 649 of file softpub.c.

◆ RVA_BSS

#define RVA_BSS   0x2000

Definition at line 652 of file softpub.c.

◆ RVA_IDATA

#define RVA_IDATA   0x3000

Definition at line 654 of file softpub.c.

◆ RVA_TEXT

#define RVA_TEXT   0x1000

Definition at line 651 of file softpub.c.

◆ RVA_TOTAL

#define RVA_TOTAL   0x4000

Definition at line 656 of file softpub.c.

◆ VA_START

#define VA_START   0x400000

Definition at line 647 of file softpub.c.

◆ WINTRUST_GET_PROC

#define WINTRUST_GET_PROC (   func)
Value:
p ## func = (void*)GetProcAddress(hWintrust, #func); \
if(!p ## func) { \
trace("GetProcAddress(%s) failed\n", #func); \
}
GLfloat GLfloat p
Definition: glext.h:8902

Typedef Documentation

◆ SAFE_ADD_CERT

typedef BOOL(WINAPI * SAFE_ADD_CERT) (CRYPT_PROVIDER_DATA *, DWORD, BOOL, DWORD, PCCERT_CONTEXT)

Definition at line 46 of file softpub.c.

◆ SAFE_ADD_PRIVDATA

typedef BOOL(WINAPI * SAFE_ADD_PRIVDATA) (CRYPT_PROVIDER_DATA *, CRYPT_PROVIDER_PRIVDATA *)

Definition at line 48 of file softpub.c.

◆ SAFE_ADD_SGNR

Definition at line 44 of file softpub.c.

◆ SAFE_ADD_STORE

typedef BOOL(WINAPI * SAFE_ADD_STORE) (CRYPT_PROVIDER_DATA *, HCERTSTORE)

Definition at line 42 of file softpub.c.

◆ SAFE_MEM_ALLOC

typedef void *(WINAPI * SAFE_MEM_ALLOC) (DWORD)

Definition at line 40 of file softpub.c.

◆ SAFE_MEM_FREE

typedef void(WINAPI * SAFE_MEM_FREE) (void *)

Definition at line 41 of file softpub.c.

◆ SAFE_PROVIDER_CERTCHKPOLICY_CALL

typedef BOOL(WINAPI * SAFE_PROVIDER_CERTCHKPOLICY_CALL) (CRYPT_PROVIDER_DATA *, DWORD, BOOL, DWORD)

Definition at line 58 of file softpub.c.

◆ SAFE_PROVIDER_CERTTRUST_CALL

typedef HRESULT(WINAPI * SAFE_PROVIDER_CERTTRUST_CALL) (CRYPT_PROVIDER_DATA *)

Definition at line 53 of file softpub.c.

◆ SAFE_PROVIDER_CLEANUP_CALL

typedef HRESULT(WINAPI * SAFE_PROVIDER_CLEANUP_CALL) (CRYPT_PROVIDER_DATA *)

Definition at line 57 of file softpub.c.

◆ SAFE_PROVIDER_FINALPOLICY_CALL

typedef HRESULT(WINAPI * SAFE_PROVIDER_FINALPOLICY_CALL) (CRYPT_PROVIDER_DATA *)

Definition at line 54 of file softpub.c.

◆ SAFE_PROVIDER_FUNCTIONS

◆ SAFE_PROVIDER_INIT_CALL

typedef HRESULT(WINAPI * SAFE_PROVIDER_INIT_CALL) (CRYPT_PROVIDER_DATA *)

Definition at line 50 of file softpub.c.

◆ SAFE_PROVIDER_OBJTRUST_CALL

typedef HRESULT(WINAPI * SAFE_PROVIDER_OBJTRUST_CALL) (CRYPT_PROVIDER_DATA *)

Definition at line 51 of file softpub.c.

◆ SAFE_PROVIDER_SIGTRUST_CALL

typedef HRESULT(WINAPI * SAFE_PROVIDER_SIGTRUST_CALL) (CRYPT_PROVIDER_DATA *)

Definition at line 52 of file softpub.c.

◆ SAFE_PROVIDER_TESTFINALPOLICY_CALL

typedef HRESULT(WINAPI * SAFE_PROVIDER_TESTFINALPOLICY_CALL) (CRYPT_PROVIDER_DATA *)

Definition at line 55 of file softpub.c.

Function Documentation

◆ BOOL()

static BOOL ( WINAPI pWTHelperGetKnownUsages)
static

◆ call_winverify()

static void call_winverify ( WCHAR pathW,
LONG status,
BOOL  hash_only 
)
static

Definition at line 1114 of file softpub.c.

1115{
1116 static GUID WVTPolicyGUID = WINTRUST_ACTION_GENERIC_VERIFY_V2;
1117 WINTRUST_FILE_INFO file_info = { sizeof(file_info), 0 };
1118 WINTRUST_DATA data = { sizeof(data), 0 };
1119 LONG ret;
1120
1121 file_info.pcwszFilePath = pathW;
1122
1123 data.dwUIChoice = WTD_UI_NONE;
1124 data.fdwRevocationChecks = WTD_REVOKE_NONE;
1125 data.dwUnionChoice = WTD_CHOICE_FILE;
1126 data.pFile = &file_info;
1127 data.dwStateAction = WTD_STATEACTION_VERIFY;
1128 data.dwProvFlags = hash_only ? WTD_HASH_ONLY_FLAG : 0;
1129 *status = WinVerifyTrust(NULL, &WVTPolicyGUID, &data);
1130
1131 data.dwStateAction = WTD_STATEACTION_CLOSE;
1132 ret = WinVerifyTrust(NULL, &WVTPolicyGUID, &data);
1133 ok(ret == S_OK, "WinVerifyTrust failed: %08x\n", ret);
1134}
#define ok(value,...)
Definition: atltest.h:57
#define NULL
Definition: types.h:112
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
#define S_OK
Definition: intsafe.h:52
long LONG
Definition: pedump.c:60
#define WINTRUST_ACTION_GENERIC_VERIFY_V2
Definition: softpub.h:108
Definition: ps.c:97
int ret
#define WTD_HASH_ONLY_FLAG
Definition: wintrust.h:137
#define WTD_STATEACTION_CLOSE
Definition: wintrust.h:124
#define WTD_STATEACTION_VERIFY
Definition: wintrust.h:123
#define WTD_REVOKE_NONE
Definition: wintrust.h:88
#define WTD_UI_NONE
Definition: wintrust.h:84
#define WTD_CHOICE_FILE
Definition: wintrust.h:91
LONG WINAPI WinVerifyTrust(HWND hwnd, GUID *ActionID, LPVOID ActionData)

Referenced by test_wintrust_digest().

◆ create_temp_file()

static HANDLE create_temp_file ( WCHAR temp_file)
static

Definition at line 286 of file softpub.c.

287{
290
292 {
293 static const WCHAR img[] = { 'i','m','g',0 };
294
298 }
299 return file;
300}
#define ARRAY_SIZE(A)
Definition: main.h:33
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define GENERIC_READ
Definition: compat.h:135
#define MAX_PATH
Definition: compat.h:34
#define CreateFileW
Definition: compat.h:741
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
DWORD WINAPI GetTempPathW(IN DWORD count, OUT LPWSTR path)
Definition: path.c:2080
UINT WINAPI GetTempFileNameW(IN LPCWSTR lpPathName, IN LPCWSTR lpPrefixString, IN UINT uUnique, OUT LPWSTR lpTempFileName)
Definition: filename.c:84
GLint GLvoid * img
Definition: gl.h:1956
#define CREATE_ALWAYS
Definition: disk.h:72
char temp_path[MAX_PATH]
Definition: mspatcha.c:123
#define GENERIC_WRITE
Definition: nt_native.h:90
Definition: fci.c:127
Definition: fci.c:110
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by test_bind_image_ex(), test_get_digest_stream(), test_image_load(), test_sip_create_indirect_data(), test_wintrust(), test_wintrust_digest(), and testObjTrust().

◆ getNotepadPath()

static void getNotepadPath ( WCHAR notepadPathW,
DWORD  size 
)
static

Definition at line 272 of file softpub.c.

273{
274 static const CHAR notepad[] = "\\notepad.exe";
275 CHAR notepadPath[MAX_PATH];
276
277 /* Workaround missing W-functions for win9x */
278 GetWindowsDirectoryA(notepadPath, MAX_PATH);
279 lstrcatA(notepadPath, notepad);
280 MultiByteToWideChar(CP_ACP, 0, notepadPath, -1, notepadPathW, size);
281}
#define CP_ACP
Definition: compat.h:109
#define MultiByteToWideChar
Definition: compat.h:110
UINT WINAPI GetWindowsDirectoryA(OUT LPSTR lpBuffer, IN UINT uSize)
Definition: path.c:2337
GLsizeiptr size
Definition: glext.h:5919
LPSTR WINAPI lstrcatA(LPSTR lpString1, LPCSTR lpString2)
Definition: lstring.c:123
char CHAR
Definition: xmlstorage.h:175

Referenced by test_wintrust(), and testObjTrust().

◆ InitFunctionPtrs()

static void InitFunctionPtrs ( void  )
static

Definition at line 85 of file softpub.c.

86{
87 HMODULE hWintrust = GetModuleHandleA("wintrust.dll");
88 HMODULE hCrypt32 = GetModuleHandleA("crypt32.dll");
89
90#define WINTRUST_GET_PROC(func) \
91 p ## func = (void*)GetProcAddress(hWintrust, #func); \
92 if(!p ## func) { \
93 trace("GetProcAddress(%s) failed\n", #func); \
94 }
95
97
98#undef WINTRUST_GET_PROC
99
100#define CRYPT32_GET_PROC(func) \
101 func ## _p = (void*)GetProcAddress(hCrypt32, #func); \
102 if(!func ## _p) { \
103 trace("GetProcAddress(%s) failed\n", #func); \
104 }
105
108
109#undef CRYPT32_GET_PROC
110}
VOID WINAPI CertFreeCertificateChain(PCCERT_CHAIN_CONTEXT pChainContext)
Definition: chain.c:2960
BOOL WINAPI CryptSIPCreateIndirectData(SIP_SUBJECTINFO *pSubjectInfo, DWORD *pcbIndirectData, SIP_INDIRECT_DATA *pIndirectData)
Definition: sip.c:715
BOOL WINAPI WTHelperGetKnownUsages(DWORD action, PCCRYPT_OID_INFO **usages)
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
#define CRYPT32_GET_PROC(func)
#define WINTRUST_GET_PROC(func)

Referenced by START_TEST().

◆ START_TEST()

START_TEST ( softpub  )

Definition at line 1311 of file softpub.c.

1312{
1316 test_wintrust();
1320}
static void test_get_known_usages(void)
Definition: softpub.c:1239
static void test_WTHelperGetProvCertFromChain(void)
Definition: softpub.c:1303
static void test_provider_funcs(void)
Definition: softpub.c:627
static void test_sip_create_indirect_data(void)
Definition: softpub.c:738
static void InitFunctionPtrs(void)
Definition: softpub.c:85
static void test_wintrust(void)
Definition: softpub.c:825
static void test_wintrust_digest(void)
Definition: softpub.c:1136

◆ test_get_known_usages()

static void test_get_known_usages ( void  )
static

Definition at line 1239 of file softpub.c.

1240{
1241 BOOL ret;
1243
1244 if (!pWTHelperGetKnownUsages)
1245 {
1246 skip("missing WTHelperGetKnownUsages\n");
1247 return;
1248 }
1249 SetLastError(0xdeadbeef);
1250 ret = pWTHelperGetKnownUsages(0, NULL);
1252 "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
1253 SetLastError(0xdeadbeef);
1254 ret = pWTHelperGetKnownUsages(1, NULL);
1256 "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
1257 SetLastError(0xdeadbeef);
1258 ret = pWTHelperGetKnownUsages(0, &usages);
1260 "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
1261 /* A value of 1 for the first parameter seems to imply the value is
1262 * allocated
1263 */
1264 SetLastError(0xdeadbeef);
1265 usages = NULL;
1266 ret = pWTHelperGetKnownUsages(1, &usages);
1267 ok(ret, "WTHelperGetKnownUsages failed: %d\n", GetLastError());
1268 ok(usages != NULL, "expected a pointer\n");
1269 if (ret && usages)
1270 {
1272
1273 /* The returned usages are an array of PCCRYPT_OID_INFOs, terminated with a
1274 * NULL pointer.
1275 */
1276 for (ptr = usages; *ptr; ptr++)
1277 {
1278 ok((*ptr)->cbSize == sizeof(CRYPT_OID_INFO) ||
1279 (*ptr)->cbSize == (sizeof(CRYPT_OID_INFO) + 2 * sizeof(LPCWSTR)), /* Vista */
1280 "unexpected size %d\n", (*ptr)->cbSize);
1281 /* Each returned usage is in the CRYPT_ENHKEY_USAGE_OID_GROUP_ID group */
1282 ok((*ptr)->dwGroupId == CRYPT_ENHKEY_USAGE_OID_GROUP_ID,
1283 "expected group CRYPT_ENHKEY_USAGE_OID_GROUP_ID, got %d\n",
1284 (*ptr)->dwGroupId);
1285 }
1286 }
1287 /* A value of 2 for the second parameter seems to imply the value is freed
1288 */
1289 SetLastError(0xdeadbeef);
1290 ret = pWTHelperGetKnownUsages(2, &usages);
1291 ok(ret, "WTHelperGetKnownUsages failed: %d\n", GetLastError());
1292 ok(usages == NULL, "expected pointer to be cleared\n");
1293 SetLastError(0xdeadbeef);
1294 usages = NULL;
1295 ret = pWTHelperGetKnownUsages(2, &usages);
1296 ok(ret, "WTHelperGetKnownUsages failed: %d\n", GetLastError());
1297 SetLastError(0xdeadbeef);
1298 ret = pWTHelperGetKnownUsages(2, NULL);
1300 "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
1301}
#define skip(...)
Definition: atltest.h:64
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define SetLastError(x)
Definition: compat.h:752
unsigned int BOOL
Definition: ntddk_ex.h:94
static PVOID ptr
Definition: dispmode.c:27
static PCCRYPT_OID_INFO ** usages
Definition: softpub.c:81
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define CRYPT_ENHKEY_USAGE_OID_GROUP_ID
Definition: wincrypt.h:1690
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185

Referenced by START_TEST().

◆ test_provider_funcs()

static void test_provider_funcs ( void  )
static

Definition at line 627 of file softpub.c.

628{
629 static GUID generic_verify_v2 = WINTRUST_ACTION_GENERIC_VERIFY_V2;
631 BOOL ret;
632
633 ret = WintrustLoadFunctionPointers(&generic_verify_v2,
635 if (!ret)
636 skip("WintrustLoadFunctionPointers failed\n");
637 else
638 {
640 testInitialize(&funcs, &generic_verify_v2);
641 testObjTrust(&funcs, &generic_verify_v2);
642 testCertTrust(&funcs, &generic_verify_v2);
643 }
644}
BOOL WINAPI WintrustLoadFunctionPointers(GUID *pgActionID, CRYPT_PROVIDER_FUNCTIONS *pPfns)
Definition: register.c:841
static void testInitialize(void)
Definition: main.c:66
static void testObjTrust(SAFE_PROVIDER_FUNCTIONS *funcs, GUID *actionID)
Definition: softpub.c:302
struct _SAFE_PROVIDER_FUNCTIONS SAFE_PROVIDER_FUNCTIONS
static void test_utils(SAFE_PROVIDER_FUNCTIONS *funcs)
Definition: softpub.c:125
static void testCertTrust(SAFE_PROVIDER_FUNCTIONS *funcs, GUID *actionID)
Definition: softpub.c:546
static struct __wine_debug_functions funcs
Definition: debug.c:59

Referenced by START_TEST().

◆ test_sip_create_indirect_data()

static void test_sip_create_indirect_data ( void  )
static

Definition at line 738 of file softpub.c.

739{
740 static GUID unknown = { 0xC689AAB8, 0x8E78, 0x11D0, { 0x8C,0x47,
741 0x00,0xC0,0x4F,0xC2,0x95,0xEE } };
742 static char oid_sha1[] = szOID_OIWSEC_sha1;
743 BOOL ret;
744 SIP_SUBJECTINFO subjinfo = { 0 };
746 HANDLE file;
747 DWORD count;
748
749 if (!CryptSIPCreateIndirectData_p)
750 {
751 skip("Missing CryptSIPCreateIndirectData\n");
752 return;
753 }
754 SetLastError(0xdeadbeef);
755 ret = CryptSIPCreateIndirectData_p(NULL, NULL, NULL);
757 "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
758 SetLastError(0xdeadbeef);
759 ret = CryptSIPCreateIndirectData_p(&subjinfo, NULL, NULL);
761 "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
762 subjinfo.cbSize = sizeof(subjinfo);
763 SetLastError(0xdeadbeef);
764 ret = CryptSIPCreateIndirectData_p(&subjinfo, NULL, NULL);
766 "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
769 {
770 skip("couldn't create temp file\n");
771 return;
772 }
773 WriteFile(file, &bin, sizeof(bin), &count, NULL);
775
776 subjinfo.hFile = file;
777 SetLastError(0xdeadbeef);
778 ret = CryptSIPCreateIndirectData_p(&subjinfo, NULL, NULL);
780 "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
781 subjinfo.pgSubjectType = &unknown;
782 SetLastError(0xdeadbeef);
783 ret = CryptSIPCreateIndirectData_p(&subjinfo, NULL, NULL);
785 "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
786 subjinfo.DigestAlgorithm.pszObjId = oid_sha1;
787 count = 0xdeadbeef;
788 ret = CryptSIPCreateIndirectData_p(&subjinfo, &count, NULL);
790 ok(ret, "CryptSIPCreateIndirectData failed: %d\n", GetLastError());
791 ok(count, "expected a positive count\n");
792 if (ret)
793 {
795
796 count = 256;
797 ret = CryptSIPCreateIndirectData_p(&subjinfo, &count, indirect);
798 ok(ret, "CryptSIPCreateIndirectData failed: %d\n", GetLastError());
799 /* If the count is larger than needed, it's unmodified */
800 ok(count == 256, "unexpected count %d\n", count);
801 ok(!strcmp(indirect->Data.pszObjId, SPC_PE_IMAGE_DATA_OBJID),
802 "unexpected data oid %s\n",
803 indirect->Data.pszObjId);
804 ok(!strcmp(indirect->DigestAlgorithm.pszObjId, oid_sha1),
805 "unexpected digest algorithm oid %s\n",
806 indirect->DigestAlgorithm.pszObjId);
807 ok(indirect->Digest.cbData == 20, "unexpected hash size %d\n",
808 indirect->Digest.cbData);
809 if (indirect->Digest.cbData == 20)
810 {
811 const BYTE hash[20] = {
812 0x8a,0xd5,0x45,0x53,0x3d,0x67,0xdf,0x2f,0x78,0xe0,
813 0x55,0x0a,0xe0,0xd9,0x7a,0x28,0x3e,0xbf,0x45,0x2b };
814
815 ok(!memcmp(indirect->Digest.pbData, hash, 20),
816 "unexpected value\n");
817 }
818
820 }
823}
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
static WCHAR unknown[MAX_STRING_RESOURCE_LEN]
Definition: object.c:1605
#define CloseHandle
Definition: compat.h:739
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
BOOL WINAPI FlushFileBuffers(IN HANDLE hFile)
Definition: fileinfo.c:25
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint GLuint GLsizei count
Definition: gl.h:1545
#define todo_wine
Definition: custom.c:79
static HANDLE create_temp_file(WCHAR *temp_file)
Definition: softpub.c:286
static struct _PeImage bin
CRYPT_ALGORITHM_IDENTIFIER DigestAlgorithm
Definition: mssip.h:61
HANDLE hFile
Definition: mssip.h:53
GUID * pgSubjectType
Definition: mssip.h:52
DWORD cbSize
Definition: mssip.h:51
Definition: _hash_fun.h:40
#define szOID_OIWSEC_sha1
Definition: wincrypt.h:3100
#define SPC_PE_IMAGE_DATA_OBJID
Definition: wintrust.h:486
unsigned char BYTE
Definition: xxhash.c:193

Referenced by START_TEST().

◆ test_utils()

static void test_utils ( SAFE_PROVIDER_FUNCTIONS funcs)
static

Definition at line 125 of file softpub.c.

126{
128 HCERTSTORE store;
129 CRYPT_PROVIDER_SGNR sgnr = { 0 };
130 BOOL ret;
131
132 /* Crash
133 ret = funcs->pfnAddStore2Chain(NULL, NULL);
134 ret = funcs->pfnAddStore2Chain(&data, NULL);
135 */
138 if (store)
139 {
140 ret = funcs->pfnAddStore2Chain(&data, store);
141 ok(ret, "pfnAddStore2Chain failed: %08x\n", GetLastError());
142 ok(data.chStores == 1, "Expected 1 store, got %d\n", data.chStores);
143 ok(data.pahStores != NULL, "Expected pahStores to be allocated\n");
144 if (data.pahStores)
145 {
146 ok(data.pahStores[0] == store, "Unexpected store\n");
147 CertCloseStore(data.pahStores[0], 0);
148 funcs->pfnFree(data.pahStores);
149 data.pahStores = NULL;
150 data.chStores = 0;
151 CertCloseStore(store, 0);
152 store = NULL;
153 }
154 }
155 else
156 skip("CertOpenStore failed: %08x\n", GetLastError());
157
158 /* Crash
159 ret = funcs->pfnAddSgnr2Chain(NULL, FALSE, 0, NULL);
160 ret = funcs->pfnAddSgnr2Chain(&data, FALSE, 0, NULL);
161 */
162 ret = funcs->pfnAddSgnr2Chain(&data, FALSE, 0, &sgnr);
163 ok(ret, "pfnAddSgnr2Chain failed: %08x\n", GetLastError());
164 ok(data.csSigners == 1, "Expected 1 signer, got %d\n", data.csSigners);
165 ok(data.pasSigners != NULL, "Expected pasSigners to be allocated\n");
166 if (data.pasSigners)
167 {
169
170 ok(!memcmp(&data.pasSigners[0], &sgnr, sizeof(sgnr)),
171 "Unexpected data in signer\n");
172 /* Adds into the location specified by the index */
173 sgnr.cbStruct = sizeof(CRYPT_PROVIDER_SGNR);
174 sgnr.sftVerifyAsOf.dwLowDateTime = 0xdeadbeef;
175 ret = funcs->pfnAddSgnr2Chain(&data, FALSE, 1, &sgnr);
176 ok(ret, "pfnAddSgnr2Chain failed: %08x\n", GetLastError());
177 ok(data.csSigners == 2, "Expected 2 signers, got %d\n", data.csSigners);
178 ok(!memcmp(&data.pasSigners[1], &sgnr, sizeof(sgnr)),
179 "Unexpected data in signer\n");
180 /* This also adds, but the index is ignored */
181 sgnr.cbStruct = sizeof(DWORD);
182 ret = funcs->pfnAddSgnr2Chain(&data, FALSE, 0, &sgnr);
183 ok(ret, "pfnAddSgnr2Chain failed: %08x\n", GetLastError());
184 ok(data.csSigners == 3, "Expected 3 signers, got %d\n", data.csSigners);
187 ok(!memcmp(&data.pasSigners[2], &sgnr, sizeof(sgnr)),
188 "Unexpected data in signer\n");
189 /* But too large a thing isn't added */
190 sgnr.cbStruct = sizeof(sgnr) + sizeof(DWORD);
191 SetLastError(0xdeadbeef);
192 ret = funcs->pfnAddSgnr2Chain(&data, FALSE, 0, &sgnr);
194 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
195
196 /* Crash
197 ret = funcs->pfnAddCert2Chain(NULL, 0, FALSE, 0, NULL);
198 ret = funcs->pfnAddCert2Chain(&data, 0, FALSE, 0, NULL);
199 */
201 sizeof(v1CertWithPubKey));
202 if (cert)
203 {
204 /* Notes on behavior that are hard to test:
205 * 1. If pasSigners is invalid, pfnAddCert2Chain crashes
206 * 2. An invalid signer index isn't checked.
207 */
208 ret = funcs->pfnAddCert2Chain(&data, 0, FALSE, 0, cert);
209 ok(ret, "pfnAddCert2Chain failed: %08x\n", GetLastError());
210 ok(data.pasSigners[0].csCertChain == 1, "Expected 1 cert, got %d\n",
211 data.pasSigners[0].csCertChain);
212 ok(data.pasSigners[0].pasCertChain != NULL,
213 "Expected pasCertChain to be allocated\n");
214 if (data.pasSigners[0].pasCertChain)
215 {
216 ok(data.pasSigners[0].pasCertChain[0].pCert == cert,
217 "Unexpected cert\n");
219 data.pasSigners[0].pasCertChain[0].pCert);
220 }
222 }
223 else
224 skip("CertCreateCertificateContext failed: %08x\n", GetLastError());
225 funcs->pfnFree(data.pasSigners);
226 }
227}
#define FALSE
Definition: types.h:117
BOOL WINAPI CertFreeCertificateContext(PCCERT_CONTEXT pCertContext)
Definition: cert.c:371
PCCERT_CONTEXT WINAPI CertCreateCertificateContext(DWORD dwCertEncodingType, const BYTE *pbCertEncoded, DWORD cbCertEncoded)
Definition: cert.c:316
HCERTSTORE WINAPI CertOpenStore(LPCSTR lpszStoreProvider, DWORD dwMsgAndCertEncodingType, HCRYPTPROV_LEGACY hCryptProv, DWORD dwFlags, const void *pvPara)
Definition: store.c:815
BOOL WINAPI CertCloseStore(HCERTSTORE hCertStore, DWORD dwFlags)
Definition: store.c:1127
static BYTE cert[]
Definition: msg.c:1437
static const BYTE v1CertWithPubKey[]
Definition: softpub.c:112
#define DWORD
Definition: nt_native.h:44
FILETIME sftVerifyAsOf
Definition: wintrust.h:233
DWORD dwLowDateTime
Definition: mapidefs.h:65
#define CERT_STORE_CREATE_NEW_FLAG
Definition: wincrypt.h:2464
#define X509_ASN_ENCODING
Definition: wincrypt.h:2297
#define CERT_STORE_PROV_MEMORY
Definition: wincrypt.h:2251
struct _CRYPT_PROVIDER_SGNR CRYPT_PROVIDER_SGNR

Referenced by test_provider_funcs().

◆ test_wintrust()

static void test_wintrust ( void  )
static

Definition at line 825 of file softpub.c.

826{
827 static GUID generic_action_v2 = WINTRUST_ACTION_GENERIC_VERIFY_V2;
828 WINTRUST_DATA wtd;
830 LONG r;
831 HRESULT hr;
832 WCHAR pathW[MAX_PATH];
833
834 memset(&wtd, 0, sizeof(wtd));
835 wtd.cbStruct = sizeof(wtd);
839 U(wtd).pFile = &file;
841 memset(&file, 0, sizeof(file));
842 file.cbStruct = sizeof(file);
843 file.pcwszFilePath = pathW;
844 /* Test with an empty file */
845 file.hFile = create_temp_file(pathW);
846 r = WinVerifyTrust(INVALID_HANDLE_VALUE, &generic_action_v2, &wtd);
848 "expected TRUST_E_SUBJECT_FORM_UNKNOWN, got %08x\n", r);
849 CloseHandle(file.hFile);
850 DeleteFileW(pathW);
851 file.hFile = NULL;
852 /* Test with a known file path, which we expect not have a signature */
853 getNotepadPath(pathW, MAX_PATH);
854 r = WinVerifyTrust(INVALID_HANDLE_VALUE, &generic_action_v2, &wtd);
856 "expected TRUST_E_NOSIGNATURE or CRYPT_E_FILE_ERROR, got %08x\n", r);
858 r = WinVerifyTrust(INVALID_HANDLE_VALUE, &generic_action_v2, &wtd);
859 ok(r == S_OK, "WinVerifyTrust failed: %08x\n", r);
861 hr = WinVerifyTrustEx(INVALID_HANDLE_VALUE, &generic_action_v2, &wtd);
863 "expected TRUST_E_NOSIGNATURE or CRYPT_E_FILE_ERROR, got %08x\n", hr);
865 r = WinVerifyTrust(INVALID_HANDLE_VALUE, &generic_action_v2, &wtd);
866 ok(r == S_OK, "WinVerifyTrust failed: %08x\n", r);
867}
#define U(x)
Definition: wordpad.c:45
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
static void getNotepadPath(WCHAR *notepadPathW, DWORD size)
Definition: softpub.c:272
#define memset(x, y, z)
Definition: compat.h:39
HRESULT hr
Definition: shlfolder.c:183
DWORD dwUnionChoice
Definition: wintrust.h:104
DWORD dwStateAction
Definition: wintrust.h:114
DWORD fdwRevocationChecks
Definition: wintrust.h:103
DWORD cbStruct
Definition: wintrust.h:99
DWORD dwUIChoice
Definition: wintrust.h:102
#define CRYPT_E_FILE_ERROR
Definition: winerror.h:3006
#define TRUST_E_SUBJECT_FORM_UNKNOWN
Definition: winerror.h:3114
#define TRUST_E_NOSIGNATURE
Definition: winerror.h:3116
#define WTD_REVOKE_WHOLECHAIN
Definition: wintrust.h:89
HRESULT WINAPI WinVerifyTrustEx(HWND hwnd, GUID *ActionID, WINTRUST_DATA *ActionData)

Referenced by START_TEST().

◆ test_wintrust_digest()

static void test_wintrust_digest ( void  )
static

Definition at line 1136 of file softpub.c.

1137{
1138 static const BYTE Dummy[] = { 0x11,0x22,0x33,0x44 };
1139 static const struct
1140 {
1141 struct { const BYTE *data; DWORD length; } blocks[5];
1142 struct { LONG status; BOOL todo; } t1;
1143 struct { LONG status; BOOL todo; } t2;
1144 }
1145 tests[] =
1146 {
1147 /* 32-bit tests */
1148 {
1149 {{ SelfSignedFile32, sizeof(SelfSignedFile32) }},
1150 { CERT_E_CHAINING, TRUE }, { S_OK, FALSE }
1151 },
1152 {
1153 {{ SelfSignedFile32, sizeof(SelfSignedFile32) },
1154 { Dummy, sizeof(Dummy) }},
1156 },
1157 {
1158 {{ Dummy, sizeof(Dummy) },
1159 { SelfSignedFile32 + sizeof(Dummy), sizeof(SelfSignedFile32) - sizeof(Dummy) }},
1161 },
1162 {
1163 {{ SelfSignedFile32, 19 },
1164 { Dummy, sizeof(Dummy) },
1165 { SelfSignedFile32 + 19 + sizeof(Dummy), sizeof(SelfSignedFile32) - 19 - sizeof(Dummy) }},
1167 },
1168 {
1169 {{ SelfSignedFile32, sizeof(IMAGE_DOS_HEADER) }},
1171 },
1172 {
1173 {{ SelfSignedFile32, sizeof(IMAGE_DOS_HEADER) + sizeof(IMAGE_NT_HEADERS32) * 2 }},
1175 },
1176
1177 /* 64-bit tests */
1178 {
1179 {{ SelfSignedFile64, sizeof(SelfSignedFile64) }},
1180 { CERT_E_CHAINING, TRUE }, { S_OK, FALSE }
1181 },
1182 {
1183 {{ SelfSignedFile64, sizeof(SelfSignedFile64) },
1184 { Dummy, sizeof(Dummy) }},
1186 },
1187 {
1188 {{ Dummy, sizeof(Dummy) },
1189 { SelfSignedFile64 + sizeof(Dummy), sizeof(SelfSignedFile64) - sizeof(Dummy) }},
1191 },
1192 {
1193 {{ SelfSignedFile64, 19 },
1194 { Dummy, sizeof(Dummy) },
1195 { SelfSignedFile64 + 19 + sizeof(Dummy), sizeof(SelfSignedFile64) - 19 - sizeof(Dummy) }},
1197 },
1198 {
1199 {{ SelfSignedFile64, sizeof(IMAGE_DOS_HEADER) }},
1201 },
1202 {
1203 {{ SelfSignedFile64, sizeof(IMAGE_DOS_HEADER) + sizeof(IMAGE_NT_HEADERS64) * 2 }},
1205 },
1206 };
1207 WCHAR pathW[MAX_PATH];
1208 DWORD written;
1209 HANDLE file;
1210 LONG status;
1211 BOOL ret;
1212 int i, j;
1213
1214 for (i = 0; i < ARRAY_SIZE(tests); i++)
1215 {
1216 file = create_temp_file(pathW);
1217 ok(file != INVALID_HANDLE_VALUE, "failed to create temporary file\n");
1218
1219 for (j = 0; tests[i].blocks[j].data; j++)
1220 {
1221 ret = WriteFile(file, tests[i].blocks[j].data, tests[i].blocks[j].length, &written, NULL);
1222 ok(ret && written == tests[i].blocks[j].length, "WriteFile failed with %u\n", GetLastError());
1223 }
1224
1226
1227 call_winverify(pathW, &status, FALSE);
1228 todo_wine_if(tests[i].t1.todo)
1229 ok(status == tests[i].t1.status, "test %d/1: expected %08x, got %08x\n", i, tests[i].t1.status, status);
1230
1231 call_winverify(pathW, &status, TRUE);
1232 todo_wine_if(tests[i].t2.todo)
1233 ok(status == tests[i].t2.status, "test %d/2: expected %08x, got %08x\n", i, tests[i].t2.status, status);
1234
1235 DeleteFileW(pathW);
1236 }
1237}
#define TRUE
Definition: types.h:120
struct _IMAGE_DOS_HEADER IMAGE_DOS_HEADER
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
static int blocks
Definition: mkdosfs.c:527
static struct test_info tests[]
BOOL todo
Definition: filedlg.c:313
#define todo_wine_if(is_todo)
Definition: custom.c:76
static const BYTE SelfSignedFile64[]
Definition: softpub.c:987
static const BYTE SelfSignedFile32[]
Definition: softpub.c:881
static void call_winverify(WCHAR *pathW, LONG *status, BOOL hash_only)
Definition: softpub.c:1114
#define CERT_E_CHAINING
Definition: winerror.h:3126
#define TRUST_E_BAD_DIGEST
Definition: winerror.h:3109

Referenced by START_TEST().

◆ test_WTHelperGetProvCertFromChain()

static void test_WTHelperGetProvCertFromChain ( void  )
static

Definition at line 1303 of file softpub.c.

1304{
1306
1308 ok(!cert, "got certificate\n");
1309}
CRYPT_PROVIDER_CERT *WINAPI WTHelperGetProvCertFromChain(CRYPT_PROVIDER_SGNR *pSgnr, DWORD idxCert)

Referenced by START_TEST().

◆ testCertTrust()

static void testCertTrust ( SAFE_PROVIDER_FUNCTIONS funcs,
GUID actionID 
)
static

Definition at line 546 of file softpub.c.

547{
549 CRYPT_PROVIDER_SIGSTATE sig_state = { 0 };
550 CRYPT_PROVIDER_SGNR sgnr = { sizeof(sgnr), { 0 } };
551 HRESULT ret;
552 BOOL b;
553
554 if (!CertFreeCertificateChain_p)
555 {
556 win_skip("CertFreeCertificateChain not found\n");
557 return;
558 }
559
560 data.pSigState = &sig_state;
561 data.padwTrustStepErrors =
562 funcs->pfnAlloc(TRUSTERROR_MAX_STEPS * sizeof(DWORD));
563 if (!data.padwTrustStepErrors)
564 {
565 skip("pfnAlloc failed\n");
566 return;
567 }
568 ret = funcs->pfnCertificateTrust(&data);
569 ok(ret == S_FALSE, "Expected S_FALSE, got %08x\n", ret);
570 ok(data.padwTrustStepErrors[TRUSTERROR_STEP_FINAL_CERTPROV] ==
571 TRUST_E_NOSIGNATURE, "Expected TRUST_E_NOSIGNATURE, got %08x\n",
572 data.padwTrustStepErrors[TRUSTERROR_STEP_FINAL_CERTPROV]);
573 b = funcs->pfnAddSgnr2Chain(&data, FALSE, 0, &sgnr);
574 if (b)
575 {
577
578 /* An empty signer "succeeds," even though there's no cert */
579 ret = funcs->pfnCertificateTrust(&data);
580 ok(ret == S_OK, "Expected S_OK, got %08x\n", ret);
582 sizeof(selfSignedCert));
583 if (cert)
584 {
585 WINTRUST_DATA wintrust_data = { 0 };
586
587 b = funcs->pfnAddCert2Chain(&data, 0, FALSE, 0, cert);
588 ok(b == TRUE, "Expected TRUE, got %d\n", b);
589
590 /* If pWintrustData isn't set, crashes attempting to access
591 * pWintrustData->fdwRevocationChecks
592 */
593 data.pWintrustData = &wintrust_data;
594 /* If psPfns isn't set, crashes attempting to access
595 * psPfns->pfnCertCheckPolicy
596 */
598 ret = funcs->pfnCertificateTrust(&data);
599 ok(ret == S_OK, "Expected S_OK, got %08x\n", ret);
600 ok(data.csSigners == 1, "Unexpected number of signers %d\n",
601 data.csSigners);
602 ok(data.pasSigners[0].pChainContext != NULL,
603 "Expected a certificate chain\n");
604 ok(data.pasSigners[0].csCertChain == 1,
605 "Unexpected number of chain elements %d\n",
606 data.pasSigners[0].csCertChain);
607 /* pasSigners and pasSigners[0].pasCertChain are guaranteed to be
608 * initialized, see tests for pfnAddSgnr2Chain and pfnAddCert2Chain
609 */
610 ok(!data.pasSigners[0].pasCertChain[0].fTrustedRoot,
611 "Didn't expect cert to be trusted\n");
612 ok(data.pasSigners[0].pasCertChain[0].fSelfSigned,
613 "Expected cert to be self-signed\n");
614 ok(data.pasSigners[0].pasCertChain[0].dwConfidence ==
616 "Expected CERT_CONFIDENCE_SIG | CERT_CONFIDENCE_TIMENEST, got %08x\n",
617 data.pasSigners[0].pasCertChain[0].dwConfidence);
619 data.pasSigners[0].pasCertChain[0].pCert);
620 CertFreeCertificateChain_p(data.pasSigners[0].pChainContext);
622 }
623 }
624 funcs->pfnFree(data.padwTrustStepErrors);
625}
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
#define b
Definition: ke_i.h:79
static const BYTE selfSignedCert[]
Definition: softpub.c:432
#define win_skip
Definition: test.h:163
#define S_FALSE
Definition: winerror.h:2357
#define TRUSTERROR_MAX_STEPS
Definition: wintrust.h:282
#define TRUSTERROR_STEP_FINAL_CERTPROV
Definition: wintrust.h:277
#define CERT_CONFIDENCE_TIMENEST
Definition: wintrust.h:226
#define CERT_CONFIDENCE_SIG
Definition: wintrust.h:224

Referenced by test_provider_funcs().

◆ testInitialize()

static void testInitialize ( SAFE_PROVIDER_FUNCTIONS funcs,
GUID actionID 
)
static

Definition at line 229 of file softpub.c.

230{
231 HRESULT ret;
233 WINTRUST_DATA wintrust_data = { 0 };
234
235 if (!funcs->pfnInitialize)
236 {
237 skip("missing pfnInitialize\n");
238 return;
239 }
240
241 /* Crashes
242 ret = funcs->pfnInitialize(NULL);
243 */
244 memset(&data, 0, sizeof(data));
245 ret = funcs->pfnInitialize(&data);
246 ok(ret == S_FALSE, "Expected S_FALSE, got %08x\n", ret);
247 data.padwTrustStepErrors =
248 funcs->pfnAlloc(TRUSTERROR_MAX_STEPS * sizeof(DWORD));
249 /* Without wintrust data set, crashes when padwTrustStepErrors is set */
250 data.pWintrustData = &wintrust_data;
251 if (data.padwTrustStepErrors)
252 {
253 /* Apparently, cdwTrustStepErrors does not need to be set. */
254 memset(data.padwTrustStepErrors, 0,
255 TRUSTERROR_MAX_STEPS * sizeof(DWORD));
256 ret = funcs->pfnInitialize(&data);
257 ok(ret == S_OK, "Expected S_OK, got %08x\n", ret);
258 data.cdwTrustStepErrors = 1;
259 ret = funcs->pfnInitialize(&data);
260 ok(ret == S_OK, "Expected S_OK, got %08x\n", ret);
261 memset(data.padwTrustStepErrors, 0xba,
262 TRUSTERROR_MAX_STEPS * sizeof(DWORD));
263 ret = funcs->pfnInitialize(&data);
264 ok(ret == S_FALSE, "Expected S_FALSE, got %08x\n", ret);
265 data.padwTrustStepErrors[TRUSTERROR_STEP_FINAL_WVTINIT] = 0;
266 ret = funcs->pfnInitialize(&data);
267 ok(ret == S_OK, "Expected S_OK, got %08x\n", ret);
268 funcs->pfnFree(data.padwTrustStepErrors);
269 }
270}
#define TRUSTERROR_STEP_FINAL_WVTINIT
Definition: wintrust.h:273

◆ testObjTrust()

static void testObjTrust ( SAFE_PROVIDER_FUNCTIONS funcs,
GUID actionID 
)
static

Definition at line 302 of file softpub.c.

303{
304 HRESULT ret;
306 CRYPT_PROVIDER_SIGSTATE sig_state = { 0 };
307 WINTRUST_DATA wintrust_data = { 0 };
308 WINTRUST_CERT_INFO certInfo = { sizeof(WINTRUST_CERT_INFO), 0 };
309 WINTRUST_FILE_INFO fileInfo = { sizeof(WINTRUST_FILE_INFO), 0 };
310
311 if (!funcs->pfnObjectTrust)
312 {
313 skip("missing pfnObjectTrust\n");
314 return;
315 }
316
317 /* Crashes
318 ret = funcs->pfnObjectTrust(NULL);
319 */
320 data.pSigState = &sig_state;
321 data.pWintrustData = &wintrust_data;
322 data.padwTrustStepErrors =
323 funcs->pfnAlloc(TRUSTERROR_MAX_STEPS * sizeof(DWORD));
324 if (data.padwTrustStepErrors)
325 {
326 WCHAR pathW[MAX_PATH];
327 PROVDATA_SIP provDataSIP = { 0 };
328 static const GUID unknown = { 0xC689AAB8, 0x8E78, 0x11D0, { 0x8C,0x47,
329 0x00,0xC0,0x4F,0xC2,0x95,0xEE } };
330 static GUID bogusGuid = { 0xdeadbeef, 0xbaad, 0xf00d, { 0x00,0x00,0x00,
331 0x00,0x00,0x00,0x00,0x00 } };
332
333 ret = funcs->pfnObjectTrust(&data);
334 ok(ret == S_FALSE, "Expected S_FALSE, got %08x\n", ret);
335 ok(data.padwTrustStepErrors[TRUSTERROR_STEP_FINAL_OBJPROV] ==
337 "Expected ERROR_INVALID_PARAMETER, got %08x\n",
338 data.padwTrustStepErrors[TRUSTERROR_STEP_FINAL_OBJPROV]);
339 U(wintrust_data).pCert = &certInfo;
340 wintrust_data.dwUnionChoice = WTD_CHOICE_CERT;
341 ret = funcs->pfnObjectTrust(&data);
342 ok(ret == S_OK, "Expected S_OK, got %08x\n", ret);
345 ret = funcs->pfnObjectTrust(&data);
346 ok(ret == S_OK, "Expected S_OK, got %08x\n", ret);
348 certInfo.psCertContext = NULL;
349 wintrust_data.dwUnionChoice = WTD_CHOICE_FILE;
350 U(wintrust_data).pFile = NULL;
351 ret = funcs->pfnObjectTrust(&data);
352 ok(ret == S_FALSE, "Expected S_FALSE, got %08x\n", ret);
353 ok(data.padwTrustStepErrors[TRUSTERROR_STEP_FINAL_OBJPROV] ==
355 "Expected ERROR_INVALID_PARAMETER, got %08x\n",
356 data.padwTrustStepErrors[TRUSTERROR_STEP_FINAL_OBJPROV]);
357 U(wintrust_data).pFile = &fileInfo;
358 /* Crashes
359 ret = funcs->pfnObjectTrust(&data);
360 */
361 /* Create and test with an empty file */
362 fileInfo.hFile = create_temp_file(pathW);
363 /* pfnObjectTrust now crashes unless both pPDSip and psPfns are set */
364 U(data).pPDSip = &provDataSIP;
366 ret = funcs->pfnObjectTrust(&data);
367 ok(ret == S_FALSE, "Expected S_FALSE, got %08x\n", ret);
368 ok(data.padwTrustStepErrors[TRUSTERROR_STEP_FINAL_OBJPROV] ==
370 "expected TRUST_E_SUBJECT_FORM_UNKNOWN, got %08x\n",
371 data.padwTrustStepErrors[TRUSTERROR_STEP_FINAL_OBJPROV]);
372 CloseHandle(fileInfo.hFile);
373 fileInfo.hFile = NULL;
374 fileInfo.pcwszFilePath = pathW;
375 ret = funcs->pfnObjectTrust(&data);
376 ok(ret == S_FALSE, "Expected S_FALSE, got %08x\n", ret);
377 ok(data.padwTrustStepErrors[TRUSTERROR_STEP_FINAL_OBJPROV] ==
379 "expected TRUST_E_SUBJECT_FORM_UNKNOWN, got %08x\n",
380 data.padwTrustStepErrors[TRUSTERROR_STEP_FINAL_OBJPROV]);
381 DeleteFileW(pathW);
382 /* Test again with a file we expect to exist, and to contain no
383 * signature.
384 */
385 getNotepadPath(pathW, MAX_PATH);
386 ret = funcs->pfnObjectTrust(&data);
387 ok(ret == S_FALSE, "Expected S_FALSE, got %08x\n", ret);
388 ok(data.padwTrustStepErrors[TRUSTERROR_STEP_FINAL_OBJPROV] ==
390 data.padwTrustStepErrors[TRUSTERROR_STEP_FINAL_OBJPROV] ==
392 "Expected TRUST_E_NOSIGNATURE or TRUST_E_SUBJECT_FORM_UNKNOWN, got %08x\n",
393 data.padwTrustStepErrors[TRUSTERROR_STEP_FINAL_OBJPROV]);
394 if (data.padwTrustStepErrors[TRUSTERROR_STEP_FINAL_OBJPROV] ==
396 {
397 ok(!memcmp(&provDataSIP.gSubject, &unknown, sizeof(unknown)),
398 "Unexpected subject GUID\n");
399 ok(provDataSIP.pSip != NULL, "Expected a SIP\n");
400 ok(provDataSIP.psSipSubjectInfo != NULL,
401 "Expected a subject info\n");
402 }
403 /* Specifying the GUID results in that GUID being the subject GUID */
404 fileInfo.pgKnownSubject = &bogusGuid;
405 ret = funcs->pfnObjectTrust(&data);
406 ok(ret == S_FALSE, "Expected S_FALSE, got %08x\n", ret);
407 ok(data.padwTrustStepErrors[TRUSTERROR_STEP_FINAL_OBJPROV] ==
409 data.padwTrustStepErrors[TRUSTERROR_STEP_FINAL_OBJPROV] ==
411 data.padwTrustStepErrors[TRUSTERROR_STEP_FINAL_OBJPROV] ==
413 "Expected TRUST_E_NOSIGNATURE or TRUST_E_SUBJECT_FORM_UNKNOWN or TRUST_E_PROVIDER_UNKNOWN, got %08x\n",
414 data.padwTrustStepErrors[TRUSTERROR_STEP_FINAL_OBJPROV]);
415 if (data.padwTrustStepErrors[TRUSTERROR_STEP_FINAL_OBJPROV] ==
417 {
418 ok(!memcmp(&provDataSIP.gSubject, &bogusGuid, sizeof(bogusGuid)),
419 "unexpected subject GUID\n");
420 }
421 /* Specifying a bogus GUID pointer crashes */
422 if (0)
423 {
424 fileInfo.pgKnownSubject = (GUID *)0xdeadbeef;
425 ret = funcs->pfnObjectTrust(&data);
426 ok(ret == S_FALSE, "Expected S_FALSE, got %08x\n", ret);
427 }
428 funcs->pfnFree(data.padwTrustStepErrors);
429 }
430}
CERT_CONTEXT * psCertContext
Definition: wintrust.h:72
GUID * pgKnownSubject
Definition: wintrust.h:32
LPCWSTR pcwszFilePath
Definition: wintrust.h:30
struct SIP_SUBJECTINFO_ * psSipSubjectInfo
Definition: wintrust.h:341
GUID gSubject
Definition: wintrust.h:338
struct SIP_DISPATCH_INFO_ * pSip
Definition: wintrust.h:339
struct _CERT_CONTEXT * PCERT_CONTEXT
#define TRUST_E_PROVIDER_UNKNOWN
Definition: winerror.h:3112
struct WINTRUST_CERT_INFO_ WINTRUST_CERT_INFO
#define TRUSTERROR_STEP_FINAL_OBJPROV
Definition: wintrust.h:275
struct WINTRUST_FILE_INFO_ WINTRUST_FILE_INFO
#define WTD_CHOICE_CERT
Definition: wintrust.h:95

Referenced by test_provider_funcs().

◆ VOID()

static DWORD SIP_INDIRECT_DATA *static VOID ( WINAPI CertFreeCertificateChain_p)
static

Variable Documentation

◆ bin

◆ selfSignedCert

const BYTE selfSignedCert[]
static

Definition at line 432 of file softpub.c.

Referenced by testCertTrust().

◆ SelfSignedFile32

const BYTE SelfSignedFile32[]
static

Definition at line 881 of file softpub.c.

Referenced by test_wintrust_digest().

◆ SelfSignedFile64

const BYTE SelfSignedFile64[]
static

Definition at line 987 of file softpub.c.

Referenced by test_wintrust_digest().

◆ usages

◆ v1CertWithPubKey

const BYTE v1CertWithPubKey[]
static
Initial value:
= {
0x30,0x81,0x95,0x02,0x01,0x01,0x30,0x02,0x06,0x00,0x30,0x15,0x31,0x13,0x30,
0x11,0x06,0x03,0x55,0x04,0x03,0x13,0x0a,0x4a,0x75,0x61,0x6e,0x20,0x4c,0x61,
0x6e,0x67,0x00,0x30,0x22,0x18,0x0f,0x31,0x36,0x30,0x31,0x30,0x31,0x30,0x31,
0x30,0x30,0x30,0x30,0x30,0x30,0x5a,0x18,0x0f,0x31,0x36,0x30,0x31,0x30,0x31,
0x30,0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x5a,0x30,0x15,0x31,0x13,0x30,0x11,
0x06,0x03,0x55,0x04,0x03,0x13,0x0a,0x4a,0x75,0x61,0x6e,0x20,0x4c,0x61,0x6e,
0x67,0x00,0x30,0x22,0x30,0x0d,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,
0x01,0x01,0x05,0x00,0x03,0x11,0x00,0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0xa3,0x16,0x30,0x14,0x30,0x12,0x06,
0x03,0x55,0x1d,0x13,0x01,0x01,0xff,0x04,0x08,0x30,0x06,0x01,0x01,0xff,0x02,
0x01,0x01 }

Definition at line 112 of file softpub.c.

Referenced by test_utils(), and testObjTrust().