Source code of Windows XP (NT5)
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.

203 lines
3.9 KiB

  1. /*++
  2. Copyright (C) 1996, 1997 Microsoft Corporation
  3. Module Name:
  4. nt5wrap.cpp
  5. Abstract:
  6. Client side CryptXXXData calls.
  7. Client funcs are preceeded by "CS" == Client Side
  8. Server functions are preceeded by "SS" == Server Side
  9. Author:
  10. Scott Field (sfield) 14-Aug-97
  11. Revisions:
  12. Todds 04-Sep-97 Ported to .dll
  13. Matt Thomlinson (mattt) 09-Oct-97 Moved to common area for link by crypt32
  14. philh 03-Dec-97 Added I_CertProtectFunction
  15. philh 29-Sep-98 Renamed I_CertProtectFunction to
  16. I_CertCltProtectFunction.
  17. I_CertProtectFunction was moved to
  18. ..\ispu\pki\certstor\protroot.cpp
  19. petesk 25-Jan-00 Moved to keysvc
  20. --*/
  21. #include <windows.h>
  22. #include <wincrypt.h>
  23. #include <cryptui.h>
  24. #include "unicode.h"
  25. #include "waitsvc.h"
  26. #include "certprot.h"
  27. // midl generated files
  28. #include "keyrpc.h"
  29. #include "lenroll.h"
  30. #include "keysvc.h"
  31. #include "keysvcc.h"
  32. #include "cerrpc.h"
  33. // fwds
  34. RPC_STATUS CertBindA(
  35. unsigned char **pszBinding,
  36. RPC_BINDING_HANDLE *phBind
  37. );
  38. RPC_STATUS CertUnbindA(
  39. unsigned char **pszBinding,
  40. RPC_BINDING_HANDLE *phBind
  41. );
  42. BOOL
  43. WINAPI
  44. I_CertCltProtectFunction(
  45. IN DWORD dwFuncId,
  46. IN DWORD dwFlags,
  47. IN OPTIONAL LPCWSTR pwszIn,
  48. IN OPTIONAL BYTE *pbIn,
  49. IN DWORD cbIn,
  50. OUT OPTIONAL BYTE **ppbOut,
  51. OUT OPTIONAL DWORD *pcbOut
  52. )
  53. {
  54. BOOL fResult;
  55. DWORD dwRetVal;
  56. RPC_BINDING_HANDLE h = NULL;
  57. unsigned char *pszBinding;
  58. RPC_STATUS RpcStatus;
  59. HANDLE hEvent = NULL;
  60. BYTE *pbSSOut = NULL;
  61. DWORD cbSSOut = 0;
  62. BYTE rgbIn[1];
  63. if (NULL == pwszIn)
  64. pwszIn = L"";
  65. if (NULL == pbIn) {
  66. pbIn = rgbIn;
  67. cbIn = 0;
  68. }
  69. if (!FIsWinNT5()) {
  70. SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
  71. goto ErrorReturn;
  72. }
  73. RpcStatus = CertBindA(&pszBinding, &h);
  74. if (RpcStatus != RPC_S_OK) {
  75. SetLastError(RpcStatus);
  76. goto ErrorReturn;
  77. }
  78. __try {
  79. dwRetVal = SSCertProtectFunction(
  80. h,
  81. dwFuncId,
  82. dwFlags,
  83. pwszIn,
  84. pbIn,
  85. cbIn,
  86. &pbSSOut,
  87. &cbSSOut
  88. );
  89. } __except(EXCEPTION_EXECUTE_HANDLER) {
  90. dwRetVal = GetExceptionCode();
  91. }
  92. CertUnbindA(&pszBinding, &h);
  93. if (ERROR_SUCCESS != dwRetVal) {
  94. if (RPC_S_UNKNOWN_IF == dwRetVal)
  95. dwRetVal = ERROR_CALL_NOT_IMPLEMENTED;
  96. SetLastError(dwRetVal);
  97. goto ErrorReturn;
  98. }
  99. fResult = TRUE;
  100. CommonReturn:
  101. if (ppbOut)
  102. *ppbOut = pbSSOut;
  103. else if (pbSSOut)
  104. midl_user_free(pbSSOut);
  105. if (pcbOut)
  106. *pcbOut = cbSSOut;
  107. return fResult;
  108. ErrorReturn:
  109. fResult = FALSE;
  110. goto CommonReturn;
  111. }
  112. static RPC_STATUS CertBindA(unsigned char **pszBinding, RPC_BINDING_HANDLE *phBind)
  113. {
  114. RPC_STATUS status;
  115. static BOOL fDone = FALSE;
  116. //
  117. // wait for the service to be available before attempting bind
  118. //
  119. WaitForCryptService(L"CryptSvc", &fDone);
  120. status = RpcStringBindingComposeA(
  121. NULL,
  122. (unsigned char*)KEYSVC_LOCAL_PROT_SEQ,
  123. NULL,
  124. (unsigned char*)KEYSVC_LOCAL_ENDPOINT,
  125. NULL,
  126. (unsigned char * *)pszBinding
  127. );
  128. if (status)
  129. {
  130. return(status);
  131. }
  132. status = RpcBindingFromStringBindingA(*pszBinding, phBind);
  133. return status;
  134. }
  135. static RPC_STATUS CertUnbindA(unsigned char **pszBinding, RPC_BINDING_HANDLE *phBind)
  136. {
  137. RPC_STATUS status;
  138. status = RpcStringFreeA(pszBinding);
  139. if (status)
  140. {
  141. return(status);
  142. }
  143. RpcBindingFree(phBind);
  144. return RPC_S_OK;
  145. }