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.

118 lines
2.9 KiB

  1. //+-------------------------------------------------------------------------
  2. // Microsoft Windows
  3. //
  4. // Copyright (C) Microsoft Corporation, 1995 - 1996
  5. //
  6. // File: tpvksave.cpp
  7. //
  8. // Contents: Private Key Delete Test
  9. //
  10. // See Usage() for list of delete options.
  11. //
  12. // Functions: main
  13. //
  14. // History: 11-May-96 philh created
  15. // 07-Jun-96 HelleS Added printing the command line
  16. // and Failed or Passed at the end.
  17. //--------------------------------------------------------------------------
  18. #include <windows.h>
  19. #include <assert.h>
  20. #include "wincrypt.h"
  21. #include "certtest.h"
  22. #include <stdlib.h>
  23. #include <stdio.h>
  24. #include <string.h>
  25. #include <memory.h>
  26. #include <time.h>
  27. static void Usage(void)
  28. {
  29. int i;
  30. printf("Usage: tpvkdel [options]\n");
  31. printf("Options are:\n");
  32. printf(" -p<number> - Crypto provider type number\n");
  33. printf(" -c<name> - Crypto key container name\n");
  34. printf(" -d - Delete from provider\n");
  35. printf(" -h - This message\n");
  36. printf("\n");
  37. }
  38. int _cdecl main(int argc, char * argv[])
  39. {
  40. int ReturnStatus;
  41. HCRYPTPROV hProv = 0;
  42. DWORD dwProvType = PROV_RSA_FULL;
  43. LPSTR pszContainer = NULL;
  44. BOOL fDelete = FALSE;
  45. while (--argc>0)
  46. {
  47. if (**++argv == '-')
  48. {
  49. switch(argv[0][1])
  50. {
  51. case 'p':
  52. dwProvType = strtoul( argv[0]+2, NULL, 10);
  53. break;
  54. case 'c':
  55. pszContainer = argv[0]+2;
  56. if (*pszContainer == '\0') {
  57. printf("Need to specify crypto key container name\n");
  58. goto BadUsage;
  59. }
  60. break;
  61. case 'd':
  62. fDelete = TRUE;
  63. break;
  64. case 'h':
  65. default:
  66. goto BadUsage;
  67. }
  68. } else {
  69. printf("Too many arguments\n");
  70. goto BadUsage;
  71. }
  72. }
  73. if (!fDelete)
  74. goto BadUsage;
  75. printf("command line: %s\n", GetCommandLine());
  76. printf("Deleting existing private keys\n");
  77. // Note: for CRYPT_DELETEKEYSET, the returned hProv is undefined
  78. // and must not be released.
  79. if (!CryptAcquireContext(
  80. &hProv,
  81. pszContainer,
  82. NULL, // pszProvider
  83. dwProvType,
  84. CRYPT_DELETEKEYSET
  85. ))
  86. {
  87. PrintLastError("CryptAcquireContext(CRYPT_DELETEKEYSET)");
  88. ReturnStatus = -1;
  89. }
  90. else
  91. ReturnStatus = 0;
  92. goto CommonReturn;
  93. BadUsage:
  94. Usage();
  95. ReturnStatus = -1;
  96. CommonReturn:
  97. if (!ReturnStatus)
  98. printf("Passed\n");
  99. else
  100. printf("Failed\n");
  101. return ReturnStatus;
  102. }