Debian Codegraph @

channels/rdpear/common/rdpear-common/rdpear_common.h

raw
1 /**
2 * FreeRDP: A Remote Desktop Protocol Implementation
3 *
4 * Copyright 2023 David Fort <[email protected]>
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
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
27 #include <freerdp/api.h>
28
29 #include <rdpear-common/ndr.h>
30
31 typedef enum
32 {
33 RDPEAR_PACKAGE_KERBEROS,
34 RDPEAR_PACKAGE_NTLM,
35 RDPEAR_PACKAGE_UNKNOWN
36 } RdpEarPackageType;
37
38 /* RDPEAR 2.2.1.1 */
39 typedef enum
40 {
41 // Start Kerberos remote calls
42 RemoteCallKerbMinimum = 0x100,
43 RemoteCallKerbNegotiateVersion = 0x100,
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
82 WINPR_ATTR_NODISCARD
83 FREERDP_LOCAL RdpEarPackageType rdpear_packageType_from_name(const WinPrAsn1_OctetString* package);
84
85 WINPR_ATTR_MALLOC(Stream_Free, 1)
86 WINPR_ATTR_NODISCARD
87 FREERDP_LOCAL wStream* rdpear_encodePayload(BOOL isKerb, wStream* payload);
88
89 #define RDPEAR_COMMON_MESSAGE_DECL(V) \
90 WINPR_ATTR_NODISCARD \
91 FREERDP_LOCAL BOOL ndr_read_##V(NdrContext* context, wStream* s, const void* hints, V* obj); \
92 WINPR_ATTR_NODISCARD \
93 FREERDP_LOCAL BOOL ndr_write_##V(NdrContext* context, wStream* s, const void* hints, \
94 const V* obj); \
95 FREERDP_LOCAL void ndr_destroy_##V(NdrContext* context, const void* hints, V* obj); \
96 FREERDP_LOCAL void ndr_dump_##V(wLog* logger, UINT32 lvl, size_t indentLevel, const V* obj); \
97 WINPR_ATTR_NODISCARD \
98 FREERDP_LOCAL NdrMessageType ndr_##V##_descr(void)
99
100 /** @brief 2.2.1.2.2 KERB_RPC_OCTET_STRING */
101 typedef struct
102 {
103 UINT32 length;
104 BYTE* value;
105 } KERB_RPC_OCTET_STRING;
106
107 RDPEAR_COMMON_MESSAGE_DECL(KERB_RPC_OCTET_STRING);
108
109 /** @brief 2.2.1.2.1 KERB_ASN1_DATA */
110 typedef struct
111 {
112 UINT32 Pdu;
113 NdrArrayHints Asn1BufferHints;
114 BYTE* Asn1Buffer;
115 } KERB_ASN1_DATA;
116
117 RDPEAR_COMMON_MESSAGE_DECL(KERB_ASN1_DATA);
118
119 /** @brief 2.3.10 RPC_UNICODE_STRING (MS-DTYP) */
120 typedef struct
121 {
122 NdrVaryingArrayHints lenHints;
123 UINT32 strLength;
124 WCHAR* Buffer;
125 } RPC_UNICODE_STRING;
126
127 RDPEAR_COMMON_MESSAGE_DECL(RPC_UNICODE_STRING);
128
129 /** @brief 2.2.1.2.3 KERB_RPC_INTERNAL_NAME */
130 typedef struct
131 {
132 UINT16 NameType;
133 NdrArrayHints nameHints;
134 RPC_UNICODE_STRING* Names;
135 } KERB_RPC_INTERNAL_NAME;
136
137 RDPEAR_COMMON_MESSAGE_DECL(KERB_RPC_INTERNAL_NAME);
138
139 /** @brief 2.2.1.2.8 KERB_RPC_ENCRYPTION_KEY */
140 typedef struct
141 {
142 UINT32 reserved1;
143 UINT32 reserved2;
144 KERB_RPC_OCTET_STRING reserved3;
145 } KERB_RPC_ENCRYPTION_KEY;
146
147 RDPEAR_COMMON_MESSAGE_DECL(KERB_RPC_ENCRYPTION_KEY);
148
149 /** @brief 2.2.2.1.8 BuildEncryptedAuthData */
150 typedef struct
151 {
152 UINT32 KeyUsage;
153 KERB_RPC_ENCRYPTION_KEY* Key;
154 KERB_ASN1_DATA* PlainAuthData;
155 } BuildEncryptedAuthDataReq;
156
157 RDPEAR_COMMON_MESSAGE_DECL(BuildEncryptedAuthDataReq);
158
159 /** @brief 2.2.2.1.7 ComputeTgsChecksum */
160 typedef struct
161 {
162 KERB_ASN1_DATA* requestBody;
163 KERB_RPC_ENCRYPTION_KEY* Key;
164 UINT32 ChecksumType;
165 } ComputeTgsChecksumReq;
166
167 RDPEAR_COMMON_MESSAGE_DECL(ComputeTgsChecksumReq);
168
169 /** @brief 2.2.2.1.4 CreateApReqAuthenticator */
170 typedef struct
171 {
172 KERB_RPC_ENCRYPTION_KEY* EncryptionKey;
173 ULONG SequenceNumber;
174 KERB_RPC_INTERNAL_NAME* ClientName;
175 RPC_UNICODE_STRING* ClientRealm;
176 PLARGE_INTEGER SkewTime;
177 KERB_RPC_ENCRYPTION_KEY* SubKey; // optional
178 KERB_ASN1_DATA* AuthData; // optional
179 KERB_ASN1_DATA* GssChecksum; // optional
180 ULONG KeyUsage;
181 } CreateApReqAuthenticatorReq;
182
183 RDPEAR_COMMON_MESSAGE_DECL(CreateApReqAuthenticatorReq);
184
185 /** @brief 2.2.2.1.4 CreateApReqAuthenticator */
186 typedef struct
187 {
188 LARGE_INTEGER AuthenticatorTime;
189 KERB_ASN1_DATA Authenticator;
190 LONG KerbProtocolError;
191 } CreateApReqAuthenticatorResp;
192
193 RDPEAR_COMMON_MESSAGE_DECL(CreateApReqAuthenticatorResp);
194
195 /** @brief 2.2.2.1.6 UnpackKdcReplyBody */
196 typedef struct
197 {
198 KERB_ASN1_DATA* EncryptedData;
199 KERB_RPC_ENCRYPTION_KEY* Key;
200 KERB_RPC_ENCRYPTION_KEY* StrengthenKey;
201 ULONG Pdu;
202 ULONG KeyUsage;
203 } UnpackKdcReplyBodyReq;
204
205 RDPEAR_COMMON_MESSAGE_DECL(UnpackKdcReplyBodyReq);
206
207 /** @brief 2.2.2.1.6 UnpackKdcReplyBody */
208 typedef struct
209 {
210 LONG KerbProtocolError;
211 KERB_ASN1_DATA ReplyBody;
212 } UnpackKdcReplyBodyResp;
213
214 RDPEAR_COMMON_MESSAGE_DECL(UnpackKdcReplyBodyResp);
215
216 typedef struct
217 {
218 KERB_ASN1_DATA* EncryptedReply;
219 KERB_RPC_ENCRYPTION_KEY* Key;
220 } DecryptApReplyReq;
221
222 RDPEAR_COMMON_MESSAGE_DECL(DecryptApReplyReq);
223
224 typedef struct
225 {
226 KERB_ASN1_DATA* Reply;
227 KERB_ASN1_DATA* ReplyBody;
228 KERB_RPC_ENCRYPTION_KEY* SessionKey;
229 } PackApReplyReq;
230
231 RDPEAR_COMMON_MESSAGE_DECL(PackApReplyReq);
232
233 typedef struct
234 {
235 NdrArrayHints PackedReplyHints;
236 BYTE* PackedReply;
237 } PackApReplyResp;
238
239 RDPEAR_COMMON_MESSAGE_DECL(PackApReplyResp);
240
241 #undef RDPEAR_COMMON_MESSAGE_DECL
242
243 #endif /* FREERDP_CHANNEL_RDPEAR_COMMON_H */