[CRYPTEXT] Add a minimal shell extension that will show the certificate dialog 1343/head
authorMark Jansen <mark.jansen@reactos.org>
Sat, 9 Feb 2019 00:44:39 +0000 (01:44 +0100)
committerMark Jansen <mark.jansen@reactos.org>
Sat, 9 Feb 2019 00:44:39 +0000 (01:44 +0100)
boot/bootdata/hivecls.inf
dll/shellext/CMakeLists.txt
dll/shellext/cryptext/CMakeLists.txt [new file with mode: 0644]
dll/shellext/cryptext/cryptext.c [new file with mode: 0644]
dll/shellext/cryptext/cryptext.spec [new file with mode: 0644]
dll/shellext/cryptext/precomp.h [new file with mode: 0644]

index 446da70..37d81fd 100644 (file)
@@ -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"" %*"
 
 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"
 ; ReactOS Command Script Files
 HKCR,".cmd","",0x00000000,"cmdfile"
 HKCR,"cmdfile","",0x00000000,"ReactOS Command Script"
index e11df36..0f57882 100644 (file)
@@ -1,5 +1,6 @@
 
 add_subdirectory(acppage)
 
 add_subdirectory(acppage)
+add_subdirectory(cryptext)
 add_subdirectory(deskadp)
 add_subdirectory(deskmon)
 add_subdirectory(devcpux)
 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 (file)
index 0000000..faa2301
--- /dev/null
@@ -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 (file)
index 0000000..8825f41
--- /dev/null
@@ -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 (mark.jansen@reactos.org)
+ */
+
+#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 (file)
index 0000000..b89f1db
--- /dev/null
@@ -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 (file)
index 0000000..e9df5d3
--- /dev/null
@@ -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 */