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.

258 lines
8.7 KiB

  1. #include "item.h"
  2. #ifndef CERT_NAME_STR_ENABLE_UTF8_UNICODE_FLAG
  3. #define CERT_NAME_STR_ENABLE_UTF8_UNICODE_FLAG 0
  4. #endif
  5. BOOL FormatNames(DWORD cNames, PCERT_NAME_BLOB rgNames, HWND hwnd, DWORD idc)
  6. {
  7. DWORD cb;
  8. BOOL f;
  9. DWORD i;
  10. DWORD i1;
  11. DWORD i2;
  12. PCERT_ALT_NAME_INFO pname = NULL;
  13. WCHAR rgwch[4096];
  14. rgwch[0] = 0;
  15. for (i1=0; i1<cNames; i1++) {
  16. f = CryptDecodeObjectEx(X509_ASN_ENCODING, X509_ALTERNATE_NAME,
  17. rgNames[i1].pbData, rgNames[i1].cbData,
  18. CRYPT_ENCODE_ALLOC_FLAG, NULL, &pname, &cb);
  19. if (!f) break;
  20. for (i2=0; i2<pname->cAltEntry; i2++) {
  21. if (i2 > 0) {
  22. wcscat(rgwch, L" ");
  23. }
  24. switch( pname->rgAltEntry[i2].dwAltNameChoice ) {
  25. case CERT_ALT_NAME_RFC822_NAME:
  26. wcscat(rgwch, L"SMTP: ");
  27. wcscat(rgwch, pname->rgAltEntry[i2].pwszRfc822Name);
  28. wcscat(rgwch, L"\r\n");
  29. break;
  30. case CERT_ALT_NAME_DIRECTORY_NAME:
  31. break;
  32. }
  33. }
  34. free(pname);
  35. pname = NULL;
  36. }
  37. if (f) SetDlgItemTextW(hwnd, idc, rgwch);
  38. return f;
  39. }
  40. BOOL ParseNames(DWORD * pcNames, PCERT_NAME_BLOB * prgNames, HWND hwnd, DWORD idc)
  41. {
  42. DWORD cb;
  43. DWORD cEntry = 0;
  44. DWORD cNames = 0;
  45. BOOL f;
  46. DWORD i;
  47. LPWSTR pwsz;
  48. LPWSTR pwsz1;
  49. CRYPT_DER_BLOB rgDer[50] = {0};
  50. CERT_ALT_NAME_INFO rgNames[50] = {0};
  51. CERT_ALT_NAME_ENTRY rgEntry[200] = {0};
  52. WCHAR rgwch[4096];
  53. GetDlgItemTextW(hwnd, idc, rgwch, sizeof(rgwch)/sizeof(WCHAR));
  54. rgwch[4095] = 0;
  55. pwsz = rgwch;
  56. while (*pwsz != 0) {
  57. if (cEntry == 200) {
  58. MessageBox(hwnd, "Can't have more than 200 entries", "smimetst", MB_OK);
  59. return FALSE;
  60. }
  61. if (*pwsz == ' ') {
  62. while (*pwsz == ' ') pwsz++;
  63. rgNames[cNames-1].cAltEntry += 1;
  64. }
  65. else {
  66. if (cNames == 50) {
  67. MessageBox(hwnd, "Can't have more than 50 names", "smimetst", MB_OK);
  68. return FALSE;
  69. }
  70. cNames += 1;
  71. rgNames[cNames-1].rgAltEntry = &rgEntry[cEntry];
  72. rgNames[cNames-1].cAltEntry = 1;
  73. }
  74. if (_wcsnicmp(pwsz, L"SMTP:", 5) == 0) {
  75. pwsz += 5;
  76. while (*pwsz == ' ') pwsz++;
  77. rgEntry[cEntry].dwAltNameChoice = CERT_ALT_NAME_RFC822_NAME;
  78. rgEntry[cEntry].pwszRfc822Name = pwsz;
  79. while ((*pwsz != 0) && (*pwsz != '\n') && (*pwsz != '\r')) pwsz++;
  80. }
  81. else if (_wcsnicmp(pwsz, L"X500:", 5) == 0) {
  82. pwsz += 5;
  83. while (*pwsz == ' ') pwsz++;
  84. for (pwsz1 = pwsz; ((*pwsz != 0) && (*pwsz != '\n') &&
  85. (*pwsz != '\r')); pwsz++);
  86. if (*pwsz != 0) {
  87. *pwsz = 0;
  88. pwsz++;
  89. }
  90. rgEntry[cEntry].dwAltNameChoice = CERT_ALT_NAME_DIRECTORY_NAME;
  91. f = CertStrToNameW(X509_ASN_ENCODING, pwsz1,
  92. CERT_NAME_STR_ENABLE_UTF8_UNICODE_FLAG, NULL,
  93. NULL, &cb, NULL);
  94. if (!f) {
  95. MessageBox(hwnd, "X500 name does not parse", "smimetst", MB_OK);
  96. return FALSE;
  97. }
  98. rgEntry[cEntry].DirectoryName.pbData = (LPBYTE) malloc(cb);
  99. f = CertStrToNameW(X509_ASN_ENCODING, pwsz1,
  100. CERT_NAME_STR_ENABLE_UTF8_UNICODE_FLAG, NULL,
  101. rgEntry[cEntry].DirectoryName.pbData, &cb,
  102. NULL);
  103. if (!f) return FALSE;
  104. rgEntry[cEntry].DirectoryName.cbData = cb;
  105. }
  106. else {
  107. MessageBox(hwnd, "unknown address type", "smimetst", MB_OK);
  108. return FALSE;
  109. }
  110. if (*pwsz == '\r') {
  111. *pwsz = 0;
  112. pwsz++;
  113. }
  114. if (*pwsz == '\n') {
  115. *pwsz = 0;
  116. pwsz++;
  117. }
  118. cEntry += 1;
  119. }
  120. *prgNames = (PCERT_NAME_BLOB) malloc(sizeof(CERT_NAME_BLOB) * cNames);
  121. if (*prgNames == NULL) return FALSE;
  122. for (i=0; i<cNames; i++) {
  123. f = CryptEncodeObjectEx(X509_ASN_ENCODING, X509_ALTERNATE_NAME,
  124. &rgNames[i], CRYPT_ENCODE_ALLOC_FLAG, NULL,
  125. &(*prgNames)[i].pbData, &(*prgNames)[i].cbData);
  126. if (!f) return f;
  127. }
  128. *pcNames = cNames;
  129. return f;
  130. }
  131. BOOL ReceiptCreateDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  132. {
  133. DWORD cb;
  134. DWORD cbNames;
  135. BOOL f;
  136. LPBYTE pb;
  137. PSMIME_RECEIPT_REQUEST pReceipt;
  138. static CSignData * psd = NULL;
  139. CHAR rgchContent[256];
  140. SMIME_RECEIPT_REQUEST receipt;
  141. switch (message) {
  142. case WM_INITDIALOG:
  143. pReceipt = NULL;
  144. psd = (CSignData *) lParam;
  145. psd->GetReceiptData(&pb, &cbNames);
  146. f = CryptDecodeObjectEx(X509_ASN_ENCODING, szOID_SMIME_Receipt_Request,
  147. pb, cbNames, CRYPT_ENCODE_ALLOC_FLAG, NULL,
  148. &pReceipt, &cb);
  149. if (pReceipt) {
  150. // Set Content Identifier -- M00TODO
  151. SetDlgItemText(hwnd, IDC_RC_CONTENT,
  152. (LPSTR) pReceipt->ContentIdentifier.pbData);
  153. // Set Top buttons -
  154. // M00BUG
  155. if (pReceipt->ReceiptsFrom.cNames > 0) {
  156. FormatNames(pReceipt->ReceiptsFrom.cNames,
  157. pReceipt->ReceiptsFrom.rgNames, hwnd, IDC_RC_FROM_TEXT);
  158. }
  159. // Set ReceiptsTo
  160. FormatNames(pReceipt->cReceiptsTo, pReceipt->rgReceiptsTo, hwnd,
  161. IDC_RC_TO_TEXT);
  162. }
  163. else {
  164. FormatNames(CMyNames, RgMyNames, hwnd, IDC_RC_TO_TEXT);
  165. }
  166. break;
  167. case WM_COMMAND:
  168. switch(wParam) {
  169. case MAKELONG(IDC_RC_FROM_ALL, BN_CLICKED):
  170. case MAKELONG(IDC_RC_FROM_TOP, BN_CLICKED):
  171. EnableWindow(GetDlgItem(hwnd, IDC_RC_FROM_TEXT), FALSE);
  172. break;
  173. case MAKELONG(IDC_RC_FROM_SOME, BN_CLICKED):
  174. EnableWindow(GetDlgItem(hwnd, IDC_RC_FROM_TEXT), TRUE);
  175. break;
  176. case IDOK:
  177. memset(&receipt, 0, sizeof(receipt));
  178. GetDlgItemText(hwnd, IDC_RC_CONTENT,
  179. rgchContent, sizeof(rgchContent));
  180. receipt.ContentIdentifier.pbData = (LPBYTE) rgchContent;
  181. receipt.ContentIdentifier.cbData = strlen(rgchContent);
  182. if (SendMessage(GetDlgItem(hwnd, IDC_RC_FROM_ALL), BM_GETCHECK, 0, 0)) {
  183. receipt.ReceiptsFrom.AllOrFirstTier = SMIME_RECEIPTS_FROM_ALL;
  184. }
  185. else if (SendMessage(GetDlgItem(hwnd, IDC_RC_FROM_TOP), BM_GETCHECK, 0, 0)) {
  186. receipt.ReceiptsFrom.AllOrFirstTier = SMIME_RECEIPTS_FROM_FIRST_TIER;
  187. }
  188. else {
  189. receipt.ReceiptsFrom.AllOrFirstTier = 0;
  190. if (!ParseNames(&receipt.ReceiptsFrom.cNames,
  191. &receipt.ReceiptsFrom.rgNames,
  192. hwnd, IDC_RC_FROM_TEXT)) {
  193. return FALSE;
  194. }
  195. }
  196. if (!ParseNames(&receipt.cReceiptsTo, &receipt.rgReceiptsTo,
  197. hwnd, IDC_RC_TO_TEXT)) {
  198. free(receipt.ReceiptsFrom.rgNames);
  199. return FALSE;
  200. }
  201. f = CryptEncodeObjectEx(X509_ASN_ENCODING,
  202. szOID_SMIME_Receipt_Request, &receipt,
  203. CRYPT_ENCODE_ALLOC_FLAG, NULL, &pb, &cb);
  204. free(receipt.ReceiptsFrom.rgNames);
  205. free(receipt.rgReceiptsTo);
  206. if (!f) return FALSE;
  207. psd->SetReceiptData(pb, cb);
  208. //
  209. case IDCANCEL:
  210. EndDialog(hwnd, wParam);
  211. break;
  212. default:
  213. return FALSE;
  214. }
  215. break;
  216. default:
  217. return FALSE;
  218. }
  219. return TRUE;
  220. }