From a5bbed2b95abb5b8983df487c62039c683fe98cb Mon Sep 17 00:00:00 2001 From: Juan Lang Date: Wed, 22 Aug 2007 09:38:44 -0700 Subject: [PATCH] advapi32: Add more tests for CryptVerifySignatureW, and correct its parameter checking. --- dlls/advapi32/crypt.c | 7 +---- dlls/advapi32/tests/crypt.c | 76 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 6 deletions(-) diff --git a/dlls/advapi32/crypt.c b/dlls/advapi32/crypt.c index 60131bb28df..63f89f6869a 100644 --- a/dlls/advapi32/crypt.c +++ b/dlls/advapi32/crypt.c @@ -2134,12 +2134,7 @@ BOOL WINAPI CryptVerifySignatureW (HCRYPTHASH hHash, CONST BYTE *pbSignature, DW TRACE("(0x%lx, %p, %d, 0x%lx, %s, %08x)\n", hHash, pbSignature, dwSigLen, hPubKey, debugstr_w(sDescription), dwFlags); - if (!hash || !key) - { - SetLastError(ERROR_INVALID_HANDLE); - return FALSE; - } - if (!pbSignature || !dwSigLen || + if (!hash || !key || !hash->pProvider || hash->pProvider->dwMagic != MAGIC_CRYPTPROV || !key->pProvider || key->pProvider->dwMagic != MAGIC_CRYPTPROV) { diff --git a/dlls/advapi32/tests/crypt.c b/dlls/advapi32/tests/crypt.c index a8db3849cd7..9fa532cb1d0 100644 --- a/dlls/advapi32/tests/crypt.c +++ b/dlls/advapi32/tests/crypt.c @@ -349,6 +349,81 @@ static void test_incorrect_api_usage(void) ok (!result && GetLastError() == ERROR_INVALID_PARAMETER, "%d\n", GetLastError()); } +static const BYTE privKey[] = { + 0x07, 0x02, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x52, 0x53, 0x41, 0x32, 0x00, + 0x02, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x79, 0x10, 0x1c, 0xd0, 0x6b, 0x10, + 0x18, 0x30, 0x94, 0x61, 0xdc, 0x0e, 0xcb, 0x96, 0x4e, 0x21, 0x3f, 0x79, 0xcd, + 0xa9, 0x17, 0x62, 0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 0x92, 0x4c, 0x38, 0x6b, 0x96, 0x6d, 0xcd, 0x86, 0x67, + 0x5c, 0xea, 0x54, 0x94, 0xa4, 0xca, 0xa4, 0x02, 0xa5, 0x21, 0x4d, 0xae, 0x40, + 0x8f, 0x9d, 0x51, 0x83, 0xf2, 0x3f, 0x33, 0xc1, 0x72, 0xb4, 0x1d, 0x94, 0x6e, + 0x7d, 0xe4, 0x27, 0x3f, 0xea, 0xff, 0xe5, 0x9b, 0xa7, 0x5e, 0x55, 0x8e, 0x0d, + 0x69, 0x1c, 0x7a, 0xff, 0x81, 0x9d, 0x53, 0x52, 0x97, 0x9a, 0x76, 0x79, 0xda, + 0x93, 0x32, 0x16, 0xec, 0x69, 0x51, 0x1a, 0x4e, 0xc3, 0xf1, 0x72, 0x80, 0x78, + 0x5e, 0x66, 0x4a, 0x8d, 0x85, 0x2f, 0x3f, 0xb2, 0xa7 }; + +static void test_verify_sig(void) +{ + BOOL ret; + HCRYPTPROV prov; + HCRYPTKEY key; + HCRYPTHASH hash; + BYTE bogus[] = { 0 }; + + SetLastError(0xdeadbeef); + ret = pCryptVerifySignatureW(0, NULL, 0, 0, NULL, 0); + ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, + "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError()); + ret = pCryptAcquireContextA(&prov, szKeySet, NULL, PROV_RSA_FULL, + CRYPT_NEWKEYSET); + if (!ret && GetLastError() == NTE_EXISTS) + ret = pCryptAcquireContextA(&prov, szKeySet, NULL, PROV_RSA_FULL, 0); + ret = pCryptImportKey(prov, (LPBYTE)privKey, sizeof(privKey), 0, 0, &key); + ok(ret, "CryptImportKey failed: %08x\n", GetLastError()); + ret = pCryptCreateHash(prov, CALG_MD5, 0, 0, &hash); + ok(ret, "CryptCreateHash failed: %08x\n", GetLastError()); + SetLastError(0xdeadbeef); + ret = pCryptVerifySignatureW(hash, NULL, 0, 0, NULL, 0); + ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, + "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError()); + SetLastError(0xdeadbeef); + ret = pCryptVerifySignatureW(0, NULL, 0, key, NULL, 0); + ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, + "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError()); + SetLastError(0xdeadbeef); + ret = pCryptVerifySignatureW(hash, NULL, 0, key, NULL, 0); + ok(!ret && GetLastError() == NTE_BAD_SIGNATURE, + "Expected NTE_BAD_SIGNATURE, got %08x\n", GetLastError()); + SetLastError(0xdeadbeef); + ret = pCryptVerifySignatureW(hash, NULL, sizeof(bogus), key, NULL, 0); + ok(!ret && GetLastError() == NTE_BAD_SIGNATURE, + "Expected NTE_BAD_SIGNATURE, got %08x\n", GetLastError()); + SetLastError(0xdeadbeef); + ret = pCryptVerifySignatureW(hash, bogus, 0, key, NULL, 0); + ok(!ret && GetLastError() == NTE_BAD_SIGNATURE, + "Expected NTE_BAD_SIGNATURE, got %08x\n", GetLastError()); + SetLastError(0xdeadbeef); + ret = pCryptVerifySignatureW(hash, bogus, sizeof(bogus), key, NULL, 0); + ok(!ret && GetLastError() == NTE_BAD_SIGNATURE, + "Expected NTE_BAD_SIGNATURE, got %08x\n", GetLastError()); + pCryptDestroyKey(key); + pCryptDestroyHash(hash); + pCryptReleaseContext(prov, 0); +} + static BOOL FindProvRegVals(DWORD dwIndex, DWORD *pdwProvType, LPSTR *pszProvName, DWORD *pcbProvName, DWORD *pdwProvCount) { @@ -779,6 +854,7 @@ START_TEST(crypt) init_environment(); test_acquire_context(); test_incorrect_api_usage(); + test_verify_sig(); clean_up_environment(); } -- 2.11.4.GIT