FreeRDP
Loading...
Searching...
No Matches
TestSspiCredSSP.c
1#include <stdio.h>
2#include <string.h>
3
4#include <winpr/crt.h>
5#include <winpr/sspi.h>
6#include <winpr/credssp.h>
7
8/* Smoke-test the WinPR CredSSP package without a KDC: it registers, acquires an outbound
9 * credential (which wires up the inner Negotiate credential from the CREDSSP_CRED_EX), and
10 * frees it. The full exchange (Negotiate tokens, pubKeyAuth, delegated credentials) uses
11 * Kerberos and is validated end to end through the lsa4posix daemon against the live DC. */
12
13int TestSspiCredSSP(int argc, char* argv[])
14{
15 WINPR_UNUSED(argc);
16 WINPR_UNUSED(argv);
17
18 SecurityFunctionTableW* table = InitSecurityInterfaceExW(SSPI_INTERFACE_WINPR);
19 if (!table || !table->QuerySecurityPackageInfoW || !table->AcquireCredentialsHandleW ||
20 !table->FreeCredentialsHandle)
21 {
22 (void)fprintf(stderr, "no WinPR security function table\n");
23 return -1;
24 }
25
26 WCHAR pkg[] = { 'C', 'R', 'E', 'D', 'S', 'S', 'P', '\0' };
27
28 /* the package must resolve by name */
29 PSecPkgInfoW info = nullptr;
30 if (table->QuerySecurityPackageInfoW(pkg, &info) != SEC_E_OK)
31 {
32 (void)fprintf(stderr, "QuerySecurityPackageInfoW(CREDSSP) failed\n");
33 return -1;
34 }
35 if (table->FreeContextBuffer)
36 (void)table->FreeContextBuffer(info);
37
38 WCHAR user[] = { 't', 'e', 's', 't', 'u', 's', 'e', 'r', '\0' };
39 WCHAR domain[] = { 'T', 'E', 'S', 'T', '\0' };
40 WCHAR pass[] = { 'S', 'e', 'c', 'r', 'e', 't', '1', '!', '\0' };
41 SEC_WINNT_AUTH_IDENTITY_W identity = WINPR_C_ARRAY_INIT;
42 identity.User = (UINT16*)user;
43 identity.UserLength = 8;
44 identity.Domain = (UINT16*)domain;
45 identity.DomainLength = 4;
46 identity.Password = (UINT16*)pass;
47 identity.PasswordLength = 8;
48 identity.Flags = SEC_WINNT_AUTH_IDENTITY_UNICODE;
49
50 CREDSSP_CRED cred = { .Type = CredsspSubmitBufferBothOld };
51 cred.pSpnegoCred = &identity;
52 CREDSSP_CRED_EX credEx = { .Type = (CREDSPP_SUBMIT_TYPE)CredsspCredEx };
53 credEx.Version = CREDSSP_CRED_EX_VERSION;
54 credEx.Cred = cred;
55
56 CredHandle creds = WINPR_C_ARRAY_INIT;
57 TimeStamp expiry = WINPR_C_ARRAY_INIT;
58 const SECURITY_STATUS status = table->AcquireCredentialsHandleW(
59 nullptr, pkg, SECPKG_CRED_OUTBOUND, nullptr, &credEx, nullptr, nullptr, &creds, &expiry);
60 if (status != SEC_E_OK)
61 {
62 (void)fprintf(stderr, "AcquireCredentialsHandle(CREDSSP) failed: 0x%08" PRIx32 "\n",
63 (UINT32)status);
64 return -1;
65 }
66
67 const SECURITY_STATUS freed = table->FreeCredentialsHandle(&creds);
68 if (freed != SEC_E_OK)
69 {
70 (void)fprintf(stderr, "FreeCredentialsHandle(CREDSSP) failed: 0x%08" PRIx32 "\n",
71 (UINT32)freed);
72 return -1;
73 }
74
75 return 0;
76}