ReactOS 0.4.15-dev-8096-ga0eec98
cert.c File Reference
#include <stdio.h>
#include <stdarg.h>
#include <windef.h>
#include <winbase.h>
#include <winreg.h>
#include <winerror.h>
#include <wincrypt.h>
#include "wine/test.h"
Include dependency graph for cert.c:

Go to the source code of this file.

Classes

struct  IntBlobTest
 

Macros

#define GET_PROC(dll, func)
 

Functions

static PCCERT_CONTEXT (WINAPI *pCertCreateSelfSignCertificate)(HCRYPTPROV_OR_NCRYPT_KEY_HANDLE
 
static BOOL (WINAPI *pCertGetValidUsages)(DWORD
 
static void init_function_pointers (void)
 
static void testAddCert (void)
 
static void checkHash (const BYTE *data, DWORD dataLen, ALG_ID algID, PCCERT_CONTEXT context, DWORD propID)
 
static void testCertProperties (void)
 
static void testCreateCert (void)
 
static void testDupCert (void)
 
static void testLinkCert (void)
 
static void testFindCert (void)
 
static void testGetSubjectCert (void)
 
static void testGetIssuerCert (void)
 
static void testCryptHashCert (void)
 
static void verifySig (HCRYPTPROV csp, const BYTE *toSign, size_t toSignLen, const BYTE *sig, unsigned int sigLen)
 
static void testSignCert (HCRYPTPROV csp, const CRYPT_DATA_BLOB *toBeSigned, LPCSTR sigOID, BYTE *sig, DWORD *sigLen)
 
static void testVerifyCertSig (HCRYPTPROV csp, const CRYPT_DATA_BLOB *toBeSigned, LPCSTR sigOID, const BYTE *sig, DWORD sigLen)
 
static void testVerifyCertSigEx (HCRYPTPROV csp, const CRYPT_DATA_BLOB *toBeSigned, LPCSTR sigOID, const BYTE *sig, DWORD sigLen)
 
static void testCertSigs (void)
 
static void testSignAndEncodeCert (void)
 
static void testCreateSelfSignCert (void)
 
static void testIntendedKeyUsage (void)
 
static void testKeyUsage (void)
 
static void testGetValidUsages (void)
 
static void testCompareCertName (void)
 
static void testIsRDNAttrsInCertificateName (void)
 
static void testCompareIntegerBlob (void)
 
static void testComparePublicKeyInfo (void)
 
static void testHashPublicKeyInfo (void)
 
static void testHashToBeSigned (void)
 
static void testCompareCert (void)
 
static void testVerifySubjectCert (void)
 
static void testVerifyRevocation (void)
 
static void testAcquireCertPrivateKey (void)
 
static void testGetPublicKeyLength (void)
 
 START_TEST (cert)
 

Variables

static PCERT_NAME_BLOB
 
static DWORD
 
static PCRYPT_KEY_PROV_INFO
 
static PCRYPT_ALGORITHM_IDENTIFIER
 
static PSYSTEMTIME
 
static PCERT_EXTENSIONS
 
static PCCERT_CONTEXT int LPSTR DWORD *static void HCRYPTPROV_OR_NCRYPT_KEY_HANDLE DWORD BOOL *static LPCSTR
 
static PCCERT_CONTEXT int LPSTR DWORD *static void HCRYPTPROV_OR_NCRYPT_KEY_HANDLE DWORD BOOL *static const void PCRYPT_ENCODE_PARA
 
static BYTE subjectName []
 
static BYTE serialNum [] = { 1 }
 
static const BYTE bigCert []
 
static BYTE bigCertHash []
 
static const BYTE bigCertWithDifferentSubject []
 
static const BYTE bigCertWithDifferentIssuer []
 
static BYTE subjectName2 []
 
static const BYTE bigCert2 []
 
static const BYTE bigCert2WithDifferentSerial []
 
static BYTE bigCert2Hash []
 
static const BYTE certWithUsage []
 
static const CHAR cspNameA [] = "WineCryptTemp"
 
static WCHAR cspNameW [] = { 'W','i','n','e','C','r','y','p','t','T','e','m','p',0 }
 
static const BYTE v1CertWithPubKey []
 
static const BYTE v1CertWithSubjectKeyId []
 
static const BYTE subjectKeyId []
 
static const BYTE selfSignedCert []
 
static const BYTE selfSignedSignatureHash []
 
static BYTE subjectName3 []
 
static const BYTE iTunesCert0 []
 
static const BYTE iTunesCert1 []
 
static const BYTE iTunesCert2 []
 
static const BYTE iTunesCert3 []
 
static BYTE iTunesIssuer []
 
static BYTE iTunesSerialNum []
 
static const BYTE expiredCert []
 
static const BYTE childOfExpired []
 
static const BYTE chain10_0 []
 
static const BYTE chain10_1 []
 
static const BYTE chain7_1 []
 
static BYTE emptyCert [] = { 0x30, 0x00 }
 
static const BYTE md5SignedEmptyCert []
 
static const BYTE md5SignedEmptyCertNoNull []
 
static const LPCSTR keyUsages []
 
static const BYTE cert2WithUsage []
 
static BYTE cn []
 
static BYTE cnWithLeadingSpace []
 
static BYTE cnWithTrailingSpace []
 
static BYTE cnWithIntermediateSpace []
 
static BYTE cnThenO []
 
static BYTE oThenCN []
 
static BYTE int1 [] = { 0x88, 0xff, 0xff, 0xff }
 
static BYTE int2 [] = { 0x88, 0xff }
 
static BYTE int3 [] = { 0x23, 0xff }
 
static BYTE int4 [] = { 0x7f, 0x00 }
 
static BYTE int5 [] = { 0x7f }
 
static BYTE int6 [] = { 0x80, 0x00, 0x00, 0x00 }
 
static BYTE int7 [] = { 0x80, 0x00 }
 
static struct IntBlobTest intBlobs []
 
static const BYTE md5SignedEmptyCertHash []
 
static const BYTE rootWithKeySignAndCRLSign []
 
static const BYTE eeCert []
 
static const BYTE rootSignedCRL []
 
static BYTE privKey []
 
static const BYTE exportedPublicKeyBlob []
 
static const BYTE asnEncodedPublicKey []
 

Macro Definition Documentation

◆ GET_PROC

#define GET_PROC (   dll,
  func 
)
Value:
p ## func = (void *)GetProcAddress(dll, #func); \
if(!p ## func) \
trace("GetProcAddress(%s) failed\n", #func);
#define GetProcAddress(x, y)
Definition: compat.h:753
GLenum func
Definition: glext.h:6028
GLfloat GLfloat p
Definition: glext.h:8902
static HMODULE dll
Definition: str.c:188

Function Documentation

◆ BOOL()

static BOOL ( WINAPI pCertGetValidUsages)
static

◆ checkHash()

static void checkHash ( const BYTE data,
DWORD  dataLen,
ALG_ID  algID,
PCCERT_CONTEXT  context,
DWORD  propID 
)
static

Definition at line 325 of file cert.c.

327{
328 BYTE hash[20] = { 0 }, hashProperty[20];
329 BOOL ret;
330 DWORD size;
331 DWORD dwSizeWithNull;
332
333 memset(hash, 0, sizeof(hash));
334 memset(hashProperty, 0, sizeof(hashProperty));
335 size = sizeof(hash);
336 ret = CryptHashCertificate(0, algID, 0, data, dataLen, hash, &size);
337 ok(ret, "CryptHashCertificate failed: %08x\n", GetLastError());
339 &dwSizeWithNull);
340 ok(ret, "algID %08x, propID %d: CertGetCertificateContextProperty failed: %08x\n",
341 algID, propID, GetLastError());
342 ret = CertGetCertificateContextProperty(context, propID, hashProperty,
343 &size);
344 ok(ret, "CertGetCertificateContextProperty failed: %08x\n",
345 GetLastError());
346 ok(!memcmp(hash, hashProperty, size), "Unexpected hash for property %d\n",
347 propID);
348 ok(size == dwSizeWithNull, "Unexpected length of hash for property: received %d instead of %d\n",
349 dwSizeWithNull,size);
350}
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
#define ok(value,...)
Definition: atltest.h:57
#define NULL
Definition: types.h:112
BOOL WINAPI CertGetCertificateContextProperty(PCCERT_CONTEXT pCertContext, DWORD dwPropId, void *pvData, DWORD *pcbData)
Definition: cert.c:551
BOOL WINAPI CryptHashCertificate(HCRYPTPROV_LEGACY hCryptProv, ALG_ID Algid, DWORD dwFlags, const BYTE *pbEncoded, DWORD cbEncoded, BYTE *pbComputedHash, DWORD *pcbComputedHash)
Definition: cert.c:2187
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLsizeiptr size
Definition: glext.h:5919
#define memset(x, y, z)
Definition: compat.h:39
Definition: http.c:7252
Definition: _hash_fun.h:40
int ret
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
unsigned char BYTE
Definition: xxhash.c:193

Referenced by testCertProperties().

◆ init_function_pointers()

static void init_function_pointers ( void  )
static

Definition at line 42 of file cert.c.

43{
44 HMODULE hCrypt32 = GetModuleHandleA("crypt32.dll");
45 HMODULE hAdvapi32 = GetModuleHandleA("advapi32.dll");
46
47#define GET_PROC(dll, func) \
48 p ## func = (void *)GetProcAddress(dll, #func); \
49 if(!p ## func) \
50 trace("GetProcAddress(%s) failed\n", #func);
51
57
59
60#undef GET_PROC
61}
BOOL WINAPI CryptAcquireContextA(HCRYPTPROV *phProv, LPCSTR pszContainer, LPCSTR pszProvider, DWORD dwProvType, DWORD dwFlags)
Definition: crypt.c:569
BOOL WINAPI CryptAcquireCertificatePrivateKey(PCCERT_CONTEXT pCert, DWORD dwFlags, void *pvReserved, HCRYPTPROV_OR_NCRYPT_KEY_HANDLE *phCryptProv, DWORD *pdwKeySpec, BOOL *pfCallerFreeProv)
Definition: cert.c:881
BOOL WINAPI CryptVerifyCertificateSignatureEx(HCRYPTPROV_LEGACY hCryptProv, DWORD dwCertEncodingType, DWORD dwSubjectType, void *pvSubject, DWORD dwIssuerType, void *pvIssuer, DWORD dwFlags, void *pvReserved)
Definition: cert.c:2717
PCCERT_CONTEXT WINAPI CertCreateSelfSignCertificate(HCRYPTPROV_OR_NCRYPT_KEY_HANDLE hProv, PCERT_NAME_BLOB pSubjectIssuerBlob, DWORD dwFlags, PCRYPT_KEY_PROV_INFO pKeyProvInfo, PCRYPT_ALGORITHM_IDENTIFIER pSignatureAlgorithm, PSYSTEMTIME pStartTime, PSYSTEMTIME pEndTime, PCERT_EXTENSIONS pExtensions)
Definition: cert.c:3552
BOOL WINAPI CertGetValidUsages(DWORD cCerts, PCCERT_CONTEXT *rghCerts, int *cNumOIDs, LPSTR *rghOIDs, DWORD *pcbOIDs)
Definition: cert.c:3159
BOOL WINAPI CryptEncodeObjectEx(DWORD dwCertEncodingType, LPCSTR lpszStructType, const void *pvStructInfo, DWORD dwFlags, PCRYPT_ENCODE_PARA pEncodePara, void *pvEncoded, DWORD *pcbEncoded)
Definition: encode.c:4696
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
#define GET_PROC(dll, func)

Referenced by START_TEST().

◆ PCCERT_CONTEXT()

static PCCERT_CONTEXT ( WINAPI pCertCreateSelfSignCertificate)
static

◆ START_TEST()

START_TEST ( cert  )

Definition at line 4063 of file cert.c.

4064{
4066
4067 testAddCert();
4070 testDupCert();
4071 testFindCert();
4074 testLinkCert();
4075
4077 testCertSigs();
4081 testKeyUsage();
4094}
static void testComparePublicKeyInfo(void)
Definition: cert.c:3189
static void testCompareCertName(void)
Definition: cert.c:2961
static void testCryptHashCert(void)
Definition: cert.c:1752
static void testCreateCert(void)
Definition: cert.c:635
static void testVerifyRevocation(void)
Definition: cert.c:3597
static void testGetPublicKeyLength(void)
Definition: cert.c:3971
static void testSignAndEncodeCert(void)
Definition: cert.c:2089
static void testLinkCert(void)
Definition: cert.c:776
static void testCertProperties(void)
Definition: cert.c:405
static void testDupCert(void)
Definition: cert.c:679
static void testHashPublicKeyInfo(void)
Definition: cert.c:3322
static void init_function_pointers(void)
Definition: cert.c:42
static void testAcquireCertPrivateKey(void)
Definition: cert.c:3762
static void testHashToBeSigned(void)
Definition: cert.c:3366
static void testIntendedKeyUsage(void)
Definition: cert.c:2459
static void testGetIssuerCert(void)
Definition: cert.c:1562
static void testCompareIntegerBlob(void)
Definition: cert.c:3175
static void testCompareCert(void)
Definition: cert.c:3422
static void testKeyUsage(void)
Definition: cert.c:2511
static void testIsRDNAttrsInCertificateName(void)
Definition: cert.c:3031
static void testCreateSelfSignCert(void)
Definition: cert.c:2175
static void testCertSigs(void)
Definition: cert.c:2049
static void testAddCert(void)
Definition: cert.c:143
static void testGetSubjectCert(void)
Definition: cert.c:1362
static void testGetValidUsages(void)
Definition: cert.c:2804
static void testFindCert(void)
Definition: cert.c:1131
static void testVerifySubjectCert(void)
Definition: cert.c:3455

◆ testAcquireCertPrivateKey()

static void testAcquireCertPrivateKey ( void  )
static

Definition at line 3762 of file cert.c.

3763{
3764 BOOL ret;
3766 HCRYPTPROV csp;
3767 DWORD size, keySpec;
3768 BOOL callerFree;
3769 CRYPT_KEY_PROV_INFO keyProvInfo;
3770 HCRYPTKEY key;
3771 WCHAR ms_def_prov_w[MAX_PATH];
3772
3773 if (!pCryptAcquireCertificatePrivateKey)
3774 {
3775 win_skip("CryptAcquireCertificatePrivateKey() is not available\n");
3776 return;
3777 }
3778
3779 lstrcpyW(ms_def_prov_w, MS_DEF_PROV_W);
3780
3781 keyProvInfo.pwszContainerName = cspNameW;
3782 keyProvInfo.pwszProvName = ms_def_prov_w;
3783 keyProvInfo.dwProvType = PROV_RSA_FULL;
3784 keyProvInfo.dwFlags = 0;
3785 keyProvInfo.cProvParam = 0;
3786 keyProvInfo.rgProvParam = NULL;
3787 keyProvInfo.dwKeySpec = AT_SIGNATURE;
3788
3789 pCryptAcquireContextA(NULL, cspNameA, MS_DEF_PROV_A, PROV_RSA_FULL,
3791
3793 sizeof(selfSignedCert));
3794
3795 /* Crash
3796 ret = pCryptAcquireCertificatePrivateKey(NULL, 0, NULL, NULL, NULL, NULL);
3797 ret = pCryptAcquireCertificatePrivateKey(NULL, 0, NULL, NULL, NULL,
3798 &callerFree);
3799 ret = pCryptAcquireCertificatePrivateKey(NULL, 0, NULL, NULL, &keySpec,
3800 NULL);
3801 ret = pCryptAcquireCertificatePrivateKey(NULL, 0, NULL, &csp, NULL, NULL);
3802 ret = pCryptAcquireCertificatePrivateKey(NULL, 0, NULL, &csp, &keySpec,
3803 &callerFree);
3804 ret = pCryptAcquireCertificatePrivateKey(cert, 0, NULL, NULL, NULL, NULL);
3805 */
3806
3807 /* Missing private key */
3808 ret = pCryptAcquireCertificatePrivateKey(cert, 0, NULL, &csp, NULL, NULL);
3810 "Expected CRYPT_E_NO_KEY_PROPERTY, got %08x\n", GetLastError());
3811 ret = pCryptAcquireCertificatePrivateKey(cert, 0, NULL, &csp, &keySpec,
3812 &callerFree);
3814 "Expected CRYPT_E_NO_KEY_PROPERTY, got %08x\n", GetLastError());
3816 &keyProvInfo);
3817 ret = pCryptAcquireCertificatePrivateKey(cert, 0, NULL, &csp, &keySpec,
3818 &callerFree);
3820 "Expected CRYPT_E_NO_KEY_PROPERTY, got %08x\n", GetLastError());
3821
3822 pCryptAcquireContextA(&csp, cspNameA, MS_DEF_PROV_A, PROV_RSA_FULL,
3824 ret = CryptImportKey(csp, privKey, sizeof(privKey), 0, 0, &key);
3825 ok(ret, "CryptImportKey failed: %08x\n", GetLastError());
3826 if (ret)
3827 {
3828 HCRYPTPROV certCSP;
3829 DWORD size;
3830 CERT_KEY_CONTEXT keyContext;
3831
3832 /* Don't cache provider */
3833 ret = pCryptAcquireCertificatePrivateKey(cert, 0, NULL, &certCSP,
3834 &keySpec, &callerFree);
3835 ok(ret ||
3836 broken(!ret), /* win95 */
3837 "CryptAcquireCertificatePrivateKey failed: %08x\n",
3838 GetLastError());
3839 if (ret)
3840 {
3841 ok(callerFree, "Expected callerFree to be TRUE\n");
3842 CryptReleaseContext(certCSP, 0);
3843 }
3844
3845 ret = pCryptAcquireCertificatePrivateKey(cert, 0, NULL, &certCSP,
3846 NULL, NULL);
3847 ok(ret ||
3848 broken(!ret), /* win95 */
3849 "CryptAcquireCertificatePrivateKey failed: %08x\n",
3850 GetLastError());
3851 CryptReleaseContext(certCSP, 0);
3852
3853 /* Use the key prov info's caching (there shouldn't be any) */
3854 ret = pCryptAcquireCertificatePrivateKey(cert,
3855 CRYPT_ACQUIRE_USE_PROV_INFO_FLAG, NULL, &certCSP, &keySpec,
3856 &callerFree);
3857 ok(ret ||
3858 broken(!ret), /* win95 */
3859 "CryptAcquireCertificatePrivateKey failed: %08x\n",
3860 GetLastError());
3861 if (ret)
3862 {
3863 ok(callerFree, "Expected callerFree to be TRUE\n");
3864 CryptReleaseContext(certCSP, 0);
3865 }
3866
3867 /* Cache it (and check that it's cached) */
3868 ret = pCryptAcquireCertificatePrivateKey(cert,
3869 CRYPT_ACQUIRE_CACHE_FLAG, NULL, &certCSP, &keySpec, &callerFree);
3870 ok(ret ||
3871 broken(!ret), /* win95 */
3872 "CryptAcquireCertificatePrivateKey failed: %08x\n",
3873 GetLastError());
3874 ok(!callerFree, "Expected callerFree to be FALSE\n");
3875 size = sizeof(keyContext);
3877 &keyContext, &size);
3878 ok(ret ||
3879 broken(!ret), /* win95 */
3880 "CertGetCertificateContextProperty failed: %08x\n",
3881 GetLastError());
3882
3883 /* Remove the cached provider */
3884 CryptReleaseContext(keyContext.hCryptProv, 0);
3886 NULL);
3887 /* Allow caching via the key prov info */
3890 &keyProvInfo);
3891 /* Now use the key prov info's caching */
3892 ret = pCryptAcquireCertificatePrivateKey(cert,
3893 CRYPT_ACQUIRE_USE_PROV_INFO_FLAG, NULL, &certCSP, &keySpec,
3894 &callerFree);
3895 ok(ret ||
3896 broken(!ret), /* win95 */
3897 "CryptAcquireCertificatePrivateKey failed: %08x\n",
3898 GetLastError());
3899 ok(!callerFree, "Expected callerFree to be FALSE\n");
3900 size = sizeof(keyContext);
3902 &keyContext, &size);
3903 ok(ret ||
3904 broken(!ret), /* win95 */
3905 "CertGetCertificateContextProperty failed: %08x\n",
3906 GetLastError());
3907 CryptReleaseContext(certCSP, 0);
3908
3910 }
3911
3912 /* Some sanity-checking on public key exporting */
3914 &cert->pCertInfo->SubjectPublicKeyInfo, &key);
3915 ok(ret, "CryptImportPublicKeyInfo failed: %08x\n", GetLastError());
3916 if (ret)
3917 {
3919 ok(ret, "CryptExportKey failed: %08x\n", GetLastError());
3920 if (ret)
3921 {
3922 LPBYTE buf = HeapAlloc(GetProcessHeap(), 0, size), encodedKey;
3923
3925 ok(ret, "CryptExportKey failed: %08x\n", GetLastError());
3926 ok(size == sizeof(exportedPublicKeyBlob), "Unexpected size %d\n",
3927 size);
3928 ok(!memcmp(buf, exportedPublicKeyBlob, size), "Unexpected value\n");
3929 ret = pCryptEncodeObjectEx(X509_ASN_ENCODING, RSA_CSP_PUBLICKEYBLOB,
3930 buf, CRYPT_ENCODE_ALLOC_FLAG, NULL, &encodedKey, &size);
3931 ok(ret, "CryptEncodeObjectEx failed: %08x\n", GetLastError());
3932 if (ret)
3933 {
3934 ok(size == sizeof(asnEncodedPublicKey), "Unexpected size %d\n",
3935 size);
3936 ok(!memcmp(encodedKey, asnEncodedPublicKey, size),
3937 "Unexpected value\n");
3938 LocalFree(encodedKey);
3939 }
3941 }
3943 }
3945 NULL, 0, NULL, NULL, &size);
3946 ok(ret, "CryptExportPublicKeyInfoEx failed: %08x\n", GetLastError());
3947 if (ret)
3948 {
3950
3952 NULL, 0, NULL, info, &size);
3953 ok(ret, "CryptExportPublicKeyInfoEx failed: %08x\n", GetLastError());
3954 if (ret)
3955 {
3956 ok(info->PublicKey.cbData == sizeof(asnEncodedPublicKey),
3957 "Unexpected size %d\n", info->PublicKey.cbData);
3958 ok(!memcmp(info->PublicKey.pbData, asnEncodedPublicKey,
3959 info->PublicKey.cbData), "Unexpected value\n");
3960 }
3962 }
3963
3964 CryptReleaseContext(csp, 0);
3965 pCryptAcquireContextA(&csp, cspNameA, MS_DEF_PROV_A, PROV_RSA_FULL,
3967
3969}
#define broken(x)
Definition: _sntprintf.h:21
BOOL WINAPI CryptExportKey(HCRYPTKEY hKey, HCRYPTKEY hExpKey, DWORD dwBlobType, DWORD dwFlags, BYTE *pbData, DWORD *pdwDataLen)
Definition: crypt.c:1416
BOOL WINAPI CryptDestroyKey(HCRYPTKEY hKey)
Definition: crypt.c:930
BOOL WINAPI CryptReleaseContext(HCRYPTPROV hProv, DWORD dwFlags)
Definition: crypt.c:648
BOOL WINAPI CryptImportKey(HCRYPTPROV hProv, const BYTE *pbData, DWORD dwDataLen, HCRYPTKEY hPubKey, DWORD dwFlags, HCRYPTKEY *phKey)
Definition: crypt.c:1850
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
BOOL WINAPI CertSetCertificateContextProperty(PCCERT_CONTEXT pCertContext, DWORD dwPropId, DWORD dwFlags, const void *pvData)
Definition: cert.c:799
BOOL WINAPI CryptExportPublicKeyInfoEx(HCRYPTPROV_OR_NCRYPT_KEY_HANDLE hCryptProv, DWORD dwKeySpec, DWORD dwCertEncodingType, LPSTR pszPublicKeyObjId, DWORD dwFlags, void *pvAuxInfo, PCERT_PUBLIC_KEY_INFO pInfo, DWORD *pcbInfo)
Definition: encode.c:4934
BOOL WINAPI CryptImportPublicKeyInfo(HCRYPTPROV hCryptProv, DWORD dwCertEncodingType, PCERT_PUBLIC_KEY_INFO pInfo, HCRYPTKEY *phKey)
Definition: encode.c:4970
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define MAX_PATH
Definition: compat.h:34
#define HeapFree(x, y, z)
Definition: compat.h:735
#define lstrcpyW
Definition: compat.h:749
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594
static WCHAR cspNameW[]
Definition: cert.c:353
static BYTE privKey[]
Definition: cert.c:3721
static const BYTE exportedPublicKeyBlob[]
Definition: cert.c:3747
static const BYTE asnEncodedPublicKey[]
Definition: cert.c:3755
static const CHAR cspNameA[]
Definition: cert.c:352
static const BYTE selfSignedCert[]
Definition: cert.c:378
static BYTE cert[]
Definition: msg.c:1437
#define win_skip
Definition: test.h:163
HCRYPTPROV hCryptProv
Definition: wincrypt.h:220
LPWSTR pwszContainerName
Definition: wincrypt.h:209
PCRYPT_KEY_PROV_PARAM rgProvParam
Definition: wincrypt.h:214
Definition: copy.c:22
unsigned char * LPBYTE
Definition: typedefs.h:53
#define MS_DEF_PROV_A
Definition: wincrypt.h:1860
#define CRYPT_NEWKEYSET
Definition: wincrypt.h:2070
#define PROV_RSA_FULL
Definition: wincrypt.h:2039
#define CERT_KEY_CONTEXT_PROP_ID
Definition: wincrypt.h:2690
ULONG_PTR HCRYPTPROV
Definition: wincrypt.h:46
#define CERT_KEY_PROV_INFO_PROP_ID
Definition: wincrypt.h:2686
#define CERT_SET_KEY_CONTEXT_PROP_ID
Definition: wincrypt.h:3595
#define CRYPT_DELETEKEYSET
Definition: wincrypt.h:2071
#define X509_ASN_ENCODING
Definition: wincrypt.h:2297
#define PUBLICKEYBLOB
Definition: wincrypt.h:2240
static const WCHAR MS_DEF_PROV_W[]
Definition: wincrypt.h:1868
#define RSA_CSP_PUBLICKEYBLOB
Definition: wincrypt.h:3384
#define CRYPT_ENCODE_ALLOC_FLAG
Definition: wincrypt.h:3441
#define AT_SIGNATURE
Definition: wincrypt.h:2036
ULONG_PTR HCRYPTKEY
Definition: wincrypt.h:49
#define CRYPT_ACQUIRE_USE_PROV_INFO_FLAG
Definition: wincrypt.h:3602
#define CRYPT_ACQUIRE_CACHE_FLAG
Definition: wincrypt.h:3601
#define CRYPT_E_NO_KEY_PROPERTY
Definition: winerror.h:3014
#define NTE_BAD_KEYSET
Definition: winerror.h:2890
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by START_TEST().

◆ testAddCert()

static void testAddCert ( void  )
static

Definition at line 143 of file cert.c.

144{
145 HCERTSTORE store;
148 PCCERT_CONTEXT copyContext;
149 BOOL ret;
150
153 ok(store != NULL, "CertOpenStore failed: %d\n", GetLastError());
154 if (!store)
155 return;
156
157 /* Weird--bad add disposition leads to an access violation in Windows.
158 * Both tests crash on some win9x boxes.
159 */
160 if (0)
161 {
163 sizeof(bigCert), 0, NULL);
166 "Expected STATUS_ACCESS_VIOLATION or E_INVALIDARG, got %08x\n",
167 GetLastError());
169 bigCert, sizeof(bigCert), 0, NULL);
172 "Expected STATUS_ACCESS_VIOLATION or E_INVALIDARG, got %08x\n",
173 GetLastError());
174 }
175
176 /* Weird--can add a cert to the NULL store (does this have special
177 * meaning?)
178 */
179 context = NULL;
182 ok(ret || broken(GetLastError() == OSS_DATA_ERROR /* win98 */),
183 "CertAddEncodedCertificateToStore failed: %08x\n", GetLastError());
184 if (context)
186 if (!ret && GetLastError() == OSS_DATA_ERROR)
187 {
188 skip("bigCert can't be decoded, skipping tests\n");
189 return;
190 }
191
194 ok(ret, "CertAddEncodedCertificateToStore failed: %08x\n",
195 GetLastError());
198 ok(ret, "CertAddEncodedCertificateToStore failed: %08x\n",
199 GetLastError());
200 /* This has the same name as bigCert, so finding isn't done by name */
203 ok(ret, "CertAddEncodedCertificateToStore failed: %08x\n",
204 GetLastError());
205 ok(context != NULL, "Expected a context\n");
206 if (context)
207 {
209
210 /* Duplicate (AddRef) the context so we can still use it after
211 * deleting it from the store.
212 */
215 /* Set the same hash as bigCert2, and try to readd it */
217 0, &hash);
218 ok(ret, "CertSetCertificateContextProperty failed: %08x\n",
219 GetLastError());
222 /* The failure is a bit odd (CRYPT_E_ASN1_BADTAG), so just check
223 * that it fails.
224 */
225 ok(!ret, "Expected failure\n");
227 }
229 sizeof(bigCert2));
230 ok(context != NULL, "Expected a context\n");
231 if (context)
232 {
233 /* Try to readd bigCert2 to the store */
237 "Expected CRYPT_E_EXISTS, got %08x\n", GetLastError());
239 }
240
241 /* Adding a cert with the same issuer name and serial number (but
242 * different subject) as an existing cert succeeds.
243 */
244 context = NULL;
248 ok(ret, "CertAddEncodedCertificateToStore failed: %08x\n",
249 GetLastError());
250 if (context)
252
253 /* Adding a cert with the same subject name and serial number (but
254 * different issuer) as an existing cert succeeds.
255 */
256 context = NULL;
260 ok(ret, "CertAddEncodedCertificateToStore failed: %08x\n",
261 GetLastError());
262 if (context)
264
265 /* Adding a cert with the same issuer name and serial number (but
266 * different otherwise) as an existing cert succeeds.
267 */
268 context = NULL;
272 ok(ret, "CertAddEncodedCertificateToStore failed: %08x\n",
273 GetLastError());
274 if (context)
276
279 ok(collection != NULL, "CertOpenStore failed: %08x\n", GetLastError());
280 if (collection)
281 {
282 /* Add store to the collection, but disable updates */
284
286 sizeof(bigCert2));
287 ok(context != NULL, "Expected a context\n");
288 if (context)
289 {
290 /* Try to readd bigCert2 to the collection */
294 "Expected CRYPT_E_EXISTS, got %08x\n", GetLastError());
295 /* Replacing an existing certificate context is allowed, even
296 * though updates to the collection aren't..
297 */
300 ok(ret, "CertAddCertificateContextToStore failed: %08x\n",
301 GetLastError());
302 /* use the existing certificate and ask for a copy of the context*/
303 copyContext = NULL;
305 CERT_STORE_ADD_USE_EXISTING, &copyContext);
306 ok(ret, "CertAddCertificateContextToStore failed: %08x\n",
307 GetLastError());
308 ok(copyContext != NULL, "Expected on output a non NULL copyContext\n");
309 if (copyContext)
310 CertFreeCertificateContext(copyContext);
311 /* but adding a new certificate isn't allowed. */
315 "Expected E_ACCESSDENIED, got %08x\n", GetLastError());
317 }
318
320 }
321
322 CertCloseStore(store, 0);
323}
#define skip(...)
Definition: atltest.h:64
BOOL WINAPI CertAddStoreToCollection(HCERTSTORE hCollectionStore, HCERTSTORE hSiblingStore, DWORD dwUpdateFlags, DWORD dwPriority)
#define E_INVALIDARG
Definition: ddrawi.h:101
BOOL WINAPI CertAddCertificateContextToStore(HCERTSTORE hCertStore, PCCERT_CONTEXT pCertContext, DWORD dwAddDisposition, PCCERT_CONTEXT *ppStoreContext)
Definition: cert.c:286
BOOL WINAPI CertAddEncodedCertificateToStore(HCERTSTORE hCertStore, DWORD dwCertEncodingType, const BYTE *pbCertEncoded, DWORD cbCertEncoded, DWORD dwAddDisposition, PCCERT_CONTEXT *ppCertContext)
Definition: cert.c:58
PCCERT_CONTEXT WINAPI CertDuplicateCertificateContext(PCCERT_CONTEXT pCertContext)
Definition: cert.c:360
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
BOOL WINAPI CertDeleteCertificateFromStore(PCCERT_CONTEXT pCertContext)
Definition: store.c:943
static const BYTE bigCert[]
Definition: cert.c:67
static const BYTE bigCertWithDifferentSubject[]
Definition: cert.c:80
static const BYTE bigCertWithDifferentIssuer[]
Definition: cert.c:91
static const BYTE bigCert2WithDifferentSerial[]
Definition: cert.c:116
static BYTE bigCert2Hash[]
Definition: cert.c:127
static const BYTE bigCert2[]
Definition: cert.c:106
static const BYTE certWithUsage[]
Definition: cert.c:130
static ICollection collection
Definition: typelib.c:184
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:242
#define CERT_STORE_PROV_COLLECTION
Definition: wincrypt.h:2261
#define CERT_STORE_ADD_REPLACE_EXISTING
Definition: wincrypt.h:2484
#define CERT_STORE_CREATE_NEW_FLAG
Definition: wincrypt.h:2464
#define CERT_STORE_PROV_MEMORY
Definition: wincrypt.h:2251
#define CERT_STORE_ADD_USE_EXISTING
Definition: wincrypt.h:2483
#define CERT_STORE_ADD_NEW
Definition: wincrypt.h:2482
#define CERT_HASH_PROP_ID
Definition: wincrypt.h:2688
#define CERT_STORE_ADD_ALWAYS
Definition: wincrypt.h:2485
#define E_ACCESSDENIED
Definition: winerror.h:2849
#define CRYPT_E_EXISTS
Definition: winerror.h:3008
#define OSS_DATA_ERROR
Definition: winerror.h:3042

Referenced by START_TEST().

◆ testCertProperties()

static void testCertProperties ( void  )
static

Definition at line 405 of file cert.c.

406{
408 bigCert, sizeof(bigCert));
409 DWORD propID, numProps, access, size;
410 BOOL ret;
411 BYTE hash[20] = { 0 }, hashProperty[20];
413 CERT_KEY_CONTEXT keyContext;
414
415 ok(context != NULL || broken(GetLastError() == OSS_DATA_ERROR /* win98 */),
416 "CertCreateCertificateContext failed: %08x\n", GetLastError());
417 if (!context)
418 return;
419
420 /* This crashes
421 propID = CertEnumCertificateContextProperties(NULL, 0);
422 */
423
424 propID = 0;
425 numProps = 0;
426 do {
428 if (propID)
429 numProps++;
430 } while (propID != 0);
431 ok(numProps == 0, "Expected 0 properties, got %d\n", numProps);
432
433 /* Tests with a NULL cert context. Prop ID 0 fails.. */
436 "Expected E_INVALIDARG, got %08x\n", GetLastError());
437 /* while this just crashes.
438 ret = CertSetCertificateContextProperty(NULL,
439 CERT_KEY_PROV_HANDLE_PROP_ID, 0, NULL);
440 */
441
444 "Expected E_INVALIDARG, got %08x\n", GetLastError());
445 /* Can't set the cert property directly, this crashes.
446 ret = CertSetCertificateContextProperty(context,
447 CERT_CERT_PROP_ID, 0, bigCert2);
448 */
449
450 /* These all crash.
451 ret = CertGetCertificateContextProperty(context,
452 CERT_ACCESS_STATE_PROP_ID, 0, NULL);
453 ret = CertGetCertificateContextProperty(context, CERT_HASH_PROP_ID,
454 NULL, NULL);
455 ret = CertGetCertificateContextProperty(context, CERT_HASH_PROP_ID,
456 hashProperty, NULL);
457 */
458 /* A missing prop */
459 size = 0;
463 "Expected CRYPT_E_NOT_FOUND, got %08x\n", GetLastError());
464 /* And, an implicit property */
465 size = sizeof(access);
468 ok(ret, "CertGetCertificateContextProperty failed: %08x\n",
469 GetLastError());
471 "Didn't expect a persisted cert\n");
472 /* Trying to set this "read only" property crashes.
473 access |= CERT_ACCESS_STATE_WRITE_PERSIST_FLAG;
474 ret = CertSetCertificateContextProperty(context,
475 CERT_ACCESS_STATE_PROP_ID, 0, &access);
476 */
477
478 /* Can I set the hash to an invalid hash? */
479 blob.pbData = hash;
480 blob.cbData = sizeof(hash);
482 &blob);
483 ok(ret, "CertSetCertificateContextProperty failed: %08x\n",
484 GetLastError());
485 size = sizeof(hashProperty);
487 hashProperty, &size);
488 ok(ret, "CertGetCertificateContextProperty failed: %08x\n",
489 GetLastError());
490 ok(!memcmp(hashProperty, hash, sizeof(hash)), "Unexpected hash\n");
491 /* Delete the (bogus) hash, and get the real one */
493 NULL);
494 ok(ret, "CertSetCertificateContextProperty failed: %08x\n",
495 GetLastError());
498
499 /* Now that the hash property is set, we should get one property when
500 * enumerating.
501 */
502 propID = 0;
503 numProps = 0;
504 do {
506 if (propID)
507 numProps++;
508 } while (propID != 0);
509 ok(numProps == 1, "Expected 1 properties, got %d\n", numProps);
510
511 /* Check a few other implicit properties */
514
515 /* Getting the signature hash fails with this bogus certificate */
516 size = 0;
519 ok(!ret &&
522 GetLastError() == OSS_DATA_ERROR), /* win9x */
523 "Expected CRYPT_E_ASN1_BADTAG, got %08x\n", GetLastError());
524
525 /* Test key contexts and handles and such */
526 size = 0;
528 NULL, &size);
530 "Expected CRYPT_E_NOT_FOUND, got %08x\n", GetLastError());
531 size = sizeof(CERT_KEY_CONTEXT);
533 NULL, &size);
535 "Expected CRYPT_E_NOT_FOUND, got %08x\n", GetLastError());
537 &keyContext, &size);
539 "Expected CRYPT_E_NOT_FOUND, got %08x\n", GetLastError());
540 /* Key context with an invalid size */
541 keyContext.cbSize = 0;
543 0, &keyContext);
545 "Expected E_INVALIDARG, got %08x\n", GetLastError());
546 size = sizeof(keyContext);
548 &keyContext, &size);
550 "Expected CRYPT_E_NOT_FOUND, got %08x\n", GetLastError());
551 keyContext.cbSize = sizeof(keyContext);
552 keyContext.hCryptProv = 0;
553 keyContext.dwKeySpec = AT_SIGNATURE;
555 0, &keyContext);
556 ok(ret, "CertSetCertificateContextProperty failed: %08x\n", GetLastError());
557 /* Now that that's set, the key prov handle property is also gettable.
558 */
559 size = sizeof(keyContext.hCryptProv);
562 ok(ret, "Expected to get the CERT_KEY_PROV_HANDLE_PROP_ID, got %08x\n",
563 GetLastError());
564 /* Remove the key prov handle property.. */
567 ok(ret, "CertSetCertificateContextProperty failed: %08x\n",
568 GetLastError());
569 /* and the key context's CSP is set to NULL. */
570 size = sizeof(keyContext);
572 CERT_KEY_CONTEXT_PROP_ID, &keyContext, &size);
573 ok(ret, "CertGetCertificateContextProperty failed: %08x\n",
574 GetLastError());
575 ok(keyContext.hCryptProv == 0, "Expected no hCryptProv\n");
576
577 /* According to MSDN the subject key id can be stored as a property,
578 * as a subject key extension, or as the SHA1 hash of the public key,
579 * but this cert has none of them:
580 */
584 "Expected ERROR_INVALID_DATA, got %08x\n", GetLastError());
586 /* This cert does have a public key, but its subject key identifier still
587 * isn't available: */
593 "Expected ERROR_INVALID_DATA, got %08x\n", GetLastError());
595 /* This cert with a subject key extension can have its key identifier
596 * property retrieved:
597 */
602 ok(ret, "CertGetCertificateContextProperty failed: %08x\n", GetLastError());
603 if (ret)
604 {
606
607 if (buf)
608 {
611 ok(ret, "CertGetCertificateContextProperty failed: %08x\n",
612 GetLastError());
613 ok(!memcmp(buf, subjectKeyId, size), "Unexpected subject key id\n");
615 }
616 }
618
621 /* Getting the signature hash of a valid (self-signed) cert succeeds */
622 size = 0;
625 ok(ret, "CertGetCertificateContextProperty failed: %08x\n", GetLastError());
626 ok(size == sizeof(selfSignedSignatureHash), "unexpected size %d\n", size);
628 CERT_SIGNATURE_HASH_PROP_ID, hashProperty, &size);
629 if (ret)
630 ok(!memcmp(hashProperty, selfSignedSignatureHash, size),
631 "unexpected value\n");
633}
DWORD WINAPI CertEnumCertificateContextProperties(PCCERT_CONTEXT pCertContext, DWORD dwPropId)
Definition: cert.c:380
GLuint GLint GLboolean GLint GLenum access
Definition: glext.h:7866
static void checkHash(const BYTE *data, DWORD dataLen, ALG_ID algID, PCCERT_CONTEXT context, DWORD propID)
Definition: cert.c:325
static const BYTE selfSignedSignatureHash[]
Definition: cert.c:402
static const BYTE subjectKeyId[]
Definition: cert.c:376
static const BYTE v1CertWithPubKey[]
Definition: cert.c:354
static const BYTE v1CertWithSubjectKeyId[]
Definition: cert.c:366
Definition: image.c:134
#define CERT_MD5_HASH_PROP_ID
Definition: wincrypt.h:2689
#define CALG_SHA1
Definition: wincrypt.h:1807
#define CERT_KEY_IDENTIFIER_PROP_ID
Definition: wincrypt.h:2706
#define CALG_MD5
Definition: wincrypt.h:1805
#define CERT_ACCESS_STATE_PROP_ID
Definition: wincrypt.h:2700
struct _CERT_KEY_CONTEXT CERT_KEY_CONTEXT
#define CERT_ACCESS_STATE_WRITE_PERSIST_FLAG
Definition: wincrypt.h:2766
#define CERT_SIGNATURE_HASH_PROP_ID
Definition: wincrypt.h:2701
#define CERT_KEY_PROV_HANDLE_PROP_ID
Definition: wincrypt.h:2685
#define CRYPT_E_NOT_FOUND
Definition: winerror.h:3007
#define CRYPT_E_ASN1_BADTAG
Definition: winerror.h:3095
#define ERROR_INVALID_DATA
Definition: winerror.h:116

Referenced by START_TEST().

◆ testCertSigs()

static void testCertSigs ( void  )
static

Definition at line 2049 of file cert.c.

2050{
2051 HCRYPTPROV csp;
2052 CRYPT_DATA_BLOB toBeSigned = { sizeof(emptyCert), emptyCert };
2053 BOOL ret;
2054 BYTE sig[64];
2055 DWORD sigSize = sizeof(sig);
2056
2057 /* Just in case a previous run failed, delete this thing */
2058 pCryptAcquireContextA(&csp, cspNameA, MS_DEF_PROV_A, PROV_RSA_FULL,
2060 ret = pCryptAcquireContextA(&csp, cspNameA, MS_DEF_PROV_A, PROV_RSA_FULL,
2062 ok(ret, "CryptAcquireContext failed: %08x\n", GetLastError());
2063
2064 testSignCert(csp, &toBeSigned, szOID_RSA_SHA1RSA, sig, &sigSize);
2065 testVerifyCertSig(csp, &toBeSigned, szOID_RSA_SHA1RSA, sig, sigSize);
2066 testVerifyCertSigEx(csp, &toBeSigned, szOID_RSA_SHA1RSA, sig, sigSize);
2067
2068 CryptReleaseContext(csp, 0);
2069 ret = pCryptAcquireContextA(&csp, cspNameA, MS_DEF_PROV_A, PROV_RSA_FULL,
2071 ok(ret, "CryptAcquireContext failed: %08x\n", GetLastError());
2072}
static void testVerifyCertSigEx(HCRYPTPROV csp, const CRYPT_DATA_BLOB *toBeSigned, LPCSTR sigOID, const BYTE *sig, DWORD sigLen)
Definition: cert.c:1948
static void testVerifyCertSig(HCRYPTPROV csp, const CRYPT_DATA_BLOB *toBeSigned, LPCSTR sigOID, const BYTE *sig, DWORD sigLen)
Definition: cert.c:1881
static BYTE emptyCert[]
Definition: cert.c:2047
static void testSignCert(HCRYPTPROV csp, const CRYPT_DATA_BLOB *toBeSigned, LPCSTR sigOID, BYTE *sig, DWORD *sigLen)
Definition: cert.c:1819
#define szOID_RSA_SHA1RSA
Definition: wincrypt.h:3022

Referenced by START_TEST().

◆ testCompareCert()

static void testCompareCert ( void  )
static

Definition at line 3422 of file cert.c.

3423{
3424 CERT_INFO info1 = { 0 }, info2 = { 0 };
3425 BOOL ret;
3426
3427 /* Crashes */
3428 if (0)
3430
3431 /* Certs with the same issuer and serial number are equal, even if they
3432 * differ in other respects (like subject).
3433 */
3435 info1.SerialNumber.cbData = sizeof(serialNum);
3436 info1.Issuer.pbData = subjectName;
3437 info1.Issuer.cbData = sizeof(subjectName);
3438 info1.Subject.pbData = subjectName2;
3439 info1.Subject.cbData = sizeof(subjectName2);
3440 info2.SerialNumber.pbData = serialNum;
3441 info2.SerialNumber.cbData = sizeof(serialNum);
3442 info2.Issuer.pbData = subjectName;
3443 info2.Issuer.cbData = sizeof(subjectName);
3444 info2.Subject.pbData = subjectName;
3445 info2.Subject.cbData = sizeof(subjectName);
3446 ret = CertCompareCertificate(X509_ASN_ENCODING, &info1, &info2);
3447 ok(ret, "Expected certs to be equal\n");
3448
3449 info2.Issuer.pbData = subjectName2;
3450 info2.Issuer.cbData = sizeof(subjectName2);
3451 ret = CertCompareCertificate(X509_ASN_ENCODING, &info1, &info2);
3452 ok(!ret, "Expected certs not to be equal\n");
3453}
BOOL WINAPI CertCompareCertificate(DWORD dwCertEncodingType, PCERT_INFO pCertId1, PCERT_INFO pCertId2)
Definition: cert.c:1166
static BYTE serialNum[]
Definition: cert.c:66
static BYTE subjectName[]
Definition: cert.c:63
static BYTE subjectName2[]
Definition: cert.c:103
CERT_NAME_BLOB Subject
Definition: wincrypt.h:247
CERT_NAME_BLOB Issuer
Definition: wincrypt.h:244
CRYPT_INTEGER_BLOB SerialNumber
Definition: wincrypt.h:242
BYTE * pbData
Definition: wincrypt.h:103

Referenced by START_TEST().

◆ testCompareCertName()

static void testCompareCertName ( void  )
static

Definition at line 2961 of file cert.c.

2962{
2963 static BYTE bogus[] = { 1, 2, 3, 4 };
2964 static BYTE bogusPrime[] = { 0, 1, 2, 3, 4 };
2965 static BYTE emptyPrime[] = { 0x30, 0x00, 0x01 };
2966 BOOL ret;
2967 CERT_NAME_BLOB blob1, blob2;
2968
2969 /* crashes
2970 ret = CertCompareCertificateName(0, NULL, NULL);
2971 */
2972 /* An empty name checks against itself.. */
2973 blob1.pbData = emptyCert;
2974 blob1.cbData = sizeof(emptyCert);
2975 ret = CertCompareCertificateName(0, &blob1, &blob1);
2976 ok(ret, "CertCompareCertificateName failed: %08x\n", GetLastError());
2977 /* It doesn't have to be a valid encoded name.. */
2978 blob1.pbData = bogus;
2979 blob1.cbData = sizeof(bogus);
2980 ret = CertCompareCertificateName(0, &blob1, &blob1);
2981 ok(ret, "CertCompareCertificateName failed: %08x\n", GetLastError());
2982 /* Leading zeroes matter.. */
2983 blob2.pbData = bogusPrime;
2984 blob2.cbData = sizeof(bogusPrime);
2985 ret = CertCompareCertificateName(0, &blob1, &blob2);
2986 ok(!ret, "Expected failure\n");
2987 /* As do trailing extra bytes. */
2988 blob2.pbData = emptyPrime;
2989 blob2.cbData = sizeof(emptyPrime);
2990 ret = CertCompareCertificateName(0, &blob1, &blob2);
2991 ok(!ret, "Expected failure\n");
2992 /* Tests to show that CertCompareCertificateName doesn't decode the name
2993 * to remove spaces, or to do an order-independent comparison.
2994 */
2995 /* Compare CN="Juan Lang" with CN=" Juan Lang" */
2996 blob1.pbData = cn;
2997 blob1.cbData = sizeof(cn);
2998 blob2.pbData = cnWithLeadingSpace;
2999 blob2.cbData = sizeof(cnWithLeadingSpace);
3000 ret = CertCompareCertificateName(0, &blob1, &blob2);
3001 ok(!ret, "Expected failure\n");
3003 ok(!ret, "Expected failure\n");
3004 /* Compare CN="Juan Lang" with CN="Juan Lang " */
3006 blob2.cbData = sizeof(cnWithTrailingSpace);
3007 ret = CertCompareCertificateName(0, &blob1, &blob2);
3008 ok(!ret, "Expected failure\n");
3010 ok(!ret, "Expected failure\n");
3011 /* Compare CN="Juan Lang" with CN="Juan Lang" */
3013 blob2.cbData = sizeof(cnWithIntermediateSpace);
3014 ret = CertCompareCertificateName(0, &blob1, &blob2);
3015 ok(!ret, "Expected failure\n");
3017 ok(!ret, "Expected failure\n");
3018 /* Compare 'CN="Juan Lang", O="The Wine Project"' with
3019 * 'O="The Wine Project", CN="Juan Lang"'
3020 */
3021 blob1.pbData = cnThenO;
3022 blob1.cbData = sizeof(cnThenO);
3023 blob2.pbData = oThenCN;
3024 blob2.cbData = sizeof(oThenCN);
3025 ret = CertCompareCertificateName(0, &blob1, &blob2);
3026 ok(!ret, "Expected failure\n");
3028 ok(!ret, "Expected failure\n");
3029}
BOOL WINAPI CertCompareCertificateName(DWORD dwCertEncodingType, PCERT_NAME_BLOB pCertName1, PCERT_NAME_BLOB pCertName2)
Definition: cert.c:1180
static BYTE cnWithIntermediateSpace[]
Definition: cert.c:2947
static BYTE cn[]
Definition: cert.c:2938
static BYTE cnThenO[]
Definition: cert.c:2950
static BYTE oThenCN[]
Definition: cert.c:2955
static BYTE cnWithTrailingSpace[]
Definition: cert.c:2944
static BYTE cnWithLeadingSpace[]
Definition: cert.c:2941

Referenced by START_TEST().

◆ testCompareIntegerBlob()

static void testCompareIntegerBlob ( void  )
static

Definition at line 3175 of file cert.c.

3176{
3177 DWORD i;
3178 BOOL ret;
3179
3180 for (i = 0; i < ARRAY_SIZE(intBlobs); i++)
3181 {
3182 ret = CertCompareIntegerBlob(&intBlobs[i].blob1, &intBlobs[i].blob2);
3183 ok(ret == intBlobs[i].areEqual,
3184 "%d: expected blobs %s compare\n", i, intBlobs[i].areEqual ?
3185 "to" : "not to");
3186 }
3187}
#define ARRAY_SIZE(A)
Definition: main.h:33
BOOL WINAPI CertCompareIntegerBlob(PCRYPT_INTEGER_BLOB pInt1, PCRYPT_INTEGER_BLOB pInt2)
Definition: cert.c:1221
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
static struct IntBlobTest intBlobs[]

Referenced by START_TEST().

◆ testComparePublicKeyInfo()

static void testComparePublicKeyInfo ( void  )
static

Definition at line 3189 of file cert.c.

3190{
3191 BOOL ret;
3192 CERT_PUBLIC_KEY_INFO info1 = { { 0 } }, info2 = { { 0 } };
3193 static CHAR oid_rsa_rsa[] = szOID_RSA_RSA;
3194 static CHAR oid_rsa_sha1rsa[] = szOID_RSA_SHA1RSA;
3195 static CHAR oid_x957_dsa[] = szOID_X957_DSA;
3196 static BYTE bits1[] = { 1, 0 };
3197 static BYTE bits2[] = { 0 };
3198 static BYTE bits3[] = { 1 };
3199 static BYTE bits4[] = { 0x30,8, 2,1,0x81, 2,3,1,0,1 }; /* ASN_SEQUENCE */
3200 static BYTE bits5[] = { 0x30,9, 2,2,0,0x81, 2,3,1,0,1 }; /* ASN_SEQUENCE */
3201 static BYTE bits6[] = { 0x30,9, 2,2,0,0x82, 2,3,1,0,1 }; /* ASN_SEQUENCE */
3202 static BYTE bits7[] = { 0x04,8, 2,1,0x81, 2,3,1,0,1 }; /* ASN_OCTETSTRING */
3203 static BYTE bits8[] = { 0x04,9, 2,2,0,0x81, 2,3,1,0,1 }; /* ASN_OCTETSTRING */
3204 static BYTE bits9[] = { 0x04,9, 2,2,0,0x82, 2,3,1,0,1 }; /* ASN_OCTETSTRING */
3205
3206 /* crashes
3207 ret = CertComparePublicKeyInfo(0, NULL, NULL);
3208 */
3209 /* Empty public keys compare */
3210 ret = CertComparePublicKeyInfo(0, &info1, &info2);
3211 ok(ret, "CertComparePublicKeyInfo failed: %08x\n", GetLastError());
3213 ok(ret, "CertComparePublicKeyInfo failed: %08x\n", GetLastError());
3214
3215 /* Different OIDs appear to compare */
3216 info1.Algorithm.pszObjId = oid_rsa_rsa;
3217 info2.Algorithm.pszObjId = oid_rsa_sha1rsa;
3218 ret = CertComparePublicKeyInfo(0, &info1, &info2);
3219 ok(ret, "CertComparePublicKeyInfo failed: %08x\n", GetLastError());
3221 ok(ret, "CertComparePublicKeyInfo failed: %08x\n", GetLastError());
3222
3223 info2.Algorithm.pszObjId = oid_x957_dsa;
3224 ret = CertComparePublicKeyInfo(0, &info1, &info2);
3225 ok(ret, "CertComparePublicKeyInfo failed: %08x\n", GetLastError());
3227 ok(ret, "CertComparePublicKeyInfo failed: %08x\n", GetLastError());
3228
3229 info1.PublicKey.cbData = sizeof(bits1);
3230 info1.PublicKey.pbData = bits1;
3231 info1.PublicKey.cUnusedBits = 0;
3232 info2.PublicKey.cbData = sizeof(bits1);
3233 info2.PublicKey.pbData = bits1;
3234 info2.PublicKey.cUnusedBits = 0;
3235 ret = CertComparePublicKeyInfo(0, &info1, &info2);
3236 ok(ret, "CertComparePublicKeyInfo failed: %08x\n", GetLastError());
3238 ok(ret, "CertComparePublicKeyInfo failed: %08x\n", GetLastError());
3239
3240 info2.Algorithm.pszObjId = oid_rsa_rsa;
3241 info1.PublicKey.cbData = sizeof(bits4);
3242 info1.PublicKey.pbData = bits4;
3243 info1.PublicKey.cUnusedBits = 0;
3244 info2.PublicKey.cbData = sizeof(bits5);
3245 info2.PublicKey.pbData = bits5;
3246 info2.PublicKey.cUnusedBits = 0;
3247 ret = CertComparePublicKeyInfo(0, &info1, &info2);
3248 ok(!ret, "CertComparePublicKeyInfo: as raw binary: keys should be unequal\n");
3250 ok(ret, "CertComparePublicKeyInfo: as ASN.1 encoded: keys should be equal\n");
3251
3252 info1.PublicKey.cUnusedBits = 1;
3253 info2.PublicKey.cUnusedBits = 5;
3255 ok(ret, "CertComparePublicKeyInfo: ASN.1 encoding should ignore cUnusedBits\n");
3256 info1.PublicKey.cUnusedBits = 0;
3257 info2.PublicKey.cUnusedBits = 0;
3258 info1.PublicKey.cbData--; /* kill one byte, make ASN.1 encoded data invalid */
3260 ok(!ret, "CertComparePublicKeyInfo: comparing bad ASN.1 encoded key should fail\n");
3261 /* Even though they compare in their used bits, these do not compare */
3262 info1.PublicKey.cbData = sizeof(bits2);
3263 info1.PublicKey.pbData = bits2;
3264 info1.PublicKey.cUnusedBits = 0;
3265 info2.PublicKey.cbData = sizeof(bits3);
3266 info2.PublicKey.pbData = bits3;
3267 info2.PublicKey.cUnusedBits = 1;
3268 ret = CertComparePublicKeyInfo(0, &info1, &info2);
3269 /* Simple (non-comparing) case */
3270 ok(!ret, "Expected keys not to compare\n");
3272 ok(!ret, "Expected keys not to compare\n");
3273
3274 info2.PublicKey.cbData = sizeof(bits1);
3275 info2.PublicKey.pbData = bits1;
3276 info2.PublicKey.cUnusedBits = 0;
3277 ret = CertComparePublicKeyInfo(0, &info1, &info2);
3278 ok(!ret, "Expected keys not to compare\n");
3280 ok(!ret, "Expected keys not to compare\n");
3281
3282 info1.PublicKey.cbData = sizeof(bits7);
3283 info1.PublicKey.pbData = bits7;
3284 info1.PublicKey.cUnusedBits = 0;
3285 info2.PublicKey.cbData = sizeof(bits8);
3286 info2.PublicKey.pbData = bits8;
3287 info2.PublicKey.cUnusedBits = 0;
3288 ret = CertComparePublicKeyInfo(0, &info1, &info2);
3289 ok(!ret, "CertComparePublicKeyInfo: as raw binary: keys should be unequal\n");
3291 ok(!ret, "CertComparePublicKeyInfo: as ASN.1 encoded: keys should be unequal\n");
3292
3293 ret = CertComparePublicKeyInfo(0, &info1, &info1);
3294 ok(ret, "CertComparePublicKeyInfo: as raw binary: keys should be equal\n");
3296 ok(ret, "CertComparePublicKeyInfo: as ASN.1 encoded: keys should be equal\n");
3297 info1.PublicKey.cbData--; /* kill one byte, make ASN.1 encoded data invalid */
3299 ok(ret, "CertComparePublicKeyInfo: as ASN.1 encoded: keys should be equal\n");
3300
3301 /* ASN.1 encoded non-comparing case */
3302 info1.PublicKey.cbData = sizeof(bits5);
3303 info1.PublicKey.pbData = bits5;
3304 info1.PublicKey.cUnusedBits = 0;
3305 info2.PublicKey.cbData = sizeof(bits6);
3306 info2.PublicKey.pbData = bits6;
3307 info2.PublicKey.cUnusedBits = 0;
3309 ok(!ret, "CertComparePublicKeyInfo: different keys should be unequal\n");
3310
3311 /* ASN.1 encoded non-comparing case */
3312 info1.PublicKey.cbData = sizeof(bits8);
3313 info1.PublicKey.pbData = bits8;
3314 info1.PublicKey.cUnusedBits = 0;
3315 info2.PublicKey.cbData = sizeof(bits9);
3316 info2.PublicKey.pbData = bits9;
3317 info2.PublicKey.cUnusedBits = 0;
3319 ok(!ret, "CertComparePublicKeyInfo: different keys should be unequal\n");
3320}
BOOL WINAPI CertComparePublicKeyInfo(DWORD dwCertEncodingType, PCERT_PUBLIC_KEY_INFO pPublicKey1, PCERT_PUBLIC_KEY_INFO pPublicKey2)
Definition: cert.c:1244
CRYPT_BIT_BLOB PublicKey
Definition: wincrypt.h:226
CRYPT_ALGORITHM_IDENTIFIER Algorithm
Definition: wincrypt.h:225
DWORD cUnusedBits
Definition: wincrypt.h:198
BYTE * pbData
Definition: wincrypt.h:197
#define szOID_X957_DSA
Definition: wincrypt.h:3061
#define szOID_RSA_RSA
Definition: wincrypt.h:3015
char CHAR
Definition: xmlstorage.h:175

Referenced by START_TEST().

◆ testCreateCert()

static void testCreateCert ( void  )
static

Definition at line 635 of file cert.c.

636{
637 PCCERT_CONTEXT cert, enumCert;
639 BOOL ret;
640
641 SetLastError(0xdeadbeef);
644 "expected E_INVALIDARG, got %08x\n", GetLastError());
645 SetLastError(0xdeadbeef);
647 sizeof(selfSignedCert));
649 "expected E_INVALIDARG, got %08x\n", GetLastError());
650 SetLastError(0xdeadbeef);
652 ok(!cert &&
654 broken(GetLastError() == OSS_MORE_INPUT /* NT4 */)),
655 "expected CRYPT_E_ASN1_EOD, got %08x\n", GetLastError());
656
659 ok(cert != NULL, "creating cert failed: %08x\n", GetLastError());
660 /* Even in-memory certs are expected to have a store associated with them */
661 ok(cert->hCertStore != NULL, "expected created cert to have a store\n");
662 /* The cert doesn't have the archived property set (which would imply it
663 * doesn't show up in enumerations.)
664 */
665 size = 0;
667 NULL, &size);
669 "expected CRYPT_E_NOT_FOUND, got %08x\n", GetLastError());
670 /* Strangely, enumerating the certs in the store finds none. */
671 enumCert = NULL;
672 count = 0;
673 while ((enumCert = CertEnumCertificatesInStore(cert->hCertStore, enumCert)))
674 count++;
675 ok(!count, "expected 0, got %d\n", count);
677}
PCCERT_CONTEXT WINAPI CertEnumCertificatesInStore(HCERTSTORE hCertStore, PCCERT_CONTEXT pPrev)
Definition: store.c:928
#define SetLastError(x)
Definition: compat.h:752
GLuint GLuint GLsizei count
Definition: gl.h:1545
#define CERT_ARCHIVED_PROP_ID
Definition: wincrypt.h:2705
#define CRYPT_E_ASN1_EOD
Definition: winerror.h:3086
#define OSS_MORE_INPUT
Definition: winerror.h:3041

Referenced by START_TEST().

◆ testCreateSelfSignCert()

static void testCreateSelfSignCert ( void  )
static

Definition at line 2175 of file cert.c.

2176{
2179 HCRYPTPROV csp;
2180 BOOL ret;
2181 HCRYPTKEY key;
2183
2184 if (!pCertCreateSelfSignCertificate)
2185 {
2186 win_skip("CertCreateSelfSignCertificate() is not available\n");
2187 return;
2188 }
2189
2190 /* This crashes:
2191 context = pCertCreateSelfSignCertificate(0, NULL, 0, NULL, NULL, NULL, NULL,
2192 NULL);
2193 * Calling this with no first parameter creates a new key container, which
2194 * lasts beyond the test, so I don't test that. Nb: the generated key
2195 * name is a GUID.
2196 context = pCertCreateSelfSignCertificate(0, &name, 0, NULL, NULL, NULL, NULL,
2197 NULL);
2198 */
2199
2200 /* Acquire a CSP */
2201 pCryptAcquireContextA(&csp, cspNameA, MS_DEF_PROV_A, PROV_RSA_FULL,
2203 ret = pCryptAcquireContextA(&csp, cspNameA, MS_DEF_PROV_A, PROV_RSA_FULL,
2205 ok(ret, "CryptAcquireContext failed: %08x\n", GetLastError());
2206
2207 context = pCertCreateSelfSignCertificate(csp, &name, 0, NULL, NULL, NULL,
2208 NULL, NULL);
2210 "Expected NTE_NO_KEY, got %08x\n", GetLastError());
2211 ret = CryptGenKey(csp, AT_SIGNATURE, 0, &key);
2212 ok(ret, "CryptGenKey failed: %08x\n", GetLastError());
2213 if (ret)
2214 {
2215 context = pCertCreateSelfSignCertificate(csp, &name, 0, NULL, NULL, NULL,
2216 NULL, NULL);
2217 ok(context != NULL, "CertCreateSelfSignCertificate failed: %08x\n",
2218 GetLastError());
2219 if (context)
2220 {
2221 DWORD size = 0;
2222
2223 /* The context must have a key provider info property */
2226 ok(ret && size, "Expected non-zero key provider info\n");
2227 if (size)
2228 {
2230
2231 if (pInfo)
2232 {
2235 ok(ret, "CertGetCertificateContextProperty failed: %08x\n",
2236 GetLastError());
2237 if (ret)
2238 {
2239 /* Sanity-check the key provider */
2241 "Unexpected key container\n");
2243 "Unexpected provider\n");
2244 ok(pInfo->dwKeySpec == AT_SIGNATURE,
2245 "Expected AT_SIGNATURE, got %d\n", pInfo->dwKeySpec);
2246 }
2247 HeapFree(GetProcessHeap(), 0, pInfo);
2248 }
2249 }
2250
2252 }
2253
2255 }
2256
2257 CryptReleaseContext(csp, 0);
2258 ret = pCryptAcquireContextA(&csp, cspNameA, MS_DEF_PROV_A, PROV_RSA_FULL,
2260 ok(ret, "CryptAcquireContext failed: %08x\n", GetLastError());
2261
2262 /* Do the same test with a CSP, AT_KEYEXCHANGE and key info */
2263 pCryptAcquireContextA(&csp, cspNameA, MS_DEF_PROV_A, PROV_RSA_FULL,
2265 ret = pCryptAcquireContextA(&csp, cspNameA, MS_DEF_PROV_A, PROV_RSA_FULL,
2267 ok(ret, "CryptAcquireContext failed: %08x\n", GetLastError());
2268 ret = CryptGenKey(csp, AT_SIGNATURE, 0, &key);
2269 ok(ret, "CryptGenKey failed: %08x\n", GetLastError());
2270
2271 memset(&info,0,sizeof(info));
2272 info.dwProvType = PROV_RSA_FULL;
2273 info.dwKeySpec = AT_KEYEXCHANGE;
2274 info.pwszProvName = (LPWSTR) MS_DEF_PROV_W;
2275 info.pwszContainerName = cspNameW;
2276 /* This should fail because the CSP doesn't have the specified key. */
2277 SetLastError(0xdeadbeef);
2278 context = pCertCreateSelfSignCertificate(csp, &name, 0, &info, NULL, NULL,
2279 NULL, NULL);
2280 ok(context == NULL, "expected failure\n");
2281 if (context != NULL)
2283 else
2284 ok(GetLastError() == NTE_NO_KEY, "expected NTE_NO_KEY, got %08x\n",
2285 GetLastError());
2286 /* Again, with a CSP, AT_SIGNATURE and key info */
2287 info.dwKeySpec = AT_SIGNATURE;
2288 SetLastError(0xdeadbeef);
2289 context = pCertCreateSelfSignCertificate(csp, &name, 0, &info, NULL, NULL,
2290 NULL, NULL);
2291 ok(context != NULL,
2292 "CertCreateSelfSignCertificate failed: %08x\n", GetLastError());
2293 if (context)
2294 {
2295 DWORD size = 0;
2296
2297 /* The context must have a key provider info property */
2300 ok(ret && size, "Expected non-zero key provider info\n");
2301 if (size)
2302 {
2304
2305 if (pInfo)
2306 {
2309 ok(ret, "CertGetCertificateContextProperty failed: %08x\n",
2310 GetLastError());
2311 if (ret)
2312 {
2313 /* Sanity-check the key provider */
2315 "Unexpected key container\n");
2317 "Unexpected provider\n");
2318 ok(pInfo->dwKeySpec == AT_SIGNATURE,
2319 "Expected AT_SIGNATURE, got %d\n", pInfo->dwKeySpec);
2320 }
2321 HeapFree(GetProcessHeap(), 0, pInfo);
2322 }
2323 }
2324
2326 }
2328
2329 CryptReleaseContext(csp, 0);
2330 ret = pCryptAcquireContextA(&csp, cspNameA, MS_DEF_PROV_A, PROV_RSA_FULL,
2332 ok(ret, "CryptAcquireContext failed: %08x\n", GetLastError());
2333
2334 /* Do the same test with no CSP, AT_KEYEXCHANGE and key info */
2335 info.dwKeySpec = AT_KEYEXCHANGE;
2336 context = pCertCreateSelfSignCertificate(0, &name, 0, &info, NULL, NULL,
2337 NULL, NULL);
2338 ok(context != NULL, "CertCreateSelfSignCertificate failed: %08x\n",
2339 GetLastError());
2340 if (context)
2341 {
2342 DWORD size = 0;
2343
2344 /* The context must have a key provider info property */
2347 ok(ret && size, "Expected non-zero key provider info\n");
2348 if (size)
2349 {
2351
2352 if (pInfo)
2353 {
2356 ok(ret, "CertGetCertificateContextProperty failed: %08x\n",
2357 GetLastError());
2358 if (ret)
2359 {
2360 /* Sanity-check the key provider */
2362 "Unexpected key container\n");
2364 "Unexpected provider\n");
2365 ok(pInfo->dwKeySpec == AT_KEYEXCHANGE,
2366 "Expected AT_KEYEXCHANGE, got %d\n", pInfo->dwKeySpec);
2367 }
2368 HeapFree(GetProcessHeap(), 0, pInfo);
2369 }
2370 }
2371
2373 }
2374
2375 pCryptAcquireContextA(&csp, cspNameA, MS_DEF_PROV_A, PROV_RSA_FULL,
2377
2378 /* Acquire a CSP and generate an AT_KEYEXCHANGE key in it. */
2379 pCryptAcquireContextA(&csp, cspNameA, MS_DEF_PROV_A, PROV_RSA_FULL,
2381 ret = pCryptAcquireContextA(&csp, cspNameA, MS_DEF_PROV_A, PROV_RSA_FULL,
2383 ok(ret, "CryptAcquireContext failed: %08x\n", GetLastError());
2384
2385 context = pCertCreateSelfSignCertificate(csp, &name, 0, NULL, NULL, NULL,
2386 NULL, NULL);
2388 "Expected NTE_NO_KEY, got %08x\n", GetLastError());
2389 ret = CryptGenKey(csp, AT_KEYEXCHANGE, 0, &key);
2390 ok(ret, "CryptGenKey failed: %08x\n", GetLastError());
2392
2393 memset(&info,0,sizeof(info));
2394 info.dwProvType = PROV_RSA_FULL;
2395 info.dwKeySpec = AT_SIGNATURE;
2396 info.pwszProvName = (LPWSTR) MS_DEF_PROV_W;
2397 info.pwszContainerName = cspNameW;
2398 /* This should fail because the CSP doesn't have the specified key. */
2399 SetLastError(0xdeadbeef);
2400 context = pCertCreateSelfSignCertificate(csp, &name, 0, &info, NULL, NULL,
2401 NULL, NULL);
2402 ok(context == NULL, "expected failure\n");
2403 if (context != NULL)
2405 else
2406 ok(GetLastError() == NTE_NO_KEY, "expected NTE_NO_KEY, got %08x\n",
2407 GetLastError());
2408 /* Again, with a CSP, AT_KEYEXCHANGE and key info. This succeeds because the
2409 * CSP has an AT_KEYEXCHANGE key in it.
2410 */
2411 info.dwKeySpec = AT_KEYEXCHANGE;
2412 SetLastError(0xdeadbeef);
2413 context = pCertCreateSelfSignCertificate(csp, &name, 0, &info, NULL, NULL,
2414 NULL, NULL);
2415 ok(context != NULL,
2416 "CertCreateSelfSignCertificate failed: %08x\n", GetLastError());
2417 if (context)
2418 {
2419 DWORD size = 0;
2420
2421 /* The context must have a key provider info property */
2424 ok(ret && size, "Expected non-zero key provider info\n");
2425 if (size)
2426 {
2428
2429 if (pInfo)
2430 {
2433 ok(ret, "CertGetCertificateContextProperty failed: %08x\n",
2434 GetLastError());
2435 if (ret)
2436 {
2437 /* Sanity-check the key provider */
2439 "Unexpected key container\n");
2441 "Unexpected provider\n");
2442 ok(pInfo->dwKeySpec == AT_KEYEXCHANGE,
2443 "Expected AT_KEYEXCHANGE, got %d\n", pInfo->dwKeySpec);
2444 }
2445 HeapFree(GetProcessHeap(), 0, pInfo);
2446 }
2447 }
2448
2450 }
2451
2452 CryptReleaseContext(csp, 0);
2453 ret = pCryptAcquireContextA(&csp, cspNameA, MS_DEF_PROV_A, PROV_RSA_FULL,
2455 ok(ret, "CryptAcquireContext failed: %08x\n", GetLastError());
2456
2457}
BOOL WINAPI CryptGenKey(HCRYPTPROV hProv, ALG_ID Algid, DWORD dwFlags, HCRYPTKEY *phKey)
Definition: crypt.c:1451
int WINAPI lstrcmpW(LPCWSTR str1, LPCWSTR str2)
Definition: locale.c:4242
Definition: name.c:39
#define AT_KEYEXCHANGE
Definition: wincrypt.h:2035
#define NTE_NO_KEY
Definition: winerror.h:2881
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by START_TEST().

◆ testCryptHashCert()

static void testCryptHashCert ( void  )
static

Definition at line 1752 of file cert.c.

1753{
1754 static const BYTE emptyHash[] = { 0xda, 0x39, 0xa3, 0xee, 0x5e, 0x6b, 0x4b,
1755 0x0d, 0x32, 0x55, 0xbf, 0xef, 0x95, 0x60, 0x18, 0x90, 0xaf, 0xd8, 0x07,
1756 0x09 };
1757 static const BYTE knownHash[] = { 0xae, 0x9d, 0xbf, 0x6d, 0xf5, 0x46, 0xee,
1758 0x8b, 0xc5, 0x7a, 0x13, 0xba, 0xc2, 0xb1, 0x04, 0xf2, 0xbf, 0x52, 0xa8,
1759 0xa2 };
1760 static const BYTE toHash[] = "abcdefghijklmnopqrstuvwxyz0123456789.,;!?:";
1761 BOOL ret;
1762 BYTE hash[20];
1763 DWORD hashLen = sizeof(hash);
1764
1765 /* NULL buffer and nonzero length crashes
1766 ret = CryptHashCertificate(0, 0, 0, NULL, size, hash, &hashLen);
1767 empty hash length also crashes
1768 ret = CryptHashCertificate(0, 0, 0, buf, size, hash, NULL);
1769 */
1770 /* Test empty hash */
1771 ret = CryptHashCertificate(0, 0, 0, toHash, sizeof(toHash), NULL,
1772 &hashLen);
1773 ok(ret, "CryptHashCertificate failed: %08x\n", GetLastError());
1774 ok(hashLen == sizeof(hash), "Got unexpected size of hash %d\n", hashLen);
1775 /* Test with empty buffer */
1776 ret = CryptHashCertificate(0, 0, 0, NULL, 0, hash, &hashLen);
1777 ok(ret, "CryptHashCertificate failed: %08x\n", GetLastError());
1778 ok(!memcmp(hash, emptyHash, sizeof(emptyHash)),
1779 "Unexpected hash of nothing\n");
1780 /* Test a known value */
1781 ret = CryptHashCertificate(0, 0, 0, toHash, sizeof(toHash), hash,
1782 &hashLen);
1783 ok(ret, "CryptHashCertificate failed: %08x\n", GetLastError());
1784 ok(!memcmp(hash, knownHash, sizeof(knownHash)), "Unexpected hash\n");
1785}

Referenced by START_TEST().

◆ testDupCert()

static void testDupCert ( void  )
static

Definition at line 679 of file cert.c.

680{
681 PCCERT_CONTEXT context, dupContext, storeContext, storeContext2, context2;
682 HCERTSTORE store, store2;
683 BOOL ret;
684
687 ok(store != NULL, "CertOpenStore failed: %d\n", GetLastError());
688 if (!store)
689 return;
690
693 ok(ret || broken(GetLastError() == OSS_DATA_ERROR /* win98 */),
694 "CertAddEncodedCertificateToStore failed: %08x\n", GetLastError());
695 if (!ret && GetLastError() == OSS_DATA_ERROR)
696 {
697 skip("bigCert can't be decoded, skipping tests\n");
698 return;
699 }
700 ok(context != NULL, "Expected a valid cert context\n");
701 if (context)
702 {
703 ok(context->cbCertEncoded == sizeof(bigCert),
704 "Wrong cert size %d\n", context->cbCertEncoded);
705 ok(!memcmp(context->pbCertEncoded, bigCert, sizeof(bigCert)),
706 "Unexpected encoded cert in context\n");
707 ok(context->hCertStore == store, "Unexpected store\n");
708
710 ok(dupContext != NULL, "Expected valid duplicate\n");
711 /* Not only is it a duplicate, it's identical: the address is the
712 * same.
713 */
714 ok(dupContext == context, "Expected identical context addresses\n");
715 CertFreeCertificateContext(dupContext);
717 }
718 CertCloseStore(store, 0);
719
721 ok(context != NULL, "CertCreateCertificateContext failed\n");
722
724 ok(dupContext == context, "context != dupContext\n");
725
726 ret = CertFreeCertificateContext(dupContext);
727 ok(ret, "CertFreeCertificateContext failed\n");
728
730 ok(store != NULL, "CertOpenStore failed: %d\n", GetLastError());
731
733 ok(ret, "CertAddCertificateContextToStore failed\n");
734 ok(storeContext != NULL && storeContext != context, "unexpected storeContext\n");
735 ok(storeContext->hCertStore == store, "unexpected hCertStore\n");
736
737 ok(storeContext->pbCertEncoded != context->pbCertEncoded, "unexpected pbCertEncoded\n");
738 ok(storeContext->cbCertEncoded == context->cbCertEncoded, "unexpected cbCertEncoded\n");
739 ok(storeContext->pCertInfo != context->pCertInfo, "unexpected pCertInfo\n");
740
742 ok(store2 != NULL, "CertOpenStore failed: %d\n", GetLastError());
743
744 ret = CertAddCertificateContextToStore(store2, storeContext, CERT_STORE_ADD_NEW, &storeContext2);
745 ok(ret, "CertAddCertificateContextToStore failed\n");
746 ok(storeContext2 != NULL && storeContext2 != storeContext, "unexpected storeContext\n");
747 ok(storeContext2->hCertStore == store2, "unexpected hCertStore\n");
748
749 ok(storeContext2->pbCertEncoded != storeContext->pbCertEncoded, "unexpected pbCertEncoded\n");
750 ok(storeContext2->cbCertEncoded == storeContext->cbCertEncoded, "unexpected cbCertEncoded\n");
751 ok(storeContext2->pCertInfo != storeContext->pCertInfo, "unexpected pCertInfo\n");
752
753 CertFreeCertificateContext(storeContext2);
754 CertFreeCertificateContext(storeContext);
755
757 ok(context2 != NULL, "CertCreateCertificateContext failed\n");
758
759 ok(context2->hCertStore == context->hCertStore, "Unexpected hCertStore\n");
760
763 ok(ret, "CertFreeCertificateContext failed\n");
764
765 CertCloseStore(store, 0);
766 CertCloseStore(store2, 0);
767
768 SetLastError(0xdeadbeef);
770 ok(context == NULL, "Expected context to be NULL\n");
771
773 ok(ret, "CertFreeCertificateContext failed\n");
774}
HCERTSTORE hCertStore
Definition: wincrypt.h:483
PCERT_INFO pCertInfo
Definition: wincrypt.h:482
BYTE * pbCertEncoded
Definition: wincrypt.h:480
DWORD cbCertEncoded
Definition: wincrypt.h:481

Referenced by START_TEST().

◆ testFindCert()

static void testFindCert ( void  )
static

Definition at line 1131 of file cert.c.

1132{
1133 HCERTSTORE store;
1134 PCCERT_CONTEXT context = NULL, subject;
1135 BOOL ret;
1136 CERT_INFO certInfo = { 0 };
1138 BYTE otherSerialNumber[] = { 2 };
1139 DWORD count;
1140 static const WCHAR juan[] = { 'j','u','a','n',0 };
1141 static const WCHAR lang[] = { 'L','A','N','G',0 };
1142 static const WCHAR malcolm[] = { 'm','a','l','c','o','l','m',0 };
1143
1146 ok(store != NULL, "CertOpenStore failed: %d\n", GetLastError());
1147 if (!store)
1148 return;
1149
1152 ok(ret || broken(GetLastError() == OSS_DATA_ERROR /* win98 */),
1153 "CertAddEncodedCertificateToStore failed: %08x\n", GetLastError());
1154 if (!ret && GetLastError() == OSS_DATA_ERROR)
1155 {
1156 skip("bigCert can't be decoded, skipping tests\n");
1157 return;
1158 }
1161 ok(ret, "CertAddEncodedCertificateToStore failed: %08x\n",
1162 GetLastError());
1163 /* This has the same name as bigCert */
1166 ok(ret, "CertAddEncodedCertificateToStore failed: %08x\n",
1167 GetLastError());
1168
1169 /* Crashes
1170 context = CertFindCertificateInStore(NULL, 0, 0, 0, NULL, NULL);
1171 */
1172
1173 /* Check first cert's there, by issuer */
1174 certInfo.Subject.pbData = subjectName;
1175 certInfo.Subject.cbData = sizeof(subjectName);
1176 certInfo.SerialNumber.pbData = serialNum;
1177 certInfo.SerialNumber.cbData = sizeof(serialNum);
1179 CERT_FIND_ISSUER_NAME, &certInfo.Subject, NULL);
1180 ok(context != NULL, "CertFindCertificateInStore failed: %08x\n",
1181 GetLastError());
1182 if (context)
1183 {
1186 ok(context != NULL, "Expected more than one cert\n");
1187 if (context)
1188 {
1190 0, CERT_FIND_ISSUER_NAME, &certInfo.Subject, context);
1191 ok(context == NULL, "Expected precisely two certs\n");
1192 }
1193 }
1194
1195 /* Check second cert's there as well, by subject name */
1196 certInfo.Subject.pbData = subjectName2;
1197 certInfo.Subject.cbData = sizeof(subjectName2);
1199 CERT_FIND_SUBJECT_NAME, &certInfo.Subject, NULL);
1200 ok(context != NULL, "CertFindCertificateInStore failed: %08x\n",
1201 GetLastError());
1202 if (context)
1203 {
1206 ok(context == NULL, "Expected one cert only\n");
1207 }
1208
1209 /* Strange but true: searching for the subject cert requires you to set
1210 * the issuer, not the subject
1211 */
1213 CERT_FIND_SUBJECT_CERT, &certInfo, NULL);
1214 ok(context == NULL, "Expected no certificate\n");
1215 certInfo.Subject.pbData = NULL;
1216 certInfo.Subject.cbData = 0;
1217 certInfo.Issuer.pbData = subjectName2;
1218 certInfo.Issuer.cbData = sizeof(subjectName2);
1220 CERT_FIND_SUBJECT_CERT, &certInfo, NULL);
1221 ok(context != NULL, "CertFindCertificateInStore failed: %08x\n",
1222 GetLastError());
1223 if (context)
1224 {
1226 CERT_FIND_SUBJECT_CERT, &certInfo, context);
1227 ok(context == NULL, "Expected one cert only\n");
1228 }
1229 /* A non-matching serial number will not match. */
1230 certInfo.SerialNumber.pbData = otherSerialNumber;
1231 certInfo.SerialNumber.cbData = sizeof(otherSerialNumber);
1233 CERT_FIND_SUBJECT_CERT, &certInfo, NULL);
1234 ok(context == NULL, "Expected no match\n");
1235 /* No serial number will not match */
1236 certInfo.SerialNumber.cbData = 0;
1238 CERT_FIND_SUBJECT_CERT, &certInfo, NULL);
1239 ok(context == NULL, "Expected no match\n");
1240 /* A serial number still won't match if the name doesn't */
1241 certInfo.SerialNumber.pbData = serialNum;
1242 certInfo.SerialNumber.cbData = sizeof(serialNum);
1243 certInfo.Issuer.pbData = subjectName3;
1244 certInfo.Issuer.cbData = sizeof(subjectName3);
1246 CERT_FIND_SUBJECT_CERT, &certInfo, NULL);
1247 ok(context == NULL, "Expected no match\n");
1248
1249 /* The nice thing about hashes, they're unique */
1250 blob.pbData = bigCertHash;
1251 blob.cbData = sizeof(bigCertHash);
1254 ok(context != NULL, "CertFindCertificateInStore failed: %08x\n",
1255 GetLastError());
1256 if (context)
1257 {
1259 CERT_FIND_SHA1_HASH, &certInfo.Subject, context);
1260 ok(context == NULL, "Expected one cert only\n");
1261 }
1262
1263 /* Searching for NULL string matches any context. */
1264 count = 0;
1265 context = NULL;
1266 do {
1269 if (context)
1270 count++;
1271 } while (context);
1272 ok(count == 3, "expected 3 contexts\n");
1273 count = 0;
1274 context = NULL;
1275 do {
1278 if (context)
1279 count++;
1280 } while (context);
1281 ok(count == 2, "expected 2 contexts\n");
1282 count = 0;
1283 context = NULL;
1284 do {
1287 if (context)
1288 count++;
1289 } while (context);
1290 ok(count == 3, "expected 3 contexts\n");
1291 SetLastError(0xdeadbeef);
1293 CERT_FIND_ISSUER_STR, malcolm, NULL);
1294 ok(!context, "expected no certs\n");
1296 "expected CRYPT_E_NOT_FOUND, got %08x\n", GetLastError());
1297
1298 CertCloseStore(store, 0);
1299
1300 /* Another subject cert search, using iTunes's certs */
1305 ok(ret, "CertAddEncodedCertificateToStore failed: %08x\n",
1306 GetLastError());
1309 ok(ret, "CertAddEncodedCertificateToStore failed: %08x\n",
1310 GetLastError());
1313 ok(ret, "CertAddEncodedCertificateToStore failed: %08x\n",
1314 GetLastError());
1316 iTunesCert3, sizeof(iTunesCert3), CERT_STORE_ADD_NEW, &subject);
1317 ok(ret, "CertAddEncodedCertificateToStore failed: %08x\n",
1318 GetLastError());
1319
1320 /* The certInfo's issuer does not match any subject, but the serial
1321 * number does match a cert whose issuer matches certInfo's issuer.
1322 * This yields a match.
1323 */
1324 certInfo.SerialNumber.cbData = sizeof(iTunesSerialNum);
1326 certInfo.Issuer.cbData = sizeof(iTunesIssuer);
1327 certInfo.Issuer.pbData = iTunesIssuer;
1329 CERT_FIND_SUBJECT_CERT, &certInfo, NULL);
1330 ok(context != NULL, "Expected a match\n");
1331 if (context)
1332 {
1333 ret = CertCompareCertificateName(context->dwCertEncodingType,
1334 &certInfo.Issuer, &context->pCertInfo->Subject);
1335 ok(!ret, "Expected subject name not to match\n");
1336 ret = CertCompareCertificateName(context->dwCertEncodingType,
1337 &certInfo.Issuer, &context->pCertInfo->Issuer);
1338 ok(ret, "Expected issuer name to match\n");
1340 &context->pCertInfo->SerialNumber);
1341 ok(ret, "Expected serial number to match\n");
1343 CERT_FIND_SUBJECT_CERT, &certInfo, context);
1344 ok(context == NULL, "Expected one cert only\n");
1345 }
1346
1348 CERT_FIND_ISSUER_OF, subject, NULL);
1349 ok(context != NULL, "Expected an issuer\n");
1350 if (context)
1351 {
1354
1355 ok(!none, "Expected no parent of issuer\n");
1357 }
1359 CertCloseStore(store, 0);
1360}
PCCERT_CONTEXT WINAPI CertFindCertificateInStore(HCERTSTORE hCertStore, DWORD dwCertEncodingType, DWORD dwFlags, DWORD dwType, const void *pvPara, PCCERT_CONTEXT pPrevCertContext)
Definition: cert.c:1765
static BYTE iTunesSerialNum[]
Definition: cert.c:1127
static BYTE bigCertHash[]
Definition: cert.c:77
static BYTE subjectName3[]
Definition: cert.c:802
static const BYTE iTunesCert2[]
Definition: cert.c:941
static const BYTE iTunesCert3[]
Definition: cert.c:1024
static BYTE iTunesIssuer[]
Definition: cert.c:1110
static const BYTE iTunesCert0[]
Definition: cert.c:805
static const BYTE iTunesCert1[]
Definition: cert.c:871
static const WCHAR lang[]
Definition: wbemdisp.c:287
#define CERT_FIND_SUBJECT_CERT
Definition: wincrypt.h:2901
#define CERT_FIND_SUBJECT_NAME
Definition: wincrypt.h:2878
#define CERT_FIND_SHA1_HASH
Definition: wincrypt.h:2865
#define CERT_FIND_ISSUER_STR
Definition: wincrypt.h:2895
#define CERT_FIND_ISSUER_NAME
Definition: wincrypt.h:2882
#define CERT_FIND_ISSUER_OF
Definition: wincrypt.h:2903

Referenced by START_TEST().

◆ testGetIssuerCert()

static void testGetIssuerCert ( void  )
static

Definition at line 1562 of file cert.c.

1563{
1564 BOOL ret;
1566 DWORD flags = 0xffffffff, size;
1567 CERT_NAME_BLOB certsubject;
1568 BYTE *certencoded;
1569 WCHAR rootW[] = {'R', 'O', 'O', 'T', '\0'},
1570 certname[] = {'C', 'N', '=', 'd', 'u', 'm', 'm', 'y', ',', ' ', 'T', '=', 'T', 'e', 's', 't', '\0'};
1573
1574 ok(store != NULL, "CertOpenStore failed: %08x\n", GetLastError());
1575
1578 ok(ret, "CertAddEncodedCertificateToStore failed: %08x\n",
1579 GetLastError());
1580
1583 ok(ret, "CertAddEncodedCertificateToStore failed: %08x\n",
1584 GetLastError());
1585
1586 /* These crash:
1587 parent = CertGetIssuerCertificateFromStore(NULL, NULL, NULL, NULL);
1588 parent = CertGetIssuerCertificateFromStore(store, NULL, NULL, NULL);
1589 */
1592 "Expected E_INVALIDARG, got %08x\n", GetLastError());
1595 "Expected E_INVALIDARG, got %08x\n", GetLastError());
1598 "Expected E_INVALIDARG, got %08x\n", GetLastError());
1599 /* Confusing: the caller cannot set either of the
1600 * CERT_STORE_NO_*_FLAGs, as these are not checks,
1601 * they're results:
1602 */
1606 "Expected E_INVALIDARG, got %08x\n", GetLastError());
1607 /* Perform no checks */
1608 flags = 0;
1610 ok(parent != NULL, "CertGetIssuerCertificateFromStore failed: %08x\n",
1611 GetLastError());
1612 if (parent)
1614 /* Check revocation and signature only */
1617 ok(parent != NULL, "CertGetIssuerCertificateFromStore failed: %08x\n",
1618 GetLastError());
1619 /* Confusing: CERT_STORE_REVOCATION_FLAG succeeds when there is no CRL by
1620 * setting CERT_STORE_NO_CRL_FLAG.
1621 */
1623 "Expected CERT_STORE_REVOCATION_FLAG | CERT_STORE_NO_CRL_FLAG, got %08x\n",
1624 flags);
1625 if (parent)
1627 /* Checking time validity is not productive, because while most Windows
1628 * versions return 0 (time valid) because the child is not expired,
1629 * Windows 2003 SP1 returns that it is expired. Thus the range of
1630 * possibilities is covered, and a test verifies nothing.
1631 */
1632
1634 CertCloseStore(store, 0);
1635
1636 flags = 0;
1639 /* With only the child certificate, no issuer will be found */
1642 ok(ret, "CertAddEncodedCertificateToStore failed: %08x\n", GetLastError());
1644 ok(parent == NULL, "Expected no issuer\n");
1645 ok(GetLastError() == CRYPT_E_NOT_FOUND, "Expected CRYPT_E_NOT_FOUND, got %08X\n", GetLastError());
1646 /* Adding an issuer allows one (and only one) issuer to be found */
1649 ok(ret, "CertAddEncodedCertificateToStore failed: %08x\n", GetLastError());
1651 ok(parent == cert1, "Expected cert1 to be the issuer\n");
1653 ok(parent == NULL, "Expected only one issuer\n");
1654 ok(GetLastError() == CRYPT_E_NOT_FOUND, "Expected CRYPT_E_NOT_FOUND, got %08X\n", GetLastError());
1655 /* Adding a second issuer allows two issuers to be found - and the second
1656 * issuer is found before the first, implying certs are added to the head
1657 * of a list.
1658 */
1661 ok(ret, "CertAddEncodedCertificateToStore failed: %08x\n", GetLastError());
1663 ok(parent == cert2, "Expected cert2 to be the first issuer\n");
1665 ok(parent == cert1, "Expected cert1 to be the second issuer\n");
1667 ok(parent == NULL, "Expected no more than two issuers\n");
1668 ok(GetLastError() == CRYPT_E_NOT_FOUND, "Expected CRYPT_E_NOT_FOUND, got %08X\n", GetLastError());
1672 CertCloseStore(store, 0);
1673
1674 /* Repeat the test, reversing the order in which issuers are added,
1675 * to show it's order-dependent.
1676 */
1679 /* With only the child certificate, no issuer will be found */
1682 ok(ret, "CertAddEncodedCertificateToStore failed: %08x\n", GetLastError());
1684 ok(parent == NULL, "Expected no issuer\n");
1685 ok(GetLastError() == CRYPT_E_NOT_FOUND, "Expected CRYPT_E_NOT_FOUND, got %08X\n", GetLastError());
1686 /* Adding an issuer allows one (and only one) issuer to be found */
1689 ok(ret, "CertAddEncodedCertificateToStore failed: %08x\n", GetLastError());
1691 ok(parent == cert1, "Expected cert1 to be the issuer\n");
1693 ok(parent == NULL, "Expected only one issuer\n");
1694 ok(GetLastError() == CRYPT_E_NOT_FOUND, "Expected CRYPT_E_NOT_FOUND, got %08X\n", GetLastError());
1695 /* Adding a second issuer allows two issuers to be found - and the second
1696 * issuer is found before the first, implying certs are added to the head
1697 * of a list.
1698 */
1701 ok(ret, "CertAddEncodedCertificateToStore failed: %08x\n", GetLastError());
1703 ok(parent == cert2, "Expected cert2 to be the first issuer\n");
1705 ok(parent == cert1, "Expected cert1 to be the second issuer\n");
1707 ok(parent == NULL, "Expected no more than two issuers\n");
1708 ok(GetLastError() == CRYPT_E_NOT_FOUND, "Expected CRYPT_E_NOT_FOUND, got %08X\n", GetLastError());
1709
1710 /* Self-sign a certificate, add to the store and test getting the issuer */
1711 size = 0;
1713 "CertStrToName should have worked\n");
1714 certencoded = HeapAlloc(GetProcessHeap(), 0, size);
1715 ok(CertStrToNameW(X509_ASN_ENCODING, certname, CERT_X500_NAME_STR, NULL, certencoded, &size, NULL),
1716 "CertStrToName should have worked\n");
1717 certsubject.pbData = certencoded;
1718 certsubject.cbData = size;
1719 cert3 = CertCreateSelfSignCertificate(0, &certsubject, 0, NULL, NULL, NULL, NULL, NULL);
1720 ok(cert3 != NULL, "CertCreateSelfSignCertificate should have worked\n");
1722 ok(ret, "CertAddEncodedCertificateToStore failed: %08x\n", GetLastError());
1724 cert3 = CertEnumCertificatesInStore(store, NULL);
1725 ok(cert3 != NULL, "CertEnumCertificatesInStore should have worked\n");
1726 SetLastError(0xdeadbeef);
1727 flags = 0;
1729 ok(!parent, "Expected NULL\n");
1731 "Expected CRYPT_E_SELF_SIGNED, got %08X\n", GetLastError());
1735 CertCloseStore(store, 0);
1736 HeapFree(GetProcessHeap(), 0, certencoded);
1737
1738 /* Test root storage self-signed certificate */
1740 ok(store != NULL, "CertOpenStore failed: %08x\n", GetLastError());
1741 flags = 0;
1743 ok(cert1 != NULL, "CertEnumCertificatesInStore should have worked\n");
1744 SetLastError(0xdeadbeef);
1746 ok(!parent, "Expected NULL\n");
1748 "Expected CRYPT_E_SELF_SIGNED, got %08X\n", GetLastError());
1749 CertCloseStore(store, 0);
1750}
PCCERT_CONTEXT WINAPI CertGetIssuerCertificateFromStore(HCERTSTORE hCertStore, PCCERT_CONTEXT pSubjectContext, PCCERT_CONTEXT pPrevIssuerContext, DWORD *pdwFlags)
Definition: cert.c:1887
static const WCHAR rootW[]
Definition: chain.c:69
BOOL WINAPI CertStrToNameW(DWORD dwCertEncodingType, LPCWSTR pszX500, DWORD dwStrType, void *pvReserved, BYTE *pbEncoded, DWORD *pcbEncoded, LPCWSTR *ppszError)
Definition: str.c:1024
r parent
Definition: btrfs.c:3010
GLbitfield flags
Definition: glext.h:7161
static const BYTE chain10_1[]
Definition: cert.c:1503
static const BYTE childOfExpired[]
Definition: cert.c:1452
static const BYTE chain10_0[]
Definition: cert.c:1474
static const BYTE chain7_1[]
Definition: cert.c:1532
static const BYTE expiredCert[]
Definition: cert.c:1425
static const BYTE cert2[]
Definition: message.c:844
static const BYTE cert1[]
Definition: message.c:828
static HWND child
Definition: cursoricon.c:298
#define CERT_STORE_REVOCATION_FLAG
Definition: wincrypt.h:3460
#define CERT_X500_NAME_STR
Definition: wincrypt.h:3486
#define CERT_STORE_PROV_SYSTEM
Definition: wincrypt.h:2260
#define CERT_STORE_NO_ISSUER_FLAG
Definition: wincrypt.h:3462
#define CERT_STORE_NO_CRL_FLAG
Definition: wincrypt.h:3461
#define CERT_STORE_SIGNATURE_FLAG
Definition: wincrypt.h:3458
#define CERT_SYSTEM_STORE_CURRENT_USER
Definition: wincrypt.h:2324
#define CRYPT_E_SELF_SIGNED
Definition: winerror.h:3010

Referenced by START_TEST().

◆ testGetPublicKeyLength()

static void testGetPublicKeyLength ( void  )
static

Definition at line 3971 of file cert.c.

3972{
3973 static char oid_rsa_rsa[] = szOID_RSA_RSA;
3974 static char oid_rsa_dh[] = szOID_RSA_DH;
3975 static char bogusOID[] = "1.2.3";
3976 DWORD ret;
3977 CERT_PUBLIC_KEY_INFO info = { { 0 } };
3978 BYTE bogusKey[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
3979 BYTE key[] = { 0x30,0x0f,0x02,0x08,0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
3980 0x02,0x03,0x01,0x00,0x01 };
3981
3982 /* Crashes
3983 ret = CertGetPublicKeyLength(0, NULL);
3984 */
3985 /* With an empty public key info */
3986 SetLastError(0xdeadbeef);
3989 "Expected length 0 and ERROR_FILE_NOT_FOUND, got length %d, %08x\n",
3990 ret, GetLastError());
3991 SetLastError(0xdeadbeef);
3993 ok(ret == 0 &&
3995 GetLastError() == OSS_BAD_ARG), /* win9x */
3996 "Expected length 0 and CRYPT_E_ASN1_EOD, got length %d, %08x\n",
3997 ret, GetLastError());
3998 /* With a nearly-empty public key info */
3999 info.Algorithm.pszObjId = oid_rsa_rsa;
4000 SetLastError(0xdeadbeef);
4003 "Expected length 0 and ERROR_FILE_NOT_FOUND, got length %d, %08x\n",
4004 ret, GetLastError());
4005 SetLastError(0xdeadbeef);
4007 ok(ret == 0 &&
4009 GetLastError() == OSS_BAD_ARG), /* win9x */
4010 "Expected length 0 and CRYPT_E_ASN1_EOD, got length %d, %08x\n",
4011 ret, GetLastError());
4012 /* With a bogus key */
4013 info.PublicKey.cbData = sizeof(bogusKey);
4014 info.PublicKey.pbData = bogusKey;
4015 SetLastError(0xdeadbeef);
4018 "Expected length 0 and ERROR_FILE_NOT_FOUND, got length %d, %08x\n",
4019 ret, GetLastError());
4020 SetLastError(0xdeadbeef);
4022 ok(ret == 0 &&
4024 GetLastError() == OSS_PDU_MISMATCH), /* win9x */
4025 "Expected length 0 and CRYPT_E_ASN1_BADTAGTAG, got length %d, %08x\n",
4026 ret, GetLastError());
4027 /* With a believable RSA key but a bogus OID */
4028 info.Algorithm.pszObjId = bogusOID;
4029 info.PublicKey.cbData = sizeof(key);
4030 info.PublicKey.pbData = key;
4031 SetLastError(0xdeadbeef);
4034 "Expected length 0 and ERROR_FILE_NOT_FOUND, got length %d, %08x\n",
4035 ret, GetLastError());
4036 SetLastError(0xdeadbeef);
4038 ok(ret == 56 || broken(ret == 0 && GetLastError() == NTE_BAD_LEN) /* Win7 */,
4039 "Expected length 56, got %d\n", ret);
4040 /* An RSA key with the DH OID */
4041 info.Algorithm.pszObjId = oid_rsa_dh;
4042 SetLastError(0xdeadbeef);
4044 ok(ret == 0 &&
4046 GetLastError() == E_INVALIDARG), /* win9x */
4047 "Expected length 0 and CRYPT_E_ASN1_BADTAG, got length %d, %08x\n",
4048 ret, GetLastError());
4049 /* With the RSA OID */
4050 info.Algorithm.pszObjId = oid_rsa_rsa;
4051 SetLastError(0xdeadbeef);
4053 ok(ret == 56 || broken(ret == 0 && GetLastError() == NTE_BAD_LEN) /* Win7 */,
4054 "Expected length 56, got %d\n", ret);
4055 /* With the RSA OID and a message encoding */
4056 info.Algorithm.pszObjId = oid_rsa_rsa;
4057 SetLastError(0xdeadbeef);
4059 ok(ret == 56 || broken(ret == 0 && GetLastError() == NTE_BAD_LEN) /* Win7 */,
4060 "Expected length 56, got %d\n", ret);
4061}
DWORD WINAPI CertGetPublicKeyLength(DWORD dwCertEncodingType, PCERT_PUBLIC_KEY_INFO pPublicKey)
Definition: cert.c:1305
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
#define szOID_RSA_DH
Definition: wincrypt.h:3027
#define PKCS_7_ASN_ENCODING
Definition: wincrypt.h:2299
#define OSS_PDU_MISMATCH
Definition: winerror.h:3046
#define NTE_BAD_LEN
Definition: winerror.h:2872
#define OSS_BAD_ARG
Definition: winerror.h:3043

Referenced by START_TEST().

◆ testGetSubjectCert()

static void testGetSubjectCert ( void  )
static

Definition at line 1362 of file cert.c.

1363{
1364 HCERTSTORE store;
1365 PCCERT_CONTEXT context1, context2;
1366 CERT_INFO info = { 0 };
1367 BOOL ret;
1368
1371 ok(store != NULL, "CertOpenStore failed: %d\n", GetLastError());
1372 if (!store)
1373 return;
1374
1377 ok(ret || broken(GetLastError() == OSS_DATA_ERROR /* win98 */),
1378 "CertAddEncodedCertificateToStore failed: %08x\n", GetLastError());
1379 if (!ret && GetLastError() == OSS_DATA_ERROR)
1380 {
1381 skip("bigCert can't be decoded, skipping tests\n");
1382 return;
1383 }
1385 bigCert2, sizeof(bigCert2), CERT_STORE_ADD_NEW, &context1);
1386 ok(ret, "CertAddEncodedCertificateToStore failed: %08x\n",
1387 GetLastError());
1388 ok(context1 != NULL, "Expected a context\n");
1391 ok(ret, "CertAddEncodedCertificateToStore failed: %08x\n",
1392 GetLastError());
1393
1395 NULL);
1396 ok(!context2 && GetLastError() == E_INVALIDARG,
1397 "Expected E_INVALIDARG, got %08x\n", GetLastError());
1399 &info);
1400 ok(!context2 && GetLastError() == CRYPT_E_NOT_FOUND,
1401 "Expected CRYPT_E_NOT_FOUND, got %08x\n", GetLastError());
1402 info.SerialNumber.cbData = sizeof(serialNum);
1403 info.SerialNumber.pbData = serialNum;
1405 &info);
1406 ok(!context2 && GetLastError() == CRYPT_E_NOT_FOUND,
1407 "Expected CRYPT_E_NOT_FOUND, got %08x\n", GetLastError());
1408 info.Issuer.cbData = sizeof(subjectName2);
1409 info.Issuer.pbData = subjectName2;
1411 &info);
1412 ok(context2 != NULL,
1413 "CertGetSubjectCertificateFromStore failed: %08x\n", GetLastError());
1414 /* Not only should this find a context, but it should be the same
1415 * (same address) as context1.
1416 */
1417 ok(context1 == context2, "Expected identical context addresses\n");
1419
1421 CertCloseStore(store, 0);
1422}
PCCERT_CONTEXT WINAPI CertGetSubjectCertificateFromStore(HCERTSTORE hCertStore, DWORD dwCertEncodingType, PCERT_INFO pCertId)
Definition: cert.c:1831

Referenced by START_TEST().

◆ testGetValidUsages()

static void testGetValidUsages ( void  )
static

Definition at line 2804 of file cert.c.

2805{
2806 static const LPCSTR expectedOIDs[] = {
2807 "1.3.6.1.5.5.7.3.3",
2808 "1.3.6.1.5.5.7.3.2",
2809 "1.2.840.113549.1.1.1",
2810 };
2811 static const LPCSTR expectedOIDs2[] = {
2812 "1.3.6.1.5.5.7.3.2",
2813 "1.2.840.113549.1.1.1",
2814 };
2815 BOOL ret;
2816 int numOIDs;
2817 DWORD size;
2818 LPSTR *oids = NULL;
2819 PCCERT_CONTEXT contexts[3];
2820
2821 if (!pCertGetValidUsages)
2822 {
2823 win_skip("CertGetValidUsages() is not available\n");
2824 return;
2825 }
2826
2827 /* Crash
2828 ret = pCertGetValidUsages(0, NULL, NULL, NULL, NULL);
2829 ret = pCertGetValidUsages(0, NULL, NULL, NULL, &size);
2830 */
2831 contexts[0] = NULL;
2832 numOIDs = size = 0xdeadbeef;
2833 SetLastError(0xdeadbeef);
2834 ret = pCertGetValidUsages(1, &contexts[0], &numOIDs, NULL, &size);
2835 ok(ret, "CertGetValidUsages failed: %d\n", GetLastError());
2836 ok(numOIDs == -1, "Expected -1, got %d\n", numOIDs);
2837 ok(size == 0, "Expected size 0, got %d\n", size);
2839 sizeof(bigCert));
2841 sizeof(certWithUsage));
2844 numOIDs = size = 0xdeadbeef;
2845 ret = pCertGetValidUsages(0, NULL, &numOIDs, NULL, &size);
2846 ok(ret, "CertGetValidUsages failed: %08x\n", GetLastError());
2847 ok(numOIDs == -1, "Expected -1, got %d\n", numOIDs);
2848 ok(size == 0, "Expected size 0, got %d\n", size);
2849 numOIDs = size = 0xdeadbeef;
2850 ret = pCertGetValidUsages(1, contexts, &numOIDs, NULL, &size);
2851 ok(ret, "CertGetValidUsages failed: %08x\n", GetLastError());
2852 ok(numOIDs == -1, "Expected -1, got %d\n", numOIDs);
2853 ok(size == 0, "Expected size 0, got %d\n", size);
2854 ret = pCertGetValidUsages(1, &contexts[1], &numOIDs, NULL, &size);
2855 ok(ret, "CertGetValidUsages failed: %08x\n", GetLastError());
2856 ok(numOIDs == 3, "Expected 3, got %d\n", numOIDs);
2857 ok(size, "Expected non-zero size\n");
2858 oids = HeapAlloc(GetProcessHeap(), 0, size);
2859 if (oids)
2860 {
2861 int i;
2862 DWORD smallSize = 1;
2863
2864 SetLastError(0xdeadbeef);
2865 ret = pCertGetValidUsages(1, &contexts[1], &numOIDs, oids, &smallSize);
2867 "Expected ERROR_MORE_DATA, got %d\n", GetLastError());
2868 ret = pCertGetValidUsages(1, &contexts[1], &numOIDs, oids, &size);
2869 ok(ret, "CertGetValidUsages failed: %08x\n", GetLastError());
2870 for (i = 0; i < numOIDs; i++)
2871 ok(!lstrcmpA(oids[i], expectedOIDs[i]), "unexpected OID %s\n",
2872 oids[i]);
2873 HeapFree(GetProcessHeap(), 0, oids);
2874 }
2875 numOIDs = 0xdeadbeef;
2876 /* Oddly enough, this crashes when the number of contexts is not 1:
2877 ret = pCertGetValidUsages(2, contexts, &numOIDs, NULL, &size);
2878 * but setting size to 0 allows it to succeed:
2879 */
2880 size = 0;
2881 ret = pCertGetValidUsages(2, contexts, &numOIDs, NULL, &size);
2882 ok(ret, "CertGetValidUsages failed: %08x\n", GetLastError());
2883 ok(numOIDs == 3, "Expected 3, got %d\n", numOIDs);
2884 ok(size, "Expected non-zero size\n");
2885 oids = HeapAlloc(GetProcessHeap(), 0, size);
2886 if (oids)
2887 {
2888 int i;
2889
2890 ret = pCertGetValidUsages(1, &contexts[1], &numOIDs, oids, &size);
2891 ok(ret, "CertGetValidUsages failed: %08x\n", GetLastError());
2892 for (i = 0; i < numOIDs; i++)
2893 ok(!lstrcmpA(oids[i], expectedOIDs[i]), "unexpected OID %s\n",
2894 oids[i]);
2895 HeapFree(GetProcessHeap(), 0, oids);
2896 }
2897 numOIDs = 0xdeadbeef;
2898 size = 0;
2899 ret = pCertGetValidUsages(1, &contexts[2], &numOIDs, NULL, &size);
2900 ok(ret, "CertGetValidUsages failed: %08x\n", GetLastError());
2901 ok(numOIDs == 2, "Expected 2, got %d\n", numOIDs);
2902 ok(size, "Expected non-zero size\n");
2903 oids = HeapAlloc(GetProcessHeap(), 0, size);
2904 if (oids)
2905 {
2906 int i;
2907
2908 ret = pCertGetValidUsages(1, &contexts[2], &numOIDs, oids, &size);
2909 ok(ret, "CertGetValidUsages failed: %08x\n", GetLastError());
2910 for (i = 0; i < numOIDs; i++)
2911 ok(!lstrcmpA(oids[i], expectedOIDs2[i]), "unexpected OID %s\n",
2912 oids[i]);
2913 HeapFree(GetProcessHeap(), 0, oids);
2914 }
2915 numOIDs = 0xdeadbeef;
2916 size = 0;
2917 ret = pCertGetValidUsages(3, contexts, &numOIDs, NULL, &size);
2918 ok(ret, "CertGetValidUsages failed: %08x\n", GetLastError());
2919 ok(numOIDs == 2, "Expected 2, got %d\n", numOIDs);
2920 ok(size, "Expected non-zero size\n");
2921 oids = HeapAlloc(GetProcessHeap(), 0, size);
2922 if (oids)
2923 {
2924 int i;
2925
2926 ret = pCertGetValidUsages(3, contexts, &numOIDs, oids, &size);
2927 ok(ret, "CertGetValidUsages failed: %08x\n", GetLastError());
2928 for (i = 0; i < numOIDs; i++)
2929 ok(!lstrcmpA(oids[i], expectedOIDs2[i]), "unexpected OID %s\n",
2930 oids[i]);
2931 HeapFree(GetProcessHeap(), 0, oids);
2932 }
2933 CertFreeCertificateContext(contexts[0]);
2934 CertFreeCertificateContext(contexts[1]);
2935 CertFreeCertificateContext(contexts[2]);
2936}
#define ERROR_MORE_DATA
Definition: dderror.h:13
int WINAPI lstrcmpA(LPCSTR str1, LPCSTR str2)
Definition: locale.c:4194
static const BYTE cert2WithUsage[]
Definition: cert.c:2792
const char * LPCSTR
Definition: xmlstorage.h:183
char * LPSTR
Definition: xmlstorage.h:182

Referenced by START_TEST().

◆ testHashPublicKeyInfo()

static void testHashPublicKeyInfo ( void  )
static

Definition at line 3322 of file cert.c.

3323{
3324 BOOL ret;
3325 CERT_PUBLIC_KEY_INFO info = { { 0 } };
3326 DWORD len;
3327
3328 /* Crash
3329 ret = CryptHashPublicKeyInfo(0, 0, 0, 0, NULL, NULL, NULL);
3330 ret = CryptHashPublicKeyInfo(0, 0, 0, 0, &info, NULL, NULL);
3331 */
3332 ret = CryptHashPublicKeyInfo(0, 0, 0, 0, NULL, NULL, &len);
3334 "Expected ERROR_FILE_NOT_FOUND, got %08x\n", GetLastError());
3335 /* Crashes on some win9x boxes */
3336 if (0)
3337 {
3340 "Expected STATUS_ACCESS_VIOLATION, got %08x\n", GetLastError());
3341 }
3343 ok(ret ||
3344 broken(!ret), /* win9x */
3345 "CryptHashPublicKeyInfo failed: %08x\n", GetLastError());
3346 if (ret)
3347 {
3348 ok(len == 16, "Expected hash size 16, got %d\n", len);
3349 if (len == 16)
3350 {
3351 static const BYTE emptyHash[] = { 0xb8,0x51,0x3a,0x31,0x0e,0x9f,0x40,
3352 0x36,0x9c,0x92,0x45,0x1b,0x9d,0xc8,0xf9,0xf6 };
3353 BYTE buf[16];
3354
3356 &len);
3357 ok(ret, "CryptHashPublicKeyInfo failed: %08x\n", GetLastError());
3358 ok(!memcmp(buf, emptyHash, len), "Unexpected hash\n");
3359 }
3360 }
3361}
BOOL WINAPI CryptHashPublicKeyInfo(HCRYPTPROV_LEGACY hCryptProv, ALG_ID Algid, DWORD dwFlags, DWORD dwCertEncodingType, PCERT_PUBLIC_KEY_INFO pInfo, BYTE *pbComputedHash, DWORD *pcbComputedHash)
Definition: cert.c:2216
GLenum GLsizei len
Definition: glext.h:6722

Referenced by START_TEST().

◆ testHashToBeSigned()

static void testHashToBeSigned ( void  )
static

Definition at line 3366 of file cert.c.

3367{
3368 BOOL ret;
3369 DWORD size;
3370 BYTE hash[16];
3371
3372 /* Crash */
3373 if (0)
3374 {
3375 CryptHashToBeSigned(0, 0, NULL, 0, NULL, NULL);
3376 }
3377 SetLastError(0xdeadbeef);
3378 ret = CryptHashToBeSigned(0, 0, NULL, 0, NULL, &size);
3380 "expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
3381 SetLastError(0xdeadbeef);
3383 ok(!ret &&
3385 GetLastError() == OSS_BAD_ARG), /* win9x */
3386 "expected CRYPT_E_ASN1_EOD, got %08x\n", GetLastError());
3387 /* Can't sign anything: has to be asn.1 encoded, at least */
3388 SetLastError(0xdeadbeef);
3390 NULL, &size);
3391 ok(!ret &&
3393 GetLastError() == OSS_MORE_INPUT), /* win9x */
3394 "expected CRYPT_E_ASN1_BADTAG, got %08x\n", GetLastError());
3395 /* Can't be empty, either */
3396 SetLastError(0xdeadbeef);
3398 sizeof(emptyCert), NULL, &size);
3399 ok(!ret &&
3401 GetLastError() == OSS_DATA_ERROR), /* win9x */
3402 "expected CRYPT_E_ASN1_CORRUPT, got %08x\n", GetLastError());
3403 /* Signing a cert works */
3405 sizeof(md5SignedEmptyCert), NULL, &size);
3406 ok(ret ||
3407 broken(!ret), /* win9x */
3408 "CryptHashToBeSigned failed: %08x\n", GetLastError());
3409 if (ret)
3410 {
3411 ok(size == sizeof(md5SignedEmptyCertHash), "unexpected size %d\n", size);
3412 }
3413
3415 sizeof(md5SignedEmptyCert), hash, &size);
3416 ok(ret || broken(!ret && GetLastError() == NTE_BAD_ALGID) /* NT4 */,
3417 "CryptHashToBeSigned failed: %08x\n", GetLastError());
3418
3419 ok(!memcmp(hash, md5SignedEmptyCertHash, size), "unexpected value\n");
3420}
BOOL WINAPI CryptHashToBeSigned(HCRYPTPROV_LEGACY hCryptProv, DWORD dwCertEncodingType, const BYTE *pbEncoded, DWORD cbEncoded, BYTE *pbComputedHash, DWORD *pcbComputedHash)
Definition: cert.c:2260
static BYTE int1[]
Definition: cert.c:3154
static const BYTE md5SignedEmptyCertHash[]
Definition: cert.c:3363
static const BYTE md5SignedEmptyCert[]
Definition: cert.c:2074
#define NTE_BAD_ALGID
Definition: winerror.h:2876
#define CRYPT_E_ASN1_CORRUPT
Definition: winerror.h:3087

Referenced by START_TEST().

◆ testIntendedKeyUsage()

static void testIntendedKeyUsage ( void  )
static

Definition at line 2459 of file cert.c.

2460{
2461 BOOL ret;
2462 CERT_INFO info = { 0 };
2463 static char oid_key_usage[] = szOID_KEY_USAGE;
2464 /* A couple "key usages". Really they're just encoded bits which aren't
2465 * necessarily restricted to the defined key usage values.
2466 */
2467 static BYTE usage1[] = { 0x03,0x03,0x00,0xff,0xff };
2468 static BYTE usage2[] = { 0x03,0x03,0x01,0xff,0xfe };
2469 static const BYTE expected_usage1[] = { 0xff,0xff,0x00,0x00 };
2470 static const BYTE expected_usage2[] = { 0xff,0xfe,0x00,0x00 };
2471 CERT_EXTENSION ext = { oid_key_usage, TRUE, { sizeof(usage1), usage1 } };
2472 BYTE usage_bytes[4];
2473
2474 if (0)
2475 {
2476 /* Crash */
2478 }
2480 ok(!ret, "expected failure\n");
2481 ret = CertGetIntendedKeyUsage(0, &info, usage_bytes, sizeof(usage_bytes));
2482 ok(!ret, "expected failure\n");
2484 ok(!ret, "expected failure\n");
2486 sizeof(usage_bytes));
2487 ok(!ret, "expected failure\n");
2488 info.cExtension = 1;
2489 info.rgExtension = &ext;
2491 ok(!ret, "expected failure\n");
2492 /* The unused bytes are filled with 0. */
2494 sizeof(usage_bytes));
2495 ok(ret, "CertGetIntendedKeyUsage failed: %08x\n", GetLastError());
2496 ok(!memcmp(usage_bytes, expected_usage1, sizeof(expected_usage1)),
2497 "unexpected value\n");
2498 /* The usage bytes are copied in big-endian order. */
2499 ext.Value.cbData = sizeof(usage2);
2500 ext.Value.pbData = usage2;
2502 sizeof(usage_bytes));
2503 ok(ret, "CertGetIntendedKeyUsage failed: %08x\n", GetLastError());
2504 ok(!memcmp(usage_bytes, expected_usage2, sizeof(expected_usage2)),
2505 "unexpected value\n");
2506}
#define TRUE
Definition: types.h:120
BOOL WINAPI CertGetIntendedKeyUsage(DWORD dwCertEncodingType, PCERT_INFO pCertInfo, BYTE *pbKeyUsage, DWORD cbKeyUsage)
Definition: cert.c:2810
static const WCHAR *const ext[]
Definition: module.c:53
#define szOID_KEY_USAGE
Definition: wincrypt.h:3185

Referenced by START_TEST().

◆ testIsRDNAttrsInCertificateName()

static void testIsRDNAttrsInCertificateName ( void  )
static

Definition at line 3031 of file cert.c.

3032{
3033 static char oid_1_2_3[] = "1.2.3";
3034 static char oid_common_name[] = szOID_COMMON_NAME;
3035 static char oid_organization[] = szOID_ORGANIZATION_NAME;
3036 static char juan[] = "Juan Lang";
3037 static char juan_with_leading_space[] = " Juan Lang";
3038 static char juan_with_intermediate_space[] = "Juan Lang";
3039 static char juan_with_trailing_space[] = "Juan Lang ";
3040 static char juan_lower_case[] = "juan lang";
3041 static WCHAR juanW[] = { 'J','u','a','n',' ','L','a','n','g',0 };
3042 static char the_wine_project[] = "The Wine Project";
3043 BOOL ret;
3046 CERT_RDN rdn = { 0, NULL };
3047
3048 name.cbData = sizeof(cn);
3049 name.pbData = cn;
3050 if (0)
3051 {
3052 /* Crash */
3055 }
3056 SetLastError(0xdeadbeef);
3059 "expected ERROR_FILE_NOT_FOUND, got %08x\n", GetLastError());
3061 ok(ret, "CertIsRDNAttrsInCertificateName failed: %08x\n", GetLastError());
3062 attr[0].pszObjId = oid_1_2_3;
3063 rdn.rgRDNAttr = attr;
3064 rdn.cRDNAttr = 1;
3065 SetLastError(0xdeadbeef);
3068 "expected CRYPT_E_NO_MATCH, got %08x\n", GetLastError());
3069 attr[0].pszObjId = oid_common_name;
3070 attr[0].dwValueType = CERT_RDN_PRINTABLE_STRING;
3071 attr[0].Value.cbData = strlen(juan);
3072 attr[0].Value.pbData = (BYTE *)juan;
3074 ok(ret, "CertIsRDNAttrsInCertificateName failed: %08x\n", GetLastError());
3075 /* Again, spaces are not removed for name comparison. */
3076 attr[0].Value.cbData = strlen(juan_with_leading_space);
3077 attr[0].Value.pbData = (BYTE *)juan_with_leading_space;
3078 SetLastError(0xdeadbeef);
3081 "expected CRYPT_E_NO_MATCH, got %08x\n", GetLastError());
3082 attr[0].Value.cbData = strlen(juan_with_intermediate_space);
3083 attr[0].Value.pbData = (BYTE *)juan_with_intermediate_space;
3084 SetLastError(0xdeadbeef);
3087 "expected CRYPT_E_NO_MATCH, got %08x\n", GetLastError());
3088 attr[0].Value.cbData = strlen(juan_with_trailing_space);
3089 attr[0].Value.pbData = (BYTE *)juan_with_trailing_space;
3090 SetLastError(0xdeadbeef);
3093 "expected CRYPT_E_NO_MATCH, got %08x\n", GetLastError());
3094 /* The lower case name isn't matched unless a case insensitive match is
3095 * specified.
3096 */
3097 attr[0].Value.cbData = strlen(juan_lower_case);
3098 attr[0].Value.pbData = (BYTE *)juan_lower_case;
3099 SetLastError(0xdeadbeef);
3102 "expected CRYPT_E_NO_MATCH, got %08x\n", GetLastError());
3105 ok(ret ||
3106 broken(!ret && GetLastError() == CRYPT_E_NO_MATCH), /* Older crypt32 */
3107 "CertIsRDNAttrsInCertificateName failed: %08x\n", GetLastError());
3108 /* The values don't match unless they have the same RDN type */
3109 attr[0].dwValueType = CERT_RDN_UNICODE_STRING;
3110 attr[0].Value.cbData = lstrlenW(juanW) * sizeof(WCHAR);
3111 attr[0].Value.pbData = (BYTE *)juanW;
3112 SetLastError(0xdeadbeef);
3115 "expected CRYPT_E_NO_MATCH, got %08x\n", GetLastError());
3116 SetLastError(0xdeadbeef);
3120 "expected CRYPT_E_NO_MATCH, got %08x\n", GetLastError());
3121 attr[0].dwValueType = CERT_RDN_IA5_STRING;
3122 attr[0].Value.cbData = strlen(juan);
3123 attr[0].Value.pbData = (BYTE *)juan;
3124 SetLastError(0xdeadbeef);
3127 "expected CRYPT_E_NO_MATCH, got %08x\n", GetLastError());
3128 /* All attributes must be present */
3129 attr[0].dwValueType = CERT_RDN_PRINTABLE_STRING;
3130 attr[0].Value.cbData = strlen(juan);
3131 attr[0].Value.pbData = (BYTE *)juan;
3132 attr[1].pszObjId = oid_organization;
3133 attr[1].dwValueType = CERT_RDN_PRINTABLE_STRING;
3134 attr[1].Value.cbData = strlen(the_wine_project);
3135 attr[1].Value.pbData = (BYTE *)the_wine_project;
3136 rdn.cRDNAttr = 2;
3137 SetLastError(0xdeadbeef);
3140 "expected CRYPT_E_NO_MATCH, got %08x\n", GetLastError());
3141 /* Order also matters */
3142 name.pbData = cnThenO;
3143 name.cbData = sizeof(cnThenO);
3145 ok(ret, "CertIsRDNAttrsInCertificateName failed: %08x\n", GetLastError());
3146 name.pbData = oThenCN;
3147 name.cbData = sizeof(oThenCN);
3148 SetLastError(0xdeadbeef);
3151 "expected CRYPT_E_NO_MATCH, got %08x\n", GetLastError());
3152}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
BOOL WINAPI CertIsRDNAttrsInCertificateName(DWORD dwCertEncodingType, DWORD dwFlags, PCERT_NAME_BLOB pCertName, PCERT_RDN pRDN)
Definition: cert.c:2131
#define lstrlenW
Definition: compat.h:750
DWORD cRDNAttr
Definition: wincrypt.h:262
PCERT_RDN_ATTR rgRDNAttr
Definition: wincrypt.h:263
Definition: cookie.c:202
#define CERT_RDN_IA5_STRING
Definition: wincrypt.h:2784
#define CERT_RDN_PRINTABLE_STRING
Definition: wincrypt.h:2780
#define CERT_CASE_INSENSITIVE_IS_RDN_ATTRS_FLAG
Definition: wincrypt.h:2807
#define CERT_UNICODE_IS_RDN_ATTRS_FLAG
Definition: wincrypt.h:2806
#define szOID_COMMON_NAME
Definition: wincrypt.h:3134
#define CERT_RDN_UNICODE_STRING
Definition: wincrypt.h:2792
#define szOID_ORGANIZATION_NAME
Definition: wincrypt.h:3141
#define CRYPT_E_NO_MATCH
Definition: winerror.h:3012

Referenced by START_TEST().

◆ testKeyUsage()

static void testKeyUsage ( void  )
static

Definition at line 2511 of file cert.c.

2512{
2513 BOOL ret;
2515 DWORD size;
2516
2517 /* Test base cases */
2520 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
2521 size = 1;
2524 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
2525 size = 0;
2528 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
2529 /* These crash
2530 ret = CertSetEnhancedKeyUsage(NULL, NULL);
2531 usage.cUsageIdentifier = 0;
2532 ret = CertSetEnhancedKeyUsage(NULL, &usage);
2533 */
2534 /* Test with a cert with no enhanced key usage extension */
2536 sizeof(bigCert));
2537 ok(context != NULL, "CertCreateCertificateContext failed: %08x\n",
2538 GetLastError());
2539 if (context)
2540 {
2541 static const char oid[] = "1.2.3.4";
2542 BYTE buf[sizeof(CERT_ENHKEY_USAGE) + 2 * (sizeof(LPSTR) + sizeof(oid))];
2544
2547 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
2548 size = 1;
2550 if (ret)
2551 {
2552 /* Windows 2000, ME, or later: even though it succeeded, we expect
2553 * CRYPT_E_NOT_FOUND, which indicates there is no enhanced key
2554 * usage set for this cert (which implies it's valid for all uses.)
2555 */
2557 "Expected CRYPT_E_NOT_FOUND, got %08x\n", GetLastError());
2558 ok(size == sizeof(CERT_ENHKEY_USAGE), "Wrong size %d\n", size);
2559 ret = CertGetEnhancedKeyUsage(context, 0, pUsage, &size);
2560 ok(ret, "CertGetEnhancedKeyUsage failed: %08x\n", GetLastError());
2561 ok(pUsage->cUsageIdentifier == 0, "Expected 0 usages, got %d\n",
2562 pUsage->cUsageIdentifier);
2563 }
2564 else
2565 {
2566 /* Windows NT, 95, or 98: it fails, and the last error is
2567 * CRYPT_E_NOT_FOUND.
2568 */
2570 "Expected CRYPT_E_NOT_FOUND, got %08x\n", GetLastError());
2571 }
2572 /* I can add a usage identifier when no key usage has been set */
2574 ok(ret, "CertAddEnhancedKeyUsageIdentifier failed: %08x\n",
2575 GetLastError());
2576 size = sizeof(buf);
2579 ok(ret && GetLastError() == 0,
2580 "CertGetEnhancedKeyUsage failed: %08x\n", GetLastError());
2581 ok(pUsage->cUsageIdentifier == 1, "Expected 1 usage, got %d\n",
2582 pUsage->cUsageIdentifier);
2583 if (pUsage->cUsageIdentifier)
2584 ok(!strcmp(pUsage->rgpszUsageIdentifier[0], oid),
2585 "Expected %s, got %s\n", oid, pUsage->rgpszUsageIdentifier[0]);
2586 /* Now set an empty key usage */
2587 pUsage->cUsageIdentifier = 0;
2589 ok(ret, "CertSetEnhancedKeyUsage failed: %08x\n", GetLastError());
2590 /* Shouldn't find it in the cert */
2591 size = sizeof(buf);
2595 "Expected CRYPT_E_NOT_FOUND, got %08x\n", GetLastError());
2596 /* Should find it as an extended property */
2599 ok(ret && GetLastError() == 0,
2600 "CertGetEnhancedKeyUsage failed: %08x\n", GetLastError());
2601 ok(pUsage->cUsageIdentifier == 0, "Expected 0 usages, got %d\n",
2602 pUsage->cUsageIdentifier);
2603 /* Should find it as either */
2604 ret = CertGetEnhancedKeyUsage(context, 0, pUsage, &size);
2605 ok(ret && GetLastError() == 0,
2606 "CertGetEnhancedKeyUsage failed: %08x\n", GetLastError());
2607 ok(pUsage->cUsageIdentifier == 0, "Expected 0 usages, got %d\n",
2608 pUsage->cUsageIdentifier);
2609 /* Add a usage identifier */
2611 ok(ret, "CertAddEnhancedKeyUsageIdentifier failed: %08x\n",
2612 GetLastError());
2613 size = sizeof(buf);
2614 ret = CertGetEnhancedKeyUsage(context, 0, pUsage, &size);
2615 ok(ret && GetLastError() == 0,
2616 "CertGetEnhancedKeyUsage failed: %08x\n", GetLastError());
2617 ok(pUsage->cUsageIdentifier == 1, "Expected 1 identifier, got %d\n",
2618 pUsage->cUsageIdentifier);
2619 if (pUsage->cUsageIdentifier)
2620 ok(!strcmp(pUsage->rgpszUsageIdentifier[0], oid),
2621 "Expected %s, got %s\n", oid, pUsage->rgpszUsageIdentifier[0]);
2622 /* Re-adding the same usage identifier succeeds, though it only adds
2623 * a duplicate usage identifier on versions prior to Vista
2624 */
2626 ok(ret, "CertAddEnhancedKeyUsageIdentifier failed: %08x\n",
2627 GetLastError());
2628 size = sizeof(buf);
2629 ret = CertGetEnhancedKeyUsage(context, 0, pUsage, &size);
2630 ok(ret && GetLastError() == 0,
2631 "CertGetEnhancedKeyUsage failed: %08x\n", GetLastError());
2632 ok(pUsage->cUsageIdentifier == 1 || pUsage->cUsageIdentifier == 2,
2633 "Expected 1 or 2 identifiers, got %d\n", pUsage->cUsageIdentifier);
2634 if (pUsage->cUsageIdentifier)
2635 ok(!strcmp(pUsage->rgpszUsageIdentifier[0], oid),
2636 "Expected %s, got %s\n", oid, pUsage->rgpszUsageIdentifier[0]);
2637 if (pUsage->cUsageIdentifier >= 2)
2638 ok(!strcmp(pUsage->rgpszUsageIdentifier[1], oid),
2639 "Expected %s, got %s\n", oid, pUsage->rgpszUsageIdentifier[1]);
2640 /* Now set a NULL extended property--this deletes the property. */
2642 ok(ret, "CertSetEnhancedKeyUsage failed: %08x\n", GetLastError());
2643 SetLastError(0xbaadcafe);
2644 size = sizeof(buf);
2645 ret = CertGetEnhancedKeyUsage(context, 0, pUsage, &size);
2646 ok(ret || broken(!ret && GetLastError() == CRYPT_E_NOT_FOUND /* NT4 */),
2647 "CertGetEnhancedKeyUsage failed: %08x\n", GetLastError());
2649 "Expected CRYPT_E_NOT_FOUND, got %08x\n", GetLastError());
2650
2652 }
2653 /* Now test with a cert with an enhanced key usage extension */
2655 sizeof(certWithUsage));
2656 ok(context != NULL, "CertCreateCertificateContext failed: %08x\n",
2657 GetLastError());
2658 if (context)
2659 {
2660 LPBYTE buf = NULL;
2661 DWORD bufSize = 0, i;
2662
2663 /* The size may depend on what flags are used to query it, so I
2664 * realloc the buffer for each test.
2665 */
2668 ok(ret, "CertGetEnhancedKeyUsage failed: %08x\n", GetLastError());
2670 if (buf)
2671 {
2673
2674 /* Should find it in the cert */
2675 size = bufSize;
2678 ok(ret && GetLastError() == 0,
2679 "CertGetEnhancedKeyUsage failed: %08x\n", GetLastError());
2680 ok(pUsage->cUsageIdentifier == 3, "Expected 3 usages, got %d\n",
2681 pUsage->cUsageIdentifier);
2682 for (i = 0; i < pUsage->cUsageIdentifier; i++)
2684 "Expected %s, got %s\n", keyUsages[i],
2685 pUsage->rgpszUsageIdentifier[i]);
2687 }
2689 ok(ret, "CertGetEnhancedKeyUsage failed: %08x\n", GetLastError());
2691 if (buf)
2692 {
2694
2695 /* Should find it as either */
2696 size = bufSize;
2697 ret = CertGetEnhancedKeyUsage(context, 0, pUsage, &size);
2698 /* In Windows, GetLastError returns CRYPT_E_NOT_FOUND not found
2699 * here, even though the return is successful and the usage id
2700 * count is positive. I don't enforce that here.
2701 */
2702 ok(ret,
2703 "CertGetEnhancedKeyUsage failed: %08x\n", GetLastError());
2704 ok(pUsage->cUsageIdentifier == 3, "Expected 3 usages, got %d\n",
2705 pUsage->cUsageIdentifier);
2706 for (i = 0; i < pUsage->cUsageIdentifier; i++)
2708 "Expected %s, got %s\n", keyUsages[i],
2709 pUsage->rgpszUsageIdentifier[i]);
2711 }
2712 /* Shouldn't find it as an extended property */
2716 "Expected CRYPT_E_NOT_FOUND, got %08x\n", GetLastError());
2717 /* Adding a usage identifier overrides the cert's usage!? */
2719 ok(ret, "CertAddEnhancedKeyUsageIdentifier failed: %08x\n",
2720 GetLastError());
2722 ok(ret, "CertGetEnhancedKeyUsage failed: %08x\n", GetLastError());
2724 if (buf)
2725 {
2727
2728 /* Should find it as either */
2729 size = bufSize;
2730 ret = CertGetEnhancedKeyUsage(context, 0, pUsage, &size);
2731 ok(ret,
2732 "CertGetEnhancedKeyUsage failed: %08x\n", GetLastError());
2733 ok(pUsage->cUsageIdentifier == 1, "Expected 1 usage, got %d\n",
2734 pUsage->cUsageIdentifier);
2736 "Expected %s, got %s\n", szOID_RSA_RSA,
2737 pUsage->rgpszUsageIdentifier[0]);
2739 }
2740 /* But querying the cert directly returns its usage */
2743 ok(ret, "CertGetEnhancedKeyUsage failed: %08x\n", GetLastError());
2745 if (buf)
2746 {
2748
2749 size = bufSize;
2752 ok(ret,
2753 "CertGetEnhancedKeyUsage failed: %08x\n", GetLastError());
2754 ok(pUsage->cUsageIdentifier == 3, "Expected 3 usages, got %d\n",
2755 pUsage->cUsageIdentifier);
2756 for (i = 0; i < pUsage->cUsageIdentifier; i++)
2758 "Expected %s, got %s\n", keyUsages[i],
2759 pUsage->rgpszUsageIdentifier[i]);
2761 }
2762 /* And removing the only usage identifier in the extended property
2763 * results in the cert's key usage being found.
2764 */
2766 ok(ret, "CertRemoveEnhancedKeyUsage failed: %08x\n", GetLastError());
2768 ok(ret, "CertGetEnhancedKeyUsage failed: %08x\n", GetLastError());
2770 if (buf)
2771 {
2773
2774 /* Should find it as either */
2775 size = bufSize;
2776 ret = CertGetEnhancedKeyUsage(context, 0, pUsage, &size);
2777 ok(ret,
2778 "CertGetEnhancedKeyUsage failed: %08x\n", GetLastError());
2779 ok(pUsage->cUsageIdentifier == 3, "Expected 3 usages, got %d\n",
2780 pUsage->cUsageIdentifier);
2781 for (i = 0; i < pUsage->cUsageIdentifier; i++)
2783 "Expected %s, got %s\n", keyUsages[i],
2784 pUsage->rgpszUsageIdentifier[i]);
2786 }
2787
2789 }
2790}
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
BOOL WINAPI CertRemoveEnhancedKeyUsageIdentifier(PCCERT_CONTEXT pCertContext, LPCSTR pszUsageIdentifier)
Definition: cert.c:3063
BOOL WINAPI CertSetEnhancedKeyUsage(PCCERT_CONTEXT pCertContext, PCERT_ENHKEY_USAGE pUsage)
Definition: cert.c:2952
BOOL WINAPI CertAddEnhancedKeyUsageIdentifier(PCCERT_CONTEXT pCertContext, LPCSTR pszUsageIdentifier)
Definition: cert.c:2978
BOOL WINAPI CertGetEnhancedKeyUsage(PCCERT_CONTEXT pCertContext, DWORD dwFlags, PCERT_ENHKEY_USAGE pUsage, DWORD *pcbUsage)
Definition: cert.c:2847
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
GLuint GLsizei bufSize
Definition: glext.h:6040
static const LPCSTR keyUsages[]
Definition: cert.c:2508
DWORD cUsageIdentifier
Definition: wincrypt.h:719
LPSTR * rgpszUsageIdentifier
Definition: wincrypt.h:720
#define CERT_FIND_EXT_ONLY_ENHKEY_USAGE_FLAG
Definition: wincrypt.h:2916
struct _CTL_USAGE CERT_ENHKEY_USAGE
#define CERT_FIND_PROP_ONLY_ENHKEY_USAGE_FLAG
Definition: wincrypt.h:2918
struct _CTL_USAGE * PCERT_ENHKEY_USAGE

Referenced by START_TEST().

◆ testLinkCert()

static void testLinkCert ( void  )
static

Definition at line 776 of file cert.c.

777{
778 const CERT_CONTEXT *context, *link;
779 HCERTSTORE store;
780 BOOL ret;
781
783 ok(context != NULL, "CertCreateCertificateContext failed\n");
784
786 ok(store != NULL, "CertOpenStore failed: %d\n", GetLastError());
787
789 ok(ret, "CertAddCertificateContextToStore failed\n");
790 ok(link != NULL && link != context, "unexpected storeContext\n");
791 ok(link->hCertStore == store, "unexpected hCertStore\n");
792
793 ok(link->pbCertEncoded == context->pbCertEncoded, "unexpected pbCertEncoded\n");
794 ok(link->cbCertEncoded == context->cbCertEncoded, "unexpected cbCertEncoded\n");
795 ok(link->pCertInfo == context->pCertInfo, "unexpected pCertInfo\n");
796
799 CertCloseStore(store, 0);
800}
const WCHAR * link
Definition: db.cpp:997
BOOL WINAPI CertAddCertificateLinkToStore(HCERTSTORE hCertStore, PCCERT_CONTEXT pCertContext, DWORD dwAddDisposition, PCCERT_CONTEXT *ppCertContext)
Definition: cert.c:296

Referenced by START_TEST().

◆ testSignAndEncodeCert()

static void testSignAndEncodeCert ( void  )
static

Definition at line 2089 of file cert.c.

2090{
2091 static char oid_rsa_md5rsa[] = szOID_RSA_MD5RSA;
2092 static char oid_rsa_md5[] = szOID_RSA_MD5;
2093 BOOL ret;
2094 DWORD size;
2095 CRYPT_ALGORITHM_IDENTIFIER algID = { 0 };
2096 CERT_INFO info = { 0 };
2097
2098 /* Crash
2099 ret = CryptSignAndEncodeCertificate(0, 0, 0, NULL, NULL, NULL, NULL, NULL,
2100 NULL);
2101 ret = CryptSignAndEncodeCertificate(0, 0, 0, NULL, NULL, NULL, NULL, NULL,
2102 &size);
2103 */
2104 ret = CryptSignAndEncodeCertificate(0, 0, 0, NULL, NULL, &algID, NULL, NULL,
2105 &size);
2107 "Expected ERROR_FILE_NOT_FOUND, got %08x\n", GetLastError());
2109 &algID, NULL, NULL, &size);
2111 "Expected ERROR_FILE_NOT_FOUND, got %08x\n", GetLastError());
2113 &algID, NULL, NULL, &size);
2115 "Expected ERROR_FILE_NOT_FOUND, got %08x\n", GetLastError());
2116 /* Crashes on some win9x boxes */
2117 if (0)
2118 {
2122 "Expected STATUS_ACCESS_VIOLATION, got %08x\n", GetLastError());
2123 }
2124 /* Crashes
2125 ret = CryptSignAndEncodeCertificate(0, 0, X509_ASN_ENCODING,
2126 X509_CERT_TO_BE_SIGNED, &info, NULL, NULL, NULL, &size);
2127 */
2129 X509_CERT_TO_BE_SIGNED, &info, &algID, NULL, NULL, &size);
2130 ok(!ret &&
2132 GetLastError() == OSS_BAD_PTR), /* win9x */
2133 "Expected NTE_BAD_ALGID, got %08x\n", GetLastError());
2134 algID.pszObjId = oid_rsa_md5rsa;
2136 X509_CERT_TO_BE_SIGNED, &info, &algID, NULL, NULL, &size);
2137 ok(!ret &&
2140 GetLastError() == OSS_BAD_PTR), /* Win9x */
2141 "Expected ERROR_INVALID_PARAMETER or NTE_BAD_ALGID, got %08x\n",
2142 GetLastError());
2143 algID.pszObjId = oid_rsa_md5;
2145 X509_CERT_TO_BE_SIGNED, &info, &algID, NULL, NULL, &size);
2146 /* oid_rsa_md5 not present in some win2k */
2147 if (ret)
2148 {
2150
2151 if (buf)
2152 {
2154 X509_CERT_TO_BE_SIGNED, &info, &algID, NULL, buf, &size);
2155 ok(ret, "CryptSignAndEncodeCertificate failed: %08x\n",
2156 GetLastError());
2157 /* Tricky: because the NULL parameters may either be omitted or
2158 * included as an asn.1-encoded NULL (0x05,0x00), two different
2159 * values are allowed.
2160 */
2161 ok(size == sizeof(md5SignedEmptyCert) ||
2162 size == sizeof(md5SignedEmptyCertNoNull), "Unexpected size %d\n",
2163 size);
2164 if (size == sizeof(md5SignedEmptyCert))
2166 "Unexpected value\n");
2167 else if (size == sizeof(md5SignedEmptyCertNoNull))
2169 "Unexpected value\n");
2171 }
2172 }
2173}
BOOL WINAPI CryptSignAndEncodeCertificate(HCRYPTPROV_OR_NCRYPT_KEY_HANDLE hCryptProv, DWORD dwKeySpec, DWORD dwCertEncodingType, LPCSTR lpszStructType, const void *pvStructInfo, PCRYPT_ALGORITHM_IDENTIFIER pSignatureAlgorithm, const void *pvHashAuxInfo, BYTE *pbEncoded, DWORD *pcbEncoded)
Definition: cert.c:2364
static const BYTE md5SignedEmptyCertNoNull[]
Definition: cert.c:2081
static char oid_rsa_md5[]
Definition: msg.c:34
#define X509_CERT_TO_BE_SIGNED
Definition: wincrypt.h:3366
#define szOID_RSA_MD5RSA
Definition: wincrypt.h:3021
#define szOID_RSA_MD5
Definition: wincrypt.h:3053
#define OSS_BAD_PTR
Definition: winerror.h:3048

Referenced by START_TEST().

◆ testSignCert()

static void testSignCert ( HCRYPTPROV  csp,
const CRYPT_DATA_BLOB toBeSigned,
LPCSTR  sigOID,
BYTE sig,