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.

188 lines
5.5 KiB

  1. #include <windows.h>
  2. #include <stdio.h>
  3. #include <cryptdlg.h>
  4. int IFilter = 0;
  5. BOOL FILTER(PCCERT_CONTEXT pccert, long, DWORD, DWORD)
  6. {
  7. switch (IFilter) {
  8. case 1:
  9. return TRUE;
  10. case 2:
  11. return (pccert->pCertInfo->dwVersion == 0);
  12. }
  13. return TRUE;
  14. }
  15. void PrintUsage()
  16. {
  17. printf("test options are:\n");
  18. printf(" -h print help\n");
  19. printf(" -A open AddressBook cert store\n");
  20. printf(" -C open CA cert store\n");
  21. printf(" -M open My cert store\n");
  22. printf(" -R open ROOT cert store\n");
  23. printf(" -F# filter number to apply\n");
  24. printf(" 1 - view all certs\n");
  25. printf(" 2 - view V1 certs only\n");
  26. printf(" -S<name> open <name> cert store\n");
  27. }
  28. int __cdecl main(int argc, char * argv[])
  29. {
  30. BOOL fWide = FALSE;
  31. HCERTSTORE hcertstor = NULL;
  32. int i;
  33. PCCERT_CONTEXT pccert = NULL;
  34. char * szPurposeOid = "1.3.6.1.5.5.7.3.4";
  35. for (i=1; i<argc; i++) {
  36. if ((argv[i][0] == '-') || (argv[i][0] == '/')) {
  37. switch(argv[i][1]) {
  38. case 'h':
  39. PrintUsage();
  40. exit(0);
  41. case 'A':
  42. hcertstor = CertOpenStore(sz_CERT_STORE_PROV_SYSTEM_W, X509_ASN_ENCODING,
  43. NULL, CERT_SYSTEM_STORE_CURRENT_USER,
  44. L"AddressBook");
  45. break;
  46. case 'M':
  47. hcertstor = CertOpenStore(sz_CERT_STORE_PROV_SYSTEM_W, X509_ASN_ENCODING,
  48. NULL, CERT_SYSTEM_STORE_CURRENT_USER,
  49. L"My");
  50. break;
  51. case 'R':
  52. hcertstor = CertOpenStore(sz_CERT_STORE_PROV_SYSTEM_W, X509_ASN_ENCODING,
  53. NULL, CERT_SYSTEM_STORE_CURRENT_USER,
  54. L"ROOT");
  55. break;
  56. case 'C':
  57. hcertstor = CertOpenStore(sz_CERT_STORE_PROV_SYSTEM_W, X509_ASN_ENCODING,
  58. NULL, CERT_SYSTEM_STORE_CURRENT_USER,
  59. L"CA");
  60. break;
  61. case 'F':
  62. IFilter = atoi(&argv[i][2]);
  63. break;
  64. case 'P':
  65. if (argv[i][2] != 0) {
  66. szPurposeOid = &argv[i][2];
  67. }
  68. else
  69. szPurposeOid = NULL;
  70. break;
  71. case 'W':
  72. fWide = TRUE;
  73. break;
  74. default:
  75. PrintUsage();
  76. exit(1);
  77. }
  78. }
  79. else {
  80. PrintUsage();
  81. exit(1);
  82. }
  83. }
  84. if (hcertstor == NULL) {
  85. hcertstor = CertOpenStore(sz_CERT_STORE_PROV_SYSTEM_W, X509_ASN_ENCODING,
  86. NULL, CERT_SYSTEM_STORE_CURRENT_USER,
  87. L"MY");
  88. }
  89. if (fWide) {
  90. CERT_SELECT_STRUCT_W css = {0};
  91. css.dwSize = sizeof(css);
  92. css.szPurposeOid = szPurposeOid;
  93. css.hwndParent = NULL;
  94. css.hInstance = NULL;
  95. css.pTemplateName = NULL;
  96. css.dwFlags = CSS_SHOW_HELP;
  97. css.szTitle = NULL;
  98. css.cCertStore = 1;
  99. css.arrayCertStore = &hcertstor;
  100. css.cCertContext = 0;
  101. css.arrayCertContext = &pccert;
  102. css.lCustData = 0;
  103. css.pfnHook = NULL;
  104. if (IFilter > 0) {
  105. css.pfnFilter = FILTER;
  106. }
  107. else {
  108. css.pfnFilter = NULL;
  109. }
  110. css.szHelpFileName = L"Help File";
  111. css.dwHelpId = 100;
  112. if (CertSelectCertificateW(&css)) {
  113. CERT_VIEWPROPERTIES_STRUCT_W cvp;
  114. memset(&cvp, 0, sizeof(cvp));
  115. cvp.dwSize = sizeof(cvp);
  116. cvp.pCertContext = pccert;
  117. cvp.dwFlags |= CM_SHOW_HELP;
  118. cvp.cArrayPurposes = 1;
  119. cvp.arrayPurposes = (LPSTR *) &css.szPurposeOid;
  120. cvp.szHelpFileName = L"Help File";
  121. cvp.dwHelpId = 100;
  122. CertViewPropertiesW(&cvp);
  123. }
  124. }
  125. else {
  126. CERT_SELECT_STRUCT_A css = {0};
  127. css.dwSize = sizeof(css);
  128. css.szPurposeOid = szPurposeOid;
  129. css.hwndParent = NULL;
  130. css.hInstance = NULL;
  131. css.pTemplateName = NULL;
  132. css.dwFlags = CSS_SHOW_HELP;
  133. css.szTitle = NULL;
  134. css.cCertStore = 1;
  135. css.arrayCertStore = &hcertstor;
  136. css.cCertContext = 0;
  137. css.arrayCertContext = &pccert;
  138. css.lCustData = 0;
  139. css.pfnHook = NULL;
  140. if (IFilter > 0) {
  141. css.pfnFilter = FILTER;
  142. }
  143. else {
  144. css.pfnFilter = NULL;
  145. }
  146. css.szHelpFileName = "Help File";
  147. css.dwHelpId = 100;
  148. if (CertSelectCertificateA(&css)) {
  149. CERT_VIEWPROPERTIES_STRUCT_A cvp;
  150. memset(&cvp, 0, sizeof(cvp));
  151. cvp.dwSize = sizeof(cvp);
  152. cvp.pCertContext = pccert;
  153. cvp.dwFlags |= CM_SHOW_HELP;
  154. cvp.cArrayPurposes = 1;
  155. cvp.arrayPurposes = (LPSTR *) &css.szPurposeOid;
  156. cvp.szHelpFileName = "Help File";
  157. cvp.dwHelpId = 100;
  158. CertViewPropertiesA(&cvp);
  159. }
  160. }
  161. return 0;
  162. }