* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
-#include <assert.h>
#include <stdio.h>
#include <stdarg.h>
+
#include <windef.h>
#include <winbase.h>
#include <winreg.h>
size = sizeof(hashProperty);
ret = CertGetCertificateContextProperty(context, CERT_HASH_PROP_ID,
hashProperty, &size);
+ ok(ret, "CertGetCertificateContextProperty failed: %08x\n",
+ GetLastError());
ok(!memcmp(hashProperty, hash, sizeof(hash)), "Unexpected hash\n");
/* Delete the (bogus) hash, and get the real one */
ret = CertSetCertificateContextProperty(context, CERT_HASH_PROP_ID, 0,
CertFreeCertificateContext(context);
}
+static void testCreateCert(void)
+{
+ PCCERT_CONTEXT cert, enumCert;
+ DWORD count, size;
+ BOOL ret;
+
+ SetLastError(0xdeadbeef);
+ cert = CertCreateCertificateContext(0, NULL, 0);
+ ok(!cert && GetLastError() == E_INVALIDARG,
+ "expected E_INVALIDARG, got %08x\n", GetLastError());
+ SetLastError(0xdeadbeef);
+ cert = CertCreateCertificateContext(0, selfSignedCert,
+ sizeof(selfSignedCert));
+ ok(!cert && GetLastError() == E_INVALIDARG,
+ "expected E_INVALIDARG, got %08x\n", GetLastError());
+ SetLastError(0xdeadbeef);
+ cert = CertCreateCertificateContext(X509_ASN_ENCODING, NULL, 0);
+ ok(!cert &&
+ (GetLastError() == CRYPT_E_ASN1_EOD ||
+ broken(GetLastError() == OSS_MORE_INPUT /* NT4 */)),
+ "expected CRYPT_E_ASN1_EOD, got %08x\n", GetLastError());
+
+ cert = CertCreateCertificateContext(X509_ASN_ENCODING,
+ selfSignedCert, sizeof(selfSignedCert));
+ ok(cert != NULL, "creating cert failed: %08x\n", GetLastError());
+ /* Even in-memory certs are expected to have a store associated with them */
+ todo_wine
+ ok(cert->hCertStore != NULL, "expected created cert to have a store\n");
+ /* The cert doesn't have the archived property set (which would imply it
+ * doesn't show up in enumerations.)
+ */
+ size = 0;
+ ret = CertGetCertificateContextProperty(cert, CERT_ARCHIVED_PROP_ID,
+ NULL, &size);
+ ok(!ret && GetLastError() == CRYPT_E_NOT_FOUND,
+ "expected CRYPT_E_NOT_FOUND, got %08x\n", GetLastError());
+ /* Strangely, enumerating the certs in the store finds none. */
+ enumCert = NULL;
+ count = 0;
+ while ((enumCert = CertEnumCertificatesInStore(cert->hCertStore, enumCert)))
+ count++;
+ ok(!count, "expected 0, got %d\n", count);
+ CertFreeCertificateContext(cert);
+}
+
static void testDupCert(void)
{
HCERTSTORE store;
/* With only the child certificate, no issuer will be found */
ret = CertAddEncodedCertificateToStore(store, X509_ASN_ENCODING,
chain7_1, sizeof(chain7_1), CERT_STORE_ADD_ALWAYS, &child);
+ ok(ret, "CertAddEncodedCertificateToStore failed: %08x\n", GetLastError());
parent = CertGetIssuerCertificateFromStore(store, child, NULL, &flags);
ok(parent == NULL, "Expected no issuer\n");
/* Adding an issuer allows one (and only one) issuer to be found */
ret = CertAddEncodedCertificateToStore(store, X509_ASN_ENCODING,
chain10_1, sizeof(chain10_1), CERT_STORE_ADD_ALWAYS, &cert1);
+ ok(ret, "CertAddEncodedCertificateToStore failed: %08x\n", GetLastError());
parent = CertGetIssuerCertificateFromStore(store, child, NULL, &flags);
ok(parent == cert1, "Expected cert1 to be the issuer\n");
parent = CertGetIssuerCertificateFromStore(store, child, parent, &flags);
*/
ret = CertAddEncodedCertificateToStore(store, X509_ASN_ENCODING,
chain10_0, sizeof(chain10_0), CERT_STORE_ADD_ALWAYS, &cert2);
+ ok(ret, "CertAddEncodedCertificateToStore failed: %08x\n", GetLastError());
parent = CertGetIssuerCertificateFromStore(store, child, NULL, &flags);
ok(parent == cert2, "Expected cert2 to be the first issuer\n");
parent = CertGetIssuerCertificateFromStore(store, child, parent, &flags);
/* With only the child certificate, no issuer will be found */
ret = CertAddEncodedCertificateToStore(store, X509_ASN_ENCODING,
chain7_1, sizeof(chain7_1), CERT_STORE_ADD_ALWAYS, &child);
+ ok(ret, "CertAddEncodedCertificateToStore failed: %08x\n", GetLastError());
parent = CertGetIssuerCertificateFromStore(store, child, NULL, &flags);
ok(parent == NULL, "Expected no issuer\n");
/* Adding an issuer allows one (and only one) issuer to be found */
ret = CertAddEncodedCertificateToStore(store, X509_ASN_ENCODING,
chain10_0, sizeof(chain10_0), CERT_STORE_ADD_ALWAYS, &cert1);
+ ok(ret, "CertAddEncodedCertificateToStore failed: %08x\n", GetLastError());
parent = CertGetIssuerCertificateFromStore(store, child, NULL, &flags);
ok(parent == cert1, "Expected cert1 to be the issuer\n");
parent = CertGetIssuerCertificateFromStore(store, child, parent, &flags);
*/
ret = CertAddEncodedCertificateToStore(store, X509_ASN_ENCODING,
chain10_1, sizeof(chain10_1), CERT_STORE_ADD_ALWAYS, &cert2);
+ ok(ret, "CertAddEncodedCertificateToStore failed: %08x\n", GetLastError());
parent = CertGetIssuerCertificateFromStore(store, child, NULL, &flags);
ok(parent == cert2, "Expected cert2 to be the first issuer\n");
parent = CertGetIssuerCertificateFromStore(store, child, parent, &flags);
CryptReleaseContext(csp, 0);
ret = pCryptAcquireContextA(&csp, cspNameA, MS_DEF_PROV_A, PROV_RSA_FULL,
CRYPT_DELETEKEYSET);
+ ok(ret, "CryptAcquireContext failed: %08x\n", GetLastError());
}
static const BYTE md5SignedEmptyCert[] = {
CryptReleaseContext(csp, 0);
ret = pCryptAcquireContextA(&csp, cspNameA, MS_DEF_PROV_A, PROV_RSA_FULL,
CRYPT_DELETEKEYSET);
+ ok(ret, "CryptAcquireContext failed: %08x\n", GetLastError());
+
/* do the same test with AT_KEYEXCHANGE and key info*/
memset(&info,0,sizeof(info));
if (0)
{
/* Crash */
- ret = CertGetIntendedKeyUsage(0, NULL, NULL, 0);
+ CertGetIntendedKeyUsage(0, NULL, NULL, 0);
}
ret = CertGetIntendedKeyUsage(0, &info, NULL, 0);
ok(!ret, "expected failure\n");
ok(!ret, "expected failure\n");
ret = CertGetIntendedKeyUsage(X509_ASN_ENCODING, &info, usage_bytes,
sizeof(usage_bytes));
+ ok(!ret, "expected failure\n");
info.cExtension = 1;
info.rgExtension = &ext;
ret = CertGetIntendedKeyUsage(X509_ASN_ENCODING, &info, NULL, 0);
SetLastError(0xbaadcafe);
size = sizeof(buf);
ret = CertGetEnhancedKeyUsage(context, 0, pUsage, &size);
+ ok(ret || broken(!ret && GetLastError() == CRYPT_E_NOT_FOUND /* NT4 */),
+ "CertGetEnhancedKeyUsage failed: %08x\n", GetLastError());
ok(GetLastError() == CRYPT_E_NOT_FOUND,
"Expected CRYPT_E_NOT_FOUND, got %08x\n", GetLastError());
if (0)
{
/* Crash */
- ret = CertIsRDNAttrsInCertificateName(0, 0, NULL, NULL);
- ret = CertIsRDNAttrsInCertificateName(X509_ASN_ENCODING, 0, &name,
- NULL);
+ CertIsRDNAttrsInCertificateName(0, 0, NULL, NULL);
+ CertIsRDNAttrsInCertificateName(X509_ASN_ENCODING, 0, &name, NULL);
}
SetLastError(0xdeadbeef);
ret = CertIsRDNAttrsInCertificateName(0, 0, &name, NULL);
/* Crash */
if (0)
{
- ret = CryptHashToBeSigned(0, 0, NULL, 0, NULL, NULL);
+ CryptHashToBeSigned(0, 0, NULL, 0, NULL, NULL);
}
SetLastError(0xdeadbeef);
ret = CryptHashToBeSigned(0, 0, NULL, 0, NULL, &size);
ret = CryptHashToBeSigned(0, X509_ASN_ENCODING, md5SignedEmptyCert,
sizeof(md5SignedEmptyCert), hash, &size);
+ ok(ret || broken(!ret && GetLastError() == NTE_BAD_ALGID) /* NT4 */,
+ "CryptHashToBeSigned failed: %08x\n", GetLastError());
+
ok(!memcmp(hash, md5SignedEmptyCertHash, size), "unexpected value\n");
}
CERT_INFO info1 = { 0 }, info2 = { 0 };
BOOL ret;
- /* Crashes
- ret = CertCompareCertificate(X509_ASN_ENCODING, NULL, NULL);
- */
+ /* Crashes */
+ if (0)
+ CertCompareCertificate(X509_ASN_ENCODING, NULL, NULL);
/* Certs with the same issuer and serial number are equal, even if they
* differ in other respects (like subject).
testAddCert();
testCertProperties();
+ testCreateCert();
testDupCert();
testFindCert();
testGetSubjectCert();