2 * Copyright 2008 Juan Lang
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #include "cryptuiapi.h"
28 #include "wine/debug.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(cryptui);
32 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
34 TRACE("(0x%p, %d, %p)\n", hinstDLL, fdwReason, lpvReserved);
38 case DLL_WINE_PREATTACH:
39 return FALSE; /* prefer native version */
40 case DLL_PROCESS_ATTACH:
41 DisableThreadLibraryCalls(hinstDLL);
43 case DLL_PROCESS_DETACH:
51 /***********************************************************************
52 * CryptUIDlgCertMgr (CRYPTUI.@)
54 BOOL WINAPI CryptUIDlgCertMgr(PCCRYPTUI_CERT_MGR_STRUCT pCryptUICertMgr)
56 FIXME("(%p): stub\n", pCryptUICertMgr);
60 BOOL WINAPI CryptUIDlgViewCertificateA(
61 PCCRYPTUI_VIEWCERTIFICATE_STRUCTA pCertViewInfo, BOOL *pfPropertiesChanged)
63 CRYPTUI_VIEWCERTIFICATE_STRUCTW viewInfo;
67 TRACE("(%p, %p)\n", pCertViewInfo, pfPropertiesChanged);
69 memcpy(&viewInfo, pCertViewInfo, sizeof(viewInfo));
70 if (pCertViewInfo->szTitle)
72 int len = MultiByteToWideChar(CP_ACP, 0, pCertViewInfo->szTitle, -1,
75 title = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
78 MultiByteToWideChar(CP_ACP, 0, pCertViewInfo->szTitle, -1, title,
80 viewInfo.szTitle = title;
88 ret = CryptUIDlgViewCertificateW(&viewInfo, pfPropertiesChanged);
89 HeapFree(GetProcessHeap(), 0, title);
94 BOOL WINAPI CryptUIDlgViewCertificateW(PCCRYPTUI_VIEWCERTIFICATE_STRUCTW pCertViewInfo,
95 BOOL *pfPropertiesChanged)
97 FIXME("(%p, %p): stub\n", pCertViewInfo, pfPropertiesChanged);
98 if (pfPropertiesChanged) *pfPropertiesChanged = FALSE;
102 static PCCERT_CONTEXT make_cert_from_file(LPCWSTR fileName)
105 DWORD size, encoding = X509_ASN_ENCODING | PKCS_7_ASN_ENCODING;
109 file = CreateFileW(fileName, GENERIC_READ, FILE_SHARE_READ, NULL,
110 OPEN_EXISTING, 0, NULL);
111 if (file == INVALID_HANDLE_VALUE)
113 WARN("can't open certificate file %s\n", debugstr_w(fileName));
116 if ((size = GetFileSize(file, NULL)))
118 if ((buffer = HeapAlloc(GetProcessHeap(), 0, size)))
121 if (!ReadFile(file, buffer, size, &read, NULL) || read != size)
123 WARN("can't read certificate file %s\n", debugstr_w(fileName));
124 HeapFree(GetProcessHeap(), 0, buffer);
132 WARN("empty file %s\n", debugstr_w(fileName));
137 cert = CertCreateCertificateContext(encoding, buffer, size);
138 HeapFree(GetProcessHeap(), 0, buffer);
142 BOOL WINAPI CryptUIWizImport(DWORD dwFlags, HWND hwndParent, LPCWSTR pwszWizardTitle,
143 PCCRYPTUI_WIZ_IMPORT_SRC_INFO pImportSrc, HCERTSTORE hDestCertStore)
145 static const WCHAR Root[] = {'R','o','o','t',0};
148 const CERT_CONTEXT *cert;
150 TRACE("(0x%08x, %p, %s, %p, %p)\n", dwFlags, hwndParent, debugstr_w(pwszWizardTitle),
151 pImportSrc, hDestCertStore);
153 FIXME("only certificate files are supported\n");
155 if (!(dwFlags & CRYPTUI_WIZ_NO_UI)) FIXME("UI not implemented\n");
158 pImportSrc->dwSize != sizeof(CRYPTUI_WIZ_IMPORT_SRC_INFO))
160 SetLastError(E_INVALIDARG);
164 if (pImportSrc->dwSubjectChoice != CRYPTUI_WIZ_IMPORT_SUBJECT_FILE)
166 FIXME("source type not implemented: %u\n", pImportSrc->dwSubjectChoice);
169 if (!(cert = make_cert_from_file(pImportSrc->pwszFileName)))
171 WARN("unable to create certificate context\n");
174 if (hDestCertStore) store = hDestCertStore;
177 FIXME("certificate store should be determined dynamically, picking Root store\n");
178 if (!(store = CertOpenStore(CERT_STORE_PROV_SYSTEM_W, 0, 0, CERT_SYSTEM_STORE_CURRENT_USER, Root)))
180 WARN("unable to open certificate store\n");
181 CertFreeCertificateContext(cert);
185 ret = CertAddCertificateContextToStore(store, cert, CERT_STORE_ADD_REPLACE_EXISTING, NULL);
187 if (!hDestCertStore) CertCloseStore(store, 0);
188 CertFreeCertificateContext(cert);