1#include <winpr/print.h>
3#include <rdpear-common/ndr.h>
4#include <rdpear-common/rdpear_common.h>
7#define MAX(a, b) ((a) > (b)) ? (a) : (b)
10#define MIN(a, b) ((a) < (b)) ? (a) : (b)
13static BYTE nextValue(BYTE old, INT32 offset,
char symbol,
char startSymbol)
15 const INT32 uold = 16 * old;
16 const INT32 diff = symbol - startSymbol;
17 const INT32 res = uold + diff + offset;
18 return (BYTE)MIN(MAX(0, res), UINT8_MAX);
21static BYTE* parseHexBlock(
const char* str,
size_t* plen)
26 BYTE* ret = malloc(strlen(str) / 2);
28 const char* ptr = str;
42 WLog_ERR(
"",
"error parsing hex block, unpaired char");
57 tmp = nextValue(tmp, 0, *ptr,
'0');
75 tmp = nextValue(tmp, 10, *ptr,
'a');
93 tmp = nextValue(tmp, 10, *ptr,
'A');
105 WLog_ERR(
"",
"invalid char in hex block");
115static int TestNdrEarWrite(
int argc,
char* argv[])
121 BYTE buffer[16] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
124 wStream* s = Stream_New(NULL, 100);
128 NdrContext* context = ndr_context_new(FALSE, 1);
132 if (!ndr_write_KERB_ASN1_DATA(context, s, NULL, &asn1))
134 if (!ndr_treat_deferred_write(context, s))
141 ndr_context_destroy(&context);
142 Stream_Free(s, TRUE);
146static BOOL run_payload(NdrContext* context,
const BYTE* payload4,
size_t sizeofPayload4)
148 WINPR_ASSERT(context);
156 wStream* s = Stream_StaticInit(&staticS, payload4, sizeofPayload4);
157 if (!ndr_skip_bytes(context, s, 4))
159 if (!ndr_read_CreateApReqAuthenticatorReq(context, s, NULL, &createApReqAuthenticatorReq))
161 if (!ndr_treat_deferred_read(context, s))
163 if (createApReqAuthenticatorReq.KeyUsage != 7)
165 if (!createApReqAuthenticatorReq.EncryptionKey)
167 if (createApReqAuthenticatorReq.SubKey)
169 if (!createApReqAuthenticatorReq.ClientName)
171 if (createApReqAuthenticatorReq.ClientName->nameHints.count != 1)
173 if (!createApReqAuthenticatorReq.ClientRealm)
175 if (!createApReqAuthenticatorReq.AuthData)
177 if (createApReqAuthenticatorReq.AuthData->Asn1BufferHints.count != 2)
179 if (!createApReqAuthenticatorReq.SkewTime)
181 if (createApReqAuthenticatorReq.SkewTime->QuadPart != 0)
184 ndr_destroy_CreateApReqAuthenticatorReq(context, NULL, &createApReqAuthenticatorReq);
185 ndr_context_reset(context);
189static int TestNdrEarRead(
int argc,
char* argv[])
197 NdrContext* context = ndr_context_new(FALSE, 1);
203 const BYTE payload[] = {
204 0x00, 0x00, 0x00, 0x00,
205 0x02, 0x00, 0x00, 0x00,
206 0x28, 0x00, 0x02, 0x00,
209 0x02, 0x00, 0x00, 0x00,
215 wStream* s = Stream_StaticInit(&staticS, payload,
sizeof(payload));
218 if (!ndr_read_KERB_ASN1_DATA(context, s, NULL, &asn1) ||
219 !ndr_treat_deferred_read(context, s) || asn1.Asn1BufferHints.count != 2 ||
220 *asn1.Asn1Buffer != 0x30)
222 ndr_destroy_KERB_ASN1_DATA(context, NULL, &asn1);
223 ndr_context_reset(context);
229 const BYTE payload2[] = {
233 0x1c, 0x00, 0x02, 0x00,
235 0x0f, 0x00, 0x00, 0x00,
236 0x00, 0x00, 0x00, 0x00,
237 0x0e, 0x00, 0x00, 0x00,
239 0x48, 0x00, 0x41, 0x00, 0x52, 0x00, 0x44, 0x00, 0x45, 0x00, 0x4e, 0x00, 0x49, 0x00,
240 0x4e, 0x00, 0x47, 0x00, 0x33, 0x00, 0x2e, 0x00, 0x43, 0x00, 0x4f, 0x00, 0x4d, 0x00,
247 wStream* s = Stream_StaticInit(&staticS, payload2,
sizeof(payload2));
249 if (!ndr_read_RPC_UNICODE_STRING(context, s, NULL, &unicode) ||
250 !ndr_treat_deferred_read(context, s))
252 ndr_destroy_RPC_UNICODE_STRING(context, NULL, &unicode);
253 ndr_context_reset(context);
258 const BYTE payload3[] = {
262 0x10, 0x00, 0x02, 0x00,
264 0x01, 0x00, 0x00, 0x00,
269 0x14, 0x00, 0x02, 0x00,
271 0x0f, 0x00, 0x00, 0x00,
272 0x00, 0x00, 0x00, 0x00,
273 0x0e, 0x00, 0x00, 0x00,
274 0x41, 0x00, 0x64, 0x00, 0x6d, 0x00, 0x69, 0x00, 0x6e, 0x00, 0x69, 0x00, 0x73, 0x00,
275 0x74, 0x00, 0x72, 0x00, 0x61, 0x00, 0x74, 0x00, 0x65, 0x00, 0x75, 0x00, 0x72, 0x00,
283 wStream* s = Stream_StaticInit(&staticS, payload3,
sizeof(payload3));
284 if (!ndr_read_KERB_RPC_INTERNAL_NAME(context, s, NULL, &intName) ||
285 !ndr_treat_deferred_read(context, s))
287 ndr_destroy_KERB_RPC_INTERNAL_NAME(context, NULL, &intName);
288 ndr_context_reset(context);
294 const BYTE payload4[] = {
295 0x03, 0x01, 0x03, 0x01,
296 0x04, 0x00, 0x02, 0x00,
297 0xf8, 0xca, 0x95, 0x11,
298 0x0c, 0x00, 0x02, 0x00,
299 0x18, 0x00, 0x02, 0x00,
300 0x20, 0x00, 0x02, 0x00,
301 0x00, 0x00, 0x00, 0x00,
302 0x24, 0x00, 0x02, 0x00,
303 0x2c, 0x00, 0x02, 0x00,
304 0x07, 0x00, 0x00, 0x00,
307 0x40, 0xe9, 0x12, 0xdf,
308 0x12, 0x00, 0x00, 0x00,
310 0x4c, 0x00, 0x00, 0x00,
311 0x08, 0x00, 0x02, 0x00,
313 0x4c, 0x00, 0x00, 0x00,
314 0xc4, 0x41, 0xee, 0x34, 0x82, 0x2b, 0x29, 0x61, 0xe2, 0x96, 0xb5, 0x75, 0x61, 0x2d,
315 0xbf, 0x86, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
316 0x00, 0x00, 0x00, 0x00, 0x89, 0x08, 0x60, 0x2e, 0x30, 0x3e, 0xfe, 0x56, 0x11, 0xf0,
317 0x31, 0xf2, 0xd6, 0x2e, 0x3d, 0x33, 0xfe, 0xce, 0x56, 0x12, 0xbf, 0xb2, 0xe5, 0x86,
318 0x29, 0x8d, 0x29, 0x74, 0x1f, 0x8a, 0xf9, 0xb9, 0x8c, 0xd4, 0x86, 0x3a, 0x21, 0x92,
319 0xb2, 0x07, 0x95, 0x4b, 0xea, 0xee,
324 0x10, 0x00, 0x02, 0x00,
326 0x01, 0x00, 0x00, 0x00,
331 0x14, 0x00, 0x02, 0x00,
333 0x0f, 0x00, 0x00, 0x00,
334 0x00, 0x00, 0x00, 0x00,
335 0x0e, 0x00, 0x00, 0x00,
336 0x41, 0x00, 0x64, 0x00, 0x6d, 0x00, 0x69, 0x00, 0x6e, 0x00, 0x69, 0x00, 0x73, 0x00,
337 0x74, 0x00, 0x72, 0x00, 0x61, 0x00, 0x74, 0x00, 0x65, 0x00, 0x75, 0x00, 0x72, 0x00,
342 0x1c, 0x00, 0x02, 0x00,
344 0x0f, 0x00, 0x00, 0x00,
345 0x00, 0x00, 0x00, 0x00,
346 0x0e, 0x00, 0x00, 0x00,
347 0x48, 0x00, 0x41, 0x00, 0x52, 0x00, 0x44, 0x00, 0x45, 0x00, 0x4e, 0x00, 0x49, 0x00,
348 0x4e, 0x00, 0x47, 0x00, 0x33, 0x00, 0x2e, 0x00, 0x43, 0x00, 0x4f, 0x00, 0x4d, 0x00,
350 0x00, 0x00, 0x00, 0x00,
353 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
356 0x00, 0x00, 0x00, 0x00,
357 0x02, 0x00, 0x00, 0x00,
358 0x28, 0x00, 0x02, 0x00,
360 0x02, 0x00, 0x00, 0x00,
361 0x30, 0x00, 0x00, 0x00,
364 0x08, 0x00, 0x00, 0x00,
365 0x1b, 0x00, 0x00, 0x00,
366 0x30, 0x00, 0x02, 0x00,
368 0x1b, 0x00, 0x00, 0x00,
369 0x30, 0x19, 0xa0, 0x03, 0x02, 0x01, 0x07, 0xa1, 0x12, 0x04, 0x10, 0xb9, 0x4f, 0xcd,
370 0xae, 0xd9, 0xa8, 0xff, 0x49, 0x69, 0x5a, 0xd1, 0x1d, 0x38, 0x49, 0xb6, 0x92, 0x00
372 if (!run_payload(context, payload4,
sizeof(payload4)))
378 size_t sizeofPayload4 = 0;
379 BYTE* payload4 = parseHexBlock(
"03 01 03 01 \
380 04 00 02 00 38 9e ef 6b 0c 00 02 00 18 00 02 00 \
381 20 00 02 00 00 00 00 00 24 00 02 00 2c 00 02 00 \
382 07 00 00 00 13 8a a5 a8 12 00 00 00 20 00 00 00 \
383 08 00 02 00 20 00 00 00 c9 03 42 a8 17 8f d9 c4 \
384 9b d2 c4 6e 73 64 98 7b 90 f5 9a 28 77 8e ca de \
385 29 2e a3 8d 8a 56 36 d5 01 00 01 00 10 00 02 00 \
386 01 00 00 00 1c 00 1e 00 14 00 02 00 0f 00 00 00 \
387 00 00 00 00 0e 00 00 00 41 00 64 00 6d 00 69 00 \
388 6e 00 69 00 73 00 74 00 72 00 61 00 74 00 65 00 \
389 75 00 72 00 1c 00 1e 00 1c 00 02 00 0f 00 00 00 \
390 00 00 00 00 0e 00 00 00 48 00 41 00 52 00 44 00 \
391 45 00 4e 00 49 00 4e 00 47 00 33 00 2e 00 43 00 \
392 4f 00 4d 00 00 00 00 00 00 00 00 00 00 00 00 00 \
393 02 00 00 00 28 00 02 00 02 00 00 00 30 00 00 00 \
394 08 00 00 00 1b 00 00 00 30 00 02 00 1b 00 00 00 \
395 30 19 a0 03 02 01 07 a1 12 04 10 e4 aa ff 2b 93 \
396 97 4c f2 5c 0b 49 85 72 92 94 54 00",
398 const BOOL rc = run_payload(context, payload4, sizeofPayload4);
407 ndr_context_destroy(&context);
411int TestNdrEar(
int argc,
char* argv[])
413 const int rc = TestNdrEarWrite(argc, argv);
416 return TestNdrEarRead(argc, argv);
2.2.2.1.4 CreateApReqAuthenticator
2.2.1.2.3 KERB_RPC_INTERNAL_NAME
2.3.10 RPC_UNICODE_STRING (MS-DTYP)