Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

438 lines
19 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997 - 1999
  6. //
  7. // File: internal.h
  8. //
  9. //--------------------------------------------------------------------------
  10. #ifndef _INTERNAL_H
  11. #define _INTERNAL_H
  12. #include "richedit.h"
  13. #include "ccertbmp.h"
  14. #define CRYPTUI_MAX_STRING_SIZE 768
  15. ///////////////////////////////////////////////////////////////////////////////
  16. // macro for getting the number of bytes in an array
  17. ///////////////////////////////////////////////////////////////////////////////
  18. #define ARRAYSIZE(x) (sizeof(x)/sizeof(x[0]))
  19. #define ICON_X_POS 21
  20. #define ICON_Y_POS 10
  21. #define IMAGE_PROPERTY 0
  22. #define IMAGE_EXTENSION 1
  23. #define IMAGE_CRITICAL_EXTENSION 2
  24. #define IMAGE_V1 3
  25. ///////////////////////////////////////////////////////////////////////////////
  26. // this structure is used to subclass an edit control and give it a link look
  27. // and feel
  28. ///////////////////////////////////////////////////////////////////////////////
  29. typedef struct _LIST_DISPLAY_HELPER {
  30. BOOL fHexText;
  31. LPWSTR pwszDisplayText;
  32. BYTE *pbData;
  33. DWORD cbData;
  34. } LIST_DISPLAY_HELPER, *PLIST_DISPLAY_HELPER;
  35. ///////////////////////////////////////////////////////////////////////////////
  36. // this structure is used to subclass an edit control and give it a link look
  37. // and feel
  38. ///////////////////////////////////////////////////////////////////////////////
  39. typedef struct _LINK_SUBCLASS_DATA {
  40. HWND hwndParent;
  41. WNDPROC wpPrev;
  42. DWORD uId;
  43. HWND hwndTip;
  44. LPSTR pszURL;
  45. BOOL fMouseCaptured;
  46. BOOL fNoCOM;
  47. BOOL fUseArrowInsteadOfHand;
  48. } LINK_SUBCLASS_DATA, *PLINK_SUBCLASS_DATA;
  49. ///////////////////////////////////////////////////////////////////////////////
  50. // this structure is used to for the CertViewCert api and it's supporting
  51. // property sheet dialog procs
  52. ///////////////////////////////////////////////////////////////////////////////
  53. #define MAX_CERT_CHAIN_LENGTH 40
  54. typedef struct {
  55. PCCRYPTUI_VIEWCERTIFICATE_STRUCTW pcvp;
  56. DWORD cpCryptProviderCerts;
  57. PCRYPT_PROVIDER_CERT rgpCryptProviderCerts[MAX_CERT_CHAIN_LENGTH];
  58. DWORD dwChainError;
  59. DWORD cUsages;
  60. LPSTR *rgUsages;
  61. HTREEITEM hItem; // Leaf item in trust view
  62. BOOL fDblClk;
  63. CCertificateBmp *pCCertBmp;
  64. HWND hwndGeneralPage;
  65. HWND hwndDetailPage;
  66. HWND hwndHierarchyPage;
  67. RECT goodForOriginalRect;
  68. WINTRUST_DATA sWTD;
  69. WINTRUST_CERT_INFO sWTCI;
  70. BOOL fFreeWTD;
  71. BOOL fAddingToChain;
  72. BOOL fDeletingChain;
  73. LPWSTR pwszErrorString;
  74. BOOL fAccept;
  75. BOOL fNoCOM;
  76. BOOL *pfPropertiesChanged;
  77. BOOL fCPSDisplayed;
  78. BOOL fIgnoreUntrustedRoot;
  79. BOOL fWarnUntrustedRoot;
  80. BOOL fRootInRemoteStore;
  81. HICON hIcon;
  82. BOOL fCancelled;
  83. BOOL fIssuerDisplayedAsLink;
  84. BOOL fSubjectDisplayedAsLink;
  85. BOOL fWarnRemoteTrust;
  86. } CERT_VIEW_HELPER, *PCERT_VIEW_HELPER;
  87. #define WM_MY_REINITIALIZE (WM_USER+20)
  88. ///////////////////////////////////////////////////////////////////////////////
  89. // this structure is used to for the CertViewCTL api and it's supporting
  90. // property sheet dialog procs
  91. ///////////////////////////////////////////////////////////////////////////////
  92. typedef struct {
  93. PCCRYPTUI_VIEWCTL_STRUCTW pcvctl;
  94. DWORD chStores;
  95. HCERTSTORE *phStores;
  96. HCERTSTORE hExtraStore;
  97. PCCERT_CONTEXT pSignerCert;
  98. PCMSG_SIGNER_INFO pbSignerInfo;
  99. DWORD cbSignerInfo;
  100. HICON hIcon;
  101. HCRYPTMSG hMsg;
  102. int previousSelection;
  103. int currentSelection;
  104. BOOL fNoSignature;
  105. BOOL fCancelled;
  106. DWORD dwInheritableError;
  107. BOOL fCatFile;
  108. } CTL_VIEW_HELPER, *PCTL_VIEW_HELPER;
  109. ///////////////////////////////////////////////////////////////////////////////
  110. // this structure is used to for the CertViewCRL api and it's supporting
  111. // property sheet dialog procs
  112. ///////////////////////////////////////////////////////////////////////////////
  113. typedef struct {
  114. PCCRYPTUI_VIEWCRL_STRUCTW pcvcrl;
  115. int currentSelection;
  116. HICON hIcon;
  117. BOOL fCancelled;
  118. } CRL_VIEW_HELPER, *PCRL_VIEW_HELPER;
  119. ///////////////////////////////////////////////////////////////////////////////
  120. // this structure is used to for the CertSetProperties api and it's supporting
  121. // property sheet dialog procs
  122. ///////////////////////////////////////////////////////////////////////////////
  123. typedef struct {
  124. PCCRYPTUI_VIEWCERTIFICATEPROPERTIES_STRUCTW pcsp;
  125. LPWSTR pwszInitialCertName;
  126. LPWSTR pwszInitialDescription;
  127. BOOL fSelfCleanup;
  128. BOOL fInserting;
  129. BOOL *pfPropertiesChanged;
  130. BOOL fPropertiesChanged;
  131. BOOL fGetPagesCalled;
  132. LPSTR *rgszValidChainUsages;
  133. int cszValidUsages;
  134. DWORD EKUPropertyState;
  135. BOOL fAddPurposeCanBeEnabled;
  136. BOOL fCancelled;
  137. DWORD dwRadioButtonState;
  138. BOOL fMMCCallbackMade;
  139. BOOL InWMInit;
  140. } CERT_SETPROPERTIES_HELPER, *PCERT_SETPROPERTIES_HELPER;
  141. ///////////////////////////////////////////////////////////////////////////////
  142. // this structure is used to for the CertViewSignerInfo api
  143. ///////////////////////////////////////////////////////////////////////////////
  144. #define CRYPTUI_VIEWSIGNERINFO_RESERVED_FIELD_IS_SIGNERINFO_PRIVATE 0x80000000
  145. #define CRYPTUI_VIEWSIGNERINFO_RESERVED_FIELD_IS_ERROR_CODE 0x40000000
  146. typedef struct {
  147. PCRYPT_PROVIDER_DATA pCryptProviderData;
  148. BOOL fpCryptProviderDataTrustedUsage;
  149. DWORD idxSigner;
  150. BOOL fCounterSigner;
  151. DWORD idxCounterSigner;
  152. DWORD dwInheritedError;
  153. } CERT_VIEWSIGNERINFO_PRIVATE, *PCERT_VIEWSIGNERINFO_PRIVATE;
  154. ///////////////////////////////////////////////////////////////////////////////
  155. // this structure is used to for the CertViewSignerInfo api and it's supporting
  156. // property sheet dialog procs
  157. ///////////////////////////////////////////////////////////////////////////////
  158. typedef struct {
  159. PCCRYPTUI_VIEWSIGNERINFO_STRUCTW pcvsi;
  160. PCCERT_CONTEXT pSignersCert;
  161. int previousSelection;
  162. int currentSelection;
  163. HICON hIcon;
  164. HCERTSTORE hExtraStore;
  165. PCERT_VIEWSIGNERINFO_PRIVATE pPrivate;
  166. BOOL fPrivateAllocated;
  167. CRYPT_PROVIDER_DEFUSAGE CryptProviderDefUsage;
  168. WINTRUST_DATA WTD;
  169. BOOL fUseDefaultProvider;
  170. BOOL fCancelled;
  171. DWORD dwInheritedError;
  172. } SIGNER_VIEW_HELPER, *PSIGNER_VIEW_HELPER;
  173. ///////////////////////////////////////////////////////////////////////////////
  174. // this structure is used to for the CertViewSignatures api and it's supporting
  175. // property sheet dialog procs
  176. ///////////////////////////////////////////////////////////////////////////////
  177. typedef struct {
  178. PCRYPTUI_VIEWSIGNATURES_STRUCTW pcvs;
  179. BOOL fSelfCleanup;
  180. HCERTSTORE hExtraStore;
  181. } CERT_VIEWSIGNATURES_HELPER, *PCERT_VIEWSIGNATURES_HELPER;
  182. ///////////////////////////////////////////////////////////////////////////////
  183. // these functions are the property pages procs for the CertViewCert API
  184. ///////////////////////////////////////////////////////////////////////////////
  185. INT_PTR APIENTRY ViewPageDetails(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
  186. INT_PTR APIENTRY ViewPageGeneral(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
  187. INT_PTR APIENTRY ViewPageHierarchy(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
  188. ///////////////////////////////////////////////////////////////////////////////
  189. // these functions are the property pages procs for the CertViewCTL API
  190. ///////////////////////////////////////////////////////////////////////////////
  191. INT_PTR APIENTRY ViewPageCTLGeneral(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
  192. INT_PTR APIENTRY ViewPageCTLTrustList(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
  193. INT_PTR APIENTRY ViewPageCatalogEntries(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
  194. ///////////////////////////////////////////////////////////////////////////////
  195. // these functions are the property pages procs for the CertViewCRL API
  196. ///////////////////////////////////////////////////////////////////////////////
  197. INT_PTR APIENTRY ViewPageCRLGeneral(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
  198. INT_PTR APIENTRY ViewPageCRLRevocationList(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
  199. ///////////////////////////////////////////////////////////////////////////////
  200. // these functions are the property pages procs for the CertViewSignerInfo API
  201. ///////////////////////////////////////////////////////////////////////////////
  202. INT_PTR APIENTRY ViewPageSignerGeneral(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
  203. INT_PTR APIENTRY ViewPageSignerAdvanced(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
  204. ///////////////////////////////////////////////////////////////////////////////
  205. // used for obvious purposes
  206. ///////////////////////////////////////////////////////////////////////////////
  207. BOOL IsWin95(void);
  208. extern BOOL FIsWin95;
  209. BOOL CheckRichedit20Exists(void);
  210. extern BOOL fRichedit20Exists;
  211. BOOL fRichedit20Usable(HWND hwndEdit);
  212. #undef SetWindowLong
  213. #define SetWindowLong SetWindowLongA
  214. #undef GetWindowLong
  215. #define GetWindowLong GetWindowLongA
  216. #undef SendMessage
  217. #define SendMessage SendMessageA
  218. //
  219. // frmtutil.cpp
  220. //
  221. BOOL FormatAlgorithmString(LPWSTR *ppString, CRYPT_ALGORITHM_IDENTIFIER const *pAlgorithm);
  222. BOOL FormatSerialNoString(LPWSTR *ppString, CRYPT_INTEGER_BLOB const *pblob);
  223. BOOL FormatMemBufToString(LPWSTR *ppString, LPBYTE pbData, DWORD cbData);
  224. BOOL FormatDateString(LPWSTR *ppString, FILETIME ft, BOOL fIncludeTime, BOOL fLongFormat, HWND hwnd = NULL);
  225. BOOL FormatValidityString(LPWSTR *ppString, PCCERT_CONTEXT pCertContext, HWND hwnd = NULL);
  226. BOOL FormatDNNameString(LPWSTR *ppString, LPBYTE pbData, DWORD cbData, BOOL fMultiline);
  227. BOOL FormatEnhancedKeyUsageString(LPWSTR *ppString, PCCERT_CONTEXT pCertContext, BOOL fPropertiesOnly, BOOL fMultiline);
  228. BOOL FormatMemBufToWindow(HWND hWnd, LPBYTE pbData, DWORD cbData);
  229. LPWSTR AllocAndReturnSignTime(CMSG_SIGNER_INFO const *pSignerInfo, FILETIME **ppSignTime, HWND hwnd = NULL);
  230. LPWSTR AllocAndReturnTimeStampersTimes(CMSG_SIGNER_INFO const *pSignerInfo, FILETIME **ppSignTime, HWND hwnd = NULL);
  231. LPWSTR FormatCTLSubjectUsage(CTL_USAGE *pSubjectUsage, BOOL fMultiline);
  232. //
  233. // usagutil.cpp
  234. //
  235. BOOL OIDinArray(LPCSTR pszOID, LPSTR *rgszOIDArray, DWORD cOIDs);
  236. BOOL AllocAndReturnKeyUsageList(PCRYPT_PROVIDER_CERT pCryptProviderCert, LPSTR **pKeyUsageOIDs, DWORD *numOIDs);
  237. BOOL AllocAndReturnEKUList(PCCERT_CONTEXT pCert, LPSTR **pKeyUsageOIDs, DWORD *numOIDs);
  238. void FreeEKUList(LPSTR *pKeyUsageOIDs, DWORD numOIDs);
  239. BOOL MyGetOIDInfo(LPWSTR string, DWORD stringSize, LPSTR pszObjId);
  240. BOOL OIDInUsages(PCERT_ENHKEY_USAGE pUsage, LPCSTR pszOID);
  241. BOOL fPropertiesDisabled(PCERT_ENHKEY_USAGE pPropertyUsage);
  242. BOOL CertHasEmptyEKUProp(PCCERT_CONTEXT pCertContext);
  243. BOOL ValidateCertForUsage(
  244. PCCERT_CONTEXT pCertContext,
  245. FILETIME *psftVerifyAsOf,
  246. DWORD cStores,
  247. HCERTSTORE * rghStores,
  248. HCERTSTORE hExtraStore,
  249. LPCSTR pszOID);
  250. //
  251. // linkutil.cpp
  252. //
  253. void CryptuiGoLink(HWND hwndParent, char *pszWhere, BOOL fNoCOM);
  254. BOOL AllocAndGetIssuerURL(LPSTR *ppURLString, PCCERT_CONTEXT pCertContext);
  255. BOOL AllocAndGetSubjectURL(LPSTR *ppURLString, PCCERT_CONTEXT pCertContext);
  256. //
  257. // cps.cpp
  258. //
  259. DWORD GetCPSInfo(PCCERT_CONTEXT pCertContext, LPWSTR * ppwszUrlString, LPWSTR * ppwszDisplayText);
  260. BOOL IsOKToDisplayCPS(PCCERT_CONTEXT pCertContext, DWORD dwChainError);
  261. BOOL DisplayCPS(HWND hwnd, PCCERT_CONTEXT pCertContext, DWORD dwChainError, BOOL fNoCOM);
  262. //
  263. // disputil.cpp
  264. //
  265. void DisplayExtensions(HWND hWndListView, DWORD cExtension, PCERT_EXTENSION rgExtension, BOOL fCritical, DWORD *index);
  266. PLIST_DISPLAY_HELPER MakeListDisplayHelper(BOOL fHexText, LPWSTR pwszDisplayText, BYTE *pbData, DWORD cbData);
  267. PLIST_DISPLAY_HELPER MakeListDisplayHelperForExtension(LPSTR pszObjId, BYTE *pbData, DWORD cbData);
  268. void FreeListDisplayHelper(PLIST_DISPLAY_HELPER pDisplayHelper);
  269. void DisplayHelperTextInEdit(HWND hWndListView, HWND hwndDlg, int nIDEdit, int index);
  270. void SetTextFormatInitial(HWND hWnd);
  271. void SetTextFormatHex(HWND hWnd);
  272. BOOL GetUnknownErrorString(LPWSTR *ppwszErrorString, DWORD dwError);
  273. BOOL GetCertErrorString(LPWSTR *ppwszErrorString, PCRYPT_PROVIDER_CERT pCryptProviderCert);
  274. void CertSubclassEditControlForArrowCursor (HWND hwndEdit);
  275. void CertSubclassEditControlForLink (HWND hwndDlg, HWND hwndEdit, PLINK_SUBCLASS_DATA plsd);
  276. void * GetStoreName(HCERTSTORE hCertStore, BOOL fWideChar);
  277. void ModifyOrInsertRow(
  278. HWND hWndListView,
  279. LV_ITEMW *plvI,
  280. LPWSTR pwszValueText,
  281. LPWSTR pwszText,
  282. BOOL fAddRows,
  283. BOOL fHex);
  284. int CALLBACK HidePropSheetCancelButtonCallback(
  285. HWND hwndDlg,
  286. UINT uMsg,
  287. LPARAM lParam);
  288. INT_PTR WINAPI CryptUIPropertySheetA(LPCPROPSHEETHEADERA pHdr);
  289. INT_PTR WINAPI CryptUIPropertySheetW(LPCPROPSHEETHEADERW pHdr);
  290. BOOL IsTrueErrorString(CERT_VIEW_HELPER *pviewhelp);
  291. //
  292. // convutil.cpp
  293. //
  294. LPSTR CertUIMkMBStr(LPCWSTR pwsz);
  295. LPWSTR CertUIMkWStr(LPCSTR psz);
  296. LPSTR AllocAndCopyMBStr(LPCSTR psz);
  297. LPWSTR AllocAndCopyWStr(LPCWSTR pwsz);
  298. LPPROPSHEETPAGEA ConvertToPropPageA(LPCPROPSHEETPAGEW ppage, DWORD cPages);
  299. void FreePropSheetPagesA(LPPROPSHEETPAGEA ppage, DWORD cPages);
  300. BOOL ConvertToPropPageW(LPCPROPSHEETPAGEA ppage, DWORD cPages, LPCPROPSHEETPAGEW *pppageW);
  301. void FreePropSheetPagesW(LPPROPSHEETPAGEW ppage, DWORD cPages);
  302. //
  303. // gettrst.cpp
  304. //
  305. BOOL CalculateUsages(PCERT_VIEW_HELPER pviewhelp);
  306. BOOL BuildChain(PCERT_VIEW_HELPER pviewhelp, LPSTR pszUsage);
  307. BOOL BuildWinVTrustState(
  308. LPCWSTR szFileName,
  309. CMSG_SIGNER_INFO const *pSignerInfo,
  310. DWORD cStores,
  311. HCERTSTORE *rghStores,
  312. LPCSTR pszOID,
  313. PCERT_VIEWSIGNERINFO_PRIVATE pcvsiPrivate,
  314. CRYPT_PROVIDER_DEFUSAGE *pCryptProviderDefUsage,
  315. WINTRUST_DATA *pWTD);
  316. BOOL FreeWinVTrustState(
  317. LPCWSTR szFileName,
  318. CMSG_SIGNER_INFO const *pSignerInfo,
  319. DWORD cStores,
  320. HCERTSTORE *rghStores,
  321. LPCSTR pszOID,
  322. CRYPT_PROVIDER_DEFUSAGE *pCryptProviderDefUsage,
  323. WINTRUST_DATA *pWTD);
  324. //
  325. // other stuff (util.cpp)
  326. //
  327. BOOL CommonInit();
  328. BOOL FreeAndCloseKnownStores(DWORD chStores, HCERTSTORE *phStores);
  329. BOOL AllocAndOpenKnownStores(DWORD *chStores, HCERTSTORE **pphStores);
  330. HBITMAP LoadResourceBitmap(HINSTANCE hInstance, LPSTR lpString, HPALETTE* lphPalette);
  331. void MaskBlt
  332. (
  333. HBITMAP& hbmImage,
  334. HPALETTE hpal,
  335. HDC& hdc, int xDst, int yDst, int dx, int dy
  336. );
  337. PCCERT_CONTEXT GetSignersCert(CMSG_SIGNER_INFO const *pSignerInfo, HCERTSTORE hExtraStore, DWORD cStores, HCERTSTORE *rghStores);
  338. BOOL fIsCatalogFile(CTL_USAGE *pSubjectUsage);
  339. DWORD CryptUISetRicheditTextW(HWND hwndDlg, UINT id, LPCWSTR pwsz);
  340. void SetRicheditIMFOption(HWND hWndRichEdit);
  341. /*BOOL CryptUISetupFonts(HFONT *pBoldFont);
  342. void CryptUIDestroyFonts(HFONT hBoldFont);
  343. void CryptUISetControlFont(HFONT hFont, HWND hwnd, INT nId);
  344. */
  345. //
  346. // These routines extract and pretty print fields in the certs. The
  347. // routines use crt to allocate and return a buffer
  348. //
  349. LPWSTR PrettySubject(PCCERT_CONTEXT pccert);
  350. typedef struct {
  351. DWORD dw1;
  352. DWORD dw2;
  353. } HELPMAP;
  354. BOOL OnContextHelp(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam,
  355. HELPMAP const * rgCtxMap);
  356. //--------------------------------------------------------------------------
  357. //
  358. // IsValidURL
  359. //
  360. //--------------------------------------------------------------------------
  361. BOOL IsValidURL (LPWSTR pwszURL);
  362. //--------------------------------------------------------------------------
  363. //
  364. // FormatMessageUnicodeIds
  365. //
  366. //--------------------------------------------------------------------------
  367. LPWSTR FormatMessageUnicodeIds (UINT ids, ...);
  368. //--------------------------------------------------------------------------
  369. //
  370. // FormatMessageUnicodeString
  371. //
  372. //--------------------------------------------------------------------------
  373. LPWSTR FormatMessageUnicodeString (LPWSTR pwszFormat, ...);
  374. //--------------------------------------------------------------------------
  375. //
  376. // FormatMessageUnicode
  377. //
  378. //--------------------------------------------------------------------------
  379. LPWSTR FormatMessageUnicode (LPWSTR pwszFormat, va_list * pArgList);
  380. #endif //_INTERNAL_H