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
24 #define NONAMELESSUNION
37 #include "cryptuiapi.h"
38 #include "cryptuires.h"
42 #include "wine/debug.h"
43 #include "wine/unicode.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(cryptui
);
47 static HINSTANCE hInstance
;
49 BOOL WINAPI
DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
51 TRACE("(0x%p, %d, %p)\n", hinstDLL
, fdwReason
, lpvReserved
);
55 case DLL_WINE_PREATTACH
:
56 return FALSE
; /* prefer native version */
57 case DLL_PROCESS_ATTACH
:
59 DisableThreadLibraryCalls(hinstDLL
);
61 case DLL_PROCESS_DETACH
:
69 #define MAX_STRING_LEN 512
71 static void add_cert_columns(HWND hwnd
)
73 HWND lv
= GetDlgItem(hwnd
, IDC_MGR_CERTS
);
75 WCHAR buf
[MAX_STRING_LEN
];
78 SendMessageW(lv
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0, LVS_EX_FULLROWSELECT
);
79 GetWindowRect(lv
, &rc
);
80 LoadStringW(hInstance
, IDS_SUBJECT_COLUMN
, buf
,
81 sizeof(buf
) / sizeof(buf
[0]));
82 column
.mask
= LVCF_WIDTH
| LVCF_TEXT
;
83 column
.cx
= (rc
.right
- rc
.left
) * 29 / 100 - 2;
85 SendMessageW(lv
, LVM_INSERTCOLUMNW
, 0, (LPARAM
)&column
);
86 LoadStringW(hInstance
, IDS_ISSUER_COLUMN
, buf
,
87 sizeof(buf
) / sizeof(buf
[0]));
88 SendMessageW(lv
, LVM_INSERTCOLUMNW
, 1, (LPARAM
)&column
);
89 column
.cx
= (rc
.right
- rc
.left
) * 16 / 100 - 2;
90 LoadStringW(hInstance
, IDS_EXPIRATION_COLUMN
, buf
,
91 sizeof(buf
) / sizeof(buf
[0]));
92 SendMessageW(lv
, LVM_INSERTCOLUMNW
, 2, (LPARAM
)&column
);
93 column
.cx
= (rc
.right
- rc
.left
) * 23 / 100 - 1;
94 LoadStringW(hInstance
, IDS_FRIENDLY_NAME_COLUMN
, buf
,
95 sizeof(buf
) / sizeof(buf
[0]));
96 SendMessageW(lv
, LVM_INSERTCOLUMNW
, 3, (LPARAM
)&column
);
99 static void add_cert_to_view(HWND lv
, PCCERT_CONTEXT cert
, DWORD
*allocatedLen
,
104 WCHAR dateFmt
[80]; /* sufficient for LOCALE_SSHORTDATE */
109 item
.mask
= LVIF_IMAGE
| LVIF_PARAM
| LVIF_TEXT
;
110 item
.iItem
= SendMessageW(lv
, LVM_GETITEMCOUNT
, 0, 0);
113 item
.lParam
= (LPARAM
)CertDuplicateCertificateContext(cert
);
114 len
= CertGetNameStringW(cert
, CERT_NAME_SIMPLE_DISPLAY_TYPE
, 0, NULL
,
116 if (len
> *allocatedLen
)
118 HeapFree(GetProcessHeap(), 0, *str
);
119 *str
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
125 CertGetNameStringW(cert
, CERT_NAME_SIMPLE_DISPLAY_TYPE
, 0, NULL
,
128 SendMessageW(lv
, LVM_INSERTITEMW
, 0, (LPARAM
)&item
);
131 item
.mask
= LVIF_TEXT
;
132 len
= CertGetNameStringW(cert
, CERT_NAME_SIMPLE_DISPLAY_TYPE
,
133 CERT_NAME_ISSUER_FLAG
, NULL
, NULL
, 0);
134 if (len
> *allocatedLen
)
136 HeapFree(GetProcessHeap(), 0, *str
);
137 *str
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
143 CertGetNameStringW(cert
, CERT_NAME_SIMPLE_DISPLAY_TYPE
,
144 CERT_NAME_ISSUER_FLAG
, NULL
, *str
, len
);
147 SendMessageW(lv
, LVM_SETITEMTEXTW
, item
.iItem
, (LPARAM
)&item
);
150 GetLocaleInfoW(LOCALE_SYSTEM_DEFAULT
, LOCALE_SSHORTDATE
, dateFmt
,
151 sizeof(dateFmt
) / sizeof(dateFmt
[0]));
152 FileTimeToSystemTime(&cert
->pCertInfo
->NotAfter
, &sysTime
);
153 GetDateFormatW(LOCALE_SYSTEM_DEFAULT
, 0, &sysTime
, dateFmt
, date
,
154 sizeof(date
) / sizeof(date
[0]));
157 SendMessageW(lv
, LVM_SETITEMTEXTW
, item
.iItem
, (LPARAM
)&item
);
159 if (!CertGetCertificateContextProperty(cert
, CERT_FRIENDLY_NAME_PROP_ID
,
161 len
= LoadStringW(hInstance
, IDS_FRIENDLY_NAME_NONE
, (LPWSTR
)&none
, 0);
162 if (len
> *allocatedLen
)
164 HeapFree(GetProcessHeap(), 0, *str
);
165 *str
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
171 if (!CertGetCertificateContextProperty(cert
, CERT_FRIENDLY_NAME_PROP_ID
,
177 SendMessageW(lv
, LVM_SETITEMTEXTW
, item
.iItem
, (LPARAM
)&item
);
181 static LPSTR
get_cert_mgr_usages(void)
183 static const WCHAR keyName
[] = { 'S','o','f','t','w','a','r','e','\\','M',
184 'i','c','r','o','s','o','f','t','\\','C','r','y','p','t','o','g','r','a',
185 'p','h','y','\\','U','I','\\','C','e','r','t','m','g','r','\\','P','u',
186 'r','p','o','s','e',0 };
190 if (!RegCreateKeyExW(HKEY_CURRENT_USER
, keyName
, 0, NULL
, 0, KEY_READ
,
196 rc
= RegQueryValueExA(key
, "Purpose", NULL
, &type
, NULL
, &size
);
197 if ((!rc
|| rc
== ERROR_MORE_DATA
) && type
== REG_SZ
)
199 str
= HeapAlloc(GetProcessHeap(), 0, size
);
202 rc
= RegQueryValueExA(key
, "Purpose", NULL
, NULL
, (LPBYTE
)str
,
206 HeapFree(GetProcessHeap(), 0, str
);
217 PurposeFilterShowAll
= 0,
218 PurposeFilterShowAdvanced
= 1,
219 PurposeFilterShowOID
= 2
222 static void initialize_purpose_selection(HWND hwnd
)
224 HWND cb
= GetDlgItem(hwnd
, IDC_MGR_PURPOSE_SELECTION
);
225 WCHAR buf
[MAX_STRING_LEN
];
229 LoadStringW(hInstance
, IDS_PURPOSE_ALL
, buf
,
230 sizeof(buf
) / sizeof(buf
[0]));
231 index
= SendMessageW(cb
, CB_INSERTSTRING
, -1, (LPARAM
)buf
);
232 SendMessageW(cb
, CB_SETITEMDATA
, index
, (LPARAM
)PurposeFilterShowAll
);
233 LoadStringW(hInstance
, IDS_PURPOSE_ADVANCED
, buf
,
234 sizeof(buf
) / sizeof(buf
[0]));
235 index
= SendMessageW(cb
, CB_INSERTSTRING
, -1, (LPARAM
)buf
);
236 SendMessageW(cb
, CB_SETITEMDATA
, index
, (LPARAM
)PurposeFilterShowAdvanced
);
237 SendMessageW(cb
, CB_SETCURSEL
, 0, 0);
238 if ((usages
= get_cert_mgr_usages()))
242 for (ptr
= usages
, comma
= strchr(ptr
, ','); ptr
&& *ptr
;
243 ptr
= comma
? comma
+ 1 : NULL
,
244 comma
= ptr
? strchr(ptr
, ',') : NULL
)
246 PCCRYPT_OID_INFO info
;
250 if ((info
= CryptFindOIDInfo(CRYPT_OID_INFO_OID_KEY
, ptr
, 0)))
252 index
= SendMessageW(cb
, CB_INSERTSTRING
, 0,
253 (LPARAM
)info
->pwszName
);
254 SendMessageW(cb
, CB_SETITEMDATA
, index
, (LPARAM
)info
);
257 HeapFree(GetProcessHeap(), 0, usages
);
261 extern BOOL WINAPI
WTHelperGetKnownUsages(DWORD action
,
262 PCCRYPT_OID_INFO
**usages
);
264 static CERT_ENHKEY_USAGE
*add_oid_to_usage(CERT_ENHKEY_USAGE
*usage
, LPSTR oid
)
266 if (!usage
->cUsageIdentifier
)
267 usage
->rgpszUsageIdentifier
= HeapAlloc(GetProcessHeap(), 0,
270 usage
->rgpszUsageIdentifier
= HeapReAlloc(GetProcessHeap(), 0,
271 usage
->rgpszUsageIdentifier
,
272 (usage
->cUsageIdentifier
+ 1) * sizeof(LPSTR
));
273 if (usage
->rgpszUsageIdentifier
)
274 usage
->rgpszUsageIdentifier
[usage
->cUsageIdentifier
++] = oid
;
277 HeapFree(GetProcessHeap(), 0, usage
);
283 static CERT_ENHKEY_USAGE
*convert_usages_str_to_usage(LPSTR usageStr
)
285 CERT_ENHKEY_USAGE
*usage
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
286 sizeof(CERT_ENHKEY_USAGE
));
292 for (ptr
= usageStr
, comma
= strchr(ptr
, ','); usage
&& ptr
&& *ptr
;
293 ptr
= comma
? comma
+ 1 : NULL
,
294 comma
= ptr
? strchr(ptr
, ',') : NULL
)
298 add_oid_to_usage(usage
, ptr
);
304 static CERT_ENHKEY_USAGE
*create_advanced_filter(void)
306 CERT_ENHKEY_USAGE
*advancedUsage
= HeapAlloc(GetProcessHeap(),
307 HEAP_ZERO_MEMORY
, sizeof(CERT_ENHKEY_USAGE
));
311 PCCRYPT_OID_INFO
*usages
;
313 if (WTHelperGetKnownUsages(1, &usages
))
315 LPSTR disabledUsagesStr
;
317 if ((disabledUsagesStr
= get_cert_mgr_usages()))
319 CERT_ENHKEY_USAGE
*disabledUsages
=
320 convert_usages_str_to_usage(disabledUsagesStr
);
324 PCCRYPT_OID_INFO
*ptr
;
326 for (ptr
= usages
; *ptr
; ptr
++)
329 BOOL disabled
= FALSE
;
331 for (i
= 0; !disabled
&&
332 i
< disabledUsages
->cUsageIdentifier
; i
++)
333 if (!strcmp(disabledUsages
->rgpszUsageIdentifier
[i
],
337 add_oid_to_usage(advancedUsage
,
338 (LPSTR
)(*ptr
)->pszOID
);
340 /* The individual strings are pointers to disabledUsagesStr,
341 * so they're freed when it is.
343 HeapFree(GetProcessHeap(), 0,
344 disabledUsages
->rgpszUsageIdentifier
);
345 HeapFree(GetProcessHeap(), 0, disabledUsages
);
347 HeapFree(GetProcessHeap(), 0, disabledUsagesStr
);
349 WTHelperGetKnownUsages(2, &usages
);
352 return advancedUsage
;
355 static int CALLBACK
cert_mgr_sort_by_subject(LPARAM lp1
, LPARAM lp2
, LPARAM lp
);
357 static void show_store_certs(HWND hwnd
, HCERTSTORE store
)
359 HWND lv
= GetDlgItem(hwnd
, IDC_MGR_CERTS
);
360 HWND cb
= GetDlgItem(hwnd
, IDC_MGR_PURPOSE_SELECTION
);
361 PCCERT_CONTEXT cert
= NULL
;
362 DWORD allocatedLen
= 0;
365 PurposeFilter filter
= PurposeFilterShowAll
;
367 CERT_ENHKEY_USAGE
*advanced
= NULL
;
369 index
= SendMessageW(cb
, CB_GETCURSEL
, 0, 0);
372 INT_PTR data
= SendMessageW(cb
, CB_GETITEMDATA
, index
, 0);
378 PCCRYPT_OID_INFO info
= (PCCRYPT_OID_INFO
)data
;
380 filter
= PurposeFilterShowOID
;
384 if (filter
== PurposeFilterShowAdvanced
)
385 advanced
= create_advanced_filter();
387 cert
= CertEnumCertificatesInStore(store
, cert
);
392 if (filter
== PurposeFilterShowAll
)
399 if (CertGetValidUsages(1, &cert
, &numOIDs
, NULL
, &cbOIDs
))
403 /* -1 implies all usages are valid */
408 LPSTR
*oids
= HeapAlloc(GetProcessHeap(), 0, cbOIDs
);
412 if (CertGetValidUsages(1, &cert
, &numOIDs
, oids
,
417 if (filter
== PurposeFilterShowOID
)
419 for (i
= 0; !show
&& i
< numOIDs
; i
++)
420 if (!strcmp(oids
[i
], oid
))
425 for (i
= 0; !show
&& i
< numOIDs
; i
++)
430 j
< advanced
->cUsageIdentifier
; j
++)
432 advanced
->rgpszUsageIdentifier
[j
]))
437 HeapFree(GetProcessHeap(), 0, oids
);
443 add_cert_to_view(lv
, cert
, &allocatedLen
, &str
);
446 HeapFree(GetProcessHeap(), 0, str
);
449 HeapFree(GetProcessHeap(), 0, advanced
->rgpszUsageIdentifier
);
450 HeapFree(GetProcessHeap(), 0, advanced
);
452 SendMessageW(lv
, LVM_SORTITEMSEX
, (WPARAM
)lv
,
453 (LPARAM
)cert_mgr_sort_by_subject
);
456 static const WCHAR my
[] = { 'M','y',0 };
457 static const WCHAR addressBook
[] = {
458 'A','d','d','r','e','s','s','B','o','o','k',0 };
459 static const WCHAR ca
[] = { 'C','A',0 };
460 static const WCHAR root
[] = { 'R','o','o','t',0 };
461 static const WCHAR trustedPublisher
[] = {
462 'T','r','u','s','t','e','d','P','u','b','l','i','s','h','e','r',0 };
463 static const WCHAR disallowed
[] = { 'D','i','s','a','l','l','o','w','e','d',0 };
465 struct CertMgrStoreInfo
469 int removePluralWarning
;
472 static const struct CertMgrStoreInfo defaultStoreList
[] = {
473 { my
, IDS_WARN_REMOVE_MY
, IDS_WARN_REMOVE_PLURAL_MY
},
474 { addressBook
, IDS_WARN_REMOVE_ADDRESSBOOK
,
475 IDS_WARN_REMOVE_PLURAL_ADDRESSBOOK
},
476 { ca
, IDS_WARN_REMOVE_CA
, IDS_WARN_REMOVE_PLURAL_CA
},
477 { root
, IDS_WARN_REMOVE_ROOT
, IDS_WARN_REMOVE_PLURAL_ROOT
},
478 { trustedPublisher
, IDS_WARN_REMOVE_TRUSTEDPUBLISHER
,
479 IDS_WARN_REMOVE_PLURAL_TRUSTEDPUBLISHER
},
480 { disallowed
, IDS_WARN_REMOVE_DEFAULT
},
483 static const struct CertMgrStoreInfo publisherStoreList
[] = {
484 { root
, IDS_WARN_REMOVE_ROOT
, IDS_WARN_REMOVE_PLURAL_ROOT
},
485 { trustedPublisher
, IDS_WARN_REMOVE_TRUSTEDPUBLISHER
,
486 IDS_WARN_REMOVE_PLURAL_TRUSTEDPUBLISHER
},
487 { disallowed
, IDS_WARN_REMOVE_PLURAL_DEFAULT
},
492 HIMAGELIST imageList
;
495 const struct CertMgrStoreInfo
*stores
;
498 static void show_cert_stores(HWND hwnd
, DWORD dwFlags
, struct CertMgrData
*data
)
500 const struct CertMgrStoreInfo
*storeList
;
502 HWND tab
= GetDlgItem(hwnd
, IDC_MGR_STORES
);
504 if (dwFlags
& CRYPTUI_CERT_MGR_PUBLISHER_TAB
)
506 storeList
= publisherStoreList
;
507 cStores
= sizeof(publisherStoreList
) / sizeof(publisherStoreList
[0]);
511 storeList
= defaultStoreList
;
512 cStores
= sizeof(defaultStoreList
) / sizeof(defaultStoreList
[0]);
514 if (dwFlags
& CRYPTUI_CERT_MGR_SINGLE_TAB_FLAG
)
516 data
->nStores
= cStores
;
517 data
->stores
= storeList
;
518 for (i
= 0; i
< cStores
; i
++)
524 if (!(name
= CryptFindLocalizedName(storeList
[i
].name
)))
525 name
= storeList
[i
].name
;
526 store
= CertOpenStore(CERT_STORE_PROV_SYSTEM_W
, 0, 0,
527 CERT_SYSTEM_STORE_CURRENT_USER
, storeList
[i
].name
);
528 item
.mask
= TCIF_TEXT
| TCIF_PARAM
;
529 item
.pszText
= (LPWSTR
)name
;
530 item
.lParam
= (LPARAM
)store
;
531 SendMessageW(tab
, TCM_INSERTITEMW
, i
, (LPARAM
)&item
);
535 static void free_certs(HWND lv
)
538 int items
= SendMessageW(lv
, LVM_GETITEMCOUNT
, 0, 0), i
;
540 for (i
= 0; i
< items
; i
++)
542 item
.mask
= LVIF_PARAM
;
545 SendMessageW(lv
, LVM_GETITEMW
, 0, (LPARAM
)&item
);
546 CertFreeCertificateContext((PCCERT_CONTEXT
)item
.lParam
);
550 static HCERTSTORE
cert_mgr_index_to_store(HWND tab
, int index
)
554 item
.mask
= TCIF_PARAM
;
555 SendMessageW(tab
, TCM_GETITEMW
, index
, (LPARAM
)&item
);
556 return (HCERTSTORE
)item
.lParam
;
559 static HCERTSTORE
cert_mgr_current_store(HWND hwnd
)
561 HWND tab
= GetDlgItem(hwnd
, IDC_MGR_STORES
);
563 return cert_mgr_index_to_store(tab
, SendMessageW(tab
, TCM_GETCURSEL
, 0, 0));
566 static void close_stores(HWND tab
)
568 int i
, tabs
= SendMessageW(tab
, TCM_GETITEMCOUNT
, 0, 0);
570 for (i
= 0; i
< tabs
; i
++)
571 CertCloseStore(cert_mgr_index_to_store(tab
, i
), 0);
574 static void refresh_store_certs(HWND hwnd
)
576 HWND lv
= GetDlgItem(hwnd
, IDC_MGR_CERTS
);
579 SendMessageW(lv
, LVM_DELETEALLITEMS
, 0, 0);
580 show_store_certs(hwnd
, cert_mgr_current_store(hwnd
));
584 CheckBitmapIndexUnchecked
= 1,
585 CheckBitmapIndexChecked
= 2,
586 CheckBitmapIndexDisabledUnchecked
= 3,
587 CheckBitmapIndexDisabledChecked
= 4
590 static void add_known_usage(HWND lv
, PCCRYPT_OID_INFO info
,
591 CheckBitmapIndex state
)
595 item
.mask
= LVIF_TEXT
| LVIF_STATE
| LVIF_PARAM
;
596 item
.state
= INDEXTOSTATEIMAGEMASK(state
);
597 item
.stateMask
= LVIS_STATEIMAGEMASK
;
598 item
.iItem
= SendMessageW(lv
, LVM_GETITEMCOUNT
, 0, 0);
600 item
.lParam
= (LPARAM
)info
;
601 item
.pszText
= (LPWSTR
)info
->pwszName
;
602 SendMessageW(lv
, LVM_INSERTITEMW
, 0, (LPARAM
)&item
);
605 static void add_known_usages_to_list(HWND lv
, CheckBitmapIndex state
)
607 PCCRYPT_OID_INFO
*usages
;
609 if (WTHelperGetKnownUsages(1, &usages
))
611 PCCRYPT_OID_INFO
*ptr
;
613 for (ptr
= usages
; *ptr
; ptr
++)
614 add_known_usage(lv
, *ptr
, state
);
615 WTHelperGetKnownUsages(2, &usages
);
619 static void toggle_usage(HWND hwnd
, int iItem
)
623 HWND lv
= GetDlgItem(hwnd
, IDC_CERTIFICATE_USAGES
);
625 item
.mask
= LVIF_STATE
;
628 item
.stateMask
= LVIS_STATEIMAGEMASK
;
629 res
= SendMessageW(lv
, LVM_GETITEMW
, 0, (LPARAM
)&item
);
632 int state
= item
.state
>> 12;
634 item
.state
= INDEXTOSTATEIMAGEMASK(
635 state
== CheckBitmapIndexChecked
? CheckBitmapIndexUnchecked
:
636 CheckBitmapIndexChecked
);
637 SendMessageW(lv
, LVM_SETITEMSTATE
, iItem
, (LPARAM
)&item
);
641 static LONG_PTR
find_oid_in_list(HWND lv
, LPCSTR oid
)
643 PCCRYPT_OID_INFO oidInfo
= CryptFindOIDInfo(CRYPT_OID_INFO_OID_KEY
,
644 (void *)oid
, CRYPT_ENHKEY_USAGE_OID_GROUP_ID
);
649 LVFINDINFOW findInfo
;
651 findInfo
.flags
= LVFI_PARAM
;
652 findInfo
.lParam
= (LPARAM
)oidInfo
;
653 ret
= SendMessageW(lv
, LVM_FINDITEMW
, -1, (LPARAM
)&findInfo
);
657 LVFINDINFOA findInfo
;
659 findInfo
.flags
= LVFI_STRING
;
661 ret
= SendMessageW(lv
, LVM_FINDITEMA
, -1, (LPARAM
)&findInfo
);
666 static void save_cert_mgr_usages(HWND hwnd
)
668 static const WCHAR keyName
[] = { 'S','o','f','t','w','a','r','e','\\','M',
669 'i','c','r','o','s','o','f','t','\\','C','r','y','p','t','o','g','r','a',
670 'p','h','y','\\','U','I','\\','C','e','r','t','m','g','r','\\','P','u',
671 'r','p','o','s','e',0 };
673 HWND lv
= GetDlgItem(hwnd
, IDC_CERTIFICATE_USAGES
);
674 int purposes
= SendMessageW(lv
, LVM_GETITEMCOUNT
, 0, 0), i
;
678 item
.mask
= LVIF_STATE
| LVIF_PARAM
;
680 item
.stateMask
= LVIS_STATEIMAGEMASK
;
681 for (i
= 0; i
< purposes
; i
++)
684 if (SendMessageW(lv
, LVM_GETITEMW
, 0, (LPARAM
)&item
))
686 int state
= item
.state
>> 12;
688 if (state
== CheckBitmapIndexUnchecked
)
690 CRYPT_OID_INFO
*info
= (CRYPT_OID_INFO
*)item
.lParam
;
691 BOOL firstString
= TRUE
;
694 str
= HeapAlloc(GetProcessHeap(), 0,
695 strlen(info
->pszOID
) + 1);
698 str
= HeapReAlloc(GetProcessHeap(), 0, str
,
699 strlen(str
) + 1 + strlen(info
->pszOID
) + 1);
704 LPSTR ptr
= firstString
? str
: str
+ strlen(str
);
708 strcpy(ptr
, info
->pszOID
);
713 if (!RegCreateKeyExW(HKEY_CURRENT_USER
, keyName
, 0, NULL
, 0, KEY_ALL_ACCESS
,
717 RegSetValueExA(key
, "Purpose", 0, REG_SZ
, (const BYTE
*)str
,
720 RegDeleteValueA(key
, "Purpose");
723 HeapFree(GetProcessHeap(), 0, str
);
726 static LRESULT CALLBACK
cert_mgr_advanced_dlg_proc(HWND hwnd
, UINT msg
,
727 WPARAM wp
, LPARAM lp
)
735 HWND lv
= GetDlgItem(hwnd
, IDC_CERTIFICATE_USAGES
);
736 HIMAGELIST imageList
;
737 LPSTR disabledUsages
;
739 GetWindowRect(lv
, &rc
);
740 column
.mask
= LVCF_WIDTH
;
741 column
.cx
= rc
.right
- rc
.left
;
742 SendMessageW(lv
, LVM_INSERTCOLUMNW
, 0, (LPARAM
)&column
);
743 imageList
= ImageList_Create(16, 16, ILC_COLOR4
| ILC_MASK
, 4, 0);
747 COLORREF backColor
= RGB(255, 0, 255);
749 bmp
= LoadBitmapW(hInstance
, MAKEINTRESOURCEW(IDB_CHECKS
));
750 ImageList_AddMasked(imageList
, bmp
, backColor
);
752 ImageList_SetBkColor(imageList
, CLR_NONE
);
753 SendMessageW(lv
, LVM_SETIMAGELIST
, LVSIL_STATE
, (LPARAM
)imageList
);
754 SetWindowLongPtrW(hwnd
, DWLP_USER
, (LPARAM
)imageList
);
756 add_known_usages_to_list(lv
, CheckBitmapIndexChecked
);
757 if ((disabledUsages
= get_cert_mgr_usages()))
761 for (ptr
= disabledUsages
, comma
= strchr(ptr
, ','); ptr
&& *ptr
;
762 ptr
= comma
? comma
+ 1 : NULL
,
763 comma
= ptr
? strchr(ptr
, ',') : NULL
)
769 if ((index
= find_oid_in_list(lv
, ptr
)) != -1)
770 toggle_usage(hwnd
, index
);
772 HeapFree(GetProcessHeap(), 0, disabledUsages
);
778 NMHDR
*hdr
= (NMHDR
*)lp
;
784 nm
= (NMITEMACTIVATE
*)lp
;
785 toggle_usage(hwnd
, nm
->iItem
);
786 SendMessageW(GetParent(hwnd
), PSM_CHANGED
, (WPARAM
)hwnd
, 0);
795 save_cert_mgr_usages(hwnd
);
796 ImageList_Destroy((HIMAGELIST
)GetWindowLongPtrW(hwnd
, DWLP_USER
));
797 EndDialog(hwnd
, IDOK
);
800 ImageList_Destroy((HIMAGELIST
)GetWindowLongPtrW(hwnd
, DWLP_USER
));
801 EndDialog(hwnd
, IDCANCEL
);
809 static void cert_mgr_clear_cert_selection(HWND hwnd
)
811 WCHAR empty
[] = { 0 };
813 EnableWindow(GetDlgItem(hwnd
, IDC_MGR_EXPORT
), FALSE
);
814 EnableWindow(GetDlgItem(hwnd
, IDC_MGR_REMOVE
), FALSE
);
815 EnableWindow(GetDlgItem(hwnd
, IDC_MGR_VIEW
), FALSE
);
816 SendMessageW(GetDlgItem(hwnd
, IDC_MGR_PURPOSES
), WM_SETTEXT
, 0,
818 refresh_store_certs(hwnd
);
821 static PCCERT_CONTEXT
cert_mgr_index_to_cert(HWND hwnd
, int index
)
823 PCCERT_CONTEXT cert
= NULL
;
826 item
.mask
= LVIF_PARAM
;
829 if (SendMessageW(GetDlgItem(hwnd
, IDC_MGR_CERTS
), LVM_GETITEMW
, 0,
831 cert
= (PCCERT_CONTEXT
)item
.lParam
;
835 static void show_selected_cert(HWND hwnd
, int index
)
837 PCCERT_CONTEXT cert
= cert_mgr_index_to_cert(hwnd
, index
);
841 CRYPTUI_VIEWCERTIFICATE_STRUCTW viewInfo
;
843 memset(&viewInfo
, 0, sizeof(viewInfo
));
844 viewInfo
.dwSize
= sizeof(viewInfo
);
845 viewInfo
.hwndParent
= hwnd
;
846 viewInfo
.pCertContext
= cert
;
847 /* FIXME: this should be modal */
848 CryptUIDlgViewCertificateW(&viewInfo
, NULL
);
852 static void cert_mgr_show_cert_usages(HWND hwnd
, int index
)
854 HWND text
= GetDlgItem(hwnd
, IDC_MGR_PURPOSES
);
855 PCCERT_CONTEXT cert
= cert_mgr_index_to_cert(hwnd
, index
);
856 PCERT_ENHKEY_USAGE usage
;
859 /* Get enhanced key usage. Have to check for a property and an extension
860 * separately, because CertGetEnhancedKeyUsage will succeed and return an
861 * empty usage if neither is set. Unfortunately an empty usage implies
862 * no usage is allowed, so we have to distinguish between the two cases.
864 if (CertGetEnhancedKeyUsage(cert
, CERT_FIND_PROP_ONLY_ENHKEY_USAGE_FLAG
,
867 usage
= HeapAlloc(GetProcessHeap(), 0, size
);
868 if (!CertGetEnhancedKeyUsage(cert
,
869 CERT_FIND_PROP_ONLY_ENHKEY_USAGE_FLAG
, usage
, &size
))
871 HeapFree(GetProcessHeap(), 0, usage
);
875 else if (CertGetEnhancedKeyUsage(cert
, CERT_FIND_EXT_ONLY_ENHKEY_USAGE_FLAG
,
878 usage
= HeapAlloc(GetProcessHeap(), 0, size
);
879 if (!CertGetEnhancedKeyUsage(cert
,
880 CERT_FIND_EXT_ONLY_ENHKEY_USAGE_FLAG
, usage
, &size
))
882 HeapFree(GetProcessHeap(), 0, usage
);
890 if (usage
->cUsageIdentifier
)
892 static const WCHAR commaSpace
[] = { ',',' ',0 };
896 for (i
= 0; i
< usage
->cUsageIdentifier
; i
++)
898 PCCRYPT_OID_INFO info
=
899 CryptFindOIDInfo(CRYPT_OID_INFO_OID_KEY
,
900 usage
->rgpszUsageIdentifier
[i
],
901 CRYPT_ENHKEY_USAGE_OID_GROUP_ID
);
904 len
+= strlenW(info
->pwszName
);
906 len
+= strlen(usage
->rgpszUsageIdentifier
[i
]);
907 if (i
< usage
->cUsageIdentifier
- 1)
908 len
+= strlenW(commaSpace
);
910 str
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
913 for (i
= 0, ptr
= str
; i
< usage
->cUsageIdentifier
; i
++)
915 PCCRYPT_OID_INFO info
=
916 CryptFindOIDInfo(CRYPT_OID_INFO_OID_KEY
,
917 usage
->rgpszUsageIdentifier
[i
],
918 CRYPT_ENHKEY_USAGE_OID_GROUP_ID
);
922 strcpyW(ptr
, info
->pwszName
);
923 ptr
+= strlenW(info
->pwszName
);
927 LPCSTR src
= usage
->rgpszUsageIdentifier
[i
];
929 for (; *src
; ptr
++, src
++)
933 if (i
< usage
->cUsageIdentifier
- 1)
935 strcpyW(ptr
, commaSpace
);
936 ptr
+= strlenW(commaSpace
);
940 SendMessageW(text
, WM_SETTEXT
, 0, (LPARAM
)str
);
941 HeapFree(GetProcessHeap(), 0, str
);
943 HeapFree(GetProcessHeap(), 0, usage
);
947 WCHAR buf
[MAX_STRING_LEN
];
949 LoadStringW(hInstance
, IDS_ALLOWED_PURPOSE_NONE
, buf
,
950 sizeof(buf
) / sizeof(buf
[0]));
951 SendMessageW(text
, WM_SETTEXT
, 0, (LPARAM
)buf
);
956 WCHAR buf
[MAX_STRING_LEN
];
958 LoadStringW(hInstance
, IDS_ALLOWED_PURPOSE_ALL
, buf
,
959 sizeof(buf
) / sizeof(buf
[0]));
960 SendMessageW(text
, WM_SETTEXT
, 0, (LPARAM
)buf
);
964 static void cert_mgr_do_remove(HWND hwnd
)
966 int tabIndex
= SendMessageW(GetDlgItem(hwnd
, IDC_MGR_STORES
),
967 TCM_GETCURSEL
, 0, 0);
968 struct CertMgrData
*data
=
969 (struct CertMgrData
*)GetWindowLongPtrW(hwnd
, DWLP_USER
);
971 if (tabIndex
< data
->nStores
)
973 HWND lv
= GetDlgItem(hwnd
, IDC_MGR_CERTS
);
974 WCHAR warning
[MAX_STRING_LEN
], title
[MAX_STRING_LEN
];
978 if (SendMessageW(lv
, LVM_GETSELECTEDCOUNT
, 0, 0) > 1)
979 warningID
= data
->stores
[tabIndex
].removePluralWarning
;
981 warningID
= data
->stores
[tabIndex
].removeWarning
;
983 pTitle
= data
->title
;
986 LoadStringW(hInstance
, IDS_CERT_MGR
, title
,
987 sizeof(title
) / sizeof(title
[0]));
990 LoadStringW(hInstance
, warningID
, warning
,
991 sizeof(warning
) / sizeof(warning
[0]));
992 if (MessageBoxW(hwnd
, warning
, pTitle
, MB_YESNO
) == IDYES
)
997 selection
= SendMessageW(lv
, LVM_GETNEXTITEM
, selection
,
1001 PCCERT_CONTEXT cert
= cert_mgr_index_to_cert(hwnd
,
1004 CertDeleteCertificateFromStore(cert
);
1006 } while (selection
>= 0);
1007 cert_mgr_clear_cert_selection(hwnd
);
1012 static void cert_mgr_do_export(HWND hwnd
)
1014 HWND lv
= GetDlgItem(hwnd
, IDC_MGR_CERTS
);
1015 int selectionCount
= SendMessageW(lv
, LVM_GETSELECTEDCOUNT
, 0, 0);
1017 if (selectionCount
== 1)
1019 int selection
= SendMessageW(lv
, LVM_GETNEXTITEM
, -1,
1024 PCCERT_CONTEXT cert
= cert_mgr_index_to_cert(hwnd
, selection
);
1028 CRYPTUI_WIZ_EXPORT_INFO info
;
1030 info
.dwSize
= sizeof(info
);
1031 info
.pwszExportFileName
= NULL
;
1032 info
.dwSubjectChoice
= CRYPTUI_WIZ_EXPORT_CERT_CONTEXT
;
1033 info
.u
.pCertContext
= cert
;
1035 CryptUIWizExport(0, hwnd
, NULL
, &info
, NULL
);
1039 else if (selectionCount
> 1)
1041 HCERTSTORE store
= CertOpenStore(CERT_STORE_PROV_MEMORY
, 0, 0,
1042 CERT_STORE_CREATE_NEW_FLAG
, NULL
);
1046 CRYPTUI_WIZ_EXPORT_INFO info
;
1049 info
.dwSize
= sizeof(info
);
1050 info
.pwszExportFileName
= NULL
;
1051 info
.dwSubjectChoice
=
1052 CRYPTUI_WIZ_EXPORT_CERT_STORE_CERTIFICATES_ONLY
;
1053 info
.u
.hCertStore
= store
;
1056 selection
= SendMessageW(lv
, LVM_GETNEXTITEM
, selection
,
1060 PCCERT_CONTEXT cert
= cert_mgr_index_to_cert(hwnd
,
1063 CertAddCertificateContextToStore(store
, cert
,
1064 CERT_STORE_ADD_ALWAYS
, NULL
);
1066 } while (selection
>= 0);
1067 CryptUIWizExport(0, hwnd
, NULL
, &info
, NULL
);
1068 CertCloseStore(store
, 0);
1073 static int cert_mgr_sort_by_text(HWND lv
, int col
, int index1
, int index2
)
1076 WCHAR buf1
[MAX_STRING_LEN
];
1077 WCHAR buf2
[MAX_STRING_LEN
];
1079 item
.cchTextMax
= sizeof(buf1
) / sizeof(buf1
[0]);
1080 item
.mask
= LVIF_TEXT
;
1081 item
.pszText
= buf1
;
1082 item
.iItem
= index1
;
1083 item
.iSubItem
= col
;
1084 SendMessageW(lv
, LVM_GETITEMW
, 0, (LPARAM
)&item
);
1085 item
.pszText
= buf2
;
1086 item
.iItem
= index2
;
1087 SendMessageW(lv
, LVM_GETITEMW
, 0, (LPARAM
)&item
);
1088 return strcmpW(buf1
, buf2
);
1091 static int CALLBACK
cert_mgr_sort_by_subject(LPARAM lp1
, LPARAM lp2
, LPARAM lp
)
1093 return cert_mgr_sort_by_text((HWND
)lp
, 0, lp1
, lp2
);
1096 static int CALLBACK
cert_mgr_sort_by_issuer(LPARAM lp1
, LPARAM lp2
, LPARAM lp
)
1098 return cert_mgr_sort_by_text((HWND
)lp
, 1, lp1
, lp2
);
1101 static int CALLBACK
cert_mgr_sort_by_date(LPARAM lp1
, LPARAM lp2
, LPARAM lp
)
1103 PCCERT_CONTEXT cert1
= (PCCERT_CONTEXT
)lp1
;
1104 PCCERT_CONTEXT cert2
= (PCCERT_CONTEXT
)lp2
;
1105 return CompareFileTime(&cert1
->pCertInfo
->NotAfter
,
1106 &cert2
->pCertInfo
->NotAfter
);
1109 static int CALLBACK
cert_mgr_sort_by_friendly_name(LPARAM lp1
, LPARAM lp2
,
1112 return cert_mgr_sort_by_text((HWND
)lp
, 3, lp1
, lp2
);
1115 static LRESULT CALLBACK
cert_mgr_dlg_proc(HWND hwnd
, UINT msg
, WPARAM wp
,
1118 struct CertMgrData
*data
;
1124 PCCRYPTUI_CERT_MGR_STRUCT pCryptUICertMgr
=
1125 (PCCRYPTUI_CERT_MGR_STRUCT
)lp
;
1126 HWND tab
= GetDlgItem(hwnd
, IDC_MGR_STORES
);
1128 data
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct CertMgrData
));
1131 data
->imageList
= ImageList_Create(16, 16, ILC_COLOR4
| ILC_MASK
, 2, 0);
1132 if (data
->imageList
)
1135 COLORREF backColor
= RGB(255, 0, 255);
1137 bmp
= LoadBitmapW(hInstance
, MAKEINTRESOURCEW(IDB_SMALL_ICONS
));
1138 ImageList_AddMasked(data
->imageList
, bmp
, backColor
);
1140 ImageList_SetBkColor(data
->imageList
, CLR_NONE
);
1141 SendMessageW(GetDlgItem(hwnd
, IDC_MGR_CERTS
), LVM_SETIMAGELIST
,
1142 LVSIL_SMALL
, (LPARAM
)data
->imageList
);
1144 SetWindowLongPtrW(hwnd
, DWLP_USER
, (LPARAM
)data
);
1145 data
->title
= pCryptUICertMgr
->pwszTitle
;
1147 initialize_purpose_selection(hwnd
);
1148 add_cert_columns(hwnd
);
1149 if (pCryptUICertMgr
->pwszTitle
)
1150 SendMessageW(hwnd
, WM_SETTEXT
, 0,
1151 (LPARAM
)pCryptUICertMgr
->pwszTitle
);
1152 show_cert_stores(hwnd
, pCryptUICertMgr
->dwFlags
, data
);
1153 show_store_certs(hwnd
, cert_mgr_index_to_store(tab
, 0));
1158 NMHDR
*hdr
= (NMHDR
*)lp
;
1163 cert_mgr_clear_cert_selection(hwnd
);
1165 case LVN_ITEMCHANGED
:
1167 WCHAR empty
[] = { 0 };
1168 NMITEMACTIVATE
*nm
= (NMITEMACTIVATE
*)lp
;
1169 HWND lv
= GetDlgItem(hwnd
, IDC_MGR_CERTS
);
1170 int numSelected
= SendMessageW(lv
, LVM_GETSELECTEDCOUNT
, 0, 0);
1172 EnableWindow(GetDlgItem(hwnd
, IDC_MGR_EXPORT
), numSelected
> 0);
1173 EnableWindow(GetDlgItem(hwnd
, IDC_MGR_REMOVE
), numSelected
> 0);
1174 EnableWindow(GetDlgItem(hwnd
, IDC_MGR_VIEW
), numSelected
== 1);
1175 if (numSelected
== 1)
1176 cert_mgr_show_cert_usages(hwnd
, nm
->iItem
);
1178 SendMessageW(GetDlgItem(hwnd
, IDC_MGR_PURPOSES
), WM_SETTEXT
, 0,
1183 show_selected_cert(hwnd
, ((NMITEMACTIVATE
*)lp
)->iItem
);
1187 NMLVKEYDOWN
*lvk
= (NMLVKEYDOWN
*)lp
;
1189 if (lvk
->wVKey
== VK_DELETE
)
1190 cert_mgr_do_remove(hwnd
);
1193 case LVN_COLUMNCLICK
:
1195 NMLISTVIEW
*nmlv
= (NMLISTVIEW
*)lp
;
1196 HWND lv
= GetDlgItem(hwnd
, IDC_MGR_CERTS
);
1198 /* FIXME: doesn't support swapping sort order between ascending
1201 switch (nmlv
->iSubItem
)
1204 SendMessageW(lv
, LVM_SORTITEMSEX
, (WPARAM
)lv
,
1205 (LPARAM
)cert_mgr_sort_by_subject
);
1208 SendMessageW(lv
, LVM_SORTITEMSEX
, (WPARAM
)lv
,
1209 (LPARAM
)cert_mgr_sort_by_issuer
);
1212 SendMessageW(lv
, LVM_SORTITEMS
, 0,
1213 (LPARAM
)cert_mgr_sort_by_date
);
1216 SendMessageW(lv
, LVM_SORTITEMSEX
, (WPARAM
)lv
,
1217 (LPARAM
)cert_mgr_sort_by_friendly_name
);
1228 case ((CBN_SELCHANGE
<< 16) | IDC_MGR_PURPOSE_SELECTION
):
1229 cert_mgr_clear_cert_selection(hwnd
);
1231 case IDC_MGR_IMPORT
:
1232 if (CryptUIWizImport(0, hwnd
, NULL
, NULL
,
1233 cert_mgr_current_store(hwnd
)))
1234 refresh_store_certs(hwnd
);
1236 case IDC_MGR_ADVANCED
:
1237 if (DialogBoxW(hInstance
, MAKEINTRESOURCEW(IDD_CERT_MGR_ADVANCED
),
1238 hwnd
, cert_mgr_advanced_dlg_proc
) == IDOK
)
1240 HWND cb
= GetDlgItem(hwnd
, IDC_MGR_PURPOSE_SELECTION
);
1242 LPWSTR curString
= NULL
;
1244 index
= SendMessageW(cb
, CB_GETCURSEL
, 0, 0);
1247 len
= SendMessageW(cb
, CB_GETLBTEXTLEN
, index
, 0);
1248 curString
= HeapAlloc(GetProcessHeap(), 0,
1249 (len
+ 1) * sizeof(WCHAR
));
1250 SendMessageW(cb
, CB_GETLBTEXT
, index
, (LPARAM
)curString
);
1252 SendMessageW(cb
, CB_RESETCONTENT
, 0, 0);
1253 initialize_purpose_selection(hwnd
);
1256 index
= SendMessageW(cb
, CB_FINDSTRINGEXACT
, -1,
1259 SendMessageW(cb
, CB_SETCURSEL
, index
, 0);
1260 HeapFree(GetProcessHeap(), 0, curString
);
1262 refresh_store_certs(hwnd
);
1267 HWND lv
= GetDlgItem(hwnd
, IDC_MGR_CERTS
);
1268 int selection
= SendMessageW(lv
, LVM_GETNEXTITEM
, -1,
1272 show_selected_cert(hwnd
, selection
);
1275 case IDC_MGR_EXPORT
:
1276 cert_mgr_do_export(hwnd
);
1278 case IDC_MGR_REMOVE
:
1279 cert_mgr_do_remove(hwnd
);
1282 free_certs(GetDlgItem(hwnd
, IDC_MGR_CERTS
));
1283 close_stores(GetDlgItem(hwnd
, IDC_MGR_STORES
));
1284 data
= (struct CertMgrData
*)GetWindowLongPtrW(hwnd
, DWLP_USER
);
1285 ImageList_Destroy(data
->imageList
);
1286 HeapFree(GetProcessHeap(), 0, data
);
1287 EndDialog(hwnd
, IDCANCEL
);
1295 /***********************************************************************
1296 * CryptUIDlgCertMgr (CRYPTUI.@)
1298 BOOL WINAPI
CryptUIDlgCertMgr(PCCRYPTUI_CERT_MGR_STRUCT pCryptUICertMgr
)
1300 TRACE("(%p)\n", pCryptUICertMgr
);
1302 if (pCryptUICertMgr
->dwSize
!= sizeof(CRYPTUI_CERT_MGR_STRUCT
))
1304 WARN("unexpected size %d\n", pCryptUICertMgr
->dwSize
);
1305 SetLastError(E_INVALIDARG
);
1308 DialogBoxParamW(hInstance
, MAKEINTRESOURCEW(IDD_CERT_MGR
),
1309 pCryptUICertMgr
->hwndParent
, cert_mgr_dlg_proc
, (LPARAM
)pCryptUICertMgr
);
1313 /* FIXME: real names are unknown, functions are undocumented */
1314 typedef struct _CRYPTUI_ENUM_SYSTEM_STORE_ARGS
1317 void *pvSystemStoreLocationPara
;
1318 } CRYPTUI_ENUM_SYSTEM_STORE_ARGS
, *PCRYPTUI_ENUM_SYSTEM_STORE_ARGS
;
1320 typedef struct _CRYPTUI_ENUM_DATA
1323 HCERTSTORE
*rghStore
;
1325 PCRYPTUI_ENUM_SYSTEM_STORE_ARGS rgEnumArgs
;
1326 } CRYPTUI_ENUM_DATA
, *PCRYPTUI_ENUM_DATA
;
1328 typedef BOOL (WINAPI
*PFN_SELECTED_STORE_CB
)(HCERTSTORE store
, HWND hwnd
,
1331 /* Values for dwFlags */
1332 #define CRYPTUI_ENABLE_SHOW_PHYSICAL_STORE 0x00000001
1334 typedef struct _CRYPTUI_SELECTSTORE_INFO_A
1341 CRYPTUI_ENUM_DATA
*pEnumData
;
1342 PFN_SELECTED_STORE_CB pfnSelectedStoreCallback
;
1344 } CRYPTUI_SELECTSTORE_INFO_A
, *PCRYPTUI_SELECTSTORE_INFO_A
;
1346 typedef struct _CRYPTUI_SELECTSTORE_INFO_W
1353 CRYPTUI_ENUM_DATA
*pEnumData
;
1354 PFN_SELECTED_STORE_CB pfnSelectedStoreCallback
;
1356 } CRYPTUI_SELECTSTORE_INFO_W
, *PCRYPTUI_SELECTSTORE_INFO_W
;
1370 static BOOL WINAPI
enum_store_callback(const void *pvSystemStore
,
1371 DWORD dwFlags
, PCERT_SYSTEM_STORE_INFO pStoreInfo
, void *pvReserved
,
1374 HWND tree
= GetDlgItem(pvArg
, IDC_STORE_LIST
);
1375 TVINSERTSTRUCTW tvis
;
1376 LPCWSTR localizedName
;
1379 tvis
.hParent
= NULL
;
1380 tvis
.hInsertAfter
= TVI_LAST
;
1381 tvis
.u
.item
.mask
= TVIF_TEXT
;
1382 if ((localizedName
= CryptFindLocalizedName(pvSystemStore
)))
1384 struct StoreInfo
*storeInfo
= HeapAlloc(GetProcessHeap(), 0,
1385 sizeof(struct StoreInfo
));
1389 storeInfo
->type
= SystemStore
;
1390 storeInfo
->u
.name
= HeapAlloc(GetProcessHeap(), 0,
1391 (strlenW(pvSystemStore
) + 1) * sizeof(WCHAR
));
1392 if (storeInfo
->u
.name
)
1394 tvis
.u
.item
.mask
|= TVIF_PARAM
;
1395 tvis
.u
.item
.lParam
= (LPARAM
)storeInfo
;
1396 strcpyW(storeInfo
->u
.name
, pvSystemStore
);
1400 HeapFree(GetProcessHeap(), 0, storeInfo
);
1406 tvis
.u
.item
.pszText
= (LPWSTR
)localizedName
;
1409 tvis
.u
.item
.pszText
= (LPWSTR
)pvSystemStore
;
1410 /* FIXME: need a folder icon for the store too */
1412 SendMessageW(tree
, TVM_INSERTITEMW
, 0, (LPARAM
)&tvis
);
1416 static void enumerate_stores(HWND hwnd
, CRYPTUI_ENUM_DATA
*pEnumData
)
1419 HWND tree
= GetDlgItem(hwnd
, IDC_STORE_LIST
);
1421 for (i
= 0; i
< pEnumData
->cEnumArgs
; i
++)
1422 CertEnumSystemStore(pEnumData
->rgEnumArgs
[i
].dwFlags
,
1423 pEnumData
->rgEnumArgs
[i
].pvSystemStoreLocationPara
,
1424 hwnd
, enum_store_callback
);
1425 for (i
= 0; i
< pEnumData
->cStores
; i
++)
1429 if (CertGetStoreProperty(pEnumData
->rghStore
[i
],
1430 CERT_STORE_LOCALIZED_NAME_PROP_ID
, NULL
, &size
))
1432 LPWSTR name
= HeapAlloc(GetProcessHeap(), 0, size
);
1436 if (CertGetStoreProperty(pEnumData
->rghStore
[i
],
1437 CERT_STORE_LOCALIZED_NAME_PROP_ID
, name
, &size
))
1439 struct StoreInfo
*storeInfo
= HeapAlloc(GetProcessHeap(),
1440 0, sizeof(struct StoreInfo
));
1444 TVINSERTSTRUCTW tvis
;
1446 storeInfo
->type
= StoreHandle
;
1447 storeInfo
->u
.store
= pEnumData
->rghStore
[i
];
1448 tvis
.hParent
= NULL
;
1449 tvis
.hInsertAfter
= TVI_LAST
;
1450 tvis
.u
.item
.mask
= TVIF_TEXT
| TVIF_PARAM
;
1451 tvis
.u
.item
.pszText
= name
;
1452 tvis
.u
.item
.lParam
= (LPARAM
)storeInfo
;
1453 SendMessageW(tree
, TVM_INSERTITEMW
, 0, (LPARAM
)&tvis
);
1456 HeapFree(GetProcessHeap(), 0, name
);
1462 static void free_store_info(HWND tree
)
1464 HTREEITEM next
= (HTREEITEM
)SendMessageW(tree
, TVM_GETNEXTITEM
, TVGN_CHILD
,
1471 memset(&item
, 0, sizeof(item
));
1472 item
.mask
= TVIF_HANDLE
| TVIF_PARAM
;
1474 SendMessageW(tree
, TVM_GETITEMW
, 0, (LPARAM
)&item
);
1477 struct StoreInfo
*storeInfo
= (struct StoreInfo
*)item
.lParam
;
1479 if (storeInfo
->type
== SystemStore
)
1480 HeapFree(GetProcessHeap(), 0, storeInfo
->u
.name
);
1481 HeapFree(GetProcessHeap(), 0, storeInfo
);
1483 next
= (HTREEITEM
)SendMessageW(tree
, TVM_GETNEXTITEM
, TVGN_NEXT
,
1488 static HCERTSTORE
selected_item_to_store(HWND tree
, HTREEITEM hItem
)
1490 WCHAR buf
[MAX_STRING_LEN
];
1494 memset(&item
, 0, sizeof(item
));
1495 item
.mask
= TVIF_HANDLE
| TVIF_PARAM
| TVIF_TEXT
;
1497 item
.cchTextMax
= sizeof(buf
) / sizeof(buf
[0]);
1499 SendMessageW(tree
, TVM_GETITEMW
, 0, (LPARAM
)&item
);
1502 struct StoreInfo
*storeInfo
= (struct StoreInfo
*)item
.lParam
;
1504 if (storeInfo
->type
== StoreHandle
)
1505 store
= storeInfo
->u
.store
;
1507 store
= CertOpenSystemStoreW(0, storeInfo
->u
.name
);
1511 /* It's implicitly a system store */
1512 store
= CertOpenSystemStoreW(0, buf
);
1517 struct SelectStoreInfo
1519 PCRYPTUI_SELECTSTORE_INFO_W info
;
1523 static LRESULT CALLBACK
select_store_dlg_proc(HWND hwnd
, UINT msg
, WPARAM wp
,
1526 struct SelectStoreInfo
*selectInfo
;
1533 selectInfo
= (struct SelectStoreInfo
*)lp
;
1534 SetWindowLongPtrW(hwnd
, DWLP_USER
, lp
);
1535 if (selectInfo
->info
->pwszTitle
)
1536 SendMessageW(hwnd
, WM_SETTEXT
, 0,
1537 (LPARAM
)selectInfo
->info
->pwszTitle
);
1538 if (selectInfo
->info
->pwszText
)
1539 SendMessageW(GetDlgItem(hwnd
, IDC_STORE_TEXT
), WM_SETTEXT
, 0,
1540 (LPARAM
)selectInfo
->info
->pwszText
);
1541 if (!(selectInfo
->info
->dwFlags
& CRYPTUI_ENABLE_SHOW_PHYSICAL_STORE
))
1542 ShowWindow(GetDlgItem(hwnd
, IDC_SHOW_PHYSICAL_STORES
), FALSE
);
1543 enumerate_stores(hwnd
, selectInfo
->info
->pEnumData
);
1551 HWND tree
= GetDlgItem(hwnd
, IDC_STORE_LIST
);
1552 HTREEITEM selection
= (HTREEITEM
)SendMessageW(tree
,
1553 TVM_GETNEXTITEM
, TVGN_CARET
, 0);
1555 selectInfo
= (struct SelectStoreInfo
*)GetWindowLongPtrW(hwnd
,
1559 WCHAR title
[MAX_STRING_LEN
], error
[MAX_STRING_LEN
], *pTitle
;
1561 if (selectInfo
->info
->pwszTitle
)
1562 pTitle
= selectInfo
->info
->pwszTitle
;
1565 LoadStringW(hInstance
, IDS_SELECT_STORE_TITLE
, title
,
1566 sizeof(title
) / sizeof(title
[0]));
1569 LoadStringW(hInstance
, IDS_SELECT_STORE
, error
,
1570 sizeof(error
) / sizeof(error
[0]));
1571 MessageBoxW(hwnd
, error
, pTitle
, MB_ICONEXCLAMATION
| MB_OK
);
1575 HCERTSTORE store
= selected_item_to_store(tree
, selection
);
1577 if (!selectInfo
->info
->pfnSelectedStoreCallback
||
1578 selectInfo
->info
->pfnSelectedStoreCallback(store
, hwnd
,
1579 selectInfo
->info
->pvArg
))
1581 selectInfo
->store
= store
;
1582 free_store_info(tree
);
1583 EndDialog(hwnd
, IDOK
);
1586 CertCloseStore(store
, 0);
1592 free_store_info(GetDlgItem(hwnd
, IDC_STORE_LIST
));
1593 EndDialog(hwnd
, IDCANCEL
);
1602 /***********************************************************************
1603 * CryptUIDlgSelectStoreW (CRYPTUI.@)
1605 HCERTSTORE WINAPI
CryptUIDlgSelectStoreW(PCRYPTUI_SELECTSTORE_INFO_W info
)
1607 struct SelectStoreInfo selectInfo
= { info
, NULL
};
1609 TRACE("(%p)\n", info
);
1611 if (info
->dwSize
!= sizeof(CRYPTUI_SELECTSTORE_INFO_W
))
1613 WARN("unexpected size %d\n", info
->dwSize
);
1614 SetLastError(E_INVALIDARG
);
1617 DialogBoxParamW(hInstance
, MAKEINTRESOURCEW(IDD_SELECT_STORE
), info
->parent
,
1618 select_store_dlg_proc
, (LPARAM
)&selectInfo
);
1619 return selectInfo
.store
;
1622 /***********************************************************************
1623 * CryptUIDlgSelectStoreA (CRYPTUI.@)
1625 HCERTSTORE WINAPI
CryptUIDlgSelectStoreA(PCRYPTUI_SELECTSTORE_INFO_A info
)
1627 CRYPTUI_SELECTSTORE_INFO_W infoW
;
1631 TRACE("(%p)\n", info
);
1633 if (info
->dwSize
!= sizeof(CRYPTUI_SELECTSTORE_INFO_A
))
1635 WARN("unexpected size %d\n", info
->dwSize
);
1636 SetLastError(E_INVALIDARG
);
1639 memcpy(&infoW
, info
, sizeof(*info
));
1642 len
= MultiByteToWideChar(CP_ACP
, 0, info
->pszTitle
, -1, NULL
, 0);
1643 infoW
.pwszTitle
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1644 MultiByteToWideChar(CP_ACP
, 0, info
->pszTitle
, -1, infoW
.pwszTitle
,
1649 len
= MultiByteToWideChar(CP_ACP
, 0, info
->pszText
, -1, NULL
, 0);
1650 infoW
.pwszText
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1651 MultiByteToWideChar(CP_ACP
, 0, info
->pszText
, -1, infoW
.pwszText
, len
);
1653 ret
= CryptUIDlgSelectStoreW(&infoW
);
1654 HeapFree(GetProcessHeap(), 0, infoW
.pwszText
);
1655 HeapFree(GetProcessHeap(), 0, infoW
.pwszTitle
);
1659 /***********************************************************************
1660 * CryptUIDlgViewCertificateA (CRYPTUI.@)
1662 BOOL WINAPI
CryptUIDlgViewCertificateA(
1663 PCCRYPTUI_VIEWCERTIFICATE_STRUCTA pCertViewInfo
, BOOL
*pfPropertiesChanged
)
1665 CRYPTUI_VIEWCERTIFICATE_STRUCTW viewInfo
;
1666 LPWSTR title
= NULL
;
1669 TRACE("(%p, %p)\n", pCertViewInfo
, pfPropertiesChanged
);
1671 memcpy(&viewInfo
, pCertViewInfo
, sizeof(viewInfo
));
1672 if (pCertViewInfo
->szTitle
)
1674 int len
= MultiByteToWideChar(CP_ACP
, 0, pCertViewInfo
->szTitle
, -1,
1677 title
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1680 MultiByteToWideChar(CP_ACP
, 0, pCertViewInfo
->szTitle
, -1, title
,
1682 viewInfo
.szTitle
= title
;
1690 if (pCertViewInfo
->cPropSheetPages
)
1692 FIXME("ignoring additional prop sheet pages\n");
1693 viewInfo
.cPropSheetPages
= 0;
1695 ret
= CryptUIDlgViewCertificateW(&viewInfo
, pfPropertiesChanged
);
1696 HeapFree(GetProcessHeap(), 0, title
);
1701 struct ReadStringStruct
1708 static DWORD CALLBACK
read_text_callback(DWORD_PTR dwCookie
, LPBYTE buf
,
1711 struct ReadStringStruct
*string
= (struct ReadStringStruct
*)dwCookie
;
1712 LONG cch
= min(cb
/ sizeof(WCHAR
), string
->len
- string
->pos
);
1714 TRACE("(%p, %p, %d, %p)\n", string
, buf
, cb
, pcb
);
1716 memmove(buf
, string
->buf
+ string
->pos
, cch
* sizeof(WCHAR
));
1718 *pcb
= cch
* sizeof(WCHAR
);
1722 static void add_unformatted_text_to_control(HWND hwnd
, LPCWSTR text
, LONG len
)
1724 struct ReadStringStruct string
;
1725 EDITSTREAM editstream
;
1727 TRACE("(%p, %s)\n", hwnd
, debugstr_wn(text
, len
));
1732 editstream
.dwCookie
= (DWORD_PTR
)&string
;
1733 editstream
.dwError
= 0;
1734 editstream
.pfnCallback
= read_text_callback
;
1735 SendMessageW(hwnd
, EM_STREAMIN
, SF_TEXT
| SFF_SELECTION
| SF_UNICODE
,
1736 (LPARAM
)&editstream
);
1739 static void add_string_resource_to_control(HWND hwnd
, int id
)
1744 len
= LoadStringW(hInstance
, id
, (LPWSTR
)&str
, 0);
1745 add_unformatted_text_to_control(hwnd
, str
, len
);
1748 static void add_text_with_paraformat_to_control(HWND hwnd
, LPCWSTR text
,
1749 LONG len
, const PARAFORMAT2
*fmt
)
1751 add_unformatted_text_to_control(hwnd
, text
, len
);
1752 SendMessageW(hwnd
, EM_SETPARAFORMAT
, 0, (LPARAM
)fmt
);
1755 static void add_string_resource_with_paraformat_to_control(HWND hwnd
, int id
,
1756 const PARAFORMAT2
*fmt
)
1761 len
= LoadStringW(hInstance
, id
, (LPWSTR
)&str
, 0);
1762 add_text_with_paraformat_to_control(hwnd
, str
, len
, fmt
);
1765 static LPWSTR
get_cert_name_string(PCCERT_CONTEXT pCertContext
, DWORD dwType
,
1771 len
= CertGetNameStringW(pCertContext
, dwType
, dwFlags
, NULL
, NULL
, 0);
1774 buf
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1776 CertGetNameStringW(pCertContext
, dwType
, dwFlags
, NULL
, buf
, len
);
1781 static void add_cert_string_to_control(HWND hwnd
, PCCERT_CONTEXT pCertContext
,
1782 DWORD dwType
, DWORD dwFlags
)
1784 LPWSTR name
= get_cert_name_string(pCertContext
, dwType
, dwFlags
);
1788 /* Don't include NULL-terminator in output */
1789 DWORD len
= lstrlenW(name
);
1791 add_unformatted_text_to_control(hwnd
, name
, len
);
1792 HeapFree(GetProcessHeap(), 0, name
);
1796 static void add_icon_to_control(HWND hwnd
, int id
)
1799 LPRICHEDITOLE richEditOle
= NULL
;
1800 LPOLEOBJECT object
= NULL
;
1802 LPOLECACHE oleCache
= NULL
;
1803 FORMATETC formatEtc
;
1805 LPDATAOBJECT dataObject
= NULL
;
1806 HBITMAP bitmap
= NULL
;
1809 LPOLECLIENTSITE clientSite
= NULL
;
1812 TRACE("(%p, %d)\n", hwnd
, id
);
1814 SendMessageW(hwnd
, EM_GETOLEINTERFACE
, 0, (LPARAM
)&richEditOle
);
1817 hr
= OleCreateDefaultHandler(&CLSID_NULL
, NULL
, &IID_IOleObject
,
1821 hr
= IOleObject_GetUserClassID(object
, &clsid
);
1824 hr
= IOleObject_QueryInterface(object
, &IID_IOleCache
, (void**)&oleCache
);
1827 formatEtc
.cfFormat
= CF_BITMAP
;
1828 formatEtc
.ptd
= NULL
;
1829 formatEtc
.dwAspect
= DVASPECT_CONTENT
;
1830 formatEtc
.lindex
= -1;
1831 formatEtc
.tymed
= TYMED_GDI
;
1832 hr
= IOleCache_Cache(oleCache
, &formatEtc
, 0, &conn
);
1835 hr
= IOleObject_QueryInterface(object
, &IID_IDataObject
,
1836 (void**)&dataObject
);
1839 hr
= IRichEditOle_GetClientSite(richEditOle
, &clientSite
);
1842 bitmap
= LoadImageW(hInstance
, MAKEINTRESOURCEW(id
), IMAGE_BITMAP
, 0, 0,
1843 LR_DEFAULTSIZE
| LR_LOADTRANSPARENT
);
1846 rect
.left
= rect
.top
= 0;
1847 rect
.right
= GetSystemMetrics(SM_CXICON
);
1848 rect
.bottom
= GetSystemMetrics(SM_CYICON
);
1849 stgm
.tymed
= TYMED_GDI
;
1850 stgm
.u
.hBitmap
= bitmap
;
1851 stgm
.pUnkForRelease
= NULL
;
1852 hr
= IDataObject_SetData(dataObject
, &formatEtc
, &stgm
, TRUE
);
1856 reObject
.cbStruct
= sizeof(reObject
);
1857 reObject
.cp
= REO_CP_SELECTION
;
1858 reObject
.clsid
= clsid
;
1859 reObject
.poleobj
= object
;
1860 reObject
.pstg
= NULL
;
1861 reObject
.polesite
= clientSite
;
1862 reObject
.sizel
.cx
= reObject
.sizel
.cy
= 0;
1863 reObject
.dvaspect
= DVASPECT_CONTENT
;
1864 reObject
.dwFlags
= 0;
1865 reObject
.dwUser
= 0;
1867 IRichEditOle_InsertObject(richEditOle
, &reObject
);
1871 IOleClientSite_Release(clientSite
);
1873 IDataObject_Release(dataObject
);
1875 IOleCache_Release(oleCache
);
1877 IOleObject_Release(object
);
1879 IRichEditOle_Release(richEditOle
);
1882 #define MY_INDENT 200
1884 static void add_oid_text_to_control(HWND hwnd
, char *oid
)
1887 PCCRYPT_OID_INFO oidInfo
= CryptFindOIDInfo(CRYPT_OID_INFO_OID_KEY
, oid
, 0);
1890 parFmt
.cbSize
= sizeof(parFmt
);
1891 parFmt
.dwMask
= PFM_STARTINDENT
;
1892 parFmt
.dxStartIndent
= MY_INDENT
* 3;
1895 add_text_with_paraformat_to_control(hwnd
, oidInfo
->pwszName
,
1896 lstrlenW(oidInfo
->pwszName
), &parFmt
);
1897 add_unformatted_text_to_control(hwnd
, &nl
, 1);
1907 /* The following list MUST be lexicographically sorted by OID */
1908 static struct OIDToString oidMap
[] = {
1909 /* 1.3.6.1.4.1.311.10.3.1 */
1910 { szOID_KP_CTL_USAGE_SIGNING
, IDS_PURPOSE_CTL_USAGE_SIGNING
},
1911 /* 1.3.6.1.4.1.311.10.3.4 */
1912 { szOID_KP_EFS
, IDS_PURPOSE_EFS
},
1913 /* 1.3.6.1.4.1.311.10.3.4.1 */
1914 { szOID_EFS_RECOVERY
, IDS_PURPOSE_EFS_RECOVERY
},
1915 /* 1.3.6.1.4.1.311.10.3.5 */
1916 { szOID_WHQL_CRYPTO
, IDS_PURPOSE_WHQL
},
1917 /* 1.3.6.1.4.1.311.10.3.6 */
1918 { szOID_NT5_CRYPTO
, IDS_PURPOSE_NT5
},
1919 /* 1.3.6.1.4.1.311.10.3.7 */
1920 { szOID_OEM_WHQL_CRYPTO
, IDS_PURPOSE_OEM_WHQL
},
1921 /* 1.3.6.1.4.1.311.10.3.8 */
1922 { szOID_EMBEDDED_NT_CRYPTO
, IDS_PURPOSE_EMBEDDED_NT
},
1923 /* 1.3.6.1.4.1.311.10.3.9 */
1924 { szOID_ROOT_LIST_SIGNER
, IDS_PURPOSE_ROOT_LIST_SIGNER
},
1925 /* 1.3.6.1.4.1.311.10.3.10 */
1926 { szOID_KP_QUALIFIED_SUBORDINATION
, IDS_PURPOSE_QUALIFIED_SUBORDINATION
},
1927 /* 1.3.6.1.4.1.311.10.3.11 */
1928 { szOID_KP_KEY_RECOVERY
, IDS_PURPOSE_KEY_RECOVERY
},
1929 /* 1.3.6.1.4.1.311.10.3.12 */
1930 { szOID_KP_DOCUMENT_SIGNING
, IDS_PURPOSE_DOCUMENT_SIGNING
},
1931 /* 1.3.6.1.4.1.311.10.3.13 */
1932 { szOID_KP_LIFETIME_SIGNING
, IDS_PURPOSE_LIFETIME_SIGNING
},
1933 /* 1.3.6.1.4.1.311.10.5.1 */
1934 { szOID_DRM
, IDS_PURPOSE_DRM
},
1935 /* 1.3.6.1.4.1.311.10.6.1 */
1936 { szOID_LICENSES
, IDS_PURPOSE_LICENSES
},
1937 /* 1.3.6.1.4.1.311.10.6.2 */
1938 { szOID_LICENSE_SERVER
, IDS_PURPOSE_LICENSE_SERVER
},
1939 /* 1.3.6.1.4.1.311.20.2.1 */
1940 { szOID_ENROLLMENT_AGENT
, IDS_PURPOSE_ENROLLMENT_AGENT
},
1941 /* 1.3.6.1.4.1.311.20.2.2 */
1942 { szOID_KP_SMARTCARD_LOGON
, IDS_PURPOSE_SMARTCARD_LOGON
},
1943 /* 1.3.6.1.4.1.311.21.5 */
1944 { szOID_KP_CA_EXCHANGE
, IDS_PURPOSE_CA_EXCHANGE
},
1945 /* 1.3.6.1.4.1.311.21.6 */
1946 { szOID_KP_KEY_RECOVERY_AGENT
, IDS_PURPOSE_KEY_RECOVERY_AGENT
},
1947 /* 1.3.6.1.4.1.311.21.19 */
1948 { szOID_DS_EMAIL_REPLICATION
, IDS_PURPOSE_DS_EMAIL_REPLICATION
},
1949 /* 1.3.6.1.5.5.7.3.1 */
1950 { szOID_PKIX_KP_SERVER_AUTH
, IDS_PURPOSE_SERVER_AUTH
},
1951 /* 1.3.6.1.5.5.7.3.2 */
1952 { szOID_PKIX_KP_CLIENT_AUTH
, IDS_PURPOSE_CLIENT_AUTH
},
1953 /* 1.3.6.1.5.5.7.3.3 */
1954 { szOID_PKIX_KP_CODE_SIGNING
, IDS_PURPOSE_CODE_SIGNING
},
1955 /* 1.3.6.1.5.5.7.3.4 */
1956 { szOID_PKIX_KP_EMAIL_PROTECTION
, IDS_PURPOSE_EMAIL_PROTECTION
},
1957 /* 1.3.6.1.5.5.7.3.5 */
1958 { szOID_PKIX_KP_IPSEC_END_SYSTEM
, IDS_PURPOSE_IPSEC
},
1959 /* 1.3.6.1.5.5.7.3.6 */
1960 { szOID_PKIX_KP_IPSEC_TUNNEL
, IDS_PURPOSE_IPSEC
},
1961 /* 1.3.6.1.5.5.7.3.7 */
1962 { szOID_PKIX_KP_IPSEC_USER
, IDS_PURPOSE_IPSEC
},
1963 /* 1.3.6.1.5.5.7.3.8 */
1964 { szOID_PKIX_KP_TIMESTAMP_SIGNING
, IDS_PURPOSE_TIMESTAMP_SIGNING
},
1967 static struct OIDToString
*findSupportedOID(LPCSTR oid
)
1969 int indexHigh
= sizeof(oidMap
) / sizeof(oidMap
[0]) - 1, indexLow
= 0, i
;
1970 struct OIDToString
*ret
= NULL
;
1972 for (i
= (indexLow
+ indexHigh
) / 2; !ret
&& indexLow
<= indexHigh
;
1973 i
= (indexLow
+ indexHigh
) / 2)
1977 cmp
= strcmp(oid
, oidMap
[i
].oid
);
1988 static void add_local_oid_text_to_control(HWND text
, LPCSTR oid
)
1990 struct OIDToString
*entry
;
1994 parFmt
.cbSize
= sizeof(parFmt
);
1995 parFmt
.dwMask
= PFM_STARTINDENT
;
1996 parFmt
.dxStartIndent
= MY_INDENT
* 3;
1997 if ((entry
= findSupportedOID(oid
)))
1999 WCHAR
*str
, *linebreak
, *ptr
;
2000 BOOL multiline
= FALSE
;
2003 len
= LoadStringW(hInstance
, entry
->id
, (LPWSTR
)&str
, 0);
2006 if ((linebreak
= memchrW(ptr
, '\n', len
)))
2008 WCHAR copy
[MAX_STRING_LEN
];
2011 /* The source string contains a newline, which the richedit
2012 * control won't find since it's interpreted as a paragraph
2013 * break. Therefore copy up to the newline. lstrcpynW always
2014 * NULL-terminates, so pass one more than the length of the
2015 * source line so the copy includes the entire line and the
2018 lstrcpynW(copy
, ptr
, linebreak
- ptr
+ 1);
2019 add_text_with_paraformat_to_control(text
, copy
,
2020 linebreak
- ptr
, &parFmt
);
2021 ptr
= linebreak
+ 1;
2022 add_unformatted_text_to_control(text
, &nl
, 1);
2024 else if (multiline
&& *ptr
)
2026 /* Add the last line */
2027 add_text_with_paraformat_to_control(text
, ptr
,
2028 len
- (ptr
- str
), &parFmt
);
2029 add_unformatted_text_to_control(text
, &nl
, 1);
2031 } while (linebreak
);
2034 add_text_with_paraformat_to_control(text
, str
, len
, &parFmt
);
2035 add_unformatted_text_to_control(text
, &nl
, 1);
2040 WCHAR
*oidW
= HeapAlloc(GetProcessHeap(), 0,
2041 (strlen(oid
) + 1) * sizeof(WCHAR
));
2048 for (src
= oid
, dst
= oidW
; *src
; src
++, dst
++)
2051 add_text_with_paraformat_to_control(text
, oidW
, lstrlenW(oidW
),
2053 add_unformatted_text_to_control(text
, &nl
, 1);
2054 HeapFree(GetProcessHeap(), 0, oidW
);
2059 static void display_app_usages(HWND text
, PCCERT_CONTEXT cert
,
2060 BOOL
*anyUsageAdded
)
2062 static char any_app_policy
[] = szOID_ANY_APPLICATION_POLICY
;
2064 CHARFORMATW charFmt
;
2065 PCERT_EXTENSION policyExt
;
2066 if (!*anyUsageAdded
)
2070 parFmt
.cbSize
= sizeof(parFmt
);
2071 parFmt
.dwMask
= PFM_STARTINDENT
;
2072 parFmt
.dxStartIndent
= MY_INDENT
;
2073 add_string_resource_with_paraformat_to_control(text
,
2074 IDS_CERT_INFO_PURPOSES
, &parFmt
);
2075 add_unformatted_text_to_control(text
, &nl
, 1);
2076 *anyUsageAdded
= TRUE
;
2078 memset(&charFmt
, 0, sizeof(charFmt
));
2079 charFmt
.cbSize
= sizeof(charFmt
);
2080 charFmt
.dwMask
= CFM_BOLD
;
2081 charFmt
.dwEffects
= 0;
2082 SendMessageW(text
, EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&charFmt
);
2083 if ((policyExt
= CertFindExtension(szOID_APPLICATION_CERT_POLICIES
,
2084 cert
->pCertInfo
->cExtension
, cert
->pCertInfo
->rgExtension
)))
2086 CERT_POLICIES_INFO
*policies
;
2089 if (CryptDecodeObjectEx(X509_ASN_ENCODING
, X509_CERT_POLICIES
,
2090 policyExt
->Value
.pbData
, policyExt
->Value
.cbData
,
2091 CRYPT_DECODE_ALLOC_FLAG
, NULL
, &policies
, &size
))
2095 for (i
= 0; i
< policies
->cPolicyInfo
; i
++)
2099 for (j
= 0; j
< policies
->rgPolicyInfo
[i
].cPolicyQualifier
; j
++)
2100 add_local_oid_text_to_control(text
,
2101 policies
->rgPolicyInfo
[i
].rgPolicyQualifier
[j
].
2102 pszPolicyQualifierId
);
2104 LocalFree(policies
);
2108 add_oid_text_to_control(text
, any_app_policy
);
2111 static BOOL
display_cert_usages(HWND text
, PCCERT_CONTEXT cert
,
2112 BOOL
*anyUsageAdded
)
2116 BOOL badUsages
= FALSE
;
2118 if (CertGetEnhancedKeyUsage(cert
, 0, NULL
, &size
))
2120 CHARFORMATW charFmt
;
2121 static char any_cert_policy
[] = szOID_ANY_CERT_POLICY
;
2122 PCERT_ENHKEY_USAGE usage
= HeapAlloc(GetProcessHeap(), 0, size
);
2126 if (CertGetEnhancedKeyUsage(cert
, 0, usage
, &size
))
2130 if (!*anyUsageAdded
)
2134 parFmt
.cbSize
= sizeof(parFmt
);
2135 parFmt
.dwMask
= PFM_STARTINDENT
;
2136 parFmt
.dxStartIndent
= MY_INDENT
;
2137 add_string_resource_with_paraformat_to_control(text
,
2138 IDS_CERT_INFO_PURPOSES
, &parFmt
);
2139 add_unformatted_text_to_control(text
, &nl
, 1);
2140 *anyUsageAdded
= TRUE
;
2142 memset(&charFmt
, 0, sizeof(charFmt
));
2143 charFmt
.cbSize
= sizeof(charFmt
);
2144 charFmt
.dwMask
= CFM_BOLD
;
2145 charFmt
.dwEffects
= 0;
2146 SendMessageW(text
, EM_SETCHARFORMAT
, SCF_SELECTION
,
2148 if (!usage
->cUsageIdentifier
)
2149 add_oid_text_to_control(text
, any_cert_policy
);
2151 for (i
= 0; i
< usage
->cUsageIdentifier
; i
++)
2152 add_local_oid_text_to_control(text
,
2153 usage
->rgpszUsageIdentifier
[i
]);
2157 HeapFree(GetProcessHeap(), 0, usage
);
2167 static void set_policy_text(HWND text
,
2168 PCCRYPTUI_VIEWCERTIFICATE_STRUCTW pCertViewInfo
)
2170 BOOL includeCertUsages
= FALSE
, includeAppUsages
= FALSE
;
2171 BOOL badUsages
= FALSE
, anyUsageAdded
= FALSE
;
2173 if (pCertViewInfo
->cPurposes
)
2177 for (i
= 0; i
< pCertViewInfo
->cPurposes
; i
++)
2179 if (!strcmp(pCertViewInfo
->rgszPurposes
[i
], szOID_ANY_CERT_POLICY
))
2180 includeCertUsages
= TRUE
;
2181 else if (!strcmp(pCertViewInfo
->rgszPurposes
[i
],
2182 szOID_ANY_APPLICATION_POLICY
))
2183 includeAppUsages
= TRUE
;
2189 includeAppUsages
= includeCertUsages
= TRUE
;
2190 if (includeAppUsages
)
2191 display_app_usages(text
, pCertViewInfo
->pCertContext
, &anyUsageAdded
);
2192 if (includeCertUsages
)
2193 badUsages
= display_cert_usages(text
, pCertViewInfo
->pCertContext
,
2199 parFmt
.cbSize
= sizeof(parFmt
);
2200 parFmt
.dwMask
= PFM_STARTINDENT
;
2201 parFmt
.dxStartIndent
= MY_INDENT
;
2202 add_string_resource_with_paraformat_to_control(text
,
2203 IDS_CERT_INFO_BAD_PURPOSES
, &parFmt
);
2207 static CRYPT_OBJID_BLOB
*find_policy_qualifier(CERT_POLICIES_INFO
*policies
,
2210 CRYPT_OBJID_BLOB
*ret
= NULL
;
2213 for (i
= 0; !ret
&& i
< policies
->cPolicyInfo
; i
++)
2217 for (j
= 0; !ret
&& j
< policies
->rgPolicyInfo
[i
].cPolicyQualifier
; j
++)
2218 if (!strcmp(policies
->rgPolicyInfo
[i
].rgPolicyQualifier
[j
].
2219 pszPolicyQualifierId
, policyOid
))
2220 ret
= &policies
->rgPolicyInfo
[i
].rgPolicyQualifier
[j
].
2226 static WCHAR
*get_cps_str_from_qualifier(const CRYPT_OBJID_BLOB
*qualifier
)
2228 LPWSTR qualifierStr
= NULL
;
2229 CERT_NAME_VALUE
*qualifierValue
;
2232 if (CryptDecodeObjectEx(X509_ASN_ENCODING
, X509_NAME_VALUE
,
2233 qualifier
->pbData
, qualifier
->cbData
, CRYPT_DECODE_ALLOC_FLAG
, NULL
,
2234 &qualifierValue
, &size
))
2236 size
= CertRDNValueToStrW(qualifierValue
->dwValueType
,
2237 &qualifierValue
->Value
, NULL
, 0);
2238 qualifierStr
= HeapAlloc(GetProcessHeap(), 0, size
* sizeof(WCHAR
));
2240 CertRDNValueToStrW(qualifierValue
->dwValueType
,
2241 &qualifierValue
->Value
, qualifierStr
, size
);
2242 LocalFree(qualifierValue
);
2244 return qualifierStr
;
2247 static WCHAR
*get_user_notice_from_qualifier(const CRYPT_OBJID_BLOB
*qualifier
)
2250 CERT_POLICY_QUALIFIER_USER_NOTICE
*qualifierValue
;
2253 if (CryptDecodeObjectEx(X509_ASN_ENCODING
,
2254 X509_PKIX_POLICY_QUALIFIER_USERNOTICE
,
2255 qualifier
->pbData
, qualifier
->cbData
, CRYPT_DECODE_ALLOC_FLAG
, NULL
,
2256 &qualifierValue
, &size
))
2258 str
= HeapAlloc(GetProcessHeap(), 0,
2259 (strlenW(qualifierValue
->pszDisplayText
) + 1) * sizeof(WCHAR
));
2261 strcpyW(str
, qualifierValue
->pszDisplayText
);
2262 LocalFree(qualifierValue
);
2267 struct IssuerStatement
2273 static void set_issuer_statement(HWND hwnd
,
2274 PCCRYPTUI_VIEWCERTIFICATE_STRUCTW pCertViewInfo
)
2276 PCERT_EXTENSION policyExt
;
2278 if (!(pCertViewInfo
->dwFlags
& CRYPTUI_DISABLE_ISSUERSTATEMENT
) &&
2279 (policyExt
= CertFindExtension(szOID_CERT_POLICIES
,
2280 pCertViewInfo
->pCertContext
->pCertInfo
->cExtension
,
2281 pCertViewInfo
->pCertContext
->pCertInfo
->rgExtension
)))
2283 CERT_POLICIES_INFO
*policies
;
2286 if (CryptDecodeObjectEx(X509_ASN_ENCODING
, policyExt
->pszObjId
,
2287 policyExt
->Value
.pbData
, policyExt
->Value
.cbData
,
2288 CRYPT_DECODE_ALLOC_FLAG
, NULL
, &policies
, &size
))
2290 CRYPT_OBJID_BLOB
*qualifier
;
2291 LPWSTR cps
= NULL
, userNotice
= NULL
;
2293 if ((qualifier
= find_policy_qualifier(policies
,
2294 szOID_PKIX_POLICY_QUALIFIER_CPS
)))
2295 cps
= get_cps_str_from_qualifier(qualifier
);
2296 if ((qualifier
= find_policy_qualifier(policies
,
2297 szOID_PKIX_POLICY_QUALIFIER_USERNOTICE
)))
2298 userNotice
= get_user_notice_from_qualifier(qualifier
);
2299 if (cps
|| userNotice
)
2301 struct IssuerStatement
*issuerStatement
=
2302 HeapAlloc(GetProcessHeap(), 0, sizeof(struct IssuerStatement
));
2304 if (issuerStatement
)
2306 issuerStatement
->cps
= cps
;
2307 issuerStatement
->userNotice
= userNotice
;
2308 EnableWindow(GetDlgItem(hwnd
, IDC_ISSUERSTATEMENT
), TRUE
);
2309 SetWindowLongPtrW(hwnd
, DWLP_USER
,
2310 (ULONG_PTR
)issuerStatement
);
2313 LocalFree(policies
);
2318 static void set_cert_info(HWND hwnd
,
2319 PCCRYPTUI_VIEWCERTIFICATE_STRUCTW pCertViewInfo
)
2321 CHARFORMATW charFmt
;
2323 HWND icon
= GetDlgItem(hwnd
, IDC_CERTIFICATE_ICON
);
2324 HWND text
= GetDlgItem(hwnd
, IDC_CERTIFICATE_INFO
);
2325 CRYPT_PROVIDER_SGNR
*provSigner
= WTHelperGetProvSignerFromChain(
2326 (CRYPT_PROVIDER_DATA
*)pCertViewInfo
->u
.pCryptProviderData
,
2327 pCertViewInfo
->idxSigner
, pCertViewInfo
->fCounterSigner
,
2328 pCertViewInfo
->idxCounterSigner
);
2329 CRYPT_PROVIDER_CERT
*root
=
2330 &provSigner
->pasCertChain
[provSigner
->csCertChain
- 1];
2332 if (!provSigner
->pChainContext
||
2333 (provSigner
->pChainContext
->TrustStatus
.dwErrorStatus
&
2334 CERT_TRUST_IS_PARTIAL_CHAIN
))
2335 add_icon_to_control(icon
, IDB_CERT_WARNING
);
2336 else if (!root
->fTrustedRoot
)
2337 add_icon_to_control(icon
, IDB_CERT_ERROR
);
2339 add_icon_to_control(icon
, IDB_CERT
);
2341 memset(&charFmt
, 0, sizeof(charFmt
));
2342 charFmt
.cbSize
= sizeof(charFmt
);
2343 charFmt
.dwMask
= CFM_BOLD
;
2344 charFmt
.dwEffects
= CFE_BOLD
;
2345 SendMessageW(text
, EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&charFmt
);
2346 /* FIXME: vertically center text */
2347 parFmt
.cbSize
= sizeof(parFmt
);
2348 parFmt
.dwMask
= PFM_STARTINDENT
;
2349 parFmt
.dxStartIndent
= MY_INDENT
;
2350 add_string_resource_with_paraformat_to_control(text
,
2351 IDS_CERTIFICATEINFORMATION
, &parFmt
);
2353 text
= GetDlgItem(hwnd
, IDC_CERTIFICATE_STATUS
);
2354 SendMessageW(text
, EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&charFmt
);
2355 if (provSigner
->dwError
== TRUST_E_CERT_SIGNATURE
)
2356 add_string_resource_with_paraformat_to_control(text
,
2357 IDS_CERT_INFO_BAD_SIG
, &parFmt
);
2358 else if (!provSigner
->pChainContext
||
2359 (provSigner
->pChainContext
->TrustStatus
.dwErrorStatus
&
2360 CERT_TRUST_IS_PARTIAL_CHAIN
))
2361 add_string_resource_with_paraformat_to_control(text
,
2362 IDS_CERT_INFO_PARTIAL_CHAIN
, &parFmt
);
2363 else if (!root
->fTrustedRoot
)
2365 if (provSigner
->csCertChain
== 1 && root
->fSelfSigned
)
2366 add_string_resource_with_paraformat_to_control(text
,
2367 IDS_CERT_INFO_UNTRUSTED_CA
, &parFmt
);
2369 add_string_resource_with_paraformat_to_control(text
,
2370 IDS_CERT_INFO_UNTRUSTED_ROOT
, &parFmt
);
2374 set_policy_text(text
, pCertViewInfo
);
2375 set_issuer_statement(hwnd
, pCertViewInfo
);
2379 static void set_cert_name_string(HWND hwnd
, PCCERT_CONTEXT cert
,
2380 DWORD nameFlags
, int heading
)
2383 HWND text
= GetDlgItem(hwnd
, IDC_CERTIFICATE_NAMES
);
2384 CHARFORMATW charFmt
;
2387 memset(&charFmt
, 0, sizeof(charFmt
));
2388 charFmt
.cbSize
= sizeof(charFmt
);
2389 charFmt
.dwMask
= CFM_BOLD
;
2390 charFmt
.dwEffects
= CFE_BOLD
;
2391 SendMessageW(text
, EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&charFmt
);
2392 parFmt
.cbSize
= sizeof(parFmt
);
2393 parFmt
.dwMask
= PFM_STARTINDENT
;
2394 parFmt
.dxStartIndent
= MY_INDENT
* 3;
2395 add_string_resource_with_paraformat_to_control(text
, heading
, &parFmt
);
2396 charFmt
.dwEffects
= 0;
2397 SendMessageW(text
, EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&charFmt
);
2398 add_cert_string_to_control(text
, cert
, CERT_NAME_SIMPLE_DISPLAY_TYPE
,
2400 add_unformatted_text_to_control(text
, &nl
, 1);
2401 add_unformatted_text_to_control(text
, &nl
, 1);
2402 add_unformatted_text_to_control(text
, &nl
, 1);
2406 static void add_date_string_to_control(HWND hwnd
, const FILETIME
*fileTime
)
2408 WCHAR dateFmt
[80]; /* sufficient for all versions of LOCALE_SSHORTDATE */
2412 GetLocaleInfoW(LOCALE_SYSTEM_DEFAULT
, LOCALE_SSHORTDATE
, dateFmt
,
2413 sizeof(dateFmt
) / sizeof(dateFmt
[0]));
2414 FileTimeToSystemTime(fileTime
, &sysTime
);
2415 GetDateFormatW(LOCALE_SYSTEM_DEFAULT
, 0, &sysTime
, dateFmt
, date
,
2416 sizeof(date
) / sizeof(date
[0]));
2417 add_unformatted_text_to_control(hwnd
, date
, lstrlenW(date
));
2420 static void set_cert_validity_period(HWND hwnd
, PCCERT_CONTEXT cert
)
2423 HWND text
= GetDlgItem(hwnd
, IDC_CERTIFICATE_NAMES
);
2424 CHARFORMATW charFmt
;
2427 memset(&charFmt
, 0, sizeof(charFmt
));
2428 charFmt
.cbSize
= sizeof(charFmt
);
2429 charFmt
.dwMask
= CFM_BOLD
;
2430 charFmt
.dwEffects
= CFE_BOLD
;
2431 SendMessageW(text
, EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&charFmt
);
2432 parFmt
.cbSize
= sizeof(parFmt
);
2433 parFmt
.dwMask
= PFM_STARTINDENT
;
2434 parFmt
.dxStartIndent
= MY_INDENT
* 3;
2435 add_string_resource_with_paraformat_to_control(text
, IDS_VALID_FROM
,
2437 charFmt
.dwEffects
= 0;
2438 SendMessageW(text
, EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&charFmt
);
2439 add_date_string_to_control(text
, &cert
->pCertInfo
->NotBefore
);
2440 charFmt
.dwEffects
= CFE_BOLD
;
2441 SendMessageW(text
, EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&charFmt
);
2442 add_string_resource_to_control(text
, IDS_VALID_TO
);
2443 charFmt
.dwEffects
= 0;
2444 SendMessageW(text
, EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&charFmt
);
2445 add_date_string_to_control(text
, &cert
->pCertInfo
->NotAfter
);
2446 add_unformatted_text_to_control(text
, &nl
, 1);
2449 static void set_general_info(HWND hwnd
,
2450 PCCRYPTUI_VIEWCERTIFICATE_STRUCTW pCertViewInfo
)
2452 set_cert_info(hwnd
, pCertViewInfo
);
2453 set_cert_name_string(hwnd
, pCertViewInfo
->pCertContext
, 0,
2454 IDS_SUBJECT_HEADING
);
2455 set_cert_name_string(hwnd
, pCertViewInfo
->pCertContext
,
2456 CERT_NAME_ISSUER_FLAG
, IDS_ISSUER_HEADING
);
2457 set_cert_validity_period(hwnd
, pCertViewInfo
->pCertContext
);
2460 static LRESULT CALLBACK
user_notice_dlg_proc(HWND hwnd
, UINT msg
, WPARAM wp
,
2465 struct IssuerStatement
*issuerStatement
;
2470 text
= GetDlgItem(hwnd
, IDC_USERNOTICE
);
2471 issuerStatement
= (struct IssuerStatement
*)lp
;
2472 add_unformatted_text_to_control(text
, issuerStatement
->userNotice
,
2473 strlenW(issuerStatement
->userNotice
));
2474 if (issuerStatement
->cps
)
2475 SetWindowLongPtrW(hwnd
, DWLP_USER
, (LPARAM
)issuerStatement
->cps
);
2477 EnableWindow(GetDlgItem(hwnd
, IDC_CPS
), FALSE
);
2483 EndDialog(hwnd
, IDOK
);
2488 IBindCtx
*bctx
= NULL
;
2491 CreateBindCtx(0, &bctx
);
2492 cps
= (LPWSTR
)GetWindowLongPtrW(hwnd
, DWLP_USER
);
2493 HlinkSimpleNavigateToString(cps
, NULL
, NULL
, NULL
, bctx
, NULL
,
2494 HLNF_OPENINNEWWINDOW
, 0);
2495 IBindCtx_Release(bctx
);
2503 static void show_user_notice(HWND hwnd
, struct IssuerStatement
*issuerStatement
)
2505 DialogBoxParamW(hInstance
, MAKEINTRESOURCEW(IDD_USERNOTICE
), hwnd
,
2506 user_notice_dlg_proc
, (LPARAM
)issuerStatement
);
2509 static LRESULT CALLBACK
general_dlg_proc(HWND hwnd
, UINT msg
, WPARAM wp
,
2512 PROPSHEETPAGEW
*page
;
2513 PCCRYPTUI_VIEWCERTIFICATE_STRUCTW pCertViewInfo
;
2515 TRACE("(%p, %08x, %08lx, %08lx)\n", hwnd
, msg
, wp
, lp
);
2520 page
= (PROPSHEETPAGEW
*)lp
;
2521 pCertViewInfo
= (PCCRYPTUI_VIEWCERTIFICATE_STRUCTW
)page
->lParam
;
2522 if (pCertViewInfo
->dwFlags
& CRYPTUI_DISABLE_ADDTOSTORE
)
2523 ShowWindow(GetDlgItem(hwnd
, IDC_ADDTOSTORE
), FALSE
);
2524 EnableWindow(GetDlgItem(hwnd
, IDC_ISSUERSTATEMENT
), FALSE
);
2525 set_general_info(hwnd
, pCertViewInfo
);
2530 case IDC_ADDTOSTORE
:
2531 CryptUIWizImport(0, hwnd
, NULL
, NULL
, NULL
);
2533 case IDC_ISSUERSTATEMENT
:
2535 struct IssuerStatement
*issuerStatement
=
2536 (struct IssuerStatement
*)GetWindowLongPtrW(hwnd
, DWLP_USER
);
2538 if (issuerStatement
)
2540 if (issuerStatement
->userNotice
)
2541 show_user_notice(hwnd
, issuerStatement
);
2542 else if (issuerStatement
->cps
)
2544 IBindCtx
*bctx
= NULL
;
2546 CreateBindCtx(0, &bctx
);
2547 HlinkSimpleNavigateToString(issuerStatement
->cps
, NULL
,
2548 NULL
, NULL
, bctx
, NULL
, HLNF_OPENINNEWWINDOW
, 0);
2549 IBindCtx_Release(bctx
);
2560 static UINT CALLBACK
general_callback_proc(HWND hwnd
, UINT msg
,
2561 PROPSHEETPAGEW
*page
)
2563 struct IssuerStatement
*issuerStatement
;
2569 (struct IssuerStatement
*)GetWindowLongPtrW(hwnd
, DWLP_USER
);
2570 if (issuerStatement
)
2572 HeapFree(GetProcessHeap(), 0, issuerStatement
->cps
);
2573 HeapFree(GetProcessHeap(), 0, issuerStatement
->userNotice
);
2574 HeapFree(GetProcessHeap(), 0, issuerStatement
);
2581 static void init_general_page(PCCRYPTUI_VIEWCERTIFICATE_STRUCTW pCertViewInfo
,
2582 PROPSHEETPAGEW
*page
)
2584 memset(page
, 0, sizeof(PROPSHEETPAGEW
));
2585 page
->dwSize
= sizeof(PROPSHEETPAGEW
);
2586 page
->dwFlags
= PSP_USECALLBACK
;
2587 page
->pfnCallback
= general_callback_proc
;
2588 page
->hInstance
= hInstance
;
2589 page
->u
.pszTemplate
= MAKEINTRESOURCEW(IDD_GENERAL
);
2590 page
->pfnDlgProc
= general_dlg_proc
;
2591 page
->lParam
= (LPARAM
)pCertViewInfo
;
2594 typedef WCHAR
* (*field_format_func
)(PCCERT_CONTEXT cert
);
2596 static WCHAR
*field_format_version(PCCERT_CONTEXT cert
)
2598 static const WCHAR fmt
[] = { 'V','%','d',0 };
2599 WCHAR
*buf
= HeapAlloc(GetProcessHeap(), 0, 12 * sizeof(WCHAR
));
2602 sprintfW(buf
, fmt
, cert
->pCertInfo
->dwVersion
);
2606 static WCHAR
*format_hex_string(void *pb
, DWORD cb
)
2608 WCHAR
*buf
= HeapAlloc(GetProcessHeap(), 0, (cb
* 3 + 1) * sizeof(WCHAR
));
2612 static const WCHAR fmt
[] = { '%','0','2','x',' ',0 };
2616 for (i
= 0, ptr
= buf
; i
< cb
; i
++, ptr
+= 3)
2617 sprintfW(ptr
, fmt
, ((BYTE
*)pb
)[i
]);
2622 static WCHAR
*field_format_serial_number(PCCERT_CONTEXT cert
)
2624 return format_hex_string(cert
->pCertInfo
->SerialNumber
.pbData
,
2625 cert
->pCertInfo
->SerialNumber
.cbData
);
2628 static WCHAR
*field_format_issuer(PCCERT_CONTEXT cert
)
2630 return get_cert_name_string(cert
, CERT_NAME_SIMPLE_DISPLAY_TYPE
,
2631 CERT_NAME_ISSUER_FLAG
);
2634 static WCHAR
*field_format_detailed_cert_name(PCERT_NAME_BLOB name
)
2637 DWORD len
= CertNameToStrW(X509_ASN_ENCODING
, name
,
2638 CERT_X500_NAME_STR
| CERT_NAME_STR_CRLF_FLAG
, NULL
, 0);
2642 str
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
2644 CertNameToStrW(X509_ASN_ENCODING
, name
,
2645 CERT_X500_NAME_STR
| CERT_NAME_STR_CRLF_FLAG
, str
, len
);
2650 static WCHAR
*field_format_detailed_issuer(PCCERT_CONTEXT cert
, void *param
)
2652 return field_format_detailed_cert_name(&cert
->pCertInfo
->Issuer
);
2655 static WCHAR
*field_format_subject(PCCERT_CONTEXT cert
)
2657 return get_cert_name_string(cert
, CERT_NAME_SIMPLE_DISPLAY_TYPE
, 0);
2660 static WCHAR
*field_format_detailed_subject(PCCERT_CONTEXT cert
, void *param
)
2662 return field_format_detailed_cert_name(&cert
->pCertInfo
->Subject
);
2665 static WCHAR
*format_long_date(const FILETIME
*fileTime
)
2667 WCHAR dateFmt
[80]; /* long enough for LOCALE_SLONGDATE */
2672 /* FIXME: format isn't quite right, want time too */
2673 GetLocaleInfoW(LOCALE_SYSTEM_DEFAULT
, LOCALE_SLONGDATE
, dateFmt
,
2674 sizeof(dateFmt
) / sizeof(dateFmt
[0]));
2675 FileTimeToSystemTime(fileTime
, &sysTime
);
2676 len
= GetDateFormatW(LOCALE_SYSTEM_DEFAULT
, 0, &sysTime
, dateFmt
, NULL
, 0);
2679 buf
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
2681 GetDateFormatW(LOCALE_SYSTEM_DEFAULT
, 0, &sysTime
, dateFmt
, buf
,
2687 static WCHAR
*field_format_from_date(PCCERT_CONTEXT cert
)
2689 return format_long_date(&cert
->pCertInfo
->NotBefore
);
2692 static WCHAR
*field_format_to_date(PCCERT_CONTEXT cert
)
2694 return format_long_date(&cert
->pCertInfo
->NotAfter
);
2697 static WCHAR
*field_format_public_key(PCCERT_CONTEXT cert
)
2699 PCCRYPT_OID_INFO oidInfo
;
2702 oidInfo
= CryptFindOIDInfo(CRYPT_OID_INFO_OID_KEY
,
2703 cert
->pCertInfo
->SubjectPublicKeyInfo
.Algorithm
.pszObjId
, 0);
2706 WCHAR fmt
[MAX_STRING_LEN
];
2708 if (LoadStringW(hInstance
, IDS_FIELD_PUBLIC_KEY_FORMAT
, fmt
,
2709 sizeof(fmt
) / sizeof(fmt
[0])))
2711 /* Allocate the output buffer. Use the number of bytes in the
2712 * public key as a conservative (high) estimate for the number of
2713 * digits in its output.
2714 * The output is of the form (in English)
2715 * "<public key algorithm> (<public key bit length> bits)".
2716 * Ordinarily having two positional parameters in a string is not a
2717 * good idea, but as this isn't a sentence fragment, it shouldn't
2718 * be word-order dependent.
2720 buf
= HeapAlloc(GetProcessHeap(), 0,
2721 (strlenW(fmt
) + strlenW(oidInfo
->pwszName
) +
2722 cert
->pCertInfo
->SubjectPublicKeyInfo
.PublicKey
.cbData
* 8)
2725 sprintfW(buf
, fmt
, oidInfo
->pwszName
,
2726 CertGetPublicKeyLength(X509_ASN_ENCODING
,
2727 &cert
->pCertInfo
->SubjectPublicKeyInfo
));
2733 static WCHAR
*field_format_detailed_public_key(PCCERT_CONTEXT cert
, void *param
)
2735 return format_hex_string(
2736 cert
->pCertInfo
->SubjectPublicKeyInfo
.PublicKey
.pbData
,
2737 cert
->pCertInfo
->SubjectPublicKeyInfo
.PublicKey
.cbData
);
2740 struct field_value_data
;
2743 PCCRYPTUI_VIEWCERTIFICATE_STRUCTW pCertViewInfo
;
2744 BOOL
*pfPropertiesChanged
;
2746 struct field_value_data
*fields
;
2749 typedef void (*add_fields_func
)(HWND hwnd
, struct detail_data
*data
);
2751 typedef WCHAR
*(*create_detailed_value_func
)(PCCERT_CONTEXT cert
, void *param
);
2753 struct field_value_data
2755 create_detailed_value_func create
;
2756 LPWSTR detailed_value
;
2760 static void add_field_value_data(struct detail_data
*data
,
2761 create_detailed_value_func create
, void *param
)
2764 data
->fields
= HeapReAlloc(GetProcessHeap(), 0, data
->fields
,
2765 (data
->cFields
+ 1) * sizeof(struct field_value_data
));
2767 data
->fields
= HeapAlloc(GetProcessHeap(), 0,
2768 sizeof(struct field_value_data
));
2771 data
->fields
[data
->cFields
].create
= create
;
2772 data
->fields
[data
->cFields
].detailed_value
= NULL
;
2773 data
->fields
[data
->cFields
].param
= param
;
2778 static void add_field_and_value_to_list(HWND hwnd
, struct detail_data
*data
,
2779 LPWSTR field
, LPWSTR value
, create_detailed_value_func create
, void *param
)
2782 int iItem
= SendMessageW(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2784 item
.mask
= LVIF_TEXT
| LVIF_PARAM
;
2787 item
.pszText
= field
;
2788 item
.lParam
= (LPARAM
)data
;
2789 SendMessageW(hwnd
, LVM_INSERTITEMW
, 0, (LPARAM
)&item
);
2792 item
.pszText
= value
;
2794 SendMessageW(hwnd
, LVM_SETITEMTEXTW
, iItem
, (LPARAM
)&item
);
2796 add_field_value_data(data
, create
, param
);
2799 static void add_string_id_and_value_to_list(HWND hwnd
, struct detail_data
*data
,
2800 int id
, LPWSTR value
, create_detailed_value_func create
, void *param
)
2802 WCHAR buf
[MAX_STRING_LEN
];
2804 LoadStringW(hInstance
, id
, buf
, sizeof(buf
) / sizeof(buf
[0]));
2805 add_field_and_value_to_list(hwnd
, data
, buf
, value
, create
, param
);
2811 field_format_func format
;
2812 create_detailed_value_func create_detailed_value
;
2815 static void add_v1_field(HWND hwnd
, struct detail_data
*data
,
2816 const struct v1_field
*field
)
2818 WCHAR
*val
= field
->format(data
->pCertViewInfo
->pCertContext
);
2822 add_string_id_and_value_to_list(hwnd
, data
, field
->id
, val
,
2823 field
->create_detailed_value
, NULL
);
2824 HeapFree(GetProcessHeap(), 0, val
);
2828 static const struct v1_field v1_fields
[] = {
2829 { IDS_FIELD_VERSION
, field_format_version
, NULL
},
2830 { IDS_FIELD_SERIAL_NUMBER
, field_format_serial_number
, NULL
},
2831 { IDS_FIELD_ISSUER
, field_format_issuer
, field_format_detailed_issuer
},
2832 { IDS_FIELD_VALID_FROM
, field_format_from_date
, NULL
},
2833 { IDS_FIELD_VALID_TO
, field_format_to_date
, NULL
},
2834 { IDS_FIELD_SUBJECT
, field_format_subject
, field_format_detailed_subject
},
2835 { IDS_FIELD_PUBLIC_KEY
, field_format_public_key
,
2836 field_format_detailed_public_key
}
2839 static void add_v1_fields(HWND hwnd
, struct detail_data
*data
)
2842 PCCERT_CONTEXT cert
= data
->pCertViewInfo
->pCertContext
;
2844 /* The last item in v1_fields is the public key, which is not in the loop
2845 * because it's a special case.
2847 for (i
= 0; i
< sizeof(v1_fields
) / sizeof(v1_fields
[0]) - 1; i
++)
2848 add_v1_field(hwnd
, data
, &v1_fields
[i
]);
2849 if (cert
->pCertInfo
->SubjectPublicKeyInfo
.PublicKey
.cbData
)
2850 add_v1_field(hwnd
, data
, &v1_fields
[i
]);
2853 static WCHAR
*crypt_format_extension(const CERT_EXTENSION
*ext
, DWORD formatStrType
)
2858 if (CryptFormatObject(X509_ASN_ENCODING
, 0, formatStrType
, NULL
,
2859 ext
->pszObjId
, ext
->Value
.pbData
, ext
->Value
.cbData
, NULL
, &size
))
2861 str
= HeapAlloc(GetProcessHeap(), 0, size
);
2862 CryptFormatObject(X509_ASN_ENCODING
, 0, formatStrType
, NULL
,
2863 ext
->pszObjId
, ext
->Value
.pbData
, ext
->Value
.cbData
, str
, &size
);
2868 static WCHAR
*field_format_extension_hex_with_ascii(const CERT_EXTENSION
*ext
)
2872 if (ext
->Value
.cbData
)
2874 /* The output is formatted as:
2875 * <hex bytes> <ascii bytes>\n
2876 * where <hex bytes> is a string of up to 8 bytes, output as %02x,
2877 * and <ascii bytes> is the ASCII equivalent of each byte, or '.' if
2878 * the byte is not printable.
2879 * So, for example, the extension value consisting of the following
2881 * 0x30,0x14,0x31,0x12,0x30,0x10,0x06,0x03,0x55,0x04,0x03,
2882 * 0x13,0x09,0x4a,0x75,0x61,0x6e,0x20,0x4c,0x61,0x6e,0x67
2884 * 30 14 31 12 30 10 06 03 0.1.0...
2885 * 55 04 03 13 09 4a 75 61 U....Jua
2886 * 6e 20 4c 61 6e 67 n Lang
2887 * The allocation size therefore requires:
2888 * - 4 characters per character in an 8-byte line
2889 * (2 for the hex format, one for the space, one for the ASCII value)
2890 * - 3 more characters per 8-byte line (two spaces and a newline)
2891 * - 1 character for the terminating nul
2892 * FIXME: should use a fixed-width font for this
2894 DWORD lines
= (ext
->Value
.cbData
+ 7) / 8;
2896 str
= HeapAlloc(GetProcessHeap(), 0,
2897 (lines
* 8 * 4 + lines
* 3 + 1) * sizeof(WCHAR
));
2900 static const WCHAR fmt
[] = { '%','0','2','x',' ',0 };
2904 for (i
= 0, ptr
= str
; i
< ext
->Value
.cbData
; i
+= 8)
2906 /* Output as hex bytes first */
2907 for (j
= i
; j
< min(i
+ 8, ext
->Value
.cbData
); j
++, ptr
+= 3)
2908 sprintfW(ptr
, fmt
, ext
->Value
.pbData
[j
]);
2909 /* Pad the hex output with spaces for alignment */
2910 if (j
== ext
->Value
.cbData
&& j
% 8)
2912 static const WCHAR pad
[] = { ' ',' ',' ' };
2914 for (; j
% 8; j
++, ptr
+= sizeof(pad
) / sizeof(pad
[0]))
2915 memcpy(ptr
, pad
, sizeof(pad
));
2917 /* The last sprintfW included a space, so just insert one
2918 * more space between the hex bytes and the ASCII output
2921 /* Output as ASCII bytes */
2922 for (j
= i
; j
< min(i
+ 8, ext
->Value
.cbData
); j
++, ptr
++)
2924 if (isprintW(ext
->Value
.pbData
[j
]) &&
2925 !isspaceW(ext
->Value
.pbData
[j
]))
2926 *ptr
= ext
->Value
.pbData
[j
];
2938 static WCHAR
*field_format_detailed_extension(PCCERT_CONTEXT cert
, void *param
)
2940 PCERT_EXTENSION ext
= param
;
2941 LPWSTR str
= crypt_format_extension(ext
,
2942 CRYPT_FORMAT_STR_MULTI_LINE
| CRYPT_FORMAT_STR_NO_HEX
);
2945 str
= field_format_extension_hex_with_ascii(ext
);
2949 static void add_cert_extension_detail(HWND hwnd
, struct detail_data
*data
,
2950 PCERT_EXTENSION ext
)
2952 PCCRYPT_OID_INFO oidInfo
= CryptFindOIDInfo(CRYPT_OID_INFO_OID_KEY
,
2954 LPWSTR val
= crypt_format_extension(ext
, 0);
2957 add_field_and_value_to_list(hwnd
, data
, (LPWSTR
)oidInfo
->pwszName
,
2958 val
, field_format_detailed_extension
, ext
);
2961 DWORD len
= strlen(ext
->pszObjId
);
2962 LPWSTR oidW
= HeapAlloc(GetProcessHeap(), 0, (len
+ 1) * sizeof(WCHAR
));
2968 for (i
= 0; i
<= len
; i
++)
2969 oidW
[i
] = ext
->pszObjId
[i
];
2970 add_field_and_value_to_list(hwnd
, data
, oidW
, val
,
2971 field_format_detailed_extension
, ext
);
2972 HeapFree(GetProcessHeap(), 0, oidW
);
2975 HeapFree(GetProcessHeap(), 0, val
);
2978 static void add_all_extensions(HWND hwnd
, struct detail_data
*data
)
2981 PCCERT_CONTEXT cert
= data
->pCertViewInfo
->pCertContext
;
2983 for (i
= 0; i
< cert
->pCertInfo
->cExtension
; i
++)
2984 add_cert_extension_detail(hwnd
, data
, &cert
->pCertInfo
->rgExtension
[i
]);
2987 static void add_critical_extensions(HWND hwnd
, struct detail_data
*data
)
2990 PCCERT_CONTEXT cert
= data
->pCertViewInfo
->pCertContext
;
2992 for (i
= 0; i
< cert
->pCertInfo
->cExtension
; i
++)
2993 if (cert
->pCertInfo
->rgExtension
[i
].fCritical
)
2994 add_cert_extension_detail(hwnd
, data
,
2995 &cert
->pCertInfo
->rgExtension
[i
]);
2998 typedef WCHAR
* (*prop_to_value_func
)(void *pb
, DWORD cb
);
3000 struct prop_id_to_string_id
3004 BOOL prop_is_string
;
3005 prop_to_value_func prop_to_value
;
3008 static WCHAR
*format_enhanced_key_usage_value(void *pb
, DWORD cb
)
3012 ext
.pszObjId
= (LPSTR
)X509_ENHANCED_KEY_USAGE
;
3013 ext
.fCritical
= FALSE
;
3014 ext
.Value
.pbData
= pb
;
3015 ext
.Value
.cbData
= cb
;
3016 return crypt_format_extension(&ext
, 0);
3019 /* Logically the access state should also be checked, and IDC_EDITPROPERTIES
3020 * disabled for read-only certificates, but native doesn't appear to do that.
3022 static const struct prop_id_to_string_id prop_id_map
[] = {
3023 { CERT_HASH_PROP_ID
, IDS_PROP_HASH
, FALSE
, format_hex_string
},
3024 { CERT_FRIENDLY_NAME_PROP_ID
, IDS_PROP_FRIENDLY_NAME
, TRUE
, NULL
},
3025 { CERT_DESCRIPTION_PROP_ID
, IDS_PROP_DESCRIPTION
, TRUE
, NULL
},
3026 { CERT_ENHKEY_USAGE_PROP_ID
, IDS_PROP_ENHKEY_USAGE
, FALSE
,
3027 format_enhanced_key_usage_value
},
3030 static void add_properties(HWND hwnd
, struct detail_data
*data
)
3033 PCCERT_CONTEXT cert
= data
->pCertViewInfo
->pCertContext
;
3035 for (i
= 0; i
< sizeof(prop_id_map
) / sizeof(prop_id_map
[0]); i
++)
3039 if (CertGetCertificateContextProperty(cert
, prop_id_map
[i
].prop
, NULL
,
3045 /* FIXME: MS adds a separate value for the signature hash
3048 pb
= HeapAlloc(GetProcessHeap(), 0, cb
);
3051 if (CertGetCertificateContextProperty(cert
,
3052 prop_id_map
[i
].prop
, pb
, &cb
))
3054 if (prop_id_map
[i
].prop_is_string
)
3057 /* Don't double-free pb */
3061 val
= prop_id_map
[i
].prop_to_value(pb
, cb
);
3063 HeapFree(GetProcessHeap(), 0, pb
);
3065 add_string_id_and_value_to_list(hwnd
, data
, prop_id_map
[i
].id
, val
,
3071 static void add_all_fields(HWND hwnd
, struct detail_data
*data
)
3073 add_v1_fields(hwnd
, data
);
3074 add_all_extensions(hwnd
, data
);
3075 add_properties(hwnd
, data
);
3078 struct selection_list_item
3081 add_fields_func add
;
3084 static const struct selection_list_item listItems
[] = {
3085 { IDS_FIELDS_ALL
, add_all_fields
},
3086 { IDS_FIELDS_V1
, add_v1_fields
},
3087 { IDS_FIELDS_EXTENSIONS
, add_all_extensions
},
3088 { IDS_FIELDS_CRITICAL_EXTENSIONS
, add_critical_extensions
},
3089 { IDS_FIELDS_PROPERTIES
, add_properties
},
3092 static void create_show_list(HWND hwnd
, struct detail_data
*data
)
3094 HWND cb
= GetDlgItem(hwnd
, IDC_DETAIL_SELECT
);
3095 WCHAR buf
[MAX_STRING_LEN
];
3098 for (i
= 0; i
< sizeof(listItems
) / sizeof(listItems
[0]); i
++)
3102 LoadStringW(hInstance
, listItems
[i
].id
, buf
,
3103 sizeof(buf
) / sizeof(buf
[0]));
3104 index
= SendMessageW(cb
, CB_INSERTSTRING
, -1, (LPARAM
)buf
);
3105 SendMessageW(cb
, CB_SETITEMDATA
, index
, (LPARAM
)data
);
3107 SendMessageW(cb
, CB_SETCURSEL
, 0, 0);
3110 static void create_listview_columns(HWND hwnd
)
3112 HWND lv
= GetDlgItem(hwnd
, IDC_DETAIL_LIST
);
3114 WCHAR buf
[MAX_STRING_LEN
];
3117 SendMessageW(lv
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0, LVS_EX_FULLROWSELECT
);
3118 GetWindowRect(lv
, &rc
);
3119 LoadStringW(hInstance
, IDS_FIELD
, buf
, sizeof(buf
) / sizeof(buf
[0]));
3120 column
.mask
= LVCF_WIDTH
| LVCF_TEXT
;
3121 column
.cx
= (rc
.right
- rc
.left
) / 2 - 2;
3122 column
.pszText
= buf
;
3123 SendMessageW(lv
, LVM_INSERTCOLUMNW
, 0, (LPARAM
)&column
);
3124 LoadStringW(hInstance
, IDS_VALUE
, buf
, sizeof(buf
) / sizeof(buf
[0]));
3125 SendMessageW(lv
, LVM_INSERTCOLUMNW
, 1, (LPARAM
)&column
);
3128 static void set_fields_selection(HWND hwnd
, struct detail_data
*data
, int sel
)
3130 HWND list
= GetDlgItem(hwnd
, IDC_DETAIL_LIST
);
3132 if (sel
>= 0 && sel
< sizeof(listItems
) / sizeof(listItems
[0]))
3134 SendMessageW(list
, LVM_DELETEALLITEMS
, 0, 0);
3135 listItems
[sel
].add(list
, data
);
3139 static void create_cert_details_list(HWND hwnd
, struct detail_data
*data
)
3141 create_show_list(hwnd
, data
);
3142 create_listview_columns(hwnd
);
3143 set_fields_selection(hwnd
, data
, 0);
3146 static void add_purpose(HWND hwnd
, LPCSTR oid
)
3148 HWND lv
= GetDlgItem(hwnd
, IDC_CERTIFICATE_USAGES
);
3149 PCRYPT_OID_INFO info
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
3150 sizeof(CRYPT_OID_INFO
));
3154 char *oidCopy
= HeapAlloc(GetProcessHeap(), 0, strlen(oid
) + 1);
3160 strcpy(oidCopy
, oid
);
3161 info
->cbSize
= sizeof(CRYPT_OID_INFO
);
3162 info
->pszOID
= oidCopy
;
3163 item
.mask
= LVIF_TEXT
| LVIF_STATE
| LVIF_PARAM
;
3164 item
.state
= INDEXTOSTATEIMAGEMASK(CheckBitmapIndexChecked
);
3165 item
.stateMask
= LVIS_STATEIMAGEMASK
;
3166 item
.iItem
= SendMessageW(lv
, LVM_GETITEMCOUNT
, 0, 0);
3168 item
.lParam
= (LPARAM
)info
;
3169 item
.pszText
= oidCopy
;
3170 SendMessageA(lv
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
3173 HeapFree(GetProcessHeap(), 0, info
);
3177 static BOOL
is_valid_oid(LPCSTR oid
)
3181 if (oid
[0] != '0' && oid
[0] != '1' && oid
[0] != '2')
3183 else if (oid
[1] != '.')
3190 BOOL expectNum
= TRUE
;
3192 for (ptr
= oid
+ 2, ret
= TRUE
; ret
&& *ptr
; ptr
++)
3198 else if (*(ptr
+ 1) == '.')
3205 else if (!(*(ptr
+ 1)))
3215 static BOOL
is_oid_in_list(HWND hwnd
, LPCSTR oid
)
3217 return find_oid_in_list(GetDlgItem(hwnd
, IDC_CERTIFICATE_USAGES
), oid
)
3221 #define MAX_PURPOSE 255
3223 static LRESULT CALLBACK
add_purpose_dlg_proc(HWND hwnd
, UINT msg
,
3224 WPARAM wp
, LPARAM lp
)
3227 char buf
[MAX_PURPOSE
+ 1];
3232 SendMessageW(GetDlgItem(hwnd
, IDC_NEW_PURPOSE
), EM_SETLIMITTEXT
,
3234 ShowScrollBar(GetDlgItem(hwnd
, IDC_NEW_PURPOSE
), SB_VERT
, FALSE
);
3235 SetWindowLongPtrW(hwnd
, DWLP_USER
, lp
);
3241 if (LOWORD(wp
) == IDC_NEW_PURPOSE
)
3243 /* Show/hide scroll bar on description depending on how much
3246 HWND description
= GetDlgItem(hwnd
, IDC_NEW_PURPOSE
);
3247 int lines
= SendMessageW(description
, EM_GETLINECOUNT
, 0, 0);
3249 ShowScrollBar(description
, SB_VERT
, lines
> 1);
3256 SendMessageA(GetDlgItem(hwnd
, IDC_NEW_PURPOSE
), WM_GETTEXT
,
3257 sizeof(buf
) / sizeof(buf
[0]), (LPARAM
)buf
);
3260 /* An empty purpose is the same as cancelling */
3261 EndDialog(hwnd
, IDCANCEL
);
3264 else if (!is_valid_oid(buf
))
3266 WCHAR title
[MAX_STRING_LEN
], error
[MAX_STRING_LEN
];
3268 LoadStringW(hInstance
, IDS_CERTIFICATE_PURPOSE_ERROR
, error
,
3269 sizeof(error
) / sizeof(error
[0]));
3270 LoadStringW(hInstance
, IDS_CERTIFICATE_PROPERTIES
, title
,
3271 sizeof(title
) / sizeof(title
[0]));
3272 MessageBoxW(hwnd
, error
, title
, MB_ICONERROR
| MB_OK
);
3274 else if (is_oid_in_list(
3275 (HWND
)GetWindowLongPtrW(hwnd
, DWLP_USER
), buf
))
3277 WCHAR title
[MAX_STRING_LEN
], error
[MAX_STRING_LEN
];
3279 LoadStringW(hInstance
, IDS_CERTIFICATE_PURPOSE_EXISTS
,
3280 error
, sizeof(error
) / sizeof(error
[0]));
3281 LoadStringW(hInstance
, IDS_CERTIFICATE_PROPERTIES
, title
,
3282 sizeof(title
) / sizeof(title
[0]));
3283 MessageBoxW(hwnd
, error
, title
, MB_ICONEXCLAMATION
| MB_OK
);
3287 HWND parent
= (HWND
)GetWindowLongPtrW(hwnd
, DWLP_USER
);
3289 add_purpose(parent
, buf
);
3290 EndDialog(hwnd
, wp
);
3295 EndDialog(hwnd
, wp
);
3306 static WCHAR
*get_cert_property_as_string(PCCERT_CONTEXT cert
, DWORD prop
)
3311 if (CertGetCertificateContextProperty(cert
, prop
, NULL
, &cb
))
3313 name
= HeapAlloc(GetProcessHeap(), 0, cb
);
3316 if (!CertGetCertificateContextProperty(cert
, prop
, name
, &cb
))
3318 HeapFree(GetProcessHeap(), 0, name
);
3326 static void redraw_states(HWND list
, BOOL enabled
)
3328 int items
= SendMessageW(list
, LVM_GETITEMCOUNT
, 0, 0), i
;
3330 for (i
= 0; i
< items
; i
++)
3332 BOOL change
= FALSE
;
3335 state
= SendMessageW(list
, LVM_GETITEMSTATE
, i
, LVIS_STATEIMAGEMASK
);
3336 /* This reverses the INDEXTOSTATEIMAGEMASK shift. There doesn't appear
3337 * to be a handy macro for it.
3342 if (state
== CheckBitmapIndexDisabledChecked
)
3344 state
= CheckBitmapIndexChecked
;
3347 if (state
== CheckBitmapIndexDisabledUnchecked
)
3349 state
= CheckBitmapIndexUnchecked
;
3355 if (state
== CheckBitmapIndexChecked
)
3357 state
= CheckBitmapIndexDisabledChecked
;
3360 if (state
== CheckBitmapIndexUnchecked
)
3362 state
= CheckBitmapIndexDisabledUnchecked
;
3370 item
.state
= INDEXTOSTATEIMAGEMASK(state
);
3371 item
.stateMask
= LVIS_STATEIMAGEMASK
;
3372 SendMessageW(list
, LVM_SETITEMSTATE
, i
, (LPARAM
)&item
);
3378 PurposeEnableAll
= 0,
3380 PurposeEnableSelected
3383 static void select_purposes(HWND hwnd
, PurposeSelection selection
)
3385 HWND lv
= GetDlgItem(hwnd
, IDC_CERTIFICATE_USAGES
);
3389 case PurposeEnableAll
:
3390 case PurposeDisableAll
:
3391 EnableWindow(lv
, FALSE
);
3392 redraw_states(lv
, FALSE
);
3393 EnableWindow(GetDlgItem(hwnd
, IDC_ADD_PURPOSE
), FALSE
);
3395 case PurposeEnableSelected
:
3396 EnableWindow(lv
, TRUE
);
3397 redraw_states(lv
, TRUE
);
3398 EnableWindow(GetDlgItem(hwnd
, IDC_ADD_PURPOSE
), TRUE
);
3402 struct edit_cert_data
3404 PCCERT_CONTEXT cert
;
3405 BOOL
*pfPropertiesChanged
;
3406 HIMAGELIST imageList
;
3409 static void show_cert_usages(HWND hwnd
, struct edit_cert_data
*data
)
3411 PCCERT_CONTEXT cert
= data
->cert
;
3412 HWND lv
= GetDlgItem(hwnd
, IDC_CERTIFICATE_USAGES
);
3413 PCERT_ENHKEY_USAGE usage
;
3417 PurposeSelection purposeSelection
= PurposeEnableAll
;
3419 GetWindowRect(lv
, &rc
);
3420 column
.mask
= LVCF_WIDTH
;
3421 column
.cx
= rc
.right
- rc
.left
;
3422 SendMessageW(lv
, LVM_INSERTCOLUMNW
, 0, (LPARAM
)&column
);
3423 SendMessageW(lv
, LVM_SETIMAGELIST
, LVSIL_STATE
, (LPARAM
)data
->imageList
);
3425 /* Get enhanced key usage. Have to check for a property and an extension
3426 * separately, because CertGetEnhancedKeyUsage will succeed and return an
3427 * empty usage if neither is set. Unfortunately an empty usage implies
3428 * no usage is allowed, so we have to distinguish between the two cases.
3430 if (CertGetEnhancedKeyUsage(cert
, CERT_FIND_PROP_ONLY_ENHKEY_USAGE_FLAG
,
3433 usage
= HeapAlloc(GetProcessHeap(), 0, size
);
3434 if (!CertGetEnhancedKeyUsage(cert
,
3435 CERT_FIND_PROP_ONLY_ENHKEY_USAGE_FLAG
, usage
, &size
))
3437 HeapFree(GetProcessHeap(), 0, usage
);
3440 else if (usage
->cUsageIdentifier
)
3441 purposeSelection
= PurposeEnableSelected
;
3443 purposeSelection
= PurposeDisableAll
;
3445 else if (CertGetEnhancedKeyUsage(cert
, CERT_FIND_EXT_ONLY_ENHKEY_USAGE_FLAG
,
3448 usage
= HeapAlloc(GetProcessHeap(), 0, size
);
3449 if (!CertGetEnhancedKeyUsage(cert
,
3450 CERT_FIND_EXT_ONLY_ENHKEY_USAGE_FLAG
, usage
, &size
))
3452 HeapFree(GetProcessHeap(), 0, usage
);
3455 else if (usage
->cUsageIdentifier
)
3456 purposeSelection
= PurposeEnableAll
;
3458 purposeSelection
= PurposeDisableAll
;
3462 purposeSelection
= PurposeEnableAll
;
3469 for (i
= 0; i
< usage
->cUsageIdentifier
; i
++)
3471 PCCRYPT_OID_INFO info
= CryptFindOIDInfo(CRYPT_OID_INFO_OID_KEY
,
3472 usage
->rgpszUsageIdentifier
[i
], CRYPT_ENHKEY_USAGE_OID_GROUP_ID
);
3475 add_known_usage(lv
, info
, CheckBitmapIndexDisabledChecked
);
3477 add_purpose(hwnd
, usage
->rgpszUsageIdentifier
[i
]);
3479 HeapFree(GetProcessHeap(), 0, usage
);
3482 add_known_usages_to_list(lv
, CheckBitmapIndexDisabledChecked
);
3483 select_purposes(hwnd
, purposeSelection
);
3484 SendMessageW(GetDlgItem(hwnd
, IDC_ENABLE_ALL_PURPOSES
+ purposeSelection
),
3488 static void set_general_cert_properties(HWND hwnd
, struct edit_cert_data
*data
)
3490 PCCERT_CONTEXT cert
= data
->cert
;
3493 if ((str
= get_cert_property_as_string(cert
, CERT_FRIENDLY_NAME_PROP_ID
)))
3495 SendMessageW(GetDlgItem(hwnd
, IDC_FRIENDLY_NAME
), WM_SETTEXT
, 0,
3497 HeapFree(GetProcessHeap(), 0, str
);
3499 if ((str
= get_cert_property_as_string(cert
, CERT_DESCRIPTION_PROP_ID
)))
3501 SendMessageW(GetDlgItem(hwnd
, IDC_DESCRIPTION
), WM_SETTEXT
, 0,
3503 HeapFree(GetProcessHeap(), 0, str
);
3505 show_cert_usages(hwnd
, data
);
3508 static void set_cert_string_property(PCCERT_CONTEXT cert
, DWORD prop
,
3511 if (str
&& strlenW(str
))
3513 CRYPT_DATA_BLOB blob
;
3515 blob
.pbData
= (BYTE
*)str
;
3516 blob
.cbData
= (strlenW(str
) + 1) * sizeof(WCHAR
);
3517 CertSetCertificateContextProperty(cert
, prop
, 0, &blob
);
3520 CertSetCertificateContextProperty(cert
, prop
, 0, NULL
);
3523 #define WM_REFRESH_VIEW WM_USER + 0
3525 static BOOL CALLBACK
refresh_propsheet_pages(HWND hwnd
, LPARAM lParam
)
3527 if ((GetClassLongW(hwnd
, GCW_ATOM
) == WC_DIALOG
))
3528 SendMessageW(hwnd
, WM_REFRESH_VIEW
, 0, 0);
3532 #define MAX_FRIENDLY_NAME 40
3533 #define MAX_DESCRIPTION 255
3535 static void apply_general_changes(HWND hwnd
)
3537 WCHAR buf
[MAX_DESCRIPTION
+ 1];
3538 struct edit_cert_data
*data
=
3539 (struct edit_cert_data
*)GetWindowLongPtrW(hwnd
, DWLP_USER
);
3541 SendMessageW(GetDlgItem(hwnd
, IDC_FRIENDLY_NAME
), WM_GETTEXT
,
3542 sizeof(buf
) / sizeof(buf
[0]), (LPARAM
)buf
);
3543 set_cert_string_property(data
->cert
, CERT_FRIENDLY_NAME_PROP_ID
, buf
);
3544 SendMessageW(GetDlgItem(hwnd
, IDC_DESCRIPTION
), WM_GETTEXT
,
3545 sizeof(buf
) / sizeof(buf
[0]), (LPARAM
)buf
);
3546 set_cert_string_property(data
->cert
, CERT_DESCRIPTION_PROP_ID
, buf
);
3547 if (IsDlgButtonChecked(hwnd
, IDC_ENABLE_ALL_PURPOSES
))
3549 /* Setting a NULL usage removes the enhanced key usage property. */
3550 CertSetEnhancedKeyUsage(data
->cert
, NULL
);
3552 else if (IsDlgButtonChecked(hwnd
, IDC_DISABLE_ALL_PURPOSES
))
3554 CERT_ENHKEY_USAGE usage
= { 0, NULL
};
3556 CertSetEnhancedKeyUsage(data
->cert
, &usage
);
3558 else if (IsDlgButtonChecked(hwnd
, IDC_ENABLE_SELECTED_PURPOSES
))
3560 HWND lv
= GetDlgItem(hwnd
, IDC_CERTIFICATE_USAGES
);
3561 CERT_ENHKEY_USAGE usage
= { 0, NULL
};
3562 int purposes
= SendMessageW(lv
, LVM_GETITEMCOUNT
, 0, 0), i
;
3565 item
.mask
= LVIF_STATE
| LVIF_PARAM
;
3567 item
.stateMask
= LVIS_STATEIMAGEMASK
;
3568 for (i
= 0; i
< purposes
; i
++)
3571 if (SendMessageW(lv
, LVM_GETITEMW
, 0, (LPARAM
)&item
))
3573 int state
= item
.state
>> 12;
3575 if (state
== CheckBitmapIndexChecked
)
3577 CRYPT_OID_INFO
*info
= (CRYPT_OID_INFO
*)item
.lParam
;
3579 if (usage
.cUsageIdentifier
)
3580 usage
.rgpszUsageIdentifier
=
3581 HeapReAlloc(GetProcessHeap(), 0,
3582 usage
.rgpszUsageIdentifier
,
3583 (usage
.cUsageIdentifier
+ 1) * sizeof(LPSTR
));
3585 usage
.rgpszUsageIdentifier
=
3586 HeapAlloc(GetProcessHeap(), 0, sizeof(LPSTR
));
3587 if (usage
.rgpszUsageIdentifier
)
3588 usage
.rgpszUsageIdentifier
[usage
.cUsageIdentifier
++] =
3589 (LPSTR
)info
->pszOID
;
3593 CertSetEnhancedKeyUsage(data
->cert
, &usage
);
3594 HeapFree(GetProcessHeap(), 0, usage
.rgpszUsageIdentifier
);
3596 EnumChildWindows(GetParent(GetParent(hwnd
)), refresh_propsheet_pages
, 0);
3597 if (data
->pfPropertiesChanged
)
3598 *data
->pfPropertiesChanged
= TRUE
;
3601 static LRESULT CALLBACK
cert_properties_general_dlg_proc(HWND hwnd
, UINT msg
,
3602 WPARAM wp
, LPARAM lp
)
3604 PROPSHEETPAGEW
*page
;
3606 TRACE("(%p, %08x, %08lx, %08lx)\n", hwnd
, msg
, wp
, lp
);
3612 HWND description
= GetDlgItem(hwnd
, IDC_DESCRIPTION
);
3613 struct detail_data
*detailData
;
3614 struct edit_cert_data
*editData
;
3616 page
= (PROPSHEETPAGEW
*)lp
;
3617 detailData
= (struct detail_data
*)page
->lParam
;
3618 SendMessageW(GetDlgItem(hwnd
, IDC_FRIENDLY_NAME
), EM_SETLIMITTEXT
,
3619 MAX_FRIENDLY_NAME
, 0);
3620 SendMessageW(description
, EM_SETLIMITTEXT
, MAX_DESCRIPTION
, 0);
3621 ShowScrollBar(description
, SB_VERT
, FALSE
);
3622 editData
= HeapAlloc(GetProcessHeap(), 0,
3623 sizeof(struct edit_cert_data
));
3626 editData
->imageList
= ImageList_Create(16, 16,
3627 ILC_COLOR4
| ILC_MASK
, 4, 0);
3628 if (editData
->imageList
)
3631 COLORREF backColor
= RGB(255, 0, 255);
3633 bmp
= LoadBitmapW(hInstance
, MAKEINTRESOURCEW(IDB_CHECKS
));
3634 ImageList_AddMasked(editData
->imageList
, bmp
, backColor
);
3636 ImageList_SetBkColor(editData
->imageList
, CLR_NONE
);
3638 editData
->cert
= detailData
->pCertViewInfo
->pCertContext
;
3639 editData
->pfPropertiesChanged
= detailData
->pfPropertiesChanged
;
3640 SetWindowLongPtrW(hwnd
, DWLP_USER
, (LPARAM
)editData
);
3641 set_general_cert_properties(hwnd
, editData
);
3647 NMHDR
*hdr
= (NMHDR
*)lp
;
3653 nm
= (NMITEMACTIVATE
*)lp
;
3654 toggle_usage(hwnd
, nm
->iItem
);
3655 SendMessageW(GetParent(hwnd
), PSM_CHANGED
, (WPARAM
)hwnd
, 0);
3658 apply_general_changes(hwnd
);
3667 SendMessageW(GetParent(hwnd
), PSM_CHANGED
, (WPARAM
)hwnd
, 0);
3668 if (LOWORD(wp
) == IDC_DESCRIPTION
)
3670 /* Show/hide scroll bar on description depending on how much
3673 HWND description
= GetDlgItem(hwnd
, IDC_DESCRIPTION
);
3674 int lines
= SendMessageW(description
, EM_GETLINECOUNT
, 0, 0);
3676 ShowScrollBar(description
, SB_VERT
, lines
> 1);
3682 case IDC_ADD_PURPOSE
:
3683 if (DialogBoxParamW(hInstance
,
3684 MAKEINTRESOURCEW(IDD_ADD_CERT_PURPOSE
), hwnd
,
3685 add_purpose_dlg_proc
, (LPARAM
)hwnd
) == IDOK
)
3686 SendMessageW(GetParent(hwnd
), PSM_CHANGED
, (WPARAM
)hwnd
, 0);
3688 case IDC_ENABLE_ALL_PURPOSES
:
3689 case IDC_DISABLE_ALL_PURPOSES
:
3690 case IDC_ENABLE_SELECTED_PURPOSES
:
3691 SendMessageW(GetParent(hwnd
), PSM_CHANGED
, (WPARAM
)hwnd
, 0);
3692 select_purposes(hwnd
, LOWORD(wp
) - IDC_ENABLE_ALL_PURPOSES
);
3702 static UINT CALLBACK
cert_properties_general_callback(HWND hwnd
, UINT msg
,
3703 PROPSHEETPAGEW
*page
)
3707 struct edit_cert_data
*data
;
3712 lv
= GetDlgItem(hwnd
, IDC_CERTIFICATE_USAGES
);
3713 cItem
= SendMessageW(lv
, LVM_GETITEMCOUNT
, 0, 0);
3714 for (i
= 0; i
< cItem
; i
++)
3718 item
.mask
= LVIF_PARAM
;
3721 if (SendMessageW(lv
, LVM_GETITEMW
, 0, (LPARAM
)&item
) && item
.lParam
)
3723 PCRYPT_OID_INFO info
= (PCRYPT_OID_INFO
)item
.lParam
;
3725 if (info
->cbSize
== sizeof(CRYPT_OID_INFO
) && !info
->dwGroupId
)
3727 HeapFree(GetProcessHeap(), 0, (LPSTR
)info
->pszOID
);
3728 HeapFree(GetProcessHeap(), 0, info
);
3732 data
= (struct edit_cert_data
*)GetWindowLongPtrW(hwnd
, DWLP_USER
);
3735 ImageList_Destroy(data
->imageList
);
3736 HeapFree(GetProcessHeap(), 0, data
);
3743 static void show_edit_cert_properties_dialog(HWND parent
,
3744 struct detail_data
*data
)
3746 PROPSHEETHEADERW hdr
;
3747 PROPSHEETPAGEW page
; /* FIXME: need to add a cross-certificate page */
3749 TRACE("(%p)\n", data
);
3751 memset(&page
, 0, sizeof(PROPSHEETPAGEW
));
3752 page
.dwSize
= sizeof(page
);
3753 page
.dwFlags
= PSP_USECALLBACK
;
3754 page
.pfnCallback
= cert_properties_general_callback
;
3755 page
.hInstance
= hInstance
;
3756 page
.u
.pszTemplate
= MAKEINTRESOURCEW(IDD_CERT_PROPERTIES_GENERAL
);
3757 page
.pfnDlgProc
= cert_properties_general_dlg_proc
;
3758 page
.lParam
= (LPARAM
)data
;
3760 memset(&hdr
, 0, sizeof(hdr
));
3761 hdr
.dwSize
= sizeof(hdr
);
3762 hdr
.hwndParent
= parent
;
3763 hdr
.dwFlags
= PSH_PROPSHEETPAGE
;
3764 hdr
.hInstance
= hInstance
;
3765 hdr
.pszCaption
= MAKEINTRESOURCEW(IDS_CERTIFICATE_PROPERTIES
);
3766 hdr
.u3
.ppsp
= &page
;
3768 PropertySheetW(&hdr
);
3771 static void free_detail_fields(struct detail_data
*data
)
3775 for (i
= 0; i
< data
->cFields
; i
++)
3776 HeapFree(GetProcessHeap(), 0, data
->fields
[i
].detailed_value
);
3777 HeapFree(GetProcessHeap(), 0, data
->fields
);
3778 data
->fields
= NULL
;
3782 static void refresh_details_view(HWND hwnd
)
3784 HWND cb
= GetDlgItem(hwnd
, IDC_DETAIL_SELECT
);
3786 struct detail_data
*data
;
3788 curSel
= SendMessageW(cb
, CB_GETCURSEL
, 0, 0);
3789 /* Actually, any index will do, since they all store the same data value */
3790 data
= (struct detail_data
*)SendMessageW(cb
, CB_GETITEMDATA
, curSel
, 0);
3791 free_detail_fields(data
);
3792 set_fields_selection(hwnd
, data
, curSel
);
3795 static LRESULT CALLBACK
detail_dlg_proc(HWND hwnd
, UINT msg
, WPARAM wp
,
3798 PROPSHEETPAGEW
*page
;
3799 struct detail_data
*data
;
3801 TRACE("(%p, %08x, %08lx, %08lx)\n", hwnd
, msg
, wp
, lp
);
3806 page
= (PROPSHEETPAGEW
*)lp
;
3807 data
= (struct detail_data
*)page
->lParam
;
3808 create_cert_details_list(hwnd
, data
);
3809 if (!(data
->pCertViewInfo
->dwFlags
& CRYPTUI_ENABLE_EDITPROPERTIES
))
3810 EnableWindow(GetDlgItem(hwnd
, IDC_EDITPROPERTIES
), FALSE
);
3811 if (data
->pCertViewInfo
->dwFlags
& CRYPTUI_DISABLE_EXPORT
)
3812 EnableWindow(GetDlgItem(hwnd
, IDC_EXPORT
), FALSE
);
3817 HWND list
= GetDlgItem(hwnd
, IDC_DETAIL_LIST
);
3819 nm
= (NMITEMACTIVATE
*)lp
;
3820 if (nm
->hdr
.hwndFrom
== list
&& nm
->uNewState
& LVN_ITEMACTIVATE
3821 && nm
->hdr
.code
== LVN_ITEMCHANGED
)
3823 data
= (struct detail_data
*)nm
->lParam
;
3824 if (nm
->iItem
>= 0 && data
&& nm
->iItem
< data
->cFields
)
3826 WCHAR buf
[MAX_STRING_LEN
], *val
= NULL
;
3827 HWND valueCtl
= GetDlgItem(hwnd
, IDC_DETAIL_VALUE
);
3829 if (data
->fields
[nm
->iItem
].create
)
3830 val
= data
->fields
[nm
->iItem
].create(
3831 data
->pCertViewInfo
->pCertContext
,
3832 data
->fields
[nm
->iItem
].param
);
3838 item
.cchTextMax
= sizeof(buf
) / sizeof(buf
[0]);
3839 item
.mask
= LVIF_TEXT
;
3841 item
.iItem
= nm
->iItem
;
3843 res
= SendMessageW(list
, LVM_GETITEMW
, 0, (LPARAM
)&item
);
3847 /* Select all the text in the control, the next update will
3850 SendMessageW(valueCtl
, EM_SETSEL
, 0, -1);
3851 add_unformatted_text_to_control(valueCtl
, val
,
3852 val
? strlenW(val
) : 0);
3854 HeapFree(GetProcessHeap(), 0, val
);
3864 HWND cb
= GetDlgItem(hwnd
, IDC_DETAIL_SELECT
);
3865 CRYPTUI_WIZ_EXPORT_INFO info
;
3867 data
= (struct detail_data
*)SendMessageW(cb
, CB_GETITEMDATA
, 0, 0);
3868 info
.dwSize
= sizeof(info
);
3869 info
.pwszExportFileName
= NULL
;
3870 info
.dwSubjectChoice
= CRYPTUI_WIZ_EXPORT_CERT_CONTEXT
;
3871 info
.u
.pCertContext
= data
->pCertViewInfo
->pCertContext
;
3873 CryptUIWizExport(0, hwnd
, NULL
, &info
, NULL
);
3876 case IDC_EDITPROPERTIES
:
3878 HWND cb
= GetDlgItem(hwnd
, IDC_DETAIL_SELECT
);
3881 curSel
= SendMessageW(cb
, CB_GETCURSEL
, 0, 0);
3882 /* Actually, any index will do, since they all store the same
3885 data
= (struct detail_data
*)SendMessageW(cb
, CB_GETITEMDATA
,
3887 show_edit_cert_properties_dialog(GetParent(hwnd
), data
);
3890 case ((CBN_SELCHANGE
<< 16) | IDC_DETAIL_SELECT
):
3891 refresh_details_view(hwnd
);
3895 case WM_REFRESH_VIEW
:
3896 refresh_details_view(hwnd
);
3902 static UINT CALLBACK
detail_callback(HWND hwnd
, UINT msg
,
3903 PROPSHEETPAGEW
*page
)
3905 struct detail_data
*data
;
3910 data
= (struct detail_data
*)page
->lParam
;
3911 free_detail_fields(data
);
3912 HeapFree(GetProcessHeap(), 0, data
);
3918 static BOOL
init_detail_page(PCCRYPTUI_VIEWCERTIFICATE_STRUCTW pCertViewInfo
,
3919 BOOL
*pfPropertiesChanged
, PROPSHEETPAGEW
*page
)
3922 struct detail_data
*data
= HeapAlloc(GetProcessHeap(), 0,
3923 sizeof(struct detail_data
));
3927 data
->pCertViewInfo
= pCertViewInfo
;
3928 data
->pfPropertiesChanged
= pfPropertiesChanged
;
3930 data
->fields
= NULL
;
3931 memset(page
, 0, sizeof(PROPSHEETPAGEW
));
3932 page
->dwSize
= sizeof(PROPSHEETPAGEW
);
3933 page
->dwFlags
= PSP_USECALLBACK
;
3934 page
->pfnCallback
= detail_callback
;
3935 page
->hInstance
= hInstance
;
3936 page
->u
.pszTemplate
= MAKEINTRESOURCEW(IDD_DETAIL
);
3937 page
->pfnDlgProc
= detail_dlg_proc
;
3938 page
->lParam
= (LPARAM
)data
;
3946 struct hierarchy_data
3948 PCCRYPTUI_VIEWCERTIFICATE_STRUCTW pCertViewInfo
;
3949 HIMAGELIST imageList
;
3953 static LPARAM
index_to_lparam(struct hierarchy_data
*data
, DWORD index
)
3955 CRYPT_PROVIDER_SGNR
*provSigner
= WTHelperGetProvSignerFromChain(
3956 (CRYPT_PROVIDER_DATA
*)data
->pCertViewInfo
->u
.pCryptProviderData
,
3957 data
->pCertViewInfo
->idxSigner
, data
->pCertViewInfo
->fCounterSigner
,
3958 data
->pCertViewInfo
->idxCounterSigner
);
3960 /* Takes advantage of the fact that a pointer is 32-bit aligned, and
3961 * therefore always even.
3963 if (index
== provSigner
->csCertChain
- 1)
3964 return (LPARAM
)data
;
3965 return index
<< 1 | 1;
3968 static inline DWORD
lparam_to_index(struct hierarchy_data
*data
, LPARAM lp
)
3970 CRYPT_PROVIDER_SGNR
*provSigner
= WTHelperGetProvSignerFromChain(
3971 (CRYPT_PROVIDER_DATA
*)data
->pCertViewInfo
->u
.pCryptProviderData
,
3972 data
->pCertViewInfo
->idxSigner
, data
->pCertViewInfo
->fCounterSigner
,
3973 data
->pCertViewInfo
->idxCounterSigner
);
3976 return provSigner
->csCertChain
- 1;
3980 static struct hierarchy_data
*get_hierarchy_data_from_tree_item(HWND tree
,
3983 struct hierarchy_data
*data
= NULL
;
3984 HTREEITEM root
= NULL
;
3987 HTREEITEM parent
= (HTREEITEM
)SendMessageW(tree
, TVM_GETNEXTITEM
,
3988 TVGN_PARENT
, (LPARAM
)hItem
);
3998 item
.mask
= TVIF_PARAM
;
4000 SendMessageW(tree
, TVM_GETITEMW
, 0, (LPARAM
)&item
);
4001 data
= (struct hierarchy_data
*)item
.lParam
;
4006 static WCHAR
*get_cert_display_name(PCCERT_CONTEXT cert
)
4008 WCHAR
*name
= get_cert_property_as_string(cert
, CERT_FRIENDLY_NAME_PROP_ID
);
4011 name
= get_cert_name_string(cert
, CERT_NAME_SIMPLE_DISPLAY_TYPE
, 0);
4015 static void show_cert_chain(HWND hwnd
, struct hierarchy_data
*data
)
4017 HWND tree
= GetDlgItem(hwnd
, IDC_CERTPATH
);
4018 CRYPT_PROVIDER_SGNR
*provSigner
= WTHelperGetProvSignerFromChain(
4019 (CRYPT_PROVIDER_DATA
*)data
->pCertViewInfo
->u
.pCryptProviderData
,
4020 data
->pCertViewInfo
->idxSigner
, data
->pCertViewInfo
->fCounterSigner
,
4021 data
->pCertViewInfo
->idxCounterSigner
);
4023 HTREEITEM parent
= NULL
;
4025 SendMessageW(tree
, TVM_SETIMAGELIST
, TVSIL_NORMAL
, (LPARAM
)data
->imageList
);
4026 for (i
= provSigner
->csCertChain
; i
; i
--)
4030 name
= get_cert_display_name(provSigner
->pasCertChain
[i
- 1].pCert
);
4033 TVINSERTSTRUCTW tvis
;
4035 tvis
.hParent
= parent
;
4036 tvis
.hInsertAfter
= TVI_LAST
;
4037 tvis
.u
.item
.mask
= TVIF_TEXT
| TVIF_STATE
| TVIF_IMAGE
|
4038 TVIF_SELECTEDIMAGE
| TVIF_PARAM
;
4039 tvis
.u
.item
.pszText
= name
;
4040 tvis
.u
.item
.state
= TVIS_EXPANDED
;
4041 tvis
.u
.item
.stateMask
= TVIS_EXPANDED
;
4042 if (i
== 1 && (!provSigner
->pChainContext
||
4043 provSigner
->pChainContext
->TrustStatus
.dwErrorStatus
&
4044 CERT_TRUST_IS_PARTIAL_CHAIN
))
4046 /* The root of the chain has a special case: if the chain is
4047 * a partial chain, the icon is a warning icon rather than an
4050 tvis
.u
.item
.iImage
= 2;
4052 else if (provSigner
->pasCertChain
[i
- 1].pChainElement
->TrustStatus
.
4054 tvis
.u
.item
.iImage
= 0;
4056 tvis
.u
.item
.iImage
= 1;
4057 tvis
.u
.item
.iSelectedImage
= tvis
.u
.item
.iImage
;
4058 tvis
.u
.item
.lParam
= index_to_lparam(data
, i
- 1);
4059 parent
= (HTREEITEM
)SendMessageW(tree
, TVM_INSERTITEMW
, 0,
4061 HeapFree(GetProcessHeap(), 0, name
);
4066 static void set_certificate_status(HWND hwnd
, const CRYPT_PROVIDER_CERT
*cert
)
4068 /* Select all the text in the control, the next update will replace it */
4069 SendMessageW(hwnd
, EM_SETSEL
, 0, -1);
4070 /* Set the highest priority error messages first. */
4071 if (!(cert
->dwConfidence
& CERT_CONFIDENCE_SIG
))
4072 add_string_resource_to_control(hwnd
, IDS_CERTIFICATE_BAD_SIGNATURE
);
4073 else if (!(cert
->dwConfidence
& CERT_CONFIDENCE_TIME
))
4074 add_string_resource_to_control(hwnd
, IDS_CERTIFICATE_BAD_TIME
);
4075 else if (!(cert
->dwConfidence
& CERT_CONFIDENCE_TIMENEST
))
4076 add_string_resource_to_control(hwnd
, IDS_CERTIFICATE_BAD_TIMENEST
);
4077 else if (cert
->dwRevokedReason
)
4078 add_string_resource_to_control(hwnd
, IDS_CERTIFICATE_REVOKED
);
4080 add_string_resource_to_control(hwnd
, IDS_CERTIFICATE_VALID
);
4083 static void set_certificate_status_for_end_cert(HWND hwnd
,
4084 PCCRYPTUI_VIEWCERTIFICATE_STRUCTW pCertViewInfo
)
4086 HWND status
= GetDlgItem(hwnd
, IDC_CERTIFICATESTATUSTEXT
);
4087 CRYPT_PROVIDER_SGNR
*provSigner
= WTHelperGetProvSignerFromChain(
4088 (CRYPT_PROVIDER_DATA
*)pCertViewInfo
->u
.pCryptProviderData
,
4089 pCertViewInfo
->idxSigner
, pCertViewInfo
->fCounterSigner
,
4090 pCertViewInfo
->idxCounterSigner
);
4091 CRYPT_PROVIDER_CERT
*provCert
= WTHelperGetProvCertFromChain(provSigner
,
4092 pCertViewInfo
->idxCert
);
4094 set_certificate_status(status
, provCert
);
4097 static void show_cert_hierarchy(HWND hwnd
, struct hierarchy_data
*data
)
4099 /* Disable view certificate button until a certificate is selected */
4100 EnableWindow(GetDlgItem(hwnd
, IDC_VIEWCERTIFICATE
), FALSE
);
4101 show_cert_chain(hwnd
, data
);
4102 set_certificate_status_for_end_cert(hwnd
, data
->pCertViewInfo
);
4105 static void show_dialog_for_selected_cert(HWND hwnd
)
4107 HWND tree
= GetDlgItem(hwnd
, IDC_CERTPATH
);
4109 struct hierarchy_data
*data
;
4112 memset(&item
, 0, sizeof(item
));
4113 item
.mask
= TVIF_HANDLE
| TVIF_PARAM
;
4114 item
.hItem
= (HTREEITEM
)SendMessageW(tree
, TVM_GETNEXTITEM
, TVGN_CARET
, 0);
4115 SendMessageW(tree
, TVM_GETITEMW
, 0, (LPARAM
)&item
);
4116 data
= get_hierarchy_data_from_tree_item(tree
, item
.hItem
);
4117 selection
= lparam_to_index(data
, item
.lParam
);
4120 CRYPT_PROVIDER_SGNR
*provSigner
;
4121 CRYPTUI_VIEWCERTIFICATE_STRUCTW viewInfo
;
4122 BOOL changed
= FALSE
;
4124 provSigner
= WTHelperGetProvSignerFromChain(
4125 (CRYPT_PROVIDER_DATA
*)data
->pCertViewInfo
->u
.pCryptProviderData
,
4126 data
->pCertViewInfo
->idxSigner
,
4127 data
->pCertViewInfo
->fCounterSigner
,
4128 data
->pCertViewInfo
->idxCounterSigner
);
4129 memset(&viewInfo
, 0, sizeof(viewInfo
));
4130 viewInfo
.dwSize
= sizeof(viewInfo
);
4131 viewInfo
.dwFlags
= data
->pCertViewInfo
->dwFlags
;
4132 viewInfo
.szTitle
= data
->pCertViewInfo
->szTitle
;
4133 viewInfo
.pCertContext
= provSigner
->pasCertChain
[selection
].pCert
;
4134 viewInfo
.cStores
= data
->pCertViewInfo
->cStores
;
4135 viewInfo
.rghStores
= data
->pCertViewInfo
->rghStores
;
4136 viewInfo
.cPropSheetPages
= data
->pCertViewInfo
->cPropSheetPages
;
4137 viewInfo
.rgPropSheetPages
= data
->pCertViewInfo
->rgPropSheetPages
;
4138 viewInfo
.nStartPage
= data
->pCertViewInfo
->nStartPage
;
4139 CryptUIDlgViewCertificateW(&viewInfo
, &changed
);
4142 /* Delete the contents of the tree */
4143 SendMessageW(tree
, TVM_DELETEITEM
, 0, (LPARAM
)TVI_ROOT
);
4144 /* Reinitialize the tree */
4145 show_cert_hierarchy(hwnd
, data
);
4150 static LRESULT CALLBACK
hierarchy_dlg_proc(HWND hwnd
, UINT msg
, WPARAM wp
,
4153 PROPSHEETPAGEW
*page
;
4154 struct hierarchy_data
*data
;
4156 HWND tree
= GetDlgItem(hwnd
, IDC_CERTPATH
);
4158 TRACE("(%p, %08x, %08lx, %08lx)\n", hwnd
, msg
, wp
, lp
);
4163 page
= (PROPSHEETPAGEW
*)lp
;
4164 data
= (struct hierarchy_data
*)page
->lParam
;
4165 show_cert_hierarchy(hwnd
, data
);
4174 case TVN_SELCHANGEDW
:
4176 NMTREEVIEWW
*nm
= (NMTREEVIEWW
*)lp
;
4178 CRYPT_PROVIDER_SGNR
*provSigner
;
4180 data
= get_hierarchy_data_from_tree_item(tree
, nm
->itemNew
.hItem
);
4181 selection
= lparam_to_index(data
, nm
->itemNew
.lParam
);
4182 provSigner
= WTHelperGetProvSignerFromChain(
4183 (CRYPT_PROVIDER_DATA
*)data
->pCertViewInfo
->u
.pCryptProviderData
,
4184 data
->pCertViewInfo
->idxSigner
,
4185 data
->pCertViewInfo
->fCounterSigner
,
4186 data
->pCertViewInfo
->idxCounterSigner
);
4187 EnableWindow(GetDlgItem(hwnd
, IDC_VIEWCERTIFICATE
), selection
!= 0);
4188 set_certificate_status(GetDlgItem(hwnd
, IDC_CERTIFICATESTATUSTEXT
),
4189 &provSigner
->pasCertChain
[selection
]);
4193 show_dialog_for_selected_cert(hwnd
);
4194 SetWindowLongPtrW(hwnd
, DWLP_MSGRESULT
, 1);
4203 case IDC_VIEWCERTIFICATE
:
4204 show_dialog_for_selected_cert(hwnd
);
4208 case WM_REFRESH_VIEW
:
4212 /* Get hierarchy data */
4213 memset(&item
, 0, sizeof(item
));
4214 item
.mask
= TVIF_HANDLE
| TVIF_PARAM
;
4215 item
.hItem
= (HTREEITEM
)SendMessageW(tree
, TVM_GETNEXTITEM
, TVGN_ROOT
,
4217 data
= get_hierarchy_data_from_tree_item(tree
, item
.hItem
);
4218 /* Delete the contents of the tree */
4219 SendMessageW(tree
, TVM_DELETEITEM
, 0, (LPARAM
)TVI_ROOT
);
4220 /* Reinitialize the tree */
4221 show_cert_hierarchy(hwnd
, data
);
4228 static UINT CALLBACK
hierarchy_callback(HWND hwnd
, UINT msg
,
4229 PROPSHEETPAGEW
*page
)
4231 struct hierarchy_data
*data
;
4236 data
= (struct hierarchy_data
*)page
->lParam
;
4237 ImageList_Destroy(data
->imageList
);
4238 HeapFree(GetProcessHeap(), 0, data
);
4244 static BOOL
init_hierarchy_page(PCCRYPTUI_VIEWCERTIFICATE_STRUCTW pCertViewInfo
,
4245 PROPSHEETPAGEW
*page
)
4247 struct hierarchy_data
*data
= HeapAlloc(GetProcessHeap(), 0,
4248 sizeof(struct hierarchy_data
));
4253 data
->imageList
= ImageList_Create(16, 16, ILC_COLOR4
| ILC_MASK
, 2, 0);
4254 if (data
->imageList
)
4257 COLORREF backColor
= RGB(255, 0, 255);
4259 data
->pCertViewInfo
= pCertViewInfo
;
4260 data
->selectedCert
= 0xffffffff;
4262 bmp
= LoadBitmapW(hInstance
, MAKEINTRESOURCEW(IDB_SMALL_ICONS
));
4263 ImageList_AddMasked(data
->imageList
, bmp
, backColor
);
4265 ImageList_SetBkColor(data
->imageList
, CLR_NONE
);
4267 memset(page
, 0, sizeof(PROPSHEETPAGEW
));
4268 page
->dwSize
= sizeof(PROPSHEETPAGEW
);
4269 page
->dwFlags
= PSP_USECALLBACK
;
4270 page
->hInstance
= hInstance
;
4271 page
->u
.pszTemplate
= MAKEINTRESOURCEW(IDD_HIERARCHY
);
4272 page
->pfnDlgProc
= hierarchy_dlg_proc
;
4273 page
->lParam
= (LPARAM
)data
;
4274 page
->pfnCallback
= hierarchy_callback
;
4278 HeapFree(GetProcessHeap(), 0, data
);
4283 static int CALLBACK
cert_prop_sheet_proc(HWND hwnd
, UINT msg
, LPARAM lp
)
4287 TRACE("(%p, %08x, %08lx)\n", hwnd
, msg
, lp
);
4291 case PSCB_INITIALIZED
:
4292 /* Get cancel button's position.. */
4293 GetWindowRect(GetDlgItem(hwnd
, IDCANCEL
), &rc
);
4294 MapWindowPoints( 0, hwnd
, (POINT
*)&rc
, 2 );
4295 /* hide the cancel button.. */
4296 ShowWindow(GetDlgItem(hwnd
, IDCANCEL
), FALSE
);
4297 /* and move the OK button to the cancel button's original position. */
4298 SetWindowPos(GetDlgItem(hwnd
, IDOK
), 0, rc
.left
, rc
.top
, 0, 0,
4299 SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
);
4305 static BOOL
show_cert_dialog(PCCRYPTUI_VIEWCERTIFICATE_STRUCTW pCertViewInfo
,
4306 CRYPT_PROVIDER_CERT
*provCert
, BOOL
*pfPropertiesChanged
)
4308 static const WCHAR riched
[] = { 'r','i','c','h','e','d','2','0',0 };
4310 PROPSHEETPAGEW
*pages
;
4312 HMODULE lib
= LoadLibraryW(riched
);
4314 nPages
= pCertViewInfo
->cPropSheetPages
+ 1; /* one for the General tab */
4315 if (!(pCertViewInfo
->dwFlags
& CRYPTUI_HIDE_DETAILPAGE
))
4317 if (!(pCertViewInfo
->dwFlags
& CRYPTUI_HIDE_HIERARCHYPAGE
))
4319 pages
= HeapAlloc(GetProcessHeap(), 0, nPages
* sizeof(PROPSHEETPAGEW
));
4322 PROPSHEETHEADERW hdr
;
4323 CRYPTUI_INITDIALOG_STRUCT
*init
= NULL
;
4326 memset(&hdr
, 0, sizeof(hdr
));
4327 hdr
.dwSize
= sizeof(hdr
);
4328 hdr
.dwFlags
= PSH_NOAPPLYNOW
| PSH_PROPSHEETPAGE
| PSH_USECALLBACK
;
4329 hdr
.hInstance
= hInstance
;
4330 if (pCertViewInfo
->szTitle
)
4331 hdr
.pszCaption
= pCertViewInfo
->szTitle
;
4333 hdr
.pszCaption
= MAKEINTRESOURCEW(IDS_CERTIFICATE
);
4334 init_general_page(pCertViewInfo
, &pages
[hdr
.nPages
++]);
4335 if (!(pCertViewInfo
->dwFlags
& CRYPTUI_HIDE_DETAILPAGE
))
4337 if (init_detail_page(pCertViewInfo
, pfPropertiesChanged
,
4338 &pages
[hdr
.nPages
]))
4341 if (!(pCertViewInfo
->dwFlags
& CRYPTUI_HIDE_HIERARCHYPAGE
))
4343 if (init_hierarchy_page(pCertViewInfo
, &pages
[hdr
.nPages
]))
4346 /* Copy each additional page, and create the init dialog struct for it
4348 if (pCertViewInfo
->cPropSheetPages
)
4350 init
= HeapAlloc(GetProcessHeap(), 0,
4351 pCertViewInfo
->cPropSheetPages
*
4352 sizeof(CRYPTUI_INITDIALOG_STRUCT
));
4355 for (i
= 0; i
< pCertViewInfo
->cPropSheetPages
; i
++)
4357 memcpy(&pages
[hdr
.nPages
+ i
],
4358 &pCertViewInfo
->rgPropSheetPages
[i
],
4359 sizeof(PROPSHEETPAGEW
));
4360 init
[i
].lParam
= pCertViewInfo
->rgPropSheetPages
[i
].lParam
;
4361 init
[i
].pCertContext
= pCertViewInfo
->pCertContext
;
4362 pages
[hdr
.nPages
+ i
].lParam
= (LPARAM
)&init
[i
];
4364 if (pCertViewInfo
->nStartPage
& 0x8000)
4366 /* Start page index is relative to the number of default
4369 hdr
.u2
.nStartPage
= pCertViewInfo
->nStartPage
+ hdr
.nPages
;
4372 hdr
.u2
.nStartPage
= pCertViewInfo
->nStartPage
;
4373 hdr
.nPages
= nPages
;
4377 SetLastError(ERROR_OUTOFMEMORY
);
4381 /* Ignore the relative flag if there aren't any additional pages */
4382 hdr
.u2
.nStartPage
= pCertViewInfo
->nStartPage
& 0x7fff;
4389 hdr
.u3
.ppsp
= pages
;
4390 hdr
.pfnCallback
= cert_prop_sheet_proc
;
4391 l
= PropertySheetW(&hdr
);
4394 SetLastError(ERROR_CANCELLED
);
4398 HeapFree(GetProcessHeap(), 0, init
);
4399 HeapFree(GetProcessHeap(), 0, pages
);
4402 SetLastError(ERROR_OUTOFMEMORY
);
4407 /***********************************************************************
4408 * CryptUIDlgViewCertificateW (CRYPTUI.@)
4410 BOOL WINAPI
CryptUIDlgViewCertificateW(
4411 PCCRYPTUI_VIEWCERTIFICATE_STRUCTW pCertViewInfo
, BOOL
*pfPropertiesChanged
)
4413 static GUID generic_cert_verify
= WINTRUST_ACTION_GENERIC_CERT_VERIFY
;
4414 CRYPTUI_VIEWCERTIFICATE_STRUCTW viewInfo
;
4416 WINTRUST_CERT_INFO cert
;
4418 CRYPT_PROVIDER_SGNR
*signer
;
4419 CRYPT_PROVIDER_CERT
*provCert
= NULL
;
4421 TRACE("(%p, %p)\n", pCertViewInfo
, pfPropertiesChanged
);
4423 if (pCertViewInfo
->dwSize
!= sizeof(CRYPTUI_VIEWCERTIFICATE_STRUCTW
))
4425 SetLastError(ERROR_INVALID_PARAMETER
);
4428 /* Make a local copy in case we have to call WinVerifyTrust ourselves */
4429 memcpy(&viewInfo
, pCertViewInfo
, sizeof(viewInfo
));
4430 if (!pCertViewInfo
->u
.hWVTStateData
)
4432 memset(&wvt
, 0, sizeof(wvt
));
4433 wvt
.cbStruct
= sizeof(wvt
);
4434 wvt
.dwUIChoice
= WTD_UI_NONE
;
4435 if (viewInfo
.dwFlags
&
4436 CRYPTUI_ENABLE_REVOCATION_CHECK_CHAIN_EXCLUDE_ROOT
)
4437 wvt
.fdwRevocationChecks
|= WTD_REVOCATION_CHECK_CHAIN_EXCLUDE_ROOT
;
4438 if (viewInfo
.dwFlags
& CRYPTUI_ENABLE_REVOCATION_CHECK_END_CERT
)
4439 wvt
.fdwRevocationChecks
|= WTD_REVOCATION_CHECK_END_CERT
;
4440 if (viewInfo
.dwFlags
& CRYPTUI_ENABLE_REVOCATION_CHECK_CHAIN
)
4441 wvt
.fdwRevocationChecks
|= WTD_REVOCATION_CHECK_CHAIN
;
4442 wvt
.dwUnionChoice
= WTD_CHOICE_CERT
;
4443 memset(&cert
, 0, sizeof(cert
));
4444 cert
.cbStruct
= sizeof(cert
);
4445 cert
.psCertContext
= (CERT_CONTEXT
*)viewInfo
.pCertContext
;
4446 cert
.chStores
= viewInfo
.cStores
;
4447 cert
.pahStores
= viewInfo
.rghStores
;
4448 wvt
.u
.pCert
= &cert
;
4449 wvt
.dwStateAction
= WTD_STATEACTION_VERIFY
;
4450 WinVerifyTrust(NULL
, &generic_cert_verify
, &wvt
);
4451 viewInfo
.u
.pCryptProviderData
=
4452 WTHelperProvDataFromStateData(wvt
.hWVTStateData
);
4453 signer
= WTHelperGetProvSignerFromChain(
4454 (CRYPT_PROVIDER_DATA
*)viewInfo
.u
.pCryptProviderData
, 0, FALSE
, 0);
4455 provCert
= WTHelperGetProvCertFromChain(signer
, 0);
4460 viewInfo
.u
.pCryptProviderData
=
4461 WTHelperProvDataFromStateData(viewInfo
.u
.hWVTStateData
);
4462 signer
= WTHelperGetProvSignerFromChain(
4463 (CRYPT_PROVIDER_DATA
*)viewInfo
.u
.pCryptProviderData
,
4464 viewInfo
.idxSigner
, viewInfo
.fCounterSigner
,
4465 viewInfo
.idxCounterSigner
);
4466 provCert
= WTHelperGetProvCertFromChain(signer
, viewInfo
.idxCert
);
4471 ret
= show_cert_dialog(&viewInfo
, provCert
, pfPropertiesChanged
);
4472 if (!pCertViewInfo
->u
.hWVTStateData
)
4474 wvt
.dwStateAction
= WTD_STATEACTION_CLOSE
;
4475 WinVerifyTrust(NULL
, &generic_cert_verify
, &wvt
);
4481 /***********************************************************************
4482 * CryptUIDlgViewContext (CRYPTUI.@)
4484 BOOL WINAPI
CryptUIDlgViewContext(DWORD dwContextType
, LPVOID pvContext
,
4485 HWND hwnd
, LPCWSTR pwszTitle
, DWORD dwFlags
, LPVOID pvReserved
)
4489 TRACE("(%d, %p, %p, %s, %08x, %p)\n", dwContextType
, pvContext
, hwnd
,
4490 debugstr_w(pwszTitle
), dwFlags
, pvReserved
);
4492 switch (dwContextType
)
4494 case CERT_STORE_CERTIFICATE_CONTEXT
:
4496 CRYPTUI_VIEWCERTIFICATE_STRUCTW viewInfo
;
4498 memset(&viewInfo
, 0, sizeof(viewInfo
));
4499 viewInfo
.dwSize
= sizeof(viewInfo
);
4500 viewInfo
.hwndParent
= hwnd
;
4501 viewInfo
.szTitle
= pwszTitle
;
4502 viewInfo
.pCertContext
= pvContext
;
4503 ret
= CryptUIDlgViewCertificateW(&viewInfo
, NULL
);
4507 FIXME("unimplemented for context type %d\n", dwContextType
);
4508 SetLastError(E_INVALIDARG
);
4514 /* Decodes a cert's basic constraints extension (either szOID_BASIC_CONSTRAINTS
4515 * or szOID_BASIC_CONSTRAINTS2, whichever is present) to determine if it
4516 * should be a CA. If neither extension is present, returns
4517 * defaultIfNotSpecified.
4519 static BOOL
is_ca_cert(PCCERT_CONTEXT cert
, BOOL defaultIfNotSpecified
)
4521 BOOL isCA
= defaultIfNotSpecified
;
4522 PCERT_EXTENSION ext
= CertFindExtension(szOID_BASIC_CONSTRAINTS
,
4523 cert
->pCertInfo
->cExtension
, cert
->pCertInfo
->rgExtension
);
4527 CERT_BASIC_CONSTRAINTS_INFO
*info
;
4530 if (CryptDecodeObjectEx(X509_ASN_ENCODING
, szOID_BASIC_CONSTRAINTS
,
4531 ext
->Value
.pbData
, ext
->Value
.cbData
, CRYPT_DECODE_ALLOC_FLAG
,
4532 NULL
, &info
, &size
))
4534 if (info
->SubjectType
.cbData
== 1)
4535 isCA
= info
->SubjectType
.pbData
[0] & CERT_CA_SUBJECT_FLAG
;
4541 ext
= CertFindExtension(szOID_BASIC_CONSTRAINTS2
,
4542 cert
->pCertInfo
->cExtension
, cert
->pCertInfo
->rgExtension
);
4545 CERT_BASIC_CONSTRAINTS2_INFO info
;
4546 DWORD size
= sizeof(CERT_BASIC_CONSTRAINTS2_INFO
);
4548 if (CryptDecodeObjectEx(X509_ASN_ENCODING
,
4549 szOID_BASIC_CONSTRAINTS2
, ext
->Value
.pbData
, ext
->Value
.cbData
,
4550 0, NULL
, &info
, &size
))
4557 static HCERTSTORE
choose_store_for_cert(PCCERT_CONTEXT cert
)
4561 if (is_ca_cert(cert
, TRUE
))
4564 storeName
= addressBook
;
4565 return CertOpenStore(CERT_STORE_PROV_SYSTEM_W
, 0, 0,
4566 CERT_SYSTEM_STORE_CURRENT_USER
, storeName
);
4569 static BOOL
import_cert(PCCERT_CONTEXT cert
, HCERTSTORE hDestCertStore
)
4576 SetLastError(E_INVALIDARG
);
4579 if (hDestCertStore
) store
= hDestCertStore
;
4582 if (!(store
= choose_store_for_cert(cert
)))
4584 WARN("unable to open certificate store\n");
4588 ret
= CertAddCertificateContextToStore(store
, cert
,
4589 CERT_STORE_ADD_REPLACE_EXISTING_INHERIT_PROPERTIES
, NULL
);
4590 if (!hDestCertStore
) CertCloseStore(store
, 0);
4594 static BOOL
import_crl(PCCRL_CONTEXT crl
, HCERTSTORE hDestCertStore
)
4601 SetLastError(E_INVALIDARG
);
4604 if (hDestCertStore
) store
= hDestCertStore
;
4607 if (!(store
= CertOpenStore(CERT_STORE_PROV_SYSTEM_W
, 0, 0,
4608 CERT_SYSTEM_STORE_CURRENT_USER
, ca
)))
4610 WARN("unable to open certificate store\n");
4614 ret
= CertAddCRLContextToStore(store
, crl
,
4615 CERT_STORE_ADD_REPLACE_EXISTING_INHERIT_PROPERTIES
, NULL
);
4616 if (!hDestCertStore
) CertCloseStore(store
, 0);
4620 static BOOL
import_ctl(PCCTL_CONTEXT ctl
, HCERTSTORE hDestCertStore
)
4627 SetLastError(E_INVALIDARG
);
4630 if (hDestCertStore
) store
= hDestCertStore
;
4633 static const WCHAR trust
[] = { 'T','r','u','s','t',0 };
4635 if (!(store
= CertOpenStore(CERT_STORE_PROV_SYSTEM_W
, 0, 0,
4636 CERT_SYSTEM_STORE_CURRENT_USER
, trust
)))
4638 WARN("unable to open certificate store\n");
4642 ret
= CertAddCTLContextToStore(store
, ctl
,
4643 CERT_STORE_ADD_REPLACE_EXISTING_INHERIT_PROPERTIES
, NULL
);
4644 if (!hDestCertStore
) CertCloseStore(store
, 0);
4648 /* Checks type, a type such as CERT_QUERY_CONTENT_CERT returned by
4649 * CryptQueryObject, against the allowed types. Returns TRUE if the
4650 * type is allowed, FALSE otherwise.
4652 static BOOL
check_context_type(DWORD dwFlags
, DWORD type
)
4657 (CRYPTUI_WIZ_IMPORT_ALLOW_CERT
| CRYPTUI_WIZ_IMPORT_ALLOW_CRL
|
4658 CRYPTUI_WIZ_IMPORT_ALLOW_CTL
))
4662 case CERT_QUERY_CONTENT_CERT
:
4663 case CERT_QUERY_CONTENT_SERIALIZED_CERT
:
4664 ret
= dwFlags
& CRYPTUI_WIZ_IMPORT_ALLOW_CERT
;
4666 case CERT_QUERY_CONTENT_CRL
:
4667 case CERT_QUERY_CONTENT_SERIALIZED_CRL
:
4668 ret
= dwFlags
& CRYPTUI_WIZ_IMPORT_ALLOW_CRL
;
4670 case CERT_QUERY_CONTENT_CTL
:
4671 case CERT_QUERY_CONTENT_SERIALIZED_CTL
:
4672 ret
= dwFlags
& CRYPTUI_WIZ_IMPORT_ALLOW_CTL
;
4675 /* The remaining types contain more than one type, so allow
4683 /* No allowed types specified, so any type is allowed */
4687 SetLastError(E_INVALIDARG
);
4692 static void import_warning(DWORD dwFlags
, HWND hwnd
, LPCWSTR szTitle
,
4695 if (!(dwFlags
& CRYPTUI_WIZ_NO_UI
))
4697 WCHAR title
[MAX_STRING_LEN
], error
[MAX_STRING_LEN
];
4704 LoadStringW(hInstance
, IDS_IMPORT_WIZARD
, title
,
4705 sizeof(title
) / sizeof(title
[0]));
4708 LoadStringW(hInstance
, warningID
, error
,
4709 sizeof(error
) / sizeof(error
[0]));
4710 MessageBoxW(hwnd
, error
, pTitle
, MB_ICONERROR
| MB_OK
);
4714 static void import_warn_type_mismatch(DWORD dwFlags
, HWND hwnd
, LPCWSTR szTitle
)
4716 import_warning(dwFlags
, hwnd
, szTitle
, IDS_IMPORT_TYPE_MISMATCH
);
4719 static BOOL
check_store_context_type(DWORD dwFlags
, HCERTSTORE store
)
4724 (CRYPTUI_WIZ_IMPORT_ALLOW_CERT
| CRYPTUI_WIZ_IMPORT_ALLOW_CRL
|
4725 CRYPTUI_WIZ_IMPORT_ALLOW_CTL
))
4727 PCCERT_CONTEXT cert
;
4732 if ((cert
= CertEnumCertificatesInStore(store
, NULL
)))
4734 CertFreeCertificateContext(cert
);
4735 if (!(dwFlags
& CRYPTUI_WIZ_IMPORT_ALLOW_CERT
))
4738 if (ret
&& (crl
= CertEnumCRLsInStore(store
, NULL
)))
4740 CertFreeCRLContext(crl
);
4741 if (!(dwFlags
& CRYPTUI_WIZ_IMPORT_ALLOW_CRL
))
4744 if (ret
&& (ctl
= CertEnumCTLsInStore(store
, NULL
)))
4746 CertFreeCTLContext(ctl
);
4747 if (!(dwFlags
& CRYPTUI_WIZ_IMPORT_ALLOW_CTL
))
4754 SetLastError(E_INVALIDARG
);
4758 static BOOL
import_store(DWORD dwFlags
, HWND hwnd
, LPCWSTR szTitle
,
4759 HCERTSTORE source
, HCERTSTORE dest
)
4763 if ((ret
= check_store_context_type(dwFlags
, source
)))
4765 PCCERT_CONTEXT cert
= NULL
;
4766 PCCRL_CONTEXT crl
= NULL
;
4767 PCCTL_CONTEXT ctl
= NULL
;
4770 cert
= CertEnumCertificatesInStore(source
, cert
);
4772 ret
= import_cert(cert
, dest
);
4773 } while (ret
&& cert
);
4775 crl
= CertEnumCRLsInStore(source
, crl
);
4777 ret
= import_crl(crl
, dest
);
4778 } while (ret
&& crl
);
4780 ctl
= CertEnumCTLsInStore(source
, ctl
);
4782 ret
= import_ctl(ctl
, dest
);
4783 } while (ret
&& ctl
);
4786 import_warn_type_mismatch(dwFlags
, hwnd
, szTitle
);
4790 static HCERTSTORE
open_store_from_file(DWORD dwFlags
, LPCWSTR fileName
,
4791 DWORD
*pContentType
)
4793 HCERTSTORE store
= NULL
;
4794 DWORD contentType
= 0, expectedContentTypeFlags
;
4797 (CRYPTUI_WIZ_IMPORT_ALLOW_CERT
| CRYPTUI_WIZ_IMPORT_ALLOW_CRL
|
4798 CRYPTUI_WIZ_IMPORT_ALLOW_CTL
))
4800 expectedContentTypeFlags
=
4801 CERT_QUERY_CONTENT_FLAG_SERIALIZED_STORE
|
4802 CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED
|
4803 CERT_QUERY_CONTENT_FLAG_PFX
;
4804 if (dwFlags
& CRYPTUI_WIZ_IMPORT_ALLOW_CERT
)
4805 expectedContentTypeFlags
|=
4806 CERT_QUERY_CONTENT_FLAG_CERT
|
4807 CERT_QUERY_CONTENT_FLAG_SERIALIZED_CERT
;
4808 if (dwFlags
& CRYPTUI_WIZ_IMPORT_ALLOW_CRL
)
4809 expectedContentTypeFlags
|=
4810 CERT_QUERY_CONTENT_FLAG_SERIALIZED_CRL
|
4811 CERT_QUERY_CONTENT_FLAG_CRL
;
4812 if (dwFlags
& CRYPTUI_WIZ_IMPORT_ALLOW_CTL
)
4813 expectedContentTypeFlags
|=
4814 CERT_QUERY_CONTENT_FLAG_CTL
|
4815 CERT_QUERY_CONTENT_FLAG_SERIALIZED_CTL
;
4818 expectedContentTypeFlags
=
4819 CERT_QUERY_CONTENT_FLAG_CERT
|
4820 CERT_QUERY_CONTENT_FLAG_CTL
|
4821 CERT_QUERY_CONTENT_FLAG_CRL
|
4822 CERT_QUERY_CONTENT_FLAG_SERIALIZED_STORE
|
4823 CERT_QUERY_CONTENT_FLAG_SERIALIZED_CERT
|
4824 CERT_QUERY_CONTENT_FLAG_SERIALIZED_CTL
|
4825 CERT_QUERY_CONTENT_FLAG_SERIALIZED_CRL
|
4826 CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED
|
4827 CERT_QUERY_CONTENT_FLAG_PFX
;
4829 CryptQueryObject(CERT_QUERY_OBJECT_FILE
, fileName
,
4830 expectedContentTypeFlags
, CERT_QUERY_FORMAT_FLAG_ALL
, 0, NULL
,
4831 &contentType
, NULL
, &store
, NULL
, NULL
);
4833 *pContentType
= contentType
;
4837 static BOOL
import_file(DWORD dwFlags
, HWND hwnd
, LPCWSTR szTitle
,
4838 LPCWSTR fileName
, HCERTSTORE dest
)
4843 if ((source
= open_store_from_file(dwFlags
, fileName
, NULL
)))
4845 ret
= import_store(dwFlags
, hwnd
, szTitle
, source
, dest
);
4846 CertCloseStore(source
, 0);
4853 struct ImportWizData
4857 LPCWSTR pwszWizardTitle
;
4858 CRYPTUI_WIZ_IMPORT_SRC_INFO importSrc
;
4862 HCERTSTORE hDestCertStore
;
4868 static LRESULT CALLBACK
import_welcome_dlg_proc(HWND hwnd
, UINT msg
, WPARAM wp
,
4877 struct ImportWizData
*data
;
4878 PROPSHEETPAGEW
*page
= (PROPSHEETPAGEW
*)lp
;
4879 WCHAR fontFace
[MAX_STRING_LEN
];
4880 HDC hDC
= GetDC(hwnd
);
4883 data
= (struct ImportWizData
*)page
->lParam
;
4884 LoadStringW(hInstance
, IDS_WIZARD_TITLE_FONT
, fontFace
,
4885 sizeof(fontFace
) / sizeof(fontFace
[0]));
4886 height
= -MulDiv(12, GetDeviceCaps(hDC
, LOGPIXELSY
), 72);
4887 data
->titleFont
= CreateFontW(height
, 0, 0, 0, FW_BOLD
, 0, 0, 0,
4888 DEFAULT_CHARSET
, OUT_DEFAULT_PRECIS
, CLIP_DEFAULT_PRECIS
,
4889 DEFAULT_QUALITY
, DEFAULT_PITCH
| FF_DONTCARE
, fontFace
);
4890 SendMessageW(GetDlgItem(hwnd
, IDC_IMPORT_TITLE
), WM_SETFONT
,
4891 (WPARAM
)data
->titleFont
, TRUE
);
4892 ReleaseDC(hwnd
, hDC
);
4897 NMHDR
*hdr
= (NMHDR
*)lp
;
4902 PostMessageW(GetParent(hwnd
), PSM_SETWIZBUTTONS
, 0, PSWIZB_NEXT
);
4912 static const WCHAR filter_cert
[] = { '*','.','c','e','r',';','*','.',
4914 static const WCHAR filter_pfx
[] = { '*','.','p','f','x',';','*','.',
4916 static const WCHAR filter_crl
[] = { '*','.','c','r','l',0 };
4917 static const WCHAR filter_ctl
[] = { '*','.','s','t','l',0 };
4918 static const WCHAR filter_serialized_store
[] = { '*','.','s','s','t',0 };
4919 static const WCHAR filter_cms
[] = { '*','.','s','p','c',';','*','.',
4921 static const WCHAR filter_all
[] = { '*','.','*',0 };
4923 static struct StringToFilter
4928 } import_filters
[] = {
4929 { IDS_IMPORT_FILTER_CERT
, CRYPTUI_WIZ_IMPORT_ALLOW_CERT
, filter_cert
},
4930 { IDS_IMPORT_FILTER_PFX
, 0, filter_pfx
},
4931 { IDS_IMPORT_FILTER_CRL
, CRYPTUI_WIZ_IMPORT_ALLOW_CRL
, filter_crl
},
4932 { IDS_IMPORT_FILTER_CTL
, CRYPTUI_WIZ_IMPORT_ALLOW_CTL
, filter_ctl
},
4933 { IDS_IMPORT_FILTER_SERIALIZED_STORE
, 0, filter_serialized_store
},
4934 { IDS_IMPORT_FILTER_CMS
, 0, filter_cms
},
4935 { IDS_IMPORT_FILTER_ALL
, 0, filter_all
},
4938 static WCHAR
*make_import_file_filter(DWORD dwFlags
)
4941 int len
, totalLen
= 2;
4942 LPWSTR filter
= NULL
, str
;
4944 for (i
= 0; i
< sizeof(import_filters
) / sizeof(import_filters
[0]); i
++)
4946 if (!import_filters
[i
].allowFlags
|| !dwFlags
||
4947 (dwFlags
& import_filters
[i
].allowFlags
))
4949 len
= LoadStringW(hInstance
, import_filters
[i
].id
, (LPWSTR
)&str
, 0);
4950 totalLen
+= len
+ strlenW(import_filters
[i
].filter
) + 2;
4953 filter
= HeapAlloc(GetProcessHeap(), 0, totalLen
* sizeof(WCHAR
));
4959 for (i
= 0; i
< sizeof(import_filters
) / sizeof(import_filters
[0]); i
++)
4961 if (!import_filters
[i
].allowFlags
|| !dwFlags
||
4962 (dwFlags
& import_filters
[i
].allowFlags
))
4964 len
= LoadStringW(hInstance
, import_filters
[i
].id
,
4966 memcpy(ptr
, str
, len
* sizeof(WCHAR
));
4969 strcpyW(ptr
, import_filters
[i
].filter
);
4970 ptr
+= strlenW(import_filters
[i
].filter
) + 1;
4978 static BOOL
import_validate_filename(HWND hwnd
, struct ImportWizData
*data
,
4984 file
= CreateFileW(fileName
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
4985 OPEN_EXISTING
, 0, NULL
);
4986 if (file
!= INVALID_HANDLE_VALUE
)
4988 HCERTSTORE source
= open_store_from_file(data
->dwFlags
, fileName
,
4989 &data
->contentType
);
4993 warningID
= IDS_IMPORT_BAD_FORMAT
;
4994 else if (!check_store_context_type(data
->dwFlags
, source
))
4995 warningID
= IDS_IMPORT_TYPE_MISMATCH
;
4998 data
->importSrc
.dwSubjectChoice
=
4999 CRYPTUI_WIZ_IMPORT_SUBJECT_CERT_STORE
;
5000 data
->importSrc
.u
.hCertStore
= source
;
5001 data
->freeSource
= TRUE
;
5006 import_warning(data
->dwFlags
, hwnd
, data
->pwszWizardTitle
,
5013 WCHAR title
[MAX_STRING_LEN
], error
[MAX_STRING_LEN
];
5015 LPWSTR msgBuf
, fullError
;
5017 if (data
->pwszWizardTitle
)
5018 pTitle
= data
->pwszWizardTitle
;
5021 LoadStringW(hInstance
, IDS_IMPORT_WIZARD
, title
,
5022 sizeof(title
) / sizeof(title
[0]));
5025 LoadStringW(hInstance
, IDS_IMPORT_OPEN_FAILED
, error
,
5026 sizeof(error
) / sizeof(error
[0]));
5028 FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM
, NULL
,
5029 GetLastError(), 0, (LPWSTR
) &msgBuf
, 0, NULL
);
5030 fullError
= HeapAlloc(GetProcessHeap(), 0,
5031 (strlenW(error
) + strlenW(fileName
) + strlenW(msgBuf
) + 3)
5035 LPWSTR ptr
= fullError
;
5037 strcpyW(ptr
, error
);
5038 ptr
+= strlenW(error
);
5039 strcpyW(ptr
, fileName
);
5040 ptr
+= strlenW(fileName
);
5043 strcpyW(ptr
, msgBuf
);
5044 MessageBoxW(hwnd
, fullError
, pTitle
, MB_ICONERROR
| MB_OK
);
5045 HeapFree(GetProcessHeap(), 0, fullError
);
5052 static LRESULT CALLBACK
import_file_dlg_proc(HWND hwnd
, UINT msg
, WPARAM wp
,
5056 struct ImportWizData
*data
;
5062 PROPSHEETPAGEW
*page
= (PROPSHEETPAGEW
*)lp
;
5064 data
= (struct ImportWizData
*)page
->lParam
;
5065 SetWindowLongPtrW(hwnd
, DWLP_USER
, (LPARAM
)data
);
5068 HWND fileNameEdit
= GetDlgItem(hwnd
, IDC_IMPORT_FILENAME
);
5070 SendMessageW(fileNameEdit
, WM_SETTEXT
, 0, (LPARAM
)data
->fileName
);
5076 NMHDR
*hdr
= (NMHDR
*)lp
;
5081 PostMessageW(GetParent(hwnd
), PSM_SETWIZBUTTONS
, 0,
5082 PSWIZB_BACK
| PSWIZB_NEXT
);
5087 HWND fileNameEdit
= GetDlgItem(hwnd
, IDC_IMPORT_FILENAME
);
5088 DWORD len
= SendMessageW(fileNameEdit
, WM_GETTEXTLENGTH
, 0, 0);
5090 data
= (struct ImportWizData
*)GetWindowLongPtrW(hwnd
, DWLP_USER
);
5093 import_warning(data
->dwFlags
, hwnd
, data
->pwszWizardTitle
,
5094 IDS_IMPORT_EMPTY_FILE
);
5095 SetWindowLongPtrW(hwnd
, DWLP_MSGRESULT
, 1);
5100 LPWSTR fileName
= HeapAlloc(GetProcessHeap(), 0,
5101 (len
+ 1) * sizeof(WCHAR
));
5105 SendMessageW(fileNameEdit
, WM_GETTEXT
, len
+ 1,
5107 if (!import_validate_filename(hwnd
, data
, fileName
))
5109 HeapFree(GetProcessHeap(), 0, fileName
);
5110 SetWindowLongPtrW(hwnd
, DWLP_MSGRESULT
, 1);
5114 data
->fileName
= fileName
;
5125 case IDC_IMPORT_BROWSE_FILE
:
5128 WCHAR fileBuf
[MAX_PATH
];
5130 data
= (struct ImportWizData
*)GetWindowLongPtrW(hwnd
, DWLP_USER
);
5131 memset(&ofn
, 0, sizeof(ofn
));
5132 ofn
.lStructSize
= sizeof(ofn
);
5133 ofn
.hwndOwner
= hwnd
;
5134 ofn
.lpstrFilter
= make_import_file_filter(data
->dwFlags
);
5135 ofn
.lpstrFile
= fileBuf
;
5136 ofn
.nMaxFile
= sizeof(fileBuf
) / sizeof(fileBuf
[0]);
5138 if (GetOpenFileNameW(&ofn
))
5139 SendMessageW(GetDlgItem(hwnd
, IDC_IMPORT_FILENAME
), WM_SETTEXT
,
5140 0, (LPARAM
)ofn
.lpstrFile
);
5141 HeapFree(GetProcessHeap(), 0, (LPWSTR
)ofn
.lpstrFilter
);
5150 static LRESULT CALLBACK
import_store_dlg_proc(HWND hwnd
, UINT msg
, WPARAM wp
,
5154 struct ImportWizData
*data
;
5160 PROPSHEETPAGEW
*page
= (PROPSHEETPAGEW
*)lp
;
5162 data
= (struct ImportWizData
*)page
->lParam
;
5163 SetWindowLongPtrW(hwnd
, DWLP_USER
, (LPARAM
)data
);
5164 if (!data
->hDestCertStore
)
5166 SendMessageW(GetDlgItem(hwnd
, IDC_IMPORT_AUTO_STORE
), BM_CLICK
,
5168 EnableWindow(GetDlgItem(hwnd
, IDC_IMPORT_STORE
), FALSE
);
5169 EnableWindow(GetDlgItem(hwnd
, IDC_IMPORT_BROWSE_STORE
), FALSE
);
5170 EnableWindow(GetDlgItem(hwnd
, IDC_IMPORT_SPECIFY_STORE
), FALSE
);
5174 WCHAR storeTitle
[MAX_STRING_LEN
];
5176 SendMessageW(GetDlgItem(hwnd
, IDC_IMPORT_SPECIFY_STORE
), BM_CLICK
,
5178 EnableWindow(GetDlgItem(hwnd
, IDC_IMPORT_STORE
), TRUE
);
5179 EnableWindow(GetDlgItem(hwnd
, IDC_IMPORT_BROWSE_STORE
), TRUE
);
5180 EnableWindow(GetDlgItem(hwnd
, IDC_IMPORT_SPECIFY_STORE
),
5181 !(data
->dwFlags
& CRYPTUI_WIZ_IMPORT_NO_CHANGE_DEST_STORE
));
5182 LoadStringW(hInstance
, IDS_IMPORT_DEST_DETERMINED
,
5183 storeTitle
, sizeof(storeTitle
) / sizeof(storeTitle
[0]));
5184 SendMessageW(GetDlgItem(hwnd
, IDC_IMPORT_STORE
), WM_SETTEXT
,
5185 0, (LPARAM
)storeTitle
);
5191 NMHDR
*hdr
= (NMHDR
*)lp
;
5196 PostMessageW(GetParent(hwnd
), PSM_SETWIZBUTTONS
, 0,
5197 PSWIZB_BACK
| PSWIZB_NEXT
);
5202 data
= (struct ImportWizData
*)GetWindowLongPtrW(hwnd
, DWLP_USER
);
5203 if (IsDlgButtonChecked(hwnd
, IDC_IMPORT_SPECIFY_STORE
) &&
5204 !data
->hDestCertStore
)
5206 import_warning(data
->dwFlags
, hwnd
, data
->pwszWizardTitle
,
5207 IDS_IMPORT_SELECT_STORE
);
5208 SetWindowLongPtrW(hwnd
, DWLP_MSGRESULT
, 1);
5219 case IDC_IMPORT_AUTO_STORE
:
5220 data
= (struct ImportWizData
*)GetWindowLongPtrW(hwnd
, DWLP_USER
);
5221 data
->autoDest
= TRUE
;
5222 EnableWindow(GetDlgItem(hwnd
, IDC_IMPORT_STORE
), FALSE
);
5223 EnableWindow(GetDlgItem(hwnd
, IDC_IMPORT_BROWSE_STORE
), FALSE
);
5225 case IDC_IMPORT_SPECIFY_STORE
:
5226 data
= (struct ImportWizData
*)GetWindowLongPtrW(hwnd
, DWLP_USER
);
5227 data
->autoDest
= FALSE
;
5228 EnableWindow(GetDlgItem(hwnd
, IDC_IMPORT_STORE
), TRUE
);
5229 EnableWindow(GetDlgItem(hwnd
, IDC_IMPORT_BROWSE_STORE
), TRUE
);
5231 case IDC_IMPORT_BROWSE_STORE
:
5233 CRYPTUI_ENUM_SYSTEM_STORE_ARGS enumArgs
= {
5234 CERT_SYSTEM_STORE_CURRENT_USER
, NULL
};
5235 CRYPTUI_ENUM_DATA enumData
= { 0, NULL
, 1, &enumArgs
};
5236 CRYPTUI_SELECTSTORE_INFO_W selectInfo
;
5239 data
= (struct ImportWizData
*)GetWindowLongPtrW(hwnd
, DWLP_USER
);
5240 selectInfo
.dwSize
= sizeof(selectInfo
);
5241 selectInfo
.parent
= hwnd
;
5242 selectInfo
.dwFlags
= CRYPTUI_ENABLE_SHOW_PHYSICAL_STORE
;
5243 selectInfo
.pwszTitle
= NULL
;
5244 selectInfo
.pwszText
= NULL
;
5245 selectInfo
.pEnumData
= &enumData
;
5246 selectInfo
.pfnSelectedStoreCallback
= NULL
;
5247 if ((store
= CryptUIDlgSelectStoreW(&selectInfo
)))
5249 WCHAR storeTitle
[MAX_STRING_LEN
];
5251 LoadStringW(hInstance
, IDS_IMPORT_DEST_DETERMINED
,
5252 storeTitle
, sizeof(storeTitle
) / sizeof(storeTitle
[0]));
5253 SendMessageW(GetDlgItem(hwnd
, IDC_IMPORT_STORE
), WM_SETTEXT
,
5254 0, (LPARAM
)storeTitle
);
5255 data
->hDestCertStore
= store
;
5256 data
->freeDest
= TRUE
;
5266 static void show_import_details(HWND lv
, struct ImportWizData
*data
)
5268 WCHAR text
[MAX_STRING_LEN
];
5272 item
.mask
= LVIF_TEXT
;
5273 item
.iItem
= SendMessageW(lv
, LVM_GETITEMCOUNT
, 0, 0);
5275 LoadStringW(hInstance
, IDS_IMPORT_STORE_SELECTION
, text
,
5276 sizeof(text
)/ sizeof(text
[0]));
5277 item
.pszText
= text
;
5278 SendMessageW(lv
, LVM_INSERTITEMW
, 0, (LPARAM
)&item
);
5281 LoadStringW(hInstance
, IDS_IMPORT_DEST_AUTOMATIC
, text
,
5282 sizeof(text
)/ sizeof(text
[0]));
5284 LoadStringW(hInstance
, IDS_IMPORT_DEST_DETERMINED
, text
,
5285 sizeof(text
)/ sizeof(text
[0]));
5286 SendMessageW(lv
, LVM_SETITEMTEXTW
, item
.iItem
, (LPARAM
)&item
);
5287 item
.iItem
= SendMessageW(lv
, LVM_GETITEMCOUNT
, 0, 0);
5289 LoadStringW(hInstance
, IDS_IMPORT_CONTENT
, text
,
5290 sizeof(text
)/ sizeof(text
[0]));
5291 SendMessageW(lv
, LVM_INSERTITEMW
, 0, (LPARAM
)&item
);
5292 switch (data
->contentType
)
5294 case CERT_QUERY_CONTENT_CERT
:
5295 case CERT_QUERY_CONTENT_SERIALIZED_CERT
:
5296 contentID
= IDS_IMPORT_CONTENT_CERT
;
5298 case CERT_QUERY_CONTENT_CRL
:
5299 case CERT_QUERY_CONTENT_SERIALIZED_CRL
:
5300 contentID
= IDS_IMPORT_CONTENT_CRL
;
5302 case CERT_QUERY_CONTENT_CTL
:
5303 case CERT_QUERY_CONTENT_SERIALIZED_CTL
:
5304 contentID
= IDS_IMPORT_CONTENT_CTL
;
5306 case CERT_QUERY_CONTENT_PKCS7_SIGNED
:
5307 contentID
= IDS_IMPORT_CONTENT_CMS
;
5309 case CERT_QUERY_CONTENT_FLAG_PFX
:
5310 contentID
= IDS_IMPORT_CONTENT_PFX
;
5313 contentID
= IDS_IMPORT_CONTENT_STORE
;
5316 LoadStringW(hInstance
, contentID
, text
, sizeof(text
)/ sizeof(text
[0]));
5318 SendMessageW(lv
, LVM_SETITEMTEXTW
, item
.iItem
, (LPARAM
)&item
);
5321 item
.iItem
= SendMessageW(lv
, LVM_GETITEMCOUNT
, 0, 0);
5323 LoadStringW(hInstance
, IDS_IMPORT_FILE
, text
,
5324 sizeof(text
)/ sizeof(text
[0]));
5325 SendMessageW(lv
, LVM_INSERTITEMW
, 0, (LPARAM
)&item
);
5327 item
.pszText
= data
->fileName
;
5328 SendMessageW(lv
, LVM_SETITEMTEXTW
, item
.iItem
, (LPARAM
)&item
);
5332 static BOOL
do_import(DWORD dwFlags
, HWND hwndParent
, LPCWSTR pwszWizardTitle
,
5333 PCCRYPTUI_WIZ_IMPORT_SRC_INFO pImportSrc
, HCERTSTORE hDestCertStore
)
5337 switch (pImportSrc
->dwSubjectChoice
)
5339 case CRYPTUI_WIZ_IMPORT_SUBJECT_FILE
:
5340 ret
= import_file(dwFlags
, hwndParent
, pwszWizardTitle
,
5341 pImportSrc
->u
.pwszFileName
, hDestCertStore
);
5343 case CRYPTUI_WIZ_IMPORT_SUBJECT_CERT_CONTEXT
:
5344 if ((ret
= check_context_type(dwFlags
, CERT_QUERY_CONTENT_CERT
)))
5345 ret
= import_cert(pImportSrc
->u
.pCertContext
, hDestCertStore
);
5347 import_warn_type_mismatch(dwFlags
, hwndParent
, pwszWizardTitle
);
5349 case CRYPTUI_WIZ_IMPORT_SUBJECT_CRL_CONTEXT
:
5350 if ((ret
= check_context_type(dwFlags
, CERT_QUERY_CONTENT_CRL
)))
5351 ret
= import_crl(pImportSrc
->u
.pCRLContext
, hDestCertStore
);
5353 import_warn_type_mismatch(dwFlags
, hwndParent
, pwszWizardTitle
);
5355 case CRYPTUI_WIZ_IMPORT_SUBJECT_CTL_CONTEXT
:
5356 if ((ret
= check_context_type(dwFlags
, CERT_QUERY_CONTENT_CTL
)))
5357 ret
= import_ctl(pImportSrc
->u
.pCTLContext
, hDestCertStore
);
5359 import_warn_type_mismatch(dwFlags
, hwndParent
, pwszWizardTitle
);
5361 case CRYPTUI_WIZ_IMPORT_SUBJECT_CERT_STORE
:
5362 ret
= import_store(dwFlags
, hwndParent
, pwszWizardTitle
,
5363 pImportSrc
->u
.hCertStore
, hDestCertStore
);
5366 WARN("unknown source type: %u\n", pImportSrc
->dwSubjectChoice
);
5367 SetLastError(E_INVALIDARG
);
5373 static LRESULT CALLBACK
import_finish_dlg_proc(HWND hwnd
, UINT msg
, WPARAM wp
,
5377 struct ImportWizData
*data
;
5383 PROPSHEETPAGEW
*page
= (PROPSHEETPAGEW
*)lp
;
5384 HWND lv
= GetDlgItem(hwnd
, IDC_IMPORT_SETTINGS
);
5388 data
= (struct ImportWizData
*)page
->lParam
;
5389 SetWindowLongPtrW(hwnd
, DWLP_USER
, (LPARAM
)data
);
5390 SendMessageW(GetDlgItem(hwnd
, IDC_IMPORT_TITLE
), WM_SETFONT
,
5391 (WPARAM
)data
->titleFont
, TRUE
);
5392 GetWindowRect(lv
, &rc
);
5393 column
.mask
= LVCF_WIDTH
;
5394 column
.cx
= (rc
.right
- rc
.left
) / 2 - 2;
5395 SendMessageW(lv
, LVM_INSERTCOLUMNW
, 0, (LPARAM
)&column
);
5396 SendMessageW(lv
, LVM_INSERTCOLUMNW
, 1, (LPARAM
)&column
);
5397 show_import_details(lv
, data
);
5402 NMHDR
*hdr
= (NMHDR
*)lp
;
5408 HWND lv
= GetDlgItem(hwnd
, IDC_IMPORT_SETTINGS
);
5410 data
= (struct ImportWizData
*)GetWindowLongPtrW(hwnd
, DWLP_USER
);
5411 SendMessageW(lv
, LVM_DELETEALLITEMS
, 0, 0);
5412 show_import_details(lv
, data
);
5413 PostMessageW(GetParent(hwnd
), PSM_SETWIZBUTTONS
, 0,
5414 PSWIZB_BACK
| PSWIZB_FINISH
);
5420 data
= (struct ImportWizData
*)GetWindowLongPtrW(hwnd
, DWLP_USER
);
5421 if ((data
->success
= do_import(data
->dwFlags
, hwnd
,
5422 data
->pwszWizardTitle
, &data
->importSrc
, data
->hDestCertStore
)))
5424 WCHAR title
[MAX_STRING_LEN
], message
[MAX_STRING_LEN
];
5427 if (data
->pwszWizardTitle
)
5428 pTitle
= data
->pwszWizardTitle
;
5431 LoadStringW(hInstance
, IDS_IMPORT_WIZARD
, title
,
5432 sizeof(title
) / sizeof(title
[0]));
5435 LoadStringW(hInstance
, IDS_IMPORT_SUCCEEDED
, message
,
5436 sizeof(message
) / sizeof(message
[0]));
5437 MessageBoxW(hwnd
, message
, pTitle
, MB_OK
);
5440 import_warning(data
->dwFlags
, hwnd
, data
->pwszWizardTitle
,
5451 static BOOL
show_import_ui(DWORD dwFlags
, HWND hwndParent
,
5452 LPCWSTR pwszWizardTitle
, PCCRYPTUI_WIZ_IMPORT_SRC_INFO pImportSrc
,
5453 HCERTSTORE hDestCertStore
)
5455 PROPSHEETHEADERW hdr
;
5456 PROPSHEETPAGEW pages
[4];
5457 struct ImportWizData data
;
5460 data
.dwFlags
= dwFlags
;
5461 data
.pwszWizardTitle
= pwszWizardTitle
;
5464 memcpy(&data
.importSrc
, pImportSrc
, sizeof(data
.importSrc
));
5465 data
.fileName
= (LPWSTR
)pImportSrc
->u
.pwszFileName
;
5469 memset(&data
.importSrc
, 0, sizeof(data
.importSrc
));
5470 data
.fileName
= NULL
;
5472 data
.freeSource
= FALSE
;
5473 data
.hDestCertStore
= hDestCertStore
;
5474 data
.freeDest
= FALSE
;
5475 data
.autoDest
= TRUE
;
5476 data
.success
= TRUE
;
5478 memset(&pages
, 0, sizeof(pages
));
5480 pages
[nPages
].dwSize
= sizeof(pages
[0]);
5481 pages
[nPages
].hInstance
= hInstance
;
5482 pages
[nPages
].u
.pszTemplate
= MAKEINTRESOURCEW(IDD_IMPORT_WELCOME
);
5483 pages
[nPages
].pfnDlgProc
= import_welcome_dlg_proc
;
5484 pages
[nPages
].dwFlags
= PSP_HIDEHEADER
;
5485 pages
[nPages
].lParam
= (LPARAM
)&data
;
5489 pImportSrc
->dwSubjectChoice
== CRYPTUI_WIZ_IMPORT_SUBJECT_FILE
)
5491 pages
[nPages
].dwSize
= sizeof(pages
[0]);
5492 pages
[nPages
].hInstance
= hInstance
;
5493 pages
[nPages
].u
.pszTemplate
= MAKEINTRESOURCEW(IDD_IMPORT_FILE
);
5494 pages
[nPages
].pfnDlgProc
= import_file_dlg_proc
;
5495 pages
[nPages
].dwFlags
= PSP_USEHEADERTITLE
| PSP_USEHEADERSUBTITLE
;
5496 pages
[nPages
].pszHeaderTitle
= MAKEINTRESOURCEW(IDS_IMPORT_FILE_TITLE
);
5497 pages
[nPages
].pszHeaderSubTitle
=
5498 MAKEINTRESOURCEW(IDS_IMPORT_FILE_SUBTITLE
);
5499 pages
[nPages
].lParam
= (LPARAM
)&data
;
5504 switch (pImportSrc
->dwSubjectChoice
)
5506 case CRYPTUI_WIZ_IMPORT_SUBJECT_CERT_CONTEXT
:
5507 data
.contentType
= CERT_QUERY_CONTENT_CERT
;
5509 case CRYPTUI_WIZ_IMPORT_SUBJECT_CRL_CONTEXT
:
5510 data
.contentType
= CERT_QUERY_CONTENT_CRL
;
5512 case CRYPTUI_WIZ_IMPORT_SUBJECT_CTL_CONTEXT
:
5513 data
.contentType
= CERT_QUERY_CONTENT_CTL
;
5515 case CRYPTUI_WIZ_IMPORT_SUBJECT_CERT_STORE
:
5516 data
.contentType
= CERT_QUERY_CONTENT_SERIALIZED_STORE
;
5521 pages
[nPages
].dwSize
= sizeof(pages
[0]);
5522 pages
[nPages
].hInstance
= hInstance
;
5523 pages
[nPages
].u
.pszTemplate
= MAKEINTRESOURCEW(IDD_IMPORT_STORE
);
5524 pages
[nPages
].pfnDlgProc
= import_store_dlg_proc
;
5525 pages
[nPages
].dwFlags
= PSP_USEHEADERTITLE
| PSP_USEHEADERSUBTITLE
;
5526 pages
[nPages
].pszHeaderTitle
= MAKEINTRESOURCEW(IDS_IMPORT_STORE_TITLE
);
5527 pages
[nPages
].pszHeaderSubTitle
=
5528 MAKEINTRESOURCEW(IDS_IMPORT_STORE_SUBTITLE
);
5529 pages
[nPages
].lParam
= (LPARAM
)&data
;
5532 pages
[nPages
].dwSize
= sizeof(pages
[0]);
5533 pages
[nPages
].hInstance
= hInstance
;
5534 pages
[nPages
].u
.pszTemplate
= MAKEINTRESOURCEW(IDD_IMPORT_FINISH
);
5535 pages
[nPages
].pfnDlgProc
= import_finish_dlg_proc
;
5536 pages
[nPages
].dwFlags
= PSP_HIDEHEADER
;
5537 pages
[nPages
].lParam
= (LPARAM
)&data
;
5540 memset(&hdr
, 0, sizeof(hdr
));
5541 hdr
.dwSize
= sizeof(hdr
);
5542 hdr
.hwndParent
= hwndParent
;
5543 hdr
.dwFlags
= PSH_PROPSHEETPAGE
| PSH_WIZARD97_NEW
| PSH_HEADER
|
5545 hdr
.hInstance
= hInstance
;
5546 if (pwszWizardTitle
)
5547 hdr
.pszCaption
= pwszWizardTitle
;
5549 hdr
.pszCaption
= MAKEINTRESOURCEW(IDS_IMPORT_WIZARD
);
5550 hdr
.u3
.ppsp
= pages
;
5551 hdr
.nPages
= nPages
;
5552 hdr
.u4
.pszbmWatermark
= MAKEINTRESOURCEW(IDB_CERT_WATERMARK
);
5553 hdr
.u5
.pszbmHeader
= MAKEINTRESOURCEW(IDB_CERT_HEADER
);
5554 PropertySheetW(&hdr
);
5555 if (data
.fileName
!= data
.importSrc
.u
.pwszFileName
)
5556 HeapFree(GetProcessHeap(), 0, data
.fileName
);
5557 if (data
.freeSource
&&
5558 data
.importSrc
.dwSubjectChoice
== CRYPTUI_WIZ_IMPORT_SUBJECT_CERT_STORE
)
5559 CertCloseStore(data
.importSrc
.u
.hCertStore
, 0);
5560 DeleteObject(data
.titleFont
);
5561 return data
.success
;
5564 BOOL WINAPI
CryptUIWizImport(DWORD dwFlags
, HWND hwndParent
, LPCWSTR pwszWizardTitle
,
5565 PCCRYPTUI_WIZ_IMPORT_SRC_INFO pImportSrc
, HCERTSTORE hDestCertStore
)
5569 TRACE("(0x%08x, %p, %s, %p, %p)\n", dwFlags
, hwndParent
, debugstr_w(pwszWizardTitle
),
5570 pImportSrc
, hDestCertStore
);
5573 pImportSrc
->dwSize
!= sizeof(CRYPTUI_WIZ_IMPORT_SRC_INFO
))
5575 SetLastError(E_INVALIDARG
);
5579 if (!(dwFlags
& CRYPTUI_WIZ_NO_UI
))
5580 ret
= show_import_ui(dwFlags
, hwndParent
, pwszWizardTitle
, pImportSrc
,
5582 else if (pImportSrc
)
5583 ret
= do_import(dwFlags
, hwndParent
, pwszWizardTitle
, pImportSrc
,
5587 /* Can't have no UI without specifying source */
5588 SetLastError(E_INVALIDARG
);
5595 struct ExportWizData
5599 LPCWSTR pwszWizardTitle
;
5600 CRYPTUI_WIZ_EXPORT_INFO exportInfo
;
5601 CRYPTUI_WIZ_EXPORT_CERTCONTEXT_INFO contextInfo
;
5603 PCRYPT_KEY_PROV_INFO keyProvInfo
;
5610 static LRESULT CALLBACK
export_welcome_dlg_proc(HWND hwnd
, UINT msg
, WPARAM wp
,
5619 struct ExportWizData
*data
;
5620 PROPSHEETPAGEW
*page
= (PROPSHEETPAGEW
*)lp
;
5621 WCHAR fontFace
[MAX_STRING_LEN
];
5622 HDC hDC
= GetDC(hwnd
);
5625 data
= (struct ExportWizData
*)page
->lParam
;
5626 LoadStringW(hInstance
, IDS_WIZARD_TITLE_FONT
, fontFace
,
5627 sizeof(fontFace
) / sizeof(fontFace
[0]));
5628 height
= -MulDiv(12, GetDeviceCaps(hDC
, LOGPIXELSY
), 72);
5629 data
->titleFont
= CreateFontW(height
, 0, 0, 0, FW_BOLD
, 0, 0, 0,
5630 DEFAULT_CHARSET
, OUT_DEFAULT_PRECIS
, CLIP_DEFAULT_PRECIS
,
5631 DEFAULT_QUALITY
, DEFAULT_PITCH
| FF_DONTCARE
, fontFace
);
5632 SendMessageW(GetDlgItem(hwnd
, IDC_EXPORT_TITLE
), WM_SETFONT
,
5633 (WPARAM
)data
->titleFont
, TRUE
);
5634 ReleaseDC(hwnd
, hDC
);
5639 NMHDR
*hdr
= (NMHDR
*)lp
;
5644 PostMessageW(GetParent(hwnd
), PSM_SETWIZBUTTONS
, 0, PSWIZB_NEXT
);
5654 static PCRYPT_KEY_PROV_INFO
export_get_private_key_info(PCCERT_CONTEXT cert
)
5656 PCRYPT_KEY_PROV_INFO info
= NULL
;
5659 if (CertGetCertificateContextProperty(cert
, CERT_KEY_PROV_INFO_PROP_ID
,
5662 info
= HeapAlloc(GetProcessHeap(), 0, size
);
5665 if (!CertGetCertificateContextProperty(cert
,
5666 CERT_KEY_PROV_INFO_PROP_ID
, info
, &size
))
5668 HeapFree(GetProcessHeap(), 0, info
);
5676 static BOOL
export_acquire_private_key(const CRYPT_KEY_PROV_INFO
*info
,
5681 ret
= CryptAcquireContextW(phProv
, info
->pwszContainerName
,
5682 info
->pwszProvName
, info
->dwProvType
, 0);
5687 for (i
= 0; i
< info
->cProvParam
; i
++)
5688 CryptSetProvParam(*phProv
, info
->rgProvParam
[i
].dwParam
,
5689 info
->rgProvParam
[i
].pbData
, info
->rgProvParam
[i
].dwFlags
);
5694 static BOOL
export_is_key_exportable(HCRYPTPROV hProv
, DWORD keySpec
)
5699 if ((ret
= CryptGetUserKey(hProv
, keySpec
, &key
)))
5701 DWORD permissions
, size
= sizeof(permissions
);
5703 if ((ret
= CryptGetKeyParam(key
, KP_PERMISSIONS
, (BYTE
*)&permissions
,
5704 &size
, 0)) && !(permissions
& CRYPT_EXPORT
))
5706 CryptDestroyKey(key
);
5711 static LRESULT CALLBACK
export_private_key_dlg_proc(HWND hwnd
, UINT msg
,
5712 WPARAM wp
, LPARAM lp
)
5715 struct ExportWizData
*data
;
5721 PROPSHEETPAGEW
*page
= (PROPSHEETPAGEW
*)lp
;
5722 PCRYPT_KEY_PROV_INFO info
;
5723 HCRYPTPROV hProv
= 0;
5726 data
= (struct ExportWizData
*)page
->lParam
;
5727 SetWindowLongPtrW(hwnd
, DWLP_USER
, (LPARAM
)data
);
5728 /* Get enough information about a key to see whether it's exportable.
5730 if (!(info
= export_get_private_key_info(
5731 data
->exportInfo
.u
.pCertContext
)))
5732 errorID
= IDS_EXPORT_PRIVATE_KEY_UNAVAILABLE
;
5733 else if (!export_acquire_private_key(info
, &hProv
))
5734 errorID
= IDS_EXPORT_PRIVATE_KEY_UNAVAILABLE
;
5735 else if (!export_is_key_exportable(hProv
, info
->dwKeySpec
))
5736 errorID
= IDS_EXPORT_PRIVATE_KEY_NON_EXPORTABLE
;
5740 WCHAR error
[MAX_STRING_LEN
];
5742 LoadStringW(hInstance
, errorID
, error
,
5743 sizeof(error
) / sizeof(error
[0]));
5744 SendMessageW(GetDlgItem(hwnd
, IDC_EXPORT_PRIVATE_KEY_UNAVAILABLE
),
5745 WM_SETTEXT
, 0, (LPARAM
)error
);
5746 EnableWindow(GetDlgItem(hwnd
, IDC_EXPORT_PRIVATE_KEY_YES
), FALSE
);
5749 data
->keyProvInfo
= info
;
5751 CryptReleaseContext(hProv
, 0);
5752 SendMessageW(GetDlgItem(hwnd
, IDC_EXPORT_PRIVATE_KEY_NO
), BM_CLICK
,
5758 NMHDR
*hdr
= (NMHDR
*)lp
;
5763 PostMessageW(GetParent(hwnd
), PSM_SETWIZBUTTONS
, 0,
5764 PSWIZB_BACK
| PSWIZB_NEXT
);
5768 data
= (struct ExportWizData
*)GetWindowLongPtrW(hwnd
, DWLP_USER
);
5769 if (IsDlgButtonChecked(hwnd
, IDC_EXPORT_PRIVATE_KEY_NO
))
5771 data
->contextInfo
.dwExportFormat
=
5772 CRYPTUI_WIZ_EXPORT_FORMAT_DER
;
5773 data
->contextInfo
.fExportPrivateKeys
= FALSE
;
5777 data
->contextInfo
.dwExportFormat
=
5778 CRYPTUI_WIZ_EXPORT_FORMAT_PFX
;
5779 data
->contextInfo
.fExportPrivateKeys
= TRUE
;
5789 static BOOL
export_info_has_private_key(PCCRYPTUI_WIZ_EXPORT_INFO pExportInfo
)
5793 if (pExportInfo
->dwSubjectChoice
== CRYPTUI_WIZ_EXPORT_CERT_CONTEXT
)
5797 /* If there's a CRYPT_KEY_PROV_INFO set for this cert, assume the
5798 * cert has a private key.
5800 if (CertGetCertificateContextProperty(pExportInfo
->u
.pCertContext
,
5801 CERT_KEY_PROV_INFO_PROP_ID
, NULL
, &size
))
5807 static void export_format_enable_controls(HWND hwnd
, const struct ExportWizData
*data
)
5809 int defaultFormatID
;
5811 switch (data
->contextInfo
.dwExportFormat
)
5813 case CRYPTUI_WIZ_EXPORT_FORMAT_BASE64
:
5814 defaultFormatID
= IDC_EXPORT_FORMAT_BASE64
;
5816 case CRYPTUI_WIZ_EXPORT_FORMAT_PKCS7
:
5817 defaultFormatID
= IDC_EXPORT_FORMAT_CMS
;
5819 case CRYPTUI_WIZ_EXPORT_FORMAT_PFX
:
5820 defaultFormatID
= IDC_EXPORT_FORMAT_PFX
;
5823 defaultFormatID
= IDC_EXPORT_FORMAT_DER
;
5825 SendMessageW(GetDlgItem(hwnd
, defaultFormatID
), BM_CLICK
, 0, 0);
5826 if (defaultFormatID
== IDC_EXPORT_FORMAT_PFX
)
5828 EnableWindow(GetDlgItem(hwnd
, IDC_EXPORT_FORMAT_DER
), FALSE
);
5829 EnableWindow(GetDlgItem(hwnd
, IDC_EXPORT_FORMAT_BASE64
), FALSE
);
5830 EnableWindow(GetDlgItem(hwnd
, IDC_EXPORT_FORMAT_CMS
), FALSE
);
5831 EnableWindow(GetDlgItem(hwnd
, IDC_EXPORT_FORMAT_PFX
), TRUE
);
5835 EnableWindow(GetDlgItem(hwnd
, IDC_EXPORT_FORMAT_DER
), TRUE
);
5836 EnableWindow(GetDlgItem(hwnd
, IDC_EXPORT_FORMAT_BASE64
), TRUE
);
5837 EnableWindow(GetDlgItem(hwnd
, IDC_EXPORT_FORMAT_CMS
), TRUE
);
5838 EnableWindow(GetDlgItem(hwnd
, IDC_EXPORT_FORMAT_PFX
), FALSE
);
5842 static LRESULT CALLBACK
export_format_dlg_proc(HWND hwnd
, UINT msg
, WPARAM wp
,
5846 struct ExportWizData
*data
;
5852 PROPSHEETPAGEW
*page
= (PROPSHEETPAGEW
*)lp
;
5854 data
= (struct ExportWizData
*)page
->lParam
;
5855 SetWindowLongPtrW(hwnd
, DWLP_USER
, (LPARAM
)data
);
5856 export_format_enable_controls(hwnd
, data
);
5861 NMHDR
*hdr
= (NMHDR
*)lp
;
5866 PostMessageW(GetParent(hwnd
), PSM_SETWIZBUTTONS
, 0,
5867 PSWIZB_BACK
| PSWIZB_NEXT
);
5868 data
= (struct ExportWizData
*)GetWindowLongPtrW(hwnd
, DWLP_USER
);
5869 export_format_enable_controls(hwnd
, data
);
5874 BOOL skipPasswordPage
= TRUE
;
5876 data
= (struct ExportWizData
*)GetWindowLongPtrW(hwnd
, DWLP_USER
);
5877 if (IsDlgButtonChecked(hwnd
, IDC_EXPORT_FORMAT_DER
))
5878 data
->contextInfo
.dwExportFormat
=
5879 CRYPTUI_WIZ_EXPORT_FORMAT_DER
;
5880 else if (IsDlgButtonChecked(hwnd
, IDC_EXPORT_FORMAT_BASE64
))
5881 data
->contextInfo
.dwExportFormat
=
5882 CRYPTUI_WIZ_EXPORT_FORMAT_BASE64
;
5883 else if (IsDlgButtonChecked(hwnd
, IDC_EXPORT_FORMAT_CMS
))
5885 data
->contextInfo
.dwExportFormat
=
5886 CRYPTUI_WIZ_EXPORT_FORMAT_PKCS7
;
5887 if (IsDlgButtonChecked(hwnd
, IDC_EXPORT_CMS_INCLUDE_CHAIN
))
5888 data
->contextInfo
.fExportChain
=
5889 CRYPTUI_WIZ_EXPORT_FORMAT_PKCS7
;
5893 data
->contextInfo
.dwExportFormat
=
5894 CRYPTUI_WIZ_EXPORT_FORMAT_PFX
;
5895 if (IsDlgButtonChecked(hwnd
, IDC_EXPORT_PFX_INCLUDE_CHAIN
))
5896 data
->contextInfo
.fExportChain
= TRUE
;
5897 if (IsDlgButtonChecked(hwnd
, IDC_EXPORT_PFX_STRONG_ENCRYPTION
))
5898 data
->contextInfo
.fStrongEncryption
= TRUE
;
5899 if (IsDlgButtonChecked(hwnd
, IDC_EXPORT_PFX_DELETE_PRIVATE_KEY
))
5900 data
->deleteKeys
= TRUE
;
5901 skipPasswordPage
= FALSE
;
5903 SetWindowLongPtrW(hwnd
, DWLP_MSGRESULT
,
5904 skipPasswordPage
? IDD_EXPORT_FILE
: 0);
5917 case IDC_EXPORT_FORMAT_DER
:
5918 case IDC_EXPORT_FORMAT_BASE64
:
5919 EnableWindow(GetDlgItem(hwnd
, IDC_EXPORT_CMS_INCLUDE_CHAIN
),
5921 EnableWindow(GetDlgItem(hwnd
, IDC_EXPORT_PFX_INCLUDE_CHAIN
),
5923 EnableWindow(GetDlgItem(hwnd
, IDC_EXPORT_PFX_STRONG_ENCRYPTION
),
5925 EnableWindow(GetDlgItem(hwnd
,
5926 IDC_EXPORT_PFX_DELETE_PRIVATE_KEY
), FALSE
);
5928 case IDC_EXPORT_FORMAT_CMS
:
5929 EnableWindow(GetDlgItem(hwnd
, IDC_EXPORT_CMS_INCLUDE_CHAIN
),
5932 case IDC_EXPORT_FORMAT_PFX
:
5933 EnableWindow(GetDlgItem(hwnd
, IDC_EXPORT_PFX_INCLUDE_CHAIN
),
5935 EnableWindow(GetDlgItem(hwnd
, IDC_EXPORT_PFX_STRONG_ENCRYPTION
),
5937 EnableWindow(GetDlgItem(hwnd
,
5938 IDC_EXPORT_PFX_DELETE_PRIVATE_KEY
), TRUE
);
5948 static void export_password_mismatch(HWND hwnd
, const struct ExportWizData
*data
)
5950 WCHAR title
[MAX_STRING_LEN
], error
[MAX_STRING_LEN
];
5953 if (data
->pwszWizardTitle
)
5954 pTitle
= data
->pwszWizardTitle
;
5957 LoadStringW(hInstance
, IDS_EXPORT_WIZARD
, title
,
5958 sizeof(title
) / sizeof(title
[0]));
5961 LoadStringW(hInstance
, IDS_EXPORT_PASSWORD_MISMATCH
, error
,
5962 sizeof(error
) / sizeof(error
[0]));
5963 MessageBoxW(hwnd
, error
, pTitle
, MB_ICONERROR
| MB_OK
);
5964 SetFocus(GetDlgItem(hwnd
, IDC_EXPORT_PASSWORD
));
5967 static LRESULT CALLBACK
export_password_dlg_proc(HWND hwnd
, UINT msg
,
5968 WPARAM wp
, LPARAM lp
)
5971 struct ExportWizData
*data
;
5977 PROPSHEETPAGEW
*page
= (PROPSHEETPAGEW
*)lp
;
5979 data
= (struct ExportWizData
*)page
->lParam
;
5980 SetWindowLongPtrW(hwnd
, DWLP_USER
, (LPARAM
)data
);
5985 NMHDR
*hdr
= (NMHDR
*)lp
;
5990 PostMessageW(GetParent(hwnd
), PSM_SETWIZBUTTONS
, 0,
5991 PSWIZB_BACK
| PSWIZB_NEXT
);
5996 HWND passwordEdit
= GetDlgItem(hwnd
, IDC_EXPORT_PASSWORD
);
5997 HWND passwordConfirmEdit
= GetDlgItem(hwnd
,
5998 IDC_EXPORT_PASSWORD_CONFIRM
);
5999 DWORD passwordLen
= SendMessageW(passwordEdit
, WM_GETTEXTLENGTH
,
6001 DWORD passwordConfirmLen
= SendMessageW(passwordConfirmEdit
,
6002 WM_GETTEXTLENGTH
, 0, 0);
6004 data
= (struct ExportWizData
*)GetWindowLongPtrW(hwnd
, DWLP_USER
);
6005 if (!passwordLen
&& !passwordConfirmLen
)
6006 data
->contextInfo
.pwszPassword
= NULL
;
6007 else if (passwordLen
!= passwordConfirmLen
)
6009 export_password_mismatch(hwnd
, data
);
6010 SetWindowLongPtrW(hwnd
, DWLP_MSGRESULT
, 1);
6015 LPWSTR password
= HeapAlloc(GetProcessHeap(), 0,
6016 (passwordLen
+ 1) * sizeof(WCHAR
));
6017 LPWSTR passwordConfirm
= HeapAlloc(GetProcessHeap(), 0,
6018 (passwordConfirmLen
+ 1) * sizeof(WCHAR
));
6019 BOOL freePassword
= TRUE
;
6021 if (password
&& passwordConfirm
)
6023 SendMessageW(passwordEdit
, WM_GETTEXT
, passwordLen
+ 1,
6025 SendMessageW(passwordConfirmEdit
, WM_GETTEXT
,
6026 passwordConfirmLen
+ 1, (LPARAM
)passwordConfirm
);
6027 if (strcmpW(password
, passwordConfirm
))
6029 export_password_mismatch(hwnd
, data
);
6030 SetWindowLongPtrW(hwnd
, DWLP_MSGRESULT
, 1);
6035 data
->contextInfo
.pwszPassword
= password
;
6036 freePassword
= FALSE
;
6037 data
->freePassword
= TRUE
;
6041 HeapFree(GetProcessHeap(), 0, password
);
6042 HeapFree(GetProcessHeap(), 0, passwordConfirm
);
6053 static LPWSTR
export_append_extension(const struct ExportWizData
*data
,
6056 static const WCHAR cer
[] = { '.','c','e','r',0 };
6057 static const WCHAR crl
[] = { '.','c','r','l',0 };
6058 static const WCHAR ctl
[] = { '.','c','t','l',0 };
6059 static const WCHAR p7b
[] = { '.','p','7','b',0 };
6060 static const WCHAR pfx
[] = { '.','p','f','x',0 };
6061 static const WCHAR sst
[] = { '.','s','s','t',0 };
6064 BOOL appendExtension
;
6066 switch (data
->contextInfo
.dwExportFormat
)
6068 case CRYPTUI_WIZ_EXPORT_FORMAT_PKCS7
:
6071 case CRYPTUI_WIZ_EXPORT_FORMAT_PFX
:
6075 switch (data
->exportInfo
.dwSubjectChoice
)
6077 case CRYPTUI_WIZ_EXPORT_CRL_CONTEXT
:
6080 case CRYPTUI_WIZ_EXPORT_CTL_CONTEXT
:
6083 case CRYPTUI_WIZ_EXPORT_CERT_STORE
:
6090 dot
= strrchrW(fileName
, '.');
6092 appendExtension
= strcmpiW(dot
, extension
) != 0;
6094 appendExtension
= TRUE
;
6095 if (appendExtension
)
6097 fileName
= HeapReAlloc(GetProcessHeap(), 0, fileName
,
6098 (strlenW(fileName
) + strlenW(extension
) + 1) * sizeof(WCHAR
));
6100 strcatW(fileName
, extension
);
6105 static BOOL
export_validate_filename(HWND hwnd
, struct ExportWizData
*data
,
6109 BOOL tryCreate
= TRUE
, forceCreate
= FALSE
, ret
= FALSE
;
6111 file
= CreateFileW(fileName
, GENERIC_WRITE
,
6112 FILE_SHARE_READ
| FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
, 0, NULL
);
6113 if (file
!= INVALID_HANDLE_VALUE
)
6115 WCHAR warning
[MAX_STRING_LEN
], title
[MAX_STRING_LEN
];
6118 if (data
->pwszWizardTitle
)
6119 pTitle
= data
->pwszWizardTitle
;
6122 LoadStringW(hInstance
, IDS_EXPORT_WIZARD
, title
,
6123 sizeof(title
) / sizeof(title
[0]));
6126 LoadStringW(hInstance
, IDS_EXPORT_FILE_EXISTS
, warning
,
6127 sizeof(warning
) / sizeof(warning
[0]));
6128 if (MessageBoxW(hwnd
, warning
, pTitle
, MB_YESNO
) == IDYES
)
6136 file
= CreateFileW(fileName
, GENERIC_WRITE
,
6137 FILE_SHARE_READ
| FILE_SHARE_WRITE
, NULL
,
6138 forceCreate
? CREATE_ALWAYS
: CREATE_NEW
,
6140 if (file
!= INVALID_HANDLE_VALUE
)
6147 WCHAR title
[MAX_STRING_LEN
], error
[MAX_STRING_LEN
];
6149 LPWSTR msgBuf
, fullError
;
6151 if (data
->pwszWizardTitle
)
6152 pTitle
= data
->pwszWizardTitle
;
6155 LoadStringW(hInstance
, IDS_EXPORT_WIZARD
, title
,
6156 sizeof(title
) / sizeof(title
[0]));
6159 LoadStringW(hInstance
, IDS_IMPORT_OPEN_FAILED
, error
,
6160 sizeof(error
) / sizeof(error
[0]));
6162 FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM
, NULL
,
6163 GetLastError(), 0, (LPWSTR
) &msgBuf
, 0, NULL
);
6164 fullError
= HeapAlloc(GetProcessHeap(), 0,
6165 (strlenW(error
) + strlenW(fileName
) + strlenW(msgBuf
) + 3)
6169 LPWSTR ptr
= fullError
;
6171 strcpyW(ptr
, error
);
6172 ptr
+= strlenW(error
);
6173 strcpyW(ptr
, fileName
);
6174 ptr
+= strlenW(fileName
);
6177 strcpyW(ptr
, msgBuf
);
6178 MessageBoxW(hwnd
, fullError
, pTitle
, MB_ICONERROR
| MB_OK
);
6179 HeapFree(GetProcessHeap(), 0, fullError
);
6187 static const WCHAR export_filter_cert
[] = { '*','.','c','e','r',0 };
6188 static const WCHAR export_filter_crl
[] = { '*','.','c','r','l',0 };
6189 static const WCHAR export_filter_ctl
[] = { '*','.','s','t','l',0 };
6190 static const WCHAR export_filter_cms
[] = { '*','.','p','7','b',0 };
6191 static const WCHAR export_filter_pfx
[] = { '*','.','p','f','x',0 };
6192 static const WCHAR export_filter_sst
[] = { '*','.','s','s','t',0 };
6194 static WCHAR
*make_export_file_filter(DWORD exportFormat
, DWORD subjectChoice
)
6196 int baseLen
, allLen
, totalLen
= 2, baseID
;
6197 LPWSTR filter
= NULL
, baseFilter
, all
;
6200 switch (exportFormat
)
6202 case CRYPTUI_WIZ_EXPORT_FORMAT_BASE64
:
6203 baseID
= IDS_EXPORT_FILTER_BASE64_CERT
;
6204 filterStr
= export_filter_cert
;
6206 case CRYPTUI_WIZ_EXPORT_FORMAT_PFX
:
6207 baseID
= IDS_EXPORT_FILTER_PFX
;
6208 filterStr
= export_filter_pfx
;
6210 case CRYPTUI_WIZ_EXPORT_FORMAT_PKCS7
:
6211 baseID
= IDS_EXPORT_FILTER_CMS
;
6212 filterStr
= export_filter_cms
;
6215 switch (subjectChoice
)
6217 case CRYPTUI_WIZ_EXPORT_CRL_CONTEXT
:
6218 baseID
= IDS_EXPORT_FILTER_CRL
;
6219 filterStr
= export_filter_crl
;
6221 case CRYPTUI_WIZ_EXPORT_CTL_CONTEXT
:
6222 baseID
= IDS_EXPORT_FILTER_CTL
;
6223 filterStr
= export_filter_ctl
;
6225 case CRYPTUI_WIZ_EXPORT_CERT_STORE
:
6226 baseID
= IDS_EXPORT_FILTER_SERIALIZED_CERT_STORE
;
6227 filterStr
= export_filter_sst
;
6230 baseID
= IDS_EXPORT_FILTER_CERT
;
6231 filterStr
= export_filter_cert
;
6235 baseLen
= LoadStringW(hInstance
, baseID
, (LPWSTR
)&baseFilter
, 0);
6236 totalLen
+= baseLen
+ strlenW(filterStr
) + 2;
6237 allLen
= LoadStringW(hInstance
, IDS_IMPORT_FILTER_ALL
, (LPWSTR
)&all
, 0);
6238 totalLen
+= allLen
+ strlenW(filter_all
) + 2;
6239 filter
= HeapAlloc(GetProcessHeap(), 0, totalLen
* sizeof(WCHAR
));
6245 memcpy(ptr
, baseFilter
, baseLen
* sizeof(WCHAR
));
6248 strcpyW(ptr
, filterStr
);
6249 ptr
+= strlenW(filterStr
) + 1;
6250 memcpy(ptr
, all
, allLen
* sizeof(WCHAR
));
6253 strcpyW(ptr
, filter_all
);
6254 ptr
+= strlenW(filter_all
) + 1;
6260 static LRESULT CALLBACK
export_file_dlg_proc(HWND hwnd
, UINT msg
, WPARAM wp
,
6264 struct ExportWizData
*data
;
6270 PROPSHEETPAGEW
*page
= (PROPSHEETPAGEW
*)lp
;
6272 data
= (struct ExportWizData
*)page
->lParam
;
6273 SetWindowLongPtrW(hwnd
, DWLP_USER
, (LPARAM
)data
);
6274 if (data
->exportInfo
.pwszExportFileName
)
6275 SendMessageW(GetDlgItem(hwnd
, IDC_EXPORT_FILENAME
), WM_SETTEXT
, 0,
6276 (LPARAM
)data
->exportInfo
.pwszExportFileName
);
6281 NMHDR
*hdr
= (NMHDR
*)lp
;
6286 data
= (struct ExportWizData
*)GetWindowLongPtrW(hwnd
, DWLP_USER
);
6287 if (data
->contextInfo
.dwExportFormat
!=
6288 CRYPTUI_WIZ_EXPORT_FORMAT_PFX
)
6290 SetWindowLongPtrW(hwnd
, DWLP_MSGRESULT
, IDD_EXPORT_FORMAT
);
6296 HWND fileNameEdit
= GetDlgItem(hwnd
, IDC_EXPORT_FILENAME
);
6297 DWORD len
= SendMessageW(fileNameEdit
, WM_GETTEXTLENGTH
, 0, 0);
6299 data
= (struct ExportWizData
*)GetWindowLongPtrW(hwnd
, DWLP_USER
);
6302 WCHAR title
[MAX_STRING_LEN
], error
[MAX_STRING_LEN
];
6305 if (data
->pwszWizardTitle
)
6306 pTitle
= data
->pwszWizardTitle
;
6309 LoadStringW(hInstance
, IDS_EXPORT_WIZARD
, title
,
6310 sizeof(title
) / sizeof(title
[0]));
6313 LoadStringW(hInstance
, IDS_IMPORT_EMPTY_FILE
, error
,
6314 sizeof(error
) / sizeof(error
[0]));
6315 MessageBoxW(hwnd
, error
, pTitle
, MB_ICONERROR
| MB_OK
);
6316 SetWindowLongPtrW(hwnd
, DWLP_MSGRESULT
, 1);
6321 LPWSTR fileName
= HeapAlloc(GetProcessHeap(), 0,
6322 (len
+ 1) * sizeof(WCHAR
));
6326 SendMessageW(fileNameEdit
, WM_GETTEXT
, len
+ 1,
6328 fileName
= export_append_extension(data
, fileName
);
6329 if (!export_validate_filename(hwnd
, data
, fileName
))
6331 HeapFree(GetProcessHeap(), 0, fileName
);
6332 SetWindowLongPtrW(hwnd
, DWLP_MSGRESULT
, 1);
6336 data
->fileName
= fileName
;
6342 PostMessageW(GetParent(hwnd
), PSM_SETWIZBUTTONS
, 0,
6343 PSWIZB_BACK
| PSWIZB_NEXT
);
6352 case IDC_EXPORT_BROWSE_FILE
:
6355 WCHAR fileBuf
[MAX_PATH
];
6357 data
= (struct ExportWizData
*)GetWindowLongPtrW(hwnd
, DWLP_USER
);
6358 memset(&ofn
, 0, sizeof(ofn
));
6359 ofn
.lStructSize
= sizeof(ofn
);
6360 ofn
.hwndOwner
= hwnd
;
6361 ofn
.lpstrFilter
= make_export_file_filter(
6362 data
->contextInfo
.dwExportFormat
,
6363 data
->exportInfo
.dwSubjectChoice
);
6364 ofn
.lpstrFile
= fileBuf
;
6365 ofn
.nMaxFile
= sizeof(fileBuf
) / sizeof(fileBuf
[0]);
6367 if (GetSaveFileNameW(&ofn
))
6368 SendMessageW(GetDlgItem(hwnd
, IDC_EXPORT_FILENAME
), WM_SETTEXT
,
6369 0, (LPARAM
)ofn
.lpstrFile
);
6370 HeapFree(GetProcessHeap(), 0, (LPWSTR
)ofn
.lpstrFilter
);
6379 static void show_export_details(HWND lv
, const struct ExportWizData
*data
)
6381 WCHAR text
[MAX_STRING_LEN
];
6385 item
.mask
= LVIF_TEXT
;
6388 item
.iItem
= SendMessageW(lv
, LVM_GETITEMCOUNT
, 0, 0);
6390 LoadStringW(hInstance
, IDS_IMPORT_FILE
, text
,
6391 sizeof(text
)/ sizeof(text
[0]));
6392 item
.pszText
= text
;
6393 SendMessageW(lv
, LVM_INSERTITEMW
, 0, (LPARAM
)&item
);
6395 item
.pszText
= data
->fileName
;
6396 SendMessageW(lv
, LVM_SETITEMTEXTW
, item
.iItem
, (LPARAM
)&item
);
6399 item
.pszText
= text
;
6400 switch (data
->exportInfo
.dwSubjectChoice
)
6402 case CRYPTUI_WIZ_EXPORT_CRL_CONTEXT
:
6403 case CRYPTUI_WIZ_EXPORT_CTL_CONTEXT
:
6404 case CRYPTUI_WIZ_EXPORT_CERT_STORE
:
6405 case CRYPTUI_WIZ_EXPORT_CERT_STORE_CERTIFICATES_ONLY
:
6410 item
.iItem
= SendMessageW(lv
, LVM_GETITEMCOUNT
, 0, 0);
6412 LoadStringW(hInstance
, IDS_EXPORT_INCLUDE_CHAIN
, text
,
6413 sizeof(text
) / sizeof(text
[0]));
6414 SendMessageW(lv
, LVM_INSERTITEMW
, item
.iItem
, (LPARAM
)&item
);
6416 LoadStringW(hInstance
,
6417 data
->contextInfo
.fExportChain
? IDS_YES
: IDS_NO
, text
,
6418 sizeof(text
) / sizeof(text
[0]));
6419 SendMessageW(lv
, LVM_SETITEMTEXTW
, item
.iItem
, (LPARAM
)&item
);
6421 item
.iItem
= SendMessageW(lv
, LVM_GETITEMCOUNT
, 0, 0);
6423 LoadStringW(hInstance
, IDS_EXPORT_KEYS
, text
,
6424 sizeof(text
) / sizeof(text
[0]));
6425 SendMessageW(lv
, LVM_INSERTITEMW
, item
.iItem
, (LPARAM
)&item
);
6427 LoadStringW(hInstance
,
6428 data
->contextInfo
.fExportPrivateKeys
? IDS_YES
: IDS_NO
, text
,
6429 sizeof(text
) / sizeof(text
[0]));
6430 SendMessageW(lv
, LVM_SETITEMTEXTW
, item
.iItem
, (LPARAM
)&item
);
6434 item
.iItem
= SendMessageW(lv
, LVM_GETITEMCOUNT
, 0, 0);
6436 LoadStringW(hInstance
, IDS_EXPORT_FORMAT
, text
,
6437 sizeof(text
)/ sizeof(text
[0]));
6438 SendMessageW(lv
, LVM_INSERTITEMW
, 0, (LPARAM
)&item
);
6441 switch (data
->exportInfo
.dwSubjectChoice
)
6443 case CRYPTUI_WIZ_EXPORT_CRL_CONTEXT
:
6444 contentID
= IDS_EXPORT_FILTER_CRL
;
6446 case CRYPTUI_WIZ_EXPORT_CTL_CONTEXT
:
6447 contentID
= IDS_EXPORT_FILTER_CTL
;
6449 case CRYPTUI_WIZ_EXPORT_CERT_STORE
:
6450 contentID
= IDS_EXPORT_FILTER_SERIALIZED_CERT_STORE
;
6453 switch (data
->contextInfo
.dwExportFormat
)
6455 case CRYPTUI_WIZ_EXPORT_FORMAT_BASE64
:
6456 contentID
= IDS_EXPORT_FILTER_BASE64_CERT
;
6458 case CRYPTUI_WIZ_EXPORT_FORMAT_PKCS7
:
6459 contentID
= IDS_EXPORT_FILTER_CMS
;
6461 case CRYPTUI_WIZ_EXPORT_FORMAT_PFX
:
6462 contentID
= IDS_EXPORT_FILTER_PFX
;
6465 contentID
= IDS_EXPORT_FILTER_CERT
;
6468 LoadStringW(hInstance
, contentID
, text
, sizeof(text
) / sizeof(text
[0]));
6469 SendMessageW(lv
, LVM_SETITEMTEXTW
, item
.iItem
, (LPARAM
)&item
);
6472 static inline BOOL
save_der(HANDLE file
, const BYTE
*pb
, DWORD cb
)
6476 return WriteFile(file
, pb
, cb
, &bytesWritten
, NULL
);
6479 static BOOL
save_base64(HANDLE file
, const BYTE
*pb
, DWORD cb
)
6484 if ((ret
= CryptBinaryToStringA(pb
, cb
, CRYPT_STRING_BASE64
, NULL
, &size
)))
6486 LPSTR buf
= HeapAlloc(GetProcessHeap(), 0, size
);
6490 if ((ret
= CryptBinaryToStringA(pb
, cb
, CRYPT_STRING_BASE64
, buf
,
6492 ret
= WriteFile(file
, buf
, size
, &size
, NULL
);
6493 HeapFree(GetProcessHeap(), 0, buf
);
6497 SetLastError(ERROR_OUTOFMEMORY
);
6504 static inline BOOL
save_store_as_cms(HANDLE file
, HCERTSTORE store
)
6506 return CertSaveStore(store
, PKCS_7_ASN_ENCODING
| X509_ASN_ENCODING
,
6507 CERT_STORE_SAVE_AS_PKCS7
, CERT_STORE_SAVE_TO_FILE
, file
, 0);
6510 static BOOL
save_cert_as_cms(HANDLE file
, PCCRYPTUI_WIZ_EXPORT_INFO pExportInfo
,
6514 HCERTSTORE store
= CertOpenStore(CERT_STORE_PROV_MEMORY
, 0, 0,
6515 CERT_STORE_CREATE_NEW_FLAG
, NULL
);
6521 HCERTSTORE addlStore
= CertOpenStore(CERT_STORE_PROV_COLLECTION
,
6522 0, 0, CERT_STORE_CREATE_NEW_FLAG
, NULL
);
6529 for (i
= 0; ret
&& i
< pExportInfo
->cStores
; i
++)
6530 ret
= CertAddStoreToCollection(addlStore
,
6531 pExportInfo
->rghStores
, 0, 0);
6534 PCCERT_CHAIN_CONTEXT chain
;
6536 ret
= CertGetCertificateChain(NULL
,
6537 pExportInfo
->u
.pCertContext
, NULL
, addlStore
, NULL
, 0,
6543 for (i
= 0; ret
&& i
< chain
->cChain
; i
++)
6544 for (j
= 0; ret
&& j
< chain
->rgpChain
[i
]->cElement
;
6546 ret
= CertAddCertificateContextToStore(store
,
6547 chain
->rgpChain
[i
]->rgpElement
[j
]->pCertContext
,
6548 CERT_STORE_ADD_ALWAYS
, NULL
);
6549 CertFreeCertificateChain(chain
);
6553 /* No chain could be created, just add the individual
6554 * cert to the message.
6556 ret
= CertAddCertificateContextToStore(store
,
6557 pExportInfo
->u
.pCertContext
, CERT_STORE_ADD_ALWAYS
,
6561 CertCloseStore(addlStore
, 0);
6567 ret
= CertAddCertificateContextToStore(store
,
6568 pExportInfo
->u
.pCertContext
, CERT_STORE_ADD_ALWAYS
, NULL
);
6570 ret
= save_store_as_cms(file
, store
);
6571 CertCloseStore(store
, 0);
6578 static BOOL
save_serialized_store(HANDLE file
, HCERTSTORE store
)
6580 return CertSaveStore(store
, PKCS_7_ASN_ENCODING
| X509_ASN_ENCODING
,
6581 CERT_STORE_SAVE_AS_STORE
, CERT_STORE_SAVE_TO_FILE
, file
, 0);
6584 static BOOL
save_pfx(HANDLE file
, PCCRYPTUI_WIZ_EXPORT_INFO pExportInfo
,
6585 PCCRYPTUI_WIZ_EXPORT_CERTCONTEXT_INFO pContextInfo
,
6586 PCRYPT_KEY_PROV_INFO keyProvInfo
, BOOL deleteKeys
)
6588 HCERTSTORE store
= CertOpenStore(CERT_STORE_PROV_MEMORY
, X509_ASN_ENCODING
,
6589 0, CERT_STORE_CREATE_NEW_FLAG
, NULL
);
6594 CRYPT_DATA_BLOB pfxBlob
= { 0, NULL
};
6595 PCCERT_CONTEXT cert
= NULL
;
6596 BOOL freeKeyProvInfo
= FALSE
;
6598 if (pContextInfo
->fExportChain
)
6600 HCERTCHAINENGINE engine
= NULL
;
6602 if (pExportInfo
->cStores
)
6604 CERT_CHAIN_ENGINE_CONFIG config
;
6606 memset(&config
, 0, sizeof(config
));
6607 config
.cbSize
= sizeof(config
);
6608 config
.cAdditionalStore
= pExportInfo
->cStores
;
6609 config
.rghAdditionalStore
= pExportInfo
->rghStores
;
6610 ret
= CertCreateCertificateChainEngine(&config
, &engine
);
6616 CERT_CHAIN_PARA chainPara
;
6617 PCCERT_CHAIN_CONTEXT chain
;
6619 memset(&chainPara
, 0, sizeof(chainPara
));
6620 chainPara
.cbSize
= sizeof(chainPara
);
6621 ret
= CertGetCertificateChain(engine
,
6622 pExportInfo
->u
.pCertContext
, NULL
, NULL
, &chainPara
, 0, NULL
,
6628 for (i
= 0; ret
&& i
< chain
->cChain
; i
++)
6629 for (j
= 0; ret
&& j
< chain
->rgpChain
[i
]->cElement
;
6632 if (i
== 0 && j
== 0)
6633 ret
= CertAddCertificateContextToStore(store
,
6634 chain
->rgpChain
[i
]->rgpElement
[j
]->pCertContext
,
6635 CERT_STORE_ADD_ALWAYS
, &cert
);
6637 ret
= CertAddCertificateContextToStore(store
,
6638 chain
->rgpChain
[i
]->rgpElement
[j
]->pCertContext
,
6639 CERT_STORE_ADD_ALWAYS
, NULL
);
6641 CertFreeCertificateChain(chain
);
6645 CertFreeCertificateChainEngine(engine
);
6648 ret
= CertAddCertificateContextToStore(store
,
6649 pExportInfo
->u
.pCertContext
, CERT_STORE_ADD_ALWAYS
, &cert
);
6650 /* Copy private key info to newly created cert, so it'll get exported
6651 * along with the cert.
6653 if (ret
&& pContextInfo
->fExportPrivateKeys
)
6656 ret
= CertSetCertificateContextProperty(cert
,
6657 CERT_KEY_PROV_INFO_PROP_ID
, 0, keyProvInfo
);
6660 if (!(keyProvInfo
= export_get_private_key_info(cert
)))
6664 ret
= CertSetCertificateContextProperty(cert
,
6665 CERT_KEY_PROV_INFO_PROP_ID
, 0, keyProvInfo
);
6666 freeKeyProvInfo
= TRUE
;
6673 REPORT_NOT_ABLE_TO_EXPORT_PRIVATE_KEY
| EXPORT_PRIVATE_KEYS
;
6675 ret
= PFXExportCertStore(store
, &pfxBlob
,
6676 pContextInfo
->pwszPassword
, exportFlags
);
6679 pfxBlob
.pbData
= HeapAlloc(GetProcessHeap(), 0, pfxBlob
.cbData
);
6682 ret
= PFXExportCertStore(store
, &pfxBlob
,
6683 pContextInfo
->pwszPassword
, exportFlags
);
6688 ret
= WriteFile(file
, pfxBlob
.pbData
, pfxBlob
.cbData
,
6689 &bytesWritten
, NULL
);
6694 SetLastError(ERROR_OUTOFMEMORY
);
6699 if (ret
&& deleteKeys
)
6703 CryptAcquireContextW(&prov
, keyProvInfo
->pwszContainerName
,
6704 keyProvInfo
->pwszProvName
, keyProvInfo
->dwProvType
,
6705 CRYPT_DELETEKEYSET
);
6707 if (freeKeyProvInfo
)
6708 HeapFree(GetProcessHeap(), 0, keyProvInfo
);
6709 CertFreeCertificateContext(cert
);
6710 CertCloseStore(store
, 0);
6715 static BOOL
do_export(HANDLE file
, PCCRYPTUI_WIZ_EXPORT_INFO pExportInfo
,
6716 PCCRYPTUI_WIZ_EXPORT_CERTCONTEXT_INFO pContextInfo
,
6717 PCRYPT_KEY_PROV_INFO keyProvInfo
, BOOL deleteKeys
)
6721 if (pContextInfo
->dwSize
!= sizeof(CRYPTUI_WIZ_EXPORT_CERTCONTEXT_INFO
))
6723 SetLastError(E_INVALIDARG
);
6726 switch (pExportInfo
->dwSubjectChoice
)
6728 case CRYPTUI_WIZ_EXPORT_CRL_CONTEXT
:
6729 ret
= save_der(file
,
6730 pExportInfo
->u
.pCRLContext
->pbCrlEncoded
,
6731 pExportInfo
->u
.pCRLContext
->cbCrlEncoded
);
6733 case CRYPTUI_WIZ_EXPORT_CTL_CONTEXT
:
6734 ret
= save_der(file
,
6735 pExportInfo
->u
.pCTLContext
->pbCtlEncoded
,
6736 pExportInfo
->u
.pCTLContext
->cbCtlEncoded
);
6738 case CRYPTUI_WIZ_EXPORT_CERT_STORE
:
6739 ret
= save_serialized_store(file
, pExportInfo
->u
.hCertStore
);
6741 case CRYPTUI_WIZ_EXPORT_CERT_STORE_CERTIFICATES_ONLY
:
6742 ret
= save_store_as_cms(file
, pExportInfo
->u
.hCertStore
);
6745 switch (pContextInfo
->dwExportFormat
)
6747 case CRYPTUI_WIZ_EXPORT_FORMAT_DER
:
6748 ret
= save_der(file
, pExportInfo
->u
.pCertContext
->pbCertEncoded
,
6749 pExportInfo
->u
.pCertContext
->cbCertEncoded
);
6751 case CRYPTUI_WIZ_EXPORT_FORMAT_BASE64
:
6752 ret
= save_base64(file
,
6753 pExportInfo
->u
.pCertContext
->pbCertEncoded
,
6754 pExportInfo
->u
.pCertContext
->cbCertEncoded
);
6756 case CRYPTUI_WIZ_EXPORT_FORMAT_PKCS7
:
6757 ret
= save_cert_as_cms(file
, pExportInfo
,
6758 pContextInfo
->fExportChain
);
6760 case CRYPTUI_WIZ_EXPORT_FORMAT_PFX
:
6761 ret
= save_pfx(file
, pExportInfo
, pContextInfo
, keyProvInfo
,
6765 SetLastError(E_FAIL
);
6772 static LRESULT CALLBACK
export_finish_dlg_proc(HWND hwnd
, UINT msg
, WPARAM wp
,
6776 struct ExportWizData
*data
;
6782 PROPSHEETPAGEW
*page
= (PROPSHEETPAGEW
*)lp
;
6783 HWND lv
= GetDlgItem(hwnd
, IDC_EXPORT_SETTINGS
);
6787 data
= (struct ExportWizData
*)page
->lParam
;
6788 SetWindowLongPtrW(hwnd
, DWLP_USER
, (LPARAM
)data
);
6789 SendMessageW(GetDlgItem(hwnd
, IDC_EXPORT_TITLE
), WM_SETFONT
,
6790 (WPARAM
)data
->titleFont
, TRUE
);
6791 GetWindowRect(lv
, &rc
);
6792 column
.mask
= LVCF_WIDTH
;
6793 column
.cx
= (rc
.right
- rc
.left
) / 2 - 2;
6794 SendMessageW(lv
, LVM_INSERTCOLUMNW
, 0, (LPARAM
)&column
);
6795 SendMessageW(lv
, LVM_INSERTCOLUMNW
, 1, (LPARAM
)&column
);
6796 show_export_details(lv
, data
);
6801 NMHDR
*hdr
= (NMHDR
*)lp
;
6807 HWND lv
= GetDlgItem(hwnd
, IDC_EXPORT_SETTINGS
);
6809 data
= (struct ExportWizData
*)GetWindowLongPtrW(hwnd
, DWLP_USER
);
6810 SendMessageW(lv
, LVM_DELETEALLITEMS
, 0, 0);
6811 show_export_details(lv
, data
);
6812 PostMessageW(GetParent(hwnd
), PSM_SETWIZBUTTONS
, 0,
6813 PSWIZB_BACK
| PSWIZB_FINISH
);
6820 WCHAR title
[MAX_STRING_LEN
], message
[MAX_STRING_LEN
];
6824 data
= (struct ExportWizData
*)GetWindowLongPtrW(hwnd
, DWLP_USER
);
6825 if ((data
->success
= do_export(data
->file
, &data
->exportInfo
,
6826 &data
->contextInfo
, data
->keyProvInfo
, data
->deleteKeys
)))
6828 messageID
= IDS_EXPORT_SUCCEEDED
;
6833 messageID
= IDS_EXPORT_FAILED
;
6834 mbFlags
= MB_OK
| MB_ICONERROR
;
6836 if (data
->pwszWizardTitle
)
6837 pTitle
= data
->pwszWizardTitle
;
6840 LoadStringW(hInstance
, IDS_EXPORT_WIZARD
, title
,
6841 sizeof(title
) / sizeof(title
[0]));
6844 LoadStringW(hInstance
, messageID
, message
,
6845 sizeof(message
) / sizeof(message
[0]));
6846 MessageBoxW(hwnd
, message
, pTitle
, mbFlags
);
6856 static BOOL
show_export_ui(DWORD dwFlags
, HWND hwndParent
,
6857 LPCWSTR pwszWizardTitle
, PCCRYPTUI_WIZ_EXPORT_INFO pExportInfo
, const void *pvoid
)
6859 PROPSHEETHEADERW hdr
;
6860 PROPSHEETPAGEW pages
[6];
6861 struct ExportWizData data
;
6863 BOOL hasPrivateKey
, showFormatPage
= TRUE
;
6866 data
.dwFlags
= dwFlags
;
6867 data
.pwszWizardTitle
= pwszWizardTitle
;
6868 memset(&data
.exportInfo
, 0, sizeof(data
.exportInfo
));
6869 memcpy(&data
.exportInfo
, pExportInfo
,
6870 min(sizeof(data
.exportInfo
), pExportInfo
->dwSize
));
6871 if (pExportInfo
->dwSize
> sizeof(data
.exportInfo
))
6872 data
.exportInfo
.dwSize
= sizeof(data
.exportInfo
);
6873 data
.contextInfo
.dwSize
= sizeof(data
.contextInfo
);
6874 data
.contextInfo
.dwExportFormat
= CRYPTUI_WIZ_EXPORT_FORMAT_DER
;
6875 data
.contextInfo
.fExportChain
= FALSE
;
6876 data
.contextInfo
.fStrongEncryption
= FALSE
;
6877 data
.contextInfo
.fExportPrivateKeys
= FALSE
;
6878 data
.contextInfo
.pwszPassword
= NULL
;
6879 data
.freePassword
= FALSE
;
6880 if (pExportInfo
->dwSubjectChoice
== CRYPTUI_WIZ_EXPORT_CERT_CONTEXT
&&
6882 memcpy(&data
.contextInfo
, pvoid
,
6883 min(((PCCRYPTUI_WIZ_EXPORT_CERTCONTEXT_INFO
)pvoid
)->dwSize
,
6884 sizeof(data
.contextInfo
)));
6885 data
.keyProvInfo
= NULL
;
6886 data
.deleteKeys
= FALSE
;
6887 data
.fileName
= NULL
;
6888 data
.file
= INVALID_HANDLE_VALUE
;
6889 data
.success
= FALSE
;
6891 memset(&pages
, 0, sizeof(pages
));
6893 pages
[nPages
].dwSize
= sizeof(pages
[0]);
6894 pages
[nPages
].hInstance
= hInstance
;
6895 pages
[nPages
].u
.pszTemplate
= MAKEINTRESOURCEW(IDD_EXPORT_WELCOME
);
6896 pages
[nPages
].pfnDlgProc
= export_welcome_dlg_proc
;
6897 pages
[nPages
].dwFlags
= PSP_HIDEHEADER
;
6898 pages
[nPages
].lParam
= (LPARAM
)&data
;
6901 hasPrivateKey
= export_info_has_private_key(pExportInfo
);
6902 switch (pExportInfo
->dwSubjectChoice
)
6904 case CRYPTUI_WIZ_EXPORT_CRL_CONTEXT
:
6905 case CRYPTUI_WIZ_EXPORT_CTL_CONTEXT
:
6906 showFormatPage
= FALSE
;
6907 data
.contextInfo
.dwExportFormat
= CRYPTUI_WIZ_EXPORT_FORMAT_DER
;
6909 case CRYPTUI_WIZ_EXPORT_CERT_STORE
:
6910 showFormatPage
= FALSE
;
6911 data
.contextInfo
.dwExportFormat
=
6912 CRYPTUI_WIZ_EXPORT_FORMAT_SERIALIZED_CERT_STORE
;
6914 case CRYPTUI_WIZ_EXPORT_CERT_STORE_CERTIFICATES_ONLY
:
6915 showFormatPage
= FALSE
;
6916 data
.contextInfo
.dwExportFormat
= CRYPTUI_WIZ_EXPORT_FORMAT_PKCS7
;
6920 if (hasPrivateKey
&& showFormatPage
)
6922 pages
[nPages
].dwSize
= sizeof(pages
[0]);
6923 pages
[nPages
].hInstance
= hInstance
;
6924 pages
[nPages
].u
.pszTemplate
= MAKEINTRESOURCEW(IDD_EXPORT_PRIVATE_KEY
);
6925 pages
[nPages
].pfnDlgProc
= export_private_key_dlg_proc
;
6926 pages
[nPages
].dwFlags
= PSP_USEHEADERTITLE
| PSP_USEHEADERSUBTITLE
;
6927 pages
[nPages
].pszHeaderTitle
=
6928 MAKEINTRESOURCEW(IDS_EXPORT_PRIVATE_KEY_TITLE
);
6929 pages
[nPages
].pszHeaderSubTitle
=
6930 MAKEINTRESOURCEW(IDS_EXPORT_PRIVATE_KEY_SUBTITLE
);
6931 pages
[nPages
].lParam
= (LPARAM
)&data
;
6936 pages
[nPages
].dwSize
= sizeof(pages
[0]);
6937 pages
[nPages
].hInstance
= hInstance
;
6938 pages
[nPages
].u
.pszTemplate
= MAKEINTRESOURCEW(IDD_EXPORT_FORMAT
);
6939 pages
[nPages
].pfnDlgProc
= export_format_dlg_proc
;
6940 pages
[nPages
].dwFlags
= PSP_USEHEADERTITLE
| PSP_USEHEADERSUBTITLE
;
6941 pages
[nPages
].pszHeaderTitle
=
6942 MAKEINTRESOURCEW(IDS_EXPORT_FORMAT_TITLE
);
6943 pages
[nPages
].pszHeaderSubTitle
=
6944 MAKEINTRESOURCEW(IDS_EXPORT_FORMAT_SUBTITLE
);
6945 pages
[nPages
].lParam
= (LPARAM
)&data
;
6948 if (hasPrivateKey
&& showFormatPage
)
6950 pages
[nPages
].dwSize
= sizeof(pages
[0]);
6951 pages
[nPages
].hInstance
= hInstance
;
6952 pages
[nPages
].u
.pszTemplate
= MAKEINTRESOURCEW(IDD_EXPORT_PASSWORD
);
6953 pages
[nPages
].pfnDlgProc
= export_password_dlg_proc
;
6954 pages
[nPages
].dwFlags
= PSP_USEHEADERTITLE
| PSP_USEHEADERSUBTITLE
;
6955 pages
[nPages
].pszHeaderTitle
=
6956 MAKEINTRESOURCEW(IDS_EXPORT_PASSWORD_TITLE
);
6957 pages
[nPages
].pszHeaderSubTitle
=
6958 MAKEINTRESOURCEW(IDS_EXPORT_PASSWORD_SUBTITLE
);
6959 pages
[nPages
].lParam
= (LPARAM
)&data
;
6963 pages
[nPages
].dwSize
= sizeof(pages
[0]);
6964 pages
[nPages
].hInstance
= hInstance
;
6965 pages
[nPages
].u
.pszTemplate
= MAKEINTRESOURCEW(IDD_EXPORT_FILE
);
6966 pages
[nPages
].pfnDlgProc
= export_file_dlg_proc
;
6967 pages
[nPages
].dwFlags
= PSP_USEHEADERTITLE
| PSP_USEHEADERSUBTITLE
;
6968 pages
[nPages
].pszHeaderTitle
= MAKEINTRESOURCEW(IDS_EXPORT_FILE_TITLE
);
6969 pages
[nPages
].pszHeaderSubTitle
=
6970 MAKEINTRESOURCEW(IDS_EXPORT_FILE_SUBTITLE
);
6971 pages
[nPages
].lParam
= (LPARAM
)&data
;
6974 pages
[nPages
].dwSize
= sizeof(pages
[0]);
6975 pages
[nPages
].hInstance
= hInstance
;
6976 pages
[nPages
].u
.pszTemplate
= MAKEINTRESOURCEW(IDD_EXPORT_FINISH
);
6977 pages
[nPages
].pfnDlgProc
= export_finish_dlg_proc
;
6978 pages
[nPages
].dwFlags
= PSP_HIDEHEADER
;
6979 pages
[nPages
].lParam
= (LPARAM
)&data
;
6982 memset(&hdr
, 0, sizeof(hdr
));
6983 hdr
.dwSize
= sizeof(hdr
);
6984 hdr
.hwndParent
= hwndParent
;
6985 hdr
.dwFlags
= PSH_PROPSHEETPAGE
| PSH_WIZARD97_NEW
| PSH_HEADER
|
6987 hdr
.hInstance
= hInstance
;
6988 if (pwszWizardTitle
)
6989 hdr
.pszCaption
= pwszWizardTitle
;
6991 hdr
.pszCaption
= MAKEINTRESOURCEW(IDS_EXPORT_WIZARD
);
6992 hdr
.u3
.ppsp
= pages
;
6993 hdr
.nPages
= nPages
;
6994 hdr
.u4
.pszbmWatermark
= MAKEINTRESOURCEW(IDB_CERT_WATERMARK
);
6995 hdr
.u5
.pszbmHeader
= MAKEINTRESOURCEW(IDB_CERT_HEADER
);
6996 l
= PropertySheetW(&hdr
);
6997 DeleteObject(data
.titleFont
);
6998 if (data
.freePassword
)
6999 HeapFree(GetProcessHeap(), 0,
7000 (LPWSTR
)data
.contextInfo
.pwszPassword
);
7001 HeapFree(GetProcessHeap(), 0, data
.keyProvInfo
);
7002 CloseHandle(data
.file
);
7003 HeapFree(GetProcessHeap(), 0, data
.fileName
);
7006 SetLastError(ERROR_CANCELLED
);
7010 return data
.success
;
7013 BOOL WINAPI
CryptUIWizExport(DWORD dwFlags
, HWND hwndParent
,
7014 LPCWSTR pwszWizardTitle
, PCCRYPTUI_WIZ_EXPORT_INFO pExportInfo
, void *pvoid
)
7018 TRACE("(%08x, %p, %s, %p, %p)\n", dwFlags
, hwndParent
,
7019 debugstr_w(pwszWizardTitle
), pExportInfo
, pvoid
);
7021 if (!(dwFlags
& CRYPTUI_WIZ_NO_UI
))
7022 ret
= show_export_ui(dwFlags
, hwndParent
, pwszWizardTitle
, pExportInfo
,
7026 HANDLE file
= CreateFileW(pExportInfo
->pwszExportFileName
,
7027 GENERIC_WRITE
, FILE_SHARE_READ
| FILE_SHARE_WRITE
, NULL
,
7028 CREATE_ALWAYS
, 0, NULL
);
7030 if (file
!= INVALID_HANDLE_VALUE
)
7032 ret
= do_export(file
, pExportInfo
, pvoid
, NULL
, FALSE
);
7041 BOOL WINAPI
CryptUIDlgViewSignerInfoA(CRYPTUI_VIEWSIGNERINFO_STRUCTA
*pcvsi
)
7043 FIXME("%p: stub\n", pcvsi
);
7047 PCCERT_CONTEXT WINAPI
CryptUIDlgSelectCertificateW(PCCRYPTUI_SELECTCERTIFICATE_STRUCTW pcsc
)
7049 FIXME("%p: stub\n", pcsc
);
7053 PCCERT_CONTEXT WINAPI
CryptUIDlgSelectCertificateA(PCCRYPTUI_SELECTCERTIFICATE_STRUCTA pcsc
)
7055 FIXME("%p: stub\n", pcsc
);