Leaked source code of windows server 2003
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.

186 lines
7.6 KiB

  1. #include "precomp.h"
  2. #include <cryptui.h>
  3. static void displaySignHelp();
  4. INT_PTR CALLBACK CabSignProc( HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam )
  5. {
  6. TCHAR szDesc[MAX_PATH];
  7. TCHAR szPVKPath[MAX_PATH];
  8. TCHAR szSPCPath[MAX_PATH];
  9. TCHAR szInfoUrl[INTERNET_MAX_URL_LENGTH];
  10. LPCTSTR pcszInsFile;
  11. switch( msg )
  12. {
  13. case WM_SETFONT:
  14. //a change to mmc requires us to do this logic for all our property pages that use common controls
  15. INITCOMMONCONTROLSEX iccx;
  16. iccx.dwSize = sizeof(INITCOMMONCONTROLSEX);
  17. iccx.dwICC = ICC_ANIMATE_CLASS | ICC_BAR_CLASSES | ICC_LISTVIEW_CLASSES |ICC_TREEVIEW_CLASSES;
  18. InitCommonControlsEx(&iccx);
  19. break;
  20. case WM_INITDIALOG:
  21. //hide csadd per bug 27041
  22. ShowWindow(GetDlgItem(hDlg, IDC_CSADD), SW_HIDE);
  23. pcszInsFile = (LPCTSTR)((LPPROPSHEETPAGE)lParam)->lParam;
  24. SetWindowLongPtr(hDlg, DWLP_USER, (LONG_PTR) pcszInsFile);
  25. EnableDBCSChars(hDlg, IDE_CSPVK);
  26. EnableDBCSChars(hDlg, IDE_CSSPC);
  27. EnableDBCSChars(hDlg, IDE_CSURL);
  28. EnableDBCSChars(hDlg, IDE_CSDESC);
  29. GetPrivateProfileString(IS_CABSIGN, IK_PVK, TEXT(""), szPVKPath, ARRAYSIZE(szPVKPath), pcszInsFile);
  30. GetPrivateProfileString(IS_CABSIGN, IK_SPC, TEXT(""), szSPCPath, ARRAYSIZE(szSPCPath), pcszInsFile);
  31. GetPrivateProfileString(IS_CABSIGN, IK_CSURL, TEXT(""), szInfoUrl, ARRAYSIZE(szInfoUrl), pcszInsFile);
  32. GetPrivateProfileString(IS_CABSIGN, IK_NAME, TEXT(""), szDesc, ARRAYSIZE(szDesc), pcszInsFile);
  33. SetDlgItemText(hDlg, IDE_CSPVK, szPVKPath);
  34. SetDlgItemText(hDlg, IDE_CSSPC, szSPCPath);
  35. SetDlgItemText(hDlg, IDE_CSURL, szInfoUrl);
  36. SetDlgItemText(hDlg, IDE_CSDESC, szDesc);
  37. EnableWindow(GetDlgItem(hDlg, IDC_CSCOMP), FALSE);
  38. EnableWindow(GetDlgItem(hDlg, IDC_CSCOMP_TXT), FALSE);
  39. break;
  40. case WM_COMMAND:
  41. if (BN_CLICKED != GET_WM_COMMAND_CMD(wParam, lParam))
  42. return FALSE;
  43. switch (GET_WM_COMMAND_ID(wParam, lParam))
  44. {
  45. case IDC_BROWSECSPVK:
  46. GetDlgItemText( hDlg, IDE_CSPVK, szPVKPath, ARRAYSIZE(szPVKPath));
  47. if( BrowseForFile( hDlg, szPVKPath, ARRAYSIZE(szPVKPath), GFN_PVK ))
  48. SetDlgItemText( hDlg, IDE_CSPVK, szPVKPath );
  49. break;
  50. case IDC_BROWSECSSPC:
  51. GetDlgItemText( hDlg, IDE_CSSPC, szSPCPath, ARRAYSIZE(szSPCPath));
  52. if( BrowseForFile( hDlg, szSPCPath, ARRAYSIZE(szSPCPath), GFN_SPC ))
  53. SetDlgItemText( hDlg, IDE_CSSPC, szSPCPath );
  54. break;
  55. default:
  56. return FALSE;
  57. }
  58. break;
  59. case WM_HELP:
  60. displaySignHelp();
  61. break;
  62. case WM_NOTIFY:
  63. switch (((LPNMHDR)lParam)->code)
  64. {
  65. case PSN_HELP:
  66. displaySignHelp();
  67. break;
  68. case PSN_APPLY:
  69. pcszInsFile = (LPCTSTR)GetWindowLongPtr(hDlg, DWLP_USER);
  70. GetDlgItemText(hDlg, IDE_CSPVK, szPVKPath, ARRAYSIZE(szPVKPath));
  71. GetDlgItemText(hDlg, IDE_CSSPC, szSPCPath, ARRAYSIZE(szSPCPath));
  72. GetDlgItemText(hDlg, IDE_CSURL, szInfoUrl, ARRAYSIZE(szInfoUrl));
  73. GetDlgItemText(hDlg, IDE_CSDESC, szDesc, ARRAYSIZE(szDesc));
  74. if (ISNONNULL(szPVKPath) || ISNONNULL(szSPCPath)
  75. || ISNONNULL(szInfoUrl) || ISNONNULL(szDesc))
  76. {
  77. if (!CheckField(hDlg, IDE_CSSPC, FC_NONNULL | FC_FILE | FC_EXISTS) ||
  78. !CheckField(hDlg, IDE_CSPVK, FC_NONNULL | FC_FILE | FC_EXISTS) ||
  79. !CheckField(hDlg, IDE_CSDESC, FC_NONNULL) || !CheckField(hDlg, IDE_CSURL, FC_URL))
  80. {
  81. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE);
  82. break;
  83. }
  84. }
  85. WritePrivateProfileString(IS_CABSIGN, IK_PVK, szPVKPath, pcszInsFile);
  86. WritePrivateProfileString(IS_CABSIGN, IK_SPC, szSPCPath, pcszInsFile);
  87. WritePrivateProfileString(IS_CABSIGN, IK_CSURL, szInfoUrl, pcszInsFile);
  88. WritePrivateProfileString(IS_CABSIGN, IK_NAME, szDesc, pcszInsFile);
  89. break;
  90. default:
  91. return FALSE;
  92. }
  93. break;
  94. default:
  95. return FALSE;
  96. }
  97. return TRUE;
  98. }
  99. static void displaySignHelp()
  100. {
  101. WCHAR wszHelpTopic[MAX_PATH];
  102. StrCpy(wszHelpTopic, HELP_FILENAME TEXT("::/"));
  103. StrCat(wszHelpTopic, TEXT("wiz3_9.htm"));
  104. MMCPropertyHelp((LPOLESTR)wszHelpTopic);
  105. }
  106. void SignCabFile(LPCTSTR pcszFilename, LPCTSTR pcszIns, LPTSTR pszUnsignedFiles)
  107. {
  108. TCHAR szPVKPath[MAX_PATH];
  109. TCHAR szSPCPath[MAX_PATH];
  110. TCHAR szDesc[MAX_PATH];
  111. TCHAR szInfoUrl[INTERNET_MAX_URL_LENGTH];
  112. CRYPTUI_WIZ_DIGITAL_SIGN_INFO signInfo;
  113. CRYPTUI_WIZ_DIGITAL_SIGN_CERT_PVK_INFO signCertPvkInfo;
  114. CRYPTUI_WIZ_DIGITAL_SIGN_PVK_FILE_INFO signPvkFileInfo;
  115. CRYPTUI_WIZ_DIGITAL_SIGN_EXTENDED_INFO signExtInfo;
  116. USES_CONVERSION;
  117. if (GetPrivateProfileString(IS_CABSIGN, IK_PVK, TEXT(""), szPVKPath, ARRAYSIZE(szPVKPath), pcszIns) == 0||
  118. GetPrivateProfileString(IS_CABSIGN, IK_SPC, TEXT(""), szSPCPath, ARRAYSIZE(szSPCPath), pcszIns) == 0)
  119. return;
  120. GetPrivateProfileString(IS_CABSIGN, IK_NAME, TEXT(""), szDesc, ARRAYSIZE(szDesc), pcszIns);
  121. GetPrivateProfileString(IS_CABSIGN, IK_CSURL, TEXT(""), szInfoUrl, ARRAYSIZE(szInfoUrl), pcszIns);
  122. ZeroMemory(&signInfo, sizeof(CRYPTUI_WIZ_DIGITAL_SIGN_INFO));
  123. ZeroMemory(&signCertPvkInfo, sizeof(CRYPTUI_WIZ_DIGITAL_SIGN_CERT_PVK_INFO));
  124. ZeroMemory(&signPvkFileInfo, sizeof(CRYPTUI_WIZ_DIGITAL_SIGN_PVK_FILE_INFO));
  125. ZeroMemory(&signExtInfo, sizeof(CRYPTUI_WIZ_DIGITAL_SIGN_EXTENDED_INFO));
  126. signPvkFileInfo.dwSize = sizeof(CRYPTUI_WIZ_DIGITAL_SIGN_PVK_FILE_INFO);
  127. signPvkFileInfo.pwszPvkFileName = T2W(szPVKPath);
  128. signPvkFileInfo.pwszProvName = NULL;
  129. signPvkFileInfo.dwProvType = PROV_RSA_FULL;
  130. signCertPvkInfo.dwSize = sizeof(CRYPTUI_WIZ_DIGITAL_SIGN_CERT_PVK_INFO);
  131. signCertPvkInfo.pwszSigningCertFileName = T2W(szSPCPath);
  132. signCertPvkInfo.dwPvkChoice = CRYPTUI_WIZ_DIGITAL_SIGN_PVK_FILE;
  133. signCertPvkInfo.pPvkFileInfo = &signPvkFileInfo;
  134. signExtInfo.dwSize = sizeof(CRYPTUI_WIZ_DIGITAL_SIGN_EXTENDED_INFO);
  135. signExtInfo.dwAttrFlags = 0;
  136. signExtInfo.pwszDescription = T2CW(szDesc);
  137. signExtInfo.pwszMoreInfoLocation = T2CW(szInfoUrl);
  138. signExtInfo.pszHashAlg = szOID_RSA_MD5;
  139. signInfo.dwSize = sizeof(CRYPTUI_WIZ_DIGITAL_SIGN_INFO);
  140. signInfo.dwSubjectChoice = CRYPTUI_WIZ_DIGITAL_SIGN_SUBJECT_FILE;
  141. signInfo.pwszFileName = T2CW((LPTSTR)pcszFilename);
  142. signInfo.dwSigningCertChoice = CRYPTUI_WIZ_DIGITAL_SIGN_PVK;
  143. signInfo.pSigningCertPvkInfo = &signCertPvkInfo;
  144. signInfo.dwAdditionalCertChoice = CRYPTUI_WIZ_DIGITAL_SIGN_ADD_CHAIN_NO_ROOT;
  145. signInfo.pSignExtInfo = &signExtInfo;
  146. if (!CryptUIWizDigitalSign(CRYPTUI_WIZ_NO_UI, NULL, NULL, &signInfo, NULL))
  147. {
  148. if (pszUnsignedFiles != NULL)
  149. {
  150. StrCat(pszUnsignedFiles, TEXT("\r\n"));
  151. StrCat(pszUnsignedFiles, pcszFilename);
  152. }
  153. }
  154. }