20#include <winpr/config.h>
23#include <winpr/sspi.h>
30#define TAG WINPR_TAG("sspi.CredSSP")
32static const char* CREDSSP_PACKAGE_NAME =
"CredSSP";
34static SECURITY_STATUS SEC_ENTRY credssp_InitializeSecurityContextW(
36 WINPR_ATTR_UNUSED SEC_WCHAR* pszTargetName, WINPR_ATTR_UNUSED ULONG fContextReq,
37 WINPR_ATTR_UNUSED ULONG Reserved1, WINPR_ATTR_UNUSED ULONG TargetDataRep,
38 WINPR_ATTR_UNUSED
PSecBufferDesc pInput, WINPR_ATTR_UNUSED ULONG Reserved2,
40 WINPR_ATTR_UNUSED PULONG pfContextAttr, WINPR_ATTR_UNUSED
PTimeStamp ptsExpiry)
42 WLog_ERR(TAG,
"TODO: Implement");
43 return SEC_E_UNSUPPORTED_FUNCTION;
46static SECURITY_STATUS SEC_ENTRY credssp_InitializeSecurityContextA(
48 WINPR_ATTR_UNUSED ULONG fContextReq, WINPR_ATTR_UNUSED ULONG Reserved1,
49 WINPR_ATTR_UNUSED ULONG TargetDataRep, WINPR_ATTR_UNUSED
PSecBufferDesc pInput,
50 WINPR_ATTR_UNUSED ULONG Reserved2,
PCtxtHandle phNewContext,
51 WINPR_ATTR_UNUSED
PSecBufferDesc pOutput, WINPR_ATTR_UNUSED PULONG pfContextAttr,
58 if (phContext && !phContext->dwLower && !phContext->dwUpper)
59 return SEC_E_INVALID_HANDLE;
61 context = (
CREDSSP_CONTEXT*)sspi_SecureHandleGetLowerPointer(phContext);
70 context = credssp_ContextNew();
73 return SEC_E_INSUFFICIENT_MEMORY;
75 credentials = (
SSPI_CREDENTIALS*)sspi_SecureHandleGetLowerPointer(phCredential);
79 credssp_ContextFree(context);
80 return SEC_E_INVALID_HANDLE;
83 sspi_SecureHandleSetLowerPointer(phNewContext, context);
85 cnv.cpv = CREDSSP_PACKAGE_NAME;
86 sspi_SecureHandleSetUpperPointer(phNewContext, cnv.pv);
108static SECURITY_STATUS SEC_ENTRY credssp_QueryContextAttributes(
PCtxtHandle phContext,
109 WINPR_ATTR_UNUSED ULONG ulAttribute,
113 return SEC_E_INVALID_HANDLE;
116 return SEC_E_INSUFFICIENT_MEMORY;
118 WLog_ERR(TAG,
"TODO: Implement");
119 return SEC_E_UNSUPPORTED_FUNCTION;
122static SECURITY_STATUS SEC_ENTRY credssp_AcquireCredentialsHandleW(
123 WINPR_ATTR_UNUSED SEC_WCHAR* pszPrincipal, WINPR_ATTR_UNUSED SEC_WCHAR* pszPackage,
124 WINPR_ATTR_UNUSED ULONG fCredentialUse, WINPR_ATTR_UNUSED
void* pvLogonID,
125 WINPR_ATTR_UNUSED
void* pAuthData, WINPR_ATTR_UNUSED SEC_GET_KEY_FN pGetKeyFn,
126 WINPR_ATTR_UNUSED
void* pvGetKeyArgument, WINPR_ATTR_UNUSED
PCredHandle phCredential,
129 WLog_ERR(TAG,
"TODO: Implement");
130 return SEC_E_UNSUPPORTED_FUNCTION;
133static SECURITY_STATUS SEC_ENTRY credssp_AcquireCredentialsHandleA(
134 WINPR_ATTR_UNUSED SEC_CHAR* pszPrincipal, WINPR_ATTR_UNUSED SEC_CHAR* pszPackage,
135 WINPR_ATTR_UNUSED ULONG fCredentialUse, WINPR_ATTR_UNUSED
void* pvLogonID,
136 WINPR_ATTR_UNUSED
void* pAuthData, WINPR_ATTR_UNUSED SEC_GET_KEY_FN pGetKeyFn,
137 WINPR_ATTR_UNUSED
void* pvGetKeyArgument, WINPR_ATTR_UNUSED
PCredHandle phCredential,
141 SEC_WINNT_AUTH_IDENTITY* identity =
nullptr;
143 if (fCredentialUse == SECPKG_CRED_OUTBOUND)
150 credentials = sspi_CredentialsNew();
153 return SEC_E_INSUFFICIENT_MEMORY;
155 identity = (SEC_WINNT_AUTH_IDENTITY*)pAuthData;
156 CopyMemory(&(credentials->identity), identity,
sizeof(SEC_WINNT_AUTH_IDENTITY));
157 sspi_SecureHandleSetLowerPointer(phCredential, (
void*)credentials);
159 cnv.cpv = CREDSSP_PACKAGE_NAME;
160 sspi_SecureHandleSetUpperPointer(phCredential, cnv.pv);
164 WLog_ERR(TAG,
"TODO: Implement");
165 return SEC_E_UNSUPPORTED_FUNCTION;
168static SECURITY_STATUS SEC_ENTRY credssp_QueryCredentialsAttributesW(
169 WINPR_ATTR_UNUSED
PCredHandle phCredential, WINPR_ATTR_UNUSED ULONG ulAttribute,
170 WINPR_ATTR_UNUSED
void* pBuffer)
172 WLog_ERR(TAG,
"TODO: Implement");
173 return SEC_E_UNSUPPORTED_FUNCTION;
176static SECURITY_STATUS SEC_ENTRY credssp_QueryCredentialsAttributesA(
177 WINPR_ATTR_UNUSED
PCredHandle phCredential, WINPR_ATTR_UNUSED ULONG ulAttribute,
178 WINPR_ATTR_UNUSED
void* pBuffer)
180 if (ulAttribute == SECPKG_CRED_ATTR_NAMES)
186 return SEC_E_INVALID_HANDLE;
191 WLog_ERR(TAG,
"TODO: Implement");
192 return SEC_E_UNSUPPORTED_FUNCTION;
195static SECURITY_STATUS SEC_ENTRY credssp_FreeCredentialsHandle(
PCredHandle phCredential)
198 return SEC_E_INVALID_HANDLE;
202 sspi_SecureHandleInvalidate(phCredential);
204 return SEC_E_INVALID_HANDLE;
206 sspi_CredentialsFree(credentials);
210static SECURITY_STATUS SEC_ENTRY credssp_EncryptMessage(WINPR_ATTR_UNUSED
PCtxtHandle phContext,
211 WINPR_ATTR_UNUSED ULONG fQOP,
213 WINPR_ATTR_UNUSED ULONG MessageSeqNo)
215 WLog_ERR(TAG,
"TODO: Implement");
216 return SEC_E_UNSUPPORTED_FUNCTION;
219static SECURITY_STATUS SEC_ENTRY credssp_DecryptMessage(WINPR_ATTR_UNUSED
PCtxtHandle phContext,
221 WINPR_ATTR_UNUSED ULONG MessageSeqNo,
222 WINPR_ATTR_UNUSED ULONG* pfQOP)
224 WLog_ERR(TAG,
"TODO: Implement");
225 return SEC_E_UNSUPPORTED_FUNCTION;
228static SECURITY_STATUS SEC_ENTRY credssp_MakeSignature(WINPR_ATTR_UNUSED
PCtxtHandle phContext,
229 WINPR_ATTR_UNUSED ULONG fQOP,
231 WINPR_ATTR_UNUSED ULONG MessageSeqNo)
233 WLog_ERR(TAG,
"TODO: Implement");
234 return SEC_E_UNSUPPORTED_FUNCTION;
237static SECURITY_STATUS SEC_ENTRY credssp_VerifySignature(WINPR_ATTR_UNUSED
PCtxtHandle phContext,
239 WINPR_ATTR_UNUSED ULONG MessageSeqNo,
240 WINPR_ATTR_UNUSED ULONG* pfQOP)
242 WLog_ERR(TAG,
"TODO: Implement");
243 return SEC_E_UNSUPPORTED_FUNCTION;
249 credssp_QueryCredentialsAttributesA,
250 credssp_AcquireCredentialsHandleA,
251 credssp_FreeCredentialsHandle,
253 credssp_InitializeSecurityContextA,
258 credssp_QueryContextAttributes,
261 credssp_MakeSignature,
262 credssp_VerifySignature,
272 credssp_EncryptMessage,
273 credssp_DecryptMessage,
281 credssp_QueryCredentialsAttributesW,
282 credssp_AcquireCredentialsHandleW,
283 credssp_FreeCredentialsHandle,
285 credssp_InitializeSecurityContextW,
290 credssp_QueryContextAttributes,
293 credssp_MakeSignature,
294 credssp_VerifySignature,
304 credssp_EncryptMessage,
305 credssp_DecryptMessage,
316 "Microsoft CredSSP Security Provider"
319static WCHAR CREDSSP_SecPkgInfoW_NameBuffer[128] = WINPR_C_ARRAY_INIT;
320static WCHAR CREDSSP_SecPkgInfoW_CommentBuffer[128] = WINPR_C_ARRAY_INIT;
327 CREDSSP_SecPkgInfoW_NameBuffer,
328 CREDSSP_SecPkgInfoW_CommentBuffer
331BOOL CREDSSP_init(
void)
333 InitializeConstWCharFromUtf8(CREDSSP_SecPkgInfoA.Name, CREDSSP_SecPkgInfoW_NameBuffer,
334 ARRAYSIZE(CREDSSP_SecPkgInfoW_NameBuffer));
335 InitializeConstWCharFromUtf8(CREDSSP_SecPkgInfoA.Comment, CREDSSP_SecPkgInfoW_CommentBuffer,
336 ARRAYSIZE(CREDSSP_SecPkgInfoW_CommentBuffer));