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
23 #define NONAMELESSUNION
36 #include "cryptuiapi.h"
37 #include "cryptuires.h"
41 #include "wine/debug.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(cryptui
);
45 static HINSTANCE hInstance
;
47 static const WCHAR empty
[] = {0};
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
);
65 static WCHAR
*strdupAtoW( const char *str
)
67 DWORD len
= MultiByteToWideChar( CP_ACP
, 0, str
, -1, NULL
, 0 );
68 WCHAR
*ret
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
69 if (ret
) MultiByteToWideChar( CP_ACP
, 0, str
, -1, ret
, len
);
73 #define MAX_STRING_LEN 512
75 static void add_cert_columns(HWND hwnd
)
77 HWND lv
= GetDlgItem(hwnd
, IDC_MGR_CERTS
);
79 WCHAR buf
[MAX_STRING_LEN
];
82 SendMessageW(lv
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0, LVS_EX_FULLROWSELECT
);
83 GetWindowRect(lv
, &rc
);
84 LoadStringW(hInstance
, IDS_SUBJECT_COLUMN
, buf
, ARRAY_SIZE(buf
));
85 column
.mask
= LVCF_WIDTH
| LVCF_TEXT
;
86 column
.cx
= (rc
.right
- rc
.left
) * 29 / 100 - 2;
88 SendMessageW(lv
, LVM_INSERTCOLUMNW
, 0, (LPARAM
)&column
);
89 LoadStringW(hInstance
, IDS_ISSUER_COLUMN
, buf
, ARRAY_SIZE(buf
));
90 SendMessageW(lv
, LVM_INSERTCOLUMNW
, 1, (LPARAM
)&column
);
91 column
.cx
= (rc
.right
- rc
.left
) * 16 / 100 - 2;
92 LoadStringW(hInstance
, IDS_EXPIRATION_COLUMN
, buf
, ARRAY_SIZE(buf
));
93 SendMessageW(lv
, LVM_INSERTCOLUMNW
, 2, (LPARAM
)&column
);
94 column
.cx
= (rc
.right
- rc
.left
) * 23 / 100 - 1;
95 LoadStringW(hInstance
, IDS_FRIENDLY_NAME_COLUMN
, buf
, ARRAY_SIZE(buf
));
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
, ARRAY_SIZE(dateFmt
));
151 FileTimeToSystemTime(&cert
->pCertInfo
->NotAfter
, &sysTime
);
152 GetDateFormatW(LOCALE_SYSTEM_DEFAULT
, 0, &sysTime
, dateFmt
, date
, ARRAY_SIZE(date
));
155 SendMessageW(lv
, LVM_SETITEMTEXTW
, item
.iItem
, (LPARAM
)&item
);
157 if (!CertGetCertificateContextProperty(cert
, CERT_FRIENDLY_NAME_PROP_ID
,
159 len
= LoadStringW(hInstance
, IDS_FRIENDLY_NAME_NONE
, (LPWSTR
)&none
, 0);
160 if (len
> *allocatedLen
)
162 HeapFree(GetProcessHeap(), 0, *str
);
163 *str
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
169 if (!CertGetCertificateContextProperty(cert
, CERT_FRIENDLY_NAME_PROP_ID
,
175 SendMessageW(lv
, LVM_SETITEMTEXTW
, item
.iItem
, (LPARAM
)&item
);
179 static LPSTR
get_cert_mgr_usages(void)
181 static const WCHAR keyName
[] = { 'S','o','f','t','w','a','r','e','\\','M',
182 'i','c','r','o','s','o','f','t','\\','C','r','y','p','t','o','g','r','a',
183 'p','h','y','\\','U','I','\\','C','e','r','t','m','g','r','\\','P','u',
184 'r','p','o','s','e',0 };
188 if (!RegCreateKeyExW(HKEY_CURRENT_USER
, keyName
, 0, NULL
, 0, KEY_READ
,
194 rc
= RegQueryValueExA(key
, "Purpose", NULL
, &type
, NULL
, &size
);
195 if ((!rc
|| rc
== ERROR_MORE_DATA
) && type
== REG_SZ
)
197 str
= HeapAlloc(GetProcessHeap(), 0, size
);
200 rc
= RegQueryValueExA(key
, "Purpose", NULL
, NULL
, (LPBYTE
)str
,
204 HeapFree(GetProcessHeap(), 0, str
);
215 PurposeFilterShowAll
= 0,
216 PurposeFilterShowAdvanced
= 1,
217 PurposeFilterShowOID
= 2
220 static void initialize_purpose_selection(HWND hwnd
)
222 HWND cb
= GetDlgItem(hwnd
, IDC_MGR_PURPOSE_SELECTION
);
223 WCHAR buf
[MAX_STRING_LEN
];
227 LoadStringW(hInstance
, IDS_PURPOSE_ALL
, buf
, ARRAY_SIZE(buf
));
228 index
= SendMessageW(cb
, CB_INSERTSTRING
, -1, (LPARAM
)buf
);
229 SendMessageW(cb
, CB_SETITEMDATA
, index
, (LPARAM
)PurposeFilterShowAll
);
230 LoadStringW(hInstance
, IDS_PURPOSE_ADVANCED
, buf
, ARRAY_SIZE(buf
));
231 index
= SendMessageW(cb
, CB_INSERTSTRING
, -1, (LPARAM
)buf
);
232 SendMessageW(cb
, CB_SETITEMDATA
, index
, (LPARAM
)PurposeFilterShowAdvanced
);
233 SendMessageW(cb
, CB_SETCURSEL
, 0, 0);
234 if ((usages
= get_cert_mgr_usages()))
238 for (ptr
= usages
, comma
= strchr(ptr
, ','); ptr
&& *ptr
;
239 ptr
= comma
? comma
+ 1 : NULL
,
240 comma
= ptr
? strchr(ptr
, ',') : NULL
)
242 PCCRYPT_OID_INFO info
;
246 if ((info
= CryptFindOIDInfo(CRYPT_OID_INFO_OID_KEY
, ptr
, 0)))
248 index
= SendMessageW(cb
, CB_INSERTSTRING
, 0,
249 (LPARAM
)info
->pwszName
);
250 SendMessageW(cb
, CB_SETITEMDATA
, index
, (LPARAM
)info
);
253 HeapFree(GetProcessHeap(), 0, usages
);
257 extern BOOL WINAPI
WTHelperGetKnownUsages(DWORD action
,
258 PCCRYPT_OID_INFO
**usages
);
260 static CERT_ENHKEY_USAGE
*add_oid_to_usage(CERT_ENHKEY_USAGE
*usage
, LPSTR oid
)
262 if (!usage
->cUsageIdentifier
)
263 usage
->rgpszUsageIdentifier
= HeapAlloc(GetProcessHeap(), 0,
266 usage
->rgpszUsageIdentifier
= HeapReAlloc(GetProcessHeap(), 0,
267 usage
->rgpszUsageIdentifier
,
268 (usage
->cUsageIdentifier
+ 1) * sizeof(LPSTR
));
269 if (usage
->rgpszUsageIdentifier
)
270 usage
->rgpszUsageIdentifier
[usage
->cUsageIdentifier
++] = oid
;
273 HeapFree(GetProcessHeap(), 0, usage
);
279 static CERT_ENHKEY_USAGE
*convert_usages_str_to_usage(LPSTR usageStr
)
281 CERT_ENHKEY_USAGE
*usage
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
282 sizeof(CERT_ENHKEY_USAGE
));
288 for (ptr
= usageStr
, comma
= strchr(ptr
, ','); usage
&& ptr
&& *ptr
;
289 ptr
= comma
? comma
+ 1 : NULL
,
290 comma
= ptr
? strchr(ptr
, ',') : NULL
)
294 usage
= add_oid_to_usage(usage
, ptr
);
300 static CERT_ENHKEY_USAGE
*create_advanced_filter(void)
302 CERT_ENHKEY_USAGE
*advancedUsage
= HeapAlloc(GetProcessHeap(),
303 HEAP_ZERO_MEMORY
, sizeof(CERT_ENHKEY_USAGE
));
307 PCCRYPT_OID_INFO
*usages
;
309 if (WTHelperGetKnownUsages(1, &usages
))
311 LPSTR disabledUsagesStr
;
313 if ((disabledUsagesStr
= get_cert_mgr_usages()))
315 CERT_ENHKEY_USAGE
*disabledUsages
=
316 convert_usages_str_to_usage(disabledUsagesStr
);
320 PCCRYPT_OID_INFO
*ptr
;
322 for (ptr
= usages
; advancedUsage
&& *ptr
; ptr
++)
325 BOOL disabled
= FALSE
;
327 for (i
= 0; !disabled
&&
328 i
< disabledUsages
->cUsageIdentifier
; i
++)
329 if (!strcmp(disabledUsages
->rgpszUsageIdentifier
[i
],
333 advancedUsage
= add_oid_to_usage(advancedUsage
,
334 (LPSTR
)(*ptr
)->pszOID
);
336 /* The individual strings are pointers to disabledUsagesStr,
337 * so they're freed when it is.
339 HeapFree(GetProcessHeap(), 0,
340 disabledUsages
->rgpszUsageIdentifier
);
341 HeapFree(GetProcessHeap(), 0, disabledUsages
);
343 HeapFree(GetProcessHeap(), 0, disabledUsagesStr
);
345 WTHelperGetKnownUsages(2, &usages
);
348 return advancedUsage
;
351 static int CALLBACK
cert_mgr_sort_by_subject(LPARAM lp1
, LPARAM lp2
, LPARAM lp
);
353 static void show_store_certs(HWND hwnd
, HCERTSTORE store
)
355 HWND lv
= GetDlgItem(hwnd
, IDC_MGR_CERTS
);
356 HWND cb
= GetDlgItem(hwnd
, IDC_MGR_PURPOSE_SELECTION
);
357 PCCERT_CONTEXT cert
= NULL
;
358 DWORD allocatedLen
= 0;
361 PurposeFilter filter
= PurposeFilterShowAll
;
363 CERT_ENHKEY_USAGE
*advanced
= NULL
;
365 index
= SendMessageW(cb
, CB_GETCURSEL
, 0, 0);
368 INT_PTR data
= SendMessageW(cb
, CB_GETITEMDATA
, index
, 0);
374 PCCRYPT_OID_INFO info
= (PCCRYPT_OID_INFO
)data
;
376 filter
= PurposeFilterShowOID
;
380 if (filter
== PurposeFilterShowAdvanced
)
381 advanced
= create_advanced_filter();
383 cert
= CertEnumCertificatesInStore(store
, cert
);
388 if (filter
== PurposeFilterShowAll
)
395 if (CertGetValidUsages(1, &cert
, &numOIDs
, NULL
, &cbOIDs
))
399 /* -1 implies all usages are valid */
404 LPSTR
*oids
= HeapAlloc(GetProcessHeap(), 0, cbOIDs
);
408 if (CertGetValidUsages(1, &cert
, &numOIDs
, oids
,
413 if (filter
== PurposeFilterShowOID
)
415 for (i
= 0; !show
&& i
< numOIDs
; i
++)
416 if (!strcmp(oids
[i
], oid
))
421 for (i
= 0; !show
&& i
< numOIDs
; i
++)
426 j
< advanced
->cUsageIdentifier
; j
++)
428 advanced
->rgpszUsageIdentifier
[j
]))
433 HeapFree(GetProcessHeap(), 0, oids
);
439 add_cert_to_view(lv
, cert
, &allocatedLen
, &str
);
442 HeapFree(GetProcessHeap(), 0, str
);
445 HeapFree(GetProcessHeap(), 0, advanced
->rgpszUsageIdentifier
);
446 HeapFree(GetProcessHeap(), 0, advanced
);
448 SendMessageW(lv
, LVM_SORTITEMSEX
, (WPARAM
)lv
,
449 (LPARAM
)cert_mgr_sort_by_subject
);
452 static const WCHAR my
[] = { 'M','y',0 };
453 static const WCHAR addressBook
[] = {
454 'A','d','d','r','e','s','s','B','o','o','k',0 };
455 static const WCHAR ca
[] = { 'C','A',0 };
456 static const WCHAR root
[] = { 'R','o','o','t',0 };
457 static const WCHAR trustedPublisher
[] = {
458 'T','r','u','s','t','e','d','P','u','b','l','i','s','h','e','r',0 };
459 static const WCHAR disallowed
[] = { 'D','i','s','a','l','l','o','w','e','d',0 };
461 struct CertMgrStoreInfo
465 int removePluralWarning
;
468 static const struct CertMgrStoreInfo defaultStoreList
[] = {
469 { my
, IDS_WARN_REMOVE_MY
, IDS_WARN_REMOVE_PLURAL_MY
},
470 { addressBook
, IDS_WARN_REMOVE_ADDRESSBOOK
,
471 IDS_WARN_REMOVE_PLURAL_ADDRESSBOOK
},
472 { ca
, IDS_WARN_REMOVE_CA
, IDS_WARN_REMOVE_PLURAL_CA
},
473 { root
, IDS_WARN_REMOVE_ROOT
, IDS_WARN_REMOVE_PLURAL_ROOT
},
474 { trustedPublisher
, IDS_WARN_REMOVE_TRUSTEDPUBLISHER
,
475 IDS_WARN_REMOVE_PLURAL_TRUSTEDPUBLISHER
},
476 { disallowed
, IDS_WARN_REMOVE_DEFAULT
},
479 static const struct CertMgrStoreInfo publisherStoreList
[] = {
480 { root
, IDS_WARN_REMOVE_ROOT
, IDS_WARN_REMOVE_PLURAL_ROOT
},
481 { trustedPublisher
, IDS_WARN_REMOVE_TRUSTEDPUBLISHER
,
482 IDS_WARN_REMOVE_PLURAL_TRUSTEDPUBLISHER
},
483 { disallowed
, IDS_WARN_REMOVE_PLURAL_DEFAULT
},
488 HIMAGELIST imageList
;
491 const struct CertMgrStoreInfo
*stores
;
494 static void show_cert_stores(HWND hwnd
, DWORD dwFlags
, struct CertMgrData
*data
)
496 const struct CertMgrStoreInfo
*storeList
;
498 HWND tab
= GetDlgItem(hwnd
, IDC_MGR_STORES
);
500 if (dwFlags
& CRYPTUI_CERT_MGR_PUBLISHER_TAB
)
502 storeList
= publisherStoreList
;
503 cStores
= ARRAY_SIZE(publisherStoreList
);
507 storeList
= defaultStoreList
;
508 cStores
= ARRAY_SIZE(defaultStoreList
);
510 if (dwFlags
& CRYPTUI_CERT_MGR_SINGLE_TAB_FLAG
)
512 data
->nStores
= cStores
;
513 data
->stores
= storeList
;
514 for (i
= 0; i
< cStores
; i
++)
520 if (!(name
= CryptFindLocalizedName(storeList
[i
].name
)))
521 name
= storeList
[i
].name
;
522 store
= CertOpenStore(CERT_STORE_PROV_SYSTEM_W
, 0, 0,
523 CERT_SYSTEM_STORE_CURRENT_USER
, storeList
[i
].name
);
524 item
.mask
= TCIF_TEXT
| TCIF_PARAM
;
525 item
.pszText
= (LPWSTR
)name
;
526 item
.lParam
= (LPARAM
)store
;
527 SendMessageW(tab
, TCM_INSERTITEMW
, i
, (LPARAM
)&item
);
531 static void free_certs(HWND lv
)
534 int items
= SendMessageW(lv
, LVM_GETITEMCOUNT
, 0, 0), i
;
536 for (i
= 0; i
< items
; i
++)
538 item
.mask
= LVIF_PARAM
;
541 SendMessageW(lv
, LVM_GETITEMW
, 0, (LPARAM
)&item
);
542 CertFreeCertificateContext((PCCERT_CONTEXT
)item
.lParam
);
546 static HCERTSTORE
cert_mgr_index_to_store(HWND tab
, int index
)
550 item
.mask
= TCIF_PARAM
;
551 SendMessageW(tab
, TCM_GETITEMW
, index
, (LPARAM
)&item
);
552 return (HCERTSTORE
)item
.lParam
;
555 static HCERTSTORE
cert_mgr_current_store(HWND hwnd
)
557 HWND tab
= GetDlgItem(hwnd
, IDC_MGR_STORES
);
559 return cert_mgr_index_to_store(tab
, SendMessageW(tab
, TCM_GETCURSEL
, 0, 0));
562 static void close_stores(HWND tab
)
564 int i
, tabs
= SendMessageW(tab
, TCM_GETITEMCOUNT
, 0, 0);
566 for (i
= 0; i
< tabs
; i
++)
567 CertCloseStore(cert_mgr_index_to_store(tab
, i
), 0);
570 static void refresh_store_certs(HWND hwnd
)
572 HWND lv
= GetDlgItem(hwnd
, IDC_MGR_CERTS
);
575 SendMessageW(lv
, LVM_DELETEALLITEMS
, 0, 0);
576 show_store_certs(hwnd
, cert_mgr_current_store(hwnd
));
580 CheckBitmapIndexUnchecked
= 1,
581 CheckBitmapIndexChecked
= 2,
582 CheckBitmapIndexDisabledUnchecked
= 3,
583 CheckBitmapIndexDisabledChecked
= 4
586 static void add_known_usage(HWND lv
, PCCRYPT_OID_INFO info
,
587 CheckBitmapIndex state
)
591 item
.mask
= LVIF_TEXT
| LVIF_STATE
| LVIF_PARAM
;
592 item
.state
= INDEXTOSTATEIMAGEMASK(state
);
593 item
.stateMask
= LVIS_STATEIMAGEMASK
;
594 item
.iItem
= SendMessageW(lv
, LVM_GETITEMCOUNT
, 0, 0);
596 item
.lParam
= (LPARAM
)info
;
597 item
.pszText
= (LPWSTR
)info
->pwszName
;
598 SendMessageW(lv
, LVM_INSERTITEMW
, 0, (LPARAM
)&item
);
601 static void add_known_usages_to_list(HWND lv
, CheckBitmapIndex state
)
603 PCCRYPT_OID_INFO
*usages
;
605 if (WTHelperGetKnownUsages(1, &usages
))
607 PCCRYPT_OID_INFO
*ptr
;
609 for (ptr
= usages
; *ptr
; ptr
++)
610 add_known_usage(lv
, *ptr
, state
);
611 WTHelperGetKnownUsages(2, &usages
);
615 static void toggle_usage(HWND hwnd
, int iItem
)
619 HWND lv
= GetDlgItem(hwnd
, IDC_CERTIFICATE_USAGES
);
621 item
.mask
= LVIF_STATE
;
624 item
.stateMask
= LVIS_STATEIMAGEMASK
;
625 res
= SendMessageW(lv
, LVM_GETITEMW
, 0, (LPARAM
)&item
);
628 int state
= item
.state
>> 12;
630 item
.state
= INDEXTOSTATEIMAGEMASK(
631 state
== CheckBitmapIndexChecked
? CheckBitmapIndexUnchecked
:
632 CheckBitmapIndexChecked
);
633 SendMessageW(lv
, LVM_SETITEMSTATE
, iItem
, (LPARAM
)&item
);
637 static LONG_PTR
find_oid_in_list(HWND lv
, LPCSTR oid
)
639 PCCRYPT_OID_INFO oidInfo
= CryptFindOIDInfo(CRYPT_OID_INFO_OID_KEY
,
640 (void *)oid
, CRYPT_ENHKEY_USAGE_OID_GROUP_ID
);
645 LVFINDINFOW findInfo
;
647 findInfo
.flags
= LVFI_PARAM
;
648 findInfo
.lParam
= (LPARAM
)oidInfo
;
649 ret
= SendMessageW(lv
, LVM_FINDITEMW
, -1, (LPARAM
)&findInfo
);
653 LVFINDINFOA findInfo
;
655 findInfo
.flags
= LVFI_STRING
;
657 ret
= SendMessageW(lv
, LVM_FINDITEMA
, -1, (LPARAM
)&findInfo
);
662 static void save_cert_mgr_usages(HWND hwnd
)
664 static const WCHAR keyName
[] = { 'S','o','f','t','w','a','r','e','\\','M',
665 'i','c','r','o','s','o','f','t','\\','C','r','y','p','t','o','g','r','a',
666 'p','h','y','\\','U','I','\\','C','e','r','t','m','g','r','\\','P','u',
667 'r','p','o','s','e',0 };
669 HWND lv
= GetDlgItem(hwnd
, IDC_CERTIFICATE_USAGES
);
670 int purposes
= SendMessageW(lv
, LVM_GETITEMCOUNT
, 0, 0), i
;
674 item
.mask
= LVIF_STATE
| LVIF_PARAM
;
676 item
.stateMask
= LVIS_STATEIMAGEMASK
;
677 for (i
= 0; i
< purposes
; i
++)
680 if (SendMessageW(lv
, LVM_GETITEMW
, 0, (LPARAM
)&item
))
682 int state
= item
.state
>> 12;
684 if (state
== CheckBitmapIndexUnchecked
)
686 CRYPT_OID_INFO
*info
= (CRYPT_OID_INFO
*)item
.lParam
;
687 BOOL firstString
= TRUE
;
690 str
= HeapAlloc(GetProcessHeap(), 0,
691 strlen(info
->pszOID
) + 1);
694 str
= HeapReAlloc(GetProcessHeap(), 0, str
,
695 strlen(str
) + 1 + strlen(info
->pszOID
) + 1);
700 LPSTR ptr
= firstString
? str
: str
+ strlen(str
);
704 strcpy(ptr
, info
->pszOID
);
709 if (!RegCreateKeyExW(HKEY_CURRENT_USER
, keyName
, 0, NULL
, 0, KEY_ALL_ACCESS
,
713 RegSetValueExA(key
, "Purpose", 0, REG_SZ
, (const BYTE
*)str
,
716 RegDeleteValueA(key
, "Purpose");
719 HeapFree(GetProcessHeap(), 0, str
);
722 static LRESULT CALLBACK
cert_mgr_advanced_dlg_proc(HWND hwnd
, UINT msg
,
723 WPARAM wp
, LPARAM lp
)
731 HWND lv
= GetDlgItem(hwnd
, IDC_CERTIFICATE_USAGES
);
732 HIMAGELIST imageList
;
733 LPSTR disabledUsages
;
735 GetWindowRect(lv
, &rc
);
736 column
.mask
= LVCF_WIDTH
;
737 column
.cx
= rc
.right
- rc
.left
;
738 SendMessageW(lv
, LVM_INSERTCOLUMNW
, 0, (LPARAM
)&column
);
739 imageList
= ImageList_Create(16, 16, ILC_COLOR4
| ILC_MASK
, 4, 0);
743 COLORREF backColor
= RGB(255, 0, 255);
745 bmp
= LoadBitmapW(hInstance
, MAKEINTRESOURCEW(IDB_CHECKS
));
746 ImageList_AddMasked(imageList
, bmp
, backColor
);
748 ImageList_SetBkColor(imageList
, CLR_NONE
);
749 SendMessageW(lv
, LVM_SETIMAGELIST
, LVSIL_STATE
, (LPARAM
)imageList
);
750 SetWindowLongPtrW(hwnd
, DWLP_USER
, (LPARAM
)imageList
);
752 add_known_usages_to_list(lv
, CheckBitmapIndexChecked
);
753 if ((disabledUsages
= get_cert_mgr_usages()))
757 for (ptr
= disabledUsages
, comma
= strchr(ptr
, ','); ptr
&& *ptr
;
758 ptr
= comma
? comma
+ 1 : NULL
,
759 comma
= ptr
? strchr(ptr
, ',') : NULL
)
765 if ((index
= find_oid_in_list(lv
, ptr
)) != -1)
766 toggle_usage(hwnd
, index
);
768 HeapFree(GetProcessHeap(), 0, disabledUsages
);
774 NMHDR
*hdr
= (NMHDR
*)lp
;
780 nm
= (NMITEMACTIVATE
*)lp
;
781 toggle_usage(hwnd
, nm
->iItem
);
782 SendMessageW(GetParent(hwnd
), PSM_CHANGED
, (WPARAM
)hwnd
, 0);
791 save_cert_mgr_usages(hwnd
);
792 ImageList_Destroy((HIMAGELIST
)GetWindowLongPtrW(hwnd
, DWLP_USER
));
793 EndDialog(hwnd
, IDOK
);
796 ImageList_Destroy((HIMAGELIST
)GetWindowLongPtrW(hwnd
, DWLP_USER
));
797 EndDialog(hwnd
, IDCANCEL
);
805 static void cert_mgr_clear_cert_selection(HWND hwnd
)
807 EnableWindow(GetDlgItem(hwnd
, IDC_MGR_EXPORT
), FALSE
);
808 EnableWindow(GetDlgItem(hwnd
, IDC_MGR_REMOVE
), FALSE
);
809 EnableWindow(GetDlgItem(hwnd
, IDC_MGR_VIEW
), FALSE
);
810 SendMessageW(GetDlgItem(hwnd
, IDC_MGR_PURPOSES
), WM_SETTEXT
, 0,
812 refresh_store_certs(hwnd
);
815 static PCCERT_CONTEXT
cert_mgr_index_to_cert(HWND hwnd
, int index
)
817 PCCERT_CONTEXT cert
= NULL
;
820 item
.mask
= LVIF_PARAM
;
823 if (SendMessageW(GetDlgItem(hwnd
, IDC_MGR_CERTS
), LVM_GETITEMW
, 0,
825 cert
= (PCCERT_CONTEXT
)item
.lParam
;
829 static void show_selected_cert(HWND hwnd
, int index
)
831 PCCERT_CONTEXT cert
= cert_mgr_index_to_cert(hwnd
, index
);
835 CRYPTUI_VIEWCERTIFICATE_STRUCTW viewInfo
;
837 memset(&viewInfo
, 0, sizeof(viewInfo
));
838 viewInfo
.dwSize
= sizeof(viewInfo
);
839 viewInfo
.hwndParent
= hwnd
;
840 viewInfo
.pCertContext
= cert
;
841 /* FIXME: this should be modal */
842 CryptUIDlgViewCertificateW(&viewInfo
, NULL
);
846 static void get_cert_usages(PCCERT_CONTEXT cert
, LPWSTR
*str
)
848 PCERT_ENHKEY_USAGE usage
;
851 /* Get enhanced key usage. Have to check for a property and an extension
852 * separately, because CertGetEnhancedKeyUsage will succeed and return an
853 * empty usage if neither is set. Unfortunately an empty usage implies
854 * no usage is allowed, so we have to distinguish between the two cases.
856 if (CertGetEnhancedKeyUsage(cert
, CERT_FIND_PROP_ONLY_ENHKEY_USAGE_FLAG
,
859 usage
= HeapAlloc(GetProcessHeap(), 0, size
);
860 if (!CertGetEnhancedKeyUsage(cert
,
861 CERT_FIND_PROP_ONLY_ENHKEY_USAGE_FLAG
, usage
, &size
))
863 HeapFree(GetProcessHeap(), 0, usage
);
867 else if (CertGetEnhancedKeyUsage(cert
, CERT_FIND_EXT_ONLY_ENHKEY_USAGE_FLAG
,
870 usage
= HeapAlloc(GetProcessHeap(), 0, size
);
871 if (!CertGetEnhancedKeyUsage(cert
,
872 CERT_FIND_EXT_ONLY_ENHKEY_USAGE_FLAG
, usage
, &size
))
874 HeapFree(GetProcessHeap(), 0, usage
);
882 if (usage
->cUsageIdentifier
)
884 static const WCHAR commaSpace
[] = { ',',' ',0 };
888 for (i
= 0; i
< usage
->cUsageIdentifier
; i
++)
890 PCCRYPT_OID_INFO info
=
891 CryptFindOIDInfo(CRYPT_OID_INFO_OID_KEY
,
892 usage
->rgpszUsageIdentifier
[i
],
893 CRYPT_ENHKEY_USAGE_OID_GROUP_ID
);
896 len
+= lstrlenW(info
->pwszName
);
898 len
+= strlen(usage
->rgpszUsageIdentifier
[i
]);
899 if (i
< usage
->cUsageIdentifier
- 1)
900 len
+= lstrlenW(commaSpace
);
902 *str
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
905 for (i
= 0, ptr
= *str
; i
< usage
->cUsageIdentifier
; i
++)
907 PCCRYPT_OID_INFO info
=
908 CryptFindOIDInfo(CRYPT_OID_INFO_OID_KEY
,
909 usage
->rgpszUsageIdentifier
[i
],
910 CRYPT_ENHKEY_USAGE_OID_GROUP_ID
);
914 lstrcpyW(ptr
, info
->pwszName
);
915 ptr
+= lstrlenW(info
->pwszName
);
919 LPCSTR src
= usage
->rgpszUsageIdentifier
[i
];
921 for (; *src
; ptr
++, src
++)
925 if (i
< usage
->cUsageIdentifier
- 1)
927 lstrcpyW(ptr
, commaSpace
);
928 ptr
+= lstrlenW(commaSpace
);
933 HeapFree(GetProcessHeap(), 0, usage
);
937 size
= MAX_STRING_LEN
* sizeof(WCHAR
);
938 *str
= HeapAlloc(GetProcessHeap(), 0, size
);
940 LoadStringW(hInstance
, IDS_ALLOWED_PURPOSE_NONE
, *str
, size
);
945 size
= MAX_STRING_LEN
* sizeof(WCHAR
);
946 *str
= HeapAlloc(GetProcessHeap(), 0, size
);
948 LoadStringW(hInstance
, IDS_ALLOWED_PURPOSE_ALL
, *str
, size
);
952 static void cert_mgr_show_cert_usages(HWND hwnd
, int index
)
954 HWND text
= GetDlgItem(hwnd
, IDC_MGR_PURPOSES
);
955 PCCERT_CONTEXT cert
= cert_mgr_index_to_cert(hwnd
, index
);
958 get_cert_usages(cert
, &str
);
961 SendMessageW(text
, WM_SETTEXT
, 0, (LPARAM
)str
);
962 HeapFree(GetProcessHeap(), 0, str
);
966 static void cert_mgr_do_remove(HWND hwnd
)
968 int tabIndex
= SendMessageW(GetDlgItem(hwnd
, IDC_MGR_STORES
),
969 TCM_GETCURSEL
, 0, 0);
970 struct CertMgrData
*data
=
971 (struct CertMgrData
*)GetWindowLongPtrW(hwnd
, DWLP_USER
);
973 if (tabIndex
< data
->nStores
)
975 HWND lv
= GetDlgItem(hwnd
, IDC_MGR_CERTS
);
976 WCHAR warning
[MAX_STRING_LEN
], title
[MAX_STRING_LEN
];
980 if (SendMessageW(lv
, LVM_GETSELECTEDCOUNT
, 0, 0) > 1)
981 warningID
= data
->stores
[tabIndex
].removePluralWarning
;
983 warningID
= data
->stores
[tabIndex
].removeWarning
;
985 pTitle
= data
->title
;
988 LoadStringW(hInstance
, IDS_CERT_MGR
, title
, ARRAY_SIZE(title
));
991 LoadStringW(hInstance
, warningID
, warning
, ARRAY_SIZE(warning
));
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
= ARRAY_SIZE(buf1
);
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 lstrcmpW(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 NMITEMACTIVATE
*nm
= (NMITEMACTIVATE
*)lp
;
1168 HWND lv
= GetDlgItem(hwnd
, IDC_MGR_CERTS
);
1169 int numSelected
= SendMessageW(lv
, LVM_GETSELECTEDCOUNT
, 0, 0);
1171 EnableWindow(GetDlgItem(hwnd
, IDC_MGR_EXPORT
), numSelected
> 0);
1172 EnableWindow(GetDlgItem(hwnd
, IDC_MGR_REMOVE
), numSelected
> 0);
1173 EnableWindow(GetDlgItem(hwnd
, IDC_MGR_VIEW
), numSelected
== 1);
1174 if (numSelected
== 1)
1175 cert_mgr_show_cert_usages(hwnd
, nm
->iItem
);
1177 SendMessageW(GetDlgItem(hwnd
, IDC_MGR_PURPOSES
), WM_SETTEXT
, 0,
1182 show_selected_cert(hwnd
, ((NMITEMACTIVATE
*)lp
)->iItem
);
1186 NMLVKEYDOWN
*lvk
= (NMLVKEYDOWN
*)lp
;
1188 if (lvk
->wVKey
== VK_DELETE
)
1189 cert_mgr_do_remove(hwnd
);
1192 case LVN_COLUMNCLICK
:
1194 NMLISTVIEW
*nmlv
= (NMLISTVIEW
*)lp
;
1195 HWND lv
= GetDlgItem(hwnd
, IDC_MGR_CERTS
);
1197 /* FIXME: doesn't support swapping sort order between ascending
1200 switch (nmlv
->iSubItem
)
1203 SendMessageW(lv
, LVM_SORTITEMSEX
, (WPARAM
)lv
,
1204 (LPARAM
)cert_mgr_sort_by_subject
);
1207 SendMessageW(lv
, LVM_SORTITEMSEX
, (WPARAM
)lv
,
1208 (LPARAM
)cert_mgr_sort_by_issuer
);
1211 SendMessageW(lv
, LVM_SORTITEMS
, 0,
1212 (LPARAM
)cert_mgr_sort_by_date
);
1215 SendMessageW(lv
, LVM_SORTITEMSEX
, (WPARAM
)lv
,
1216 (LPARAM
)cert_mgr_sort_by_friendly_name
);
1227 case ((CBN_SELCHANGE
<< 16) | IDC_MGR_PURPOSE_SELECTION
):
1228 cert_mgr_clear_cert_selection(hwnd
);
1230 case IDC_MGR_IMPORT
:
1231 if (CryptUIWizImport(0, hwnd
, NULL
, NULL
,
1232 cert_mgr_current_store(hwnd
)))
1233 refresh_store_certs(hwnd
);
1235 case IDC_MGR_ADVANCED
:
1236 if (DialogBoxW(hInstance
, MAKEINTRESOURCEW(IDD_CERT_MGR_ADVANCED
),
1237 hwnd
, cert_mgr_advanced_dlg_proc
) == IDOK
)
1239 HWND cb
= GetDlgItem(hwnd
, IDC_MGR_PURPOSE_SELECTION
);
1241 LPWSTR curString
= NULL
;
1243 index
= SendMessageW(cb
, CB_GETCURSEL
, 0, 0);
1246 len
= SendMessageW(cb
, CB_GETLBTEXTLEN
, index
, 0);
1247 curString
= HeapAlloc(GetProcessHeap(), 0,
1248 (len
+ 1) * sizeof(WCHAR
));
1249 SendMessageW(cb
, CB_GETLBTEXT
, index
, (LPARAM
)curString
);
1251 SendMessageW(cb
, CB_RESETCONTENT
, 0, 0);
1252 initialize_purpose_selection(hwnd
);
1255 index
= SendMessageW(cb
, CB_FINDSTRINGEXACT
, -1,
1258 SendMessageW(cb
, CB_SETCURSEL
, index
, 0);
1259 HeapFree(GetProcessHeap(), 0, curString
);
1261 refresh_store_certs(hwnd
);
1266 HWND lv
= GetDlgItem(hwnd
, IDC_MGR_CERTS
);
1267 int selection
= SendMessageW(lv
, LVM_GETNEXTITEM
, -1,
1271 show_selected_cert(hwnd
, selection
);
1274 case IDC_MGR_EXPORT
:
1275 cert_mgr_do_export(hwnd
);
1277 case IDC_MGR_REMOVE
:
1278 cert_mgr_do_remove(hwnd
);
1281 free_certs(GetDlgItem(hwnd
, IDC_MGR_CERTS
));
1282 close_stores(GetDlgItem(hwnd
, IDC_MGR_STORES
));
1283 data
= (struct CertMgrData
*)GetWindowLongPtrW(hwnd
, DWLP_USER
);
1284 ImageList_Destroy(data
->imageList
);
1285 HeapFree(GetProcessHeap(), 0, data
);
1286 EndDialog(hwnd
, IDCANCEL
);
1294 /***********************************************************************
1295 * CryptUIDlgCertMgr (CRYPTUI.@)
1297 BOOL WINAPI
CryptUIDlgCertMgr(PCCRYPTUI_CERT_MGR_STRUCT pCryptUICertMgr
)
1299 TRACE("(%p)\n", pCryptUICertMgr
);
1301 if (pCryptUICertMgr
->dwSize
!= sizeof(CRYPTUI_CERT_MGR_STRUCT
))
1303 WARN("unexpected size %d\n", pCryptUICertMgr
->dwSize
);
1304 SetLastError(E_INVALIDARG
);
1307 DialogBoxParamW(hInstance
, MAKEINTRESOURCEW(IDD_CERT_MGR
),
1308 pCryptUICertMgr
->hwndParent
, cert_mgr_dlg_proc
, (LPARAM
)pCryptUICertMgr
);
1312 /* FIXME: real names are unknown, functions are undocumented */
1313 typedef struct _CRYPTUI_ENUM_SYSTEM_STORE_ARGS
1316 void *pvSystemStoreLocationPara
;
1317 } CRYPTUI_ENUM_SYSTEM_STORE_ARGS
, *PCRYPTUI_ENUM_SYSTEM_STORE_ARGS
;
1319 typedef struct _CRYPTUI_ENUM_DATA
1322 HCERTSTORE
*rghStore
;
1324 PCRYPTUI_ENUM_SYSTEM_STORE_ARGS rgEnumArgs
;
1325 } CRYPTUI_ENUM_DATA
, *PCRYPTUI_ENUM_DATA
;
1327 typedef BOOL (WINAPI
*PFN_SELECTED_STORE_CB
)(HCERTSTORE store
, HWND hwnd
,
1330 /* Values for dwFlags */
1331 #define CRYPTUI_ENABLE_SHOW_PHYSICAL_STORE 0x00000001
1333 typedef struct _CRYPTUI_SELECTSTORE_INFO_A
1340 CRYPTUI_ENUM_DATA
*pEnumData
;
1341 PFN_SELECTED_STORE_CB pfnSelectedStoreCallback
;
1343 } CRYPTUI_SELECTSTORE_INFO_A
, *PCRYPTUI_SELECTSTORE_INFO_A
;
1345 typedef struct _CRYPTUI_SELECTSTORE_INFO_W
1352 CRYPTUI_ENUM_DATA
*pEnumData
;
1353 PFN_SELECTED_STORE_CB pfnSelectedStoreCallback
;
1355 } CRYPTUI_SELECTSTORE_INFO_W
, *PCRYPTUI_SELECTSTORE_INFO_W
;
1369 static BOOL WINAPI
enum_store_callback(const void *pvSystemStore
,
1370 DWORD dwFlags
, PCERT_SYSTEM_STORE_INFO pStoreInfo
, void *pvReserved
,
1373 HWND tree
= GetDlgItem(pvArg
, IDC_STORE_LIST
);
1374 TVINSERTSTRUCTW tvis
;
1375 LPCWSTR localizedName
;
1378 tvis
.hParent
= NULL
;
1379 tvis
.hInsertAfter
= TVI_LAST
;
1380 tvis
.u
.item
.mask
= TVIF_TEXT
;
1381 if ((localizedName
= CryptFindLocalizedName(pvSystemStore
)))
1383 struct StoreInfo
*storeInfo
= HeapAlloc(GetProcessHeap(), 0,
1384 sizeof(struct StoreInfo
));
1388 storeInfo
->type
= SystemStore
;
1389 storeInfo
->u
.name
= HeapAlloc(GetProcessHeap(), 0,
1390 (lstrlenW(pvSystemStore
) + 1) * sizeof(WCHAR
));
1391 if (storeInfo
->u
.name
)
1393 tvis
.u
.item
.mask
|= TVIF_PARAM
;
1394 tvis
.u
.item
.lParam
= (LPARAM
)storeInfo
;
1395 lstrcpyW(storeInfo
->u
.name
, pvSystemStore
);
1399 HeapFree(GetProcessHeap(), 0, storeInfo
);
1405 tvis
.u
.item
.pszText
= (LPWSTR
)localizedName
;
1408 tvis
.u
.item
.pszText
= (LPWSTR
)pvSystemStore
;
1409 /* FIXME: need a folder icon for the store too */
1411 SendMessageW(tree
, TVM_INSERTITEMW
, 0, (LPARAM
)&tvis
);
1415 static void enumerate_stores(HWND hwnd
, CRYPTUI_ENUM_DATA
*pEnumData
)
1418 HWND tree
= GetDlgItem(hwnd
, IDC_STORE_LIST
);
1420 for (i
= 0; i
< pEnumData
->cEnumArgs
; i
++)
1421 CertEnumSystemStore(pEnumData
->rgEnumArgs
[i
].dwFlags
,
1422 pEnumData
->rgEnumArgs
[i
].pvSystemStoreLocationPara
,
1423 hwnd
, enum_store_callback
);
1424 for (i
= 0; i
< pEnumData
->cStores
; i
++)
1428 if (CertGetStoreProperty(pEnumData
->rghStore
[i
],
1429 CERT_STORE_LOCALIZED_NAME_PROP_ID
, NULL
, &size
))
1431 LPWSTR name
= HeapAlloc(GetProcessHeap(), 0, size
);
1435 if (CertGetStoreProperty(pEnumData
->rghStore
[i
],
1436 CERT_STORE_LOCALIZED_NAME_PROP_ID
, name
, &size
))
1438 struct StoreInfo
*storeInfo
= HeapAlloc(GetProcessHeap(),
1439 0, sizeof(struct StoreInfo
));
1443 TVINSERTSTRUCTW tvis
;
1445 storeInfo
->type
= StoreHandle
;
1446 storeInfo
->u
.store
= pEnumData
->rghStore
[i
];
1447 tvis
.hParent
= NULL
;
1448 tvis
.hInsertAfter
= TVI_LAST
;
1449 tvis
.u
.item
.mask
= TVIF_TEXT
| TVIF_PARAM
;
1450 tvis
.u
.item
.pszText
= name
;
1451 tvis
.u
.item
.lParam
= (LPARAM
)storeInfo
;
1452 SendMessageW(tree
, TVM_INSERTITEMW
, 0, (LPARAM
)&tvis
);
1455 HeapFree(GetProcessHeap(), 0, name
);
1461 static void free_store_info(HWND tree
)
1463 HTREEITEM next
= (HTREEITEM
)SendMessageW(tree
, TVM_GETNEXTITEM
, TVGN_CHILD
,
1470 memset(&item
, 0, sizeof(item
));
1471 item
.mask
= TVIF_HANDLE
| TVIF_PARAM
;
1473 SendMessageW(tree
, TVM_GETITEMW
, 0, (LPARAM
)&item
);
1476 struct StoreInfo
*storeInfo
= (struct StoreInfo
*)item
.lParam
;
1478 if (storeInfo
->type
== SystemStore
)
1479 HeapFree(GetProcessHeap(), 0, storeInfo
->u
.name
);
1480 HeapFree(GetProcessHeap(), 0, storeInfo
);
1482 next
= (HTREEITEM
)SendMessageW(tree
, TVM_GETNEXTITEM
, TVGN_NEXT
,
1487 static HCERTSTORE
selected_item_to_store(HWND tree
, HTREEITEM hItem
)
1489 WCHAR buf
[MAX_STRING_LEN
];
1493 memset(&item
, 0, sizeof(item
));
1494 item
.mask
= TVIF_HANDLE
| TVIF_PARAM
| TVIF_TEXT
;
1496 item
.cchTextMax
= ARRAY_SIZE(buf
);
1498 SendMessageW(tree
, TVM_GETITEMW
, 0, (LPARAM
)&item
);
1501 struct StoreInfo
*storeInfo
= (struct StoreInfo
*)item
.lParam
;
1503 if (storeInfo
->type
== StoreHandle
)
1504 store
= storeInfo
->u
.store
;
1506 store
= CertOpenSystemStoreW(0, storeInfo
->u
.name
);
1510 /* It's implicitly a system store */
1511 store
= CertOpenSystemStoreW(0, buf
);
1516 struct SelectStoreInfo
1518 PCRYPTUI_SELECTSTORE_INFO_W info
;
1522 static LRESULT CALLBACK
select_store_dlg_proc(HWND hwnd
, UINT msg
, WPARAM wp
,
1525 struct SelectStoreInfo
*selectInfo
;
1532 selectInfo
= (struct SelectStoreInfo
*)lp
;
1533 SetWindowLongPtrW(hwnd
, DWLP_USER
, lp
);
1534 if (selectInfo
->info
->pwszTitle
)
1535 SendMessageW(hwnd
, WM_SETTEXT
, 0,
1536 (LPARAM
)selectInfo
->info
->pwszTitle
);
1537 if (selectInfo
->info
->pwszText
)
1538 SendMessageW(GetDlgItem(hwnd
, IDC_STORE_TEXT
), WM_SETTEXT
, 0,
1539 (LPARAM
)selectInfo
->info
->pwszText
);
1540 if (!(selectInfo
->info
->dwFlags
& CRYPTUI_ENABLE_SHOW_PHYSICAL_STORE
))
1541 ShowWindow(GetDlgItem(hwnd
, IDC_SHOW_PHYSICAL_STORES
), FALSE
);
1542 enumerate_stores(hwnd
, selectInfo
->info
->pEnumData
);
1550 HWND tree
= GetDlgItem(hwnd
, IDC_STORE_LIST
);
1551 HTREEITEM selection
= (HTREEITEM
)SendMessageW(tree
,
1552 TVM_GETNEXTITEM
, TVGN_CARET
, 0);
1554 selectInfo
= (struct SelectStoreInfo
*)GetWindowLongPtrW(hwnd
,
1558 WCHAR title
[MAX_STRING_LEN
], error
[MAX_STRING_LEN
], *pTitle
;
1560 if (selectInfo
->info
->pwszTitle
)
1561 pTitle
= selectInfo
->info
->pwszTitle
;
1564 LoadStringW(hInstance
, IDS_SELECT_STORE_TITLE
, title
, ARRAY_SIZE(title
));
1567 LoadStringW(hInstance
, IDS_SELECT_STORE
, error
, ARRAY_SIZE(error
));
1568 MessageBoxW(hwnd
, error
, pTitle
, MB_ICONEXCLAMATION
| MB_OK
);
1572 HCERTSTORE store
= selected_item_to_store(tree
, selection
);
1574 if (!selectInfo
->info
->pfnSelectedStoreCallback
||
1575 selectInfo
->info
->pfnSelectedStoreCallback(store
, hwnd
,
1576 selectInfo
->info
->pvArg
))
1578 selectInfo
->store
= store
;
1579 free_store_info(tree
);
1580 EndDialog(hwnd
, IDOK
);
1583 CertCloseStore(store
, 0);
1589 free_store_info(GetDlgItem(hwnd
, IDC_STORE_LIST
));
1590 EndDialog(hwnd
, IDCANCEL
);
1599 /***********************************************************************
1600 * CryptUIDlgSelectStoreW (CRYPTUI.@)
1602 HCERTSTORE WINAPI
CryptUIDlgSelectStoreW(PCRYPTUI_SELECTSTORE_INFO_W info
)
1604 struct SelectStoreInfo selectInfo
= { info
, NULL
};
1606 TRACE("(%p)\n", info
);
1608 if (info
->dwSize
!= sizeof(CRYPTUI_SELECTSTORE_INFO_W
))
1610 WARN("unexpected size %d\n", info
->dwSize
);
1611 SetLastError(E_INVALIDARG
);
1614 DialogBoxParamW(hInstance
, MAKEINTRESOURCEW(IDD_SELECT_STORE
), info
->parent
,
1615 select_store_dlg_proc
, (LPARAM
)&selectInfo
);
1616 return selectInfo
.store
;
1619 /***********************************************************************
1620 * CryptUIDlgSelectStoreA (CRYPTUI.@)
1622 HCERTSTORE WINAPI
CryptUIDlgSelectStoreA(PCRYPTUI_SELECTSTORE_INFO_A info
)
1624 CRYPTUI_SELECTSTORE_INFO_W infoW
;
1628 TRACE("(%p)\n", info
);
1630 if (info
->dwSize
!= sizeof(CRYPTUI_SELECTSTORE_INFO_A
))
1632 WARN("unexpected size %d\n", info
->dwSize
);
1633 SetLastError(E_INVALIDARG
);
1636 memcpy(&infoW
, info
, sizeof(*info
));
1639 len
= MultiByteToWideChar(CP_ACP
, 0, info
->pszTitle
, -1, NULL
, 0);
1640 infoW
.pwszTitle
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1641 MultiByteToWideChar(CP_ACP
, 0, info
->pszTitle
, -1, infoW
.pwszTitle
,
1646 len
= MultiByteToWideChar(CP_ACP
, 0, info
->pszText
, -1, NULL
, 0);
1647 infoW
.pwszText
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1648 MultiByteToWideChar(CP_ACP
, 0, info
->pszText
, -1, infoW
.pwszText
, len
);
1650 ret
= CryptUIDlgSelectStoreW(&infoW
);
1651 HeapFree(GetProcessHeap(), 0, infoW
.pwszText
);
1652 HeapFree(GetProcessHeap(), 0, infoW
.pwszTitle
);
1656 /***********************************************************************
1657 * CryptUIDlgViewCertificateA (CRYPTUI.@)
1659 BOOL WINAPI
CryptUIDlgViewCertificateA(
1660 PCCRYPTUI_VIEWCERTIFICATE_STRUCTA pCertViewInfo
, BOOL
*pfPropertiesChanged
)
1662 CRYPTUI_VIEWCERTIFICATE_STRUCTW viewInfo
;
1663 LPWSTR title
= NULL
;
1666 TRACE("(%p, %p)\n", pCertViewInfo
, pfPropertiesChanged
);
1668 memcpy(&viewInfo
, pCertViewInfo
, sizeof(viewInfo
));
1669 if (pCertViewInfo
->szTitle
)
1671 int len
= MultiByteToWideChar(CP_ACP
, 0, pCertViewInfo
->szTitle
, -1,
1674 title
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1677 MultiByteToWideChar(CP_ACP
, 0, pCertViewInfo
->szTitle
, -1, title
,
1679 viewInfo
.szTitle
= title
;
1687 if (pCertViewInfo
->cPropSheetPages
)
1689 FIXME("ignoring additional prop sheet pages\n");
1690 viewInfo
.cPropSheetPages
= 0;
1692 ret
= CryptUIDlgViewCertificateW(&viewInfo
, pfPropertiesChanged
);
1693 HeapFree(GetProcessHeap(), 0, title
);
1698 struct ReadStringStruct
1705 static DWORD CALLBACK
read_text_callback(DWORD_PTR dwCookie
, LPBYTE buf
,
1708 struct ReadStringStruct
*string
= (struct ReadStringStruct
*)dwCookie
;
1709 LONG cch
= min(cb
/ sizeof(WCHAR
), string
->len
- string
->pos
);
1711 TRACE("(%p, %p, %d, %p)\n", string
, buf
, cb
, pcb
);
1713 memmove(buf
, string
->buf
+ string
->pos
, cch
* sizeof(WCHAR
));
1715 *pcb
= cch
* sizeof(WCHAR
);
1719 static void add_unformatted_text_to_control(HWND hwnd
, LPCWSTR text
, LONG len
)
1721 struct ReadStringStruct string
;
1722 EDITSTREAM editstream
;
1724 TRACE("(%p, %s)\n", hwnd
, debugstr_wn(text
, len
));
1729 editstream
.dwCookie
= (DWORD_PTR
)&string
;
1730 editstream
.dwError
= 0;
1731 editstream
.pfnCallback
= read_text_callback
;
1732 SendMessageW(hwnd
, EM_STREAMIN
, SF_TEXT
| SFF_SELECTION
| SF_UNICODE
,
1733 (LPARAM
)&editstream
);
1736 static void add_string_resource_to_control(HWND hwnd
, int id
)
1741 len
= LoadStringW(hInstance
, id
, (LPWSTR
)&str
, 0);
1742 add_unformatted_text_to_control(hwnd
, str
, len
);
1745 static void add_text_with_paraformat_to_control(HWND hwnd
, LPCWSTR text
,
1746 LONG len
, const PARAFORMAT2
*fmt
)
1748 add_unformatted_text_to_control(hwnd
, text
, len
);
1749 SendMessageW(hwnd
, EM_SETPARAFORMAT
, 0, (LPARAM
)fmt
);
1752 static void add_string_resource_with_paraformat_to_control(HWND hwnd
, int id
,
1753 const PARAFORMAT2
*fmt
)
1758 len
= LoadStringW(hInstance
, id
, (LPWSTR
)&str
, 0);
1759 add_text_with_paraformat_to_control(hwnd
, str
, len
, fmt
);
1762 static LPWSTR
get_cert_name_string(PCCERT_CONTEXT pCertContext
, DWORD dwType
,
1768 len
= CertGetNameStringW(pCertContext
, dwType
, dwFlags
, NULL
, NULL
, 0);
1771 buf
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1773 CertGetNameStringW(pCertContext
, dwType
, dwFlags
, NULL
, buf
, len
);
1778 static void add_cert_string_to_control(HWND hwnd
, PCCERT_CONTEXT pCertContext
,
1779 DWORD dwType
, DWORD dwFlags
)
1781 LPWSTR name
= get_cert_name_string(pCertContext
, dwType
, dwFlags
);
1785 /* Don't include NULL-terminator in output */
1786 DWORD len
= lstrlenW(name
);
1788 add_unformatted_text_to_control(hwnd
, name
, len
);
1789 HeapFree(GetProcessHeap(), 0, name
);
1793 static void add_icon_to_control(HWND hwnd
, int id
)
1796 IRichEditOle
*richEditOle
= NULL
;
1797 IOleObject
*object
= NULL
;
1799 LPOLECACHE oleCache
= NULL
;
1800 FORMATETC formatEtc
;
1802 IDataObject
*dataObject
= NULL
;
1803 HBITMAP bitmap
= NULL
;
1805 IOleClientSite
*clientSite
= NULL
;
1808 TRACE("(%p, %d)\n", hwnd
, id
);
1810 SendMessageW(hwnd
, EM_GETOLEINTERFACE
, 0, (LPARAM
)&richEditOle
);
1813 hr
= OleCreateDefaultHandler(&CLSID_NULL
, NULL
, &IID_IOleObject
,
1817 hr
= IOleObject_GetUserClassID(object
, &clsid
);
1820 hr
= IOleObject_QueryInterface(object
, &IID_IOleCache
, (void**)&oleCache
);
1823 formatEtc
.cfFormat
= CF_BITMAP
;
1824 formatEtc
.ptd
= NULL
;
1825 formatEtc
.dwAspect
= DVASPECT_CONTENT
;
1826 formatEtc
.lindex
= -1;
1827 formatEtc
.tymed
= TYMED_GDI
;
1828 hr
= IOleCache_Cache(oleCache
, &formatEtc
, 0, &conn
);
1831 hr
= IOleObject_QueryInterface(object
, &IID_IDataObject
,
1832 (void**)&dataObject
);
1835 hr
= IRichEditOle_GetClientSite(richEditOle
, &clientSite
);
1838 bitmap
= LoadImageW(hInstance
, MAKEINTRESOURCEW(id
), IMAGE_BITMAP
, 0, 0,
1839 LR_DEFAULTSIZE
| LR_LOADTRANSPARENT
);
1842 stgm
.tymed
= TYMED_GDI
;
1843 stgm
.u
.hBitmap
= bitmap
;
1844 stgm
.pUnkForRelease
= NULL
;
1845 hr
= IDataObject_SetData(dataObject
, &formatEtc
, &stgm
, TRUE
);
1849 reObject
.cbStruct
= sizeof(reObject
);
1850 reObject
.cp
= REO_CP_SELECTION
;
1851 reObject
.clsid
= clsid
;
1852 reObject
.poleobj
= object
;
1853 reObject
.pstg
= NULL
;
1854 reObject
.polesite
= clientSite
;
1855 reObject
.sizel
.cx
= reObject
.sizel
.cy
= 0;
1856 reObject
.dvaspect
= DVASPECT_CONTENT
;
1857 reObject
.dwFlags
= 0;
1858 reObject
.dwUser
= 0;
1860 IRichEditOle_InsertObject(richEditOle
, &reObject
);
1864 IOleClientSite_Release(clientSite
);
1866 IDataObject_Release(dataObject
);
1868 IOleCache_Release(oleCache
);
1870 IOleObject_Release(object
);
1872 IRichEditOle_Release(richEditOle
);
1875 #define MY_INDENT 200
1877 static void add_oid_text_to_control(HWND hwnd
, char *oid
)
1880 PCCRYPT_OID_INFO oidInfo
= CryptFindOIDInfo(CRYPT_OID_INFO_OID_KEY
, oid
, 0);
1883 parFmt
.cbSize
= sizeof(parFmt
);
1884 parFmt
.dwMask
= PFM_STARTINDENT
;
1885 parFmt
.dxStartIndent
= MY_INDENT
* 3;
1888 add_text_with_paraformat_to_control(hwnd
, oidInfo
->pwszName
,
1889 lstrlenW(oidInfo
->pwszName
), &parFmt
);
1890 add_unformatted_text_to_control(hwnd
, &nl
, 1);
1900 /* The following list MUST be lexicographically sorted by OID */
1901 static struct OIDToString oidMap
[] = {
1902 /* 1.3.6.1.4.1.311.10.3.1 */
1903 { szOID_KP_CTL_USAGE_SIGNING
, IDS_PURPOSE_CTL_USAGE_SIGNING
},
1904 /* 1.3.6.1.4.1.311.10.3.4 */
1905 { szOID_KP_EFS
, IDS_PURPOSE_EFS
},
1906 /* 1.3.6.1.4.1.311.10.3.4.1 */
1907 { szOID_EFS_RECOVERY
, IDS_PURPOSE_EFS_RECOVERY
},
1908 /* 1.3.6.1.4.1.311.10.3.5 */
1909 { szOID_WHQL_CRYPTO
, IDS_PURPOSE_WHQL
},
1910 /* 1.3.6.1.4.1.311.10.3.6 */
1911 { szOID_NT5_CRYPTO
, IDS_PURPOSE_NT5
},
1912 /* 1.3.6.1.4.1.311.10.3.7 */
1913 { szOID_OEM_WHQL_CRYPTO
, IDS_PURPOSE_OEM_WHQL
},
1914 /* 1.3.6.1.4.1.311.10.3.8 */
1915 { szOID_EMBEDDED_NT_CRYPTO
, IDS_PURPOSE_EMBEDDED_NT
},
1916 /* 1.3.6.1.4.1.311.10.3.9 */
1917 { szOID_ROOT_LIST_SIGNER
, IDS_PURPOSE_ROOT_LIST_SIGNER
},
1918 /* 1.3.6.1.4.1.311.10.3.10 */
1919 { szOID_KP_QUALIFIED_SUBORDINATION
, IDS_PURPOSE_QUALIFIED_SUBORDINATION
},
1920 /* 1.3.6.1.4.1.311.10.3.11 */
1921 { szOID_KP_KEY_RECOVERY
, IDS_PURPOSE_KEY_RECOVERY
},
1922 /* 1.3.6.1.4.1.311.10.3.12 */
1923 { szOID_KP_DOCUMENT_SIGNING
, IDS_PURPOSE_DOCUMENT_SIGNING
},
1924 /* 1.3.6.1.4.1.311.10.3.13 */
1925 { szOID_KP_LIFETIME_SIGNING
, IDS_PURPOSE_LIFETIME_SIGNING
},
1926 /* 1.3.6.1.4.1.311.10.5.1 */
1927 { szOID_DRM
, IDS_PURPOSE_DRM
},
1928 /* 1.3.6.1.4.1.311.10.6.1 */
1929 { szOID_LICENSES
, IDS_PURPOSE_LICENSES
},
1930 /* 1.3.6.1.4.1.311.10.6.2 */
1931 { szOID_LICENSE_SERVER
, IDS_PURPOSE_LICENSE_SERVER
},
1932 /* 1.3.6.1.4.1.311.20.2.1 */
1933 { szOID_ENROLLMENT_AGENT
, IDS_PURPOSE_ENROLLMENT_AGENT
},
1934 /* 1.3.6.1.4.1.311.20.2.2 */
1935 { szOID_KP_SMARTCARD_LOGON
, IDS_PURPOSE_SMARTCARD_LOGON
},
1936 /* 1.3.6.1.4.1.311.21.5 */
1937 { szOID_KP_CA_EXCHANGE
, IDS_PURPOSE_CA_EXCHANGE
},
1938 /* 1.3.6.1.4.1.311.21.6 */
1939 { szOID_KP_KEY_RECOVERY_AGENT
, IDS_PURPOSE_KEY_RECOVERY_AGENT
},
1940 /* 1.3.6.1.4.1.311.21.19 */
1941 { szOID_DS_EMAIL_REPLICATION
, IDS_PURPOSE_DS_EMAIL_REPLICATION
},
1942 /* 1.3.6.1.5.5.7.3.1 */
1943 { szOID_PKIX_KP_SERVER_AUTH
, IDS_PURPOSE_SERVER_AUTH
},
1944 /* 1.3.6.1.5.5.7.3.2 */
1945 { szOID_PKIX_KP_CLIENT_AUTH
, IDS_PURPOSE_CLIENT_AUTH
},
1946 /* 1.3.6.1.5.5.7.3.3 */
1947 { szOID_PKIX_KP_CODE_SIGNING
, IDS_PURPOSE_CODE_SIGNING
},
1948 /* 1.3.6.1.5.5.7.3.4 */
1949 { szOID_PKIX_KP_EMAIL_PROTECTION
, IDS_PURPOSE_EMAIL_PROTECTION
},
1950 /* 1.3.6.1.5.5.7.3.5 */
1951 { szOID_PKIX_KP_IPSEC_END_SYSTEM
, IDS_PURPOSE_IPSEC
},
1952 /* 1.3.6.1.5.5.7.3.6 */
1953 { szOID_PKIX_KP_IPSEC_TUNNEL
, IDS_PURPOSE_IPSEC
},
1954 /* 1.3.6.1.5.5.7.3.7 */
1955 { szOID_PKIX_KP_IPSEC_USER
, IDS_PURPOSE_IPSEC
},
1956 /* 1.3.6.1.5.5.7.3.8 */
1957 { szOID_PKIX_KP_TIMESTAMP_SIGNING
, IDS_PURPOSE_TIMESTAMP_SIGNING
},
1960 static struct OIDToString
*findSupportedOID(LPCSTR oid
)
1962 int indexHigh
= ARRAY_SIZE(oidMap
) - 1, indexLow
= 0;
1964 while (indexLow
<= indexHigh
)
1966 int cmp
, i
= (indexLow
+ indexHigh
) / 2;
1967 if (!(cmp
= strcmp(oid
, oidMap
[i
].oid
)))
1977 static void add_local_oid_text_to_control(HWND text
, LPCSTR oid
)
1979 struct OIDToString
*entry
;
1983 parFmt
.cbSize
= sizeof(parFmt
);
1984 parFmt
.dwMask
= PFM_STARTINDENT
;
1985 parFmt
.dxStartIndent
= MY_INDENT
* 3;
1986 if ((entry
= findSupportedOID(oid
)))
1988 WCHAR
*str
, *linebreak
, *ptr
;
1989 BOOL multiline
= FALSE
;
1992 len
= LoadStringW(hInstance
, entry
->id
, (LPWSTR
)&str
, 0);
1995 if ((linebreak
= wmemchr(ptr
, '\n', len
)))
1997 WCHAR copy
[MAX_STRING_LEN
];
2000 /* The source string contains a newline, which the richedit
2001 * control won't find since it's interpreted as a paragraph
2002 * break. Therefore copy up to the newline. lstrcpynW always
2003 * NULL-terminates, so pass one more than the length of the
2004 * source line so the copy includes the entire line and the
2007 lstrcpynW(copy
, ptr
, linebreak
- ptr
+ 1);
2008 add_text_with_paraformat_to_control(text
, copy
,
2009 linebreak
- ptr
, &parFmt
);
2010 ptr
= linebreak
+ 1;
2011 add_unformatted_text_to_control(text
, &nl
, 1);
2013 else if (multiline
&& *ptr
)
2015 /* Add the last line */
2016 add_text_with_paraformat_to_control(text
, ptr
,
2017 len
- (ptr
- str
), &parFmt
);
2018 add_unformatted_text_to_control(text
, &nl
, 1);
2020 } while (linebreak
);
2023 add_text_with_paraformat_to_control(text
, str
, len
, &parFmt
);
2024 add_unformatted_text_to_control(text
, &nl
, 1);
2029 WCHAR
*oidW
= HeapAlloc(GetProcessHeap(), 0,
2030 (strlen(oid
) + 1) * sizeof(WCHAR
));
2037 for (src
= oid
, dst
= oidW
; *src
; src
++, dst
++)
2040 add_text_with_paraformat_to_control(text
, oidW
, lstrlenW(oidW
),
2042 add_unformatted_text_to_control(text
, &nl
, 1);
2043 HeapFree(GetProcessHeap(), 0, oidW
);
2048 static void display_app_usages(HWND text
, PCCERT_CONTEXT cert
,
2049 BOOL
*anyUsageAdded
)
2051 static char any_app_policy
[] = szOID_ANY_APPLICATION_POLICY
;
2053 CHARFORMATW charFmt
;
2054 PCERT_EXTENSION policyExt
;
2055 if (!*anyUsageAdded
)
2059 parFmt
.cbSize
= sizeof(parFmt
);
2060 parFmt
.dwMask
= PFM_STARTINDENT
;
2061 parFmt
.dxStartIndent
= MY_INDENT
;
2062 add_string_resource_with_paraformat_to_control(text
,
2063 IDS_CERT_INFO_PURPOSES
, &parFmt
);
2064 add_unformatted_text_to_control(text
, &nl
, 1);
2065 *anyUsageAdded
= TRUE
;
2067 memset(&charFmt
, 0, sizeof(charFmt
));
2068 charFmt
.cbSize
= sizeof(charFmt
);
2069 charFmt
.dwMask
= CFM_BOLD
;
2070 charFmt
.dwEffects
= 0;
2071 SendMessageW(text
, EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&charFmt
);
2072 if ((policyExt
= CertFindExtension(szOID_APPLICATION_CERT_POLICIES
,
2073 cert
->pCertInfo
->cExtension
, cert
->pCertInfo
->rgExtension
)))
2075 CERT_POLICIES_INFO
*policies
;
2078 if (CryptDecodeObjectEx(X509_ASN_ENCODING
, X509_CERT_POLICIES
,
2079 policyExt
->Value
.pbData
, policyExt
->Value
.cbData
,
2080 CRYPT_DECODE_ALLOC_FLAG
, NULL
, &policies
, &size
))
2084 for (i
= 0; i
< policies
->cPolicyInfo
; i
++)
2088 for (j
= 0; j
< policies
->rgPolicyInfo
[i
].cPolicyQualifier
; j
++)
2089 add_local_oid_text_to_control(text
,
2090 policies
->rgPolicyInfo
[i
].rgPolicyQualifier
[j
].
2091 pszPolicyQualifierId
);
2093 LocalFree(policies
);
2097 add_oid_text_to_control(text
, any_app_policy
);
2100 static BOOL
display_cert_usages(HWND text
, PCCERT_CONTEXT cert
,
2101 BOOL
*anyUsageAdded
)
2105 BOOL badUsages
= FALSE
;
2107 if (CertGetEnhancedKeyUsage(cert
, 0, NULL
, &size
))
2109 CHARFORMATW charFmt
;
2110 static char any_cert_policy
[] = szOID_ANY_CERT_POLICY
;
2111 PCERT_ENHKEY_USAGE usage
= HeapAlloc(GetProcessHeap(), 0, size
);
2115 if (CertGetEnhancedKeyUsage(cert
, 0, usage
, &size
))
2119 if (!*anyUsageAdded
)
2123 parFmt
.cbSize
= sizeof(parFmt
);
2124 parFmt
.dwMask
= PFM_STARTINDENT
;
2125 parFmt
.dxStartIndent
= MY_INDENT
;
2126 add_string_resource_with_paraformat_to_control(text
,
2127 IDS_CERT_INFO_PURPOSES
, &parFmt
);
2128 add_unformatted_text_to_control(text
, &nl
, 1);
2129 *anyUsageAdded
= TRUE
;
2131 memset(&charFmt
, 0, sizeof(charFmt
));
2132 charFmt
.cbSize
= sizeof(charFmt
);
2133 charFmt
.dwMask
= CFM_BOLD
;
2134 charFmt
.dwEffects
= 0;
2135 SendMessageW(text
, EM_SETCHARFORMAT
, SCF_SELECTION
,
2137 if (!usage
->cUsageIdentifier
)
2138 add_oid_text_to_control(text
, any_cert_policy
);
2140 for (i
= 0; i
< usage
->cUsageIdentifier
; i
++)
2141 add_local_oid_text_to_control(text
,
2142 usage
->rgpszUsageIdentifier
[i
]);
2146 HeapFree(GetProcessHeap(), 0, usage
);
2156 static void set_policy_text(HWND text
,
2157 PCCRYPTUI_VIEWCERTIFICATE_STRUCTW pCertViewInfo
)
2159 BOOL includeCertUsages
= FALSE
, includeAppUsages
= FALSE
;
2160 BOOL badUsages
= FALSE
, anyUsageAdded
= FALSE
;
2162 if (pCertViewInfo
->cPurposes
)
2166 for (i
= 0; i
< pCertViewInfo
->cPurposes
; i
++)
2168 if (!strcmp(pCertViewInfo
->rgszPurposes
[i
], szOID_ANY_CERT_POLICY
))
2169 includeCertUsages
= TRUE
;
2170 else if (!strcmp(pCertViewInfo
->rgszPurposes
[i
],
2171 szOID_ANY_APPLICATION_POLICY
))
2172 includeAppUsages
= TRUE
;
2178 includeAppUsages
= includeCertUsages
= TRUE
;
2179 if (includeAppUsages
)
2180 display_app_usages(text
, pCertViewInfo
->pCertContext
, &anyUsageAdded
);
2181 if (includeCertUsages
)
2182 badUsages
= display_cert_usages(text
, pCertViewInfo
->pCertContext
,
2188 parFmt
.cbSize
= sizeof(parFmt
);
2189 parFmt
.dwMask
= PFM_STARTINDENT
;
2190 parFmt
.dxStartIndent
= MY_INDENT
;
2191 add_string_resource_with_paraformat_to_control(text
,
2192 IDS_CERT_INFO_BAD_PURPOSES
, &parFmt
);
2196 static CRYPT_OBJID_BLOB
*find_policy_qualifier(CERT_POLICIES_INFO
*policies
,
2199 CRYPT_OBJID_BLOB
*ret
= NULL
;
2202 for (i
= 0; !ret
&& i
< policies
->cPolicyInfo
; i
++)
2206 for (j
= 0; !ret
&& j
< policies
->rgPolicyInfo
[i
].cPolicyQualifier
; j
++)
2207 if (!strcmp(policies
->rgPolicyInfo
[i
].rgPolicyQualifier
[j
].
2208 pszPolicyQualifierId
, policyOid
))
2209 ret
= &policies
->rgPolicyInfo
[i
].rgPolicyQualifier
[j
].
2215 static WCHAR
*get_cps_str_from_qualifier(const CRYPT_OBJID_BLOB
*qualifier
)
2217 LPWSTR qualifierStr
= NULL
;
2218 CERT_NAME_VALUE
*qualifierValue
;
2221 if (CryptDecodeObjectEx(X509_ASN_ENCODING
, X509_NAME_VALUE
,
2222 qualifier
->pbData
, qualifier
->cbData
, CRYPT_DECODE_ALLOC_FLAG
, NULL
,
2223 &qualifierValue
, &size
))
2225 size
= CertRDNValueToStrW(qualifierValue
->dwValueType
,
2226 &qualifierValue
->Value
, NULL
, 0);
2227 qualifierStr
= HeapAlloc(GetProcessHeap(), 0, size
* sizeof(WCHAR
));
2229 CertRDNValueToStrW(qualifierValue
->dwValueType
,
2230 &qualifierValue
->Value
, qualifierStr
, size
);
2231 LocalFree(qualifierValue
);
2233 return qualifierStr
;
2236 static WCHAR
*get_user_notice_from_qualifier(const CRYPT_OBJID_BLOB
*qualifier
)
2239 CERT_POLICY_QUALIFIER_USER_NOTICE
*qualifierValue
;
2242 if (CryptDecodeObjectEx(X509_ASN_ENCODING
,
2243 X509_PKIX_POLICY_QUALIFIER_USERNOTICE
,
2244 qualifier
->pbData
, qualifier
->cbData
, CRYPT_DECODE_ALLOC_FLAG
, NULL
,
2245 &qualifierValue
, &size
))
2247 str
= HeapAlloc(GetProcessHeap(), 0,
2248 (lstrlenW(qualifierValue
->pszDisplayText
) + 1) * sizeof(WCHAR
));
2250 lstrcpyW(str
, qualifierValue
->pszDisplayText
);
2251 LocalFree(qualifierValue
);
2256 struct IssuerStatement
2262 static void set_issuer_statement(HWND hwnd
,
2263 PCCRYPTUI_VIEWCERTIFICATE_STRUCTW pCertViewInfo
)
2265 PCERT_EXTENSION policyExt
;
2267 if (!(pCertViewInfo
->dwFlags
& CRYPTUI_DISABLE_ISSUERSTATEMENT
) &&
2268 (policyExt
= CertFindExtension(szOID_CERT_POLICIES
,
2269 pCertViewInfo
->pCertContext
->pCertInfo
->cExtension
,
2270 pCertViewInfo
->pCertContext
->pCertInfo
->rgExtension
)))
2272 CERT_POLICIES_INFO
*policies
;
2275 if (CryptDecodeObjectEx(X509_ASN_ENCODING
, policyExt
->pszObjId
,
2276 policyExt
->Value
.pbData
, policyExt
->Value
.cbData
,
2277 CRYPT_DECODE_ALLOC_FLAG
, NULL
, &policies
, &size
))
2279 CRYPT_OBJID_BLOB
*qualifier
;
2280 LPWSTR cps
= NULL
, userNotice
= NULL
;
2282 if ((qualifier
= find_policy_qualifier(policies
,
2283 szOID_PKIX_POLICY_QUALIFIER_CPS
)))
2284 cps
= get_cps_str_from_qualifier(qualifier
);
2285 if ((qualifier
= find_policy_qualifier(policies
,
2286 szOID_PKIX_POLICY_QUALIFIER_USERNOTICE
)))
2287 userNotice
= get_user_notice_from_qualifier(qualifier
);
2288 if (cps
|| userNotice
)
2290 struct IssuerStatement
*issuerStatement
=
2291 HeapAlloc(GetProcessHeap(), 0, sizeof(struct IssuerStatement
));
2293 if (issuerStatement
)
2295 issuerStatement
->cps
= cps
;
2296 issuerStatement
->userNotice
= userNotice
;
2297 EnableWindow(GetDlgItem(hwnd
, IDC_ISSUERSTATEMENT
), TRUE
);
2298 SetWindowLongPtrW(hwnd
, DWLP_USER
,
2299 (ULONG_PTR
)issuerStatement
);
2302 LocalFree(policies
);
2307 static void set_cert_info(HWND hwnd
,
2308 PCCRYPTUI_VIEWCERTIFICATE_STRUCTW pCertViewInfo
)
2310 CHARFORMATW charFmt
;
2312 HWND icon
= GetDlgItem(hwnd
, IDC_CERTIFICATE_ICON
);
2313 HWND text
= GetDlgItem(hwnd
, IDC_CERTIFICATE_INFO
);
2314 CRYPT_PROVIDER_SGNR
*provSigner
= WTHelperGetProvSignerFromChain(
2315 (CRYPT_PROVIDER_DATA
*)pCertViewInfo
->u
.pCryptProviderData
,
2316 pCertViewInfo
->idxSigner
, pCertViewInfo
->fCounterSigner
,
2317 pCertViewInfo
->idxCounterSigner
);
2318 CRYPT_PROVIDER_CERT
*root
=
2319 &provSigner
->pasCertChain
[provSigner
->csCertChain
- 1];
2321 if (!provSigner
->pChainContext
||
2322 (provSigner
->pChainContext
->TrustStatus
.dwErrorStatus
&
2323 CERT_TRUST_IS_PARTIAL_CHAIN
))
2324 add_icon_to_control(icon
, IDB_CERT_WARNING
);
2325 else if (!root
->fTrustedRoot
)
2326 add_icon_to_control(icon
, IDB_CERT_ERROR
);
2328 add_icon_to_control(icon
, IDB_CERT
);
2330 memset(&charFmt
, 0, sizeof(charFmt
));
2331 charFmt
.cbSize
= sizeof(charFmt
);
2332 charFmt
.dwMask
= CFM_BOLD
;
2333 charFmt
.dwEffects
= CFE_BOLD
;
2334 SendMessageW(text
, EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&charFmt
);
2335 /* FIXME: vertically center text */
2336 parFmt
.cbSize
= sizeof(parFmt
);
2337 parFmt
.dwMask
= PFM_STARTINDENT
;
2338 parFmt
.dxStartIndent
= MY_INDENT
;
2339 add_string_resource_with_paraformat_to_control(text
,
2340 IDS_CERTIFICATEINFORMATION
, &parFmt
);
2342 text
= GetDlgItem(hwnd
, IDC_CERTIFICATE_STATUS
);
2343 SendMessageW(text
, EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&charFmt
);
2344 if (provSigner
->dwError
== TRUST_E_CERT_SIGNATURE
)
2345 add_string_resource_with_paraformat_to_control(text
,
2346 IDS_CERT_INFO_BAD_SIG
, &parFmt
);
2347 else if (!provSigner
->pChainContext
||
2348 (provSigner
->pChainContext
->TrustStatus
.dwErrorStatus
&
2349 CERT_TRUST_IS_PARTIAL_CHAIN
))
2350 add_string_resource_with_paraformat_to_control(text
,
2351 IDS_CERT_INFO_PARTIAL_CHAIN
, &parFmt
);
2352 else if (!root
->fTrustedRoot
)
2354 if (provSigner
->csCertChain
== 1 && root
->fSelfSigned
)
2355 add_string_resource_with_paraformat_to_control(text
,
2356 IDS_CERT_INFO_UNTRUSTED_CA
, &parFmt
);
2358 add_string_resource_with_paraformat_to_control(text
,
2359 IDS_CERT_INFO_UNTRUSTED_ROOT
, &parFmt
);
2363 set_policy_text(text
, pCertViewInfo
);
2364 set_issuer_statement(hwnd
, pCertViewInfo
);
2368 static void set_cert_name_string(HWND hwnd
, PCCERT_CONTEXT cert
,
2369 DWORD nameFlags
, int heading
)
2372 HWND text
= GetDlgItem(hwnd
, IDC_CERTIFICATE_NAMES
);
2373 CHARFORMATW charFmt
;
2376 memset(&charFmt
, 0, sizeof(charFmt
));
2377 charFmt
.cbSize
= sizeof(charFmt
);
2378 charFmt
.dwMask
= CFM_BOLD
;
2379 charFmt
.dwEffects
= CFE_BOLD
;
2380 SendMessageW(text
, EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&charFmt
);
2381 parFmt
.cbSize
= sizeof(parFmt
);
2382 parFmt
.dwMask
= PFM_STARTINDENT
;
2383 parFmt
.dxStartIndent
= MY_INDENT
* 3;
2384 add_string_resource_with_paraformat_to_control(text
, heading
, &parFmt
);
2385 charFmt
.dwEffects
= 0;
2386 SendMessageW(text
, EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&charFmt
);
2387 add_cert_string_to_control(text
, cert
, CERT_NAME_SIMPLE_DISPLAY_TYPE
,
2389 add_unformatted_text_to_control(text
, &nl
, 1);
2390 add_unformatted_text_to_control(text
, &nl
, 1);
2391 add_unformatted_text_to_control(text
, &nl
, 1);
2395 static void add_date_string_to_control(HWND hwnd
, const FILETIME
*fileTime
)
2397 WCHAR dateFmt
[80]; /* sufficient for all versions of LOCALE_SSHORTDATE */
2401 GetLocaleInfoW(LOCALE_SYSTEM_DEFAULT
, LOCALE_SSHORTDATE
, dateFmt
, ARRAY_SIZE(dateFmt
));
2402 FileTimeToSystemTime(fileTime
, &sysTime
);
2403 GetDateFormatW(LOCALE_SYSTEM_DEFAULT
, 0, &sysTime
, dateFmt
, date
, ARRAY_SIZE(date
));
2404 add_unformatted_text_to_control(hwnd
, date
, lstrlenW(date
));
2407 static void set_cert_validity_period(HWND hwnd
, PCCERT_CONTEXT cert
)
2410 HWND text
= GetDlgItem(hwnd
, IDC_CERTIFICATE_NAMES
);
2411 CHARFORMATW charFmt
;
2414 memset(&charFmt
, 0, sizeof(charFmt
));
2415 charFmt
.cbSize
= sizeof(charFmt
);
2416 charFmt
.dwMask
= CFM_BOLD
;
2417 charFmt
.dwEffects
= CFE_BOLD
;
2418 SendMessageW(text
, EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&charFmt
);
2419 parFmt
.cbSize
= sizeof(parFmt
);
2420 parFmt
.dwMask
= PFM_STARTINDENT
;
2421 parFmt
.dxStartIndent
= MY_INDENT
* 3;
2422 add_string_resource_with_paraformat_to_control(text
, IDS_VALID_FROM
,
2424 charFmt
.dwEffects
= 0;
2425 SendMessageW(text
, EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&charFmt
);
2426 add_date_string_to_control(text
, &cert
->pCertInfo
->NotBefore
);
2427 charFmt
.dwEffects
= CFE_BOLD
;
2428 SendMessageW(text
, EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&charFmt
);
2429 add_string_resource_to_control(text
, IDS_VALID_TO
);
2430 charFmt
.dwEffects
= 0;
2431 SendMessageW(text
, EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&charFmt
);
2432 add_date_string_to_control(text
, &cert
->pCertInfo
->NotAfter
);
2433 add_unformatted_text_to_control(text
, &nl
, 1);
2436 static void set_general_info(HWND hwnd
,
2437 PCCRYPTUI_VIEWCERTIFICATE_STRUCTW pCertViewInfo
)
2439 set_cert_info(hwnd
, pCertViewInfo
);
2440 set_cert_name_string(hwnd
, pCertViewInfo
->pCertContext
, 0,
2441 IDS_SUBJECT_HEADING
);
2442 set_cert_name_string(hwnd
, pCertViewInfo
->pCertContext
,
2443 CERT_NAME_ISSUER_FLAG
, IDS_ISSUER_HEADING
);
2444 set_cert_validity_period(hwnd
, pCertViewInfo
->pCertContext
);
2447 static LRESULT CALLBACK
user_notice_dlg_proc(HWND hwnd
, UINT msg
, WPARAM wp
,
2452 struct IssuerStatement
*issuerStatement
;
2457 text
= GetDlgItem(hwnd
, IDC_USERNOTICE
);
2458 issuerStatement
= (struct IssuerStatement
*)lp
;
2459 add_unformatted_text_to_control(text
, issuerStatement
->userNotice
,
2460 lstrlenW(issuerStatement
->userNotice
));
2461 if (issuerStatement
->cps
)
2462 SetWindowLongPtrW(hwnd
, DWLP_USER
, (LPARAM
)issuerStatement
->cps
);
2464 EnableWindow(GetDlgItem(hwnd
, IDC_CPS
), FALSE
);
2470 EndDialog(hwnd
, IDOK
);
2475 IBindCtx
*bctx
= NULL
;
2478 CreateBindCtx(0, &bctx
);
2479 cps
= (LPWSTR
)GetWindowLongPtrW(hwnd
, DWLP_USER
);
2480 HlinkSimpleNavigateToString(cps
, NULL
, NULL
, NULL
, bctx
, NULL
,
2481 HLNF_OPENINNEWWINDOW
, 0);
2482 IBindCtx_Release(bctx
);
2490 static void show_user_notice(HWND hwnd
, struct IssuerStatement
*issuerStatement
)
2492 DialogBoxParamW(hInstance
, MAKEINTRESOURCEW(IDD_USERNOTICE
), hwnd
,
2493 user_notice_dlg_proc
, (LPARAM
)issuerStatement
);
2496 static LRESULT CALLBACK
general_dlg_proc(HWND hwnd
, UINT msg
, WPARAM wp
,
2499 PROPSHEETPAGEW
*page
;
2500 PCCRYPTUI_VIEWCERTIFICATE_STRUCTW pCertViewInfo
;
2502 TRACE("(%p, %08x, %08lx, %08lx)\n", hwnd
, msg
, wp
, lp
);
2507 page
= (PROPSHEETPAGEW
*)lp
;
2508 pCertViewInfo
= (PCCRYPTUI_VIEWCERTIFICATE_STRUCTW
)page
->lParam
;
2509 if (pCertViewInfo
->dwFlags
& CRYPTUI_DISABLE_ADDTOSTORE
)
2510 ShowWindow(GetDlgItem(hwnd
, IDC_ADDTOSTORE
), FALSE
);
2511 EnableWindow(GetDlgItem(hwnd
, IDC_ISSUERSTATEMENT
), FALSE
);
2512 set_general_info(hwnd
, pCertViewInfo
);
2517 case IDC_ADDTOSTORE
:
2518 CryptUIWizImport(0, hwnd
, NULL
, NULL
, NULL
);
2520 case IDC_ISSUERSTATEMENT
:
2522 struct IssuerStatement
*issuerStatement
=
2523 (struct IssuerStatement
*)GetWindowLongPtrW(hwnd
, DWLP_USER
);
2525 if (issuerStatement
)
2527 if (issuerStatement
->userNotice
)
2528 show_user_notice(hwnd
, issuerStatement
);
2529 else if (issuerStatement
->cps
)
2531 IBindCtx
*bctx
= NULL
;
2533 CreateBindCtx(0, &bctx
);
2534 HlinkSimpleNavigateToString(issuerStatement
->cps
, NULL
,
2535 NULL
, NULL
, bctx
, NULL
, HLNF_OPENINNEWWINDOW
, 0);
2536 IBindCtx_Release(bctx
);
2547 static UINT CALLBACK
general_callback_proc(HWND hwnd
, UINT msg
,
2548 PROPSHEETPAGEW
*page
)
2550 struct IssuerStatement
*issuerStatement
;
2556 (struct IssuerStatement
*)GetWindowLongPtrW(hwnd
, DWLP_USER
);
2557 if (issuerStatement
)
2559 HeapFree(GetProcessHeap(), 0, issuerStatement
->cps
);
2560 HeapFree(GetProcessHeap(), 0, issuerStatement
->userNotice
);
2561 HeapFree(GetProcessHeap(), 0, issuerStatement
);
2568 static void init_general_page(PCCRYPTUI_VIEWCERTIFICATE_STRUCTW pCertViewInfo
,
2569 PROPSHEETPAGEW
*page
)
2571 memset(page
, 0, sizeof(PROPSHEETPAGEW
));
2572 page
->dwSize
= sizeof(PROPSHEETPAGEW
);
2573 page
->dwFlags
= PSP_USECALLBACK
;
2574 page
->pfnCallback
= general_callback_proc
;
2575 page
->hInstance
= hInstance
;
2576 page
->u
.pszTemplate
= MAKEINTRESOURCEW(IDD_GENERAL
);
2577 page
->pfnDlgProc
= general_dlg_proc
;
2578 page
->lParam
= (LPARAM
)pCertViewInfo
;
2581 typedef WCHAR
* (*field_format_func
)(PCCERT_CONTEXT cert
);
2583 static WCHAR
*field_format_version(PCCERT_CONTEXT cert
)
2585 static const WCHAR fmt
[] = { 'V','%','d',0 };
2586 WCHAR
*buf
= HeapAlloc(GetProcessHeap(), 0, 12 * sizeof(WCHAR
));
2589 swprintf(buf
, 12, fmt
, cert
->pCertInfo
->dwVersion
);
2593 static WCHAR
*format_hex_string(void *pb
, DWORD cb
)
2595 WCHAR
*buf
= HeapAlloc(GetProcessHeap(), 0, (cb
* 3 + 1) * sizeof(WCHAR
));
2599 static const WCHAR fmt
[] = { '%','0','2','x',' ',0 };
2603 for (i
= 0, ptr
= buf
; i
< cb
; i
++, ptr
+= 3)
2604 swprintf(ptr
, 4, fmt
, ((BYTE
*)pb
)[i
]);
2609 static WCHAR
*field_format_serial_number(PCCERT_CONTEXT cert
)
2611 return format_hex_string(cert
->pCertInfo
->SerialNumber
.pbData
,
2612 cert
->pCertInfo
->SerialNumber
.cbData
);
2615 static WCHAR
*field_format_issuer(PCCERT_CONTEXT cert
)
2617 return get_cert_name_string(cert
, CERT_NAME_SIMPLE_DISPLAY_TYPE
,
2618 CERT_NAME_ISSUER_FLAG
);
2621 static WCHAR
*field_format_detailed_cert_name(PCERT_NAME_BLOB name
)
2624 DWORD len
= CertNameToStrW(X509_ASN_ENCODING
, name
,
2625 CERT_X500_NAME_STR
| CERT_NAME_STR_CRLF_FLAG
, NULL
, 0);
2629 str
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
2631 CertNameToStrW(X509_ASN_ENCODING
, name
,
2632 CERT_X500_NAME_STR
| CERT_NAME_STR_CRLF_FLAG
, str
, len
);
2637 static WCHAR
*field_format_detailed_issuer(PCCERT_CONTEXT cert
, void *param
)
2639 return field_format_detailed_cert_name(&cert
->pCertInfo
->Issuer
);
2642 static WCHAR
*field_format_subject(PCCERT_CONTEXT cert
)
2644 return get_cert_name_string(cert
, CERT_NAME_SIMPLE_DISPLAY_TYPE
, 0);
2647 static WCHAR
*field_format_detailed_subject(PCCERT_CONTEXT cert
, void *param
)
2649 return field_format_detailed_cert_name(&cert
->pCertInfo
->Subject
);
2652 static WCHAR
*format_long_date(const FILETIME
*fileTime
)
2654 WCHAR dateFmt
[80]; /* long enough for LOCALE_SLONGDATE */
2659 /* FIXME: format isn't quite right, want time too */
2660 GetLocaleInfoW(LOCALE_SYSTEM_DEFAULT
, LOCALE_SLONGDATE
, dateFmt
, ARRAY_SIZE(dateFmt
));
2661 FileTimeToSystemTime(fileTime
, &sysTime
);
2662 len
= GetDateFormatW(LOCALE_SYSTEM_DEFAULT
, 0, &sysTime
, dateFmt
, NULL
, 0);
2665 buf
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
2667 GetDateFormatW(LOCALE_SYSTEM_DEFAULT
, 0, &sysTime
, dateFmt
, buf
,
2673 static WCHAR
*field_format_from_date(PCCERT_CONTEXT cert
)
2675 return format_long_date(&cert
->pCertInfo
->NotBefore
);
2678 static WCHAR
*field_format_to_date(PCCERT_CONTEXT cert
)
2680 return format_long_date(&cert
->pCertInfo
->NotAfter
);
2683 static WCHAR
*field_format_public_key(PCCERT_CONTEXT cert
)
2685 PCCRYPT_OID_INFO oidInfo
;
2688 oidInfo
= CryptFindOIDInfo(CRYPT_OID_INFO_OID_KEY
,
2689 cert
->pCertInfo
->SubjectPublicKeyInfo
.Algorithm
.pszObjId
, 0);
2692 WCHAR fmt
[MAX_STRING_LEN
];
2694 if (LoadStringW(hInstance
, IDS_FIELD_PUBLIC_KEY_FORMAT
, fmt
, ARRAY_SIZE(fmt
)))
2698 /* Allocate the output buffer. Use the number of bytes in the
2699 * public key as a conservative (high) estimate for the number of
2700 * digits in its output.
2701 * The output is of the form (in English)
2702 * "<public key algorithm> (<public key bit length> bits)".
2703 * Ordinarily having two positional parameters in a string is not a
2704 * good idea, but as this isn't a sentence fragment, it shouldn't
2705 * be word-order dependent.
2707 len
= lstrlenW(fmt
) + lstrlenW(oidInfo
->pwszName
) +
2708 cert
->pCertInfo
->SubjectPublicKeyInfo
.PublicKey
.cbData
* 8;
2709 buf
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(*buf
));
2713 args
[0] = (DWORD_PTR
)oidInfo
->pwszName
;
2714 args
[1] = CertGetPublicKeyLength(X509_ASN_ENCODING
,
2715 &cert
->pCertInfo
->SubjectPublicKeyInfo
);
2716 FormatMessageW(FORMAT_MESSAGE_FROM_STRING
|FORMAT_MESSAGE_ARGUMENT_ARRAY
,
2717 fmt
, 0, 0, buf
, len
, (__ms_va_list
*)args
);
2724 static WCHAR
*field_format_detailed_public_key(PCCERT_CONTEXT cert
, void *param
)
2726 return format_hex_string(
2727 cert
->pCertInfo
->SubjectPublicKeyInfo
.PublicKey
.pbData
,
2728 cert
->pCertInfo
->SubjectPublicKeyInfo
.PublicKey
.cbData
);
2731 struct field_value_data
;
2734 PCCRYPTUI_VIEWCERTIFICATE_STRUCTW pCertViewInfo
;
2735 BOOL
*pfPropertiesChanged
;
2737 struct field_value_data
*fields
;
2740 typedef void (*add_fields_func
)(HWND hwnd
, struct detail_data
*data
);
2742 typedef WCHAR
*(*create_detailed_value_func
)(PCCERT_CONTEXT cert
, void *param
);
2744 struct field_value_data
2746 create_detailed_value_func create
;
2747 LPWSTR detailed_value
;
2751 static void add_field_value_data(struct detail_data
*data
,
2752 create_detailed_value_func create
, void *param
)
2755 data
->fields
= HeapReAlloc(GetProcessHeap(), 0, data
->fields
,
2756 (data
->cFields
+ 1) * sizeof(struct field_value_data
));
2758 data
->fields
= HeapAlloc(GetProcessHeap(), 0,
2759 sizeof(struct field_value_data
));
2762 data
->fields
[data
->cFields
].create
= create
;
2763 data
->fields
[data
->cFields
].detailed_value
= NULL
;
2764 data
->fields
[data
->cFields
].param
= param
;
2769 static void add_field_and_value_to_list(HWND hwnd
, struct detail_data
*data
,
2770 LPWSTR field
, LPWSTR value
, create_detailed_value_func create
, void *param
)
2773 int iItem
= SendMessageW(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2775 item
.mask
= LVIF_TEXT
| LVIF_PARAM
;
2778 item
.pszText
= field
;
2779 item
.lParam
= (LPARAM
)data
;
2780 SendMessageW(hwnd
, LVM_INSERTITEMW
, 0, (LPARAM
)&item
);
2783 item
.pszText
= value
;
2785 SendMessageW(hwnd
, LVM_SETITEMTEXTW
, iItem
, (LPARAM
)&item
);
2787 add_field_value_data(data
, create
, param
);
2790 static void add_string_id_and_value_to_list(HWND hwnd
, struct detail_data
*data
,
2791 int id
, LPWSTR value
, create_detailed_value_func create
, void *param
)
2793 WCHAR buf
[MAX_STRING_LEN
];
2795 LoadStringW(hInstance
, id
, buf
, ARRAY_SIZE(buf
));
2796 add_field_and_value_to_list(hwnd
, data
, buf
, value
, create
, param
);
2802 field_format_func format
;
2803 create_detailed_value_func create_detailed_value
;
2806 static void add_v1_field(HWND hwnd
, struct detail_data
*data
,
2807 const struct v1_field
*field
)
2809 WCHAR
*val
= field
->format(data
->pCertViewInfo
->pCertContext
);
2813 add_string_id_and_value_to_list(hwnd
, data
, field
->id
, val
,
2814 field
->create_detailed_value
, NULL
);
2815 HeapFree(GetProcessHeap(), 0, val
);
2819 static const struct v1_field v1_fields
[] = {
2820 { IDS_FIELD_VERSION
, field_format_version
, NULL
},
2821 { IDS_FIELD_SERIAL_NUMBER
, field_format_serial_number
, NULL
},
2822 { IDS_FIELD_ISSUER
, field_format_issuer
, field_format_detailed_issuer
},
2823 { IDS_FIELD_VALID_FROM
, field_format_from_date
, NULL
},
2824 { IDS_FIELD_VALID_TO
, field_format_to_date
, NULL
},
2825 { IDS_FIELD_SUBJECT
, field_format_subject
, field_format_detailed_subject
},
2826 { IDS_FIELD_PUBLIC_KEY
, field_format_public_key
,
2827 field_format_detailed_public_key
}
2830 static void add_v1_fields(HWND hwnd
, struct detail_data
*data
)
2833 PCCERT_CONTEXT cert
= data
->pCertViewInfo
->pCertContext
;
2835 /* The last item in v1_fields is the public key, which is not in the loop
2836 * because it's a special case.
2838 for (i
= 0; i
< ARRAY_SIZE(v1_fields
) - 1; i
++)
2839 add_v1_field(hwnd
, data
, &v1_fields
[i
]);
2840 if (cert
->pCertInfo
->SubjectPublicKeyInfo
.PublicKey
.cbData
)
2841 add_v1_field(hwnd
, data
, &v1_fields
[i
]);
2844 static WCHAR
*crypt_format_extension(const CERT_EXTENSION
*ext
, DWORD formatStrType
)
2849 if (CryptFormatObject(X509_ASN_ENCODING
, 0, formatStrType
, NULL
,
2850 ext
->pszObjId
, ext
->Value
.pbData
, ext
->Value
.cbData
, NULL
, &size
))
2852 str
= HeapAlloc(GetProcessHeap(), 0, size
);
2853 CryptFormatObject(X509_ASN_ENCODING
, 0, formatStrType
, NULL
,
2854 ext
->pszObjId
, ext
->Value
.pbData
, ext
->Value
.cbData
, str
, &size
);
2859 static WCHAR
*field_format_extension_hex_with_ascii(const CERT_EXTENSION
*ext
)
2863 if (ext
->Value
.cbData
)
2865 /* The output is formatted as:
2866 * <hex bytes> <ascii bytes>\n
2867 * where <hex bytes> is a string of up to 8 bytes, output as %02x,
2868 * and <ascii bytes> is the ASCII equivalent of each byte, or '.' if
2869 * the byte is not printable.
2870 * So, for example, the extension value consisting of the following
2872 * 0x30,0x14,0x31,0x12,0x30,0x10,0x06,0x03,0x55,0x04,0x03,
2873 * 0x13,0x09,0x4a,0x75,0x61,0x6e,0x20,0x4c,0x61,0x6e,0x67
2875 * 30 14 31 12 30 10 06 03 0.1.0...
2876 * 55 04 03 13 09 4a 75 61 U....Jua
2877 * 6e 20 4c 61 6e 67 n Lang
2878 * The allocation size therefore requires:
2879 * - 4 characters per character in an 8-byte line
2880 * (2 for the hex format, one for the space, one for the ASCII value)
2881 * - 3 more characters per 8-byte line (two spaces and a newline)
2882 * - 1 character for the terminating nul
2883 * FIXME: should use a fixed-width font for this
2885 DWORD lines
= (ext
->Value
.cbData
+ 7) / 8;
2887 str
= HeapAlloc(GetProcessHeap(), 0,
2888 (lines
* 8 * 4 + lines
* 3 + 1) * sizeof(WCHAR
));
2891 static const WCHAR fmt
[] = { '%','0','2','x',' ',0 };
2895 for (i
= 0, ptr
= str
; i
< ext
->Value
.cbData
; i
+= 8)
2897 /* Output as hex bytes first */
2898 for (j
= i
; j
< min(i
+ 8, ext
->Value
.cbData
); j
++, ptr
+= 3)
2899 swprintf(ptr
, 4, fmt
, ext
->Value
.pbData
[j
]);
2900 /* Pad the hex output with spaces for alignment */
2901 if (j
== ext
->Value
.cbData
&& j
% 8)
2903 static const WCHAR pad
[] = { ' ',' ',' ' };
2905 for (; j
% 8; j
++, ptr
+= ARRAY_SIZE(pad
))
2906 memcpy(ptr
, pad
, sizeof(pad
));
2908 /* The last swprintf included a space, so just insert one
2909 * more space between the hex bytes and the ASCII output
2912 /* Output as ASCII bytes */
2913 for (j
= i
; j
< min(i
+ 8, ext
->Value
.cbData
); j
++, ptr
++)
2915 if (iswprint(ext
->Value
.pbData
[j
]) &&
2916 !iswspace(ext
->Value
.pbData
[j
]))
2917 *ptr
= ext
->Value
.pbData
[j
];
2929 static WCHAR
*field_format_detailed_extension(PCCERT_CONTEXT cert
, void *param
)
2931 PCERT_EXTENSION ext
= param
;
2932 LPWSTR str
= crypt_format_extension(ext
,
2933 CRYPT_FORMAT_STR_MULTI_LINE
| CRYPT_FORMAT_STR_NO_HEX
);
2936 str
= field_format_extension_hex_with_ascii(ext
);
2940 static void add_cert_extension_detail(HWND hwnd
, struct detail_data
*data
,
2941 PCERT_EXTENSION ext
)
2943 PCCRYPT_OID_INFO oidInfo
= CryptFindOIDInfo(CRYPT_OID_INFO_OID_KEY
,
2945 LPWSTR val
= crypt_format_extension(ext
, 0);
2948 add_field_and_value_to_list(hwnd
, data
, (LPWSTR
)oidInfo
->pwszName
,
2949 val
, field_format_detailed_extension
, ext
);
2952 DWORD len
= strlen(ext
->pszObjId
);
2953 LPWSTR oidW
= HeapAlloc(GetProcessHeap(), 0, (len
+ 1) * sizeof(WCHAR
));
2959 for (i
= 0; i
<= len
; i
++)
2960 oidW
[i
] = ext
->pszObjId
[i
];
2961 add_field_and_value_to_list(hwnd
, data
, oidW
, val
,
2962 field_format_detailed_extension
, ext
);
2963 HeapFree(GetProcessHeap(), 0, oidW
);
2966 HeapFree(GetProcessHeap(), 0, val
);
2969 static void add_all_extensions(HWND hwnd
, struct detail_data
*data
)
2972 PCCERT_CONTEXT cert
= data
->pCertViewInfo
->pCertContext
;
2974 for (i
= 0; i
< cert
->pCertInfo
->cExtension
; i
++)
2975 add_cert_extension_detail(hwnd
, data
, &cert
->pCertInfo
->rgExtension
[i
]);
2978 static void add_critical_extensions(HWND hwnd
, struct detail_data
*data
)
2981 PCCERT_CONTEXT cert
= data
->pCertViewInfo
->pCertContext
;
2983 for (i
= 0; i
< cert
->pCertInfo
->cExtension
; i
++)
2984 if (cert
->pCertInfo
->rgExtension
[i
].fCritical
)
2985 add_cert_extension_detail(hwnd
, data
,
2986 &cert
->pCertInfo
->rgExtension
[i
]);
2989 typedef WCHAR
* (*prop_to_value_func
)(void *pb
, DWORD cb
);
2991 struct prop_id_to_string_id
2995 BOOL prop_is_string
;
2996 prop_to_value_func prop_to_value
;
2999 static WCHAR
*format_enhanced_key_usage_value(void *pb
, DWORD cb
)
3003 ext
.pszObjId
= (LPSTR
)X509_ENHANCED_KEY_USAGE
;
3004 ext
.fCritical
= FALSE
;
3005 ext
.Value
.pbData
= pb
;
3006 ext
.Value
.cbData
= cb
;
3007 return crypt_format_extension(&ext
, 0);
3010 /* Logically the access state should also be checked, and IDC_EDITPROPERTIES
3011 * disabled for read-only certificates, but native doesn't appear to do that.
3013 static const struct prop_id_to_string_id prop_id_map
[] = {
3014 { CERT_HASH_PROP_ID
, IDS_PROP_HASH
, FALSE
, format_hex_string
},
3015 { CERT_FRIENDLY_NAME_PROP_ID
, IDS_PROP_FRIENDLY_NAME
, TRUE
, NULL
},
3016 { CERT_DESCRIPTION_PROP_ID
, IDS_PROP_DESCRIPTION
, TRUE
, NULL
},
3017 { CERT_ENHKEY_USAGE_PROP_ID
, IDS_PROP_ENHKEY_USAGE
, FALSE
,
3018 format_enhanced_key_usage_value
},
3021 static void add_properties(HWND hwnd
, struct detail_data
*data
)
3024 PCCERT_CONTEXT cert
= data
->pCertViewInfo
->pCertContext
;
3026 for (i
= 0; i
< ARRAY_SIZE(prop_id_map
); i
++)
3030 if (CertGetCertificateContextProperty(cert
, prop_id_map
[i
].prop
, NULL
,
3036 /* FIXME: MS adds a separate value for the signature hash
3039 pb
= HeapAlloc(GetProcessHeap(), 0, cb
);
3042 if (CertGetCertificateContextProperty(cert
,
3043 prop_id_map
[i
].prop
, pb
, &cb
))
3045 if (prop_id_map
[i
].prop_is_string
)
3048 /* Don't double-free pb */
3052 val
= prop_id_map
[i
].prop_to_value(pb
, cb
);
3054 HeapFree(GetProcessHeap(), 0, pb
);
3056 add_string_id_and_value_to_list(hwnd
, data
, prop_id_map
[i
].id
, val
,
3062 static void add_all_fields(HWND hwnd
, struct detail_data
*data
)
3064 add_v1_fields(hwnd
, data
);
3065 add_all_extensions(hwnd
, data
);
3066 add_properties(hwnd
, data
);
3069 struct selection_list_item
3072 add_fields_func add
;
3075 static const struct selection_list_item listItems
[] = {
3076 { IDS_FIELDS_ALL
, add_all_fields
},
3077 { IDS_FIELDS_V1
, add_v1_fields
},
3078 { IDS_FIELDS_EXTENSIONS
, add_all_extensions
},
3079 { IDS_FIELDS_CRITICAL_EXTENSIONS
, add_critical_extensions
},
3080 { IDS_FIELDS_PROPERTIES
, add_properties
},
3083 static void create_show_list(HWND hwnd
, struct detail_data
*data
)
3085 HWND cb
= GetDlgItem(hwnd
, IDC_DETAIL_SELECT
);
3086 WCHAR buf
[MAX_STRING_LEN
];
3089 for (i
= 0; i
< ARRAY_SIZE(listItems
); i
++)
3093 LoadStringW(hInstance
, listItems
[i
].id
, buf
, ARRAY_SIZE(buf
));
3094 index
= SendMessageW(cb
, CB_INSERTSTRING
, -1, (LPARAM
)buf
);
3095 SendMessageW(cb
, CB_SETITEMDATA
, index
, (LPARAM
)data
);
3097 SendMessageW(cb
, CB_SETCURSEL
, 0, 0);
3100 static void create_listview_columns(HWND hwnd
)
3102 HWND lv
= GetDlgItem(hwnd
, IDC_DETAIL_LIST
);
3104 WCHAR buf
[MAX_STRING_LEN
];
3107 SendMessageW(lv
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0, LVS_EX_FULLROWSELECT
);
3108 GetWindowRect(lv
, &rc
);
3109 LoadStringW(hInstance
, IDS_FIELD
, buf
, ARRAY_SIZE(buf
));
3110 column
.mask
= LVCF_WIDTH
| LVCF_TEXT
;
3111 column
.cx
= (rc
.right
- rc
.left
) / 2 - 2;
3112 column
.pszText
= buf
;
3113 SendMessageW(lv
, LVM_INSERTCOLUMNW
, 0, (LPARAM
)&column
);
3114 LoadStringW(hInstance
, IDS_VALUE
, buf
, ARRAY_SIZE(buf
));
3115 SendMessageW(lv
, LVM_INSERTCOLUMNW
, 1, (LPARAM
)&column
);
3118 static void set_fields_selection(HWND hwnd
, struct detail_data
*data
, int sel
)
3120 HWND list
= GetDlgItem(hwnd
, IDC_DETAIL_LIST
);
3122 if (sel
>= 0 && sel
< ARRAY_SIZE(listItems
))
3124 SendMessageW(list
, LVM_DELETEALLITEMS
, 0, 0);
3125 listItems
[sel
].add(list
, data
);
3129 static void create_cert_details_list(HWND hwnd
, struct detail_data
*data
)
3131 create_show_list(hwnd
, data
);
3132 create_listview_columns(hwnd
);
3133 set_fields_selection(hwnd
, data
, 0);
3136 static void add_purpose(HWND hwnd
, LPCSTR oid
)
3138 HWND lv
= GetDlgItem(hwnd
, IDC_CERTIFICATE_USAGES
);
3139 PCRYPT_OID_INFO info
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
3140 sizeof(CRYPT_OID_INFO
));
3144 char *oidCopy
= HeapAlloc(GetProcessHeap(), 0, strlen(oid
) + 1);
3150 strcpy(oidCopy
, oid
);
3151 info
->cbSize
= sizeof(CRYPT_OID_INFO
);
3152 info
->pszOID
= oidCopy
;
3153 item
.mask
= LVIF_TEXT
| LVIF_STATE
| LVIF_PARAM
;
3154 item
.state
= INDEXTOSTATEIMAGEMASK(CheckBitmapIndexChecked
);
3155 item
.stateMask
= LVIS_STATEIMAGEMASK
;
3156 item
.iItem
= SendMessageW(lv
, LVM_GETITEMCOUNT
, 0, 0);
3158 item
.lParam
= (LPARAM
)info
;
3159 item
.pszText
= oidCopy
;
3160 SendMessageA(lv
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
3163 HeapFree(GetProcessHeap(), 0, info
);
3167 static BOOL
is_valid_oid(LPCSTR oid
)
3171 if (oid
[0] != '0' && oid
[0] != '1' && oid
[0] != '2')
3173 else if (oid
[1] != '.')
3180 BOOL expectNum
= TRUE
;
3182 for (ptr
= oid
+ 2, ret
= TRUE
; ret
&& *ptr
; ptr
++)
3188 else if (*(ptr
+ 1) == '.')
3195 else if (!(*(ptr
+ 1)))
3205 static BOOL
is_oid_in_list(HWND hwnd
, LPCSTR oid
)
3207 return find_oid_in_list(GetDlgItem(hwnd
, IDC_CERTIFICATE_USAGES
), oid
)
3211 #define MAX_PURPOSE 255
3213 static LRESULT CALLBACK
add_purpose_dlg_proc(HWND hwnd
, UINT msg
,
3214 WPARAM wp
, LPARAM lp
)
3217 char buf
[MAX_PURPOSE
+ 1];
3222 SendMessageW(GetDlgItem(hwnd
, IDC_NEW_PURPOSE
), EM_SETLIMITTEXT
,
3224 ShowScrollBar(GetDlgItem(hwnd
, IDC_NEW_PURPOSE
), SB_VERT
, FALSE
);
3225 SetWindowLongPtrW(hwnd
, DWLP_USER
, lp
);
3231 if (LOWORD(wp
) == IDC_NEW_PURPOSE
)
3233 /* Show/hide scroll bar on description depending on how much
3236 HWND description
= GetDlgItem(hwnd
, IDC_NEW_PURPOSE
);
3237 int lines
= SendMessageW(description
, EM_GETLINECOUNT
, 0, 0);
3239 ShowScrollBar(description
, SB_VERT
, lines
> 1);
3246 SendMessageA(GetDlgItem(hwnd
, IDC_NEW_PURPOSE
), WM_GETTEXT
, ARRAY_SIZE(buf
),
3250 /* An empty purpose is the same as cancelling */
3251 EndDialog(hwnd
, IDCANCEL
);
3254 else if (!is_valid_oid(buf
))
3256 WCHAR title
[MAX_STRING_LEN
], error
[MAX_STRING_LEN
];
3258 LoadStringW(hInstance
, IDS_CERTIFICATE_PURPOSE_ERROR
, error
, ARRAY_SIZE(error
));
3259 LoadStringW(hInstance
, IDS_CERTIFICATE_PROPERTIES
, title
, ARRAY_SIZE(title
));
3260 MessageBoxW(hwnd
, error
, title
, MB_ICONERROR
| MB_OK
);
3262 else if (is_oid_in_list(
3263 (HWND
)GetWindowLongPtrW(hwnd
, DWLP_USER
), buf
))
3265 WCHAR title
[MAX_STRING_LEN
], error
[MAX_STRING_LEN
];
3267 LoadStringW(hInstance
, IDS_CERTIFICATE_PURPOSE_EXISTS
, error
,
3269 LoadStringW(hInstance
, IDS_CERTIFICATE_PROPERTIES
, title
, ARRAY_SIZE(title
));
3270 MessageBoxW(hwnd
, error
, title
, MB_ICONEXCLAMATION
| MB_OK
);
3274 HWND parent
= (HWND
)GetWindowLongPtrW(hwnd
, DWLP_USER
);
3276 add_purpose(parent
, buf
);
3277 EndDialog(hwnd
, wp
);
3282 EndDialog(hwnd
, wp
);
3293 static WCHAR
*get_cert_property_as_string(PCCERT_CONTEXT cert
, DWORD prop
)
3298 if (CertGetCertificateContextProperty(cert
, prop
, NULL
, &cb
))
3300 name
= HeapAlloc(GetProcessHeap(), 0, cb
);
3303 if (!CertGetCertificateContextProperty(cert
, prop
, name
, &cb
))
3305 HeapFree(GetProcessHeap(), 0, name
);
3313 static void redraw_states(HWND list
, BOOL enabled
)
3315 int items
= SendMessageW(list
, LVM_GETITEMCOUNT
, 0, 0), i
;
3317 for (i
= 0; i
< items
; i
++)
3319 BOOL change
= FALSE
;
3322 state
= SendMessageW(list
, LVM_GETITEMSTATE
, i
, LVIS_STATEIMAGEMASK
);
3323 /* This reverses the INDEXTOSTATEIMAGEMASK shift. There doesn't appear
3324 * to be a handy macro for it.
3329 if (state
== CheckBitmapIndexDisabledChecked
)
3331 state
= CheckBitmapIndexChecked
;
3334 if (state
== CheckBitmapIndexDisabledUnchecked
)
3336 state
= CheckBitmapIndexUnchecked
;
3342 if (state
== CheckBitmapIndexChecked
)
3344 state
= CheckBitmapIndexDisabledChecked
;
3347 if (state
== CheckBitmapIndexUnchecked
)
3349 state
= CheckBitmapIndexDisabledUnchecked
;
3357 item
.state
= INDEXTOSTATEIMAGEMASK(state
);
3358 item
.stateMask
= LVIS_STATEIMAGEMASK
;
3359 SendMessageW(list
, LVM_SETITEMSTATE
, i
, (LPARAM
)&item
);
3365 PurposeEnableAll
= 0,
3367 PurposeEnableSelected
3370 static void select_purposes(HWND hwnd
, PurposeSelection selection
)
3372 HWND lv
= GetDlgItem(hwnd
, IDC_CERTIFICATE_USAGES
);
3376 case PurposeEnableAll
:
3377 case PurposeDisableAll
:
3378 EnableWindow(lv
, FALSE
);
3379 redraw_states(lv
, FALSE
);
3380 EnableWindow(GetDlgItem(hwnd
, IDC_ADD_PURPOSE
), FALSE
);
3382 case PurposeEnableSelected
:
3383 EnableWindow(lv
, TRUE
);
3384 redraw_states(lv
, TRUE
);
3385 EnableWindow(GetDlgItem(hwnd
, IDC_ADD_PURPOSE
), TRUE
);
3389 struct edit_cert_data
3391 PCCERT_CONTEXT cert
;
3392 BOOL
*pfPropertiesChanged
;
3393 HIMAGELIST imageList
;
3396 static void show_cert_usages(HWND hwnd
, struct edit_cert_data
*data
)
3398 PCCERT_CONTEXT cert
= data
->cert
;
3399 HWND lv
= GetDlgItem(hwnd
, IDC_CERTIFICATE_USAGES
);
3400 PCERT_ENHKEY_USAGE usage
;
3404 PurposeSelection purposeSelection
= PurposeEnableAll
;
3406 GetWindowRect(lv
, &rc
);
3407 column
.mask
= LVCF_WIDTH
;
3408 column
.cx
= rc
.right
- rc
.left
;
3409 SendMessageW(lv
, LVM_INSERTCOLUMNW
, 0, (LPARAM
)&column
);
3410 SendMessageW(lv
, LVM_SETIMAGELIST
, LVSIL_STATE
, (LPARAM
)data
->imageList
);
3412 /* Get enhanced key usage. Have to check for a property and an extension
3413 * separately, because CertGetEnhancedKeyUsage will succeed and return an
3414 * empty usage if neither is set. Unfortunately an empty usage implies
3415 * no usage is allowed, so we have to distinguish between the two cases.
3417 if (CertGetEnhancedKeyUsage(cert
, CERT_FIND_PROP_ONLY_ENHKEY_USAGE_FLAG
,
3420 usage
= HeapAlloc(GetProcessHeap(), 0, size
);
3421 if (!CertGetEnhancedKeyUsage(cert
,
3422 CERT_FIND_PROP_ONLY_ENHKEY_USAGE_FLAG
, usage
, &size
))
3424 HeapFree(GetProcessHeap(), 0, usage
);
3427 else if (usage
->cUsageIdentifier
)
3428 purposeSelection
= PurposeEnableSelected
;
3430 purposeSelection
= PurposeDisableAll
;
3432 else if (CertGetEnhancedKeyUsage(cert
, CERT_FIND_EXT_ONLY_ENHKEY_USAGE_FLAG
,
3435 usage
= HeapAlloc(GetProcessHeap(), 0, size
);
3436 if (!CertGetEnhancedKeyUsage(cert
,
3437 CERT_FIND_EXT_ONLY_ENHKEY_USAGE_FLAG
, usage
, &size
))
3439 HeapFree(GetProcessHeap(), 0, usage
);
3442 else if (usage
->cUsageIdentifier
)
3443 purposeSelection
= PurposeEnableAll
;
3445 purposeSelection
= PurposeDisableAll
;
3449 purposeSelection
= PurposeEnableAll
;
3456 for (i
= 0; i
< usage
->cUsageIdentifier
; i
++)
3458 PCCRYPT_OID_INFO info
= CryptFindOIDInfo(CRYPT_OID_INFO_OID_KEY
,
3459 usage
->rgpszUsageIdentifier
[i
], CRYPT_ENHKEY_USAGE_OID_GROUP_ID
);
3462 add_known_usage(lv
, info
, CheckBitmapIndexDisabledChecked
);
3464 add_purpose(hwnd
, usage
->rgpszUsageIdentifier
[i
]);
3466 HeapFree(GetProcessHeap(), 0, usage
);
3469 add_known_usages_to_list(lv
, CheckBitmapIndexDisabledChecked
);
3470 select_purposes(hwnd
, purposeSelection
);
3471 SendMessageW(GetDlgItem(hwnd
, IDC_ENABLE_ALL_PURPOSES
+ purposeSelection
),
3475 static void set_general_cert_properties(HWND hwnd
, struct edit_cert_data
*data
)
3477 PCCERT_CONTEXT cert
= data
->cert
;
3480 if ((str
= get_cert_property_as_string(cert
, CERT_FRIENDLY_NAME_PROP_ID
)))
3482 SendMessageW(GetDlgItem(hwnd
, IDC_FRIENDLY_NAME
), WM_SETTEXT
, 0,
3484 HeapFree(GetProcessHeap(), 0, str
);
3486 if ((str
= get_cert_property_as_string(cert
, CERT_DESCRIPTION_PROP_ID
)))
3488 SendMessageW(GetDlgItem(hwnd
, IDC_DESCRIPTION
), WM_SETTEXT
, 0,
3490 HeapFree(GetProcessHeap(), 0, str
);
3492 show_cert_usages(hwnd
, data
);
3495 static void set_cert_string_property(PCCERT_CONTEXT cert
, DWORD prop
,
3500 CRYPT_DATA_BLOB blob
;
3502 blob
.pbData
= (BYTE
*)str
;
3503 blob
.cbData
= (lstrlenW(str
) + 1) * sizeof(WCHAR
);
3504 CertSetCertificateContextProperty(cert
, prop
, 0, &blob
);
3507 CertSetCertificateContextProperty(cert
, prop
, 0, NULL
);
3510 #define WM_REFRESH_VIEW WM_USER + 0
3512 static BOOL CALLBACK
refresh_propsheet_pages(HWND hwnd
, LPARAM lParam
)
3514 if ((GetClassLongW(hwnd
, GCW_ATOM
) == WC_DIALOG
))
3515 SendMessageW(hwnd
, WM_REFRESH_VIEW
, 0, 0);
3519 #define MAX_FRIENDLY_NAME 40
3520 #define MAX_DESCRIPTION 255
3522 static void apply_general_changes(HWND hwnd
)
3524 WCHAR buf
[MAX_DESCRIPTION
+ 1];
3525 struct edit_cert_data
*data
=
3526 (struct edit_cert_data
*)GetWindowLongPtrW(hwnd
, DWLP_USER
);
3528 SendMessageW(GetDlgItem(hwnd
, IDC_FRIENDLY_NAME
), WM_GETTEXT
, ARRAY_SIZE(buf
), (LPARAM
)buf
);
3529 set_cert_string_property(data
->cert
, CERT_FRIENDLY_NAME_PROP_ID
, buf
);
3530 SendMessageW(GetDlgItem(hwnd
, IDC_DESCRIPTION
), WM_GETTEXT
, ARRAY_SIZE(buf
), (LPARAM
)buf
);
3531 set_cert_string_property(data
->cert
, CERT_DESCRIPTION_PROP_ID
, buf
);
3532 if (IsDlgButtonChecked(hwnd
, IDC_ENABLE_ALL_PURPOSES
))
3534 /* Setting a NULL usage removes the enhanced key usage property. */
3535 CertSetEnhancedKeyUsage(data
->cert
, NULL
);
3537 else if (IsDlgButtonChecked(hwnd
, IDC_DISABLE_ALL_PURPOSES
))
3539 CERT_ENHKEY_USAGE usage
= { 0, NULL
};
3541 CertSetEnhancedKeyUsage(data
->cert
, &usage
);
3543 else if (IsDlgButtonChecked(hwnd
, IDC_ENABLE_SELECTED_PURPOSES
))
3545 HWND lv
= GetDlgItem(hwnd
, IDC_CERTIFICATE_USAGES
);
3546 CERT_ENHKEY_USAGE usage
= { 0, NULL
};
3547 int purposes
= SendMessageW(lv
, LVM_GETITEMCOUNT
, 0, 0), i
;
3550 item
.mask
= LVIF_STATE
| LVIF_PARAM
;
3552 item
.stateMask
= LVIS_STATEIMAGEMASK
;
3553 for (i
= 0; i
< purposes
; i
++)
3556 if (SendMessageW(lv
, LVM_GETITEMW
, 0, (LPARAM
)&item
))
3558 int state
= item
.state
>> 12;
3560 if (state
== CheckBitmapIndexChecked
)
3562 CRYPT_OID_INFO
*info
= (CRYPT_OID_INFO
*)item
.lParam
;
3564 if (usage
.cUsageIdentifier
)
3565 usage
.rgpszUsageIdentifier
=
3566 HeapReAlloc(GetProcessHeap(), 0,
3567 usage
.rgpszUsageIdentifier
,
3568 (usage
.cUsageIdentifier
+ 1) * sizeof(LPSTR
));
3570 usage
.rgpszUsageIdentifier
=
3571 HeapAlloc(GetProcessHeap(), 0, sizeof(LPSTR
));
3572 if (usage
.rgpszUsageIdentifier
)
3573 usage
.rgpszUsageIdentifier
[usage
.cUsageIdentifier
++] =
3574 (LPSTR
)info
->pszOID
;
3578 CertSetEnhancedKeyUsage(data
->cert
, &usage
);
3579 HeapFree(GetProcessHeap(), 0, usage
.rgpszUsageIdentifier
);
3581 EnumChildWindows(GetParent(GetParent(hwnd
)), refresh_propsheet_pages
, 0);
3582 if (data
->pfPropertiesChanged
)
3583 *data
->pfPropertiesChanged
= TRUE
;
3586 static LRESULT CALLBACK
cert_properties_general_dlg_proc(HWND hwnd
, UINT msg
,
3587 WPARAM wp
, LPARAM lp
)
3589 PROPSHEETPAGEW
*page
;
3591 TRACE("(%p, %08x, %08lx, %08lx)\n", hwnd
, msg
, wp
, lp
);
3597 HWND description
= GetDlgItem(hwnd
, IDC_DESCRIPTION
);
3598 struct detail_data
*detailData
;
3599 struct edit_cert_data
*editData
;
3601 page
= (PROPSHEETPAGEW
*)lp
;
3602 detailData
= (struct detail_data
*)page
->lParam
;
3603 SendMessageW(GetDlgItem(hwnd
, IDC_FRIENDLY_NAME
), EM_SETLIMITTEXT
,
3604 MAX_FRIENDLY_NAME
, 0);
3605 SendMessageW(description
, EM_SETLIMITTEXT
, MAX_DESCRIPTION
, 0);
3606 ShowScrollBar(description
, SB_VERT
, FALSE
);
3607 editData
= HeapAlloc(GetProcessHeap(), 0,
3608 sizeof(struct edit_cert_data
));
3611 editData
->imageList
= ImageList_Create(16, 16,
3612 ILC_COLOR4
| ILC_MASK
, 4, 0);
3613 if (editData
->imageList
)
3616 COLORREF backColor
= RGB(255, 0, 255);
3618 bmp
= LoadBitmapW(hInstance
, MAKEINTRESOURCEW(IDB_CHECKS
));
3619 ImageList_AddMasked(editData
->imageList
, bmp
, backColor
);
3621 ImageList_SetBkColor(editData
->imageList
, CLR_NONE
);
3623 editData
->cert
= detailData
->pCertViewInfo
->pCertContext
;
3624 editData
->pfPropertiesChanged
= detailData
->pfPropertiesChanged
;
3625 SetWindowLongPtrW(hwnd
, DWLP_USER
, (LPARAM
)editData
);
3626 set_general_cert_properties(hwnd
, editData
);
3632 NMHDR
*hdr
= (NMHDR
*)lp
;
3638 nm
= (NMITEMACTIVATE
*)lp
;
3639 toggle_usage(hwnd
, nm
->iItem
);
3640 SendMessageW(GetParent(hwnd
), PSM_CHANGED
, (WPARAM
)hwnd
, 0);
3643 apply_general_changes(hwnd
);
3652 SendMessageW(GetParent(hwnd
), PSM_CHANGED
, (WPARAM
)hwnd
, 0);
3653 if (LOWORD(wp
) == IDC_DESCRIPTION
)
3655 /* Show/hide scroll bar on description depending on how much
3658 HWND description
= GetDlgItem(hwnd
, IDC_DESCRIPTION
);
3659 int lines
= SendMessageW(description
, EM_GETLINECOUNT
, 0, 0);
3661 ShowScrollBar(description
, SB_VERT
, lines
> 1);
3667 case IDC_ADD_PURPOSE
:
3668 if (DialogBoxParamW(hInstance
,
3669 MAKEINTRESOURCEW(IDD_ADD_CERT_PURPOSE
), hwnd
,
3670 add_purpose_dlg_proc
, (LPARAM
)hwnd
) == IDOK
)
3671 SendMessageW(GetParent(hwnd
), PSM_CHANGED
, (WPARAM
)hwnd
, 0);
3673 case IDC_ENABLE_ALL_PURPOSES
:
3674 case IDC_DISABLE_ALL_PURPOSES
:
3675 case IDC_ENABLE_SELECTED_PURPOSES
:
3676 SendMessageW(GetParent(hwnd
), PSM_CHANGED
, (WPARAM
)hwnd
, 0);
3677 select_purposes(hwnd
, LOWORD(wp
) - IDC_ENABLE_ALL_PURPOSES
);
3687 static UINT CALLBACK
cert_properties_general_callback(HWND hwnd
, UINT msg
,
3688 PROPSHEETPAGEW
*page
)
3692 struct edit_cert_data
*data
;
3697 lv
= GetDlgItem(hwnd
, IDC_CERTIFICATE_USAGES
);
3698 cItem
= SendMessageW(lv
, LVM_GETITEMCOUNT
, 0, 0);
3699 for (i
= 0; i
< cItem
; i
++)
3703 item
.mask
= LVIF_PARAM
;
3706 if (SendMessageW(lv
, LVM_GETITEMW
, 0, (LPARAM
)&item
) && item
.lParam
)
3708 PCRYPT_OID_INFO info
= (PCRYPT_OID_INFO
)item
.lParam
;
3710 if (info
->cbSize
== sizeof(CRYPT_OID_INFO
) && !info
->dwGroupId
)
3712 HeapFree(GetProcessHeap(), 0, (LPSTR
)info
->pszOID
);
3713 HeapFree(GetProcessHeap(), 0, info
);
3717 data
= (struct edit_cert_data
*)GetWindowLongPtrW(hwnd
, DWLP_USER
);
3720 ImageList_Destroy(data
->imageList
);
3721 HeapFree(GetProcessHeap(), 0, data
);
3728 static void show_edit_cert_properties_dialog(HWND parent
,
3729 struct detail_data
*data
)
3731 PROPSHEETHEADERW hdr
;
3732 PROPSHEETPAGEW page
; /* FIXME: need to add a cross-certificate page */
3734 TRACE("(%p)\n", data
);
3736 memset(&page
, 0, sizeof(PROPSHEETPAGEW
));
3737 page
.dwSize
= sizeof(page
);
3738 page
.dwFlags
= PSP_USECALLBACK
;
3739 page
.pfnCallback
= cert_properties_general_callback
;
3740 page
.hInstance
= hInstance
;
3741 page
.u
.pszTemplate
= MAKEINTRESOURCEW(IDD_CERT_PROPERTIES_GENERAL
);
3742 page
.pfnDlgProc
= cert_properties_general_dlg_proc
;
3743 page
.lParam
= (LPARAM
)data
;
3745 memset(&hdr
, 0, sizeof(hdr
));
3746 hdr
.dwSize
= sizeof(hdr
);
3747 hdr
.hwndParent
= parent
;
3748 hdr
.dwFlags
= PSH_PROPSHEETPAGE
;
3749 hdr
.hInstance
= hInstance
;
3750 hdr
.pszCaption
= MAKEINTRESOURCEW(IDS_CERTIFICATE_PROPERTIES
);
3751 hdr
.u3
.ppsp
= &page
;
3753 PropertySheetW(&hdr
);
3756 static void free_detail_fields(struct detail_data
*data
)
3760 for (i
= 0; i
< data
->cFields
; i
++)
3761 HeapFree(GetProcessHeap(), 0, data
->fields
[i
].detailed_value
);
3762 HeapFree(GetProcessHeap(), 0, data
->fields
);
3763 data
->fields
= NULL
;
3767 static void refresh_details_view(HWND hwnd
)
3769 HWND cb
= GetDlgItem(hwnd
, IDC_DETAIL_SELECT
);
3771 struct detail_data
*data
;
3773 curSel
= SendMessageW(cb
, CB_GETCURSEL
, 0, 0);
3774 /* Actually, any index will do, since they all store the same data value */
3775 data
= (struct detail_data
*)SendMessageW(cb
, CB_GETITEMDATA
, curSel
, 0);
3776 free_detail_fields(data
);
3777 set_fields_selection(hwnd
, data
, curSel
);
3780 static LRESULT CALLBACK
detail_dlg_proc(HWND hwnd
, UINT msg
, WPARAM wp
,
3783 PROPSHEETPAGEW
*page
;
3784 struct detail_data
*data
;
3786 TRACE("(%p, %08x, %08lx, %08lx)\n", hwnd
, msg
, wp
, lp
);
3791 page
= (PROPSHEETPAGEW
*)lp
;
3792 data
= (struct detail_data
*)page
->lParam
;
3793 create_cert_details_list(hwnd
, data
);
3794 if (!(data
->pCertViewInfo
->dwFlags
& CRYPTUI_ENABLE_EDITPROPERTIES
))
3795 EnableWindow(GetDlgItem(hwnd
, IDC_EDITPROPERTIES
), FALSE
);
3796 if (data
->pCertViewInfo
->dwFlags
& CRYPTUI_DISABLE_EXPORT
)
3797 EnableWindow(GetDlgItem(hwnd
, IDC_EXPORT
), FALSE
);
3802 HWND list
= GetDlgItem(hwnd
, IDC_DETAIL_LIST
);
3804 nm
= (NMITEMACTIVATE
*)lp
;
3805 if (nm
->hdr
.hwndFrom
== list
&& nm
->uNewState
& LVN_ITEMACTIVATE
3806 && nm
->hdr
.code
== LVN_ITEMCHANGED
)
3808 data
= (struct detail_data
*)nm
->lParam
;
3809 if (nm
->iItem
>= 0 && data
&& nm
->iItem
< data
->cFields
)
3811 WCHAR buf
[MAX_STRING_LEN
], *val
= NULL
;
3812 HWND valueCtl
= GetDlgItem(hwnd
, IDC_DETAIL_VALUE
);
3814 if (data
->fields
[nm
->iItem
].create
)
3815 val
= data
->fields
[nm
->iItem
].create(
3816 data
->pCertViewInfo
->pCertContext
,
3817 data
->fields
[nm
->iItem
].param
);
3823 item
.cchTextMax
= ARRAY_SIZE(buf
);
3824 item
.mask
= LVIF_TEXT
;
3826 item
.iItem
= nm
->iItem
;
3828 res
= SendMessageW(list
, LVM_GETITEMW
, 0, (LPARAM
)&item
);
3832 /* Select all the text in the control, the next update will
3835 SendMessageW(valueCtl
, EM_SETSEL
, 0, -1);
3836 add_unformatted_text_to_control(valueCtl
, val
,
3837 val
? lstrlenW(val
) : 0);
3839 HeapFree(GetProcessHeap(), 0, val
);
3849 HWND cb
= GetDlgItem(hwnd
, IDC_DETAIL_SELECT
);
3850 CRYPTUI_WIZ_EXPORT_INFO info
;
3852 data
= (struct detail_data
*)SendMessageW(cb
, CB_GETITEMDATA
, 0, 0);
3853 info
.dwSize
= sizeof(info
);
3854 info
.pwszExportFileName
= NULL
;
3855 info
.dwSubjectChoice
= CRYPTUI_WIZ_EXPORT_CERT_CONTEXT
;
3856 info
.u
.pCertContext
= data
->pCertViewInfo
->pCertContext
;
3858 CryptUIWizExport(0, hwnd
, NULL
, &info
, NULL
);
3861 case IDC_EDITPROPERTIES
:
3863 HWND cb
= GetDlgItem(hwnd
, IDC_DETAIL_SELECT
);
3866 curSel
= SendMessageW(cb
, CB_GETCURSEL
, 0, 0);
3867 /* Actually, any index will do, since they all store the same
3870 data
= (struct detail_data
*)SendMessageW(cb
, CB_GETITEMDATA
,
3872 show_edit_cert_properties_dialog(GetParent(hwnd
), data
);
3875 case ((CBN_SELCHANGE
<< 16) | IDC_DETAIL_SELECT
):
3876 refresh_details_view(hwnd
);
3880 case WM_REFRESH_VIEW
:
3881 refresh_details_view(hwnd
);
3887 static UINT CALLBACK
detail_callback(HWND hwnd
, UINT msg
,
3888 PROPSHEETPAGEW
*page
)
3890 struct detail_data
*data
;
3895 data
= (struct detail_data
*)page
->lParam
;
3896 free_detail_fields(data
);
3897 HeapFree(GetProcessHeap(), 0, data
);
3903 static BOOL
init_detail_page(PCCRYPTUI_VIEWCERTIFICATE_STRUCTW pCertViewInfo
,
3904 BOOL
*pfPropertiesChanged
, PROPSHEETPAGEW
*page
)
3907 struct detail_data
*data
= HeapAlloc(GetProcessHeap(), 0,
3908 sizeof(struct detail_data
));
3912 data
->pCertViewInfo
= pCertViewInfo
;
3913 data
->pfPropertiesChanged
= pfPropertiesChanged
;
3915 data
->fields
= NULL
;
3916 memset(page
, 0, sizeof(PROPSHEETPAGEW
));
3917 page
->dwSize
= sizeof(PROPSHEETPAGEW
);
3918 page
->dwFlags
= PSP_USECALLBACK
;
3919 page
->pfnCallback
= detail_callback
;
3920 page
->hInstance
= hInstance
;
3921 page
->u
.pszTemplate
= MAKEINTRESOURCEW(IDD_DETAIL
);
3922 page
->pfnDlgProc
= detail_dlg_proc
;
3923 page
->lParam
= (LPARAM
)data
;
3931 struct hierarchy_data
3933 PCCRYPTUI_VIEWCERTIFICATE_STRUCTW pCertViewInfo
;
3934 HIMAGELIST imageList
;
3938 static LPARAM
index_to_lparam(struct hierarchy_data
*data
, DWORD index
)
3940 CRYPT_PROVIDER_SGNR
*provSigner
= WTHelperGetProvSignerFromChain(
3941 (CRYPT_PROVIDER_DATA
*)data
->pCertViewInfo
->u
.pCryptProviderData
,
3942 data
->pCertViewInfo
->idxSigner
, data
->pCertViewInfo
->fCounterSigner
,
3943 data
->pCertViewInfo
->idxCounterSigner
);
3945 /* Takes advantage of the fact that a pointer is 32-bit aligned, and
3946 * therefore always even.
3948 if (index
== provSigner
->csCertChain
- 1)
3949 return (LPARAM
)data
;
3950 return index
<< 1 | 1;
3953 static inline DWORD
lparam_to_index(struct hierarchy_data
*data
, LPARAM lp
)
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
);
3961 return provSigner
->csCertChain
- 1;
3965 static struct hierarchy_data
*get_hierarchy_data_from_tree_item(HWND tree
,
3968 struct hierarchy_data
*data
= NULL
;
3969 HTREEITEM root
= NULL
;
3972 HTREEITEM parent
= (HTREEITEM
)SendMessageW(tree
, TVM_GETNEXTITEM
,
3973 TVGN_PARENT
, (LPARAM
)hItem
);
3983 item
.mask
= TVIF_PARAM
;
3985 SendMessageW(tree
, TVM_GETITEMW
, 0, (LPARAM
)&item
);
3986 data
= (struct hierarchy_data
*)item
.lParam
;
3991 static WCHAR
*get_cert_display_name(PCCERT_CONTEXT cert
)
3993 WCHAR
*name
= get_cert_property_as_string(cert
, CERT_FRIENDLY_NAME_PROP_ID
);
3996 name
= get_cert_name_string(cert
, CERT_NAME_SIMPLE_DISPLAY_TYPE
, 0);
4000 static void show_cert_chain(HWND hwnd
, struct hierarchy_data
*data
)
4002 HWND tree
= GetDlgItem(hwnd
, IDC_CERTPATH
);
4003 CRYPT_PROVIDER_SGNR
*provSigner
= WTHelperGetProvSignerFromChain(
4004 (CRYPT_PROVIDER_DATA
*)data
->pCertViewInfo
->u
.pCryptProviderData
,
4005 data
->pCertViewInfo
->idxSigner
, data
->pCertViewInfo
->fCounterSigner
,
4006 data
->pCertViewInfo
->idxCounterSigner
);
4008 HTREEITEM parent
= NULL
;
4010 SendMessageW(tree
, TVM_SETIMAGELIST
, TVSIL_NORMAL
, (LPARAM
)data
->imageList
);
4011 for (i
= provSigner
->csCertChain
; i
; i
--)
4015 name
= get_cert_display_name(provSigner
->pasCertChain
[i
- 1].pCert
);
4018 TVINSERTSTRUCTW tvis
;
4020 tvis
.hParent
= parent
;
4021 tvis
.hInsertAfter
= TVI_LAST
;
4022 tvis
.u
.item
.mask
= TVIF_TEXT
| TVIF_STATE
| TVIF_IMAGE
|
4023 TVIF_SELECTEDIMAGE
| TVIF_PARAM
;
4024 tvis
.u
.item
.pszText
= name
;
4025 tvis
.u
.item
.state
= TVIS_EXPANDED
;
4026 tvis
.u
.item
.stateMask
= TVIS_EXPANDED
;
4027 if (i
== 1 && (!provSigner
->pChainContext
||
4028 provSigner
->pChainContext
->TrustStatus
.dwErrorStatus
&
4029 CERT_TRUST_IS_PARTIAL_CHAIN
))
4031 /* The root of the chain has a special case: if the chain is
4032 * a partial chain, the icon is a warning icon rather than an
4035 tvis
.u
.item
.iImage
= 2;
4037 else if (provSigner
->pasCertChain
[i
- 1].pChainElement
->TrustStatus
.
4039 tvis
.u
.item
.iImage
= 0;
4041 tvis
.u
.item
.iImage
= 1;
4042 tvis
.u
.item
.iSelectedImage
= tvis
.u
.item
.iImage
;
4043 tvis
.u
.item
.lParam
= index_to_lparam(data
, i
- 1);
4044 parent
= (HTREEITEM
)SendMessageW(tree
, TVM_INSERTITEMW
, 0,
4046 HeapFree(GetProcessHeap(), 0, name
);
4051 static void set_certificate_status(HWND hwnd
, const CRYPT_PROVIDER_CERT
*cert
)
4053 /* Select all the text in the control, the next update will replace it */
4054 SendMessageW(hwnd
, EM_SETSEL
, 0, -1);
4055 /* Set the highest priority error messages first. */
4056 if (!(cert
->dwConfidence
& CERT_CONFIDENCE_SIG
))
4057 add_string_resource_to_control(hwnd
, IDS_CERTIFICATE_BAD_SIGNATURE
);
4058 else if (!(cert
->dwConfidence
& CERT_CONFIDENCE_TIME
))
4059 add_string_resource_to_control(hwnd
, IDS_CERTIFICATE_BAD_TIME
);
4060 else if (!(cert
->dwConfidence
& CERT_CONFIDENCE_TIMENEST
))
4061 add_string_resource_to_control(hwnd
, IDS_CERTIFICATE_BAD_TIMENEST
);
4062 else if (cert
->dwRevokedReason
)
4063 add_string_resource_to_control(hwnd
, IDS_CERTIFICATE_REVOKED
);
4065 add_string_resource_to_control(hwnd
, IDS_CERTIFICATE_VALID
);
4068 static void set_certificate_status_for_end_cert(HWND hwnd
,
4069 PCCRYPTUI_VIEWCERTIFICATE_STRUCTW pCertViewInfo
)
4071 HWND status
= GetDlgItem(hwnd
, IDC_CERTIFICATESTATUSTEXT
);
4072 CRYPT_PROVIDER_SGNR
*provSigner
= WTHelperGetProvSignerFromChain(
4073 (CRYPT_PROVIDER_DATA
*)pCertViewInfo
->u
.pCryptProviderData
,
4074 pCertViewInfo
->idxSigner
, pCertViewInfo
->fCounterSigner
,
4075 pCertViewInfo
->idxCounterSigner
);
4076 CRYPT_PROVIDER_CERT
*provCert
= WTHelperGetProvCertFromChain(provSigner
,
4077 pCertViewInfo
->idxCert
);
4079 set_certificate_status(status
, provCert
);
4082 static void show_cert_hierarchy(HWND hwnd
, struct hierarchy_data
*data
)
4084 /* Disable view certificate button until a certificate is selected */
4085 EnableWindow(GetDlgItem(hwnd
, IDC_VIEWCERTIFICATE
), FALSE
);
4086 show_cert_chain(hwnd
, data
);
4087 set_certificate_status_for_end_cert(hwnd
, data
->pCertViewInfo
);
4090 static void show_dialog_for_selected_cert(HWND hwnd
)
4092 HWND tree
= GetDlgItem(hwnd
, IDC_CERTPATH
);
4094 struct hierarchy_data
*data
;
4097 memset(&item
, 0, sizeof(item
));
4098 item
.mask
= TVIF_HANDLE
| TVIF_PARAM
;
4099 item
.hItem
= (HTREEITEM
)SendMessageW(tree
, TVM_GETNEXTITEM
, TVGN_CARET
, 0);
4100 SendMessageW(tree
, TVM_GETITEMW
, 0, (LPARAM
)&item
);
4101 data
= get_hierarchy_data_from_tree_item(tree
, item
.hItem
);
4102 selection
= lparam_to_index(data
, item
.lParam
);
4105 CRYPT_PROVIDER_SGNR
*provSigner
;
4106 CRYPTUI_VIEWCERTIFICATE_STRUCTW viewInfo
;
4107 BOOL changed
= FALSE
;
4109 provSigner
= WTHelperGetProvSignerFromChain(
4110 (CRYPT_PROVIDER_DATA
*)data
->pCertViewInfo
->u
.pCryptProviderData
,
4111 data
->pCertViewInfo
->idxSigner
,
4112 data
->pCertViewInfo
->fCounterSigner
,
4113 data
->pCertViewInfo
->idxCounterSigner
);
4114 memset(&viewInfo
, 0, sizeof(viewInfo
));
4115 viewInfo
.dwSize
= sizeof(viewInfo
);
4116 viewInfo
.dwFlags
= data
->pCertViewInfo
->dwFlags
;
4117 viewInfo
.szTitle
= data
->pCertViewInfo
->szTitle
;
4118 viewInfo
.pCertContext
= provSigner
->pasCertChain
[selection
].pCert
;
4119 viewInfo
.cStores
= data
->pCertViewInfo
->cStores
;
4120 viewInfo
.rghStores
= data
->pCertViewInfo
->rghStores
;
4121 viewInfo
.cPropSheetPages
= data
->pCertViewInfo
->cPropSheetPages
;
4122 viewInfo
.rgPropSheetPages
= data
->pCertViewInfo
->rgPropSheetPages
;
4123 viewInfo
.nStartPage
= data
->pCertViewInfo
->nStartPage
;
4124 CryptUIDlgViewCertificateW(&viewInfo
, &changed
);
4127 /* Delete the contents of the tree */
4128 SendMessageW(tree
, TVM_DELETEITEM
, 0, (LPARAM
)TVI_ROOT
);
4129 /* Reinitialize the tree */
4130 show_cert_hierarchy(hwnd
, data
);
4135 static LRESULT CALLBACK
hierarchy_dlg_proc(HWND hwnd
, UINT msg
, WPARAM wp
,
4138 PROPSHEETPAGEW
*page
;
4139 struct hierarchy_data
*data
;
4141 HWND tree
= GetDlgItem(hwnd
, IDC_CERTPATH
);
4143 TRACE("(%p, %08x, %08lx, %08lx)\n", hwnd
, msg
, wp
, lp
);
4148 page
= (PROPSHEETPAGEW
*)lp
;
4149 data
= (struct hierarchy_data
*)page
->lParam
;
4150 show_cert_hierarchy(hwnd
, data
);
4159 case TVN_SELCHANGEDW
:
4161 NMTREEVIEWW
*nm
= (NMTREEVIEWW
*)lp
;
4163 CRYPT_PROVIDER_SGNR
*provSigner
;
4165 data
= get_hierarchy_data_from_tree_item(tree
, nm
->itemNew
.hItem
);
4166 selection
= lparam_to_index(data
, nm
->itemNew
.lParam
);
4167 provSigner
= WTHelperGetProvSignerFromChain(
4168 (CRYPT_PROVIDER_DATA
*)data
->pCertViewInfo
->u
.pCryptProviderData
,
4169 data
->pCertViewInfo
->idxSigner
,
4170 data
->pCertViewInfo
->fCounterSigner
,
4171 data
->pCertViewInfo
->idxCounterSigner
);
4172 EnableWindow(GetDlgItem(hwnd
, IDC_VIEWCERTIFICATE
), selection
!= 0);
4173 set_certificate_status(GetDlgItem(hwnd
, IDC_CERTIFICATESTATUSTEXT
),
4174 &provSigner
->pasCertChain
[selection
]);
4178 show_dialog_for_selected_cert(hwnd
);
4179 SetWindowLongPtrW(hwnd
, DWLP_MSGRESULT
, 1);
4188 case IDC_VIEWCERTIFICATE
:
4189 show_dialog_for_selected_cert(hwnd
);
4193 case WM_REFRESH_VIEW
:
4197 /* Get hierarchy data */
4198 memset(&item
, 0, sizeof(item
));
4199 item
.mask
= TVIF_HANDLE
| TVIF_PARAM
;
4200 item
.hItem
= (HTREEITEM
)SendMessageW(tree
, TVM_GETNEXTITEM
, TVGN_ROOT
,
4202 data
= get_hierarchy_data_from_tree_item(tree
, item
.hItem
);
4203 /* Delete the contents of the tree */
4204 SendMessageW(tree
, TVM_DELETEITEM
, 0, (LPARAM
)TVI_ROOT
);
4205 /* Reinitialize the tree */
4206 show_cert_hierarchy(hwnd
, data
);
4213 static UINT CALLBACK
hierarchy_callback(HWND hwnd
, UINT msg
,
4214 PROPSHEETPAGEW
*page
)
4216 struct hierarchy_data
*data
;
4221 data
= (struct hierarchy_data
*)page
->lParam
;
4222 ImageList_Destroy(data
->imageList
);
4223 HeapFree(GetProcessHeap(), 0, data
);
4229 static BOOL
init_hierarchy_page(PCCRYPTUI_VIEWCERTIFICATE_STRUCTW pCertViewInfo
,
4230 PROPSHEETPAGEW
*page
)
4232 struct hierarchy_data
*data
= HeapAlloc(GetProcessHeap(), 0,
4233 sizeof(struct hierarchy_data
));
4238 data
->imageList
= ImageList_Create(16, 16, ILC_COLOR4
| ILC_MASK
, 2, 0);
4239 if (data
->imageList
)
4242 COLORREF backColor
= RGB(255, 0, 255);
4244 data
->pCertViewInfo
= pCertViewInfo
;
4245 data
->selectedCert
= 0xffffffff;
4247 bmp
= LoadBitmapW(hInstance
, MAKEINTRESOURCEW(IDB_SMALL_ICONS
));
4248 ImageList_AddMasked(data
->imageList
, bmp
, backColor
);
4250 ImageList_SetBkColor(data
->imageList
, CLR_NONE
);
4252 memset(page
, 0, sizeof(PROPSHEETPAGEW
));
4253 page
->dwSize
= sizeof(PROPSHEETPAGEW
);
4254 page
->dwFlags
= PSP_USECALLBACK
;
4255 page
->hInstance
= hInstance
;
4256 page
->u
.pszTemplate
= MAKEINTRESOURCEW(IDD_HIERARCHY
);
4257 page
->pfnDlgProc
= hierarchy_dlg_proc
;
4258 page
->lParam
= (LPARAM
)data
;
4259 page
->pfnCallback
= hierarchy_callback
;
4263 HeapFree(GetProcessHeap(), 0, data
);
4268 static int CALLBACK
cert_prop_sheet_proc(HWND hwnd
, UINT msg
, LPARAM lp
)
4272 TRACE("(%p, %08x, %08lx)\n", hwnd
, msg
, lp
);
4276 case PSCB_INITIALIZED
:
4277 /* Get cancel button's position.. */
4278 GetWindowRect(GetDlgItem(hwnd
, IDCANCEL
), &rc
);
4279 MapWindowPoints( 0, hwnd
, (POINT
*)&rc
, 2 );
4280 /* hide the cancel button.. */
4281 ShowWindow(GetDlgItem(hwnd
, IDCANCEL
), FALSE
);
4282 /* and move the OK button to the cancel button's original position. */
4283 SetWindowPos(GetDlgItem(hwnd
, IDOK
), 0, rc
.left
, rc
.top
, 0, 0,
4284 SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
);
4290 static BOOL
show_cert_dialog(PCCRYPTUI_VIEWCERTIFICATE_STRUCTW pCertViewInfo
,
4291 CRYPT_PROVIDER_CERT
*provCert
, BOOL
*pfPropertiesChanged
)
4293 static const WCHAR riched
[] = { 'r','i','c','h','e','d','2','0',0 };
4295 PROPSHEETPAGEW
*pages
;
4297 HMODULE lib
= LoadLibraryW(riched
);
4299 nPages
= pCertViewInfo
->cPropSheetPages
+ 1; /* one for the General tab */
4300 if (!(pCertViewInfo
->dwFlags
& CRYPTUI_HIDE_DETAILPAGE
))
4302 if (!(pCertViewInfo
->dwFlags
& CRYPTUI_HIDE_HIERARCHYPAGE
))
4304 pages
= HeapAlloc(GetProcessHeap(), 0, nPages
* sizeof(PROPSHEETPAGEW
));
4307 PROPSHEETHEADERW hdr
;
4308 CRYPTUI_INITDIALOG_STRUCT
*init
= NULL
;
4311 memset(&hdr
, 0, sizeof(hdr
));
4312 hdr
.dwSize
= sizeof(hdr
);
4313 hdr
.dwFlags
= PSH_NOAPPLYNOW
| PSH_PROPSHEETPAGE
| PSH_USECALLBACK
;
4314 hdr
.hInstance
= hInstance
;
4315 if (pCertViewInfo
->szTitle
)
4316 hdr
.pszCaption
= pCertViewInfo
->szTitle
;
4318 hdr
.pszCaption
= MAKEINTRESOURCEW(IDS_CERTIFICATE
);
4319 init_general_page(pCertViewInfo
, &pages
[hdr
.nPages
++]);
4320 if (!(pCertViewInfo
->dwFlags
& CRYPTUI_HIDE_DETAILPAGE
))
4322 if (init_detail_page(pCertViewInfo
, pfPropertiesChanged
,
4323 &pages
[hdr
.nPages
]))
4326 if (!(pCertViewInfo
->dwFlags
& CRYPTUI_HIDE_HIERARCHYPAGE
))
4328 if (init_hierarchy_page(pCertViewInfo
, &pages
[hdr
.nPages
]))
4331 /* Copy each additional page, and create the init dialog struct for it
4333 if (pCertViewInfo
->cPropSheetPages
)
4335 init
= HeapAlloc(GetProcessHeap(), 0,
4336 pCertViewInfo
->cPropSheetPages
*
4337 sizeof(CRYPTUI_INITDIALOG_STRUCT
));
4340 for (i
= 0; i
< pCertViewInfo
->cPropSheetPages
; i
++)
4342 memcpy(&pages
[hdr
.nPages
+ i
],
4343 &pCertViewInfo
->rgPropSheetPages
[i
],
4344 sizeof(PROPSHEETPAGEW
));
4345 init
[i
].lParam
= pCertViewInfo
->rgPropSheetPages
[i
].lParam
;
4346 init
[i
].pCertContext
= pCertViewInfo
->pCertContext
;
4347 pages
[hdr
.nPages
+ i
].lParam
= (LPARAM
)&init
[i
];
4349 if (pCertViewInfo
->nStartPage
& 0x8000)
4351 /* Start page index is relative to the number of default
4354 hdr
.u2
.nStartPage
= pCertViewInfo
->nStartPage
+ hdr
.nPages
;
4357 hdr
.u2
.nStartPage
= pCertViewInfo
->nStartPage
;
4358 hdr
.nPages
= nPages
;
4362 SetLastError(ERROR_OUTOFMEMORY
);
4366 /* Ignore the relative flag if there aren't any additional pages */
4367 hdr
.u2
.nStartPage
= pCertViewInfo
->nStartPage
& 0x7fff;
4374 hdr
.u3
.ppsp
= pages
;
4375 hdr
.pfnCallback
= cert_prop_sheet_proc
;
4376 l
= PropertySheetW(&hdr
);
4379 SetLastError(ERROR_CANCELLED
);
4383 HeapFree(GetProcessHeap(), 0, init
);
4384 HeapFree(GetProcessHeap(), 0, pages
);
4387 SetLastError(ERROR_OUTOFMEMORY
);
4392 /***********************************************************************
4393 * CryptUIDlgViewCertificateW (CRYPTUI.@)
4395 BOOL WINAPI
CryptUIDlgViewCertificateW(
4396 PCCRYPTUI_VIEWCERTIFICATE_STRUCTW pCertViewInfo
, BOOL
*pfPropertiesChanged
)
4398 static GUID generic_cert_verify
= WINTRUST_ACTION_GENERIC_CERT_VERIFY
;
4399 CRYPTUI_VIEWCERTIFICATE_STRUCTW viewInfo
;
4401 WINTRUST_CERT_INFO cert
;
4403 CRYPT_PROVIDER_SGNR
*signer
;
4404 CRYPT_PROVIDER_CERT
*provCert
= NULL
;
4406 TRACE("(%p, %p)\n", pCertViewInfo
, pfPropertiesChanged
);
4408 if (pCertViewInfo
->dwSize
!= sizeof(CRYPTUI_VIEWCERTIFICATE_STRUCTW
))
4410 SetLastError(ERROR_INVALID_PARAMETER
);
4413 /* Make a local copy in case we have to call WinVerifyTrust ourselves */
4414 memcpy(&viewInfo
, pCertViewInfo
, sizeof(viewInfo
));
4415 if (!pCertViewInfo
->u
.hWVTStateData
)
4417 memset(&wvt
, 0, sizeof(wvt
));
4418 wvt
.cbStruct
= sizeof(wvt
);
4419 wvt
.dwUIChoice
= WTD_UI_NONE
;
4420 if (viewInfo
.dwFlags
&
4421 CRYPTUI_ENABLE_REVOCATION_CHECK_CHAIN_EXCLUDE_ROOT
)
4422 wvt
.fdwRevocationChecks
|= WTD_REVOCATION_CHECK_CHAIN_EXCLUDE_ROOT
;
4423 if (viewInfo
.dwFlags
& CRYPTUI_ENABLE_REVOCATION_CHECK_END_CERT
)
4424 wvt
.fdwRevocationChecks
|= WTD_REVOCATION_CHECK_END_CERT
;
4425 if (viewInfo
.dwFlags
& CRYPTUI_ENABLE_REVOCATION_CHECK_CHAIN
)
4426 wvt
.fdwRevocationChecks
|= WTD_REVOCATION_CHECK_CHAIN
;
4427 wvt
.dwUnionChoice
= WTD_CHOICE_CERT
;
4428 memset(&cert
, 0, sizeof(cert
));
4429 cert
.cbStruct
= sizeof(cert
);
4430 cert
.psCertContext
= (CERT_CONTEXT
*)viewInfo
.pCertContext
;
4431 cert
.chStores
= viewInfo
.cStores
;
4432 cert
.pahStores
= viewInfo
.rghStores
;
4433 wvt
.u
.pCert
= &cert
;
4434 wvt
.dwStateAction
= WTD_STATEACTION_VERIFY
;
4435 WinVerifyTrust(NULL
, &generic_cert_verify
, &wvt
);
4436 viewInfo
.u
.pCryptProviderData
=
4437 WTHelperProvDataFromStateData(wvt
.hWVTStateData
);
4438 signer
= WTHelperGetProvSignerFromChain(
4439 (CRYPT_PROVIDER_DATA
*)viewInfo
.u
.pCryptProviderData
, 0, FALSE
, 0);
4440 provCert
= WTHelperGetProvCertFromChain(signer
, 0);
4445 viewInfo
.u
.pCryptProviderData
=
4446 WTHelperProvDataFromStateData(viewInfo
.u
.hWVTStateData
);
4447 signer
= WTHelperGetProvSignerFromChain(
4448 (CRYPT_PROVIDER_DATA
*)viewInfo
.u
.pCryptProviderData
,
4449 viewInfo
.idxSigner
, viewInfo
.fCounterSigner
,
4450 viewInfo
.idxCounterSigner
);
4451 provCert
= WTHelperGetProvCertFromChain(signer
, viewInfo
.idxCert
);
4456 ret
= show_cert_dialog(&viewInfo
, provCert
, pfPropertiesChanged
);
4457 if (!pCertViewInfo
->u
.hWVTStateData
)
4459 wvt
.dwStateAction
= WTD_STATEACTION_CLOSE
;
4460 WinVerifyTrust(NULL
, &generic_cert_verify
, &wvt
);
4466 /***********************************************************************
4467 * CryptUIDlgViewContext (CRYPTUI.@)
4469 BOOL WINAPI
CryptUIDlgViewContext(DWORD dwContextType
, LPVOID pvContext
,
4470 HWND hwnd
, LPCWSTR pwszTitle
, DWORD dwFlags
, LPVOID pvReserved
)
4474 TRACE("(%d, %p, %p, %s, %08x, %p)\n", dwContextType
, pvContext
, hwnd
,
4475 debugstr_w(pwszTitle
), dwFlags
, pvReserved
);
4477 switch (dwContextType
)
4479 case CERT_STORE_CERTIFICATE_CONTEXT
:
4481 CRYPTUI_VIEWCERTIFICATE_STRUCTW viewInfo
;
4483 memset(&viewInfo
, 0, sizeof(viewInfo
));
4484 viewInfo
.dwSize
= sizeof(viewInfo
);
4485 viewInfo
.hwndParent
= hwnd
;
4486 viewInfo
.szTitle
= pwszTitle
;
4487 viewInfo
.pCertContext
= pvContext
;
4488 ret
= CryptUIDlgViewCertificateW(&viewInfo
, NULL
);
4492 FIXME("unimplemented for context type %d\n", dwContextType
);
4493 SetLastError(E_INVALIDARG
);
4499 /* Decodes a cert's basic constraints extension (either szOID_BASIC_CONSTRAINTS
4500 * or szOID_BASIC_CONSTRAINTS2, whichever is present) to determine if it
4501 * should be a CA. If neither extension is present, returns
4502 * defaultIfNotSpecified.
4504 static BOOL
is_ca_cert(PCCERT_CONTEXT cert
, BOOL defaultIfNotSpecified
)
4506 BOOL isCA
= defaultIfNotSpecified
;
4507 PCERT_EXTENSION ext
= CertFindExtension(szOID_BASIC_CONSTRAINTS
,
4508 cert
->pCertInfo
->cExtension
, cert
->pCertInfo
->rgExtension
);
4512 CERT_BASIC_CONSTRAINTS_INFO
*info
;
4515 if (CryptDecodeObjectEx(X509_ASN_ENCODING
, szOID_BASIC_CONSTRAINTS
,
4516 ext
->Value
.pbData
, ext
->Value
.cbData
, CRYPT_DECODE_ALLOC_FLAG
,
4517 NULL
, &info
, &size
))
4519 if (info
->SubjectType
.cbData
== 1)
4520 isCA
= info
->SubjectType
.pbData
[0] & CERT_CA_SUBJECT_FLAG
;
4526 ext
= CertFindExtension(szOID_BASIC_CONSTRAINTS2
,
4527 cert
->pCertInfo
->cExtension
, cert
->pCertInfo
->rgExtension
);
4530 CERT_BASIC_CONSTRAINTS2_INFO info
;
4531 DWORD size
= sizeof(CERT_BASIC_CONSTRAINTS2_INFO
);
4533 if (CryptDecodeObjectEx(X509_ASN_ENCODING
,
4534 szOID_BASIC_CONSTRAINTS2
, ext
->Value
.pbData
, ext
->Value
.cbData
,
4535 0, NULL
, &info
, &size
))
4542 static HCERTSTORE
choose_store_for_cert(PCCERT_CONTEXT cert
)
4546 if (is_ca_cert(cert
, TRUE
))
4549 storeName
= addressBook
;
4550 return CertOpenStore(CERT_STORE_PROV_SYSTEM_W
, 0, 0,
4551 CERT_SYSTEM_STORE_CURRENT_USER
, storeName
);
4554 static BOOL
import_cert(PCCERT_CONTEXT cert
, HCERTSTORE hDestCertStore
)
4561 SetLastError(E_INVALIDARG
);
4564 if (hDestCertStore
) store
= hDestCertStore
;
4567 if (!(store
= choose_store_for_cert(cert
)))
4569 WARN("unable to open certificate store\n");
4573 ret
= CertAddCertificateContextToStore(store
, cert
,
4574 CERT_STORE_ADD_REPLACE_EXISTING_INHERIT_PROPERTIES
, NULL
);
4575 if (!hDestCertStore
) CertCloseStore(store
, 0);
4579 static BOOL
import_crl(PCCRL_CONTEXT crl
, HCERTSTORE hDestCertStore
)
4586 SetLastError(E_INVALIDARG
);
4589 if (hDestCertStore
) store
= hDestCertStore
;
4592 if (!(store
= CertOpenStore(CERT_STORE_PROV_SYSTEM_W
, 0, 0,
4593 CERT_SYSTEM_STORE_CURRENT_USER
, ca
)))
4595 WARN("unable to open certificate store\n");
4599 ret
= CertAddCRLContextToStore(store
, crl
,
4600 CERT_STORE_ADD_REPLACE_EXISTING_INHERIT_PROPERTIES
, NULL
);
4601 if (!hDestCertStore
) CertCloseStore(store
, 0);
4605 static BOOL
import_ctl(PCCTL_CONTEXT ctl
, HCERTSTORE hDestCertStore
)
4612 SetLastError(E_INVALIDARG
);
4615 if (hDestCertStore
) store
= hDestCertStore
;
4618 static const WCHAR trust
[] = { 'T','r','u','s','t',0 };
4620 if (!(store
= CertOpenStore(CERT_STORE_PROV_SYSTEM_W
, 0, 0,
4621 CERT_SYSTEM_STORE_CURRENT_USER
, trust
)))
4623 WARN("unable to open certificate store\n");
4627 ret
= CertAddCTLContextToStore(store
, ctl
,
4628 CERT_STORE_ADD_REPLACE_EXISTING_INHERIT_PROPERTIES
, NULL
);
4629 if (!hDestCertStore
) CertCloseStore(store
, 0);
4633 /* Checks type, a type such as CERT_QUERY_CONTENT_CERT returned by
4634 * CryptQueryObject, against the allowed types. Returns TRUE if the
4635 * type is allowed, FALSE otherwise.
4637 static BOOL
check_context_type(DWORD dwFlags
, DWORD type
)
4642 (CRYPTUI_WIZ_IMPORT_ALLOW_CERT
| CRYPTUI_WIZ_IMPORT_ALLOW_CRL
|
4643 CRYPTUI_WIZ_IMPORT_ALLOW_CTL
))
4647 case CERT_QUERY_CONTENT_CERT
:
4648 case CERT_QUERY_CONTENT_SERIALIZED_CERT
:
4649 ret
= dwFlags
& CRYPTUI_WIZ_IMPORT_ALLOW_CERT
;
4651 case CERT_QUERY_CONTENT_CRL
:
4652 case CERT_QUERY_CONTENT_SERIALIZED_CRL
:
4653 ret
= dwFlags
& CRYPTUI_WIZ_IMPORT_ALLOW_CRL
;
4655 case CERT_QUERY_CONTENT_CTL
:
4656 case CERT_QUERY_CONTENT_SERIALIZED_CTL
:
4657 ret
= dwFlags
& CRYPTUI_WIZ_IMPORT_ALLOW_CTL
;
4660 /* The remaining types contain more than one type, so allow
4668 /* No allowed types specified, so any type is allowed */
4672 SetLastError(E_INVALIDARG
);
4677 static void import_warning(DWORD dwFlags
, HWND hwnd
, LPCWSTR szTitle
,
4680 if (!(dwFlags
& CRYPTUI_WIZ_NO_UI
))
4682 WCHAR title
[MAX_STRING_LEN
], error
[MAX_STRING_LEN
];
4689 LoadStringW(hInstance
, IDS_IMPORT_WIZARD
, title
, ARRAY_SIZE(title
));
4692 LoadStringW(hInstance
, warningID
, error
, ARRAY_SIZE(error
));
4693 MessageBoxW(hwnd
, error
, pTitle
, MB_ICONERROR
| MB_OK
);
4697 static void import_warn_type_mismatch(DWORD dwFlags
, HWND hwnd
, LPCWSTR szTitle
)
4699 import_warning(dwFlags
, hwnd
, szTitle
, IDS_IMPORT_TYPE_MISMATCH
);
4702 static BOOL
check_store_context_type(DWORD dwFlags
, HCERTSTORE store
)
4707 (CRYPTUI_WIZ_IMPORT_ALLOW_CERT
| CRYPTUI_WIZ_IMPORT_ALLOW_CRL
|
4708 CRYPTUI_WIZ_IMPORT_ALLOW_CTL
))
4710 PCCERT_CONTEXT cert
;
4715 if ((cert
= CertEnumCertificatesInStore(store
, NULL
)))
4717 CertFreeCertificateContext(cert
);
4718 if (!(dwFlags
& CRYPTUI_WIZ_IMPORT_ALLOW_CERT
))
4721 if (ret
&& (crl
= CertEnumCRLsInStore(store
, NULL
)))
4723 CertFreeCRLContext(crl
);
4724 if (!(dwFlags
& CRYPTUI_WIZ_IMPORT_ALLOW_CRL
))
4727 if (ret
&& (ctl
= CertEnumCTLsInStore(store
, NULL
)))
4729 CertFreeCTLContext(ctl
);
4730 if (!(dwFlags
& CRYPTUI_WIZ_IMPORT_ALLOW_CTL
))
4737 SetLastError(E_INVALIDARG
);
4741 static BOOL
import_store(DWORD dwFlags
, HWND hwnd
, LPCWSTR szTitle
,
4742 HCERTSTORE source
, HCERTSTORE dest
)
4746 if ((ret
= check_store_context_type(dwFlags
, source
)))
4748 PCCERT_CONTEXT cert
= NULL
;
4749 PCCRL_CONTEXT crl
= NULL
;
4750 PCCTL_CONTEXT ctl
= NULL
;
4753 cert
= CertEnumCertificatesInStore(source
, cert
);
4755 ret
= import_cert(cert
, dest
);
4756 } while (ret
&& cert
);
4758 crl
= CertEnumCRLsInStore(source
, crl
);
4760 ret
= import_crl(crl
, dest
);
4761 } while (ret
&& crl
);
4763 ctl
= CertEnumCTLsInStore(source
, ctl
);
4765 ret
= import_ctl(ctl
, dest
);
4766 } while (ret
&& ctl
);
4769 import_warn_type_mismatch(dwFlags
, hwnd
, szTitle
);
4773 static HCERTSTORE
open_store_from_file(DWORD dwFlags
, LPCWSTR fileName
,
4774 DWORD
*pContentType
)
4776 HCERTSTORE store
= NULL
;
4777 DWORD contentType
= 0, expectedContentTypeFlags
;
4780 (CRYPTUI_WIZ_IMPORT_ALLOW_CERT
| CRYPTUI_WIZ_IMPORT_ALLOW_CRL
|
4781 CRYPTUI_WIZ_IMPORT_ALLOW_CTL
))
4783 expectedContentTypeFlags
=
4784 CERT_QUERY_CONTENT_FLAG_SERIALIZED_STORE
|
4785 CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED
|
4786 CERT_QUERY_CONTENT_FLAG_PFX
;
4787 if (dwFlags
& CRYPTUI_WIZ_IMPORT_ALLOW_CERT
)
4788 expectedContentTypeFlags
|=
4789 CERT_QUERY_CONTENT_FLAG_CERT
|
4790 CERT_QUERY_CONTENT_FLAG_SERIALIZED_CERT
;
4791 if (dwFlags
& CRYPTUI_WIZ_IMPORT_ALLOW_CRL
)
4792 expectedContentTypeFlags
|=
4793 CERT_QUERY_CONTENT_FLAG_SERIALIZED_CRL
|
4794 CERT_QUERY_CONTENT_FLAG_CRL
;
4795 if (dwFlags
& CRYPTUI_WIZ_IMPORT_ALLOW_CTL
)
4796 expectedContentTypeFlags
|=
4797 CERT_QUERY_CONTENT_FLAG_CTL
|
4798 CERT_QUERY_CONTENT_FLAG_SERIALIZED_CTL
;
4801 expectedContentTypeFlags
=
4802 CERT_QUERY_CONTENT_FLAG_CERT
|
4803 CERT_QUERY_CONTENT_FLAG_CTL
|
4804 CERT_QUERY_CONTENT_FLAG_CRL
|
4805 CERT_QUERY_CONTENT_FLAG_SERIALIZED_STORE
|
4806 CERT_QUERY_CONTENT_FLAG_SERIALIZED_CERT
|
4807 CERT_QUERY_CONTENT_FLAG_SERIALIZED_CTL
|
4808 CERT_QUERY_CONTENT_FLAG_SERIALIZED_CRL
|
4809 CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED
|
4810 CERT_QUERY_CONTENT_FLAG_PFX
;
4812 CryptQueryObject(CERT_QUERY_OBJECT_FILE
, fileName
,
4813 expectedContentTypeFlags
, CERT_QUERY_FORMAT_FLAG_ALL
, 0, NULL
,
4814 &contentType
, NULL
, &store
, NULL
, NULL
);
4816 *pContentType
= contentType
;
4820 static BOOL
import_file(DWORD dwFlags
, HWND hwnd
, LPCWSTR szTitle
,
4821 LPCWSTR fileName
, HCERTSTORE dest
)
4826 if ((source
= open_store_from_file(dwFlags
, fileName
, NULL
)))
4828 ret
= import_store(dwFlags
, hwnd
, szTitle
, source
, dest
);
4829 CertCloseStore(source
, 0);
4836 struct ImportWizData
4840 LPCWSTR pwszWizardTitle
;
4841 CRYPTUI_WIZ_IMPORT_SRC_INFO importSrc
;
4845 HCERTSTORE hDestCertStore
;
4851 static LRESULT CALLBACK
import_welcome_dlg_proc(HWND hwnd
, UINT msg
, WPARAM wp
,
4860 struct ImportWizData
*data
;
4861 PROPSHEETPAGEW
*page
= (PROPSHEETPAGEW
*)lp
;
4862 WCHAR fontFace
[MAX_STRING_LEN
];
4863 HDC hDC
= GetDC(hwnd
);
4866 data
= (struct ImportWizData
*)page
->lParam
;
4867 LoadStringW(hInstance
, IDS_WIZARD_TITLE_FONT
, fontFace
, ARRAY_SIZE(fontFace
));
4868 height
= -MulDiv(12, GetDeviceCaps(hDC
, LOGPIXELSY
), 72);
4869 data
->titleFont
= CreateFontW(height
, 0, 0, 0, FW_BOLD
, 0, 0, 0,
4870 DEFAULT_CHARSET
, OUT_DEFAULT_PRECIS
, CLIP_DEFAULT_PRECIS
,
4871 DEFAULT_QUALITY
, DEFAULT_PITCH
| FF_DONTCARE
, fontFace
);
4872 SendMessageW(GetDlgItem(hwnd
, IDC_IMPORT_TITLE
), WM_SETFONT
,
4873 (WPARAM
)data
->titleFont
, TRUE
);
4874 ReleaseDC(hwnd
, hDC
);
4879 NMHDR
*hdr
= (NMHDR
*)lp
;
4884 PostMessageW(GetParent(hwnd
), PSM_SETWIZBUTTONS
, 0, PSWIZB_NEXT
);
4894 static const WCHAR filter_cert
[] = { '*','.','c','e','r',';','*','.',
4896 static const WCHAR filter_pfx
[] = { '*','.','p','f','x',';','*','.',
4898 static const WCHAR filter_crl
[] = { '*','.','c','r','l',0 };
4899 static const WCHAR filter_ctl
[] = { '*','.','s','t','l',0 };
4900 static const WCHAR filter_serialized_store
[] = { '*','.','s','s','t',0 };
4901 static const WCHAR filter_cms
[] = { '*','.','s','p','c',';','*','.',
4903 static const WCHAR filter_all
[] = { '*','.','*',0 };
4910 } import_filters
[] = {
4911 { IDS_IMPORT_FILTER_CERT
, CRYPTUI_WIZ_IMPORT_ALLOW_CERT
, filter_cert
},
4912 { IDS_IMPORT_FILTER_PFX
, 0, filter_pfx
},
4913 { IDS_IMPORT_FILTER_CRL
, CRYPTUI_WIZ_IMPORT_ALLOW_CRL
, filter_crl
},
4914 { IDS_IMPORT_FILTER_CTL
, CRYPTUI_WIZ_IMPORT_ALLOW_CTL
, filter_ctl
},
4915 { IDS_IMPORT_FILTER_SERIALIZED_STORE
, 0, filter_serialized_store
},
4916 { IDS_IMPORT_FILTER_CMS
, 0, filter_cms
},
4917 { IDS_IMPORT_FILTER_ALL
, 0, filter_all
},
4920 static WCHAR
*make_import_file_filter(DWORD dwFlags
)
4923 int len
, totalLen
= 2;
4924 LPWSTR filter
= NULL
, str
;
4926 for (i
= 0; i
< ARRAY_SIZE(import_filters
); i
++)
4928 if (!import_filters
[i
].allowFlags
|| !dwFlags
||
4929 (dwFlags
& import_filters
[i
].allowFlags
))
4931 len
= LoadStringW(hInstance
, import_filters
[i
].id
, (LPWSTR
)&str
, 0);
4932 totalLen
+= len
+ lstrlenW(import_filters
[i
].filter
) + 2;
4935 filter
= HeapAlloc(GetProcessHeap(), 0, totalLen
* sizeof(WCHAR
));
4941 for (i
= 0; i
< ARRAY_SIZE(import_filters
); i
++)
4943 if (!import_filters
[i
].allowFlags
|| !dwFlags
||
4944 (dwFlags
& import_filters
[i
].allowFlags
))
4946 len
= LoadStringW(hInstance
, import_filters
[i
].id
,
4948 memcpy(ptr
, str
, len
* sizeof(WCHAR
));
4951 lstrcpyW(ptr
, import_filters
[i
].filter
);
4952 ptr
+= lstrlenW(import_filters
[i
].filter
) + 1;
4960 static BOOL
import_validate_filename(HWND hwnd
, struct ImportWizData
*data
,
4966 file
= CreateFileW(fileName
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
4967 OPEN_EXISTING
, 0, NULL
);
4968 if (file
!= INVALID_HANDLE_VALUE
)
4970 HCERTSTORE source
= open_store_from_file(data
->dwFlags
, fileName
,
4971 &data
->contentType
);
4975 warningID
= IDS_IMPORT_BAD_FORMAT
;
4976 else if (!check_store_context_type(data
->dwFlags
, source
))
4977 warningID
= IDS_IMPORT_TYPE_MISMATCH
;
4980 data
->importSrc
.dwSubjectChoice
=
4981 CRYPTUI_WIZ_IMPORT_SUBJECT_CERT_STORE
;
4982 data
->importSrc
.u
.hCertStore
= source
;
4983 data
->freeSource
= TRUE
;
4988 import_warning(data
->dwFlags
, hwnd
, data
->pwszWizardTitle
,
4995 WCHAR title
[MAX_STRING_LEN
], error
[MAX_STRING_LEN
];
4997 LPWSTR msgBuf
, fullError
;
4999 if (data
->pwszWizardTitle
)
5000 pTitle
= data
->pwszWizardTitle
;
5003 LoadStringW(hInstance
, IDS_IMPORT_WIZARD
, title
, ARRAY_SIZE(title
));
5006 LoadStringW(hInstance
, IDS_IMPORT_OPEN_FAILED
, error
, ARRAY_SIZE(error
));
5008 FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM
, NULL
,
5009 GetLastError(), 0, (LPWSTR
) &msgBuf
, 0, NULL
);
5010 fullError
= HeapAlloc(GetProcessHeap(), 0,
5011 (lstrlenW(error
) + lstrlenW(fileName
) + lstrlenW(msgBuf
) + 3)
5015 LPWSTR ptr
= fullError
;
5017 lstrcpyW(ptr
, error
);
5018 ptr
+= lstrlenW(error
);
5019 lstrcpyW(ptr
, fileName
);
5020 ptr
+= lstrlenW(fileName
);
5023 lstrcpyW(ptr
, msgBuf
);
5024 MessageBoxW(hwnd
, fullError
, pTitle
, MB_ICONERROR
| MB_OK
);
5025 HeapFree(GetProcessHeap(), 0, fullError
);
5032 static LRESULT CALLBACK
import_file_dlg_proc(HWND hwnd
, UINT msg
, WPARAM wp
,
5036 struct ImportWizData
*data
;
5042 PROPSHEETPAGEW
*page
= (PROPSHEETPAGEW
*)lp
;
5044 data
= (struct ImportWizData
*)page
->lParam
;
5045 SetWindowLongPtrW(hwnd
, DWLP_USER
, (LPARAM
)data
);
5048 HWND fileNameEdit
= GetDlgItem(hwnd
, IDC_IMPORT_FILENAME
);
5050 SendMessageW(fileNameEdit
, WM_SETTEXT
, 0, (LPARAM
)data
->fileName
);
5056 NMHDR
*hdr
= (NMHDR
*)lp
;
5061 PostMessageW(GetParent(hwnd
), PSM_SETWIZBUTTONS
, 0,
5062 PSWIZB_BACK
| PSWIZB_NEXT
);
5067 HWND fileNameEdit
= GetDlgItem(hwnd
, IDC_IMPORT_FILENAME
);
5068 DWORD len
= SendMessageW(fileNameEdit
, WM_GETTEXTLENGTH
, 0, 0);
5070 data
= (struct ImportWizData
*)GetWindowLongPtrW(hwnd
, DWLP_USER
);
5073 import_warning(data
->dwFlags
, hwnd
, data
->pwszWizardTitle
,
5074 IDS_IMPORT_EMPTY_FILE
);
5075 SetWindowLongPtrW(hwnd
, DWLP_MSGRESULT
, 1);
5080 LPWSTR fileName
= HeapAlloc(GetProcessHeap(), 0,
5081 (len
+ 1) * sizeof(WCHAR
));
5085 SendMessageW(fileNameEdit
, WM_GETTEXT
, len
+ 1,
5087 if (!import_validate_filename(hwnd
, data
, fileName
))
5089 HeapFree(GetProcessHeap(), 0, fileName
);
5090 SetWindowLongPtrW(hwnd
, DWLP_MSGRESULT
, 1);
5094 data
->fileName
= fileName
;
5105 case IDC_IMPORT_BROWSE_FILE
:
5108 WCHAR fileBuf
[MAX_PATH
];
5110 data
= (struct ImportWizData
*)GetWindowLongPtrW(hwnd
, DWLP_USER
);
5111 memset(&ofn
, 0, sizeof(ofn
));
5112 ofn
.lStructSize
= sizeof(ofn
);
5113 ofn
.hwndOwner
= hwnd
;
5114 ofn
.lpstrFilter
= make_import_file_filter(data
->dwFlags
);
5115 ofn
.lpstrFile
= fileBuf
;
5116 ofn
.nMaxFile
= ARRAY_SIZE(fileBuf
);
5118 if (GetOpenFileNameW(&ofn
))
5119 SendMessageW(GetDlgItem(hwnd
, IDC_IMPORT_FILENAME
), WM_SETTEXT
,
5120 0, (LPARAM
)ofn
.lpstrFile
);
5121 HeapFree(GetProcessHeap(), 0, (LPWSTR
)ofn
.lpstrFilter
);
5130 static LRESULT CALLBACK
import_store_dlg_proc(HWND hwnd
, UINT msg
, WPARAM wp
,
5134 struct ImportWizData
*data
;
5140 PROPSHEETPAGEW
*page
= (PROPSHEETPAGEW
*)lp
;
5142 data
= (struct ImportWizData
*)page
->lParam
;
5143 SetWindowLongPtrW(hwnd
, DWLP_USER
, (LPARAM
)data
);
5144 if (!data
->hDestCertStore
)
5146 SendMessageW(GetDlgItem(hwnd
, IDC_IMPORT_AUTO_STORE
), BM_CLICK
,
5148 EnableWindow(GetDlgItem(hwnd
, IDC_IMPORT_STORE
), FALSE
);
5149 EnableWindow(GetDlgItem(hwnd
, IDC_IMPORT_BROWSE_STORE
), FALSE
);
5150 EnableWindow(GetDlgItem(hwnd
, IDC_IMPORT_SPECIFY_STORE
), FALSE
);
5154 WCHAR storeTitle
[MAX_STRING_LEN
];
5156 SendMessageW(GetDlgItem(hwnd
, IDC_IMPORT_SPECIFY_STORE
), BM_CLICK
,
5158 EnableWindow(GetDlgItem(hwnd
, IDC_IMPORT_STORE
), TRUE
);
5159 EnableWindow(GetDlgItem(hwnd
, IDC_IMPORT_BROWSE_STORE
), TRUE
);
5160 EnableWindow(GetDlgItem(hwnd
, IDC_IMPORT_SPECIFY_STORE
),
5161 !(data
->dwFlags
& CRYPTUI_WIZ_IMPORT_NO_CHANGE_DEST_STORE
));
5162 LoadStringW(hInstance
, IDS_IMPORT_DEST_DETERMINED
, storeTitle
, ARRAY_SIZE(storeTitle
));
5163 SendMessageW(GetDlgItem(hwnd
, IDC_IMPORT_STORE
), WM_SETTEXT
,
5164 0, (LPARAM
)storeTitle
);
5170 NMHDR
*hdr
= (NMHDR
*)lp
;
5175 PostMessageW(GetParent(hwnd
), PSM_SETWIZBUTTONS
, 0,
5176 PSWIZB_BACK
| PSWIZB_NEXT
);
5181 data
= (struct ImportWizData
*)GetWindowLongPtrW(hwnd
, DWLP_USER
);
5182 if (IsDlgButtonChecked(hwnd
, IDC_IMPORT_SPECIFY_STORE
) &&
5183 !data
->hDestCertStore
)
5185 import_warning(data
->dwFlags
, hwnd
, data
->pwszWizardTitle
,
5186 IDS_IMPORT_SELECT_STORE
);
5187 SetWindowLongPtrW(hwnd
, DWLP_MSGRESULT
, 1);
5198 case IDC_IMPORT_AUTO_STORE
:
5199 data
= (struct ImportWizData
*)GetWindowLongPtrW(hwnd
, DWLP_USER
);
5200 data
->autoDest
= TRUE
;
5201 EnableWindow(GetDlgItem(hwnd
, IDC_IMPORT_STORE
), FALSE
);
5202 EnableWindow(GetDlgItem(hwnd
, IDC_IMPORT_BROWSE_STORE
), FALSE
);
5204 case IDC_IMPORT_SPECIFY_STORE
:
5205 data
= (struct ImportWizData
*)GetWindowLongPtrW(hwnd
, DWLP_USER
);
5206 data
->autoDest
= FALSE
;
5207 EnableWindow(GetDlgItem(hwnd
, IDC_IMPORT_STORE
), TRUE
);
5208 EnableWindow(GetDlgItem(hwnd
, IDC_IMPORT_BROWSE_STORE
), TRUE
);
5210 case IDC_IMPORT_BROWSE_STORE
:
5212 CRYPTUI_ENUM_SYSTEM_STORE_ARGS enumArgs
= {
5213 CERT_SYSTEM_STORE_CURRENT_USER
, NULL
};
5214 CRYPTUI_ENUM_DATA enumData
= { 0, NULL
, 1, &enumArgs
};
5215 CRYPTUI_SELECTSTORE_INFO_W selectInfo
;
5218 data
= (struct ImportWizData
*)GetWindowLongPtrW(hwnd
, DWLP_USER
);
5219 selectInfo
.dwSize
= sizeof(selectInfo
);
5220 selectInfo
.parent
= hwnd
;
5221 selectInfo
.dwFlags
= CRYPTUI_ENABLE_SHOW_PHYSICAL_STORE
;
5222 selectInfo
.pwszTitle
= NULL
;
5223 selectInfo
.pwszText
= NULL
;
5224 selectInfo
.pEnumData
= &enumData
;
5225 selectInfo
.pfnSelectedStoreCallback
= NULL
;
5226 if ((store
= CryptUIDlgSelectStoreW(&selectInfo
)))
5228 WCHAR storeTitle
[MAX_STRING_LEN
];
5230 LoadStringW(hInstance
, IDS_IMPORT_DEST_DETERMINED
, storeTitle
,
5231 ARRAY_SIZE(storeTitle
));
5232 SendMessageW(GetDlgItem(hwnd
, IDC_IMPORT_STORE
), WM_SETTEXT
,
5233 0, (LPARAM
)storeTitle
);
5234 data
->hDestCertStore
= store
;
5235 data
->freeDest
= TRUE
;
5245 static void show_import_details(HWND lv
, struct ImportWizData
*data
)
5247 WCHAR text
[MAX_STRING_LEN
];
5251 item
.mask
= LVIF_TEXT
;
5252 item
.iItem
= SendMessageW(lv
, LVM_GETITEMCOUNT
, 0, 0);
5254 LoadStringW(hInstance
, IDS_IMPORT_STORE_SELECTION
, text
, ARRAY_SIZE(text
));
5255 item
.pszText
= text
;
5256 SendMessageW(lv
, LVM_INSERTITEMW
, 0, (LPARAM
)&item
);
5259 LoadStringW(hInstance
, IDS_IMPORT_DEST_AUTOMATIC
, text
, ARRAY_SIZE(text
));
5261 LoadStringW(hInstance
, IDS_IMPORT_DEST_DETERMINED
, text
, ARRAY_SIZE(text
));
5262 SendMessageW(lv
, LVM_SETITEMTEXTW
, item
.iItem
, (LPARAM
)&item
);
5263 item
.iItem
= SendMessageW(lv
, LVM_GETITEMCOUNT
, 0, 0);
5265 LoadStringW(hInstance
, IDS_IMPORT_CONTENT
, text
, ARRAY_SIZE(text
));
5266 SendMessageW(lv
, LVM_INSERTITEMW
, 0, (LPARAM
)&item
);
5267 switch (data
->contentType
)
5269 case CERT_QUERY_CONTENT_CERT
:
5270 case CERT_QUERY_CONTENT_SERIALIZED_CERT
:
5271 contentID
= IDS_IMPORT_CONTENT_CERT
;
5273 case CERT_QUERY_CONTENT_CRL
:
5274 case CERT_QUERY_CONTENT_SERIALIZED_CRL
:
5275 contentID
= IDS_IMPORT_CONTENT_CRL
;
5277 case CERT_QUERY_CONTENT_CTL
:
5278 case CERT_QUERY_CONTENT_SERIALIZED_CTL
:
5279 contentID
= IDS_IMPORT_CONTENT_CTL
;
5281 case CERT_QUERY_CONTENT_PKCS7_SIGNED
:
5282 contentID
= IDS_IMPORT_CONTENT_CMS
;
5284 case CERT_QUERY_CONTENT_FLAG_PFX
:
5285 contentID
= IDS_IMPORT_CONTENT_PFX
;
5288 contentID
= IDS_IMPORT_CONTENT_STORE
;
5291 LoadStringW(hInstance
, contentID
, text
, ARRAY_SIZE(text
));
5293 SendMessageW(lv
, LVM_SETITEMTEXTW
, item
.iItem
, (LPARAM
)&item
);
5296 item
.iItem
= SendMessageW(lv
, LVM_GETITEMCOUNT
, 0, 0);
5298 LoadStringW(hInstance
, IDS_IMPORT_FILE
, text
, ARRAY_SIZE(text
));
5299 SendMessageW(lv
, LVM_INSERTITEMW
, 0, (LPARAM
)&item
);
5301 item
.pszText
= data
->fileName
;
5302 SendMessageW(lv
, LVM_SETITEMTEXTW
, item
.iItem
, (LPARAM
)&item
);
5306 static BOOL
do_import(DWORD dwFlags
, HWND hwndParent
, LPCWSTR pwszWizardTitle
,
5307 PCCRYPTUI_WIZ_IMPORT_SRC_INFO pImportSrc
, HCERTSTORE hDestCertStore
)
5311 switch (pImportSrc
->dwSubjectChoice
)
5313 case CRYPTUI_WIZ_IMPORT_SUBJECT_FILE
:
5314 ret
= import_file(dwFlags
, hwndParent
, pwszWizardTitle
,
5315 pImportSrc
->u
.pwszFileName
, hDestCertStore
);
5317 case CRYPTUI_WIZ_IMPORT_SUBJECT_CERT_CONTEXT
:
5318 if ((ret
= check_context_type(dwFlags
, CERT_QUERY_CONTENT_CERT
)))
5319 ret
= import_cert(pImportSrc
->u
.pCertContext
, hDestCertStore
);
5321 import_warn_type_mismatch(dwFlags
, hwndParent
, pwszWizardTitle
);
5323 case CRYPTUI_WIZ_IMPORT_SUBJECT_CRL_CONTEXT
:
5324 if ((ret
= check_context_type(dwFlags
, CERT_QUERY_CONTENT_CRL
)))
5325 ret
= import_crl(pImportSrc
->u
.pCRLContext
, hDestCertStore
);
5327 import_warn_type_mismatch(dwFlags
, hwndParent
, pwszWizardTitle
);
5329 case CRYPTUI_WIZ_IMPORT_SUBJECT_CTL_CONTEXT
:
5330 if ((ret
= check_context_type(dwFlags
, CERT_QUERY_CONTENT_CTL
)))
5331 ret
= import_ctl(pImportSrc
->u
.pCTLContext
, hDestCertStore
);
5333 import_warn_type_mismatch(dwFlags
, hwndParent
, pwszWizardTitle
);
5335 case CRYPTUI_WIZ_IMPORT_SUBJECT_CERT_STORE
:
5336 ret
= import_store(dwFlags
, hwndParent
, pwszWizardTitle
,
5337 pImportSrc
->u
.hCertStore
, hDestCertStore
);
5340 WARN("unknown source type: %u\n", pImportSrc
->dwSubjectChoice
);
5341 SetLastError(E_INVALIDARG
);
5347 static LRESULT CALLBACK
import_finish_dlg_proc(HWND hwnd
, UINT msg
, WPARAM wp
,
5351 struct ImportWizData
*data
;
5357 PROPSHEETPAGEW
*page
= (PROPSHEETPAGEW
*)lp
;
5358 HWND lv
= GetDlgItem(hwnd
, IDC_IMPORT_SETTINGS
);
5362 data
= (struct ImportWizData
*)page
->lParam
;
5363 SetWindowLongPtrW(hwnd
, DWLP_USER
, (LPARAM
)data
);
5364 SendMessageW(GetDlgItem(hwnd
, IDC_IMPORT_TITLE
), WM_SETFONT
,
5365 (WPARAM
)data
->titleFont
, TRUE
);
5366 GetWindowRect(lv
, &rc
);
5367 column
.mask
= LVCF_WIDTH
;
5368 column
.cx
= (rc
.right
- rc
.left
) / 2 - 2;
5369 SendMessageW(lv
, LVM_INSERTCOLUMNW
, 0, (LPARAM
)&column
);
5370 SendMessageW(lv
, LVM_INSERTCOLUMNW
, 1, (LPARAM
)&column
);
5371 show_import_details(lv
, data
);
5376 NMHDR
*hdr
= (NMHDR
*)lp
;
5382 HWND lv
= GetDlgItem(hwnd
, IDC_IMPORT_SETTINGS
);
5384 data
= (struct ImportWizData
*)GetWindowLongPtrW(hwnd
, DWLP_USER
);
5385 SendMessageW(lv
, LVM_DELETEALLITEMS
, 0, 0);
5386 show_import_details(lv
, data
);
5387 PostMessageW(GetParent(hwnd
), PSM_SETWIZBUTTONS
, 0,
5388 PSWIZB_BACK
| PSWIZB_FINISH
);
5394 data
= (struct ImportWizData
*)GetWindowLongPtrW(hwnd
, DWLP_USER
);
5395 if ((data
->success
= do_import(data
->dwFlags
, hwnd
,
5396 data
->pwszWizardTitle
, &data
->importSrc
, data
->hDestCertStore
)))
5398 WCHAR title
[MAX_STRING_LEN
], message
[MAX_STRING_LEN
];
5401 if (data
->pwszWizardTitle
)
5402 pTitle
= data
->pwszWizardTitle
;
5405 LoadStringW(hInstance
, IDS_IMPORT_WIZARD
, title
, ARRAY_SIZE(title
));
5408 LoadStringW(hInstance
, IDS_IMPORT_SUCCEEDED
, message
, ARRAY_SIZE(message
));
5409 MessageBoxW(hwnd
, message
, pTitle
, MB_OK
);
5412 import_warning(data
->dwFlags
, hwnd
, data
->pwszWizardTitle
,
5423 static BOOL
show_import_ui(DWORD dwFlags
, HWND hwndParent
,
5424 LPCWSTR pwszWizardTitle
, PCCRYPTUI_WIZ_IMPORT_SRC_INFO pImportSrc
,
5425 HCERTSTORE hDestCertStore
)
5427 PROPSHEETHEADERW hdr
;
5428 PROPSHEETPAGEW pages
[4];
5429 struct ImportWizData data
;
5432 data
.dwFlags
= dwFlags
;
5433 data
.pwszWizardTitle
= pwszWizardTitle
;
5436 memcpy(&data
.importSrc
, pImportSrc
, sizeof(data
.importSrc
));
5437 data
.fileName
= (LPWSTR
)pImportSrc
->u
.pwszFileName
;
5441 memset(&data
.importSrc
, 0, sizeof(data
.importSrc
));
5442 data
.fileName
= NULL
;
5444 data
.freeSource
= FALSE
;
5445 data
.hDestCertStore
= hDestCertStore
;
5446 data
.freeDest
= FALSE
;
5447 data
.autoDest
= TRUE
;
5448 data
.success
= TRUE
;
5450 memset(pages
, 0, sizeof(pages
));
5452 pages
[nPages
].dwSize
= sizeof(pages
[0]);
5453 pages
[nPages
].hInstance
= hInstance
;
5454 pages
[nPages
].u
.pszTemplate
= MAKEINTRESOURCEW(IDD_IMPORT_WELCOME
);
5455 pages
[nPages
].pfnDlgProc
= import_welcome_dlg_proc
;
5456 pages
[nPages
].dwFlags
= PSP_HIDEHEADER
;
5457 pages
[nPages
].lParam
= (LPARAM
)&data
;
5461 pImportSrc
->dwSubjectChoice
== CRYPTUI_WIZ_IMPORT_SUBJECT_FILE
)
5463 pages
[nPages
].dwSize
= sizeof(pages
[0]);
5464 pages
[nPages
].hInstance
= hInstance
;
5465 pages
[nPages
].u
.pszTemplate
= MAKEINTRESOURCEW(IDD_IMPORT_FILE
);
5466 pages
[nPages
].pfnDlgProc
= import_file_dlg_proc
;
5467 pages
[nPages
].dwFlags
= PSP_USEHEADERTITLE
| PSP_USEHEADERSUBTITLE
;
5468 pages
[nPages
].pszHeaderTitle
= MAKEINTRESOURCEW(IDS_IMPORT_FILE_TITLE
);
5469 pages
[nPages
].pszHeaderSubTitle
=
5470 MAKEINTRESOURCEW(IDS_IMPORT_FILE_SUBTITLE
);
5471 pages
[nPages
].lParam
= (LPARAM
)&data
;
5476 switch (pImportSrc
->dwSubjectChoice
)
5478 case CRYPTUI_WIZ_IMPORT_SUBJECT_CERT_CONTEXT
:
5479 data
.contentType
= CERT_QUERY_CONTENT_CERT
;
5481 case CRYPTUI_WIZ_IMPORT_SUBJECT_CRL_CONTEXT
:
5482 data
.contentType
= CERT_QUERY_CONTENT_CRL
;
5484 case CRYPTUI_WIZ_IMPORT_SUBJECT_CTL_CONTEXT
:
5485 data
.contentType
= CERT_QUERY_CONTENT_CTL
;
5487 case CRYPTUI_WIZ_IMPORT_SUBJECT_CERT_STORE
:
5488 data
.contentType
= CERT_QUERY_CONTENT_SERIALIZED_STORE
;
5493 pages
[nPages
].dwSize
= sizeof(pages
[0]);
5494 pages
[nPages
].hInstance
= hInstance
;
5495 pages
[nPages
].u
.pszTemplate
= MAKEINTRESOURCEW(IDD_IMPORT_STORE
);
5496 pages
[nPages
].pfnDlgProc
= import_store_dlg_proc
;
5497 pages
[nPages
].dwFlags
= PSP_USEHEADERTITLE
| PSP_USEHEADERSUBTITLE
;
5498 pages
[nPages
].pszHeaderTitle
= MAKEINTRESOURCEW(IDS_IMPORT_STORE_TITLE
);
5499 pages
[nPages
].pszHeaderSubTitle
=
5500 MAKEINTRESOURCEW(IDS_IMPORT_STORE_SUBTITLE
);
5501 pages
[nPages
].lParam
= (LPARAM
)&data
;
5504 pages
[nPages
].dwSize
= sizeof(pages
[0]);
5505 pages
[nPages
].hInstance
= hInstance
;
5506 pages
[nPages
].u
.pszTemplate
= MAKEINTRESOURCEW(IDD_IMPORT_FINISH
);
5507 pages
[nPages
].pfnDlgProc
= import_finish_dlg_proc
;
5508 pages
[nPages
].dwFlags
= PSP_HIDEHEADER
;
5509 pages
[nPages
].lParam
= (LPARAM
)&data
;
5512 memset(&hdr
, 0, sizeof(hdr
));
5513 hdr
.dwSize
= sizeof(hdr
);
5514 hdr
.hwndParent
= hwndParent
;
5515 hdr
.dwFlags
= PSH_PROPSHEETPAGE
| PSH_WIZARD97_NEW
| PSH_HEADER
|
5517 hdr
.hInstance
= hInstance
;
5518 if (pwszWizardTitle
)
5519 hdr
.pszCaption
= pwszWizardTitle
;
5521 hdr
.pszCaption
= MAKEINTRESOURCEW(IDS_IMPORT_WIZARD
);
5522 hdr
.u3
.ppsp
= pages
;
5523 hdr
.nPages
= nPages
;
5524 hdr
.u4
.pszbmWatermark
= MAKEINTRESOURCEW(IDB_CERT_WATERMARK
);
5525 hdr
.u5
.pszbmHeader
= MAKEINTRESOURCEW(IDB_CERT_HEADER
);
5526 PropertySheetW(&hdr
);
5527 if (data
.fileName
!= data
.importSrc
.u
.pwszFileName
)
5528 HeapFree(GetProcessHeap(), 0, data
.fileName
);
5529 if (data
.freeSource
&&
5530 data
.importSrc
.dwSubjectChoice
== CRYPTUI_WIZ_IMPORT_SUBJECT_CERT_STORE
)
5531 CertCloseStore(data
.importSrc
.u
.hCertStore
, 0);
5532 DeleteObject(data
.titleFont
);
5533 return data
.success
;
5536 BOOL WINAPI
CryptUIWizImport(DWORD dwFlags
, HWND hwndParent
, LPCWSTR pwszWizardTitle
,
5537 PCCRYPTUI_WIZ_IMPORT_SRC_INFO pImportSrc
, HCERTSTORE hDestCertStore
)
5541 TRACE("(0x%08x, %p, %s, %p, %p)\n", dwFlags
, hwndParent
, debugstr_w(pwszWizardTitle
),
5542 pImportSrc
, hDestCertStore
);
5545 pImportSrc
->dwSize
!= sizeof(CRYPTUI_WIZ_IMPORT_SRC_INFO
))
5547 SetLastError(E_INVALIDARG
);
5551 if (!(dwFlags
& CRYPTUI_WIZ_NO_UI
))
5552 ret
= show_import_ui(dwFlags
, hwndParent
, pwszWizardTitle
, pImportSrc
,
5554 else if (pImportSrc
)
5555 ret
= do_import(dwFlags
, hwndParent
, pwszWizardTitle
, pImportSrc
,
5559 /* Can't have no UI without specifying source */
5560 SetLastError(E_INVALIDARG
);
5567 struct ExportWizData
5571 LPCWSTR pwszWizardTitle
;
5572 CRYPTUI_WIZ_EXPORT_INFO exportInfo
;
5573 CRYPTUI_WIZ_EXPORT_CERTCONTEXT_INFO contextInfo
;
5575 PCRYPT_KEY_PROV_INFO keyProvInfo
;
5582 static LRESULT CALLBACK
export_welcome_dlg_proc(HWND hwnd
, UINT msg
, WPARAM wp
,
5591 struct ExportWizData
*data
;
5592 PROPSHEETPAGEW
*page
= (PROPSHEETPAGEW
*)lp
;
5593 WCHAR fontFace
[MAX_STRING_LEN
];
5594 HDC hDC
= GetDC(hwnd
);
5597 data
= (struct ExportWizData
*)page
->lParam
;
5598 LoadStringW(hInstance
, IDS_WIZARD_TITLE_FONT
, fontFace
, ARRAY_SIZE(fontFace
));
5599 height
= -MulDiv(12, GetDeviceCaps(hDC
, LOGPIXELSY
), 72);
5600 data
->titleFont
= CreateFontW(height
, 0, 0, 0, FW_BOLD
, 0, 0, 0,
5601 DEFAULT_CHARSET
, OUT_DEFAULT_PRECIS
, CLIP_DEFAULT_PRECIS
,
5602 DEFAULT_QUALITY
, DEFAULT_PITCH
| FF_DONTCARE
, fontFace
);
5603 SendMessageW(GetDlgItem(hwnd
, IDC_EXPORT_TITLE
), WM_SETFONT
,
5604 (WPARAM
)data
->titleFont
, TRUE
);
5605 ReleaseDC(hwnd
, hDC
);
5610 NMHDR
*hdr
= (NMHDR
*)lp
;
5615 PostMessageW(GetParent(hwnd
), PSM_SETWIZBUTTONS
, 0, PSWIZB_NEXT
);
5625 static PCRYPT_KEY_PROV_INFO
export_get_private_key_info(PCCERT_CONTEXT cert
)
5627 PCRYPT_KEY_PROV_INFO info
= NULL
;
5630 if (CertGetCertificateContextProperty(cert
, CERT_KEY_PROV_INFO_PROP_ID
,
5633 info
= HeapAlloc(GetProcessHeap(), 0, size
);
5636 if (!CertGetCertificateContextProperty(cert
,
5637 CERT_KEY_PROV_INFO_PROP_ID
, info
, &size
))
5639 HeapFree(GetProcessHeap(), 0, info
);
5647 static BOOL
export_acquire_private_key(const CRYPT_KEY_PROV_INFO
*info
,
5652 ret
= CryptAcquireContextW(phProv
, info
->pwszContainerName
,
5653 info
->pwszProvName
, info
->dwProvType
, 0);
5658 for (i
= 0; i
< info
->cProvParam
; i
++)
5659 CryptSetProvParam(*phProv
, info
->rgProvParam
[i
].dwParam
,
5660 info
->rgProvParam
[i
].pbData
, info
->rgProvParam
[i
].dwFlags
);
5665 static BOOL
export_is_key_exportable(HCRYPTPROV hProv
, DWORD keySpec
)
5670 if ((ret
= CryptGetUserKey(hProv
, keySpec
, &key
)))
5672 DWORD permissions
, size
= sizeof(permissions
);
5674 if ((ret
= CryptGetKeyParam(key
, KP_PERMISSIONS
, (BYTE
*)&permissions
,
5675 &size
, 0)) && !(permissions
& CRYPT_EXPORT
))
5677 CryptDestroyKey(key
);
5682 static LRESULT CALLBACK
export_private_key_dlg_proc(HWND hwnd
, UINT msg
,
5683 WPARAM wp
, LPARAM lp
)
5686 struct ExportWizData
*data
;
5692 PROPSHEETPAGEW
*page
= (PROPSHEETPAGEW
*)lp
;
5693 PCRYPT_KEY_PROV_INFO info
;
5694 HCRYPTPROV hProv
= 0;
5697 data
= (struct ExportWizData
*)page
->lParam
;
5698 SetWindowLongPtrW(hwnd
, DWLP_USER
, (LPARAM
)data
);
5699 /* Get enough information about a key to see whether it's exportable.
5701 if (!(info
= export_get_private_key_info(
5702 data
->exportInfo
.u
.pCertContext
)))
5703 errorID
= IDS_EXPORT_PRIVATE_KEY_UNAVAILABLE
;
5704 else if (!export_acquire_private_key(info
, &hProv
))
5705 errorID
= IDS_EXPORT_PRIVATE_KEY_UNAVAILABLE
;
5706 else if (!export_is_key_exportable(hProv
, info
->dwKeySpec
))
5707 errorID
= IDS_EXPORT_PRIVATE_KEY_NON_EXPORTABLE
;
5711 WCHAR error
[MAX_STRING_LEN
];
5713 LoadStringW(hInstance
, errorID
, error
, ARRAY_SIZE(error
));
5714 SendMessageW(GetDlgItem(hwnd
, IDC_EXPORT_PRIVATE_KEY_UNAVAILABLE
),
5715 WM_SETTEXT
, 0, (LPARAM
)error
);
5716 EnableWindow(GetDlgItem(hwnd
, IDC_EXPORT_PRIVATE_KEY_YES
), FALSE
);
5719 data
->keyProvInfo
= info
;
5721 CryptReleaseContext(hProv
, 0);
5722 SendMessageW(GetDlgItem(hwnd
, IDC_EXPORT_PRIVATE_KEY_NO
), BM_CLICK
,
5728 NMHDR
*hdr
= (NMHDR
*)lp
;
5733 PostMessageW(GetParent(hwnd
), PSM_SETWIZBUTTONS
, 0,
5734 PSWIZB_BACK
| PSWIZB_NEXT
);
5738 data
= (struct ExportWizData
*)GetWindowLongPtrW(hwnd
, DWLP_USER
);
5739 if (IsDlgButtonChecked(hwnd
, IDC_EXPORT_PRIVATE_KEY_NO
))
5741 data
->contextInfo
.dwExportFormat
=
5742 CRYPTUI_WIZ_EXPORT_FORMAT_DER
;
5743 data
->contextInfo
.fExportPrivateKeys
= FALSE
;
5747 data
->contextInfo
.dwExportFormat
=
5748 CRYPTUI_WIZ_EXPORT_FORMAT_PFX
;
5749 data
->contextInfo
.fExportPrivateKeys
= TRUE
;
5759 static BOOL
export_info_has_private_key(PCCRYPTUI_WIZ_EXPORT_INFO pExportInfo
)
5763 if (pExportInfo
->dwSubjectChoice
== CRYPTUI_WIZ_EXPORT_CERT_CONTEXT
)
5767 /* If there's a CRYPT_KEY_PROV_INFO set for this cert, assume the
5768 * cert has a private key.
5770 if (CertGetCertificateContextProperty(pExportInfo
->u
.pCertContext
,
5771 CERT_KEY_PROV_INFO_PROP_ID
, NULL
, &size
))
5777 static void export_format_enable_controls(HWND hwnd
, const struct ExportWizData
*data
)
5779 int defaultFormatID
;
5781 switch (data
->contextInfo
.dwExportFormat
)
5783 case CRYPTUI_WIZ_EXPORT_FORMAT_BASE64
:
5784 defaultFormatID
= IDC_EXPORT_FORMAT_BASE64
;
5786 case CRYPTUI_WIZ_EXPORT_FORMAT_PKCS7
:
5787 defaultFormatID
= IDC_EXPORT_FORMAT_CMS
;
5789 case CRYPTUI_WIZ_EXPORT_FORMAT_PFX
:
5790 defaultFormatID
= IDC_EXPORT_FORMAT_PFX
;
5793 defaultFormatID
= IDC_EXPORT_FORMAT_DER
;
5795 SendMessageW(GetDlgItem(hwnd
, defaultFormatID
), BM_CLICK
, 0, 0);
5796 if (defaultFormatID
== IDC_EXPORT_FORMAT_PFX
)
5798 EnableWindow(GetDlgItem(hwnd
, IDC_EXPORT_FORMAT_DER
), FALSE
);
5799 EnableWindow(GetDlgItem(hwnd
, IDC_EXPORT_FORMAT_BASE64
), FALSE
);
5800 EnableWindow(GetDlgItem(hwnd
, IDC_EXPORT_FORMAT_CMS
), FALSE
);
5801 EnableWindow(GetDlgItem(hwnd
, IDC_EXPORT_FORMAT_PFX
), TRUE
);
5805 EnableWindow(GetDlgItem(hwnd
, IDC_EXPORT_FORMAT_DER
), TRUE
);
5806 EnableWindow(GetDlgItem(hwnd
, IDC_EXPORT_FORMAT_BASE64
), TRUE
);
5807 EnableWindow(GetDlgItem(hwnd
, IDC_EXPORT_FORMAT_CMS
), TRUE
);
5808 EnableWindow(GetDlgItem(hwnd
, IDC_EXPORT_FORMAT_PFX
), FALSE
);
5812 static LRESULT CALLBACK
export_format_dlg_proc(HWND hwnd
, UINT msg
, WPARAM wp
,
5816 struct ExportWizData
*data
;
5822 PROPSHEETPAGEW
*page
= (PROPSHEETPAGEW
*)lp
;
5824 data
= (struct ExportWizData
*)page
->lParam
;
5825 SetWindowLongPtrW(hwnd
, DWLP_USER
, (LPARAM
)data
);
5826 export_format_enable_controls(hwnd
, data
);
5831 NMHDR
*hdr
= (NMHDR
*)lp
;
5836 PostMessageW(GetParent(hwnd
), PSM_SETWIZBUTTONS
, 0,
5837 PSWIZB_BACK
| PSWIZB_NEXT
);
5838 data
= (struct ExportWizData
*)GetWindowLongPtrW(hwnd
, DWLP_USER
);
5839 export_format_enable_controls(hwnd
, data
);
5844 BOOL skipPasswordPage
= TRUE
;
5846 data
= (struct ExportWizData
*)GetWindowLongPtrW(hwnd
, DWLP_USER
);
5847 if (IsDlgButtonChecked(hwnd
, IDC_EXPORT_FORMAT_DER
))
5848 data
->contextInfo
.dwExportFormat
=
5849 CRYPTUI_WIZ_EXPORT_FORMAT_DER
;
5850 else if (IsDlgButtonChecked(hwnd
, IDC_EXPORT_FORMAT_BASE64
))
5851 data
->contextInfo
.dwExportFormat
=
5852 CRYPTUI_WIZ_EXPORT_FORMAT_BASE64
;
5853 else if (IsDlgButtonChecked(hwnd
, IDC_EXPORT_FORMAT_CMS
))
5855 data
->contextInfo
.dwExportFormat
=
5856 CRYPTUI_WIZ_EXPORT_FORMAT_PKCS7
;
5857 if (IsDlgButtonChecked(hwnd
, IDC_EXPORT_CMS_INCLUDE_CHAIN
))
5858 data
->contextInfo
.fExportChain
=
5859 CRYPTUI_WIZ_EXPORT_FORMAT_PKCS7
;
5863 data
->contextInfo
.dwExportFormat
=
5864 CRYPTUI_WIZ_EXPORT_FORMAT_PFX
;
5865 if (IsDlgButtonChecked(hwnd
, IDC_EXPORT_PFX_INCLUDE_CHAIN
))
5866 data
->contextInfo
.fExportChain
= TRUE
;
5867 if (IsDlgButtonChecked(hwnd
, IDC_EXPORT_PFX_STRONG_ENCRYPTION
))
5868 data
->contextInfo
.fStrongEncryption
= TRUE
;
5869 if (IsDlgButtonChecked(hwnd
, IDC_EXPORT_PFX_DELETE_PRIVATE_KEY
))
5870 data
->deleteKeys
= TRUE
;
5871 skipPasswordPage
= FALSE
;
5873 SetWindowLongPtrW(hwnd
, DWLP_MSGRESULT
,
5874 skipPasswordPage
? IDD_EXPORT_FILE
: 0);
5887 case IDC_EXPORT_FORMAT_DER
:
5888 case IDC_EXPORT_FORMAT_BASE64
:
5889 EnableWindow(GetDlgItem(hwnd
, IDC_EXPORT_CMS_INCLUDE_CHAIN
),
5891 EnableWindow(GetDlgItem(hwnd
, IDC_EXPORT_PFX_INCLUDE_CHAIN
),
5893 EnableWindow(GetDlgItem(hwnd
, IDC_EXPORT_PFX_STRONG_ENCRYPTION
),
5895 EnableWindow(GetDlgItem(hwnd
,
5896 IDC_EXPORT_PFX_DELETE_PRIVATE_KEY
), FALSE
);
5898 case IDC_EXPORT_FORMAT_CMS
:
5899 EnableWindow(GetDlgItem(hwnd
, IDC_EXPORT_CMS_INCLUDE_CHAIN
),
5902 case IDC_EXPORT_FORMAT_PFX
:
5903 EnableWindow(GetDlgItem(hwnd
, IDC_EXPORT_PFX_INCLUDE_CHAIN
),
5905 EnableWindow(GetDlgItem(hwnd
, IDC_EXPORT_PFX_STRONG_ENCRYPTION
),
5907 EnableWindow(GetDlgItem(hwnd
,
5908 IDC_EXPORT_PFX_DELETE_PRIVATE_KEY
), TRUE
);
5918 static void export_password_mismatch(HWND hwnd
, const struct ExportWizData
*data
)
5920 WCHAR title
[MAX_STRING_LEN
], error
[MAX_STRING_LEN
];
5923 if (data
->pwszWizardTitle
)
5924 pTitle
= data
->pwszWizardTitle
;
5927 LoadStringW(hInstance
, IDS_EXPORT_WIZARD
, title
, ARRAY_SIZE(title
));
5930 LoadStringW(hInstance
, IDS_EXPORT_PASSWORD_MISMATCH
, error
, ARRAY_SIZE(error
));
5931 MessageBoxW(hwnd
, error
, pTitle
, MB_ICONERROR
| MB_OK
);
5932 SetFocus(GetDlgItem(hwnd
, IDC_EXPORT_PASSWORD
));
5935 static LRESULT CALLBACK
export_password_dlg_proc(HWND hwnd
, UINT msg
,
5936 WPARAM wp
, LPARAM lp
)
5939 struct ExportWizData
*data
;
5945 PROPSHEETPAGEW
*page
= (PROPSHEETPAGEW
*)lp
;
5947 data
= (struct ExportWizData
*)page
->lParam
;
5948 SetWindowLongPtrW(hwnd
, DWLP_USER
, (LPARAM
)data
);
5953 NMHDR
*hdr
= (NMHDR
*)lp
;
5958 PostMessageW(GetParent(hwnd
), PSM_SETWIZBUTTONS
, 0,
5959 PSWIZB_BACK
| PSWIZB_NEXT
);
5964 HWND passwordEdit
= GetDlgItem(hwnd
, IDC_EXPORT_PASSWORD
);
5965 HWND passwordConfirmEdit
= GetDlgItem(hwnd
,
5966 IDC_EXPORT_PASSWORD_CONFIRM
);
5967 DWORD passwordLen
= SendMessageW(passwordEdit
, WM_GETTEXTLENGTH
,
5969 DWORD passwordConfirmLen
= SendMessageW(passwordConfirmEdit
,
5970 WM_GETTEXTLENGTH
, 0, 0);
5972 data
= (struct ExportWizData
*)GetWindowLongPtrW(hwnd
, DWLP_USER
);
5973 if (!passwordLen
&& !passwordConfirmLen
)
5974 data
->contextInfo
.pwszPassword
= NULL
;
5975 else if (passwordLen
!= passwordConfirmLen
)
5977 export_password_mismatch(hwnd
, data
);
5978 SetWindowLongPtrW(hwnd
, DWLP_MSGRESULT
, 1);
5983 LPWSTR password
= HeapAlloc(GetProcessHeap(), 0,
5984 (passwordLen
+ 1) * sizeof(WCHAR
));
5985 LPWSTR passwordConfirm
= HeapAlloc(GetProcessHeap(), 0,
5986 (passwordConfirmLen
+ 1) * sizeof(WCHAR
));
5987 BOOL freePassword
= TRUE
;
5989 if (password
&& passwordConfirm
)
5991 SendMessageW(passwordEdit
, WM_GETTEXT
, passwordLen
+ 1,
5993 SendMessageW(passwordConfirmEdit
, WM_GETTEXT
,
5994 passwordConfirmLen
+ 1, (LPARAM
)passwordConfirm
);
5995 if (lstrcmpW(password
, passwordConfirm
))
5997 export_password_mismatch(hwnd
, data
);
5998 SetWindowLongPtrW(hwnd
, DWLP_MSGRESULT
, 1);
6003 data
->contextInfo
.pwszPassword
= password
;
6004 freePassword
= FALSE
;
6005 data
->freePassword
= TRUE
;
6009 HeapFree(GetProcessHeap(), 0, password
);
6010 HeapFree(GetProcessHeap(), 0, passwordConfirm
);
6021 static LPWSTR
export_append_extension(const struct ExportWizData
*data
,
6024 static const WCHAR cer
[] = { '.','c','e','r',0 };
6025 static const WCHAR crl
[] = { '.','c','r','l',0 };
6026 static const WCHAR ctl
[] = { '.','c','t','l',0 };
6027 static const WCHAR p7b
[] = { '.','p','7','b',0 };
6028 static const WCHAR pfx
[] = { '.','p','f','x',0 };
6029 static const WCHAR sst
[] = { '.','s','s','t',0 };
6032 BOOL appendExtension
;
6034 switch (data
->contextInfo
.dwExportFormat
)
6036 case CRYPTUI_WIZ_EXPORT_FORMAT_PKCS7
:
6039 case CRYPTUI_WIZ_EXPORT_FORMAT_PFX
:
6043 switch (data
->exportInfo
.dwSubjectChoice
)
6045 case CRYPTUI_WIZ_EXPORT_CRL_CONTEXT
:
6048 case CRYPTUI_WIZ_EXPORT_CTL_CONTEXT
:
6051 case CRYPTUI_WIZ_EXPORT_CERT_STORE
:
6058 dot
= wcsrchr(fileName
, '.');
6060 appendExtension
= wcsicmp(dot
, extension
) != 0;
6062 appendExtension
= TRUE
;
6063 if (appendExtension
)
6065 fileName
= HeapReAlloc(GetProcessHeap(), 0, fileName
,
6066 (lstrlenW(fileName
) + lstrlenW(extension
) + 1) * sizeof(WCHAR
));
6068 lstrcatW(fileName
, extension
);
6073 static BOOL
export_validate_filename(HWND hwnd
, struct ExportWizData
*data
,
6077 BOOL tryCreate
= TRUE
, forceCreate
= FALSE
, ret
= FALSE
;
6079 file
= CreateFileW(fileName
, GENERIC_WRITE
,
6080 FILE_SHARE_READ
| FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
, 0, NULL
);
6081 if (file
!= INVALID_HANDLE_VALUE
)
6083 WCHAR warning
[MAX_STRING_LEN
], title
[MAX_STRING_LEN
];
6086 if (data
->pwszWizardTitle
)
6087 pTitle
= data
->pwszWizardTitle
;
6090 LoadStringW(hInstance
, IDS_EXPORT_WIZARD
, title
, ARRAY_SIZE(title
));
6093 LoadStringW(hInstance
, IDS_EXPORT_FILE_EXISTS
, warning
, ARRAY_SIZE(warning
));
6094 if (MessageBoxW(hwnd
, warning
, pTitle
, MB_YESNO
) == IDYES
)
6102 file
= CreateFileW(fileName
, GENERIC_WRITE
,
6103 FILE_SHARE_READ
| FILE_SHARE_WRITE
, NULL
,
6104 forceCreate
? CREATE_ALWAYS
: CREATE_NEW
,
6106 if (file
!= INVALID_HANDLE_VALUE
)
6113 WCHAR title
[MAX_STRING_LEN
], error
[MAX_STRING_LEN
];
6115 LPWSTR msgBuf
, fullError
;
6117 if (data
->pwszWizardTitle
)
6118 pTitle
= data
->pwszWizardTitle
;
6121 LoadStringW(hInstance
, IDS_EXPORT_WIZARD
, title
, ARRAY_SIZE(title
));
6124 LoadStringW(hInstance
, IDS_IMPORT_OPEN_FAILED
, error
, ARRAY_SIZE(error
));
6126 FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM
, NULL
,
6127 GetLastError(), 0, (LPWSTR
) &msgBuf
, 0, NULL
);
6128 fullError
= HeapAlloc(GetProcessHeap(), 0,
6129 (lstrlenW(error
) + lstrlenW(fileName
) + lstrlenW(msgBuf
) + 3)
6133 LPWSTR ptr
= fullError
;
6135 lstrcpyW(ptr
, error
);
6136 ptr
+= lstrlenW(error
);
6137 lstrcpyW(ptr
, fileName
);
6138 ptr
+= lstrlenW(fileName
);
6141 lstrcpyW(ptr
, msgBuf
);
6142 MessageBoxW(hwnd
, fullError
, pTitle
, MB_ICONERROR
| MB_OK
);
6143 HeapFree(GetProcessHeap(), 0, fullError
);
6151 static const WCHAR export_filter_cert
[] = { '*','.','c','e','r',0 };
6152 static const WCHAR export_filter_crl
[] = { '*','.','c','r','l',0 };
6153 static const WCHAR export_filter_ctl
[] = { '*','.','s','t','l',0 };
6154 static const WCHAR export_filter_cms
[] = { '*','.','p','7','b',0 };
6155 static const WCHAR export_filter_pfx
[] = { '*','.','p','f','x',0 };
6156 static const WCHAR export_filter_sst
[] = { '*','.','s','s','t',0 };
6158 static WCHAR
*make_export_file_filter(DWORD exportFormat
, DWORD subjectChoice
)
6160 int baseLen
, allLen
, totalLen
= 2, baseID
;
6161 LPWSTR filter
= NULL
, baseFilter
, all
;
6164 switch (exportFormat
)
6166 case CRYPTUI_WIZ_EXPORT_FORMAT_BASE64
:
6167 baseID
= IDS_EXPORT_FILTER_BASE64_CERT
;
6168 filterStr
= export_filter_cert
;
6170 case CRYPTUI_WIZ_EXPORT_FORMAT_PFX
:
6171 baseID
= IDS_EXPORT_FILTER_PFX
;
6172 filterStr
= export_filter_pfx
;
6174 case CRYPTUI_WIZ_EXPORT_FORMAT_PKCS7
:
6175 baseID
= IDS_EXPORT_FILTER_CMS
;
6176 filterStr
= export_filter_cms
;
6179 switch (subjectChoice
)
6181 case CRYPTUI_WIZ_EXPORT_CRL_CONTEXT
:
6182 baseID
= IDS_EXPORT_FILTER_CRL
;
6183 filterStr
= export_filter_crl
;
6185 case CRYPTUI_WIZ_EXPORT_CTL_CONTEXT
:
6186 baseID
= IDS_EXPORT_FILTER_CTL
;
6187 filterStr
= export_filter_ctl
;
6189 case CRYPTUI_WIZ_EXPORT_CERT_STORE
:
6190 baseID
= IDS_EXPORT_FILTER_SERIALIZED_CERT_STORE
;
6191 filterStr
= export_filter_sst
;
6194 baseID
= IDS_EXPORT_FILTER_CERT
;
6195 filterStr
= export_filter_cert
;
6199 baseLen
= LoadStringW(hInstance
, baseID
, (LPWSTR
)&baseFilter
, 0);
6200 totalLen
+= baseLen
+ lstrlenW(filterStr
) + 2;
6201 allLen
= LoadStringW(hInstance
, IDS_IMPORT_FILTER_ALL
, (LPWSTR
)&all
, 0);
6202 totalLen
+= allLen
+ lstrlenW(filter_all
) + 2;
6203 filter
= HeapAlloc(GetProcessHeap(), 0, totalLen
* sizeof(WCHAR
));
6209 memcpy(ptr
, baseFilter
, baseLen
* sizeof(WCHAR
));
6212 lstrcpyW(ptr
, filterStr
);
6213 ptr
+= lstrlenW(filterStr
) + 1;
6214 memcpy(ptr
, all
, allLen
* sizeof(WCHAR
));
6217 lstrcpyW(ptr
, filter_all
);
6218 ptr
+= lstrlenW(filter_all
) + 1;
6224 static LRESULT CALLBACK
export_file_dlg_proc(HWND hwnd
, UINT msg
, WPARAM wp
,
6228 struct ExportWizData
*data
;
6234 PROPSHEETPAGEW
*page
= (PROPSHEETPAGEW
*)lp
;
6236 data
= (struct ExportWizData
*)page
->lParam
;
6237 SetWindowLongPtrW(hwnd
, DWLP_USER
, (LPARAM
)data
);
6238 if (data
->exportInfo
.pwszExportFileName
)
6239 SendMessageW(GetDlgItem(hwnd
, IDC_EXPORT_FILENAME
), WM_SETTEXT
, 0,
6240 (LPARAM
)data
->exportInfo
.pwszExportFileName
);
6245 NMHDR
*hdr
= (NMHDR
*)lp
;
6250 data
= (struct ExportWizData
*)GetWindowLongPtrW(hwnd
, DWLP_USER
);
6251 if (data
->contextInfo
.dwExportFormat
!=
6252 CRYPTUI_WIZ_EXPORT_FORMAT_PFX
)
6254 SetWindowLongPtrW(hwnd
, DWLP_MSGRESULT
, IDD_EXPORT_FORMAT
);
6260 HWND fileNameEdit
= GetDlgItem(hwnd
, IDC_EXPORT_FILENAME
);
6261 DWORD len
= SendMessageW(fileNameEdit
, WM_GETTEXTLENGTH
, 0, 0);
6263 data
= (struct ExportWizData
*)GetWindowLongPtrW(hwnd
, DWLP_USER
);
6266 WCHAR title
[MAX_STRING_LEN
], error
[MAX_STRING_LEN
];
6269 if (data
->pwszWizardTitle
)
6270 pTitle
= data
->pwszWizardTitle
;
6273 LoadStringW(hInstance
, IDS_EXPORT_WIZARD
, title
, ARRAY_SIZE(title
));
6276 LoadStringW(hInstance
, IDS_IMPORT_EMPTY_FILE
, error
, ARRAY_SIZE(error
));
6277 MessageBoxW(hwnd
, error
, pTitle
, MB_ICONERROR
| MB_OK
);
6278 SetWindowLongPtrW(hwnd
, DWLP_MSGRESULT
, 1);
6283 LPWSTR fileName
= HeapAlloc(GetProcessHeap(), 0,
6284 (len
+ 1) * sizeof(WCHAR
));
6288 SendMessageW(fileNameEdit
, WM_GETTEXT
, len
+ 1,
6290 fileName
= export_append_extension(data
, fileName
);
6291 if (!export_validate_filename(hwnd
, data
, fileName
))
6293 HeapFree(GetProcessHeap(), 0, fileName
);
6294 SetWindowLongPtrW(hwnd
, DWLP_MSGRESULT
, 1);
6298 data
->fileName
= fileName
;
6304 PostMessageW(GetParent(hwnd
), PSM_SETWIZBUTTONS
, 0,
6305 PSWIZB_BACK
| PSWIZB_NEXT
);
6314 case IDC_EXPORT_BROWSE_FILE
:
6317 WCHAR fileBuf
[MAX_PATH
];
6319 data
= (struct ExportWizData
*)GetWindowLongPtrW(hwnd
, DWLP_USER
);
6320 memset(&ofn
, 0, sizeof(ofn
));
6321 ofn
.lStructSize
= sizeof(ofn
);
6322 ofn
.hwndOwner
= hwnd
;
6323 ofn
.lpstrFilter
= make_export_file_filter(
6324 data
->contextInfo
.dwExportFormat
,
6325 data
->exportInfo
.dwSubjectChoice
);
6326 ofn
.lpstrFile
= fileBuf
;
6327 ofn
.nMaxFile
= ARRAY_SIZE(fileBuf
);
6329 if (GetSaveFileNameW(&ofn
))
6330 SendMessageW(GetDlgItem(hwnd
, IDC_EXPORT_FILENAME
), WM_SETTEXT
,
6331 0, (LPARAM
)ofn
.lpstrFile
);
6332 HeapFree(GetProcessHeap(), 0, (LPWSTR
)ofn
.lpstrFilter
);
6341 static void show_export_details(HWND lv
, const struct ExportWizData
*data
)
6343 WCHAR text
[MAX_STRING_LEN
];
6347 item
.mask
= LVIF_TEXT
;
6350 item
.iItem
= SendMessageW(lv
, LVM_GETITEMCOUNT
, 0, 0);
6352 LoadStringW(hInstance
, IDS_IMPORT_FILE
, text
, ARRAY_SIZE(text
));
6353 item
.pszText
= text
;
6354 SendMessageW(lv
, LVM_INSERTITEMW
, 0, (LPARAM
)&item
);
6356 item
.pszText
= data
->fileName
;
6357 SendMessageW(lv
, LVM_SETITEMTEXTW
, item
.iItem
, (LPARAM
)&item
);
6360 item
.pszText
= text
;
6361 switch (data
->exportInfo
.dwSubjectChoice
)
6363 case CRYPTUI_WIZ_EXPORT_CRL_CONTEXT
:
6364 case CRYPTUI_WIZ_EXPORT_CTL_CONTEXT
:
6365 case CRYPTUI_WIZ_EXPORT_CERT_STORE
:
6366 case CRYPTUI_WIZ_EXPORT_CERT_STORE_CERTIFICATES_ONLY
:
6371 item
.iItem
= SendMessageW(lv
, LVM_GETITEMCOUNT
, 0, 0);
6373 LoadStringW(hInstance
, IDS_EXPORT_INCLUDE_CHAIN
, text
, ARRAY_SIZE(text
));
6374 SendMessageW(lv
, LVM_INSERTITEMW
, item
.iItem
, (LPARAM
)&item
);
6376 LoadStringW(hInstance
, data
->contextInfo
.fExportChain
? IDS_YES
: IDS_NO
, text
,
6378 SendMessageW(lv
, LVM_SETITEMTEXTW
, item
.iItem
, (LPARAM
)&item
);
6380 item
.iItem
= SendMessageW(lv
, LVM_GETITEMCOUNT
, 0, 0);
6382 LoadStringW(hInstance
, IDS_EXPORT_KEYS
, text
, ARRAY_SIZE(text
));
6383 SendMessageW(lv
, LVM_INSERTITEMW
, item
.iItem
, (LPARAM
)&item
);
6385 LoadStringW(hInstance
, data
->contextInfo
.fExportPrivateKeys
? IDS_YES
: IDS_NO
, text
,
6387 SendMessageW(lv
, LVM_SETITEMTEXTW
, item
.iItem
, (LPARAM
)&item
);
6391 item
.iItem
= SendMessageW(lv
, LVM_GETITEMCOUNT
, 0, 0);
6393 LoadStringW(hInstance
, IDS_EXPORT_FORMAT
, text
, ARRAY_SIZE(text
));
6394 SendMessageW(lv
, LVM_INSERTITEMW
, 0, (LPARAM
)&item
);
6397 switch (data
->exportInfo
.dwSubjectChoice
)
6399 case CRYPTUI_WIZ_EXPORT_CRL_CONTEXT
:
6400 contentID
= IDS_EXPORT_FILTER_CRL
;
6402 case CRYPTUI_WIZ_EXPORT_CTL_CONTEXT
:
6403 contentID
= IDS_EXPORT_FILTER_CTL
;
6405 case CRYPTUI_WIZ_EXPORT_CERT_STORE
:
6406 contentID
= IDS_EXPORT_FILTER_SERIALIZED_CERT_STORE
;
6409 switch (data
->contextInfo
.dwExportFormat
)
6411 case CRYPTUI_WIZ_EXPORT_FORMAT_BASE64
:
6412 contentID
= IDS_EXPORT_FILTER_BASE64_CERT
;
6414 case CRYPTUI_WIZ_EXPORT_FORMAT_PKCS7
:
6415 contentID
= IDS_EXPORT_FILTER_CMS
;
6417 case CRYPTUI_WIZ_EXPORT_FORMAT_PFX
:
6418 contentID
= IDS_EXPORT_FILTER_PFX
;
6421 contentID
= IDS_EXPORT_FILTER_CERT
;
6424 LoadStringW(hInstance
, contentID
, text
, ARRAY_SIZE(text
));
6425 SendMessageW(lv
, LVM_SETITEMTEXTW
, item
.iItem
, (LPARAM
)&item
);
6428 static inline BOOL
save_der(HANDLE file
, const BYTE
*pb
, DWORD cb
)
6432 return WriteFile(file
, pb
, cb
, &bytesWritten
, NULL
);
6435 static BOOL
save_base64(HANDLE file
, const BYTE
*pb
, DWORD cb
)
6440 if ((ret
= CryptBinaryToStringA(pb
, cb
, CRYPT_STRING_BASE64
, NULL
, &size
)))
6442 LPSTR buf
= HeapAlloc(GetProcessHeap(), 0, size
);
6446 if ((ret
= CryptBinaryToStringA(pb
, cb
, CRYPT_STRING_BASE64
, buf
,
6448 ret
= WriteFile(file
, buf
, size
, &size
, NULL
);
6449 HeapFree(GetProcessHeap(), 0, buf
);
6453 SetLastError(ERROR_OUTOFMEMORY
);
6460 static inline BOOL
save_store_as_cms(HANDLE file
, HCERTSTORE store
)
6462 return CertSaveStore(store
, PKCS_7_ASN_ENCODING
| X509_ASN_ENCODING
,
6463 CERT_STORE_SAVE_AS_PKCS7
, CERT_STORE_SAVE_TO_FILE
, file
, 0);
6466 static BOOL
save_cert_as_cms(HANDLE file
, PCCRYPTUI_WIZ_EXPORT_INFO pExportInfo
,
6470 HCERTSTORE store
= CertOpenStore(CERT_STORE_PROV_MEMORY
, 0, 0,
6471 CERT_STORE_CREATE_NEW_FLAG
, NULL
);
6477 HCERTSTORE addlStore
= CertOpenStore(CERT_STORE_PROV_COLLECTION
,
6478 0, 0, CERT_STORE_CREATE_NEW_FLAG
, NULL
);
6485 for (i
= 0; ret
&& i
< pExportInfo
->cStores
; i
++)
6486 ret
= CertAddStoreToCollection(addlStore
,
6487 pExportInfo
->rghStores
, 0, 0);
6490 PCCERT_CHAIN_CONTEXT chain
;
6492 ret
= CertGetCertificateChain(NULL
,
6493 pExportInfo
->u
.pCertContext
, NULL
, addlStore
, NULL
, 0,
6499 for (i
= 0; ret
&& i
< chain
->cChain
; i
++)
6500 for (j
= 0; ret
&& j
< chain
->rgpChain
[i
]->cElement
;
6502 ret
= CertAddCertificateContextToStore(store
,
6503 chain
->rgpChain
[i
]->rgpElement
[j
]->pCertContext
,
6504 CERT_STORE_ADD_ALWAYS
, NULL
);
6505 CertFreeCertificateChain(chain
);
6509 /* No chain could be created, just add the individual
6510 * cert to the message.
6512 ret
= CertAddCertificateContextToStore(store
,
6513 pExportInfo
->u
.pCertContext
, CERT_STORE_ADD_ALWAYS
,
6517 CertCloseStore(addlStore
, 0);
6523 ret
= CertAddCertificateContextToStore(store
,
6524 pExportInfo
->u
.pCertContext
, CERT_STORE_ADD_ALWAYS
, NULL
);
6526 ret
= save_store_as_cms(file
, store
);
6527 CertCloseStore(store
, 0);
6534 static BOOL
save_serialized_store(HANDLE file
, HCERTSTORE store
)
6536 return CertSaveStore(store
, PKCS_7_ASN_ENCODING
| X509_ASN_ENCODING
,
6537 CERT_STORE_SAVE_AS_STORE
, CERT_STORE_SAVE_TO_FILE
, file
, 0);
6540 static BOOL
save_pfx(HANDLE file
, PCCRYPTUI_WIZ_EXPORT_INFO pExportInfo
,
6541 PCCRYPTUI_WIZ_EXPORT_CERTCONTEXT_INFO pContextInfo
,
6542 PCRYPT_KEY_PROV_INFO keyProvInfo
, BOOL deleteKeys
)
6544 HCERTSTORE store
= CertOpenStore(CERT_STORE_PROV_MEMORY
, X509_ASN_ENCODING
,
6545 0, CERT_STORE_CREATE_NEW_FLAG
, NULL
);
6550 CRYPT_DATA_BLOB pfxBlob
= { 0, NULL
};
6551 PCCERT_CONTEXT cert
= NULL
;
6552 BOOL freeKeyProvInfo
= FALSE
;
6554 if (pContextInfo
->fExportChain
)
6556 HCERTCHAINENGINE engine
= NULL
;
6558 if (pExportInfo
->cStores
)
6560 CERT_CHAIN_ENGINE_CONFIG config
;
6562 memset(&config
, 0, sizeof(config
));
6563 config
.cbSize
= sizeof(config
);
6564 config
.cAdditionalStore
= pExportInfo
->cStores
;
6565 config
.rghAdditionalStore
= pExportInfo
->rghStores
;
6566 ret
= CertCreateCertificateChainEngine(&config
, &engine
);
6572 CERT_CHAIN_PARA chainPara
;
6573 PCCERT_CHAIN_CONTEXT chain
;
6575 memset(&chainPara
, 0, sizeof(chainPara
));
6576 chainPara
.cbSize
= sizeof(chainPara
);
6577 ret
= CertGetCertificateChain(engine
,
6578 pExportInfo
->u
.pCertContext
, NULL
, NULL
, &chainPara
, 0, NULL
,
6584 for (i
= 0; ret
&& i
< chain
->cChain
; i
++)
6585 for (j
= 0; ret
&& j
< chain
->rgpChain
[i
]->cElement
;
6588 if (i
== 0 && j
== 0)
6589 ret
= CertAddCertificateContextToStore(store
,
6590 chain
->rgpChain
[i
]->rgpElement
[j
]->pCertContext
,
6591 CERT_STORE_ADD_ALWAYS
, &cert
);
6593 ret
= CertAddCertificateContextToStore(store
,
6594 chain
->rgpChain
[i
]->rgpElement
[j
]->pCertContext
,
6595 CERT_STORE_ADD_ALWAYS
, NULL
);
6597 CertFreeCertificateChain(chain
);
6601 CertFreeCertificateChainEngine(engine
);
6604 ret
= CertAddCertificateContextToStore(store
,
6605 pExportInfo
->u
.pCertContext
, CERT_STORE_ADD_ALWAYS
, &cert
);
6606 /* Copy private key info to newly created cert, so it'll get exported
6607 * along with the cert.
6609 if (ret
&& pContextInfo
->fExportPrivateKeys
)
6612 ret
= CertSetCertificateContextProperty(cert
,
6613 CERT_KEY_PROV_INFO_PROP_ID
, 0, keyProvInfo
);
6616 if (!(keyProvInfo
= export_get_private_key_info(cert
)))
6620 ret
= CertSetCertificateContextProperty(cert
,
6621 CERT_KEY_PROV_INFO_PROP_ID
, 0, keyProvInfo
);
6622 freeKeyProvInfo
= TRUE
;
6629 REPORT_NOT_ABLE_TO_EXPORT_PRIVATE_KEY
| EXPORT_PRIVATE_KEYS
;
6631 ret
= PFXExportCertStore(store
, &pfxBlob
,
6632 pContextInfo
->pwszPassword
, exportFlags
);
6635 pfxBlob
.pbData
= HeapAlloc(GetProcessHeap(), 0, pfxBlob
.cbData
);
6638 ret
= PFXExportCertStore(store
, &pfxBlob
,
6639 pContextInfo
->pwszPassword
, exportFlags
);
6644 ret
= WriteFile(file
, pfxBlob
.pbData
, pfxBlob
.cbData
,
6645 &bytesWritten
, NULL
);
6650 SetLastError(ERROR_OUTOFMEMORY
);
6655 if (ret
&& deleteKeys
)
6659 CryptAcquireContextW(&prov
, keyProvInfo
->pwszContainerName
,
6660 keyProvInfo
->pwszProvName
, keyProvInfo
->dwProvType
,
6661 CRYPT_DELETEKEYSET
);
6663 if (freeKeyProvInfo
)
6664 HeapFree(GetProcessHeap(), 0, keyProvInfo
);
6665 CertFreeCertificateContext(cert
);
6666 CertCloseStore(store
, 0);
6671 static BOOL
do_export(HANDLE file
, PCCRYPTUI_WIZ_EXPORT_INFO pExportInfo
,
6672 PCCRYPTUI_WIZ_EXPORT_CERTCONTEXT_INFO pContextInfo
,
6673 PCRYPT_KEY_PROV_INFO keyProvInfo
, BOOL deleteKeys
)
6677 if (pContextInfo
->dwSize
!= sizeof(CRYPTUI_WIZ_EXPORT_CERTCONTEXT_INFO
))
6679 SetLastError(E_INVALIDARG
);
6682 switch (pExportInfo
->dwSubjectChoice
)
6684 case CRYPTUI_WIZ_EXPORT_CRL_CONTEXT
:
6685 ret
= save_der(file
,
6686 pExportInfo
->u
.pCRLContext
->pbCrlEncoded
,
6687 pExportInfo
->u
.pCRLContext
->cbCrlEncoded
);
6689 case CRYPTUI_WIZ_EXPORT_CTL_CONTEXT
:
6690 ret
= save_der(file
,
6691 pExportInfo
->u
.pCTLContext
->pbCtlEncoded
,
6692 pExportInfo
->u
.pCTLContext
->cbCtlEncoded
);
6694 case CRYPTUI_WIZ_EXPORT_CERT_STORE
:
6695 ret
= save_serialized_store(file
, pExportInfo
->u
.hCertStore
);
6697 case CRYPTUI_WIZ_EXPORT_CERT_STORE_CERTIFICATES_ONLY
:
6698 ret
= save_store_as_cms(file
, pExportInfo
->u
.hCertStore
);
6701 switch (pContextInfo
->dwExportFormat
)
6703 case CRYPTUI_WIZ_EXPORT_FORMAT_DER
:
6704 ret
= save_der(file
, pExportInfo
->u
.pCertContext
->pbCertEncoded
,
6705 pExportInfo
->u
.pCertContext
->cbCertEncoded
);
6707 case CRYPTUI_WIZ_EXPORT_FORMAT_BASE64
:
6708 ret
= save_base64(file
,
6709 pExportInfo
->u
.pCertContext
->pbCertEncoded
,
6710 pExportInfo
->u
.pCertContext
->cbCertEncoded
);
6712 case CRYPTUI_WIZ_EXPORT_FORMAT_PKCS7
:
6713 ret
= save_cert_as_cms(file
, pExportInfo
,
6714 pContextInfo
->fExportChain
);
6716 case CRYPTUI_WIZ_EXPORT_FORMAT_PFX
:
6717 ret
= save_pfx(file
, pExportInfo
, pContextInfo
, keyProvInfo
,
6721 SetLastError(E_FAIL
);
6728 static LRESULT CALLBACK
export_finish_dlg_proc(HWND hwnd
, UINT msg
, WPARAM wp
,
6732 struct ExportWizData
*data
;
6738 PROPSHEETPAGEW
*page
= (PROPSHEETPAGEW
*)lp
;
6739 HWND lv
= GetDlgItem(hwnd
, IDC_EXPORT_SETTINGS
);
6743 data
= (struct ExportWizData
*)page
->lParam
;
6744 SetWindowLongPtrW(hwnd
, DWLP_USER
, (LPARAM
)data
);
6745 SendMessageW(GetDlgItem(hwnd
, IDC_EXPORT_TITLE
), WM_SETFONT
,
6746 (WPARAM
)data
->titleFont
, TRUE
);
6747 GetWindowRect(lv
, &rc
);
6748 column
.mask
= LVCF_WIDTH
;
6749 column
.cx
= (rc
.right
- rc
.left
) / 2 - 2;
6750 SendMessageW(lv
, LVM_INSERTCOLUMNW
, 0, (LPARAM
)&column
);
6751 SendMessageW(lv
, LVM_INSERTCOLUMNW
, 1, (LPARAM
)&column
);
6752 show_export_details(lv
, data
);
6757 NMHDR
*hdr
= (NMHDR
*)lp
;
6763 HWND lv
= GetDlgItem(hwnd
, IDC_EXPORT_SETTINGS
);
6765 data
= (struct ExportWizData
*)GetWindowLongPtrW(hwnd
, DWLP_USER
);
6766 SendMessageW(lv
, LVM_DELETEALLITEMS
, 0, 0);
6767 show_export_details(lv
, data
);
6768 PostMessageW(GetParent(hwnd
), PSM_SETWIZBUTTONS
, 0,
6769 PSWIZB_BACK
| PSWIZB_FINISH
);
6776 WCHAR title
[MAX_STRING_LEN
], message
[MAX_STRING_LEN
];
6780 data
= (struct ExportWizData
*)GetWindowLongPtrW(hwnd
, DWLP_USER
);
6781 if ((data
->success
= do_export(data
->file
, &data
->exportInfo
,
6782 &data
->contextInfo
, data
->keyProvInfo
, data
->deleteKeys
)))
6784 messageID
= IDS_EXPORT_SUCCEEDED
;
6789 messageID
= IDS_EXPORT_FAILED
;
6790 mbFlags
= MB_OK
| MB_ICONERROR
;
6792 if (data
->pwszWizardTitle
)
6793 pTitle
= data
->pwszWizardTitle
;
6796 LoadStringW(hInstance
, IDS_EXPORT_WIZARD
, title
, ARRAY_SIZE(title
));
6799 LoadStringW(hInstance
, messageID
, message
, ARRAY_SIZE(message
));
6800 MessageBoxW(hwnd
, message
, pTitle
, mbFlags
);
6810 static BOOL
show_export_ui(DWORD dwFlags
, HWND hwndParent
,
6811 LPCWSTR pwszWizardTitle
, PCCRYPTUI_WIZ_EXPORT_INFO pExportInfo
, const void *pvoid
)
6813 PROPSHEETHEADERW hdr
;
6814 PROPSHEETPAGEW pages
[6];
6815 struct ExportWizData data
;
6817 BOOL hasPrivateKey
, showFormatPage
= TRUE
;
6820 data
.dwFlags
= dwFlags
;
6821 data
.pwszWizardTitle
= pwszWizardTitle
;
6822 memset(&data
.exportInfo
, 0, sizeof(data
.exportInfo
));
6823 memcpy(&data
.exportInfo
, pExportInfo
,
6824 min(sizeof(data
.exportInfo
), pExportInfo
->dwSize
));
6825 if (pExportInfo
->dwSize
> sizeof(data
.exportInfo
))
6826 data
.exportInfo
.dwSize
= sizeof(data
.exportInfo
);
6827 data
.contextInfo
.dwSize
= sizeof(data
.contextInfo
);
6828 data
.contextInfo
.dwExportFormat
= CRYPTUI_WIZ_EXPORT_FORMAT_DER
;
6829 data
.contextInfo
.fExportChain
= FALSE
;
6830 data
.contextInfo
.fStrongEncryption
= FALSE
;
6831 data
.contextInfo
.fExportPrivateKeys
= FALSE
;
6832 data
.contextInfo
.pwszPassword
= NULL
;
6833 data
.freePassword
= FALSE
;
6834 if (pExportInfo
->dwSubjectChoice
== CRYPTUI_WIZ_EXPORT_CERT_CONTEXT
&&
6836 memcpy(&data
.contextInfo
, pvoid
,
6837 min(((PCCRYPTUI_WIZ_EXPORT_CERTCONTEXT_INFO
)pvoid
)->dwSize
,
6838 sizeof(data
.contextInfo
)));
6839 data
.keyProvInfo
= NULL
;
6840 data
.deleteKeys
= FALSE
;
6841 data
.fileName
= NULL
;
6842 data
.file
= INVALID_HANDLE_VALUE
;
6843 data
.success
= FALSE
;
6845 memset(pages
, 0, sizeof(pages
));
6847 pages
[nPages
].dwSize
= sizeof(pages
[0]);
6848 pages
[nPages
].hInstance
= hInstance
;
6849 pages
[nPages
].u
.pszTemplate
= MAKEINTRESOURCEW(IDD_EXPORT_WELCOME
);
6850 pages
[nPages
].pfnDlgProc
= export_welcome_dlg_proc
;
6851 pages
[nPages
].dwFlags
= PSP_HIDEHEADER
;
6852 pages
[nPages
].lParam
= (LPARAM
)&data
;
6855 hasPrivateKey
= export_info_has_private_key(pExportInfo
);
6856 switch (pExportInfo
->dwSubjectChoice
)
6858 case CRYPTUI_WIZ_EXPORT_CRL_CONTEXT
:
6859 case CRYPTUI_WIZ_EXPORT_CTL_CONTEXT
:
6860 showFormatPage
= FALSE
;
6861 data
.contextInfo
.dwExportFormat
= CRYPTUI_WIZ_EXPORT_FORMAT_DER
;
6863 case CRYPTUI_WIZ_EXPORT_CERT_STORE
:
6864 showFormatPage
= FALSE
;
6865 data
.contextInfo
.dwExportFormat
=
6866 CRYPTUI_WIZ_EXPORT_FORMAT_SERIALIZED_CERT_STORE
;
6868 case CRYPTUI_WIZ_EXPORT_CERT_STORE_CERTIFICATES_ONLY
:
6869 showFormatPage
= FALSE
;
6870 data
.contextInfo
.dwExportFormat
= CRYPTUI_WIZ_EXPORT_FORMAT_PKCS7
;
6874 if (hasPrivateKey
&& showFormatPage
)
6876 pages
[nPages
].dwSize
= sizeof(pages
[0]);
6877 pages
[nPages
].hInstance
= hInstance
;
6878 pages
[nPages
].u
.pszTemplate
= MAKEINTRESOURCEW(IDD_EXPORT_PRIVATE_KEY
);
6879 pages
[nPages
].pfnDlgProc
= export_private_key_dlg_proc
;
6880 pages
[nPages
].dwFlags
= PSP_USEHEADERTITLE
| PSP_USEHEADERSUBTITLE
;
6881 pages
[nPages
].pszHeaderTitle
=
6882 MAKEINTRESOURCEW(IDS_EXPORT_PRIVATE_KEY_TITLE
);
6883 pages
[nPages
].pszHeaderSubTitle
=
6884 MAKEINTRESOURCEW(IDS_EXPORT_PRIVATE_KEY_SUBTITLE
);
6885 pages
[nPages
].lParam
= (LPARAM
)&data
;
6890 pages
[nPages
].dwSize
= sizeof(pages
[0]);
6891 pages
[nPages
].hInstance
= hInstance
;
6892 pages
[nPages
].u
.pszTemplate
= MAKEINTRESOURCEW(IDD_EXPORT_FORMAT
);
6893 pages
[nPages
].pfnDlgProc
= export_format_dlg_proc
;
6894 pages
[nPages
].dwFlags
= PSP_USEHEADERTITLE
| PSP_USEHEADERSUBTITLE
;
6895 pages
[nPages
].pszHeaderTitle
=
6896 MAKEINTRESOURCEW(IDS_EXPORT_FORMAT_TITLE
);
6897 pages
[nPages
].pszHeaderSubTitle
=
6898 MAKEINTRESOURCEW(IDS_EXPORT_FORMAT_SUBTITLE
);
6899 pages
[nPages
].lParam
= (LPARAM
)&data
;
6902 if (hasPrivateKey
&& showFormatPage
)
6904 pages
[nPages
].dwSize
= sizeof(pages
[0]);
6905 pages
[nPages
].hInstance
= hInstance
;
6906 pages
[nPages
].u
.pszTemplate
= MAKEINTRESOURCEW(IDD_EXPORT_PASSWORD
);
6907 pages
[nPages
].pfnDlgProc
= export_password_dlg_proc
;
6908 pages
[nPages
].dwFlags
= PSP_USEHEADERTITLE
| PSP_USEHEADERSUBTITLE
;
6909 pages
[nPages
].pszHeaderTitle
=
6910 MAKEINTRESOURCEW(IDS_EXPORT_PASSWORD_TITLE
);
6911 pages
[nPages
].pszHeaderSubTitle
=
6912 MAKEINTRESOURCEW(IDS_EXPORT_PASSWORD_SUBTITLE
);
6913 pages
[nPages
].lParam
= (LPARAM
)&data
;
6917 pages
[nPages
].dwSize
= sizeof(pages
[0]);
6918 pages
[nPages
].hInstance
= hInstance
;
6919 pages
[nPages
].u
.pszTemplate
= MAKEINTRESOURCEW(IDD_EXPORT_FILE
);
6920 pages
[nPages
].pfnDlgProc
= export_file_dlg_proc
;
6921 pages
[nPages
].dwFlags
= PSP_USEHEADERTITLE
| PSP_USEHEADERSUBTITLE
;
6922 pages
[nPages
].pszHeaderTitle
= MAKEINTRESOURCEW(IDS_EXPORT_FILE_TITLE
);
6923 pages
[nPages
].pszHeaderSubTitle
=
6924 MAKEINTRESOURCEW(IDS_EXPORT_FILE_SUBTITLE
);
6925 pages
[nPages
].lParam
= (LPARAM
)&data
;
6928 pages
[nPages
].dwSize
= sizeof(pages
[0]);
6929 pages
[nPages
].hInstance
= hInstance
;
6930 pages
[nPages
].u
.pszTemplate
= MAKEINTRESOURCEW(IDD_EXPORT_FINISH
);
6931 pages
[nPages
].pfnDlgProc
= export_finish_dlg_proc
;
6932 pages
[nPages
].dwFlags
= PSP_HIDEHEADER
;
6933 pages
[nPages
].lParam
= (LPARAM
)&data
;
6936 memset(&hdr
, 0, sizeof(hdr
));
6937 hdr
.dwSize
= sizeof(hdr
);
6938 hdr
.hwndParent
= hwndParent
;
6939 hdr
.dwFlags
= PSH_PROPSHEETPAGE
| PSH_WIZARD97_NEW
| PSH_HEADER
|
6941 hdr
.hInstance
= hInstance
;
6942 if (pwszWizardTitle
)
6943 hdr
.pszCaption
= pwszWizardTitle
;
6945 hdr
.pszCaption
= MAKEINTRESOURCEW(IDS_EXPORT_WIZARD
);
6946 hdr
.u3
.ppsp
= pages
;
6947 hdr
.nPages
= nPages
;
6948 hdr
.u4
.pszbmWatermark
= MAKEINTRESOURCEW(IDB_CERT_WATERMARK
);
6949 hdr
.u5
.pszbmHeader
= MAKEINTRESOURCEW(IDB_CERT_HEADER
);
6950 l
= PropertySheetW(&hdr
);
6951 DeleteObject(data
.titleFont
);
6952 if (data
.freePassword
)
6953 HeapFree(GetProcessHeap(), 0,
6954 (LPWSTR
)data
.contextInfo
.pwszPassword
);
6955 HeapFree(GetProcessHeap(), 0, data
.keyProvInfo
);
6956 CloseHandle(data
.file
);
6957 HeapFree(GetProcessHeap(), 0, data
.fileName
);
6960 SetLastError(ERROR_CANCELLED
);
6964 return data
.success
;
6967 BOOL WINAPI
CryptUIWizExport(DWORD dwFlags
, HWND hwndParent
,
6968 LPCWSTR pwszWizardTitle
, PCCRYPTUI_WIZ_EXPORT_INFO pExportInfo
, void *pvoid
)
6972 TRACE("(%08x, %p, %s, %p, %p)\n", dwFlags
, hwndParent
,
6973 debugstr_w(pwszWizardTitle
), pExportInfo
, pvoid
);
6975 if (!(dwFlags
& CRYPTUI_WIZ_NO_UI
))
6976 ret
= show_export_ui(dwFlags
, hwndParent
, pwszWizardTitle
, pExportInfo
,
6980 HANDLE file
= CreateFileW(pExportInfo
->pwszExportFileName
,
6981 GENERIC_WRITE
, FILE_SHARE_READ
| FILE_SHARE_WRITE
, NULL
,
6982 CREATE_ALWAYS
, 0, NULL
);
6984 if (file
!= INVALID_HANDLE_VALUE
)
6986 ret
= do_export(file
, pExportInfo
, pvoid
, NULL
, FALSE
);
6995 BOOL WINAPI
CryptUIDlgViewSignerInfoA(CRYPTUI_VIEWSIGNERINFO_STRUCTA
*pcvsi
)
6997 FIXME("%p: stub\n", pcvsi
);
7001 static void init_columns(HWND lv
, DWORD flags
)
7003 WCHAR buf
[MAX_STRING_LEN
];
7007 SendMessageW(lv
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0, LVS_EX_FULLROWSELECT
);
7008 column
.mask
= LVCF_WIDTH
| LVCF_TEXT
;
7010 column
.pszText
= buf
;
7011 if (!(flags
& CRYPTUI_SELECT_ISSUEDTO_COLUMN
))
7013 LoadStringW(hInstance
, IDS_SUBJECT_COLUMN
, buf
, ARRAY_SIZE(buf
));
7014 SendMessageW(lv
, LVM_INSERTCOLUMNW
, i
++, (LPARAM
)&column
);
7016 if (!(flags
& CRYPTUI_SELECT_ISSUEDBY_COLUMN
))
7018 LoadStringW(hInstance
, IDS_ISSUER_COLUMN
, buf
, ARRAY_SIZE(buf
));
7019 SendMessageW(lv
, LVM_INSERTCOLUMNW
, i
++, (LPARAM
)&column
);
7021 if (!(flags
& CRYPTUI_SELECT_INTENDEDUSE_COLUMN
))
7023 LoadStringW(hInstance
, IDS_INTENDED_USE_COLUMN
, buf
, ARRAY_SIZE(buf
));
7024 SendMessageW(lv
, LVM_INSERTCOLUMNW
, i
++, (LPARAM
)&column
);
7026 if (!(flags
& CRYPTUI_SELECT_FRIENDLYNAME_COLUMN
))
7028 LoadStringW(hInstance
, IDS_FRIENDLY_NAME_COLUMN
, buf
, ARRAY_SIZE(buf
));
7029 SendMessageW(lv
, LVM_INSERTCOLUMNW
, i
++, (LPARAM
)&column
);
7031 if (!(flags
& CRYPTUI_SELECT_EXPIRATION_COLUMN
))
7033 LoadStringW(hInstance
, IDS_EXPIRATION_COLUMN
, buf
, ARRAY_SIZE(buf
));
7034 SendMessageW(lv
, LVM_INSERTCOLUMNW
, i
++, (LPARAM
)&column
);
7036 if (!(flags
& CRYPTUI_SELECT_LOCATION_COLUMN
))
7038 LoadStringW(hInstance
, IDS_LOCATION_COLUMN
, buf
, ARRAY_SIZE(buf
));
7039 SendMessageW(lv
, LVM_INSERTCOLUMNW
, i
++, (LPARAM
)&column
);
7043 static void add_cert_to_list(HWND lv
, PCCERT_CONTEXT cert
, DWORD flags
, DWORD
*allocatedLen
,
7048 WCHAR dateFmt
[80]; /* sufficient for LOCALE_SSHORTDATE */
7051 LPWSTR none
, usages
;
7053 item
.mask
= LVIF_IMAGE
| LVIF_PARAM
| LVIF_TEXT
;
7054 item
.iItem
= SendMessageW(lv
, LVM_GETITEMCOUNT
, 0, 0);
7057 item
.lParam
= (LPARAM
)CertDuplicateCertificateContext(cert
);
7060 item
.mask
|= LVIF_STATE
;
7061 item
.state
= LVIS_SELECTED
;
7062 item
.stateMask
= -1;
7064 if (!(flags
& CRYPTUI_SELECT_ISSUEDTO_COLUMN
))
7066 len
= CertGetNameStringW(cert
, CERT_NAME_SIMPLE_DISPLAY_TYPE
, 0, NULL
, NULL
, 0);
7067 if (len
> *allocatedLen
)
7069 HeapFree(GetProcessHeap(), 0, *str
);
7070 *str
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
7072 *allocatedLen
= len
;
7076 CertGetNameStringW(cert
, CERT_NAME_SIMPLE_DISPLAY_TYPE
, 0, NULL
, *str
, len
);
7077 item
.pszText
= *str
;
7078 SendMessageW(lv
, LVM_INSERTITEMW
, 0, (LPARAM
)&item
);
7080 item
.mask
= LVIF_TEXT
;
7083 if (!(flags
& CRYPTUI_SELECT_ISSUEDBY_COLUMN
))
7085 len
= CertGetNameStringW(cert
, CERT_NAME_SIMPLE_DISPLAY_TYPE
, CERT_NAME_ISSUER_FLAG
, NULL
,
7087 if (len
> *allocatedLen
)
7089 HeapFree(GetProcessHeap(), 0, *str
);
7090 *str
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
7092 *allocatedLen
= len
;
7096 CertGetNameStringW(cert
, CERT_NAME_SIMPLE_DISPLAY_TYPE
, CERT_NAME_ISSUER_FLAG
, NULL
,
7098 item
.pszText
= *str
;
7100 SendMessageW(lv
, LVM_INSERTITEMW
, 0, (LPARAM
)&item
);
7102 SendMessageW(lv
, LVM_SETITEMTEXTW
, item
.iItem
, (LPARAM
)&item
);
7104 item
.mask
= LVIF_TEXT
;
7107 if (!(flags
& CRYPTUI_SELECT_INTENDEDUSE_COLUMN
))
7109 get_cert_usages(cert
, &usages
);
7112 item
.pszText
= usages
;
7114 SendMessageW(lv
, LVM_INSERTITEMW
, 0, (LPARAM
)&item
);
7116 SendMessageW(lv
, LVM_SETITEMTEXTW
, item
.iItem
, (LPARAM
)&item
);
7117 HeapFree(GetProcessHeap(), 0, usages
);
7119 item
.mask
= LVIF_TEXT
;
7122 if (!(flags
& CRYPTUI_SELECT_FRIENDLYNAME_COLUMN
))
7124 if (!CertGetCertificateContextProperty(cert
, CERT_FRIENDLY_NAME_PROP_ID
, NULL
, &len
))
7125 len
= LoadStringW(hInstance
, IDS_FRIENDLY_NAME_NONE
, (LPWSTR
)&none
, 0);
7126 if (len
> *allocatedLen
)
7128 HeapFree(GetProcessHeap(), 0, *str
);
7129 *str
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
7131 *allocatedLen
= len
;
7135 if (!CertGetCertificateContextProperty(cert
, CERT_FRIENDLY_NAME_PROP_ID
, *str
, &len
))
7136 item
.pszText
= none
;
7138 item
.pszText
= *str
;
7140 SendMessageW(lv
, LVM_INSERTITEMW
, 0, (LPARAM
)&item
);
7142 SendMessageW(lv
, LVM_SETITEMTEXTW
, item
.iItem
, (LPARAM
)&item
);
7144 item
.mask
= LVIF_TEXT
;
7147 if (!(flags
& CRYPTUI_SELECT_EXPIRATION_COLUMN
))
7149 GetLocaleInfoW(LOCALE_SYSTEM_DEFAULT
, LOCALE_SSHORTDATE
, dateFmt
, ARRAY_SIZE(dateFmt
));
7150 FileTimeToSystemTime(&cert
->pCertInfo
->NotAfter
, &sysTime
);
7151 GetDateFormatW(LOCALE_SYSTEM_DEFAULT
, 0, &sysTime
, dateFmt
, buf
, ARRAY_SIZE(buf
));
7154 SendMessageW(lv
, LVM_INSERTITEMW
, 0, (LPARAM
)&item
);
7156 SendMessageW(lv
, LVM_SETITEMTEXTW
, item
.iItem
, (LPARAM
)&item
);
7157 item
.mask
= LVIF_TEXT
;
7160 if (!(flags
& CRYPTUI_SELECT_LOCATION_COLUMN
))
7162 static int show_fixme
;
7164 FIXME("showing location is not implemented\n");
7165 LoadStringW(hInstance
, IDS_NO_IMPL
, buf
, ARRAY_SIZE(buf
));
7167 SendMessageW(lv
, LVM_INSERTITEMW
, 0, (LPARAM
)&item
);
7169 SendMessageW(lv
, LVM_SETITEMTEXTW
, item
.iItem
, (LPARAM
)&item
);
7173 static void add_store_certs(HWND lv
, HCERTSTORE store
, DWORD flags
, PFNCFILTERPROC filter
,
7174 void *callback_data
)
7176 PCCERT_CONTEXT cert
= NULL
;
7177 BOOL select
= FALSE
;
7178 DWORD allocatedLen
= 0;
7182 cert
= CertEnumCertificatesInStore(store
, cert
);
7183 if (cert
&& (!filter
|| filter(cert
, &select
, callback_data
)))
7184 add_cert_to_list(lv
, cert
, flags
, &allocatedLen
, &str
);
7186 HeapFree(GetProcessHeap(), 0, str
);
7189 static PCCERT_CONTEXT
select_cert_get_selected(HWND hwnd
, int selection
)
7191 HWND lv
= GetDlgItem(hwnd
, IDC_SELECT_CERTS
);
7192 PCCERT_CONTEXT cert
= NULL
;
7196 selection
= SendMessageW(lv
, LVM_GETNEXTITEM
, -1, LVNI_SELECTED
);
7199 item
.mask
= LVIF_PARAM
;
7200 item
.iItem
= selection
;
7202 if (SendMessageW(lv
, LVM_GETITEMW
, 0, (LPARAM
)&item
))
7203 cert
= (PCCERT_CONTEXT
)item
.lParam
;
7207 static void select_cert_update_view_button(HWND hwnd
)
7209 HWND lv
= GetDlgItem(hwnd
, IDC_SELECT_CERTS
);
7210 int numSelected
= SendMessageW(lv
, LVM_GETSELECTEDCOUNT
, 0, 0);
7212 EnableWindow(GetDlgItem(hwnd
, IDC_SELECT_VIEW_CERT
), numSelected
== 1);
7215 struct SelectCertData
7217 PCCERT_CONTEXT
*cert
;
7219 HIMAGELIST imageList
;
7222 HCERTSTORE
*rghStores
;
7223 DWORD cPropSheetPages
;
7224 LPCPROPSHEETPAGEW rgPropSheetPages
;
7225 PFNCCERTDISPLAYPROC displayProc
;
7229 static void select_cert_view(HWND hwnd
, PCCERT_CONTEXT cert
, struct SelectCertData
*data
)
7231 CRYPTUI_VIEWCERTIFICATE_STRUCTW viewInfo
;
7233 if (data
->displayProc
&& data
->displayProc(cert
, hwnd
, data
->callbackData
))
7235 memset(&viewInfo
, 0, sizeof(viewInfo
));
7236 viewInfo
.dwSize
= sizeof(viewInfo
);
7237 viewInfo
.hwndParent
= hwnd
;
7238 viewInfo
.pCertContext
= cert
;
7239 viewInfo
.cStores
= data
->cStores
;
7240 viewInfo
.rghStores
= data
->rghStores
;
7241 viewInfo
.cPropSheetPages
= data
->cPropSheetPages
;
7242 viewInfo
.rgPropSheetPages
= data
->rgPropSheetPages
;
7243 /* FIXME: this should be modal */
7244 CryptUIDlgViewCertificateW(&viewInfo
, NULL
);
7253 static int CALLBACK
select_cert_sort_by_text(LPARAM lp1
, LPARAM lp2
, LPARAM lp
)
7255 struct SortData
*data
= (struct SortData
*)lp
;
7256 return cert_mgr_sort_by_text(data
->hwnd
, data
->column
, lp1
, lp2
);
7259 struct SelectCertParam
7261 PCCRYPTUI_SELECTCERTIFICATE_STRUCTW pcsc
;
7262 PCCERT_CONTEXT cert
;
7265 static LRESULT CALLBACK
select_cert_dlg_proc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
7267 struct SelectCertData
*data
;
7273 struct SelectCertParam
*param
= (struct SelectCertParam
*)lp
;
7274 PCCRYPTUI_SELECTCERTIFICATE_STRUCTW pcsc
= param
->pcsc
;
7275 HWND lv
= GetDlgItem(hwnd
, IDC_SELECT_CERTS
);
7278 data
= HeapAlloc(GetProcessHeap(), 0, sizeof(*data
));
7281 data
->cert
= ¶m
->cert
;
7282 data
->dateColumn
= 4 -
7283 ((pcsc
->dwDontUseColumn
& CRYPTUI_SELECT_ISSUEDTO_COLUMN
) ? 1 : 0) -
7284 ((pcsc
->dwDontUseColumn
& CRYPTUI_SELECT_ISSUEDBY_COLUMN
) ? 1 : 0) -
7285 ((pcsc
->dwDontUseColumn
& CRYPTUI_SELECT_INTENDEDUSE_COLUMN
) ? 1 : 0) -
7286 ((pcsc
->dwDontUseColumn
& CRYPTUI_SELECT_FRIENDLYNAME_COLUMN
) ? 1 : 0);
7287 data
->imageList
= ImageList_Create(16, 16, ILC_COLOR4
| ILC_MASK
, 2, 0);
7288 if (data
->imageList
)
7291 COLORREF backColor
= RGB(255, 0, 255);
7293 bmp
= LoadBitmapW(hInstance
, MAKEINTRESOURCEW(IDB_SMALL_ICONS
));
7294 ImageList_AddMasked(data
->imageList
, bmp
, backColor
);
7296 ImageList_SetBkColor(data
->imageList
, CLR_NONE
);
7297 SendMessageW(GetDlgItem(hwnd
, IDC_SELECT_CERTS
), LVM_SETIMAGELIST
, LVSIL_SMALL
,
7298 (LPARAM
)data
->imageList
);
7300 data
->title
= pcsc
->szTitle
;
7301 data
->cStores
= pcsc
->cStores
;
7302 data
->rghStores
= pcsc
->rghStores
;
7303 data
->cPropSheetPages
= pcsc
->cPropSheetPages
;
7304 data
->rgPropSheetPages
= pcsc
->rgPropSheetPages
;
7305 data
->displayProc
= pcsc
->pDisplayCallback
;
7306 data
->callbackData
= pcsc
->pvCallbackData
;
7307 SetWindowLongPtrW(hwnd
, DWLP_USER
, (LPARAM
)data
);
7310 SendMessageW(hwnd
, WM_SETTEXT
, 0, (LPARAM
)pcsc
->szTitle
);
7311 if (pcsc
->szDisplayString
)
7312 SendMessageW(GetDlgItem(hwnd
, IDC_SELECT_DISPLAY_STRING
), WM_SETTEXT
, 0,
7313 (LPARAM
)pcsc
->szDisplayString
);
7314 init_columns(lv
, pcsc
->dwDontUseColumn
);
7315 while (i
< pcsc
->cDisplayStores
)
7316 add_store_certs(lv
, pcsc
->rghDisplayStores
[i
++], pcsc
->dwDontUseColumn
,
7317 pcsc
->pFilterCallback
, pcsc
->pvCallbackData
);
7318 select_cert_update_view_button(hwnd
);
7323 NMHDR
*hdr
= (NMHDR
*)lp
;
7329 PCCERT_CONTEXT cert
= select_cert_get_selected(hwnd
, ((NMITEMACTIVATE
*)lp
)->iItem
);
7331 data
= (struct SelectCertData
*)GetWindowLongPtrW(hwnd
, DWLP_USER
);
7333 select_cert_view(hwnd
, cert
, data
);
7336 case LVN_COLUMNCLICK
:
7338 NMLISTVIEW
*nmlv
= (NMLISTVIEW
*)lp
;
7339 HWND lv
= GetDlgItem(hwnd
, IDC_SELECT_CERTS
);
7341 /* FIXME: doesn't support swapping sort order between ascending and descending. */
7342 data
= (struct SelectCertData
*)GetWindowLongPtrW(hwnd
, DWLP_USER
);
7343 if (nmlv
->iSubItem
== data
->dateColumn
)
7344 SendMessageW(lv
, LVM_SORTITEMS
, 0, (LPARAM
)cert_mgr_sort_by_date
);
7347 struct SortData sortData
;
7350 sortData
.column
= nmlv
->iSubItem
;
7351 SendMessageW(lv
, LVM_SORTITEMSEX
, (WPARAM
)&sortData
,
7352 (LPARAM
)select_cert_sort_by_text
);
7364 PCCERT_CONTEXT cert
= select_cert_get_selected(hwnd
, -1);
7366 data
= (struct SelectCertData
*)GetWindowLongPtrW(hwnd
, DWLP_USER
);
7369 WCHAR buf
[40], title
[40];
7371 LoadStringW(hInstance
, IDS_SELECT_CERT
, buf
, ARRAY_SIZE(buf
));
7373 LoadStringW(hInstance
, IDS_SELECT_CERT_TITLE
, title
, ARRAY_SIZE(title
));
7374 MessageBoxW(hwnd
, buf
, data
->title
? data
->title
: title
, MB_OK
| MB_ICONWARNING
);
7377 *data
->cert
= CertDuplicateCertificateContext(cert
);
7378 free_certs(GetDlgItem(hwnd
, IDC_SELECT_CERTS
));
7379 ImageList_Destroy(data
->imageList
);
7380 HeapFree(GetProcessHeap(), 0, data
);
7381 EndDialog(hwnd
, IDOK
);
7385 data
= (struct SelectCertData
*)GetWindowLongPtrW(hwnd
, DWLP_USER
);
7386 free_certs(GetDlgItem(hwnd
, IDC_SELECT_CERTS
));
7387 ImageList_Destroy(data
->imageList
);
7388 HeapFree(GetProcessHeap(), 0, data
);
7389 EndDialog(hwnd
, IDCANCEL
);
7391 case IDC_SELECT_VIEW_CERT
:
7393 PCCERT_CONTEXT cert
= select_cert_get_selected(hwnd
, -1);
7395 data
= (struct SelectCertData
*)GetWindowLongPtrW(hwnd
, DWLP_USER
);
7397 select_cert_view(hwnd
, cert
, data
);
7406 PCCERT_CONTEXT WINAPI
CryptUIDlgSelectCertificateW(PCCRYPTUI_SELECTCERTIFICATE_STRUCTW pcsc
)
7408 struct SelectCertParam param
;
7410 TRACE("%p\n", pcsc
);
7412 if (pcsc
->dwSize
!= sizeof(*pcsc
) && pcsc
->dwSize
!= sizeof(*pcsc
) - sizeof(HCERTSTORE
))
7414 WARN("unexpected size %d\n", pcsc
->dwSize
);
7415 SetLastError(E_INVALIDARG
);
7418 if (pcsc
->dwFlags
& CRYPTUI_SELECTCERT_MULTISELECT
)
7419 FIXME("ignoring CRYPTUI_SELECTCERT_MULTISELECT\n");
7422 DialogBoxParamW(hInstance
, MAKEINTRESOURCEW(IDD_SELECT_CERT
), pcsc
->hwndParent
,
7423 select_cert_dlg_proc
, (LPARAM
)¶m
);
7427 static void free_prop_sheet_pages(PROPSHEETPAGEW
*pages
, DWORD num
)
7431 for (i
= 0; i
< num
; i
++)
7433 if (!(pages
[i
].dwFlags
& PSP_DLGINDIRECT
) && !IS_INTRESOURCE(pages
[i
].u
.pszTemplate
))
7434 HeapFree(GetProcessHeap(), 0, (void *)pages
[i
].u
.pszTemplate
);
7435 if ((pages
[i
].dwFlags
& PSP_USEICONID
) && !IS_INTRESOURCE(pages
[i
].u2
.pszIcon
))
7436 HeapFree(GetProcessHeap(), 0, (void *)pages
[i
].u2
.pszIcon
);
7437 if ((pages
[i
].dwFlags
& PSP_USETITLE
) && !IS_INTRESOURCE(pages
[i
].pszTitle
))
7438 HeapFree(GetProcessHeap(), 0, (void *)pages
[i
].pszTitle
);
7439 if ((pages
[i
].dwFlags
& PSP_USEHEADERTITLE
) && !IS_INTRESOURCE(pages
[i
].pszHeaderTitle
))
7440 HeapFree(GetProcessHeap(), 0, (void *)pages
[i
].pszHeaderTitle
);
7441 if ((pages
[i
].dwFlags
& PSP_USEHEADERSUBTITLE
) &&
7442 !IS_INTRESOURCE(pages
[i
].pszHeaderSubTitle
))
7443 HeapFree(GetProcessHeap(), 0, (void *)pages
[i
].pszHeaderSubTitle
);
7445 HeapFree(GetProcessHeap(), 0, pages
);
7448 static PROPSHEETPAGEW
*prop_sheet_pages_AtoW(LPCPROPSHEETPAGEA pages
, DWORD num
)
7450 PROPSHEETPAGEW
*psp
;
7451 DWORD i
, size
= sizeof(*psp
) * num
;
7453 psp
= HeapAlloc(GetProcessHeap(), 0, size
);
7456 memcpy(psp
, pages
, size
);
7457 for (i
= 0; i
< num
; i
++)
7459 if (!(pages
[i
].dwFlags
& PSP_DLGINDIRECT
) && !IS_INTRESOURCE(pages
[i
].u
.pszTemplate
))
7460 psp
[i
].u
.pszTemplate
= NULL
;
7461 if ((pages
[i
].dwFlags
& PSP_USEICONID
) && !IS_INTRESOURCE(pages
[i
].u2
.pszIcon
))
7462 psp
[i
].u2
.pszIcon
= NULL
;
7463 if ((pages
[i
].dwFlags
& PSP_USETITLE
) && !IS_INTRESOURCE(pages
[i
].pszTitle
))
7464 psp
[i
].pszTitle
= NULL
;
7465 if (pages
[i
].dwFlags
& PSP_USECALLBACK
)
7466 psp
[i
].pfnCallback
= NULL
;
7467 if ((pages
[i
].dwFlags
& PSP_USEHEADERTITLE
) && !IS_INTRESOURCE(pages
[i
].pszHeaderTitle
))
7468 psp
[i
].pszHeaderTitle
= NULL
;
7469 if ((pages
[i
].dwFlags
& PSP_USEHEADERSUBTITLE
) &&
7470 !IS_INTRESOURCE(pages
[i
].pszHeaderSubTitle
))
7471 psp
[i
].pszHeaderSubTitle
= NULL
;
7473 for (i
= 0; i
< num
; i
++)
7475 if (!(pages
[i
].dwFlags
& PSP_DLGINDIRECT
) && !IS_INTRESOURCE(pages
[i
].u
.pszTemplate
))
7477 if (!(psp
[i
].u
.pszTemplate
= strdupAtoW( pages
[i
].u
.pszTemplate
))) goto error
;
7479 if ((pages
[i
].dwFlags
& PSP_USEICONID
) && !IS_INTRESOURCE(pages
[i
].u2
.pszIcon
))
7481 if (!(psp
[i
].u2
.pszIcon
= strdupAtoW( pages
[i
].u2
.pszIcon
))) goto error
;
7483 if ((pages
[i
].dwFlags
& PSP_USETITLE
) && !IS_INTRESOURCE(pages
[i
].pszTitle
))
7485 if (!(psp
[i
].pszTitle
= strdupAtoW( pages
[i
].pszTitle
))) goto error
;
7487 if (pages
[i
].dwFlags
& PSP_USECALLBACK
)
7488 FIXME("ignoring pfnCallback\n");
7489 if ((pages
[i
].dwFlags
& PSP_USEHEADERTITLE
) && !IS_INTRESOURCE(pages
[i
].pszHeaderTitle
))
7491 if (!(psp
[i
].pszHeaderTitle
= strdupAtoW( pages
[i
].pszHeaderTitle
))) goto error
;
7493 if ((pages
[i
].dwFlags
& PSP_USEHEADERSUBTITLE
) &&
7494 !IS_INTRESOURCE(pages
[i
].pszHeaderSubTitle
))
7496 if (!(psp
[i
].pszHeaderSubTitle
= strdupAtoW( pages
[i
].pszHeaderSubTitle
))) goto error
;
7501 free_prop_sheet_pages(psp
, num
);
7505 PCCERT_CONTEXT WINAPI
CryptUIDlgSelectCertificateA(PCCRYPTUI_SELECTCERTIFICATE_STRUCTA pcsc
)
7507 PCCERT_CONTEXT cert
= NULL
;
7508 CRYPTUI_SELECTCERTIFICATE_STRUCTW selCertInfo
;
7509 LPWSTR title
= NULL
, display_str
= NULL
;
7510 PROPSHEETPAGEW
*pages
= NULL
;
7512 TRACE("%p\n", pcsc
);
7514 if (pcsc
->dwSize
!= sizeof(*pcsc
) && pcsc
->dwSize
!= sizeof(*pcsc
) - sizeof(HCERTSTORE
))
7516 WARN("unexpected size %d\n", pcsc
->dwSize
);
7517 SetLastError(E_INVALIDARG
);
7520 memcpy(&selCertInfo
, pcsc
, pcsc
->dwSize
);
7523 if (!(title
= strdupAtoW( pcsc
->szTitle
))) goto error
;
7524 selCertInfo
.szTitle
= title
;
7526 if (pcsc
->szDisplayString
)
7528 if (!(display_str
= strdupAtoW( pcsc
->szDisplayString
))) goto error
;
7529 selCertInfo
.szDisplayString
= display_str
;
7531 if (pcsc
->cPropSheetPages
)
7533 pages
= prop_sheet_pages_AtoW(pcsc
->rgPropSheetPages
, pcsc
->cPropSheetPages
);
7536 selCertInfo
.rgPropSheetPages
= pages
;
7538 cert
= CryptUIDlgSelectCertificateW(&selCertInfo
);
7540 HeapFree(GetProcessHeap(), 0, title
);
7541 HeapFree(GetProcessHeap(), 0, display_str
);
7542 if (pcsc
->cPropSheetPages
)
7543 free_prop_sheet_pages(pages
, pcsc
->cPropSheetPages
);
7547 PCCERT_CONTEXT WINAPI
CryptUIDlgSelectCertificateFromStore(HCERTSTORE hCertStore
, HWND hwnd
, LPCWSTR pwszTitle
,
7548 LPCWSTR pwszDisplayString
, DWORD dwDontUseColumn
,
7549 DWORD dwFlags
, void *pvReserved
)
7551 CRYPTUI_SELECTCERTIFICATE_STRUCTW sc
;
7553 TRACE("%p %p %s %s %x %x %p\n", hCertStore
, hwnd
, debugstr_w(pwszTitle
), debugstr_w(pwszDisplayString
), dwDontUseColumn
, dwFlags
, pvReserved
);
7555 memset(&sc
, 0, sizeof(sc
));
7557 sc
.dwSize
= sizeof(sc
);
7558 sc
.hwndParent
= hwnd
;
7559 sc
.dwFlags
= dwFlags
;
7560 sc
.szTitle
= pwszTitle
;
7561 sc
.szDisplayString
= pwszDisplayString
;
7562 sc
.dwDontUseColumn
= dwDontUseColumn
;
7563 sc
.cDisplayStores
= 1;
7564 sc
.rghDisplayStores
= &hCertStore
;
7565 return CryptUIDlgSelectCertificateW(&sc
);
7568 BOOL WINAPI
CryptUIWizDigitalSign(DWORD flags
, HWND parent
, LPCWSTR title
, PCCRYPTUI_WIZ_DIGITAL_SIGN_INFO info
,
7569 PCCRYPTUI_WIZ_DIGITAL_SIGN_CONTEXT
*context
)
7571 FIXME("%d %p %s %p %p: stub\n", flags
, parent
, debugstr_w(title
), info
, context
);