summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Beauzée-Luyssen <hugo@beauzee.fr>2018-12-17 11:37:12 +0100
committerHugo Beauzée-Luyssen <hugo@beauzee.fr>2018-12-20 19:33:47 +0100
commitac34af7160c866b7e2354d2d197e63af48e479d8 (patch)
treed50c99a79fc1ddec8dcfcd724725968bcdfdb135
parentfd91542eb82c61feeb3b9483afa6ab303b6ef1b7 (diff)
downloadgnutls-ac34af7160c866b7e2354d2d197e63af48e479d8.tar.gz
win32: Check that CertOpenStore is behaving as CertOpenSystemStore
The test isn't located in tests/windows since we need the actual libcrypt32 implementations.
-rw-r--r--tests/Makefile.am4
-rw-r--r--tests/win-certopenstore.c70
2 files changed, 74 insertions, 0 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 7bc98df743..043aefc01d 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -486,6 +486,10 @@ else
TESTS_ENVIRONMENT += WINDOWS=1
+win32_certopenstore_SOURCES = win-certopenstore.c
+win32_certopenstore_LDADD = $(LDADD) -lcrypt32
+ctests += win32-certopenstore
+
endif
cpptests =
diff --git a/tests/win-certopenstore.c b/tests/win-certopenstore.c
new file mode 100644
index 0000000000..162defa4e3
--- /dev/null
+++ b/tests/win-certopenstore.c
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2018 Hugo Beauzée-Luyssen
+ *
+ * Author: Hugo Beauzée-Luyssen
+ *
+ * This file is part of GnuTLS.
+ *
+ * GnuTLS is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GnuTLS is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GnuTLS; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/*
+ * This test verifies the assumptions about CertOpenStore and
+ * CertOpenSystemStore to be equivalent when passed some specific flags
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#ifndef _WIN32
+#error "This test shouldn't have been included"
+#endif
+
+#include <windows.h>
+#include <wincrypt.h>
+#include <assert.h>
+
+void doit(void)
+{
+ HCERTSTORE hStore = CertOpenStore(CERT_STORE_PROV_SYSTEM, 0, 0, CERT_SYSTEM_STORE_CURRENT_USER , L"ROOT");
+ assert(hStore != NULL);
+ HCERTSTORE hSystemStore = CertOpenSystemStore(0, "ROOT");
+ assert(hSystemStore != NULL);
+
+ PCCERT_CONTEXT prevCtx = NULL;
+ PCCERT_CONTEXT ctx = NULL;
+ PCCERT_CONTEXT sysPrevCtx = NULL;
+ PCCERT_CONTEXT sysCtx = NULL;
+
+ while (1)
+ {
+ ctx = CertEnumCertificatesInStore(hStore, prevCtx);
+ sysCtx = CertEnumCertificatesInStore(hSystemStore, sysPrevCtx);
+ if (ctx == NULL || sysCtx == NULL)
+ break;
+ if (CertCompareIntegerBlob(&ctx->pCertInfo->SerialNumber,
+ &sysCtx->pCertInfo->SerialNumber) != TRUE)
+ assert(0);
+
+ prevCtx = ctx;
+ sysPrevCtx = sysCtx;
+ }
+ assert(ctx == NULL && sysCtx == NULL);
+
+ CertCloseStore(hStore, 0);
+ CertCloseStore(hSystemStore, 0);
+}
+