https://git.reactos.org/?p=reactos.git;a=commitdiff;h=fb7a0344cdfcd7764f9fe30df1d12791234b7dfb

commit fb7a0344cdfcd7764f9fe30df1d12791234b7dfb
Author:     Mark Jansen <[email protected]>
AuthorDate: Sat Feb 9 01:44:39 2019 +0100
Commit:     Mark Jansen <[email protected]>
CommitDate: Sat Feb 9 01:44:39 2019 +0100

    [CRYPTEXT] Add a minimal shell extension that will show the certificate 
dialog
---
 boot/bootdata/hivecls.inf            |  4 +++
 dll/shellext/CMakeLists.txt          |  1 +
 dll/shellext/cryptext/CMakeLists.txt | 17 ++++++++++
 dll/shellext/cryptext/cryptext.c     | 63 ++++++++++++++++++++++++++++++++++++
 dll/shellext/cryptext/cryptext.spec  |  2 ++
 dll/shellext/cryptext/precomp.h      | 18 +++++++++++
 6 files changed, 105 insertions(+)

diff --git a/boot/bootdata/hivecls.inf b/boot/bootdata/hivecls.inf
index 446da702532..37d81fd4b12 100644
--- a/boot/bootdata/hivecls.inf
+++ b/boot/bootdata/hivecls.inf
@@ -76,6 +76,10 @@ 
HKCR,"batfile\DefaultIcon","",0x00020000,"%SystemRoot%\system32\shell32.dll,-153
 
HKCR,"batfile\shell\edit\command","",0x00020000,"%SystemRoot%\system32\notepad.exe
 ""%1"""
 HKCR,"batfile\shell\open\command","",0x00000000,"""%1"" %*"
 
+; Certificate
+HKCR,".cer","",0x00000000,"cerfile"
+HKCR,"cerfile\shell\open\command","",0x00020000,"%SystemRoot%\system32\rundll32.exe
 cryptext.dll,CryptExtOpenCER %1"
+
 ; ReactOS Command Script Files
 HKCR,".cmd","",0x00000000,"cmdfile"
 HKCR,"cmdfile","",0x00000000,"ReactOS Command Script"
diff --git a/dll/shellext/CMakeLists.txt b/dll/shellext/CMakeLists.txt
index e11df360013..0f57882163f 100644
--- a/dll/shellext/CMakeLists.txt
+++ b/dll/shellext/CMakeLists.txt
@@ -1,5 +1,6 @@
 
 add_subdirectory(acppage)
+add_subdirectory(cryptext)
 add_subdirectory(deskadp)
 add_subdirectory(deskmon)
 add_subdirectory(devcpux)
diff --git a/dll/shellext/cryptext/CMakeLists.txt 
b/dll/shellext/cryptext/CMakeLists.txt
new file mode 100644
index 00000000000..faa2301ce9a
--- /dev/null
+++ b/dll/shellext/cryptext/CMakeLists.txt
@@ -0,0 +1,17 @@
+
+spec2def(cryptext.dll cryptext.spec)
+
+list(APPEND SOURCE
+    cryptext.c
+    precomp.h)
+
+add_library(cryptext SHARED
+    ${SOURCE}
+    cryptext.spec
+    ${CMAKE_CURRENT_BINARY_DIR}/cryptext.def)
+
+set_module_type(cryptext win32dll UNICODE)
+target_link_libraries(cryptext uuid)
+add_importlibs(cryptext cryptui crypt32 user32 msvcrt kernel32 ntdll)
+add_pch(cryptext precomp.h SOURCE)
+add_cd_file(TARGET cryptext DESTINATION reactos/system32 FOR all)
diff --git a/dll/shellext/cryptext/cryptext.c b/dll/shellext/cryptext/cryptext.c
new file mode 100644
index 00000000000..8825f41b91b
--- /dev/null
+++ b/dll/shellext/cryptext/cryptext.c
@@ -0,0 +1,63 @@
+/*
+ * PROJECT:     ReactOS CryptExt Shell Extension
+ * LICENSE:     GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
+ * PURPOSE:     cryptext implementation
+ * COPYRIGHT:   Copyright 2019 Mark Jansen ([email protected])
+ */
+
+#include "precomp.h"
+
+
+BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
+{
+    switch (dwReason)
+    {
+    case DLL_PROCESS_ATTACH:
+        DisableThreadLibraryCalls(hInstance);
+        break;
+    }
+
+    return TRUE;
+}
+
+EXTERN_C
+VOID WINAPI CryptExtOpenCERW(HWND hWnd, HINSTANCE hInst, LPCWSTR file, DWORD 
nCmdShow)
+{
+    PCCERT_CONTEXT pvContext;
+    if (file)
+    {
+        if (CryptQueryObject(CERT_QUERY_OBJECT_FILE, file, 
CERT_QUERY_CONTENT_FLAG_CERT, CERT_QUERY_FORMAT_FLAG_ALL,
+                             0, NULL, NULL, NULL, NULL, NULL, (CONST 
VOID**)&pvContext))
+        {
+            CRYPTUI_VIEWCERTIFICATE_STRUCT CertViewInfo = {0};
+            CertViewInfo.dwSize = sizeof(CertViewInfo);
+            CertViewInfo.pCertContext = pvContext;
+            CryptUIDlgViewCertificate(&CertViewInfo, NULL);
+            CertFreeCertificateContext(pvContext);
+        }
+        else
+        {
+            MessageBoxW(NULL, L"This is not a valid certificate", NULL, MB_OK);
+        }
+    }
+}
+
+EXTERN_C
+VOID WINAPI CryptExtOpenCER(HWND hWnd, HINSTANCE hInst, LPCSTR file, DWORD 
nCmdShow)
+{
+    LPWSTR fileW;
+    int len;
+
+    if (file)
+    {
+
+        len = MultiByteToWideChar(CP_ACP, 0, file, -1, NULL, 0);
+        fileW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
+        if (fileW)
+        {
+            MultiByteToWideChar(CP_ACP, 0, file, -1, fileW, len);
+            CryptExtOpenCERW(hWnd, hInst, fileW, nCmdShow);
+            HeapFree(GetProcessHeap(), 0, fileW);
+        }
+    }
+}
diff --git a/dll/shellext/cryptext/cryptext.spec 
b/dll/shellext/cryptext/cryptext.spec
new file mode 100644
index 00000000000..b89f1dbc0a9
--- /dev/null
+++ b/dll/shellext/cryptext/cryptext.spec
@@ -0,0 +1,2 @@
+@ stdcall CryptExtOpenCER(ptr ptr str long)
+@ stdcall CryptExtOpenCERW(ptr ptr wstr long)
diff --git a/dll/shellext/cryptext/precomp.h b/dll/shellext/cryptext/precomp.h
new file mode 100644
index 00000000000..e9df5d3270b
--- /dev/null
+++ b/dll/shellext/cryptext/precomp.h
@@ -0,0 +1,18 @@
+#ifndef CRYPTEXT_PRECOMP_H
+#define CRYPTEXT_PRECOMP_H
+
+#define COBJMACROS
+#define WIN32_NO_STATUS
+#define _INC_WINDOWS
+#define COM_NO_WINDOWS_H
+#define NTOS_MODE_USER
+
+#include <windef.h>
+#include <winbase.h>
+#include <winnls.h>
+#include <wincrypt.h>
+#include <winuser.h>
+#include <cryptuiapi.h>
+
+
+#endif /* CRYPTEXT_PRECOMP_H */

Reply via email to