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