[CRYPTEXT] Add a minimal shell extension that will show the certificate dialog
[reactos.git] / dll / shellext / cryptext / cryptext.c
1 /*
2 * PROJECT: ReactOS CryptExt Shell Extension
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: cryptext implementation
5 * COPYRIGHT: Copyright 2019 Mark Jansen (mark.jansen@reactos.org)
6 */
7
8 #include "precomp.h"
9
10
11 BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
12 {
13 switch (dwReason)
14 {
15 case DLL_PROCESS_ATTACH:
16 DisableThreadLibraryCalls(hInstance);
17 break;
18 }
19
20 return TRUE;
21 }
22
23 EXTERN_C
24 VOID WINAPI CryptExtOpenCERW(HWND hWnd, HINSTANCE hInst, LPCWSTR file, DWORD nCmdShow)
25 {
26 PCCERT_CONTEXT pvContext;
27 if (file)
28 {
29 if (CryptQueryObject(CERT_QUERY_OBJECT_FILE, file, CERT_QUERY_CONTENT_FLAG_CERT, CERT_QUERY_FORMAT_FLAG_ALL,
30 0, NULL, NULL, NULL, NULL, NULL, (CONST VOID**)&pvContext))
31 {
32 CRYPTUI_VIEWCERTIFICATE_STRUCT CertViewInfo = {0};
33 CertViewInfo.dwSize = sizeof(CertViewInfo);
34 CertViewInfo.pCertContext = pvContext;
35 CryptUIDlgViewCertificate(&CertViewInfo, NULL);
36 CertFreeCertificateContext(pvContext);
37 }
38 else
39 {
40 MessageBoxW(NULL, L"This is not a valid certificate", NULL, MB_OK);
41 }
42 }
43 }
44
45 EXTERN_C
46 VOID WINAPI CryptExtOpenCER(HWND hWnd, HINSTANCE hInst, LPCSTR file, DWORD nCmdShow)
47 {
48 LPWSTR fileW;
49 int len;
50
51 if (file)
52 {
53
54 len = MultiByteToWideChar(CP_ACP, 0, file, -1, NULL, 0);
55 fileW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
56 if (fileW)
57 {
58 MultiByteToWideChar(CP_ACP, 0, file, -1, fileW, len);
59 CryptExtOpenCERW(hWnd, hInst, fileW, nCmdShow);
60 HeapFree(GetProcessHeap(), 0, fileW);
61 }
62 }
63 }