2 Unix SMB/CIFS implementation.
4 test suite for netlogon PAC operations
6 Copyright (C) Andrew Bartlett <abartlet@samba.org> 2012
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "auth/auth.h"
24 #include "auth/auth_sam_reply.h"
25 #include "auth/gensec/gensec.h"
26 #include "system/kerberos.h"
27 #include "auth/kerberos/kerberos.h"
28 #include "auth/credentials/credentials.h"
29 #include "auth/credentials/credentials_krb5.h"
30 #include "lib/cmdline/popt_common.h"
31 #include "torture/rpc/torture_rpc.h"
32 #include "libcli/auth/libcli_auth.h"
33 #include "libcli/security/security.h"
34 #include "librpc/gen_ndr/ndr_netlogon_c.h"
35 #include "librpc/gen_ndr/ndr_krb5pac.h"
36 #include "librpc/gen_ndr/ndr_samr_c.h"
37 #include "param/param.h"
39 #define TEST_MACHINE_NAME_BDC "torturepacbdc"
40 #define TEST_MACHINE_NAME_WKSTA "torturepacwksta"
41 #define TEST_MACHINE_NAME_WKSTA_DES "torturepacwkdes"
42 #define TEST_MACHINE_NAME_S2U4SELF_BDC "tests2u4selfbdc"
43 #define TEST_MACHINE_NAME_S2U4SELF_WKSTA "tests2u4selfwk"
46 struct PAC_SIGNATURE_DATA
*pac_srv_sig
;
47 struct PAC_SIGNATURE_DATA
*pac_kdc_sig
;
50 /* A helper function which avoids touching the local databases to
51 * generate the session info, as we just want to verify the PAC
52 * details, not the full local token */
53 static NTSTATUS
test_generate_session_info_pac(struct auth4_context
*auth_ctx
,
55 struct smb_krb5_context
*smb_krb5_context
,
57 const char *principal_name
,
58 const struct tsocket_address
*remote_address
,
59 uint32_t session_info_flags
,
60 struct auth_session_info
**session_info
)
63 struct auth_user_info_dc
*user_info_dc
;
65 struct pac_data
*pac_data
;
67 tmp_ctx
= talloc_named(mem_ctx
, 0, "gensec_gssapi_session_info context");
68 NT_STATUS_HAVE_NO_MEMORY(tmp_ctx
);
70 auth_ctx
->private_data
= pac_data
= talloc_zero(auth_ctx
, struct pac_data
);
72 pac_data
->pac_srv_sig
= talloc(tmp_ctx
, struct PAC_SIGNATURE_DATA
);
73 if (!pac_data
->pac_srv_sig
) {
75 return NT_STATUS_NO_MEMORY
;
77 pac_data
->pac_kdc_sig
= talloc(tmp_ctx
, struct PAC_SIGNATURE_DATA
);
78 if (!pac_data
->pac_kdc_sig
) {
80 return NT_STATUS_NO_MEMORY
;
83 nt_status
= kerberos_pac_blob_to_user_info_dc(tmp_ctx
,
85 smb_krb5_context
->krb5_context
,
87 pac_data
->pac_srv_sig
,
88 pac_data
->pac_kdc_sig
);
89 if (!NT_STATUS_IS_OK(nt_status
)) {
94 talloc_steal(pac_data
, pac_data
->pac_srv_sig
);
95 talloc_steal(pac_data
, pac_data
->pac_kdc_sig
);
97 if (user_info_dc
->info
->authenticated
) {
98 session_info_flags
|= AUTH_SESSION_INFO_AUTHENTICATED
;
101 session_info_flags
|= AUTH_SESSION_INFO_SIMPLE_PRIVILEGES
;
102 nt_status
= auth_generate_session_info(mem_ctx
,
105 user_info_dc
, session_info_flags
,
107 if (!NT_STATUS_IS_OK(nt_status
)) {
108 talloc_free(tmp_ctx
);
112 talloc_free(tmp_ctx
);
116 /* Check to see if we can pass the PAC across to the NETLOGON server for validation */
118 /* Also happens to be a really good one-step verfication of our Kerberos stack */
120 static bool test_PACVerify(struct torture_context
*tctx
,
121 struct dcerpc_pipe
*p
,
122 struct cli_credentials
*credentials
,
123 enum netr_SchannelType secure_channel_type
,
124 const char *test_machine_name
)
128 struct netr_LogonSamLogon r
;
130 union netr_LogonLevel logon
;
131 union netr_Validation validation
;
132 uint8_t authoritative
;
133 struct netr_Authenticator return_authenticator
;
135 struct netr_GenericInfo generic
;
136 struct netr_Authenticator auth
, auth2
;
138 struct netlogon_creds_CredentialState
*creds
;
139 struct gensec_security
*gensec_client_context
;
140 struct gensec_security
*gensec_server_context
;
142 DATA_BLOB client_to_server
, server_to_client
, pac_wrapped
, payload
;
143 struct PAC_Validate pac_wrapped_struct
;
145 enum ndr_err_code ndr_err
;
147 struct auth4_context
*auth_context
;
148 struct auth_session_info
*session_info
;
149 struct pac_data
*pac_data
;
151 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
152 TALLOC_CTX
*tmp_ctx
= talloc_new(tctx
);
153 torture_assert(tctx
, tmp_ctx
!= NULL
, "talloc_new() failed");
155 if (!test_SetupCredentials2(p
, tctx
, NETLOGON_NEG_AUTH2_ADS_FLAGS
,
156 credentials
, secure_channel_type
,
161 auth_context
= talloc_zero(tmp_ctx
, struct auth4_context
);
162 torture_assert(tctx
, auth_context
!= NULL
, "talloc_new() failed");
164 auth_context
->generate_session_info_pac
= test_generate_session_info_pac
;
166 status
= gensec_client_start(tctx
, &gensec_client_context
,
167 lpcfg_gensec_settings(tctx
, tctx
->lp_ctx
));
168 torture_assert_ntstatus_ok(tctx
, status
, "gensec_client_start (client) failed");
170 status
= gensec_set_target_hostname(gensec_client_context
, test_machine_name
);
172 status
= gensec_set_credentials(gensec_client_context
, cmdline_credentials
);
173 torture_assert_ntstatus_ok(tctx
, status
, "gensec_set_credentials (client) failed");
175 status
= gensec_start_mech_by_sasl_name(gensec_client_context
, "GSSAPI");
176 torture_assert_ntstatus_ok(tctx
, status
, "gensec_start_mech_by_sasl_name (client) failed");
178 status
= gensec_server_start(tctx
,
179 lpcfg_gensec_settings(tctx
, tctx
->lp_ctx
),
180 auth_context
, &gensec_server_context
);
181 torture_assert_ntstatus_ok(tctx
, status
, "gensec_server_start (server) failed");
183 status
= gensec_set_credentials(gensec_server_context
, credentials
);
184 torture_assert_ntstatus_ok(tctx
, status
, "gensec_set_credentials (server) failed");
186 status
= gensec_start_mech_by_sasl_name(gensec_server_context
, "GSSAPI");
187 torture_assert_ntstatus_ok(tctx
, status
, "gensec_start_mech_by_sasl_name (server) failed");
189 server_to_client
= data_blob(NULL
, 0);
192 /* Do a client-server update dance */
193 status
= gensec_update(gensec_client_context
, tmp_ctx
, tctx
->ev
, server_to_client
, &client_to_server
);
194 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {;
195 torture_assert_ntstatus_ok(tctx
, status
, "gensec_update (client) failed");
198 status
= gensec_update(gensec_server_context
, tmp_ctx
, tctx
->ev
, client_to_server
, &server_to_client
);
199 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {;
200 torture_assert_ntstatus_ok(tctx
, status
, "gensec_update (server) failed");
203 if (NT_STATUS_IS_OK(status
)) {
208 /* Extract the PAC using Samba's code */
210 status
= gensec_session_info(gensec_server_context
, gensec_server_context
, &session_info
);
211 torture_assert_ntstatus_ok(tctx
, status
, "gensec_session_info failed");
213 pac_data
= talloc_get_type(auth_context
->private_data
, struct pac_data
);
215 torture_assert(tctx
, pac_data
!= NULL
, "gensec_update failed to fill in pac_data in auth_context");
216 torture_assert(tctx
, pac_data
->pac_srv_sig
!= NULL
, "pac_srv_sig not present");
217 torture_assert(tctx
, pac_data
->pac_kdc_sig
!= NULL
, "pac_kdc_sig not present");
219 pac_wrapped_struct
.ChecksumLength
= pac_data
->pac_srv_sig
->signature
.length
;
220 pac_wrapped_struct
.SignatureType
= pac_data
->pac_kdc_sig
->type
;
221 pac_wrapped_struct
.SignatureLength
= pac_data
->pac_kdc_sig
->signature
.length
;
222 pac_wrapped_struct
.ChecksumAndSignature
= payload
223 = data_blob_talloc(tmp_ctx
, NULL
,
224 pac_wrapped_struct
.ChecksumLength
225 + pac_wrapped_struct
.SignatureLength
);
226 memcpy(&payload
.data
[0],
227 pac_data
->pac_srv_sig
->signature
.data
,
228 pac_wrapped_struct
.ChecksumLength
);
229 memcpy(&payload
.data
[pac_wrapped_struct
.ChecksumLength
],
230 pac_data
->pac_kdc_sig
->signature
.data
,
231 pac_wrapped_struct
.SignatureLength
);
233 ndr_err
= ndr_push_struct_blob(&pac_wrapped
, tmp_ctx
, &pac_wrapped_struct
,
234 (ndr_push_flags_fn_t
)ndr_push_PAC_Validate
);
235 torture_assert(tctx
, NDR_ERR_CODE_IS_SUCCESS(ndr_err
), "ndr_push_struct_blob of PACValidate structure failed");
237 torture_assert(tctx
, (creds
->negotiate_flags
& NETLOGON_NEG_ARCFOUR
), "not willing to even try a PACValidate without RC4 encryption");
238 netlogon_creds_arcfour_crypt(creds
, pac_wrapped
.data
, pac_wrapped
.length
);
240 generic
.length
= pac_wrapped
.length
;
241 generic
.data
= pac_wrapped
.data
;
243 /* Validate it over the netlogon pipe */
245 generic
.identity_info
.parameter_control
= 0;
246 generic
.identity_info
.logon_id_high
= 0;
247 generic
.identity_info
.logon_id_low
= 0;
248 generic
.identity_info
.domain_name
.string
= session_info
->info
->domain_name
;
249 generic
.identity_info
.account_name
.string
= session_info
->info
->account_name
;
250 generic
.identity_info
.workstation
.string
= test_machine_name
;
252 generic
.package_name
.string
= "Kerberos";
254 logon
.generic
= &generic
;
257 netlogon_creds_client_authenticator(creds
, &auth
);
258 r
.in
.credential
= &auth
;
259 r
.in
.return_authenticator
= &auth2
;
261 r
.in
.logon_level
= NetlogonGenericInformation
;
262 r
.in
.server_name
= talloc_asprintf(tctx
, "\\\\%s", dcerpc_server_name(p
));
263 r
.in
.computer_name
= cli_credentials_get_workstation(credentials
);
264 r
.in
.validation_level
= NetlogonValidationGenericInfo2
;
265 r
.out
.validation
= &validation
;
266 r
.out
.authoritative
= &authoritative
;
267 r
.out
.return_authenticator
= &return_authenticator
;
269 torture_assert_ntstatus_ok(tctx
, dcerpc_netr_LogonSamLogon_r(b
, tctx
, &r
),
270 "LogonSamLogon failed");
272 torture_assert_ntstatus_ok(tctx
, r
.out
.result
, "LogonSamLogon failed");
274 /* This will break the signature nicely (even in the crypto wrapping), check we get a logon failure */
275 generic
.data
[generic
.length
-1]++;
277 logon
.generic
= &generic
;
280 netlogon_creds_client_authenticator(creds
, &auth
);
281 r
.in
.credential
= &auth
;
282 r
.in
.return_authenticator
= &auth2
;
283 r
.in
.logon_level
= NetlogonGenericInformation
;
285 r
.in
.server_name
= talloc_asprintf(tctx
, "\\\\%s", dcerpc_server_name(p
));
286 r
.in
.computer_name
= cli_credentials_get_workstation(credentials
);
287 r
.in
.validation_level
= NetlogonValidationGenericInfo2
;
289 torture_assert_ntstatus_ok(tctx
, dcerpc_netr_LogonSamLogon_r(b
, tctx
, &r
),
290 "LogonSamLogon failed");
292 torture_assert_ntstatus_equal(tctx
, r
.out
.result
, NT_STATUS_LOGON_FAILURE
, "LogonSamLogon failed");
294 torture_assert(tctx
, netlogon_creds_client_check(creds
, &r
.out
.return_authenticator
->cred
),
295 "Credential chaining failed");
297 /* This will break the parsing nicely (even in the crypto wrapping), check we get INVALID_PARAMETER */
300 logon
.generic
= &generic
;
303 netlogon_creds_client_authenticator(creds
, &auth
);
304 r
.in
.credential
= &auth
;
305 r
.in
.return_authenticator
= &auth2
;
306 r
.in
.logon_level
= NetlogonGenericInformation
;
308 r
.in
.server_name
= talloc_asprintf(tctx
, "\\\\%s", dcerpc_server_name(p
));
309 r
.in
.computer_name
= cli_credentials_get_workstation(credentials
);
310 r
.in
.validation_level
= NetlogonValidationGenericInfo2
;
312 torture_assert_ntstatus_ok(tctx
, dcerpc_netr_LogonSamLogon_r(b
, tctx
, &r
),
313 "LogonSamLogon failed");
315 torture_assert_ntstatus_equal(tctx
, r
.out
.result
, NT_STATUS_INVALID_PARAMETER
, "LogonSamLogon failed");
317 torture_assert(tctx
, netlogon_creds_client_check(creds
,
318 &r
.out
.return_authenticator
->cred
),
319 "Credential chaining failed");
321 pac_wrapped_struct
.ChecksumLength
= pac_data
->pac_srv_sig
->signature
.length
;
322 pac_wrapped_struct
.SignatureType
= pac_data
->pac_kdc_sig
->type
;
324 /* Break the SignatureType */
325 pac_wrapped_struct
.SignatureType
++;
327 pac_wrapped_struct
.SignatureLength
= pac_data
->pac_kdc_sig
->signature
.length
;
328 pac_wrapped_struct
.ChecksumAndSignature
= payload
329 = data_blob_talloc(tmp_ctx
, NULL
,
330 pac_wrapped_struct
.ChecksumLength
331 + pac_wrapped_struct
.SignatureLength
);
332 memcpy(&payload
.data
[0],
333 pac_data
->pac_srv_sig
->signature
.data
,
334 pac_wrapped_struct
.ChecksumLength
);
335 memcpy(&payload
.data
[pac_wrapped_struct
.ChecksumLength
],
336 pac_data
->pac_kdc_sig
->signature
.data
,
337 pac_wrapped_struct
.SignatureLength
);
339 ndr_err
= ndr_push_struct_blob(&pac_wrapped
, tmp_ctx
, &pac_wrapped_struct
,
340 (ndr_push_flags_fn_t
)ndr_push_PAC_Validate
);
341 torture_assert(tctx
, NDR_ERR_CODE_IS_SUCCESS(ndr_err
), "ndr_push_struct_blob of PACValidate structure failed");
343 torture_assert(tctx
, (creds
->negotiate_flags
& NETLOGON_NEG_ARCFOUR
), "not willing to even try a PACValidate without RC4 encryption");
344 netlogon_creds_arcfour_crypt(creds
, pac_wrapped
.data
, pac_wrapped
.length
);
346 generic
.length
= pac_wrapped
.length
;
347 generic
.data
= pac_wrapped
.data
;
349 logon
.generic
= &generic
;
352 netlogon_creds_client_authenticator(creds
, &auth
);
353 r
.in
.credential
= &auth
;
354 r
.in
.return_authenticator
= &auth2
;
355 r
.in
.logon_level
= NetlogonGenericInformation
;
357 r
.in
.server_name
= talloc_asprintf(tctx
, "\\\\%s", dcerpc_server_name(p
));
358 r
.in
.computer_name
= cli_credentials_get_workstation(credentials
);
359 r
.in
.validation_level
= NetlogonValidationGenericInfo2
;
361 torture_assert_ntstatus_ok(tctx
, dcerpc_netr_LogonSamLogon_r(b
, tctx
, &r
),
362 "LogonSamLogon failed");
364 torture_assert_ntstatus_equal(tctx
, r
.out
.result
, NT_STATUS_LOGON_FAILURE
, "LogonSamLogon failed");
366 torture_assert(tctx
, netlogon_creds_client_check(creds
, &r
.out
.return_authenticator
->cred
),
367 "Credential chaining failed");
369 pac_wrapped_struct
.ChecksumLength
= pac_data
->pac_srv_sig
->signature
.length
;
370 pac_wrapped_struct
.SignatureType
= pac_data
->pac_kdc_sig
->type
;
371 pac_wrapped_struct
.SignatureLength
= pac_data
->pac_kdc_sig
->signature
.length
;
373 pac_wrapped_struct
.ChecksumAndSignature
= payload
374 = data_blob_talloc(tmp_ctx
, NULL
,
375 pac_wrapped_struct
.ChecksumLength
376 + pac_wrapped_struct
.SignatureLength
);
377 memcpy(&payload
.data
[0],
378 pac_data
->pac_srv_sig
->signature
.data
,
379 pac_wrapped_struct
.ChecksumLength
);
380 memcpy(&payload
.data
[pac_wrapped_struct
.ChecksumLength
],
381 pac_data
->pac_kdc_sig
->signature
.data
,
382 pac_wrapped_struct
.SignatureLength
);
384 /* Break the signature length */
385 pac_wrapped_struct
.SignatureLength
++;
387 ndr_err
= ndr_push_struct_blob(&pac_wrapped
, tmp_ctx
, &pac_wrapped_struct
,
388 (ndr_push_flags_fn_t
)ndr_push_PAC_Validate
);
389 torture_assert(tctx
, NDR_ERR_CODE_IS_SUCCESS(ndr_err
), "ndr_push_struct_blob of PACValidate structure failed");
391 torture_assert(tctx
, (creds
->negotiate_flags
& NETLOGON_NEG_ARCFOUR
), "not willing to even try a PACValidate without RC4 encryption");
392 netlogon_creds_arcfour_crypt(creds
, pac_wrapped
.data
, pac_wrapped
.length
);
394 generic
.length
= pac_wrapped
.length
;
395 generic
.data
= pac_wrapped
.data
;
397 logon
.generic
= &generic
;
400 netlogon_creds_client_authenticator(creds
, &auth
);
401 r
.in
.credential
= &auth
;
402 r
.in
.return_authenticator
= &auth2
;
403 r
.in
.logon_level
= NetlogonGenericInformation
;
405 r
.in
.server_name
= talloc_asprintf(tctx
, "\\\\%s", dcerpc_server_name(p
));
406 r
.in
.computer_name
= cli_credentials_get_workstation(credentials
);
407 r
.in
.validation_level
= NetlogonValidationGenericInfo2
;
409 torture_assert_ntstatus_ok(tctx
, dcerpc_netr_LogonSamLogon_r(b
, tctx
, &r
),
410 "LogonSamLogon failed");
412 torture_assert_ntstatus_equal(tctx
, r
.out
.result
, NT_STATUS_INVALID_PARAMETER
, "LogonSamLogon failed");
414 torture_assert(tctx
, netlogon_creds_client_check(creds
, &r
.out
.return_authenticator
->cred
),
415 "Credential chaining failed");
420 static bool test_PACVerify_bdc(struct torture_context
*tctx
,
421 struct dcerpc_pipe
*p
,
422 struct cli_credentials
*credentials
)
424 return test_PACVerify(tctx
, p
, credentials
, SEC_CHAN_BDC
, TEST_MACHINE_NAME_BDC
);
427 static bool test_PACVerify_workstation(struct torture_context
*tctx
,
428 struct dcerpc_pipe
*p
,
429 struct cli_credentials
*credentials
)
431 return test_PACVerify(tctx
, p
, credentials
, SEC_CHAN_WKSTA
, TEST_MACHINE_NAME_WKSTA
);
434 static bool test_PACVerify_workstation_des(struct torture_context
*tctx
,
435 struct dcerpc_pipe
*p
, struct cli_credentials
*credentials
, struct test_join
*join_ctx
)
437 struct samr_SetUserInfo r
;
438 union samr_UserInfo user_info
;
439 struct dcerpc_pipe
*samr_pipe
= torture_join_samr_pipe(join_ctx
);
441 #ifdef AD_DC_BUILD_IS_ENABLED
442 struct smb_krb5_context
*smb_krb5_context
;
445 ret
= cli_credentials_get_krb5_context(cmdline_credentials
, tctx
->lp_ctx
, &smb_krb5_context
);
446 torture_assert_int_equal(tctx
, ret
, 0, "cli_credentials_get_krb5_context() failed");
448 if (krb5_config_get_bool_default(smb_krb5_context
->krb5_context
, NULL
, FALSE
,
450 "allow_weak_crypto", NULL
) == FALSE
) {
451 torture_skip(tctx
, "Cannot test DES without [libdefaults] allow_weak_crypto = yes");
454 torture_skip(tctx
, "Skipping DES test in non-AD DC build");
457 /* Mark this workstation with DES-only */
458 user_info
.info16
.acct_flags
= ACB_USE_DES_KEY_ONLY
| ACB_WSTRUST
;
459 r
.in
.user_handle
= torture_join_samr_user_policy(join_ctx
);
461 r
.in
.info
= &user_info
;
463 torture_assert_ntstatus_ok(tctx
, dcerpc_samr_SetUserInfo_r(samr_pipe
->binding_handle
, tctx
, &r
),
464 "failed to set DES info account flags");
465 torture_assert_ntstatus_ok(tctx
, r
.out
.result
,
466 "failed to set DES into account flags");
468 return test_PACVerify(tctx
, p
, credentials
, SEC_CHAN_WKSTA
, TEST_MACHINE_NAME_WKSTA_DES
);
472 /* Check various ways to get the PAC, in particular check the group membership and other details between the PAC from a normal kinit, S2U4Self and a SamLogon */
473 static bool test_S2U4Self(struct torture_context
*tctx
,
474 struct dcerpc_pipe
*p
,
475 struct cli_credentials
*credentials
,
476 enum netr_SchannelType secure_channel_type
,
477 const char *test_machine_name
)
480 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
482 struct netr_LogonSamLogon r
;
484 union netr_LogonLevel logon
;
485 union netr_Validation validation
;
486 uint8_t authoritative
;
488 struct netr_Authenticator auth
, auth2
;
490 DATA_BLOB client_to_server
, server_to_client
;
492 struct netlogon_creds_CredentialState
*creds
;
493 struct gensec_security
*gensec_client_context
;
494 struct gensec_security
*gensec_server_context
;
496 struct auth4_context
*auth_context
;
497 struct auth_session_info
*kinit_session_info
;
498 struct auth_session_info
*s2u4self_session_info
;
499 struct auth_user_info_dc
*netlogon_user_info_dc
;
501 struct netr_NetworkInfo ninfo
;
502 DATA_BLOB names_blob
, chal
, lm_resp
, nt_resp
;
504 int flags
= CLI_CRED_NTLMv2_AUTH
;
506 struct dom_sid
*builtin_domain
;
508 TALLOC_CTX
*tmp_ctx
= talloc_new(tctx
);
510 torture_assert(tctx
, tmp_ctx
!= NULL
, "talloc_new() failed");
512 auth_context
= talloc_zero(tmp_ctx
, struct auth4_context
);
513 torture_assert(tctx
, auth_context
!= NULL
, "talloc_new() failed");
515 auth_context
->generate_session_info_pac
= test_generate_session_info_pac
;
517 /* First, do a normal Kerberos connection */
519 status
= gensec_client_start(tctx
, &gensec_client_context
,
520 lpcfg_gensec_settings(tctx
, tctx
->lp_ctx
));
521 torture_assert_ntstatus_ok(tctx
, status
, "gensec_client_start (client) failed");
523 status
= gensec_set_target_hostname(gensec_client_context
, test_machine_name
);
525 status
= gensec_set_credentials(gensec_client_context
, cmdline_credentials
);
526 torture_assert_ntstatus_ok(tctx
, status
, "gensec_set_credentials (client) failed");
528 status
= gensec_start_mech_by_sasl_name(gensec_client_context
, "GSSAPI");
529 torture_assert_ntstatus_ok(tctx
, status
, "gensec_start_mech_by_sasl_name (client) failed");
531 status
= gensec_server_start(tctx
,
532 lpcfg_gensec_settings(tctx
, tctx
->lp_ctx
),
533 auth_context
, &gensec_server_context
);
534 torture_assert_ntstatus_ok(tctx
, status
, "gensec_server_start (server) failed");
536 status
= gensec_set_credentials(gensec_server_context
, credentials
);
537 torture_assert_ntstatus_ok(tctx
, status
, "gensec_set_credentials (server) failed");
539 status
= gensec_start_mech_by_sasl_name(gensec_server_context
, "GSSAPI");
540 torture_assert_ntstatus_ok(tctx
, status
, "gensec_start_mech_by_sasl_name (server) failed");
542 server_to_client
= data_blob(NULL
, 0);
545 /* Do a client-server update dance */
546 status
= gensec_update(gensec_client_context
, tmp_ctx
, tctx
->ev
, server_to_client
, &client_to_server
);
547 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {;
548 torture_assert_ntstatus_ok(tctx
, status
, "gensec_update (client) failed");
551 status
= gensec_update(gensec_server_context
, tmp_ctx
, tctx
->ev
, client_to_server
, &server_to_client
);
552 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {;
553 torture_assert_ntstatus_ok(tctx
, status
, "gensec_update (server) failed");
556 if (NT_STATUS_IS_OK(status
)) {
561 /* Extract the PAC using Samba's code */
563 status
= gensec_session_info(gensec_server_context
, gensec_server_context
, &kinit_session_info
);
564 torture_assert_ntstatus_ok(tctx
, status
, "gensec_session_info failed");
567 /* Now do the dance with S2U4Self */
569 /* Wipe out any existing ccache */
570 cli_credentials_invalidate_ccache(credentials
, CRED_SPECIFIED
);
571 cli_credentials_set_impersonate_principal(credentials
,
572 cli_credentials_get_principal(cmdline_credentials
, tmp_ctx
),
573 talloc_asprintf(tmp_ctx
, "host/%s", test_machine_name
));
575 status
= gensec_client_start(tctx
, &gensec_client_context
,
576 lpcfg_gensec_settings(tctx
, tctx
->lp_ctx
));
577 torture_assert_ntstatus_ok(tctx
, status
, "gensec_client_start (client) failed");
579 status
= gensec_set_target_hostname(gensec_client_context
, test_machine_name
);
581 /* We now set the same credentials on both client and server contexts */
582 status
= gensec_set_credentials(gensec_client_context
, credentials
);
583 torture_assert_ntstatus_ok(tctx
, status
, "gensec_set_credentials (client) failed");
585 status
= gensec_start_mech_by_sasl_name(gensec_client_context
, "GSSAPI");
586 torture_assert_ntstatus_ok(tctx
, status
, "gensec_start_mech_by_sasl_name (client) failed");
588 status
= gensec_server_start(tctx
,
589 lpcfg_gensec_settings(tctx
, tctx
->lp_ctx
),
590 auth_context
, &gensec_server_context
);
591 torture_assert_ntstatus_ok(tctx
, status
, "gensec_server_start (server) failed");
593 status
= gensec_set_credentials(gensec_server_context
, credentials
);
594 torture_assert_ntstatus_ok(tctx
, status
, "gensec_set_credentials (server) failed");
596 status
= gensec_start_mech_by_sasl_name(gensec_server_context
, "GSSAPI");
597 torture_assert_ntstatus_ok(tctx
, status
, "gensec_start_mech_by_sasl_name (server) failed");
599 server_to_client
= data_blob(NULL
, 0);
602 /* Do a client-server update dance */
603 status
= gensec_update(gensec_client_context
, tmp_ctx
, tctx
->ev
, server_to_client
, &client_to_server
);
604 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {;
605 torture_assert_ntstatus_ok(tctx
, status
, "gensec_update (client) failed");
608 status
= gensec_update(gensec_server_context
, tmp_ctx
, tctx
->ev
, client_to_server
, &server_to_client
);
609 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {;
610 torture_assert_ntstatus_ok(tctx
, status
, "gensec_update (server) failed");
613 if (NT_STATUS_IS_OK(status
)) {
618 /* Don't pollute the remaining tests with the changed credentials */
619 cli_credentials_invalidate_ccache(credentials
, CRED_SPECIFIED
);
620 cli_credentials_set_target_service(credentials
, NULL
);
621 cli_credentials_set_impersonate_principal(credentials
, NULL
, NULL
);
623 /* Extract the PAC using Samba's code */
625 status
= gensec_session_info(gensec_server_context
, gensec_server_context
, &s2u4self_session_info
);
626 torture_assert_ntstatus_ok(tctx
, status
, "gensec_session_info failed");
628 cli_credentials_get_ntlm_username_domain(cmdline_credentials
, tctx
,
629 &ninfo
.identity_info
.account_name
.string
,
630 &ninfo
.identity_info
.domain_name
.string
);
632 /* Now try with SamLogon */
633 generate_random_buffer(ninfo
.challenge
,
634 sizeof(ninfo
.challenge
));
635 chal
= data_blob_const(ninfo
.challenge
,
636 sizeof(ninfo
.challenge
));
638 names_blob
= NTLMv2_generate_names_blob(tctx
, cli_credentials_get_workstation(credentials
),
639 cli_credentials_get_domain(credentials
));
641 status
= cli_credentials_get_ntlm_response(cmdline_credentials
, tctx
,
647 torture_assert_ntstatus_ok(tctx
, status
, "cli_credentials_get_ntlm_response failed");
649 ninfo
.lm
.data
= lm_resp
.data
;
650 ninfo
.lm
.length
= lm_resp
.length
;
652 ninfo
.nt
.data
= nt_resp
.data
;
653 ninfo
.nt
.length
= nt_resp
.length
;
655 ninfo
.identity_info
.parameter_control
= 0;
656 ninfo
.identity_info
.logon_id_low
= 0;
657 ninfo
.identity_info
.logon_id_high
= 0;
658 ninfo
.identity_info
.workstation
.string
= cli_credentials_get_workstation(credentials
);
660 logon
.network
= &ninfo
;
662 r
.in
.server_name
= talloc_asprintf(tctx
, "\\\\%s", dcerpc_server_name(p
));
663 r
.in
.computer_name
= cli_credentials_get_workstation(credentials
);
664 r
.in
.credential
= &auth
;
665 r
.in
.return_authenticator
= &auth2
;
666 r
.in
.logon_level
= NetlogonNetworkInformation
;
668 r
.out
.validation
= &validation
;
669 r
.out
.authoritative
= &authoritative
;
671 if (!test_SetupCredentials2(p
, tctx
, NETLOGON_NEG_AUTH2_ADS_FLAGS
,
672 credentials
, secure_channel_type
,
678 netlogon_creds_client_authenticator(creds
, &auth
);
680 r
.in
.validation_level
= 3;
682 status
= dcerpc_netr_LogonSamLogon_r(b
, tctx
, &r
);
683 torture_assert_ntstatus_ok(tctx
, status
, "LogonSamLogon failed");
685 torture_assert(tctx
, netlogon_creds_client_check(creds
,
686 &r
.out
.return_authenticator
->cred
),
687 "Credential chaining failed");
689 status
= make_user_info_dc_netlogon_validation(tmp_ctx
,
690 ninfo
.identity_info
.account_name
.string
,
691 r
.in
.validation_level
,
693 true, /* This user was authenticated */
694 &netlogon_user_info_dc
);
696 torture_assert_ntstatus_ok(tctx
, status
, "make_user_info_dc_netlogon_validation failed");
698 torture_assert_str_equal(tctx
, netlogon_user_info_dc
->info
->account_name
== NULL
? "" : netlogon_user_info_dc
->info
->account_name
,
699 kinit_session_info
->info
->account_name
, "Account name differs for kinit-based PAC");
700 torture_assert_str_equal(tctx
,netlogon_user_info_dc
->info
->account_name
== NULL
? "" : netlogon_user_info_dc
->info
->account_name
,
701 s2u4self_session_info
->info
->account_name
, "Account name differs for S2U4Self");
702 torture_assert_str_equal(tctx
, netlogon_user_info_dc
->info
->full_name
== NULL
? "" : netlogon_user_info_dc
->info
->full_name
, kinit_session_info
->info
->full_name
, "Full name differs for kinit-based PAC");
703 torture_assert_str_equal(tctx
, netlogon_user_info_dc
->info
->full_name
== NULL
? "" : netlogon_user_info_dc
->info
->full_name
, s2u4self_session_info
->info
->full_name
, "Full name differs for S2U4Self");
704 torture_assert_int_equal(tctx
, netlogon_user_info_dc
->num_sids
, kinit_session_info
->torture
->num_dc_sids
, "Different numbers of domain groups for kinit-based PAC");
705 torture_assert_int_equal(tctx
, netlogon_user_info_dc
->num_sids
, s2u4self_session_info
->torture
->num_dc_sids
, "Different numbers of domain groups for S2U4Self");
707 builtin_domain
= dom_sid_parse_talloc(tmp_ctx
, SID_BUILTIN
);
709 for (i
= 0; i
< kinit_session_info
->torture
->num_dc_sids
; i
++) {
710 torture_assert(tctx
, dom_sid_equal(&netlogon_user_info_dc
->sids
[i
], &kinit_session_info
->torture
->dc_sids
[i
]), "Different domain groups for kinit-based PAC");
711 torture_assert(tctx
, dom_sid_equal(&netlogon_user_info_dc
->sids
[i
], &s2u4self_session_info
->torture
->dc_sids
[i
]), "Different domain groups for S2U4Self");
712 torture_assert(tctx
, !dom_sid_in_domain(builtin_domain
, &s2u4self_session_info
->torture
->dc_sids
[i
]), "Returned BUILTIN domain in groups for S2U4Self");
713 torture_assert(tctx
, !dom_sid_in_domain(builtin_domain
, &kinit_session_info
->torture
->dc_sids
[i
]), "Returned BUILTIN domain in groups kinit-based PAC");
714 torture_assert(tctx
, !dom_sid_in_domain(builtin_domain
, &netlogon_user_info_dc
->sids
[i
]), "Returned BUILTIN domian in groups from NETLOGON SamLogon reply");
720 static bool test_S2U4Self_bdc(struct torture_context
*tctx
,
721 struct dcerpc_pipe
*p
,
722 struct cli_credentials
*credentials
)
724 return test_S2U4Self(tctx
, p
, credentials
, SEC_CHAN_BDC
, TEST_MACHINE_NAME_S2U4SELF_BDC
);
727 static bool test_S2U4Self_workstation(struct torture_context
*tctx
,
728 struct dcerpc_pipe
*p
,
729 struct cli_credentials
*credentials
)
731 return test_S2U4Self(tctx
, p
, credentials
, SEC_CHAN_WKSTA
, TEST_MACHINE_NAME_S2U4SELF_WKSTA
);
734 struct torture_suite
*torture_rpc_remote_pac(TALLOC_CTX
*mem_ctx
)
736 struct torture_suite
*suite
= torture_suite_create(mem_ctx
, "pac");
737 struct torture_rpc_tcase
*tcase
;
739 /* It is important to use different names, so that old entries in our credential cache are not used */
740 tcase
= torture_suite_add_machine_bdc_rpc_iface_tcase(suite
, "netlogon-bdc",
741 &ndr_table_netlogon
, TEST_MACHINE_NAME_BDC
);
742 torture_rpc_tcase_add_test_creds(tcase
, "verify-sig", test_PACVerify_bdc
);
744 tcase
= torture_suite_add_machine_workstation_rpc_iface_tcase(suite
, "netlogon-member",
745 &ndr_table_netlogon
, TEST_MACHINE_NAME_WKSTA
);
746 torture_rpc_tcase_add_test_creds(tcase
, "verify-sig", test_PACVerify_workstation
);
748 tcase
= torture_suite_add_machine_workstation_rpc_iface_tcase(suite
, "netlogon-member-des",
749 &ndr_table_netlogon
, TEST_MACHINE_NAME_WKSTA_DES
);
750 torture_rpc_tcase_add_test_join(tcase
, "verify-sig", test_PACVerify_workstation_des
);
752 tcase
= torture_suite_add_machine_bdc_rpc_iface_tcase(suite
, "netlogon-bdc",
753 &ndr_table_netlogon
, TEST_MACHINE_NAME_S2U4SELF_BDC
);
754 torture_rpc_tcase_add_test_creds(tcase
, "s2u4self", test_S2U4Self_bdc
);
756 tcase
= torture_suite_add_machine_workstation_rpc_iface_tcase(suite
, "netlogon-member",
757 &ndr_table_netlogon
, TEST_MACHINE_NAME_S2U4SELF_WKSTA
);
759 torture_rpc_tcase_add_test_creds(tcase
, "s2u4self", test_S2U4Self_workstation
);