FreeRDP
Loading...
Searching...
No Matches
TestMarshalUnmarshal.c
1
19#include <string.h>
20#include <winpr/cred.h>
21
22typedef struct
23{
24 LPCSTR marshalled;
25 BYTE source[CERT_HASH_LENGTH];
26} TestItem;
27
28static const TestItem testValues[] = {
29 { "@@BQ9eNR0KWVU-CT8sPCp8z37POZHJ",
30 { 0x50, 0xef, 0x35, 0x11, 0xad, 0x58, 0x15, 0xf5, 0x0b, 0x13,
31 0xcf, 0x3e, 0x42, 0xca, 0xcf, 0xf7, 0xfe, 0x38, 0xd9, 0x91 } },
32 { "@@BKay-HwJsFZzclXAWZ#nO6Eluc7P",
33 { 0x8a, 0x26, 0xff, 0x07, 0x9c, 0xb0, 0x45, 0x36, 0x73, 0xe5,
34 0x05, 0x58, 0x99, 0x7f, 0x3a, 0x3a, 0x51, 0xba, 0xdc, 0xfe }
35
36 }
37};
38
39static int TestUnmarshal(WINPR_ATTR_UNUSED int argc, WINPR_ATTR_UNUSED char** argv)
40{
41
42 for (size_t i = 0; i < ARRAYSIZE(testValues); i++)
43 {
44 CRED_MARSHAL_TYPE t = BinaryBlobForSystem;
45 CERT_CREDENTIAL_INFO* certInfo = NULL;
46 const TestItem* const val = &testValues[i];
47
48 if (!CredUnmarshalCredentialA(val->marshalled, &t, (void**)&certInfo) || !certInfo ||
49 (t != CertCredential))
50 return -1;
51
52 const BOOL ok =
53 memcmp(val->source, certInfo->rgbHashOfCert, sizeof(certInfo->rgbHashOfCert)) == 0;
54
55 free(certInfo);
56
57 if (!ok)
58 return -1;
59 }
60 return 0;
61}
62
63static int TestMarshal(WINPR_ATTR_UNUSED int argc, WINPR_ATTR_UNUSED char** argv)
64{
65
66 for (size_t i = 0; i < ARRAYSIZE(testValues); i++)
67 {
68 CERT_CREDENTIAL_INFO certInfo = { sizeof(certInfo), { 0 } };
69 const TestItem* const val = &testValues[i];
70
71 memcpy(certInfo.rgbHashOfCert, val->source, sizeof(certInfo.rgbHashOfCert));
72 LPSTR out = NULL;
73
74 if (!CredMarshalCredentialA(CertCredential, &certInfo, &out) || !out)
75 return -1;
76
77 BOOL ok = (strcmp(val->marshalled, out) == 0);
78
79 free(out);
80
81 if (!ok)
82 return -1;
83 }
84 return 0;
85}
86
87int TestMarshalUnmarshal(int argc, char** argv)
88{
89 int ret = TestUnmarshal(argc, argv);
90 if (ret)
91 return ret;
92
93 ret = TestMarshal(argc, argv);
94 return ret;
95}