FreeRDP
Loading...
Searching...
No Matches
rdpear_common.h
1
18
19#ifndef FREERDP_CHANNEL_RDPEAR_COMMON_H
20#define FREERDP_CHANNEL_RDPEAR_COMMON_H
21
22#include <winpr/stream.h>
23#include <winpr/asn1.h>
24#include <winpr/wlog.h>
25#include <winpr/sspi.h>
26#include <winpr/ndr.h>
27
28#include <freerdp/api.h>
29
31typedef enum
32{
33 RDPEAR_PACKAGE_KERBEROS,
34 RDPEAR_PACKAGE_NTLM,
35 RDPEAR_PACKAGE_UNKNOWN
36} RdpEarPackageType;
37
38/* RDPEAR 2.2.1.1 */
39typedef enum
40{
41 // Start Kerberos remote calls
42 RemoteCallKerbMinimum = 0x100,
43 RemoteCallKerbNegotiateVersion = RemoteCallKerbMinimum,
44 RemoteCallKerbBuildAsReqAuthenticator,
45 RemoteCallKerbVerifyServiceTicket,
46 RemoteCallKerbCreateApReqAuthenticator,
47 RemoteCallKerbDecryptApReply,
48 RemoteCallKerbUnpackKdcReplyBody,
49 RemoteCallKerbComputeTgsChecksum,
50 RemoteCallKerbBuildEncryptedAuthData,
51 RemoteCallKerbPackApReply,
52 RemoteCallKerbHashS4UPreauth,
53 RemoteCallKerbSignS4UPreauthData,
54 RemoteCallKerbVerifyChecksum,
55 RemoteCallKerbReserved1,
56 RemoteCallKerbReserved2,
57 RemoteCallKerbReserved3,
58 RemoteCallKerbReserved4,
59 RemoteCallKerbReserved5,
60 RemoteCallKerbReserved6,
61 RemoteCallKerbReserved7,
62 RemoteCallKerbDecryptPacCredentials,
63 RemoteCallKerbCreateECDHKeyAgreement,
64 RemoteCallKerbCreateDHKeyAgreement,
65 RemoteCallKerbDestroyKeyAgreement,
66 RemoteCallKerbKeyAgreementGenerateNonce,
67 RemoteCallKerbFinalizeKeyAgreement,
68 RemoteCallKerbMaximum = 0x1ff,
69 // End Kerberos remote calls
70
71 // Start NTLM remote calls
72 RemoteCallNtlmMinimum = 0x200,
73 RemoteCallNtlmNegotiateVersion = 0x200,
74 RemoteCallNtlmLm20GetNtlm3ChallengeResponse,
75 RemoteCallNtlmCalculateNtResponse,
76 RemoteCallNtlmCalculateUserSessionKeyNt,
77 RemoteCallNtlmCompareCredentials,
78 RemoteCallNtlmMaximum = 0x2ff,
79 // End NTLM remote calls
80} RemoteGuardCallId;
81
82FREERDP_LOCAL RdpEarPackageType rdpear_packageType_from_name(const WinPrAsn1_OctetString* package);
83FREERDP_LOCAL wStream* rdpear_encodePayload(RdpEarPackageType packageType, wStream* payload);
84
85#define RDPEAR_COMMON_MESSAGE_DECL(V) \
86 FREERDP_LOCAL BOOL ndr_decoder_read_##V(WinPrNdrDecoder* context, wStream* s, \
87 const void* hints, V* obj); \
88 FREERDP_LOCAL BOOL ndr_encoder_write_##V(WinPrNdrEncoder* context, wStream* s, \
89 const void* hints, const V* obj); \
90 FREERDP_LOCAL void ndr_destroy_##V(const void* hints, V* obj); \
91 FREERDP_LOCAL void ndr_dump_##V(wLog* logger, UINT32 lvl, size_t indentLevel, const V* obj); \
92 FREERDP_LOCAL WinPrNdrMessageType ndr_##V##_descr(void)
93
95typedef struct
96{
97 UINT32 length;
98 BYTE* value;
100
101RDPEAR_COMMON_MESSAGE_DECL(KERB_RPC_OCTET_STRING);
102
104typedef struct
105{
106 UINT32 Pdu;
107 WinPrNdrArrayHints Asn1BufferHints;
108 BYTE* Asn1Buffer;
110
111RDPEAR_COMMON_MESSAGE_DECL(KERB_ASN1_DATA);
112
114typedef struct
115{
117 UINT32 strLength;
118 WCHAR* Buffer;
120
121RDPEAR_COMMON_MESSAGE_DECL(RPC_UNICODE_STRING);
122
124typedef struct
125{
126 UINT16 NameType;
127 WinPrNdrArrayHints nameHints;
128 RPC_UNICODE_STRING* Names;
130
131RDPEAR_COMMON_MESSAGE_DECL(KERB_RPC_INTERNAL_NAME);
132
134typedef struct
135{
136 UINT32 reserved1;
137 UINT32 reserved2;
138 KERB_RPC_OCTET_STRING reserved3;
140
141RDPEAR_COMMON_MESSAGE_DECL(KERB_RPC_ENCRYPTION_KEY);
142
144typedef struct
145{
146 UINT32 KeyUsage;
148 KERB_ASN1_DATA* PlainAuthData;
150
151RDPEAR_COMMON_MESSAGE_DECL(BuildEncryptedAuthDataReq);
152
154typedef struct
155{
156 KERB_ASN1_DATA* requestBody;
158 UINT32 ChecksumType;
160
161RDPEAR_COMMON_MESSAGE_DECL(ComputeTgsChecksumReq);
162
164typedef struct
165{
166 KERB_RPC_ENCRYPTION_KEY* EncryptionKey;
167 ULONG SequenceNumber;
168 KERB_RPC_INTERNAL_NAME* ClientName;
169 RPC_UNICODE_STRING* ClientRealm;
170 PLARGE_INTEGER SkewTime;
171 KERB_RPC_ENCRYPTION_KEY* SubKey; // optional
172 KERB_ASN1_DATA* AuthData; // optional
173 KERB_ASN1_DATA* GssChecksum; // optional
174 ULONG KeyUsage;
176
177RDPEAR_COMMON_MESSAGE_DECL(CreateApReqAuthenticatorReq);
178
180typedef struct
181{
182 LARGE_INTEGER AuthenticatorTime;
183 KERB_ASN1_DATA Authenticator;
184 LONG KerbProtocolError;
186
187RDPEAR_COMMON_MESSAGE_DECL(CreateApReqAuthenticatorResp);
188
190typedef struct
191{
192 KERB_ASN1_DATA* EncryptedData;
194 KERB_RPC_ENCRYPTION_KEY* StrengthenKey;
195 ULONG Pdu;
196 ULONG KeyUsage;
198
199RDPEAR_COMMON_MESSAGE_DECL(UnpackKdcReplyBodyReq);
200
202typedef struct
203{
204 LONG KerbProtocolError;
205 KERB_ASN1_DATA ReplyBody;
207
208RDPEAR_COMMON_MESSAGE_DECL(UnpackKdcReplyBodyResp);
209
210typedef struct
211{
212 KERB_ASN1_DATA* EncryptedReply;
215
216RDPEAR_COMMON_MESSAGE_DECL(DecryptApReplyReq);
217
218typedef struct
219{
220 KERB_ASN1_DATA* Reply;
221 KERB_ASN1_DATA* ReplyBody;
222 KERB_RPC_ENCRYPTION_KEY* SessionKey;
224
225RDPEAR_COMMON_MESSAGE_DECL(PackApReplyReq);
226
227typedef struct
228{
229 WinPrNdrArrayHints PackedReplyHints;
230 BYTE* PackedReply;
232
233RDPEAR_COMMON_MESSAGE_DECL(PackApReplyResp);
234
235#undef RDPEAR_COMMON_MESSAGE_DECL
236
241typedef union
242{
243 UINT32 NegotiateVersion;
245 DecryptApReplyReq DecryptApReply;
246 UnpackKdcReplyBodyReq UnpackKdcReplyBody;
247 ComputeTgsChecksumReq ComputeTgsChecksum;
248 BuildEncryptedAuthDataReq BuildEncryptedAuthData;
249 PackApReplyReq PackApReply;
251
252typedef struct
253{
254 UINT16 CallId;
257
272
273typedef struct
274{
275 UINT16 CallId;
276 UINT32 Status;
279
280#define RDPEAR_MSV1_0_CREDENTIAL_KEY_LENGTH 20
281#define RDPEAR_MSV1_0_CHALLENGE_LENGTH 8
282#define RDPEAR_MSV1_0_RESPONSE_LENGTH 24
283#define RDPEAR_MSV1_0_NTLM3_RESPONSE_LENGTH 16
284#define RDPEAR_MSV1_0_USER_SESSION_KEY_LENGTH 16
285
287typedef struct
288{
289 BYTE reserved1;
290 BYTE reserved2;
291 BYTE reserved3;
292 UINT16 reserved4;
293 BYTE reserved5[RDPEAR_MSV1_0_CREDENTIAL_KEY_LENGTH];
294 WinPrNdrArrayHints reservedSize;
295 BYTE* reserved6;
297
299typedef struct
300{
301 BYTE Data[RDPEAR_MSV1_0_CHALLENGE_LENGTH];
303
305typedef struct
306{
307 BYTE Data[RDPEAR_MSV1_0_RESPONSE_LENGTH];
309
311typedef struct
312{
313 BYTE Response[RDPEAR_MSV1_0_NTLM3_RESPONSE_LENGTH];
314 BYTE ChallengeFromClient[RDPEAR_MSV1_0_CHALLENGE_LENGTH];
316
318typedef struct
319{
320 BYTE Data[RDPEAR_MSV1_0_USER_SESSION_KEY_LENGTH];
322
324typedef struct
325{
327 RPC_UNICODE_STRING* UserName;
328 RPC_UNICODE_STRING* LogonDomainName;
329 RPC_UNICODE_STRING* ServerName;
330 BYTE ChallengeToClient[RDPEAR_MSV1_0_CHALLENGE_LENGTH];
332
333typedef struct
334{
335 WinPrNdrArrayHints Ntlm3ResponseLength;
337 MSV1_0_LM3_RESPONSE Lm3Response;
338 USER_SESSION_KEY UserSessionKey;
339 NT_CHALLENGE LmSessionKey;
341
343typedef struct
344{
345 NT_CHALLENGE* NtChallenge;
348
350typedef struct
351{
352 NT_RESPONSE* NtResponse;
355
357typedef struct
358{
359 MSV1_0_REMOTE_ENCRYPTED_SECRETS* LhsCredential;
360 MSV1_0_REMOTE_ENCRYPTED_SECRETS* RhsCredential;
362
363typedef struct
364{
365 BOOL AreNtOwfsEqual;
366 BOOL AreLmOwfsEqual;
367 BOOL AreShaOwfsEqual;
369
371typedef union
372{
373 UINT32 NegotiateVersion;
375 CalculateNtResponseReq CalculateNtResponse;
376 CalculateUserSessionKeyNtReq CalculateUserSessionKeyNt;
377 CompareCredentialsReq CompareCredentials;
379
380typedef struct
381{
382 UINT16 CallId;
385
395
396typedef struct
397{
398 UINT16 CallId;
399 UINT32 Status;
402
403/* The messages are type serialized (MS-RPCE 2.2.6): the decoder is created from the type
404 * serialization header and the reader reads the object that follows. The writer writes the type
405 * serialization header and the object. The decoded pointers are NDR referents, released by the
406 * free functions.
407 */
408
409FREERDP_LOCAL BOOL rdpear_kerb_input_read(WinPrNdrDecoder* decoder, wStream* s,
411FREERDP_LOCAL void rdpear_kerb_input_free(KerbCredIsoRemoteInput* input);
412FREERDP_LOCAL BOOL rdpear_kerb_output_write(WinPrNdrEncoder* encoder, wStream* s,
413 const KerbCredIsoRemoteOutput* output);
414FREERDP_LOCAL void rdpear_kerb_output_free(KerbCredIsoRemoteOutput* output);
415
416FREERDP_LOCAL BOOL rdpear_ntlm_input_read(WinPrNdrDecoder* decoder, wStream* s,
418FREERDP_LOCAL void rdpear_ntlm_input_free(NtlmCredIsoRemoteInput* input);
419FREERDP_LOCAL BOOL rdpear_ntlm_output_write(WinPrNdrEncoder* encoder, wStream* s,
420 const NtlmCredIsoRemoteOutput* output);
421FREERDP_LOCAL void rdpear_ntlm_output_free(NtlmCredIsoRemoteOutput* output);
422
423#endif /* FREERDP_CHANNEL_RDPEAR_COMMON_H */
NDR encoder and decoder ([C706] chapter 14, [MS-RPCE] 2.2.5 and 2.2.6).
hints for a conformant array
Definition ndr.h:553
hints for a conformant varying array
Definition ndr.h:526
2.2.2.1.8 BuildEncryptedAuthData
2.2.2.2.3 CalculateNtResponse
2.2.2.2.4 CalculateUserSessionKeyNt
2.2.2.2.5 CompareCredentials
2.2.2.1.7 ComputeTgsChecksum
2.2.2.1.4 CreateApReqAuthenticator
2.2.2.1.4 CreateApReqAuthenticator
2.2.1.2.1 KERB_ASN1_DATA
2.2.1.2.8 KERB_RPC_ENCRYPTION_KEY
2.2.1.2.3 KERB_RPC_INTERNAL_NAME
2.2.1.2.2 KERB_RPC_OCTET_STRING
KerbCredIsoRemoteInputUnion Input
KerbCredIsoRemoteOutputUnion Output
2.2.2.2.2 Lm20GetNtlm3ChallengeResponse
2.2.1.3.3 MSV1_0_LM3_RESPONSE
2.2.1.3.6 MSV1_0_REMOTE_ENCRYPTED_SECRETS, opaque for the CredSSP server
BYTE reserved5[RDPEAR_MSV1_0_CREDENTIAL_KEY_LENGTH]
2.2.1.3.1 NT_CHALLENGE, also LM_SESSION_KEY
2.2.1.3.2 NT_RESPONSE
NtlmCredIsoRemoteInputUnion Input
NtlmCredIsoRemoteOutputUnion Output
2.3.10 RPC_UNICODE_STRING (MS-DTYP)
2.2.1.3.4 USER_SESSION_KEY
2.2.2.1.6 UnpackKdcReplyBody
2.2.2.1.6 UnpackKdcReplyBody
2.2.1.2.9 KerbCredIsoRemoteInput
CreateApReqAuthenticatorReq CreateApReqAuthenticator
2.2.1.2.10 KerbCredIsoRemoteOutput
CreateApReqAuthenticatorResp CreateApReqAuthenticator
UnpackKdcReplyBodyResp UnpackKdcReplyBody
KERB_ASN1_DATA BuildEncryptedAuthData
2.2.1.3.7 NtlmCredIsoRemoteInput
Lm20GetNtlm3ChallengeResponseReq Lm20GetNtlm3ChallengeResponse
2.2.1.3.8 NtlmCredIsoRemoteOutput
USER_SESSION_KEY CalculateUserSessionKeyNt
CompareCredentialsResp CompareCredentials
Lm20GetNtlm3ChallengeResponseResp Lm20GetNtlm3ChallengeResponse