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.

102 lines
2.3 KiB

  1. #undef UNICODE // ## Not Yet
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <ctype.h>
  5. #include <windows.h>
  6. #include <wincrypt.h>
  7. CHAR pszMyName[64];
  8. HCRYPTKEY hClientKey;
  9. HCRYPTPROV hMe;
  10. HCRYPTKEY hKey2;
  11. BOOL Logon(int cArg);
  12. int __cdecl main(int cArg, char *rgszArg[])
  13. {
  14. // Logon to provider
  15. if (!Logon(cArg))
  16. goto exit;
  17. exit:
  18. return(0);
  19. }
  20. BOOL Logon(int cArg)
  21. {
  22. HCRYPTKEY hTestKey;
  23. pszMyName[0] = 0;
  24. if (RCRYPT_FAILED(CryptAcquireContext(&hMe, pszMyName, MS_DEF_PROV,
  25. PROV_RSA_FULL, 0)))
  26. {
  27. if (cArg > 1)
  28. printf("\nUser doesn't exists, try to create it ");
  29. if (RCRYPT_FAILED(CryptAcquireContext(&hMe, pszMyName,
  30. MS_DEF_PROV, PROV_RSA_FULL, CRYPT_NEWKEYSET)))
  31. {
  32. if (cArg > 1)
  33. printf("FAIL Error = %x\n", GetLastError());
  34. return(FALSE);
  35. }
  36. else
  37. {
  38. if (cArg > 1)
  39. printf("SUCCEED\n");
  40. }
  41. }
  42. else
  43. {
  44. if (cArg > 1)
  45. printf("CryptAcquireContext for user: %s\n", pszMyName);
  46. }
  47. if (RCRYPT_FAILED(CryptGetUserKey(hMe, AT_SIGNATURE, &hTestKey)))
  48. {
  49. if (cArg > 1)
  50. printf("Create signature key for %s: ", pszMyName);
  51. if (RCRYPT_FAILED(CryptGenKey(hMe, CALG_RSA_SIGN,
  52. CRYPT_EXPORTABLE, &hClientKey)))
  53. {
  54. if (cArg > 1)
  55. printf("FAIL Error = %x\n", GetLastError());
  56. return(FALSE);
  57. }
  58. if (cArg > 1)
  59. printf("SUCCEED\n");
  60. }
  61. else
  62. CryptDestroyKey(hTestKey);
  63. if (RCRYPT_FAILED(CryptGetUserKey(hMe, AT_KEYEXCHANGE, &hTestKey)))
  64. {
  65. if (cArg > 1 )
  66. printf("Create key exchange for %s: ", pszMyName);
  67. if (RCRYPT_FAILED(CryptGenKey(hMe, CALG_RSA_KEYX,
  68. CRYPT_EXPORTABLE, &hKey2)))
  69. {
  70. if (cArg > 1)
  71. printf("FAIL Error = %x\n", GetLastError());
  72. return(FALSE);
  73. }
  74. if (cArg > 1)
  75. printf("SUCCEED\n");
  76. }
  77. else
  78. CryptDestroyKey(hTestKey);
  79. if (cArg > 1)
  80. printf("Init completed\n");
  81. return(TRUE);
  82. }