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.

156 lines
4.2 KiB

  1. //+-------------------------------------------------------------------------
  2. // Microsoft Windows
  3. //
  4. // Copyright (C) Microsoft Corporation, 1999 - 1999
  5. //
  6. // File: trootlist.cpp
  7. //
  8. // Contents: Test for the Signed List of Trusted Roots APIs
  9. //
  10. // See Usage() for a list of test options.
  11. //
  12. //
  13. // Functions: main
  14. //
  15. // History: 01-Aug-99 philh created
  16. //--------------------------------------------------------------------------
  17. #include <windows.h>
  18. #include <assert.h>
  19. #include "wincrypt.h"
  20. #include "certtest.h"
  21. #include <stdlib.h>
  22. #include <stdio.h>
  23. #include <string.h>
  24. #include <memory.h>
  25. #include <time.h>
  26. static void Usage(void)
  27. {
  28. printf("Usage: trootlist [options] <FileOrUrl>\n");
  29. printf("Options are:\n");
  30. printf(" -h - This message\n");
  31. printf(" -b - Brief\n");
  32. printf(" -v - Verbose\n");
  33. printf(" -U - URL (file default)\n");
  34. printf(" -C - Intermediate CAs\n");
  35. printf("\n");
  36. }
  37. int _cdecl main(int argc, char * argv[])
  38. {
  39. BOOL fResult;
  40. int status;
  41. LPCSTR pszFileOrUrl = NULL; // Not allocated
  42. LPWSTR pwszUrl = NULL; // TestAlloc()'ed
  43. BYTE *pbEncoded = NULL; // TestAlloc()'ed
  44. DWORD cbEncoded;
  45. DWORD dwDisplayFlags = 0;
  46. BOOL fUrl = FALSE;
  47. BOOL fCAs = FALSE;
  48. CRYPT_DATA_BLOB EncodedBlob;
  49. void *pvList;
  50. while (--argc>0)
  51. {
  52. if (**++argv == '-')
  53. {
  54. switch(argv[0][1])
  55. {
  56. case 'U':
  57. fUrl = TRUE;
  58. break;
  59. case 'C':
  60. fCAs = TRUE;
  61. break;
  62. case 'b':
  63. dwDisplayFlags |= DISPLAY_BRIEF_FLAG;
  64. break;
  65. case 'v':
  66. dwDisplayFlags |= DISPLAY_VERBOSE_FLAG;
  67. break;
  68. case 'h':
  69. default:
  70. goto BadUsage;
  71. }
  72. } else {
  73. if (pszFileOrUrl == NULL)
  74. pszFileOrUrl = argv[0];
  75. else {
  76. printf("Too many arguments\n");
  77. goto BadUsage;
  78. }
  79. }
  80. }
  81. if (pszFileOrUrl == NULL) {
  82. printf("missing FileOrUrl \n");
  83. goto BadUsage;
  84. }
  85. printf("command line: %s\n", GetCommandLine());
  86. if (fUrl) {
  87. pwszUrl = AllocAndSzToWsz(pszFileOrUrl);
  88. pvList = (void *) pwszUrl;
  89. } else {
  90. if (!ReadDERFromFile(pszFileOrUrl, &pbEncoded, &cbEncoded))
  91. goto ErrorReturn;
  92. EncodedBlob.pbData = pbEncoded;
  93. EncodedBlob.cbData = cbEncoded;
  94. pvList = (void *) &EncodedBlob;
  95. }
  96. if (fCAs) {
  97. fResult = CertInstallIntermediateCAs(
  98. X509_ASN_ENCODING | PKCS_7_ASN_ENCODING,
  99. fUrl ? CERT_INSTALL_CA_FORMAT_URL : CERT_INSTALL_CA_FORMAT_BLOB,
  100. pvList,
  101. 0, // dwFlags
  102. NULL // pvReserved
  103. );
  104. if (!fResult)
  105. PrintLastError("CertInstallIntermediateCAs");
  106. else
  107. printf("Successful CertInstallIntermediateCAs\n");
  108. } else {
  109. fResult = CertInstallSignedListOfTrustedCertificates(
  110. X509_ASN_ENCODING | PKCS_7_ASN_ENCODING,
  111. CERT_INSTALL_SIGNED_LIST_PURPOSE_TRUSTED_ROOTS,
  112. fUrl ? CERT_INSTALL_SIGNED_LIST_FORMAT_URL :
  113. CERT_INSTALL_SIGNED_LIST_FORMAT_BLOB,
  114. pvList,
  115. 0, // dwFlags
  116. NULL // pvReserved
  117. );
  118. if (!fResult)
  119. PrintLastError("CertInstallSignedListOfTrustedCertificates");
  120. else
  121. printf("Successful CertInstallSignedListOfTrustedCertificates\n");
  122. }
  123. printf("Passed\n");
  124. status = 0;
  125. CommonReturn:
  126. if (pbEncoded)
  127. TestFree(pbEncoded);
  128. if (pwszUrl)
  129. TestFree(pwszUrl);
  130. return status;
  131. ErrorReturn:
  132. status = -1;
  133. printf("Failed\n");
  134. goto CommonReturn;
  135. BadUsage:
  136. Usage();
  137. goto ErrorReturn;
  138. }